List of usage examples for org.apache.commons.lang3.tuple ImmutablePair getRight
@Override
public R getRight()
From source file:org.openecomp.sdc.be.model.operations.impl.ComponentInstanceOperation.java
public Either<List<CapabilityDefinition>, TitanOperationStatus> updateCapDefPropertyValues( ComponentInstance componentInstance, List<CapabilityDefinition> capabilityDefList) { String componentInstanceId = componentInstance.getUniqueId(); log.debug("Before updating property values of capabilities of component istance {}.", componentInstanceId); TitanOperationStatus error = null;/*from www .ja va 2s . c o m*/ NodeTypeEnum nodeType = NodeTypeEnum .getByNameIgnoreCase(componentInstance.getOriginType().getInstanceType().trim()); log.debug("Before getting all capability instances of component istance {}.", componentInstanceId); Either<List<ImmutablePair<CapabilityInstData, GraphEdge>>, TitanOperationStatus> getCapabilityInstancesRes = titanGenericDao .getChildrenNodes(UniqueIdBuilder.getKeyByNodeType(nodeType), componentInstanceId, GraphEdgeLabels.CAPABILITY_INST, NodeTypeEnum.CapabilityInst, CapabilityInstData.class); if (getCapabilityInstancesRes.isRight() && !getCapabilityInstancesRes.right().value().equals(TitanOperationStatus.NOT_FOUND)) { error = getCapabilityInstancesRes.right().value(); log.debug("Failed to retrieve capability Instances of resource instance {}. Status is {}", componentInstance.getName(), error); } log.debug("After getting all capability instances of component istance {}. Status is {}", componentInstanceId, error); Map<String, Map<String, PropertyValueData>> overridedCapabilitiesHM = new HashMap<>(); if (getCapabilityInstancesRes.isLeft()) { List<ImmutablePair<CapabilityInstData, GraphEdge>> capabilityInstDataPair = getCapabilityInstancesRes .left().value(); for (ImmutablePair<CapabilityInstData, GraphEdge> curCapabilityPair : capabilityInstDataPair) { CapabilityInstData curCapabilityInst = curCapabilityPair.getLeft(); String curCapInstUid = curCapabilityInst.getUniqueId(); log.debug("Before getting all property values of capability instance {} of component istance {}.", curCapInstUid, componentInstanceId); Either<List<ImmutablePair<PropertyValueData, GraphEdge>>, TitanOperationStatus> getOverridedPropertyValuesRes = titanGenericDao .getChildrenNodes( UniqueIdBuilder .getKeyByNodeType(NodeTypeEnum.getByName(curCapabilityInst.getLabel())), curCapInstUid, GraphEdgeLabels.PROPERTY_VALUE, NodeTypeEnum.PropertyValue, PropertyValueData.class); if (getOverridedPropertyValuesRes.isRight()) { error = getOverridedPropertyValuesRes.right().value(); log.debug("Failed to retrieve property values of capability instance {}. Status is {}", curCapInstUid, error); } log.debug( "After getting all property values of capability instance {} of component istance {}. Status is {}", curCapInstUid, componentInstanceId, error); Map<String, PropertyValueData> overridedPropertyValuesHM = new HashMap<>(); List<ImmutablePair<PropertyValueData, GraphEdge>> overridedPropertyValues = getOverridedPropertyValuesRes .left().value(); for (ImmutablePair<PropertyValueData, GraphEdge> curPropertyValuePair : overridedPropertyValues) { PropertyValueData curPropertyValue = curPropertyValuePair.getLeft(); String propertyValueUid = curPropertyValue.getUniqueId(); log.debug( "Before getting property related to property value {} of capability instance {} of component istance {}.", propertyValueUid, curCapInstUid, componentInstanceId); Either<ImmutablePair<PropertyData, GraphEdge>, TitanOperationStatus> getPropertyDataRes = titanGenericDao .getChild( UniqueIdBuilder.getKeyByNodeType( NodeTypeEnum.getByName(curPropertyValue.getLabel())), propertyValueUid, GraphEdgeLabels.PROPERTY_IMPL, NodeTypeEnum.Property, PropertyData.class); if (getPropertyDataRes.isRight()) { error = getOverridedPropertyValuesRes.right().value(); log.debug("Failed to retrieve property of property value {} Status is {}", propertyValueUid, error); } if (log.isDebugEnabled()) { log.debug( "After getting property related to property value {} of capability instance {} of component istance {}. Status is {}", propertyValueUid, curCapInstUid, componentInstanceId, error); } PropertyData propertyData = getPropertyDataRes.left().value().getLeft(); overridedPropertyValuesHM.put((String) propertyData.getUniqueId(), curPropertyValue); } overridedCapabilitiesHM.put( (String) curCapabilityPair.getRight().getProperties() .get(GraphPropertiesDictionary.CAPABILITY_ID.getProperty()), overridedPropertyValuesHM); } } if (error == null && !overridedCapabilitiesHM.isEmpty()) { updateCapabilityPropertyValues(componentInstance.getCapabilities(), capabilityDefList, overridedCapabilitiesHM); } log.debug("After updating property values of capabilities of component istance {}. Status is {}", componentInstanceId, error); if (error == null) { return Either.left(capabilityDefList); } return Either.right(error); }
From source file:org.openecomp.sdc.be.model.operations.impl.ComponentOperation.java
public Either<ImmutablePair<List<Component>, Set<String>>, ActionStatus> getComponentsFromCacheForCatalog( Map<String, Long> components, ComponentTypeEnum componentType) { Either<ImmutablePair<List<Component>, Set<String>>, ActionStatus> componentsForCatalog = componentCache .getComponentsForCatalog(components, componentType); if (componentsForCatalog.isLeft()) { ImmutablePair<List<Component>, Set<String>> immutablePair = componentsForCatalog.left().value(); List<Component> foundComponents = immutablePair.getLeft(); if (foundComponents != null) { // foundComponents.forEach(p -> result.add((Resource)p)); log.debug("The number of {}s added to catalog from cache is {}", componentType.name().toLowerCase(), foundComponents.size()); }/*from w ww .j a v a 2s . c o m*/ Set<String> leftComponents = immutablePair.getRight(); int numberNonCached = leftComponents == null ? 0 : leftComponents.size(); log.debug("The number of left {}s for catalog is {}", componentType.name().toLowerCase(), numberNonCached); ImmutablePair<List<Component>, Set<String>> result = new ImmutablePair<List<Component>, Set<String>>( foundComponents, leftComponents); return Either.left(result); } return Either.right(componentsForCatalog.right().value()); }
From source file:org.openecomp.sdc.be.model.operations.impl.InterfaceLifecycleOperation.java
private Either<Operation, StorageOperationStatus> updateExistingOperation(String resourceId, Operation operation, String interfaceName, String operationName, Either<List<ImmutablePair<InterfaceData, GraphEdge>>, TitanOperationStatus> childrenNodes) { Operation newOperation = null; StorageOperationStatus storageOperationStatus = StorageOperationStatus.GENERAL_ERROR; for (ImmutablePair<InterfaceData, GraphEdge> interfaceDataNode : childrenNodes.left().value()) { GraphEdge interfaceEdge = interfaceDataNode.getRight(); Map<String, Object> interfaceEdgeProp = interfaceEdge.getProperties(); InterfaceData interfaceData = interfaceDataNode.getKey(); if (interfaceEdgeProp.get(GraphPropertiesDictionary.NAME.getProperty()).equals(interfaceName)) { Either<List<ImmutablePair<OperationData, GraphEdge>>, TitanOperationStatus> operationRes = titanGenericDao .getChildrenNodes(GraphPropertiesDictionary.UNIQUE_ID.getProperty(), (String) interfaceDataNode.getLeft().getUniqueId(), GraphEdgeLabels.INTERFACE_OPERATION, NodeTypeEnum.InterfaceOperation, OperationData.class); if (operationRes.isRight()) { log.error("Failed to find operation {} on interface {}", operationName, interfaceName); return Either.right( DaoStatusConverter.convertTitanStatusToStorageStatus(operationRes.right().value())); } else { List<ImmutablePair<OperationData, GraphEdge>> operations = operationRes.left().value(); for (ImmutablePair<OperationData, GraphEdge> operationPairEdge : operations) { GraphEdge opEdge = operationPairEdge.getRight(); OperationData opData = operationPairEdge.getLeft(); Map<String, Object> opEdgeProp = opEdge.getProperties(); if (opEdgeProp.get(GraphPropertiesDictionary.NAME.getProperty()).equals(operationName)) { ArtifactDefinition artifact = operation.getImplementation(); Either<ImmutablePair<ArtifactData, GraphEdge>, TitanOperationStatus> artifactRes = titanGenericDao .getChild(GraphPropertiesDictionary.UNIQUE_ID.getProperty(), (String) opData.getUniqueId(), GraphEdgeLabels.ARTIFACT_REF, NodeTypeEnum.ArtifactRef, ArtifactData.class); Either<ArtifactDefinition, StorageOperationStatus> artStatus; if (artifactRes.isRight()) { artStatus = artifactOperation.addArifactToComponent(artifact, (String) operationPairEdge.getLeft().getUniqueId(), NodeTypeEnum.InterfaceOperation, true, true); } else { artStatus = artifactOperation.updateArifactOnResource(artifact, (String) operationPairEdge.getLeft().getUniqueId(), (String) artifactRes.left().value().getLeft().getUniqueId(), NodeTypeEnum.InterfaceOperation, true); }/*from w w w. java 2 s. c o m*/ if (artStatus.isRight()) { titanGenericDao.rollback(); log.error("Failed to add artifact {}", operationName, interfaceName); return Either.right(artStatus.right().value()); } else { newOperation = this.convertOperationDataToOperation(opData); newOperation.setImplementation(artStatus.left().value()); } } } if (newOperation == null) { Either<InterfaceData, TitanOperationStatus> parentInterfaceStatus = findInterfaceOnParentNode( resourceId, interfaceName); if (parentInterfaceStatus.isRight()) { log.debug("Interface {} not exist", interfaceName); return Either.right(DaoStatusConverter .convertTitanStatusToStorageStatus(parentInterfaceStatus.right().value())); } InterfaceData parentInterfaceData = parentInterfaceStatus.left().value(); Either<List<ImmutablePair<OperationData, GraphEdge>>, TitanOperationStatus> opRes = titanGenericDao .getChildrenNodes(GraphPropertiesDictionary.UNIQUE_ID.getProperty(), (String) parentInterfaceData.getUniqueId(), GraphEdgeLabels.INTERFACE_OPERATION, NodeTypeEnum.InterfaceOperation, OperationData.class); if (opRes.isRight()) { log.error("Failed to find operation {} on interface", operationName, interfaceName); return Either.right(DaoStatusConverter .convertTitanStatusToStorageStatus(operationRes.right().value())); } else { List<ImmutablePair<OperationData, GraphEdge>> parentOperations = opRes.left().value(); for (ImmutablePair<OperationData, GraphEdge> operationPairEdge : parentOperations) { GraphEdge opEdge = operationPairEdge.getRight(); OperationData opData = operationPairEdge.getLeft(); Map<String, Object> opEdgeProp = opEdge.getProperties(); if (opEdgeProp.get(GraphPropertiesDictionary.NAME.getProperty()) .equals(operationName)) { return copyAndCreateNewOperation(operation, interfaceName, operationName, null, interfaceData, operationRes, opData); } } } } } } else { // not found storageOperationStatus = StorageOperationStatus.ARTIFACT_NOT_FOUND; } } if (newOperation == null) return Either.right(storageOperationStatus); else return Either.left(newOperation); }
From source file:org.openecomp.sdc.be.model.operations.impl.InterfaceLifecycleOperation.java
private Either<Operation, StorageOperationStatus> updateOperationFromParentNode(Operation operation, String resourceId, String interfaceName, String operationName) { // Operation newOperation = null; ResourceMetadataData resourceData = new ResourceMetadataData(); resourceData.getMetadataDataDefinition().setUniqueId(resourceId); Either<InterfaceData, TitanOperationStatus> parentInterfaceStatus = findInterfaceOnParentNode(resourceId, interfaceName);//from w ww .ja va 2 s .c o m if (parentInterfaceStatus.isRight()) { log.debug("Interface {} not exist", interfaceName); return Either.right( DaoStatusConverter.convertTitanStatusToStorageStatus(parentInterfaceStatus.right().value())); } InterfaceData interfaceData = parentInterfaceStatus.left().value(); InterfaceDataDefinition intDataDefinition = interfaceData.getInterfaceDataDefinition(); InterfaceDataDefinition newInterfaceInfo = new InterfaceDataDefinition(intDataDefinition); String interfaceNameSplitted = getShortInterfaceName(intDataDefinition); newInterfaceInfo.setUniqueId(UniqueIdBuilder.buildPropertyUniqueId(resourceId, interfaceNameSplitted)); InterfaceData updatedInterfaceData = new InterfaceData(newInterfaceInfo); Either<InterfaceData, TitanOperationStatus> createStatus = createInterfaceNodeAndRelation(interfaceName, resourceId, updatedInterfaceData, resourceData); if (createStatus.isRight()) { log.debug("failed to create interface node {} on resource {}", interfaceName, resourceId); return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(createStatus.right().value())); } InterfaceData newInterfaceNode = createStatus.left().value(); Either<GraphRelation, TitanOperationStatus> createRelResult = titanGenericDao .createRelation(newInterfaceNode, interfaceData, GraphEdgeLabels.DERIVED_FROM, null); if (createRelResult.isRight()) { TitanOperationStatus operationStatus = createRelResult.right().value(); log.error("Failed to associate interface {} to interface {} in graph. Status is {}", interfaceData.getUniqueId(), newInterfaceNode.getUniqueId(), operationStatus); return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(operationStatus)); } Either<List<ImmutablePair<OperationData, GraphEdge>>, TitanOperationStatus> operationRes = titanGenericDao .getChildrenNodes(GraphPropertiesDictionary.UNIQUE_ID.getProperty(), (String) interfaceData.getUniqueId(), GraphEdgeLabels.INTERFACE_OPERATION, NodeTypeEnum.InterfaceOperation, OperationData.class); if (operationRes.isRight()) { log.error("Failed to find operation {} on interface {}", operationName, interfaceName); return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(operationRes.right().value())); } else { List<ImmutablePair<OperationData, GraphEdge>> operations = operationRes.left().value(); for (ImmutablePair<OperationData, GraphEdge> operationPairEdge : operations) { GraphEdge opEdge = operationPairEdge.getRight(); OperationData opData = operationPairEdge.getLeft(); Map<String, Object> opEdgeProp = opEdge.getProperties(); if (opEdgeProp.get(GraphPropertiesDictionary.NAME.getProperty()).equals(operationName)) { return copyAndCreateNewOperation(operation, interfaceName, operationName, null, // changed // from // newOperation newInterfaceNode, operationRes, opData); } } } // if(newOperation == null) return Either.right(StorageOperationStatus.GENERAL_ERROR); // else // return Either.left(newOperation); }
From source file:org.openecomp.sdc.be.model.operations.impl.InterfaceLifecycleOperation.java
private Either<InterfaceData, TitanOperationStatus> findInterfaceOnParentNode(String resourceId, String interfaceName) {// ww w . j a va 2 s . c om Either<ImmutablePair<ResourceMetadataData, GraphEdge>, TitanOperationStatus> parentRes = titanGenericDao .getChild(GraphPropertiesDictionary.UNIQUE_ID.getProperty(), resourceId, GraphEdgeLabels.DERIVED_FROM, NodeTypeEnum.Resource, ResourceMetadataData.class); if (parentRes.isRight()) { log.debug("interface {} not found", interfaceName); return Either.right(parentRes.right().value()); } ImmutablePair<ResourceMetadataData, GraphEdge> parenNode = parentRes.left().value(); Either<List<ImmutablePair<InterfaceData, GraphEdge>>, TitanOperationStatus> childrenNodes = titanGenericDao .getChildrenNodes(GraphPropertiesDictionary.UNIQUE_ID.getProperty(), parenNode.getKey().getMetadataDataDefinition().getUniqueId(), GraphEdgeLabels.INTERFACE, NodeTypeEnum.Interface, InterfaceData.class); if (childrenNodes.isRight()) { return findInterfaceOnParentNode(parenNode.getKey().getMetadataDataDefinition().getUniqueId(), interfaceName); } else { for (ImmutablePair<InterfaceData, GraphEdge> interfaceDataNode : childrenNodes.left().value()) { GraphEdge interfaceEdge = interfaceDataNode.getRight(); Map<String, Object> interfaceEdgeProp = interfaceEdge.getProperties(); if (interfaceEdgeProp.get(GraphPropertiesDictionary.NAME.getProperty()).equals(interfaceName)) { return Either.left(interfaceDataNode.getKey()); } } return findInterfaceOnParentNode(parenNode.getKey().getMetadataDataDefinition().getUniqueId(), interfaceName); } }
From source file:org.openecomp.sdc.be.model.operations.impl.InterfaceLifecycleOperation.java
private Either<Operation, TitanOperationStatus> removeOperationOnGraph(String resourceId, String interfaceName, String operationId) {//from w w w . ja v a2 s.c o m log.debug("Before deleting operation from graph {}", operationId); Either<List<ImmutablePair<InterfaceData, GraphEdge>>, TitanOperationStatus> childrenNodes = titanGenericDao .getChildrenNodes(GraphPropertiesDictionary.UNIQUE_ID.getProperty(), resourceId, GraphEdgeLabels.INTERFACE, NodeTypeEnum.Interface, InterfaceData.class); if (childrenNodes.isRight()) { log.debug("Not found interface {}", interfaceName); return Either.right(childrenNodes.right().value()); } OperationData opData = null; for (ImmutablePair<InterfaceData, GraphEdge> interfaceDataNode : childrenNodes.left().value()) { GraphEdge interfaceEdge = interfaceDataNode.getRight(); Map<String, Object> interfaceEdgeProp = interfaceEdge.getProperties(); String interfaceSplitedName = splitType(interfaceName); if (interfaceEdgeProp.get(GraphPropertiesDictionary.NAME.getProperty()).equals(interfaceSplitedName)) { Either<List<ImmutablePair<OperationData, GraphEdge>>, TitanOperationStatus> operationRes = titanGenericDao .getChildrenNodes(GraphPropertiesDictionary.UNIQUE_ID.getProperty(), (String) interfaceDataNode.getLeft().getUniqueId(), GraphEdgeLabels.INTERFACE_OPERATION, NodeTypeEnum.InterfaceOperation, OperationData.class); if (operationRes.isRight()) { log.error("Failed to find operation {}", operationId, interfaceName); return Either.right(operationRes.right().value()); } List<ImmutablePair<OperationData, GraphEdge>> operations = operationRes.left().value(); for (ImmutablePair<OperationData, GraphEdge> operationPairEdge : operations) { opData = operationPairEdge.getLeft(); if (opData.getUniqueId().equals(operationId)) { Either<ImmutablePair<ArtifactData, GraphEdge>, TitanOperationStatus> artifactRes = titanGenericDao .getChild(GraphPropertiesDictionary.UNIQUE_ID.getProperty(), (String) operationPairEdge.getLeft().getUniqueId(), GraphEdgeLabels.ARTIFACT_REF, NodeTypeEnum.ArtifactRef, ArtifactData.class); Either<ArtifactDefinition, StorageOperationStatus> arStatus = null; if (artifactRes.isLeft()) { ArtifactData arData = artifactRes.left().value().getKey(); arStatus = artifactOperation.removeArifactFromResource( (String) operationPairEdge.getLeft().getUniqueId(), (String) arData.getUniqueId(), NodeTypeEnum.InterfaceOperation, true, true); if (arStatus.isRight()) { log.debug("failed to delete artifact {}", arData.getUniqueId()); return Either.right(TitanOperationStatus.INVALID_ID); } } Either<OperationData, TitanOperationStatus> deleteOpStatus = titanGenericDao.deleteNode( UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.InterfaceOperation), opData.getUniqueId(), OperationData.class); if (deleteOpStatus.isRight()) { log.debug("failed to delete operation {}", opData.getUniqueId()); return Either.right(TitanOperationStatus.INVALID_ID); } opData = deleteOpStatus.left().value(); Operation operation = new Operation(opData.getOperationDataDefinition()); if (arStatus != null) { operation.setImplementation(arStatus.left().value()); } if (operations.size() <= 1) { Either<InterfaceData, TitanOperationStatus> deleteInterfaceStatus = titanGenericDao .deleteNode(UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.Interface), interfaceDataNode.left.getUniqueId(), InterfaceData.class); if (deleteInterfaceStatus.isRight()) { log.debug("failed to delete interface {}", interfaceDataNode.left.getUniqueId()); return Either.right(TitanOperationStatus.INVALID_ID); } } return Either.left(operation); } } } } log.debug("Not found operation {}", interfaceName); return Either.right(TitanOperationStatus.INVALID_ID); // } }
From source file:org.openecomp.sdc.be.model.operations.impl.ResourceOperation.java
private Either<List<Resource>, StorageOperationStatus> getResourceCatalogData(boolean inTransaction, Map<String, Object> otherToMatch) { long start = System.currentTimeMillis(); long startFetchAllStates = System.currentTimeMillis(); Map<String, Object> propertiesToMatchHigest = new HashMap<>(); propertiesToMatchHigest.put(GraphPropertiesDictionary.IS_HIGHEST_VERSION.getProperty(), true); propertiesToMatchHigest.put(GraphPropertiesDictionary.IS_ABSTRACT.getProperty(), false); Either<List<ResourceMetadataData>, TitanOperationStatus> allHighestStates = titanGenericDao .getByCriteria(NodeTypeEnum.Resource, propertiesToMatchHigest, ResourceMetadataData.class); if (allHighestStates.isRight() && allHighestStates.right().value() != TitanOperationStatus.NOT_FOUND) { return Either .right(DaoStatusConverter.convertTitanStatusToStorageStatus(allHighestStates.right().value())); }// w ww. j a v a 2 s .c o m if (allHighestStates.isRight()) { return Either.left(new ArrayList<>()); } List<ResourceMetadataData> list = allHighestStates.left().value(); List<ResourceMetadataData> certified = new ArrayList<>(); List<ResourceMetadataData> noncertified = new ArrayList<>(); for (ResourceMetadataData reData : list) { if (reData.getMetadataDataDefinition().getState().equals(LifecycleStateEnum.CERTIFIED.name())) { certified.add(reData); } else { noncertified.add(reData); } } long endFetchAll = System.currentTimeMillis(); log.debug("Fetch catalog resources all states: certified {}, noncertified {}", certified.size(), noncertified.size()); log.debug("Fetch catalog resources all states from graph took {} ms", endFetchAll - startFetchAllStates); try { List<ResourceMetadataData> notCertifiedHighest = noncertified; List<ResourceMetadataData> certifiedHighestList = certified; HashMap<String, String> VFNames = new HashMap<>(); HashMap<String, String> VFCNames = new HashMap<>(); for (ResourceMetadataData data : notCertifiedHighest) { String serviceName = data.getMetadataDataDefinition().getName(); if (((ResourceMetadataDataDefinition) data.getMetadataDataDefinition()).getResourceType() .equals(ResourceTypeEnum.VF)) { VFNames.put(serviceName, serviceName); } else { VFCNames.put(serviceName, serviceName); } } for (ResourceMetadataData data : certifiedHighestList) { String serviceName = data.getMetadataDataDefinition().getName(); if (((ResourceMetadataDataDefinition) data.getMetadataDataDefinition()).getResourceType() .equals(ResourceTypeEnum.VF)) { if (!VFNames.containsKey(serviceName)) { notCertifiedHighest.add(data); } } else { if (!VFCNames.containsKey(serviceName)) { notCertifiedHighest.add(data); } } } long endFetchAllFromGraph = System.currentTimeMillis(); log.debug("Fetch all catalog resources metadata from graph took {} ms", endFetchAllFromGraph - start); long startFetchAllFromCache = System.currentTimeMillis(); List<Resource> result = new ArrayList<>(); Map<String, Long> components = notCertifiedHighest.stream() .collect(Collectors.toMap(p -> p.getMetadataDataDefinition().getUniqueId(), p -> p.getMetadataDataDefinition().getLastUpdateDate())); Either<ImmutablePair<List<Component>, Set<String>>, ActionStatus> componentsForCatalog = componentCache .getComponentsForCatalog(components, ComponentTypeEnum.RESOURCE); if (componentsForCatalog.isLeft()) { ImmutablePair<List<Component>, Set<String>> immutablePair = componentsForCatalog.left().value(); List<Component> foundComponents = immutablePair.getLeft(); if (foundComponents != null) { foundComponents.forEach(p -> result.add((Resource) p)); log.debug("The number of resources added to catalog from cache is {}", foundComponents.size()); List<String> foundComponentsUid = foundComponents.stream().map(p -> p.getUniqueId()) .collect(Collectors.toList()); notCertifiedHighest = notCertifiedHighest.stream() .filter(p -> false == foundComponentsUid.contains(p.getUniqueId())) .collect(Collectors.toList()); } Set<String> nonCachedComponents = immutablePair.getRight(); int numberNonCached = nonCachedComponents == null ? 0 : nonCachedComponents.size(); log.debug("The number of left resources for catalog is {}", numberNonCached); } long endFetchAllFromCache = System.currentTimeMillis(); log.debug("Fetch all catalog resources metadata from cache took " + (endFetchAllFromCache - startFetchAllFromCache) + " ms"); long startFetchFromGraph = System.currentTimeMillis(); log.debug("The number of resources needed to be fetch as light component is {}", notCertifiedHighest.size()); for (ResourceMetadataData data : notCertifiedHighest) { String uniqueId = data.getMetadataDataDefinition().getUniqueId(); log.trace("Fetch catalog resource non cached {} {}", uniqueId, data.getMetadataDataDefinition().getName()); Either<Resource, StorageOperationStatus> component = getLightComponent(uniqueId, inTransaction); if (component.isRight()) { log.debug("Failed to get Service for id = " + data.getUniqueId() + " error : " + component.right().value() + " skip resource"); } else { result.add(component.left().value()); } } long endFetchFromGraph = System.currentTimeMillis(); log.debug( "Fetch catalog resources from graph took " + (endFetchFromGraph - startFetchFromGraph) + " ms"); return Either.left(result); } finally { long end = System.currentTimeMillis(); log.debug("Fetch all catalog resources took {} ms", end - start); if (false == inTransaction) { titanGenericDao.commit(); } } }
From source file:org.openecomp.sdc.be.tosca.CsarUtils.java
private List<Artifact> convertToGeneratorArtifactsInput(List<ImmutablePair<Component, byte[]>> inputs) { List<Artifact> listOfArtifactsInput = new LinkedList<>(); for (ImmutablePair<Component, byte[]> triple : inputs) { Component component = triple.getLeft(); Map<String, ArtifactDefinition> toscaArtifacts = component.getToscaArtifacts(); ArtifactDefinition artifactDefinition = toscaArtifacts.get(ToscaExportHandler.ASSET_TOSCA_TEMPLATE); String artifactName = artifactDefinition.getArtifactName(); String artifactType = artifactDefinition.getArtifactType(); String artifactGroupType = artifactDefinition.getArtifactGroupType().getType(); String artifactDescription = artifactDefinition.getDescription(); String artifactLabel = artifactDefinition.getArtifactLabel(); byte[] right = triple.getRight(); // The md5 calculated on the uncoded data String md5Hex = DigestUtils.md5Hex(right); // byte[] payload = Base64.getEncoder().encode(right); byte[] payload = Base64.encodeBase64(right); String artifactVersion = artifactDefinition.getArtifactVersion(); Artifact convertedArtifact = new Artifact(artifactType, artifactGroupType, md5Hex, payload); convertedArtifact.setName(artifactName); convertedArtifact.setDescription(artifactDescription); convertedArtifact.setLabel(artifactLabel); convertedArtifact.setVersion(artifactVersion); listOfArtifactsInput.add(convertedArtifact); }// w w w . j a v a 2 s.c o m return listOfArtifactsInput; }
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 w w w . ja va 2s .c om*/ // } } 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.opentestsystem.shared.test.cooperation.StageImpl.java
@Override public synchronized void sayCue(Cue cue) { if (cue.isRetained()) { _retainedCues.add(cue);// www . j a v a 2 s . c o m } // Pump cue into waiting queues for (ImmutablePair<CuePattern, Queue<Cue>> pair_i : _listeningQueues) { if (pair_i.getLeft().isMatch(cue)) { if (!pair_i.getRight().offer(cue)) { _logger.warn("Cue {} rejected by listening queue", cue.getTag()); } } } // Call callbacks in this thread. for (ImmutablePair<CuePattern, CueCallback> pair_i : _callbacks) { if (pair_i.getLeft().isMatch(cue)) { try { pair_i.getRight().onCue(cue); } catch (Throwable t) { _logger.error("Error raised processing cue callbacks on cue {}", cue.getTag(), t); } } } // Find threads waiting on this cue boolean found = false; int i = 0; while (i < _waitingPatterns.size()) { MutablePair<CuePattern, Cue> pr_i = _waitingPatterns.get(i); if (pr_i.getLeft().isMatch(cue)) { pr_i.setRight(cue); _waitingPatterns.remove(i); found = true; } else { i++; } } // Give found threads a chance to run if (found) { notifyAll(); } }