List of usage examples for java.util Set clear
void clear();
From source file:com.jeans.iservlet.service.asset.impl.AssetServiceImpl.java
@Override @Transactional(readOnly = true)//from w ww . j av a 2s . co m public Set<Byte> checkNextStates(Set<Long> ids, byte type) { Set<Byte> states = new HashSet<Byte>(); if (ids.size() == 0) { return states; } states.add(AssetConstants.IN_USE); states.add(AssetConstants.IDLE); states.add(AssetConstants.DISUSE); if (type == AssetConstants.HARDWARE_ASSET) { states.add(AssetConstants.FIXING); states.add(AssetConstants.ELIMINATED); } // ? Set<Byte> n_h_iu = new HashSet<Byte>(); Set<Byte> n_h_id = new HashSet<Byte>(); Set<Byte> n_h_fx = new HashSet<Byte>(); Set<Byte> n_h_du = new HashSet<Byte>(); Set<Byte> n_s_iu = new HashSet<Byte>(); Set<Byte> n_s_id = new HashSet<Byte>(); n_h_iu.add(AssetConstants.IN_USE); n_h_iu.add(AssetConstants.IDLE); n_h_iu.add(AssetConstants.FIXING); n_h_id.add(AssetConstants.IN_USE); n_h_id.add(AssetConstants.FIXING); n_h_id.add(AssetConstants.DISUSE); n_h_fx.add(AssetConstants.IN_USE); n_h_fx.add(AssetConstants.IDLE); n_h_fx.add(AssetConstants.DISUSE); n_h_du.add(AssetConstants.ELIMINATED); n_s_iu.add(AssetConstants.IDLE); n_s_iu.add(AssetConstants.DISUSE); n_s_id.add(AssetConstants.IN_USE); n_s_id.add(AssetConstants.DISUSE); List<Asset> assets = loadAssets(ids, type); if (type == AssetConstants.HARDWARE_ASSET) { /* * (???) -> // -> // -> //? -> ? ? -> null */ for (Asset asset : assets) { byte oldState = asset.getState(); if (oldState == AssetConstants.ELIMINATED) { // ???? states.clear(); break; } else { if (states.size() == 0) { // ????? break; } else { switch (oldState) { case AssetConstants.IN_USE: states.retainAll(n_h_iu); break; case AssetConstants.IDLE: states.retainAll(n_h_id); break; case AssetConstants.FIXING: states.retainAll(n_h_fx); break; case AssetConstants.DISUSE: states.retainAll(n_h_du); } } } } } else { /* * -> / -> / -> null */ for (Asset asset : assets) { byte oldState = asset.getState(); if (oldState == AssetConstants.DISUSE) { // ??? states.clear(); break; } else { if (states.size() == 1) { // ????????????? continue; } else { if (oldState == AssetConstants.IN_USE) { states.retainAll(n_s_iu); } else { states.retainAll(n_s_id); } } } } } return states; }
From source file:hydrograph.ui.propertywindow.widgets.customwidgets.operational.TransformDialog.java
/** * check if error exist//from ww w.jav a2 s . c o m */ public void showHideValidationMessage() { if (errorTableViewer != null) { errorLabelList.clear(); outputFieldIndices.clear(); setErrorMessageForDuplicateOutputField(); setErrorMessageForDuplicateInputField(); setErrorMessageForInvalidMapFields(); setErrorMessageForAccumulator(); setErrorMessageIfExpressionIsNotValid(); setErrorMessageIfMergeExpressionIsNotValid(); isAllExternalFielsAreInSync(); Set<String> setToCheckDuplicates = showErrorIfOperationClassOrExpressionBlankOrOperationIDDuplicate(); errorTableViewer.getTable().setForeground(CustomColorRegistry.INSTANCE.getColorFromRegistry(255, 0, 0)); errorTableViewer.refresh(); setToCheckDuplicates.clear(); } }
From source file:gov.nih.nci.cabig.caaers.dataimport.AgentSpecificTermsImporter.java
public Map<String, Object> importFile() throws Exception { POIFSFileSystem poifs;/*from ww w.j a va 2s . c om*/ HSSFWorkbook wb; HSSFSheet sh = null; boolean isExcel = file.getName().endsWith(".xls"); boolean isCSV = file.getName().endsWith(".csv"); Map<String, Object> results = new HashMap<String, Object>(); int rowCount = 0; int columnsCount = 0; Map<String, Agent> agents = new HashMap<String, Agent>(); Map<String, Agent> missingAgents = new HashMap<String, Agent>(); Set<String> missingTerms = new HashSet<String>(); Map<String, String> asaelCache = new HashMap<String, String>(); int asael; // wipe out the table agentSpecificTermDao.deleteAll(); studyDao.deleteAllExpectedTerms(); // if (true) return null; // get needed headers if (isExcel) { poifs = new POIFSFileSystem(new FileInputStream(file)); wb = new HSSFWorkbook(poifs); sh = wb.getSheetAt(0); rowCount = sh.getLastRowNum(); columnsCount = sh.getRow(0).getLastCellNum(); for (byte i = 0; i < columnsCount; i++) { HSSFCell cell = sh.getRow(0).getCell(i); if (headers.containsKey(cell.getStringCellValue())) { headers.remove(cell.getStringCellValue()); headers.put(cell.getStringCellValue(), Short.valueOf(i)); } } } InputStream ir = null; Reader r = null; BufferedReader br = null; if (isCSV) { // readLines rowCount = 0; ir = new FileInputStream(file); r = new InputStreamReader(ir); br = new BufferedReader(r); String s = br.readLine(); while (s != null) { if (rowCount == 0) { String[] _s = s.split("[\\|]{1}"); for (byte j = 0; j < _s.length; j++) { // System.out.println(_s[j]); if (headers.containsKey(_s[j])) { headers.remove(_s[j]); headers.put(_s[j], Short.valueOf(j)); } } } rowCount++; s = br.readLine(); } br.close(); r.close(); ir.close(); ir = new FileInputStream(file); r = new InputStreamReader(ir); br = new BufferedReader(r); } /* System.out.println(rowCount); for (Map.Entry e : headers.entrySet()) { System.out.println(e.getKey() + "=>" + e.getValue()); } */ agents.clear(); missingTerms.clear(); missingAgents.clear(); asael = 0; int duplicateAgentTerms = 0; // String nsc = ""; String ctcae_category = ""; String ctcae_version = "0.0"; String ae_term = ""; String other_toxicity = ""; // Loading ASAE list // if (true) { return null; } int i = 1; while (i <= rowCount) { nsc = ""; if (isExcel) { HSSFRow row = sh.getRow(i); if (row != null) { nsc = getCellData("", i, row.getCell((short) headers.get("NSC"))); ctcae_category = getCellData("", i, row.getCell((short) headers.get("CTCAE_CATEGORY"))); ctcae_version = getCellData("", i, row.getCell((short) headers.get("CTCAE_VERSION"))); ae_term = getCellData("", i, row.getCell((short) headers.get("AE_TERM"))); other_toxicity = getCellData("", i, row.getCell((short) headers.get("OTHER_TOXICITY"))); } } else { String s; s = br.readLine(); if (s != null) { String[] _s = s.split("[\\|]{1}"); if (i > 1 && _s.length > 1) { nsc = _s[headers.get("NSC")]; ctcae_category = _s[headers.get("CTCAE_CATEGORY")]; try { ctcae_version = _s[headers.get("CTCAE_VERSION")].trim(); } catch (NumberFormatException e) { // System.out.println(s); return null; } ae_term = _s[headers.get("AE_TERM")]; if (_s.length - 1 >= headers.get("OTHER_TOXICITY")) other_toxicity = _s[headers.get("OTHER_TOXICITY")]; else other_toxicity = ""; } } } if (nsc.trim().equals("")) { i++; continue; } else { // System.out.println(String.format("%s). NSC:%s, V:%s, C:%s, T:%s", i, nsc, ctcae_version, ctcae_category, ae_term)); } Agent a = agents.get(nsc); if (a == null) { a = agentDao.getByNscNumber(nsc); // System.out.println(asael + ". OK. Found agent [" + a.getName() + "] for NSC: [" + nsc + "]"); agents.put(nsc, a); } if (a != null) { AgentSpecificCtcTerm t = new AgentSpecificCtcTerm(); t.setAgent(a); t.setOtherToxicity(other_toxicity); List<CtcTerm> list = terminologyRepository.getCtcTerm(ctcae_category, ctcae_version, ae_term); if (list.size() == 0) { // System.out.println("<ERROR>: Term not found: " + ae_term + ", Category: " + ctcae_category + ", CTCAE Version: " + ctcae_version); missingTerms.add("Term not found: " + ae_term + ", Category: " + ctcae_category + ", CTCAE Version: " + ctcae_version); } else { t.setCtcTerm(list.get(0)); if (persistASAE(t)) asael++; else duplicateAgentTerms++; } agentSpecificTermDao.evict(t); } else { if (!missingAgents.containsKey(nsc)) { // System.out.println("<ERROR>: The agent was not found by its NSC: " + nsc); missingAgents.put(nsc, null); } } i++; } if (isCSV) { br.close(); r.close(); ir.close(); } results.put(KEY_MISSING_TERMS, missingTerms); results.put(KEY_PROCESSED_AGENTS, agents.size() - missingAgents.size()); results.put(KEY_PROCESSED_AGENTTERMS, asael); results.put(KEY_MISSING_AGENTS, missingAgents); results.put(KEY_DUPLICATE_AGENT_TERMS, duplicateAgentTerms); return results; }
From source file:com.davidsoergel.trees.AbstractRootedPhylogeny.java
/** * Returns true if the current node should be included; false if it should be ignored * * @param theDisposableAncestorLists/* ww w . ja va2 s .co m*/ * @param mode * @return */ private boolean resolveMutualExclusion(Set<List<? extends PhylogenyNode<T>>> theDisposableAncestorLists, MutualExclusionResolutionMode mode) { // if there is only one list left, and it's empty, that's OK, we just finished a branch if (theDisposableAncestorLists.size() == 1) { return true; } assert theDisposableAncestorLists.size() > 1; // but if there's more than one, and one of them is empty, then we asked for a node as a leaf that turns out to be an ancestor of another leaf. // if we give the same path twice, that causes a failure here. Note leaf id uniqueness constraints above. Iterator<List<? extends PhylogenyNode<T>>> iterator = theDisposableAncestorLists.iterator(); while (iterator.hasNext()) { List<? extends PhylogenyNode<T>> ancestorList = iterator.next(); // there can be at most one empty list here due to leaf id uniqueness, so it's safe to return immediately rather than testing the rest if (ancestorList.isEmpty()) { if (mode == MutualExclusionResolutionMode.LEAF) { // don't include this node (we're currently at the ancestor) iterator.remove(); return false; } if (mode == MutualExclusionResolutionMode.ANCESTOR) { // remove all paths extending below this. // this would cause ConcurrentModificationException except that we return and never touch the iterator again theDisposableAncestorLists.clear(); theDisposableAncestorLists.add(new ArrayList<PhylogenyNode<T>>()); // the ancestor itself. Maybe not strictly necessary, but for consistency anyway return true; } if (mode == MutualExclusionResolutionMode.BOTH) { iterator.remove(); return true; } else // if (mode == EXCEPTION) { throw new TreeRuntimeException("Requested extraction of an internal node as a leaf"); } } } /*for (List<PhylogenyNode<T>> ancestorList : theAncestorLists) { if (ancestorList.isEmpty()) { throw new TreeRuntimeException("Requested extraction of an internal node as a leaf"); } }*/ // if we got here, then there are multiple ancestor lists and none of them is empty, so this is a branch point. return true; }
From source file:org.bremersee.common.security.acls.jdbc.BasicLookupStrategy.java
/** * The main method./* ww w . j av a 2s. c o m*/ * <p> * WARNING: This implementation completely disregards the "sids" argument! Every item * in the cache is expected to contain all SIDs. If you have serious performance needs * (e.g. a very large number of SIDs per object identity), you'll probably want to * develop a custom {@link LookupStrategy} implementation instead. * <p> * The implementation works in batch sizes specified by {@link #batchSize}. * * @param objects the identities to lookup (required) * @param sids the SIDs for which identities are required (ignored by this * implementation) * * @return a <tt>Map</tt> where keys represent the {@link ObjectIdentity} of the * located {@link Acl} and values are the located {@link Acl} (never <tt>null</tt> * although some entries may be missing; this method should not throw * {@link NotFoundException}, as a chain of {@link LookupStrategy}s may be used to * automatically create entries if required) */ @Override public final Map<ObjectIdentity, Acl> readAclsById(List<ObjectIdentity> objects, // NOSONAR List<Sid> sids) { Assert.isTrue(batchSize >= 1, "BatchSize must be >= 1"); Assert.notEmpty(objects, "Objects to lookup required"); // Map<ObjectIdentity,Acl> Map<ObjectIdentity, Acl> result = new HashMap<>(); // contains // FULLY // loaded // Acl // objects Set<ObjectIdentity> currentBatchToLoad = new HashSet<>(); for (int i = 0; i < objects.size(); i++) { final ObjectIdentity oid = objects.get(i); boolean aclFound = false; // Check we don't already have this ACL in the results if (result.containsKey(oid)) { aclFound = true; } // Check cache for the present ACL entry if (!aclFound) { Acl acl = aclCache.getFromCache(oid); // Ensure any cached element supports all the requested SIDs // (they should always, as our base impl doesn't filter on SID) if (acl != null) { if (acl.isSidLoaded(sids)) { // NOSONAR result.put(acl.getObjectIdentity(), acl); aclFound = true; } else { throw new IllegalStateException( "Error: SID-filtered element detected when implementation does not perform SID filtering " + "- have you added something to the cache manually?"); } } } // Load the ACL from the database if (!aclFound) { currentBatchToLoad.add(oid); } // Is it time to load from JDBC the currentBatchToLoad? if ((currentBatchToLoad.size() == this.batchSize) || ((i + 1) == objects.size())) { if (!currentBatchToLoad.isEmpty()) { // NOSONAR Map<ObjectIdentity, Acl> loadedBatch = lookupObjectIdentities(currentBatchToLoad, sids); // Add loaded batch (all elements 100% initialized) to results result.putAll(loadedBatch); // Add the loaded batch to the cache for (Acl loadedAcl : loadedBatch.values()) { // NOSONAR aclCache.putInCache((AclImpl) loadedAcl); } currentBatchToLoad.clear(); } } } return result; }
From source file:fr.landel.utils.assertor.predicate.PredicateAssertorIterableTest.java
/** * Test method for {@link AssertorIterable#contains}. * /*from w w w .java 2s. c o m*/ * @throws IOException * On contain */ @Test public void testDoesNotContainIterable() throws IOException { final String el1 = "element1"; final String el2 = "element2"; final Set<String> set = new HashSet<>(); final Set<String> set2 = new HashSet<>(); set.add(el1); set2.add(el1); set2.add(el2); Assertor.<Set<String>, String>ofIterable().not().containsAll(set2).that(set) .orElseThrow("iterable contains the list %s*"); Assertor.<Set<String>, String>ofIterable(EnumAnalysisMode.STREAM).not().containsAll(set2).that(set) .orElseThrow("iterable contains the list %s*"); Assertor.<Set<String>, String>ofIterable(EnumAnalysisMode.PARALLEL).not().containsAll(set2).that(set) .orElseThrow("iterable contains the list %s*"); set2.remove(el1); assertException(() -> { Assertor.<Set<String>, String>ofIterable().not().containsAll(set2).that(set) .orElseThrow("iterable contains the list %2$s*"); fail(ERROR); }, IllegalArgumentException.class, "iterable contains the list " + set2.toString()); assertException(() -> { Assertor.<Set<String>, String>ofIterable().not().containsAll(set2).that(set) .orElseThrow(new IOException(), true); fail(ERROR); }, IOException.class); assertException(() -> { Assertor.<Set<String>, String>ofIterable().not().containsAll((Iterable<String>) null).that(set) .orElseThrow(); fail(ERROR); }, IllegalArgumentException.class, "neither iterables can be null or empty"); assertFalse(Assertor.<Set<String>, String>ofIterable().not().containsAll(set2).that(set).isOK()); assertFalse(Assertor.<Set<String>, String>ofIterable().not().containsAll(set).that(set).isOK()); assertTrue(Assertor.<Set<String>, String>ofIterable().not().containsAny(set2).that(set).isOK()); assertFalse(Assertor.<Set<String>, String>ofIterable().not().containsAny(set).that(set).isOK()); set.clear(); assertException(() -> { Assertor.<Iterable<String>, String>ofIterable().not().containsAll(set2).that((Iterable<String>) null) .orElseThrow(); fail(ERROR); }, IllegalArgumentException.class, "neither iterables can be null or empty"); assertException(() -> { Assertor.<Set<String>, String>ofIterable().not().containsAll((Iterable<String>) null).that(set) .orElseThrow(); fail(ERROR); }, IllegalArgumentException.class, "neither iterables can be null or empty"); assertFalse(Assertor.<Set<String>, String>ofIterable().not().containsAll(set2).that(set).isOK()); assertFalse(Assertor.<Set<String>, String>ofIterable().not().containsAll(set).that(set).isOK()); assertFalse(Assertor.<Set<String>, String>ofIterable().not().containsAny(set2).that(set).isOK()); assertFalse(Assertor.<Set<String>, String>ofIterable().not().containsAny(set).that(set).isOK()); }
From source file:edu.utah.further.i2b2.query.criteria.service.impl.I2b2SearchQueryBuilder.java
/** * Constructs a {@link SearchQuery} from an {@link I2b2Query}. * //www . jav a2 s .c o m * Each QueryGroup represents an AND gate; each QueryItem is an OR gate; if a * QueryGroup is inverted, it is equivalent to NOT AND. * * @return * @see edu.utah.further.core.api.lang.Builder#build() */ @Override public SearchQuery build() { final List<I2b2QueryGroup> i2b2QueryGroups = i2b2Query.getQueryGroups(); for (final I2b2QueryGroup i2b2QueryGroup : i2b2QueryGroups) { // TODO: This is a little messy, clean up when time permits SearchCriterion currGrpCrit = junction(SearchType.DISJUNCTION); final List<I2b2KeyType> currKeys = getI2b2QueryService().getNonDemKeysInGrp(i2b2QueryGroup); final Set<SearchQueryAlias> currAliases = CollectionUtil.newSet(); final boolean subQryReq = isSubQueryRequired(currKeys); final String observationAlias = obsAliasGenerator.getAlias(subQryReq); /* * Never generate new at this point for Orders or Locations. Change when * subqueries for these types are required. They'll be required in later * versions when we have different types of orders other than Medication and * different types of locations other than CurrentLocation. */ final String orderAlias = orderAliasGenerator.getAlias(false); final String locationAlias = locAliasGenerator.getAlias(false); final String encounterAlias = encounterAliasGenerator.getAlias(false); final GroupedCriteria groupedCriteria = new GroupedCriteria(); for (final I2b2QueryItem i2b2QueryItem : i2b2QueryGroup.getQueryItems()) { // (FUR-1772) // Handle Grouped Criteria if (fromPattern(i2b2QueryItem.getItemKey()).isGroupedCriteria()) { groupedCriteria.addCriteria(i2b2QueryItem); } // Translates non grouped criteria else { final I2b2SearchCriterionBuilder criterionBuilder = toCriteria(i2b2QueryItem, observationAlias, orderAlias, locationAlias, encounterAlias); final SearchCriterion currentCriteria = criterionBuilder.build(); currAliases.addAll(criterionBuilder.buildAliases()); currGrpCrit = handleCurrCriteria(i2b2QueryGroup, i2b2QueryItem, currentCriteria, currGrpCrit); } } // Translate groups for (final Entry<I2b2KeyType, List<String>> entry : groupedCriteria.getGroupedCriteria().entrySet()) { if (!entry.getValue().isEmpty()) { currGrpCrit = handleCriteriaGroup(i2b2QueryGroup, currGrpCrit, entry.getKey(), currAliases, observationAlias, orderAlias, locationAlias, encounterAlias, entry.getValue(), null); } } if (subQryReq) { currGrpCrit = handleSubQuery(currAliases, currGrpCrit); // Do not add current alias to outer query currAliases.clear(); } currGrpCrit = handleInverted(i2b2QueryGroup, currGrpCrit); aliases.addAll(currAliases); andCriterion.addCriterion(currGrpCrit); } // The root object is hardcoded for now, eventually, when the interface permits, // have it send in what the root should be. return queryBuilder(andCriterion).addAliases(CollectionUtil.newList(aliases)).setRootObject("Person") .build(); }
From source file:com.ebay.cloud.cms.query.service.QueryPaginationByIdTest.java
private void queryAndIterate(long TOTAL_COUNT, String query, QueryContext queryContext, Set<String> allIds, int step) throws Exception { queryContext.getCursor().setLimits(null); queryContext.getCursor().setSingleCursorValue(null); Set<String> fetchedIds = new HashSet<String>(); IQueryResult result;/* w w w.jav a 2 s . c o m*/ int fetchCount = 0; queryContext.getCursor().setLimits(new int[] { step }); result = queryService.query(query, queryContext); List<String> repeatedIds = new ArrayList<String>(); do { for (IEntity e : result.getEntities()) { if (fetchedIds.contains(e.getId())) { repeatedIds.add(e.getId()); } else { fetchedIds.add(e.getId()); } fetchCount++; } if (result.hasMoreResults()) { Assert.assertNotNull(result.getNextCursor()); Assert.assertNull(result.getNextCursor().getSortOn()); Assert.assertNull(result.getNextCursor().getJoinCursorValues()); Assert.assertFalse(result.getNextCursor().isJoinCursor()); queryContext.setCursor(result.getNextCursor()); result = queryService.query(query, queryContext); } else { break; } } while (true); Set<String> missedIds = CollectionUtils.diffSet(allIds, fetchedIds); Assert.assertEquals("Missed Entity ids : " + missedIds, 0, missedIds.size()); System.out.println(" repeated entity ids: " + new ObjectMapper().writeValueAsString(repeatedIds)); if (TOTAL_COUNT != fetchCount) { Assert.fail(" repeated entity ids: " + new ObjectMapper().writeValueAsString(repeatedIds)); } Assert.assertEquals(TOTAL_COUNT, fetchCount); Assert.assertEquals(0, repeatedIds.size()); Assert.assertEquals(TOTAL_COUNT, fetchedIds.size()); // Assert.assertEquals(2, queryIterationCount); fetchedIds.clear(); fetchCount = 0; }
From source file:ddf.catalog.CatalogFrameworkImpl.java
/** * Executes a query using the specified {@link QueryRequest} and {@link FederationStrategy}. * Based on the isEnterprise and sourceIds list in the query request, the federated query may * include the local provider and {@link ConnectedSource}s. * /*w ww .j av a 2s . co m*/ * @param queryRequest * the {@link QueryRequest} * @param strategy * @return the {@link QueryResponse} * @throws FederationException */ private QueryResponse doQuery(QueryRequest queryRequest, FederationStrategy strategy) throws FederationException { String methodName = "doQuery"; logger.entry(methodName); Set<ProcessingDetails> exceptions = new HashSet<ProcessingDetails>(); Set<String> sourceIds = queryRequest.getSourceIds(); logger.debug("source ids: " + sourceIds); List<Source> sourcesToQuery = new ArrayList<Source>(); boolean addConnectedSources = false; boolean addCatalogProvider = false; boolean sourceFound = false; // Check if it's an enterprise query if (queryRequest.isEnterprise()) { addConnectedSources = true; addCatalogProvider = hasCatalogProvider(); if (sourceIds != null && !sourceIds.isEmpty()) { if (logger.isDebugEnabled()) { logger.debug("Enterprise Query also included specific sites which will now be ignored"); } sourceIds.clear(); } // add all the federated sources for (FederatedSource source : federatedSources) { if (sourceIsAvailable(source)) { sourcesToQuery.add(source); } else { exceptions.add(createUnavailableProcessingDetails(source)); } } } else if (sourceIds != null && !sourceIds.isEmpty()) { // it's a targeted federated query if (includesLocalSources(sourceIds)) { logger.debug("Local source is included in sourceIds"); addConnectedSources = connectedSourcesExist(); addCatalogProvider = hasCatalogProvider(); sourceIds.remove(getId()); sourceIds.remove(null); sourceIds.remove(""); } // See if we still have sources to look up by name if (sourceIds.size() > 0) { // TODO make this more efficient // In fanout cases, we may have multiple sources with the same // ID. So go through all of them. for (String id : sourceIds) { logger.debug("Looking up source ID = " + id); sourceFound = false; for (FederatedSource source : federatedSources) { if (id != null && id.equals(source.getId())) { sourceFound = true; if (sourceIsAvailable(source)) { sourcesToQuery.add(source); } else { exceptions.add(createUnavailableProcessingDetails(source)); } } } if (!sourceFound) { exceptions.add(new ProcessingDetailsImpl(id, new Exception("Source id is not found"))); } } } } else { // default to local sources addConnectedSources = connectedSourcesExist(); addCatalogProvider = hasCatalogProvider(); } if (addConnectedSources) { // add Connected Sources for (ConnectedSource source : connectedSources) { if (sourceIsAvailable(source)) { sourcesToQuery.add(source); } else { // do nothing -- we don't care if a connected source is // unavailable. if (logger.isWarnEnabled()) { logger.warn("Connected Source \"" + source.getId() + " is unavailable and will not be queried."); } } } } if (addCatalogProvider) { if (sourceIsAvailable(catalog)) { sourcesToQuery.add(catalog); } else { exceptions.add(createUnavailableProcessingDetails(catalog)); } } if (sourcesToQuery.isEmpty()) { // We have nothing to query at all. logger.debug("sourcesToQuery is empty - throwing exception"); // TODO change to SourceUnavailableException throw new FederationException( "SiteNames could not be resolved to valid sites, or none of the sites were available."); } logger.debug("Calling strategy.federate()"); QueryResponse response = strategy.federate(sourcesToQuery, queryRequest); return addProcessingDetails(exceptions, response); }
From source file:it.reply.orchestrator.service.commands.PrefilterCloudProviders.java
protected void discardProvidersAndServices(Set<CloudProvider> providersToDiscard, Set<CloudService> servicesToDiscard, RankCloudProvidersMessage rankCloudProvidersMessage) { // Add providers that doesn't have any compute service anymore for (CloudProvider cloudProvider : rankCloudProvidersMessage.getCloudProviders().values()) { boolean remove = true; for (CloudService cloudService : cloudProvider.getCmbdProviderServicesByType(Type.COMPUTE)) { if (!servicesToDiscard.contains(cloudService)) { remove = false;/*from ww w. j av a2 s .com*/ } else { cloudProvider.getCmdbProviderServices().remove(cloudService.getId()); } } if (remove) { addProviderToDiscard(providersToDiscard, servicesToDiscard, cloudProvider); } } // Remove discarded provider and services from SLAs and Preferences for (CloudProvider providerToDiscard : providersToDiscard) { rankCloudProvidersMessage.getCloudProviders().remove(providerToDiscard.getId()); Iterator<Sla> slaIt = rankCloudProvidersMessage.getSlamPreferences().getSla().iterator(); while (slaIt.hasNext()) { Sla sla = slaIt.next(); if (Objects.equals(providerToDiscard.getId(), sla.getCloudProviderId())) { slaIt.remove(); } } } for (CloudService cloudService : servicesToDiscard) { Iterator<Preference> extPrefIt = rankCloudProvidersMessage.getSlamPreferences().getPreferences() .iterator(); while (extPrefIt.hasNext()) { Preference extPreference = extPrefIt.next(); Iterator<PreferenceCustomer> intPrefIt = extPreference.getPreferences().iterator(); while (intPrefIt.hasNext()) { PreferenceCustomer intPreference = intPrefIt.next(); Iterator<Priority> priorityIt = intPreference.getPriority().iterator(); while (priorityIt.hasNext()) { if (Objects.equals(cloudService.getId(), priorityIt.next().getServiceId())) { priorityIt.remove(); } } if (intPreference.getPriority().isEmpty()) { intPrefIt.remove(); } } if (extPreference.getPreferences().isEmpty()) { extPrefIt.remove(); } } } providersToDiscard.clear(); servicesToDiscard.clear(); }