List of usage examples for org.apache.commons.lang3.tuple ImmutableTriple ImmutableTriple
public ImmutableTriple(final L left, final M middle, final R right)
From source file:org.openecomp.sdc.be.model.cache.ComponentCache.java
/** * * get full components from cassandra. On each component apply filter * function in order to remove unused members * * @param components// w w w.j a v a 2 s . c o m * @param filterFieldsFunc * @return <found components, found dirty components, not found components * list> or Error */ public Either<ImmutableTriple<List<Component>, List<Component>, Set<String>>, ActionStatus> getComponents( Set<String> components, Function<List<Component>, List<Component>> filterFieldsFunc) { if (false == isEnabled()) { logger.debug("Component Cache is disabled"); return Either.right(ActionStatus.NOT_ALLOWED); } Either<ImmutableTriple<List<Component>, List<Component>, Set<String>>, ActionStatus> componentsFull = getComponentsFull( components); if (componentsFull.isRight()) { return Either.right(componentsFull.right().value()); } ImmutableTriple<List<Component>, List<Component>, Set<String>> immutableTriple = componentsFull.left() .value(); List<Component> foundResources = immutableTriple.left; List<Component> foundDirtyResources = immutableTriple.middle; Set<String> notFoundResources = immutableTriple.right; List<Component> filterdFoundResources = filterFieldsFunc.apply(foundResources); List<Component> filterdFoundDirtyResources = filterFieldsFunc.apply(foundDirtyResources); ImmutableTriple<List<Component>, List<Component>, Set<String>> result = new ImmutableTriple<List<Component>, List<Component>, Set<String>>( filterdFoundResources, filterdFoundDirtyResources, notFoundResources); return Either.left(result); }
From source file:org.openecomp.sdc.be.model.cache.ComponentCache.java
/** * get components from cache of a given list ou unique ids. * * for each component data from cassandra, unzip the data if needed and * deserialize the unzipped data to java object(Component). * * @param filteredResources/* w w w . j a va 2 s .c o m*/ * @return ImmutableTripple or ActionStatus. | |-- components |-- dirty * components - components with dirty flag = true. |-- set of non * cached components * */ private Either<ImmutableTriple<List<Component>, List<Component>, Set<String>>, ActionStatus> getComponentsFull( Set<String> filteredResources) { if (false == isEnabled()) { logger.debug("Component Cache is disabled"); return Either.right(ActionStatus.NOT_ALLOWED); } List<Component> foundResources = new LinkedList<>(); List<Component> foundDirtyResources = new LinkedList<>(); Set<String> notFoundResources = new HashSet<>(); ImmutableTriple<List<Component>, List<Component>, Set<String>> result = new ImmutableTriple<List<Component>, List<Component>, Set<String>>( foundResources, foundDirtyResources, notFoundResources); long cassandraFetchStart = System.currentTimeMillis(); List<String> uidsList = new ArrayList<>(); uidsList.addAll(filteredResources); Either<List<ComponentCacheData>, ActionStatus> componentsFromCache = componentCassandraDao .getComponents(uidsList); long cassandraFetchEnd = System.currentTimeMillis(); logger.debug("Fetch time from cassandara of all components took {} ms", (cassandraFetchEnd - cassandraFetchStart)); if (componentsFromCache.isRight()) { BeEcompErrorManager.getInstance().logInternalFlowError("FetchFromCache", "Failed to fetch components from cache", ErrorSeverity.ERROR); return Either.right(componentsFromCache.right().value()); } List<ComponentCacheData> list = componentsFromCache.left().value(); logger.debug("Number of components fetched from cassandra is {}", (list == null ? 0 : list.size())); if (list != null && false == list.isEmpty()) { List<ComponentCacheData> filteredData = list.stream().filter(p -> filteredResources.contains(p.getId())) .collect(Collectors.toList()); logger.debug("Number of components filterd is {}", filteredData == null ? 0 : filteredData.size()); if (filteredData != null) { long desStart = System.currentTimeMillis(); for (ComponentCacheData componentCacheData : filteredData) { logger.debug("Process uid {} from cache", componentCacheData.getId()); String compUid = componentCacheData.getId(); Either<? extends Component, Boolean> deserializeExt = convertComponentCacheToComponent( componentCacheData); if (deserializeExt.isLeft()) { Component component = deserializeExt.left().value(); if (false == componentCacheData.getIsDirty()) { foundResources.add(component); } else { foundDirtyResources.add(component); } } else { notFoundResources.add(compUid); } } long desEnd = System.currentTimeMillis(); logger.debug("Deserialization and unzip of {} components took {} ms", filteredData.size(), (desEnd - desStart)); } } List<String> foundResourcesUid = foundResources.stream().map(p -> p.getUniqueId()) .collect(Collectors.toList()); List<String> foundDirtyResourcesUid = foundDirtyResources.stream().map(p -> p.getUniqueId()) .collect(Collectors.toList()); logger.debug("Number of processed components from cache is {}", (foundResourcesUid.size() + foundDirtyResourcesUid.size())); Set<String> notCachedResources = filteredResources.stream() .filter(p -> false == foundResourcesUid.contains(p) && false == foundDirtyResourcesUid.contains(p)) .collect(Collectors.toSet()); notFoundResources.addAll(notCachedResources); if (logger.isDebugEnabled()) { logger.debug("Number of components fetched is {}", foundResources.size()); logger.debug("Number of components fetched dirty is {}", foundDirtyResources.size()); logger.debug("Number of components non cached is {}", notCachedResources.size()); } return Either.left(result); }
From source file:org.openecomp.sdc.be.model.operations.impl.ComponentOperation.java
public Either<Collection<ComponentMetadataData>, StorageOperationStatus> getLatestVersionNotAbstractComponentsMetadataOnly( boolean isAbstract, Boolean isHighest, ComponentTypeEnum componentTypeEnum, String internalComponentType) { try {/*from w w w.j a v a 2s. com*/ // Map<String, Object> hasPpropertiesToMatch = new HashMap<>(); // Map<String, Object> hasNotPpropertiesToMatch = new HashMap<>(); List<ImmutableTriple<QueryType, String, Object>> properties = new ArrayList<>(); if (componentTypeEnum.equals(ComponentTypeEnum.RESOURCE)) { // hasPpropertiesToMatch.put(GraphPropertiesDictionary.IS_ABSTRACT.getProperty(), // isAbstract); properties.add(new ImmutableTriple<>(QueryType.HAS, GraphPropertiesDictionary.IS_ABSTRACT.getProperty(), isAbstract)); if (internalComponentType != null) { switch (internalComponentType.toLowerCase()) { case "vf": properties.add(new ImmutableTriple<>(QueryType.HAS_NOT, GraphPropertiesDictionary.RESOURCE_TYPE.getProperty(), ResourceTypeEnum.VF.name())); properties.add(new ImmutableTriple<>(QueryType.HAS_NOT, GraphPropertiesDictionary.RESOURCE_TYPE.getProperty(), ResourceTypeEnum.VL.name())); // hasNotPpropertiesToMatch.put(GraphPropertiesDictionary.RESOURCE_TYPE.getProperty(), // ResourceTypeEnum.VF.name()); break; case "service": properties.add(new ImmutableTriple<>(QueryType.HAS_NOT, GraphPropertiesDictionary.RESOURCE_TYPE.getProperty(), ResourceTypeEnum.VFC.name())); properties.add(new ImmutableTriple<>(QueryType.HAS_NOT, GraphPropertiesDictionary.RESOURCE_TYPE.getProperty(), ResourceTypeEnum.VL.name())); // hasNotPpropertiesToMatch.put(GraphPropertiesDictionary.RESOURCE_TYPE.getProperty(), // ResourceTypeEnum.VFC.name()); break; case "vl": properties.add(new ImmutableTriple<>(QueryType.HAS, GraphPropertiesDictionary.RESOURCE_TYPE.getProperty(), ResourceTypeEnum.VL.name())); // hasPpropertiesToMatch.put(GraphPropertiesDictionary.RESOURCE_TYPE.getProperty(), // ResourceTypeEnum.VL.name()); break; default: break; } } } // hasNotPpropertiesToMatch.put(GraphPropertiesDictionary.STATE.getProperty(), // LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT.name()); properties.add(new ImmutableTriple<>(QueryType.HAS_NOT, GraphPropertiesDictionary.STATE.getProperty(), LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT.name())); // hasNotPpropertiesToMatch.put(GraphPropertiesDictionary.IS_DELETED.getProperty(), // true); properties.add(new ImmutableTriple<>(QueryType.HAS_NOT, GraphPropertiesDictionary.IS_DELETED.getProperty(), true)); // Either<List<ComponentMetadataData>, TitanOperationStatus> // resourceNodes = titanGenericDao.getByCriteria( // componentTypeEnum.getNodeType(), hasPpropertiesToMatch, // hasNotPpropertiesToMatch, // ComponentMetadataData.class); Either<List<ComponentMetadataData>, TitanOperationStatus> resourceNodes = titanGenericDao .getByCriteria(componentTypeEnum.getNodeType(), ComponentMetadataData.class, properties); if (resourceNodes.isRight()) { // in case of NOT_FOUND from Titan client return to UI empty // list if (resourceNodes.right().value().equals(TitanOperationStatus.NOT_FOUND)) { return Either.left(new ArrayList<>()); } else { return Either.right( DaoStatusConverter.convertTitanStatusToStorageStatus(resourceNodes.right().value())); } } else { List<ComponentMetadataData> resourceDataList = resourceNodes.left().value(); Collection<ComponentMetadataData> resCollection = resourceDataList; if (isHighest != null && isHighest) { Map<String, ComponentMetadataData> latestVersionListMap = findLatestVersion(resourceDataList); resCollection = latestVersionListMap.values(); } return Either.left(resCollection); } } finally { titanGenericDao.commit(); } }
From source file:org.openecomp.sdc.be.tosca.ToscaExportHandler.java
private void createDependency(Map<String, Component> componentCache, List<Map<String, Map<String, String>>> imports, List<Triple<String, String, Component>> dependecies, ComponentInstance ci) {/*from w ww . ja v a 2 s . com*/ Map<String, String> files = new HashMap<>(); Map<String, Map<String, String>> importsListMember = new HashMap<>(); Component componentRI = componentCache.get(ci.getComponentUid()); if (componentRI == null) { // all resource must be only once! Either<Resource, StorageOperationStatus> resource = resourceOperation.getResource(ci.getComponentUid(), true); if (resource.isRight()) { log.debug("Failed to fetch resource with id {} for instance {}"); } Resource fetchedComponent = resource.left().value(); componentCache.put(fetchedComponent.getUniqueId(), fetchedComponent); componentRI = fetchedComponent; Map<String, ArtifactDefinition> toscaArtifacts = componentRI.getToscaArtifacts(); ArtifactDefinition artifactDefinition = toscaArtifacts.get(ASSET_TOSCA_TEMPLATE); if (artifactDefinition != null) { String artifactName = artifactDefinition.getArtifactName(); files.put(IMPORTS_FILE_KEY, artifactName); importsListMember.put(ci.getComponentName(), files); dependecies.add(new ImmutableTriple<String, String, Component>(artifactName, artifactDefinition.getEsId(), fetchedComponent)); } } if (!importsListMember.isEmpty()) { imports.add(importsListMember); } }
From source file:org.openecomp.sdc.ci.tests.api.ComponentBaseTest.java
private void cleanComponents() throws Exception { // Components to delete List<String> vfResourcesToDelete = new ArrayList<String>(); List<String> nonVfResourcesToDelete = new ArrayList<String>(); List<String> servicesToDelete = new ArrayList<String>(); List<String> productsToDelete = new ArrayList<String>(); // Categories to delete List<ImmutableTriple<String, String, String>> productGroupingsToDelete = new ArrayList<>(); List<ImmutablePair<String, String>> productSubsToDelete = new ArrayList<>(); List<ImmutablePair<String, String>> resourceSubsToDelete = new ArrayList<>(); List<String> productCategoriesToDelete = new ArrayList<>(); List<String> resourceCategoriesToDelete = new ArrayList<String>(); List<String> serviceCategoriesToDelete = new ArrayList<String>(); List<String> resourcesNotToDelete = config.getResourcesNotToDelete(); List<String> resourceCategoriesNotToDelete = config.getResourceCategoriesNotToDelete(); List<String> serviceCategoriesNotToDelete = config.getServiceCategoriesNotToDelete(); TitanGraphQuery<? extends TitanGraphQuery> query = titanGraph.query(); query = query.has(GraphPropertiesDictionary.LABEL.getProperty(), NodeTypeEnum.Resource.getName()); Iterable<TitanVertex> vertices = query.vertices(); // Iterable<TitanVertex> vertices = titanGraph.query().has(GraphPropertiesDictionary.LABEL.getProperty(), NodeTypeEnum.Resource.getName()).vertices(); if (vertices != null) { Iterator<TitanVertex> iter = vertices.iterator(); while (iter.hasNext()) { Vertex vertex = iter.next(); Boolean isAbstract = vertex.value(GraphPropertiesDictionary.IS_ABSTRACT.getProperty()); // if (!isAbstract) { String name = vertex.value(GraphPropertiesDictionary.NAME.getProperty()); String version = vertex.value(GraphPropertiesDictionary.VERSION.getProperty()); if ((resourcesNotToDelete != null && !resourcesNotToDelete.contains(name)) || (version != null && !version.equals("1.0"))) { String id = vertex.value(GraphPropertiesDictionary.UNIQUE_ID.getProperty()); String resourceType = vertex.value(GraphPropertiesDictionary.RESOURCE_TYPE.getProperty()); // if (name.startsWith("ci")) { if (resourceType.equals(ResourceTypeEnum.VF.name())) { vfResourcesToDelete.add(id); } else { nonVfResourcesToDelete.add(id); }//from www . j av a2 s .c o m // } } else if ((resourcesNotToDelete != null && !resourcesNotToDelete.contains(name)) || (version != null && version.equals("1.0"))) { if ((boolean) vertex .value(GraphPropertiesDictionary.IS_HIGHEST_VERSION.getProperty()) == false) { vertex.property(GraphPropertiesDictionary.IS_HIGHEST_VERSION.getProperty(), true); } } // } } } vertices = titanGraph.query() .has(GraphPropertiesDictionary.LABEL.getProperty(), NodeTypeEnum.Service.getName()).vertices(); if (vertices != null) { Iterator<TitanVertex> iter = vertices.iterator(); while (iter.hasNext()) { Vertex vertex = iter.next(); String id = vertex.value(GraphPropertiesDictionary.UNIQUE_ID.getProperty()); String name = vertex.value(GraphPropertiesDictionary.NAME.getProperty()); // if (name.startsWith("ci")){ servicesToDelete.add(id); // } } } vertices = titanGraph.query() .has(GraphPropertiesDictionary.LABEL.getProperty(), NodeTypeEnum.Product.getName()).vertices(); if (vertices != null) { Iterator<TitanVertex> iter = vertices.iterator(); while (iter.hasNext()) { Vertex vertex = iter.next(); String id = vertex.value(GraphPropertiesDictionary.UNIQUE_ID.getProperty()); String name = vertex.value(GraphPropertiesDictionary.NAME.getProperty()); //if (name.startsWith("ci")) { productsToDelete.add(id); //} } } // Getting categories vertices = titanGraph.query() .has(GraphPropertiesDictionary.LABEL.getProperty(), NodeTypeEnum.ResourceNewCategory.getName()) .vertices(); if (vertices != null) { Iterator<TitanVertex> iter = vertices.iterator(); while (iter.hasNext()) { Vertex category = iter.next(); String name = category.value(GraphPropertiesDictionary.NAME.getProperty()); if (!resourceCategoriesNotToDelete.contains(name)) { String catId = category.value(GraphPropertiesDictionary.UNIQUE_ID.getProperty()); resourceCategoriesToDelete.add(catId); Iterator<Vertex> subs = category.vertices(Direction.OUT, GraphEdgeLabels.SUB_CATEGORY.getProperty()); while (subs.hasNext()) { Vertex sub = subs.next(); String subCatId = sub.value(GraphPropertiesDictionary.UNIQUE_ID.getProperty()); resourceSubsToDelete.add(new ImmutablePair<String, String>(catId, subCatId)); } } } } vertices = titanGraph.query() .has(GraphPropertiesDictionary.LABEL.getProperty(), NodeTypeEnum.ServiceNewCategory.getName()) .vertices(); if (vertices != null) { Iterator<TitanVertex> iter = vertices.iterator(); while (iter.hasNext()) { Vertex category = iter.next(); String name = category.value(GraphPropertiesDictionary.NAME.getProperty()); if (!serviceCategoriesNotToDelete.contains(name)) { String id = category.value(GraphPropertiesDictionary.UNIQUE_ID.getProperty()); serviceCategoriesToDelete.add(id); } } } vertices = titanGraph.query() .has(GraphPropertiesDictionary.LABEL.getProperty(), NodeTypeEnum.ProductCategory.getName()) .vertices(); if (vertices != null) { Iterator<TitanVertex> iter = vertices.iterator(); while (iter.hasNext()) { Vertex category = iter.next(); String catId = category.value(GraphPropertiesDictionary.UNIQUE_ID.getProperty()); productCategoriesToDelete.add(catId); Iterator<Vertex> subs = category.vertices(Direction.OUT, GraphEdgeLabels.SUB_CATEGORY.getProperty()); while (subs.hasNext()) { Vertex sub = subs.next(); String subCatId = sub.value(GraphPropertiesDictionary.UNIQUE_ID.getProperty()); productSubsToDelete.add(new ImmutablePair<String, String>(catId, subCatId)); Iterator<Vertex> groupings = sub.vertices(Direction.OUT, GraphEdgeLabels.GROUPING.getProperty()); while (groupings.hasNext()) { Vertex grouping = groupings.next(); String groupId = grouping.value(GraphPropertiesDictionary.UNIQUE_ID.getProperty()); productGroupingsToDelete .add(new ImmutableTriple<String, String, String>(catId, subCatId, groupId)); } } } } titanGraph.tx().commit(); String adminId = UserRoleEnum.ADMIN.getUserId(); String productStrategistId = UserRoleEnum.PRODUCT_STRATEGIST1.getUserId(); // Component delete for (String id : productsToDelete) { RestResponse deleteProduct = ProductRestUtils.deleteProduct(id, productStrategistId); } for (String id : servicesToDelete) { RestResponse deleteServiceById = ServiceRestUtils.deleteServiceById(id, adminId); } for (String id : vfResourcesToDelete) { RestResponse deleteResource = ResourceRestUtils.deleteResource(id, adminId); } for (String id : nonVfResourcesToDelete) { RestResponse deleteResource = ResourceRestUtils.deleteResource(id, adminId); } // Categories delete - product String componentType = BaseRestUtils.PRODUCT_COMPONENT_TYPE; for (ImmutableTriple<String, String, String> triple : productGroupingsToDelete) { CategoryRestUtils.deleteGrouping(triple.getRight(), triple.getMiddle(), triple.getLeft(), productStrategistId, componentType); } for (ImmutablePair<String, String> pair : productSubsToDelete) { CategoryRestUtils.deleteSubCategory(pair.getRight(), pair.getLeft(), productStrategistId, componentType); } for (String id : productCategoriesToDelete) { CategoryRestUtils.deleteCategory(id, productStrategistId, componentType); } // Categories delete - resource componentType = BaseRestUtils.RESOURCE_COMPONENT_TYPE; for (ImmutablePair<String, String> pair : resourceSubsToDelete) { CategoryRestUtils.deleteSubCategory(pair.getRight(), pair.getLeft(), adminId, componentType); } for (String id : resourceCategoriesToDelete) { CategoryRestUtils.deleteCategory(id, adminId, componentType); } // Categories delete - resource componentType = BaseRestUtils.SERVICE_COMPONENT_TYPE; for (String id : serviceCategoriesToDelete) { CategoryRestUtils.deleteCategory(id, adminId, componentType); } }
From source file:org.protelis.lang.util.ReflectionUtils.java
/** * @param clazz/*from www. j a v a 2 s.c o m*/ * the class where to search for suitable methods * @param methodName * the method to be invoked * @param args * the arguments for the method. If a {@link Field} is passed, * then the expected type of the field is used. * @return the result of the invocation, or an {@link IllegalStateException} * if something goes wrong. */ public static Method searchBestMethod(final Class<?> clazz, final String methodName, final List<Object> args) { final List<Class<?>> originalClasses = new ArrayList<>(args.size()); final List<Class<?>> fieldedClasses = new ArrayList<>(args.size()); boolean atLeastOneField = false; for (final Object arg : args) { final Class<?> argClass = arg.getClass(); if (arg instanceof Field) { fieldedClasses.add(((Field) arg).getExpectedType()); atLeastOneField = true; } else { fieldedClasses.add(argClass); } originalClasses.add(argClass); } try { return METHOD_CACHE.get(new ImmutableTriple<>(clazz, methodName, originalClasses)); } catch (UncheckedExecutionException | ExecutionException outerException) { if (atLeastOneField) { try { return METHOD_CACHE.get(new ImmutableTriple<>(clazz, methodName, fieldedClasses)); } catch (ExecutionException e) { throw new UnsupportedOperationException("No" + methodName + originalClasses // NOPMD: false positive + " nor " + methodName + fieldedClasses + " exist in " + clazz + ".\nYou tried to invoke it with arguments " + args, e); } } throw new UnsupportedOperationException(methodName + originalClasses + " does not exist in " + clazz + ".\nYou tried to invoke it with arguments " + args, outerException); } }
From source file:org.shaman.terrain.sketch.Graph.java
@Override public Iterator<Triple<Integer, Integer, Float>> iterator() { return new Iterator<Triple<Integer, Integer, Float>>() { Triple<Integer, Integer, Float> current = null; private int u = 0; private int v = 0; @Override/* w w w .j a va2s . c o m*/ public boolean hasNext() { while (true) { if (u == graph.size()) { return false; } ArrayList<MutablePair<Integer, Float>> n = graph.get(u); if (v == n.size()) { v = 0; u++; continue; } MutablePair<Integer, Float> p = n.get(v); v++; if (p.getLeft() > u) { current = new ImmutableTriple<>(u, p.getLeft(), p.getRight()); return true; } } } @Override public Triple<Integer, Integer, Float> next() { return current; } @Override public void remove() { throw new UnsupportedOperationException("Not supported yet."); } }; }
From source file:org.tango.server.attribute.log.AttributeAppender.java
@Override protected void append(final ILoggingEvent eventObject) { while (log.size() >= depth) { log.poll();//w w w .j a v a2s. co m } final Triple<String, String, String> event = new ImmutableTriple<String, String, String>( dateFormat.format(new Date(eventObject.getTimeStamp())), eventObject.getLevel().toString(), eventObject.getFormattedMessage()); log.offer(event); }
From source file:org.verdictdb.connection.CachedDbmsConnection.java
@Override public List<Pair<String, String>> getColumns(String schema, String table) throws VerdictDBDbmsException { Triple<String, String, String> key = new ImmutableTriple<>("", schema, table); if (columnsCache.containsKey(key) && !columnsCache.get(key).isEmpty()) { return columnsCache.get(key); }//from w w w.j a v a 2 s.com synchronized (this) { List<Pair<String, String>> columns = new ArrayList<>(); columnsCache.put(key, originalConn.getColumns(schema, table)); columns.addAll(columnsCache.get(key)); return columns; } }
From source file:org.verdictdb.connection.CachedDbmsConnection.java
@Override public List<Pair<String, String>> getColumns(String catalog, String schema, String table) throws VerdictDBDbmsException { Triple<String, String, String> key = new ImmutableTriple<>(catalog, schema, table); if (columnsCache.containsKey(key) && !columnsCache.get(key).isEmpty()) { return columnsCache.get(key); }/*from ww w .j ava 2s . c om*/ synchronized (this) { List<Pair<String, String>> columns = new ArrayList<>(); columnsCache.put(key, originalConn.getColumns(catalog, schema, table)); columns.addAll(columnsCache.get(key)); return columns; } }