X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=catalog-model%2Fsrc%2Fmain%2Fjava%2Forg%2Fopenecomp%2Fsdc%2Fbe%2Fmodel%2Fjsonjanusgraph%2Foperations%2FTopologyTemplateOperation.java;h=a253d815ad6afc6c7c91a0fc5477b18965fe3d85;hb=c469756a1092194adedd590d35f0f1f8feac3a36;hp=ed9196098ec92ec6311e7fd902b145380cf4d4cd;hpb=fee0f29212b10c940ec4b19fc8f4794d06964eee;p=sdc.git diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/TopologyTemplateOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/TopologyTemplateOperation.java index ed9196098e..a253d815ad 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/TopologyTemplateOperation.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/TopologyTemplateOperation.java @@ -17,16 +17,21 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.be.model.jsonjanusgraph.operations; import com.google.gson.reflect.TypeToken; import fj.data.Either; import java.lang.reflect.Type; -import java.util.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; import java.util.Map.Entry; +import java.util.Optional; import java.util.stream.Collectors; import org.apache.commons.collections.MapUtils; +import org.apache.commons.lang3.StringUtils; import org.apache.tinkerpop.gremlin.structure.Direction; import org.apache.tinkerpop.gremlin.structure.Edge; import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus; @@ -35,11 +40,9 @@ import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum; import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum; import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum; import org.openecomp.sdc.be.datatypes.category.MetadataKeyDataDefinition; -import org.openecomp.sdc.be.datatypes.elements.MapAttributesDataDefinition; -import org.openecomp.sdc.be.datatypes.elements.MapCapabilityProperty; -import org.openecomp.sdc.be.datatypes.elements.MapListCapabilityDataDefinition; import org.openecomp.sdc.be.datatypes.elements.AdditionalInfoParameterDataDefinition; import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition; +import org.openecomp.sdc.be.datatypes.elements.AttributeDataDefinition; import org.openecomp.sdc.be.datatypes.elements.CINodeFilterDataDefinition; import org.openecomp.sdc.be.datatypes.elements.ComponentInstanceDataDefinition; import org.openecomp.sdc.be.datatypes.elements.CompositionDataDefinition; @@ -50,9 +53,12 @@ import org.openecomp.sdc.be.datatypes.elements.InterfaceDataDefinition; import org.openecomp.sdc.be.datatypes.elements.ListCapabilityDataDefinition; import org.openecomp.sdc.be.datatypes.elements.ListRequirementDataDefinition; import org.openecomp.sdc.be.datatypes.elements.MapArtifactDataDefinition; +import org.openecomp.sdc.be.datatypes.elements.MapAttributesDataDefinition; +import org.openecomp.sdc.be.datatypes.elements.MapCapabilityProperty; import org.openecomp.sdc.be.datatypes.elements.MapDataDefinition; import org.openecomp.sdc.be.datatypes.elements.MapGroupsDataDefinition; import org.openecomp.sdc.be.datatypes.elements.MapInterfaceDataDefinition; +import org.openecomp.sdc.be.datatypes.elements.MapListCapabilityDataDefinition; import org.openecomp.sdc.be.datatypes.elements.MapListRequirementDataDefinition; import org.openecomp.sdc.be.datatypes.elements.MapPropertiesDataDefinition; import org.openecomp.sdc.be.datatypes.elements.PolicyDataDefinition; @@ -83,49 +89,51 @@ import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder; import org.openecomp.sdc.common.api.Constants; import org.openecomp.sdc.common.jsongraph.util.CommonUtility; import org.openecomp.sdc.common.jsongraph.util.CommonUtility.LogLevelEnum; +import org.openecomp.sdc.common.log.elements.ErrorLogOptionalData; +import org.openecomp.sdc.common.log.enums.EcompLoggerErrorCode; import org.openecomp.sdc.common.log.wrappers.Logger; import org.openecomp.sdc.common.util.ValidationUtils; import org.springframework.beans.factory.annotation.Autowired; - @org.springframework.stereotype.Component("topology-template-operation") public class TopologyTemplateOperation extends ToscaElementOperation { private static final Logger log = Logger.getLogger(TopologyTemplateOperation.class); - @Autowired private ArchiveOperation archiveOperation; - public Either createTopologyTemplate(TopologyTemplate topologyTemplate) { - topologyTemplate.generateUUID(); + public static String buildSubComponentName(String componentName, String subComponentTypeName, int counter) { + String normalizedComponentName = ValidationUtils.normalizeComponentInstanceName(componentName); + String typeSuffix = subComponentTypeName.substring(subComponentTypeName.lastIndexOf('.') + 1, subComponentTypeName.length()); + return normalizedComponentName + Constants.GROUP_POLICY_NAME_DELIMETER + typeSuffix + Constants.GROUP_POLICY_NAME_DELIMETER + counter; + } + public Either createTopologyTemplate(TopologyTemplate topologyTemplate) { + if (topologyTemplate.getUUID() == null) { + topologyTemplate.generateUUID(); + } topologyTemplate = getResourceMetaDataFromResource(topologyTemplate); String resourceUniqueId = topologyTemplate.getUniqueId(); if (resourceUniqueId == null) { resourceUniqueId = UniqueIdBuilder.buildResourceUniqueId(); topologyTemplate.setUniqueId(resourceUniqueId); } - GraphVertex topologyTemplateVertex = new GraphVertex(); topologyTemplateVertex = fillMetadata(topologyTemplateVertex, topologyTemplate, JsonParseFlagEnum.ParseAll); - Either createdVertex = janusGraphDao.createVertex(topologyTemplateVertex); if (createdVertex.isRight()) { JanusGraphOperationStatus status = createdVertex.right().value(); - log.debug( "Error returned after creating topology template data node {}. status returned is ", topologyTemplateVertex, status); + log.debug("Error returned after creating topology template data node {}. status returned is ", topologyTemplateVertex, status); return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status)); } - StorageOperationStatus assosiateCommon = assosiateCommonForToscaElement(topologyTemplateVertex, topologyTemplate); if (assosiateCommon != StorageOperationStatus.OK) { return Either.right(assosiateCommon); } - StorageOperationStatus associateCategory = assosiateMetadataToCategory(topologyTemplateVertex, topologyTemplate); if (associateCategory != StorageOperationStatus.OK) { return Either.right(associateCategory); } - StorageOperationStatus associateInputs = associateInputsToComponent(topologyTemplateVertex, topologyTemplate); if (associateInputs != StorageOperationStatus.OK) { return Either.right(associateInputs); @@ -147,29 +155,25 @@ public class TopologyTemplateOperation extends ToscaElementOperation { return Either.right(associateInstProperties); } StorageOperationStatus associateInstInputs = associateInstInputsToComponent(topologyTemplateVertex, topologyTemplate); - if (associateInstProperties != StorageOperationStatus.OK) { + if (associateInstInputs != StorageOperationStatus.OK) { return Either.right(associateInstInputs); } StorageOperationStatus associateInstGroups = associateInstGroupsToComponent(topologyTemplateVertex, topologyTemplate); if (associateInstGroups != StorageOperationStatus.OK) { return Either.right(associateInstInputs); } - StorageOperationStatus associateRequirements = associateRequirementsToResource(topologyTemplateVertex, topologyTemplate); if (associateRequirements != StorageOperationStatus.OK) { return Either.right(associateRequirements); } - StorageOperationStatus associateCapabilities = associateCapabilitiesToResource(topologyTemplateVertex, topologyTemplate); if (associateCapabilities != StorageOperationStatus.OK) { return Either.right(associateCapabilities); } - StorageOperationStatus associateArtifacts = associateTopologyTemplateArtifactsToComponent(topologyTemplateVertex, topologyTemplate); if (associateArtifacts != StorageOperationStatus.OK) { return Either.right(associateArtifacts); } - StorageOperationStatus addAdditionalInformation = addAdditionalInformationToResource(topologyTemplateVertex, topologyTemplate); if (addAdditionalInformation != StorageOperationStatus.OK) { return Either.right(addAdditionalInformation); @@ -178,30 +182,35 @@ public class TopologyTemplateOperation extends ToscaElementOperation { if (associateCapProperties != StorageOperationStatus.OK) { return Either.right(associateCapProperties); } - StorageOperationStatus associateInterfaces = associateInterfacesToComponent(topologyTemplateVertex, topologyTemplate); if (associateInterfaces != StorageOperationStatus.OK) { return Either.right(associateInterfaces); } - StorageOperationStatus associatePathProperties = associateForwardingPathToResource(topologyTemplateVertex, topologyTemplate); - if (associateCapProperties != StorageOperationStatus.OK) { + if (associatePathProperties != StorageOperationStatus.OK) { return Either.right(associatePathProperties); } + StorageOperationStatus associateNodeFilterToComponent = associateNodeFilterToComponent(topologyTemplateVertex, topologyTemplate); + if (associateNodeFilterToComponent != StorageOperationStatus.OK) { + return Either.right(associateNodeFilterToComponent); + } + final StorageOperationStatus associateServiceToModel = associateComponentToModel(topologyTemplateVertex, topologyTemplate, + EdgeLabelEnum.MODEL); + if (associateServiceToModel != StorageOperationStatus.OK) { + return Either.right(associateServiceToModel); + } return Either.left(topologyTemplate); } private StorageOperationStatus associatePoliciesToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) { - return associatePoliciesToComponent(nodeTypeVertex, topologyTemplate.getPolicies()); - } - - private StorageOperationStatus associatePoliciesToComponent(GraphVertex nodeTypeVertex, Map policies) { + Map policies = topologyTemplate.getPolicies(); if (policies != null && !policies.isEmpty()) { policies.values().stream().filter(p -> p.getUniqueId() == null).forEach(p -> { String uid = UniqueIdBuilder.buildGroupingUid(nodeTypeVertex.getUniqueId(), p.getName()); p.setUniqueId(uid); }); - Either assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.POLICIES, EdgeLabelEnum.POLICIES, policies); + Either assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.POLICIES, + EdgeLabelEnum.POLICIES, policies); if (assosiateElementToData.isRight()) { return assosiateElementToData.right().value(); } @@ -211,33 +220,22 @@ public class TopologyTemplateOperation extends ToscaElementOperation { private StorageOperationStatus associateForwardingPathToResource(GraphVertex topologyTemplateVertex, TopologyTemplate topologyTemplate) { Map forwardingPaths = topologyTemplate.getForwardingPaths(); - return associateForwardingPathToComponent(topologyTemplateVertex,forwardingPaths); - } - - private StorageOperationStatus associateNodeFilterToResource(GraphVertex topologyTemplateVertex, - TopologyTemplate topologyTemplate) { - Map nodeFilters = - topologyTemplate.getNodeFilterComponents(); - return associateNodeFiltersToComponent(topologyTemplateVertex, nodeFilters); + return associateForwardingPathToComponent(topologyTemplateVertex, forwardingPaths); } private StorageOperationStatus associateCapPropertiesToResource(GraphVertex topologyTemplateVertex, TopologyTemplate topologyTemplate) { - Map calculatedCapProperties = topologyTemplate - .getCalculatedCapabilitiesProperties(); + Map calculatedCapProperties = topologyTemplate.getCalculatedCapabilitiesProperties(); if (MapUtils.isNotEmpty(calculatedCapProperties)) { - Either associateElementToData = associateElementToData - (topologyTemplateVertex, VertexTypeEnum.CALCULATED_CAP_PROPERTIES, - EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, calculatedCapProperties); + Either associateElementToData = associateElementToData(topologyTemplateVertex, + VertexTypeEnum.CALCULATED_CAP_PROPERTIES, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, calculatedCapProperties); if (associateElementToData.isRight()) { return associateElementToData.right().value(); } } - Map capabilitiesProperties = topologyTemplate.getCapabilitiesProperties(); if (MapUtils.isNotEmpty(capabilitiesProperties)) { - Either associateElementToData = - associateElementToData(topologyTemplateVertex, VertexTypeEnum.CAPABILITIES_PROPERTIES, - EdgeLabelEnum.CAPABILITIES_PROPERTIES, capabilitiesProperties); + Either associateElementToData = associateElementToData(topologyTemplateVertex, + VertexTypeEnum.CAPABILITIES_PROPERTIES, EdgeLabelEnum.CAPABILITIES_PROPERTIES, capabilitiesProperties); if (associateElementToData.isRight()) { return associateElementToData.right().value(); } @@ -248,51 +246,52 @@ public class TopologyTemplateOperation extends ToscaElementOperation { private StorageOperationStatus associateCapabilitiesToResource(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) { Map calculatedCapabilities = topologyTemplate.getCalculatedCapabilities(); if (calculatedCapabilities != null && !calculatedCapabilities.isEmpty()) { - Either assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.CALCULATED_CAPABILITIES, EdgeLabelEnum.CALCULATED_CAPABILITIES, calculatedCapabilities); + Either assosiateElementToData = associateElementToData(nodeTypeVertex, + VertexTypeEnum.CALCULATED_CAPABILITIES, EdgeLabelEnum.CALCULATED_CAPABILITIES, calculatedCapabilities); if (assosiateElementToData.isRight()) { return assosiateElementToData.right().value(); } } Map fullfilledCapabilities = topologyTemplate.getFullfilledCapabilities(); if (fullfilledCapabilities != null && !fullfilledCapabilities.isEmpty()) { - Either assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.FULLFILLED_CAPABILITIES, EdgeLabelEnum.FULLFILLED_CAPABILITIES, fullfilledCapabilities); + Either assosiateElementToData = associateElementToData(nodeTypeVertex, + VertexTypeEnum.FULLFILLED_CAPABILITIES, EdgeLabelEnum.FULLFILLED_CAPABILITIES, fullfilledCapabilities); if (assosiateElementToData.isRight()) { return assosiateElementToData.right().value(); } } Map capabilities = topologyTemplate.getCapabilities(); - if(MapUtils.isNotEmpty(capabilities)) { - Either associateElementToData = - associateElementToData(nodeTypeVertex, VertexTypeEnum.CAPABILITIES, - EdgeLabelEnum.CAPABILITIES, capabilities); + if (MapUtils.isNotEmpty(capabilities)) { + Either associateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.CAPABILITIES, + EdgeLabelEnum.CAPABILITIES, capabilities); if (associateElementToData.isRight()) { return associateElementToData.right().value(); } } return StorageOperationStatus.OK; - } private StorageOperationStatus associateRequirementsToResource(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) { Map calculatedRequirements = topologyTemplate.getCalculatedRequirements(); if (calculatedRequirements != null && !calculatedRequirements.isEmpty()) { - Either assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.CALCULATED_REQUIREMENTS, EdgeLabelEnum.CALCULATED_REQUIREMENTS, calculatedRequirements); + Either assosiateElementToData = associateElementToData(nodeTypeVertex, + VertexTypeEnum.CALCULATED_REQUIREMENTS, EdgeLabelEnum.CALCULATED_REQUIREMENTS, calculatedRequirements); if (assosiateElementToData.isRight()) { return assosiateElementToData.right().value(); } } Map fullfilledRequirements = topologyTemplate.getFullfilledRequirements(); if (fullfilledRequirements != null && !fullfilledRequirements.isEmpty()) { - Either assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.FULLFILLED_REQUIREMENTS, EdgeLabelEnum.FULLFILLED_REQUIREMENTS, fullfilledRequirements); + Either assosiateElementToData = associateElementToData(nodeTypeVertex, + VertexTypeEnum.FULLFILLED_REQUIREMENTS, EdgeLabelEnum.FULLFILLED_REQUIREMENTS, fullfilledRequirements); if (assosiateElementToData.isRight()) { return assosiateElementToData.right().value(); } } Map requirements = topologyTemplate.getRequirements(); - if(MapUtils.isNotEmpty(requirements)) { - Either associateElementToData = - associateElementToData(nodeTypeVertex, VertexTypeEnum.REQUIREMENTS, - EdgeLabelEnum.REQUIREMENTS, requirements); + if (MapUtils.isNotEmpty(requirements)) { + Either associateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.REQUIREMENTS, + EdgeLabelEnum.REQUIREMENTS, requirements); if (associateElementToData.isRight()) { return associateElementToData.right().value(); } @@ -302,38 +301,38 @@ public class TopologyTemplateOperation extends ToscaElementOperation { private StorageOperationStatus associateTopologyTemplateArtifactsToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) { Map addInformation = topologyTemplate.getServiceApiArtifacts(); - if (addInformation != null && !addInformation.isEmpty()) { addInformation.values().stream().filter(a -> a.getUniqueId() == null).forEach(a -> { - String uniqueId = UniqueIdBuilder.buildPropertyUniqueId(nodeTypeVertex.getUniqueId().toLowerCase(), a.getArtifactLabel().toLowerCase()); + String uniqueId = UniqueIdBuilder + .buildPropertyUniqueId(nodeTypeVertex.getUniqueId().toLowerCase(), a.getArtifactLabel().toLowerCase()); a.setUniqueId(uniqueId); }); - Either assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.SERVICE_API_ARTIFACTS, EdgeLabelEnum.SERVICE_API_ARTIFACTS, addInformation); + Either assosiateElementToData = associateElementToData(nodeTypeVertex, + VertexTypeEnum.SERVICE_API_ARTIFACTS, EdgeLabelEnum.SERVICE_API_ARTIFACTS, addInformation); if (assosiateElementToData.isRight()) { return assosiateElementToData.right().value(); } } Map instArtifacts = topologyTemplate.getInstDeploymentArtifacts(); - if (instArtifacts != null && !instArtifacts.isEmpty()) { - Either assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INST_DEPLOYMENT_ARTIFACTS, EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS, instArtifacts); + Either assosiateElementToData = associateElementToData(nodeTypeVertex, + VertexTypeEnum.INST_DEPLOYMENT_ARTIFACTS, EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS, instArtifacts); if (assosiateElementToData.isRight()) { return assosiateElementToData.right().value(); } } Map instInfoArtifacts = topologyTemplate.getInstanceArtifacts(); - if (instInfoArtifacts != null && !instInfoArtifacts.isEmpty()) { - Either assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INSTANCE_ARTIFACTS, EdgeLabelEnum.INSTANCE_ARTIFACTS, instInfoArtifacts); + Either assosiateElementToData = associateElementToData(nodeTypeVertex, + VertexTypeEnum.INSTANCE_ARTIFACTS, EdgeLabelEnum.INSTANCE_ARTIFACTS, instInfoArtifacts); if (assosiateElementToData.isRight()) { return assosiateElementToData.right().value(); } } Map requirements = topologyTemplate.getRequirements(); - if(MapUtils.isNotEmpty(requirements)) { - Either associateElementToData = - associateElementToData(nodeTypeVertex, VertexTypeEnum.REQUIREMENTS, - EdgeLabelEnum.REQUIREMENTS, requirements); + if (MapUtils.isNotEmpty(requirements)) { + Either associateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.REQUIREMENTS, + EdgeLabelEnum.REQUIREMENTS, requirements); if (associateElementToData.isRight()) { return associateElementToData.right().value(); } @@ -342,11 +341,10 @@ public class TopologyTemplateOperation extends ToscaElementOperation { } private StorageOperationStatus addAdditionalInformationToResource(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) { - Map addInformation = topologyTemplate.getAdditionalInformation(); - if (addInformation != null && !addInformation.isEmpty()) { - Either assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.ADDITIONAL_INFORMATION, EdgeLabelEnum.ADDITIONAL_INFORMATION, addInformation); + Either assosiateElementToData = associateElementToData(nodeTypeVertex, + VertexTypeEnum.ADDITIONAL_INFORMATION, EdgeLabelEnum.ADDITIONAL_INFORMATION, addInformation); if (assosiateElementToData.isRight()) { return assosiateElementToData.right().value(); } @@ -369,10 +367,10 @@ public class TopologyTemplateOperation extends ToscaElementOperation { return associateInstGroupsToComponent(nodeTypeVertex, instGroups); } - public StorageOperationStatus associateInstPropertiesToComponent(GraphVertex nodeTypeVertex, Map instProps) { if (instProps != null && !instProps.isEmpty()) { - Either assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INST_PROPERTIES, EdgeLabelEnum.INST_PROPERTIES, instProps); + Either assosiateElementToData = associateElementToData(nodeTypeVertex, + VertexTypeEnum.INST_PROPERTIES, EdgeLabelEnum.INST_PROPERTIES, instProps); if (assosiateElementToData.isRight()) { return assosiateElementToData.right().value(); } @@ -382,7 +380,8 @@ public class TopologyTemplateOperation extends ToscaElementOperation { public StorageOperationStatus associateInstInputsToComponent(GraphVertex nodeTypeVertex, Map instInputs) { if (instInputs != null && !instInputs.isEmpty()) { - Either assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INST_INPUTS, EdgeLabelEnum.INST_INPUTS, instInputs); + Either assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INST_INPUTS, + EdgeLabelEnum.INST_INPUTS, instInputs); if (assosiateElementToData.isRight()) { return assosiateElementToData.right().value(); } @@ -390,60 +389,51 @@ public class TopologyTemplateOperation extends ToscaElementOperation { return StorageOperationStatus.OK; } - public StorageOperationStatus associateInstGroupsToComponent(GraphVertex nodeTypeVertex, Map instGroups) { - if (instGroups != null && !instGroups.isEmpty()) { - Either assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INST_GROUPS, EdgeLabelEnum.INST_GROUPS, instGroups); - if (assosiateElementToData.isRight()) { - return assosiateElementToData.right().value(); + public StorageOperationStatus associateInstInterfacesToComponent( + GraphVertex nodeTypeVertex, + Map instInterfaces + ) { + if (instInterfaces != null && !instInterfaces.isEmpty()) { + Either associateElementToData = associateElementToData( + nodeTypeVertex, + VertexTypeEnum.INST_INTERFACES, + EdgeLabelEnum.INST_INTERFACES, + instInterfaces); + if (associateElementToData.isRight()) { + return associateElementToData.right().value(); } } return StorageOperationStatus.OK; } - - public StorageOperationStatus deleteInstInputsToComponent(GraphVertex nodeTypeVertex, Map instInputs) { - - if (instInputs != null && !instInputs.isEmpty()) { - instInputs.entrySet().forEach(i -> { - List uniqueKeys = new ArrayList<>(i.getValue().getMapToscaDataDefinition().keySet()); - List pathKeys = new ArrayList<>(); - pathKeys.add(i.getKey()); - - StorageOperationStatus status = deleteToscaDataDeepElements(nodeTypeVertex, EdgeLabelEnum.INST_INPUTS, VertexTypeEnum.INST_INPUTS, uniqueKeys, pathKeys, JsonPresentationFields.NAME); - if (status != StorageOperationStatus.OK) { - return; - } - }); - } - - return StorageOperationStatus.OK; - } - - public StorageOperationStatus addInstPropertiesToComponent(GraphVertex nodeTypeVertex, Map instInputs) { - - if (instInputs != null && !instInputs.isEmpty()) { - instInputs.entrySet().forEach(i -> { - StorageOperationStatus status = addToscaDataDeepElementsBlockToToscaElement(nodeTypeVertex, EdgeLabelEnum.INST_PROPERTIES, VertexTypeEnum.INST_PROPERTIES, i.getValue(), i.getKey()); - if (status != StorageOperationStatus.OK) { - return; - } - }); + public StorageOperationStatus associateInstGroupsToComponent(GraphVertex nodeTypeVertex, Map instGroups) { + if (instGroups != null && !instGroups.isEmpty()) { + Either assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INST_GROUPS, + EdgeLabelEnum.INST_GROUPS, instGroups); + if (assosiateElementToData.isRight()) { + return assosiateElementToData.right().value(); + } } - return StorageOperationStatus.OK; } - public StorageOperationStatus associateInstDeploymentArtifactsToComponent(GraphVertex nodeTypeVertex, Map instArtifacts) { - return associateInstanceArtifactsToComponent(nodeTypeVertex, instArtifacts, VertexTypeEnum.INST_DEPLOYMENT_ARTIFACTS, EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS); + protected StorageOperationStatus associateInstDeploymentArtifactsToComponent(GraphVertex nodeTypeVertex, + Map instArtifacts) { + return associateInstanceArtifactsToComponent(nodeTypeVertex, instArtifacts, VertexTypeEnum.INST_DEPLOYMENT_ARTIFACTS, + EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS); } - public StorageOperationStatus associateInstArtifactsToComponent(GraphVertex nodeTypeVertex, Map instArtifacts) { - return associateInstanceArtifactsToComponent(nodeTypeVertex, instArtifacts, VertexTypeEnum.INSTANCE_ARTIFACTS, EdgeLabelEnum.INSTANCE_ARTIFACTS); + public StorageOperationStatus associateInstArtifactsToComponent(GraphVertex nodeTypeVertex, + Map instArtifacts) { + return associateInstanceArtifactsToComponent(nodeTypeVertex, instArtifacts, VertexTypeEnum.INSTANCE_ARTIFACTS, + EdgeLabelEnum.INSTANCE_ARTIFACTS); } - private StorageOperationStatus associateInstanceArtifactsToComponent(GraphVertex nodeTypeVertex, Map instProps, VertexTypeEnum vertexType, EdgeLabelEnum edgeLabel) { + private StorageOperationStatus associateInstanceArtifactsToComponent(GraphVertex nodeTypeVertex, Map instProps, + VertexTypeEnum vertexType, EdgeLabelEnum edgeLabel) { if (instProps != null && !instProps.isEmpty()) { - Either assosiateElementToData = associateElementToData(nodeTypeVertex, vertexType, edgeLabel, instProps); + Either assosiateElementToData = associateElementToData(nodeTypeVertex, vertexType, edgeLabel, + instProps); if (assosiateElementToData.isRight()) { return assosiateElementToData.right().value(); } @@ -451,58 +441,70 @@ public class TopologyTemplateOperation extends ToscaElementOperation { return StorageOperationStatus.OK; } - public StorageOperationStatus associateOrAddCalcCapReqToComponent(GraphVertex nodeTypeVertex, Map calcRequirements, Map calcCapabilty, Map calculatedCapabilitiesProperties) { + public StorageOperationStatus associateOrAddCalcCapReqToComponent(GraphVertex nodeTypeVertex, + Map calcRequirements, + Map calcCapabilty, + Map calculatedCapabilitiesProperties) { if (!MapUtils.isEmpty(calcRequirements)) { - Either assosiateElementToData = associateOrAddElementToData(nodeTypeVertex, VertexTypeEnum.CALCULATED_REQUIREMENTS, EdgeLabelEnum.CALCULATED_REQUIREMENTS, calcRequirements); + Either assosiateElementToData = associateOrAddElementToData(nodeTypeVertex, + VertexTypeEnum.CALCULATED_REQUIREMENTS, EdgeLabelEnum.CALCULATED_REQUIREMENTS, calcRequirements); if (assosiateElementToData.isRight()) { return assosiateElementToData.right().value(); } Map fullFilled = new HashMap<>(); - assosiateElementToData = associateOrAddElementToData(nodeTypeVertex, VertexTypeEnum.FULLFILLED_REQUIREMENTS, EdgeLabelEnum.FULLFILLED_REQUIREMENTS, fullFilled); + assosiateElementToData = associateOrAddElementToData(nodeTypeVertex, VertexTypeEnum.FULLFILLED_REQUIREMENTS, + EdgeLabelEnum.FULLFILLED_REQUIREMENTS, fullFilled); if (assosiateElementToData.isRight()) { return assosiateElementToData.right().value(); } } if (!MapUtils.isEmpty(calcCapabilty)) { - Either assosiateElementToData = associateOrAddElementToData(nodeTypeVertex, VertexTypeEnum.CALCULATED_CAPABILITIES ,EdgeLabelEnum.CALCULATED_CAPABILITIES, calcCapabilty); + Either assosiateElementToData = associateOrAddElementToData(nodeTypeVertex, + VertexTypeEnum.CALCULATED_CAPABILITIES, EdgeLabelEnum.CALCULATED_CAPABILITIES, calcCapabilty); if (assosiateElementToData.isRight()) { return assosiateElementToData.right().value(); } Map fullFilled = new HashMap<>(); - assosiateElementToData = associateOrAddElementToData(nodeTypeVertex, VertexTypeEnum.FULLFILLED_CAPABILITIES, EdgeLabelEnum.FULLFILLED_CAPABILITIES, fullFilled); + assosiateElementToData = associateOrAddElementToData(nodeTypeVertex, VertexTypeEnum.FULLFILLED_CAPABILITIES, + EdgeLabelEnum.FULLFILLED_CAPABILITIES, fullFilled); if (assosiateElementToData.isRight()) { return assosiateElementToData.right().value(); } } - if (!MapUtils.isEmpty(calculatedCapabilitiesProperties)){ - return associateOrAddElementToData(nodeTypeVertex, VertexTypeEnum.CALCULATED_CAP_PROPERTIES, - EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, calculatedCapabilitiesProperties) - .right() - .on(v -> StorageOperationStatus.OK); + if (!MapUtils.isEmpty(calculatedCapabilitiesProperties)) { + return associateOrAddElementToData(nodeTypeVertex, VertexTypeEnum.CALCULATED_CAP_PROPERTIES, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, + calculatedCapabilitiesProperties).right().on(v -> StorageOperationStatus.OK); } return StorageOperationStatus.OK; } - private Either associateOrAddElementToData(GraphVertex nodeTypeVertex, VertexTypeEnum vertexTypeEnum, EdgeLabelEnum edgeLabelEnum, Map dataMap){ + private Either associateOrAddElementToData(GraphVertex nodeTypeVertex, + VertexTypeEnum vertexTypeEnum, + EdgeLabelEnum edgeLabelEnum, + Map dataMap) { return janusGraphDao.getChildVertex(nodeTypeVertex, edgeLabelEnum, JsonParseFlagEnum.ParseJson) - .either(dataVertex -> addElementsToComponent(nodeTypeVertex, dataVertex, vertexTypeEnum, edgeLabelEnum, dataMap), - status -> associateElementToDataIfNotFound(status, nodeTypeVertex, vertexTypeEnum, edgeLabelEnum, dataMap)); + .either(dataVertex -> addElementsToComponent(nodeTypeVertex, dataVertex, vertexTypeEnum, edgeLabelEnum, dataMap), + status -> associateElementToDataIfNotFound(status, nodeTypeVertex, vertexTypeEnum, edgeLabelEnum, dataMap)); } - private Either associateElementToDataIfNotFound(JanusGraphOperationStatus status, GraphVertex nodeTypeVertex, VertexTypeEnum vertexTypeEnum, EdgeLabelEnum edgeLabelEnum, Map dataMap) { + private Either associateElementToDataIfNotFound(JanusGraphOperationStatus status, GraphVertex nodeTypeVertex, + VertexTypeEnum vertexTypeEnum, EdgeLabelEnum edgeLabelEnum, + Map dataMap) { if (status == JanusGraphOperationStatus.NOT_FOUND) { return associateElementToData(nodeTypeVertex, vertexTypeEnum, edgeLabelEnum, dataMap); } return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status)); } - private Either addElementsToComponent(GraphVertex nodeTypeVertex, GraphVertex dataVertex, VertexTypeEnum vertexTypeEnum, EdgeLabelEnum edgeLabelEnum, Map dataMap) { - Optional error = dataMap.entrySet() - .stream() - .map(e -> addElementToComponent(nodeTypeVertex.getUniqueId(), vertexTypeEnum, edgeLabelEnum, e)) - .filter(s -> s != StorageOperationStatus.OK) - .findFirst(); - if(error.isPresent()){ + private Either addElementsToComponent(GraphVertex nodeTypeVertex, + GraphVertex dataVertex, + VertexTypeEnum vertexTypeEnum, + EdgeLabelEnum edgeLabelEnum, + Map dataMap) { + Optional error = dataMap.entrySet().stream() + .map(e -> addElementToComponent(nodeTypeVertex.getUniqueId(), vertexTypeEnum, edgeLabelEnum, e)) + .filter(s -> s != StorageOperationStatus.OK).findFirst(); + if (error.isPresent()) { return Either.right(error.get()); } return Either.left(dataVertex); @@ -513,9 +515,11 @@ public class TopologyTemplateOperation extends ToscaElementOperation { return associateInstAttributeToComponent(nodeTypeVertex, instAttr); } - public StorageOperationStatus associateForwardingPathToComponent(GraphVertex nodeTypeVertex, Map forwardingPathMap) { + public StorageOperationStatus associateForwardingPathToComponent(GraphVertex nodeTypeVertex, + Map forwardingPathMap) { if (forwardingPathMap != null && !forwardingPathMap.isEmpty()) { - Either assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.FORWARDING_PATH, EdgeLabelEnum.FORWARDING_PATH, forwardingPathMap); + Either assosiateElementToData = associateElementToData(nodeTypeVertex, + VertexTypeEnum.FORWARDING_PATH, EdgeLabelEnum.FORWARDING_PATH, forwardingPathMap); if (assosiateElementToData.isRight()) { return assosiateElementToData.right().value(); } @@ -525,7 +529,8 @@ public class TopologyTemplateOperation extends ToscaElementOperation { public StorageOperationStatus associateInstAttributeToComponent(GraphVertex nodeTypeVertex, Map instAttr) { if (instAttr != null && !instAttr.isEmpty()) { - Either assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INST_ATTRIBUTES, EdgeLabelEnum.INST_ATTRIBUTES, instAttr); + Either assosiateElementToData = associateElementToData(nodeTypeVertex, + VertexTypeEnum.INST_ATTRIBUTES, EdgeLabelEnum.INST_ATTRIBUTES, instAttr); if (assosiateElementToData.isRight()) { return assosiateElementToData.right().value(); } @@ -534,13 +539,13 @@ public class TopologyTemplateOperation extends ToscaElementOperation { } public StorageOperationStatus associateGroupsToComponent(GraphVertex nodeTypeVertex, Map groups) { - if (groups != null && !groups.isEmpty()) { groups.values().stream().filter(p -> p.getUniqueId() == null).forEach(p -> { String uid = UniqueIdBuilder.buildGroupingUid(nodeTypeVertex.getUniqueId(), p.getName()); p.setUniqueId(uid); }); - Either assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.GROUPS, EdgeLabelEnum.GROUPS, groups); + Either assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.GROUPS, + EdgeLabelEnum.GROUPS, groups); if (assosiateElementToData.isRight()) { return assosiateElementToData.right().value(); } @@ -559,9 +564,10 @@ public class TopologyTemplateOperation extends ToscaElementOperation { public StorageOperationStatus associateInputsToComponent(GraphVertex nodeTypeVertex, Map inputs, String id) { if (inputs != null && !inputs.isEmpty()) { - inputs.values().stream().filter(e -> e.getUniqueId() == null).forEach(e -> e.setUniqueId(UniqueIdBuilder.buildPropertyUniqueId(id, e.getName()))); - - Either assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INPUTS, EdgeLabelEnum.INPUTS, inputs); + inputs.values().stream().filter(e -> e.getUniqueId() == null) + .forEach(e -> e.setUniqueId(UniqueIdBuilder.buildPropertyUniqueId(id, e.getName()))); + Either assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INPUTS, + EdgeLabelEnum.INPUTS, inputs); if (assosiateElementToData.isRight()) { return assosiateElementToData.right().value(); } @@ -569,6 +575,21 @@ public class TopologyTemplateOperation extends ToscaElementOperation { return StorageOperationStatus.OK; } + public StorageOperationStatus associateOutputsToComponent(final GraphVertex nodeTypeVertex, + final Map outputs, + final String id) { + if (MapUtils.isNotEmpty(outputs)) { + outputs.values().stream().filter(e -> e.getUniqueId() == null) + .forEach(e -> e.setUniqueId(UniqueIdBuilder.buildPropertyUniqueId(id, e.getName()))); + final Either associateElementToData + = associateElementToData(nodeTypeVertex, VertexTypeEnum.OUTPUTS, EdgeLabelEnum.OUTPUTS, outputs); + if (associateElementToData.isRight()) { + return associateElementToData.right().value(); + } + } + return StorageOperationStatus.OK; + } + private GraphVertex fillMetadata(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate, JsonParseFlagEnum flag) { nodeTypeVertex.setLabel(VertexTypeEnum.TOPOLOGY_TEMPLATE); fillCommonMetadata(nodeTypeVertex, topologyTemplate); @@ -576,10 +597,11 @@ public class TopologyTemplateOperation extends ToscaElementOperation { nodeTypeVertex.setJson(topologyTemplate.getCompositions()); } nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.CSAR_UUID, topologyTemplate.getMetadataValue(JsonPresentationFields.CSAR_UUID)); - nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.DISTRIBUTION_STATUS, topologyTemplate.getMetadataValue(JsonPresentationFields.DISTRIBUTION_STATUS)); - + nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.CSAR_VERSION_UUID, + topologyTemplate.getMetadataValue(JsonPresentationFields.CSAR_VERSION_ID)); + nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.DISTRIBUTION_STATUS, + topologyTemplate.getMetadataValue(JsonPresentationFields.DISTRIBUTION_STATUS)); return nodeTypeVertex; - } private StorageOperationStatus assosiateMetadataToCategory(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) { @@ -594,7 +616,8 @@ public class TopologyTemplateOperation extends ToscaElementOperation { private StorageOperationStatus associateServiceMetadataToCategory(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) { String categoryName = topologyTemplate.getCategories().get(0).getName(); - Either category = categoryOperation.getCategory(categoryName, VertexTypeEnum.SERVICE_CATEGORY); + Either category = categoryOperation.getCategory(categoryName, + VertexTypeEnum.SERVICE_CATEGORY); if (category.isRight()) { log.trace("NO category {} for service {}", categoryName, topologyTemplate.getUniqueId()); return StorageOperationStatus.CATEGORY_NOT_FOUND; @@ -602,7 +625,8 @@ public class TopologyTemplateOperation extends ToscaElementOperation { GraphVertex categoryV = category.left().value(); JanusGraphOperationStatus createEdge = janusGraphDao.createEdge(nodeTypeVertex, categoryV, EdgeLabelEnum.CATEGORY, new HashMap<>()); if (createEdge != JanusGraphOperationStatus.OK) { - log.trace("Failed to associate resource {} to category {} with id {}", topologyTemplate.getUniqueId(), categoryName, categoryV.getUniqueId()); + log.trace("Failed to associate resource {} to category {} with id {}", topologyTemplate.getUniqueId(), categoryName, + categoryV.getUniqueId()); return DaoStatusConverter.convertJanusGraphStatusToStorageStatus(createEdge); } return StorageOperationStatus.OK; @@ -611,21 +635,18 @@ public class TopologyTemplateOperation extends ToscaElementOperation { @Override public Either getToscaElement(String uniqueId, ComponentParametersView componentParametersView) { JsonParseFlagEnum parseFlag = componentParametersView.detectParseFlag(); - - Either componentByLabelAndId = getComponentByLabelAndId(uniqueId, ToscaElementTypeEnum.TOPOLOGY_TEMPLATE, parseFlag); + Either componentByLabelAndId = getComponentByLabelAndId(uniqueId, ToscaElementTypeEnum.TOPOLOGY_TEMPLATE, + parseFlag); if (componentByLabelAndId.isRight()) { return Either.right(componentByLabelAndId.right().value()); } GraphVertex componentV = componentByLabelAndId.left().value(); - return getToscaElement(componentV, componentParametersView); - } - // ------------------------------------------------------------- + // ------------------------------------------------------------- public Either getToscaElement(GraphVertex componentV, ComponentParametersView componentParametersView) { TopologyTemplate toscaElement; - toscaElement = convertToTopologyTemplate(componentV); JanusGraphOperationStatus status; if (!componentParametersView.isIgnoreUsers()) { @@ -633,7 +654,6 @@ public class TopologyTemplateOperation extends ToscaElementOperation { if (status != JanusGraphOperationStatus.OK) { return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status)); } - status = setLastModifierFromGraph(componentV, toscaElement); if (status != JanusGraphOperationStatus.OK) { return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status)); @@ -643,7 +663,6 @@ public class TopologyTemplateOperation extends ToscaElementOperation { status = setTopologyTempalteCategoriesFromGraph(componentV, toscaElement); if (status != JanusGraphOperationStatus.OK) { return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status)); - } } if (!componentParametersView.isIgnoreArtifacts()) { @@ -688,118 +707,92 @@ public class TopologyTemplateOperation extends ToscaElementOperation { return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status)); } } - if (!componentParametersView.isIgnoreGroups()) { status = setGroupsFromGraph(componentV, toscaElement); if (status != JanusGraphOperationStatus.OK) { return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status)); } - } if (!componentParametersView.isIgnorePolicies()) { status = setPoliciesFromGraph(componentV, toscaElement); if (status != JanusGraphOperationStatus.OK) { return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status)); } - } if (!componentParametersView.isIgnoreComponentInstances()) { status = setInstGroupsFromGraph(componentV, toscaElement); - //Mark all CIs that has archived origins archiveOperation.setArchivedOriginsFlagInComponentInstances(componentV); - if (status != JanusGraphOperationStatus.OK) { return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status)); } - } if (!componentParametersView.isIgnoreInputs()) { status = setInputsFromGraph(componentV, toscaElement); if (status != JanusGraphOperationStatus.OK) { return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status)); } - + } + if (!componentParametersView.isIgnoreOutputs()) { + final JanusGraphOperationStatus storageStatus = setOutputsFromGraph(componentV, toscaElement); + if (storageStatus != JanusGraphOperationStatus.OK) { + return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(storageStatus)); + } } if (!componentParametersView.isIgnoreProperties()) { status = setPropertiesFromGraph(componentV, toscaElement); if (status != JanusGraphOperationStatus.OK) { return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status)); } - } - if (!componentParametersView.isIgnoreComponentInstancesInputs()) { status = setComponentInstancesInputsFromGraph(componentV, toscaElement); if (status != JanusGraphOperationStatus.OK) { return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status)); - } } - if (!componentParametersView.isIgnoreCapabiltyProperties()) { status = setComponentInstancesCapPropertiesFromGraph(componentV, toscaElement); if (status != JanusGraphOperationStatus.OK) { return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status)); - } } - if (!componentParametersView.isIgnoreServicePath()) { status = setForwardingGraphPropertiesFromGraph(componentV, toscaElement); if (status != JanusGraphOperationStatus.OK) { return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status)); - } } - if (!componentParametersView.isIgnoreNodeFilter()) { status = setNodeFilterComponentFromGraph(componentV, toscaElement); if (status != JanusGraphOperationStatus.OK) { return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status)); - } } - if (!componentParametersView.isIgnoreSubstitutionFilter()) { status = setSubstitutionFilterComponentFromGraph(componentV, toscaElement); if (status != JanusGraphOperationStatus.OK) { return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status)); - } } - if (!componentParametersView.isIgnoreInterfaces()) { JanusGraphOperationStatus storageStatus = setInterfacesFromGraph(componentV, toscaElement); if (storageStatus != JanusGraphOperationStatus.OK) { return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(storageStatus)); - - } - } - - if (!componentParametersView.isIgnoreInterfaces()) { - JanusGraphOperationStatus storageStatus = setInterfcesFromGraph(componentV, toscaElement); - if (storageStatus != JanusGraphOperationStatus.OK) { - return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(storageStatus)); - } } - if (!componentParametersView.isIgnoreComponentInstancesInterfaces()) { - JanusGraphOperationStatus storageStatus = - setComponentInstancesInterfacesFromGraph(componentV, toscaElement); + JanusGraphOperationStatus storageStatus = setComponentInstancesInterfacesFromGraph(componentV, toscaElement); if (storageStatus != JanusGraphOperationStatus.OK) { return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(storageStatus)); } } - if (!componentParametersView.isIgnoreDataType()) { JanusGraphOperationStatus storageStatus = setDataTypesFromGraph(componentV, toscaElement); if (storageStatus != JanusGraphOperationStatus.OK) { return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(storageStatus)); } } - return Either.left(toscaElement); } @@ -815,18 +808,6 @@ public class TopologyTemplateOperation extends ToscaElementOperation { return JanusGraphOperationStatus.OK; } - private JanusGraphOperationStatus setInterfcesFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) { - Either, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INTERFACE); - if (result.isLeft()) { - topologyTemplate.setInterfaces(result.left().value()); - } else { - if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) { - return result.right().value(); - } - } - return JanusGraphOperationStatus.OK; - } - private JanusGraphOperationStatus setPoliciesFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) { Either, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.POLICIES); if (result.isLeft()) { @@ -851,14 +832,11 @@ public class TopologyTemplateOperation extends ToscaElementOperation { return JanusGraphOperationStatus.OK; } - - private JanusGraphOperationStatus setComponentInstancesInterfacesFromGraph(GraphVertex componentV, - TopologyTemplate topologyTemplate) { - Either, JanusGraphOperationStatus> result = - getDataFromGraph(componentV, EdgeLabelEnum.INST_INTERFACES); + private JanusGraphOperationStatus setComponentInstancesInterfacesFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) { + Either, JanusGraphOperationStatus> result = getDataFromGraph(componentV, + EdgeLabelEnum.INST_INTERFACES); if (result.isLeft()) { - result.left().value().entrySet().forEach(entry -> topologyTemplate - .addComponentInstanceInterfaceMap(entry.getKey(), entry.getValue())); + result.left().value().entrySet().forEach(entry -> topologyTemplate.addComponentInstanceInterfaceMap(entry.getKey(), entry.getValue())); } else { if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) { return result.right().value(); @@ -870,7 +848,8 @@ public class TopologyTemplateOperation extends ToscaElementOperation { private StorageOperationStatus associateInterfacesToComponent(GraphVertex topologyTemplateVertex, TopologyTemplate topologyTemplate) { Map interfaceMap = topologyTemplate.getInterfaces(); if (interfaceMap != null && !interfaceMap.isEmpty()) { - Either assosiateElementToData = associateElementToData(topologyTemplateVertex, VertexTypeEnum.INTERFACE, EdgeLabelEnum.INTERFACE, interfaceMap); + Either assosiateElementToData = associateElementToData(topologyTemplateVertex, + VertexTypeEnum.INTERFACE, EdgeLabelEnum.INTERFACE, interfaceMap); if (assosiateElementToData.isRight()) { return assosiateElementToData.right().value(); } @@ -878,12 +857,11 @@ public class TopologyTemplateOperation extends ToscaElementOperation { return StorageOperationStatus.OK; } - public StorageOperationStatus associateNodeFiltersToComponent(GraphVertex nodeTypeVertex, - Map filterMaps) { - if (filterMaps != null && !filterMaps.isEmpty()) { - Either assosiateElementToData = associateElementToData - (nodeTypeVertex, VertexTypeEnum.NODE_FILTER_TEMPLATE, - EdgeLabelEnum.NODE_FILTER_TEMPLATE, filterMaps); + private StorageOperationStatus associateNodeFilterToComponent(GraphVertex topologyTemplateVertex, TopologyTemplate topologyTemplate) { + Map nodeFilterComponents = topologyTemplate.getNodeFilterComponents(); + if (MapUtils.isNotEmpty(nodeFilterComponents)) { + Either assosiateElementToData = associateElementToData(topologyTemplateVertex, + VertexTypeEnum.INTERFACE, EdgeLabelEnum.NODE_FILTER_TEMPLATE, nodeFilterComponents); if (assosiateElementToData.isRight()) { return assosiateElementToData.right().value(); } @@ -892,7 +870,8 @@ public class TopologyTemplateOperation extends ToscaElementOperation { } private JanusGraphOperationStatus setForwardingGraphPropertiesFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) { - Either, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.FORWARDING_PATH); + Either, JanusGraphOperationStatus> result = getDataFromGraph(componentV, + EdgeLabelEnum.FORWARDING_PATH); if (result.isLeft()) { topologyTemplate.setForwardingPaths(result.left().value()); } else { @@ -903,9 +882,9 @@ public class TopologyTemplateOperation extends ToscaElementOperation { return JanusGraphOperationStatus.OK; } - private JanusGraphOperationStatus setComponentInstancesCapPropertiesFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) { - Either, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES); + Either, JanusGraphOperationStatus> result = getDataFromGraph(componentV, + EdgeLabelEnum.CALCULATED_CAP_PROPERTIES); if (result.isLeft()) { topologyTemplate.setCalculatedCapabilitiesProperties(result.left().value()); } else { @@ -913,8 +892,8 @@ public class TopologyTemplateOperation extends ToscaElementOperation { return result.right().value(); } } - Either, JanusGraphOperationStatus> capPropResult = - getDataFromGraph(componentV, EdgeLabelEnum.CAPABILITIES_PROPERTIES); + Either, JanusGraphOperationStatus> capPropResult = getDataFromGraph(componentV, + EdgeLabelEnum.CAPABILITIES_PROPERTIES); if (capPropResult.isLeft()) { topologyTemplate.setCapabilitiesProperties(capPropResult.left().value()); } else { @@ -922,7 +901,6 @@ public class TopologyTemplateOperation extends ToscaElementOperation { return capPropResult.right().value(); } } - return JanusGraphOperationStatus.OK; } @@ -951,7 +929,8 @@ public class TopologyTemplateOperation extends ToscaElementOperation { } private JanusGraphOperationStatus setComponentInstancesPropertiesFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) { - Either, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INST_PROPERTIES); + Either, JanusGraphOperationStatus> result = getDataFromGraph(componentV, + EdgeLabelEnum.INST_PROPERTIES); if (result.isLeft()) { topologyTemplate.setInstProperties(result.left().value()); } else { @@ -964,8 +943,8 @@ public class TopologyTemplateOperation extends ToscaElementOperation { private JanusGraphOperationStatus setComponentInstancesAttributesFromGraph(final GraphVertex componentV, final TopologyTemplate topologyTemplate) { - final Either, JanusGraphOperationStatus> result = - getDataFromGraph(componentV, EdgeLabelEnum.INST_ATTRIBUTES); + final Either, JanusGraphOperationStatus> result = getDataFromGraph(componentV, + EdgeLabelEnum.INST_ATTRIBUTES); if (result.isLeft()) { topologyTemplate.setInstAttributes(result.left().value()); } else if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) { @@ -986,11 +965,9 @@ public class TopologyTemplateOperation extends ToscaElementOperation { return JanusGraphOperationStatus.OK; } - private JanusGraphOperationStatus setNodeFilterComponentFromGraph(final GraphVertex componentV, - final TopologyTemplate topologyTemplate) { - - final Either, JanusGraphOperationStatus> result = - getDataFromGraph(componentV, EdgeLabelEnum.NODE_FILTER_TEMPLATE); + private JanusGraphOperationStatus setNodeFilterComponentFromGraph(final GraphVertex componentV, final TopologyTemplate topologyTemplate) { + final Either, JanusGraphOperationStatus> result = getDataFromGraph(componentV, + EdgeLabelEnum.NODE_FILTER_TEMPLATE); if (result.isLeft()) { topologyTemplate.setNodeFilterComponents(result.left().value()); } else { @@ -1001,13 +978,20 @@ public class TopologyTemplateOperation extends ToscaElementOperation { return JanusGraphOperationStatus.OK; } - private JanusGraphOperationStatus setSubstitutionFilterComponentFromGraph(final GraphVertex componentV, - final TopologyTemplate topologyTemplate) { - - final Either, JanusGraphOperationStatus> result = - getDataFromGraph(componentV, EdgeLabelEnum.SUBSTITUTION_FILTER_TEMPLATE); + private JanusGraphOperationStatus setSubstitutionFilterComponentFromGraph(final GraphVertex componentV, final TopologyTemplate topologyTemplate) { + final Either, JanusGraphOperationStatus> result = getDataFromGraph(componentV, + EdgeLabelEnum.SUBSTITUTION_FILTER_TEMPLATE); if (result.isLeft()) { - topologyTemplate.setSubstitutionFilterDataDefinitionMap(result.left().value()); + final Map filters = result.left().value(); + if (MapUtils.isEmpty(filters)) { + return JanusGraphOperationStatus.OK; + } + if (filters.values().size() > 1) { + log.error(EcompLoggerErrorCode.DATA_ERROR, TopologyTemplateOperation.class.getName(), + (ErrorLogOptionalData) null, "Only a single substitution filter is expected, but got '{}'", filters.values().size()); + return JanusGraphOperationStatus.GENERAL_ERROR; + } + topologyTemplate.setSubstitutionFilters(new SubstitutionFilterDataDefinition(filters.values().iterator().next())); } else { if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) { return result.right().value(); @@ -1016,10 +1000,10 @@ public class TopologyTemplateOperation extends ToscaElementOperation { return JanusGraphOperationStatus.OK; } - @Override protected JanusGraphOperationStatus setRequirementsFromGraph(GraphVertex componentV, T toscaElement) { - Either, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.CALCULATED_REQUIREMENTS); + Either, JanusGraphOperationStatus> result = getDataFromGraph(componentV, + EdgeLabelEnum.CALCULATED_REQUIREMENTS); if (result.isLeft()) { ((TopologyTemplate) toscaElement).setCalculatedRequirements(result.left().value()); } else { @@ -1035,8 +1019,8 @@ public class TopologyTemplateOperation extends ToscaElementOperation { return result.right().value(); } } - Either, JanusGraphOperationStatus> requirementResult = - getDataFromGraph(componentV, EdgeLabelEnum.REQUIREMENTS); + Either, JanusGraphOperationStatus> requirementResult = getDataFromGraph(componentV, + EdgeLabelEnum.REQUIREMENTS); if (requirementResult.isLeft()) { toscaElement.setRequirements(requirementResult.left().value()); } else { @@ -1045,11 +1029,11 @@ public class TopologyTemplateOperation extends ToscaElementOperation { } } return JanusGraphOperationStatus.OK; - } protected JanusGraphOperationStatus setCapabilitiesFromGraph(GraphVertex componentV, T toscaElement) { - Either, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.CALCULATED_CAPABILITIES); + Either, JanusGraphOperationStatus> result = getDataFromGraph(componentV, + EdgeLabelEnum.CALCULATED_CAPABILITIES); if (result.isLeft()) { ((TopologyTemplate) toscaElement).setCalculatedCapabilities(result.left().value()); } else { @@ -1065,8 +1049,8 @@ public class TopologyTemplateOperation extends ToscaElementOperation { return result.right().value(); } } - Either, JanusGraphOperationStatus> capabilitiesResult = - getDataFromGraph(componentV, EdgeLabelEnum.CAPABILITIES); + Either, JanusGraphOperationStatus> capabilitiesResult = getDataFromGraph(componentV, + EdgeLabelEnum.CAPABILITIES); if (capabilitiesResult.isLeft()) { toscaElement.setCapabilities(capabilitiesResult.left().value()); } else { @@ -1082,7 +1066,8 @@ public class TopologyTemplateOperation extends ToscaElementOperation { if (storageStatus != JanusGraphOperationStatus.OK) { return storageStatus; } - Either, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.SERVICE_API_ARTIFACTS); + Either, JanusGraphOperationStatus> result = getDataFromGraph(componentV, + EdgeLabelEnum.SERVICE_API_ARTIFACTS); if (result.isLeft()) { toscaElement.setServiceApiArtifacts(result.left().value()); } else { @@ -1090,7 +1075,8 @@ public class TopologyTemplateOperation extends ToscaElementOperation { return result.right().value(); } } - Either, JanusGraphOperationStatus> resultInstArt = getDataFromGraph(componentV, EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS); + Either, JanusGraphOperationStatus> resultInstArt = getDataFromGraph(componentV, + EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS); if (resultInstArt.isLeft()) { toscaElement.setInstDeploymentArtifacts(resultInstArt.left().value()); } else { @@ -1098,7 +1084,8 @@ public class TopologyTemplateOperation extends ToscaElementOperation { return resultInstArt.right().value(); } } - Either, JanusGraphOperationStatus> instanceArt = getDataFromGraph(componentV, EdgeLabelEnum.INSTANCE_ARTIFACTS); + Either, JanusGraphOperationStatus> instanceArt = getDataFromGraph(componentV, + EdgeLabelEnum.INSTANCE_ARTIFACTS); if (instanceArt.isLeft()) { toscaElement.setInstanceArtifacts(instanceArt.left().value()); } else { @@ -1118,8 +1105,8 @@ public class TopologyTemplateOperation extends ToscaElementOperation { return result.right().value(); } } - Either, JanusGraphOperationStatus> capabilitiesResult = - getDataFromGraph(componentV, EdgeLabelEnum.CAPABILITIES); + Either, JanusGraphOperationStatus> capabilitiesResult = getDataFromGraph(componentV, + EdgeLabelEnum.CAPABILITIES); if (capabilitiesResult.isLeft()) { toscaElement.setCapabilities(capabilitiesResult.left().value()); } else { @@ -1130,6 +1117,18 @@ public class TopologyTemplateOperation extends ToscaElementOperation { return JanusGraphOperationStatus.OK; } + private JanusGraphOperationStatus setOutputsFromGraph(final GraphVertex componentV, final TopologyTemplate toscaElement) { + final Either, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.OUTPUTS); + if (result.isLeft()) { + toscaElement.setOutputs(result.left().value()); + } else { + if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) { + return result.right().value(); + } + } + return JanusGraphOperationStatus.OK; + } + private JanusGraphOperationStatus setGroupsFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) { Either, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.GROUPS); if (result.isLeft()) { @@ -1144,24 +1143,25 @@ public class TopologyTemplateOperation extends ToscaElementOperation { private JanusGraphOperationStatus setTopologyTempalteCategoriesFromGraph(GraphVertex componentV, ToscaElement toscaElement) { List categories = new ArrayList<>(); - switch (componentV.getType()) { - case RESOURCE: - return setResourceCategoryFromGraph(componentV, toscaElement); - case SERVICE: - return setServiceCategoryFromGraph(componentV, toscaElement, categories); - - default: - log.debug("Not supported component type {} ", componentV.getType()); - break; + case RESOURCE: + return setResourceCategoryFromGraph(componentV, toscaElement); + case SERVICE: + return setServiceCategoryFromGraph(componentV, toscaElement, categories); + default: + log.debug("Not supported component type {} ", componentV.getType()); + break; } return JanusGraphOperationStatus.OK; } - private JanusGraphOperationStatus setServiceCategoryFromGraph(GraphVertex componentV, ToscaElement toscaElement, List categories) { - Either childVertex = janusGraphDao.getChildVertex(componentV, EdgeLabelEnum.CATEGORY, JsonParseFlagEnum.NoParse); + private JanusGraphOperationStatus setServiceCategoryFromGraph(GraphVertex componentV, ToscaElement toscaElement, + List categories) { + Either childVertex = janusGraphDao + .getChildVertex(componentV, EdgeLabelEnum.CATEGORY, JsonParseFlagEnum.NoParse); if (childVertex.isRight()) { - log.debug("failed to fetch {} for tosca element with id {}, error {}", EdgeLabelEnum.CATEGORY, componentV.getUniqueId(), childVertex.right().value()); + log.debug("failed to fetch {} for tosca element with id {}, error {}", EdgeLabelEnum.CATEGORY, componentV.getUniqueId(), + childVertex.right().value()); return childVertex.right().value(); } GraphVertex categoryV = childVertex.left().value(); @@ -1170,31 +1170,31 @@ public class TopologyTemplateOperation extends ToscaElementOperation { category.setUniqueId(categoryV.getUniqueId()); category.setNormalizedName((String) metadataProperties.get(GraphPropertyEnum.NORMALIZED_NAME)); category.setName((String) metadataProperties.get(GraphPropertyEnum.NAME)); - final Boolean useServiceSubstitutionForNestedServices = (Boolean)metadataProperties.get(GraphPropertyEnum.USE_SUBSTITUTION_FOR_NESTED_SERVICES); - category.setUseServiceSubstitutionForNestedServices(useServiceSubstitutionForNestedServices == null ? false : useServiceSubstitutionForNestedServices); - - Type listTypeCat = new TypeToken>() {}.getType(); - List iconsfromJsonCat = getGson().fromJson((String) metadataProperties.get(GraphPropertyEnum.ICONS.getProperty()), listTypeCat); - category.setIcons(iconsfromJsonCat); - - final Type metadataKeysTypeCat = new TypeToken>() {}.getType(); - final List metadataKeysfromJsonCat = getGson().fromJson((String) metadataProperties.get(GraphPropertyEnum.METADATA_KEYS), metadataKeysTypeCat); + final Object useServiceSubstitutionForNestedServices = metadataProperties.get(GraphPropertyEnum.USE_SUBSTITUTION_FOR_NESTED_SERVICES); + category.setUseServiceSubstitutionForNestedServices( + useServiceSubstitutionForNestedServices != null && (boolean) useServiceSubstitutionForNestedServices); + Type listTypeCat = new TypeToken>() { + }.getType(); + category.setNotApplicableMetadataKeys( + (getGson().fromJson((String) metadataProperties.get(GraphPropertyEnum.NOT_APPLICABLE_METADATA_KEYS.getProperty()), listTypeCat))); + List iconsFromJsonCat = getGson().fromJson((String) metadataProperties.get(GraphPropertyEnum.ICONS.getProperty()), listTypeCat); + category.setIcons(iconsFromJsonCat); + category.setModels((getGson().fromJson((String) metadataProperties.get(GraphPropertyEnum.MODEL.getProperty()), listTypeCat))); + final Type metadataKeysTypeCat = new TypeToken>() { + }.getType(); + final List metadataKeysfromJsonCat = getGson() + .fromJson((String) metadataProperties.get(GraphPropertyEnum.METADATA_KEYS), metadataKeysTypeCat); category.setMetadataKeys(metadataKeysfromJsonCat); - categories.add(category); toscaElement.setCategories(categories); - return JanusGraphOperationStatus.OK; } @SuppressWarnings("unchecked") private TopologyTemplate convertToTopologyTemplate(GraphVertex componentV) { - TopologyTemplate topologyTemplate = super.convertToComponent(componentV); - Map json = (Map) componentV.getJson(); topologyTemplate.setCompositions(json); - return topologyTemplate; } @@ -1219,13 +1219,11 @@ public class TopologyTemplateOperation extends ToscaElementOperation { log.debug("Failed to disassociate instances properties for {} error {}", toscaElementVertex.getUniqueId(), status); Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status)); } - - status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_INPUTS); + status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_OUTPUTS); if (status != JanusGraphOperationStatus.OK) { - log.debug("Failed to disassociate instances inputs for {} error {}", toscaElementVertex.getUniqueId(), status); + log.debug("Failed to disassociate instances outputs for {} error {}", toscaElementVertex.getUniqueId(), status); Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status)); } - status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.GROUPS); if (status != JanusGraphOperationStatus.OK) { log.debug("Failed to disassociate groups for {} error {}", toscaElementVertex.getUniqueId(), status); @@ -1246,6 +1244,11 @@ public class TopologyTemplateOperation extends ToscaElementOperation { log.debug("Failed to disassociate inputs for {} error {}", toscaElementVertex.getUniqueId(), status); Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status)); } + status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.OUTPUTS); + if (status != JanusGraphOperationStatus.OK) { + log.debug("Failed to disassociate outputs for {} error {}", toscaElementVertex.getUniqueId(), status); + Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status)); + } status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_INPUTS); if (status != JanusGraphOperationStatus.OK) { log.debug("Failed to disassociate instance inputs for {} error {}", toscaElementVertex.getUniqueId(), status); @@ -1306,19 +1309,14 @@ public class TopologyTemplateOperation extends ToscaElementOperation { log.debug("Failed to disassociate instance artifact for {} error {}", toscaElementVertex.getUniqueId(), status); return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status)); } - - status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, - EdgeLabelEnum.REQUIREMENTS); + status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.REQUIREMENTS); if (status != JanusGraphOperationStatus.OK) { - log.debug("Failed to disassociate requirements for {} error {}", - toscaElementVertex.getUniqueId(), status); + log.debug("Failed to disassociate requirements for {} error {}", toscaElementVertex.getUniqueId(), status); return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status)); } - status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, - EdgeLabelEnum.CAPABILITIES); + status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.CAPABILITIES); if (status != JanusGraphOperationStatus.OK) { - log.debug("Failed to disassociate capabilities for {} error {}", - toscaElementVertex.getUniqueId(), status); + log.debug("Failed to disassociate capabilities for {} error {}", toscaElementVertex.getUniqueId(), status); return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status)); } status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_INTERFACES); @@ -1326,9 +1324,14 @@ public class TopologyTemplateOperation extends ToscaElementOperation { log.debug("Failed to disassociate instances interfaces for {} error {}", toscaElementVertex.getUniqueId(), status); return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status)); } + status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.NODE_FILTER_TEMPLATE); + if (status != JanusGraphOperationStatus.OK) { + log.debug("Failed to disassociate capabilities for {} error {}", toscaElementVertex.getUniqueId(), status); + return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status)); + } + toscaElementVertex.getVertex().remove(); log.trace("Tosca element vertex for {} was removed", toscaElementVertex.getUniqueId()); - return nodeType; } @@ -1346,6 +1349,7 @@ public class TopologyTemplateOperation extends ToscaElementOperation { @Override protected StorageOperationStatus validateCategories(T toscaElementToUpdate, GraphVertex elementV) { // Product isn't supported now!! + // TODO add for Product if (toscaElementToUpdate.getComponentType() == ComponentTypeEnum.SERVICE) { return validateServiceCategory(toscaElementToUpdate, elementV); @@ -1370,22 +1374,21 @@ public class TopologyTemplateOperation extends ToscaElementOperation { StorageOperationStatus status = StorageOperationStatus.OK; List newCategoryList = toscaElementToUpdate.getCategories(); CategoryDefinition newCategory = newCategoryList.get(0); - - Either childVertex = janusGraphDao.getChildVertex(elementV, EdgeLabelEnum.CATEGORY, JsonParseFlagEnum.NoParse); + Either childVertex = janusGraphDao + .getChildVertex(elementV, EdgeLabelEnum.CATEGORY, JsonParseFlagEnum.NoParse); if (childVertex.isRight()) { - log.debug("failed to fetch {} for tosca element with id {}, error {}", EdgeLabelEnum.CATEGORY, elementV.getUniqueId(), childVertex.right().value()); + log.debug("failed to fetch {} for tosca element with id {}, error {}", EdgeLabelEnum.CATEGORY, elementV.getUniqueId(), + childVertex.right().value()); return DaoStatusConverter.convertJanusGraphStatusToStorageStatus(childVertex.right().value()); } - GraphVertex categoryV = childVertex.left().value(); Map metadataProperties = categoryV.getMetadataProperties(); String categoryNameCurrent = (String) metadataProperties.get(GraphPropertyEnum.NAME); - String newCategoryName = newCategory.getName(); if (newCategoryName != null && !newCategoryName.equals(categoryNameCurrent)) { // the category was changed - Either getCategoryVertex = categoryOperation.getCategory(newCategoryName, VertexTypeEnum.SERVICE_CATEGORY); - + Either getCategoryVertex = categoryOperation + .getCategory(newCategoryName, VertexTypeEnum.SERVICE_CATEGORY); if (getCategoryVertex.isRight()) { return getCategoryVertex.right().value(); } @@ -1396,8 +1399,8 @@ public class TopologyTemplateOperation extends ToscaElementOperation { return status; } - public Either updateDistributionStatus(String uniqueId, User user, DistributionStatusEnum distributionStatus) { - + public Either updateDistributionStatus(String uniqueId, User user, + DistributionStatusEnum distributionStatus) { Either result = null; String userId = user.getUserId(); Either getRes = findUserVertex(userId); @@ -1413,7 +1416,7 @@ public class TopologyTemplateOperation extends ToscaElementOperation { getRes = janusGraphDao.getVertexById(uniqueId, JsonParseFlagEnum.ParseMetadata); if (getRes.isRight()) { JanusGraphOperationStatus status = getRes.right().value(); - log.debug( "Cannot find service {} in the graph. status is {}", uniqueId, status); + log.debug("Cannot find service {} in the graph. status is {}", uniqueId, status); result = Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status)); } } @@ -1421,14 +1424,17 @@ public class TopologyTemplateOperation extends ToscaElementOperation { serviceVertex = getRes.left().value(); Iterator edgeIterator = serviceVertex.getVertex().edges(Direction.IN, EdgeLabelEnum.LAST_DISTRIBUTION_STATE_MODIFIER.name()); if (edgeIterator.hasNext()) { - log.debug("Remove existing edge from user to component {}. Edge type is {}", userId, uniqueId, EdgeLabelEnum.LAST_DISTRIBUTION_STATE_MODIFIER); + log.debug("Remove existing edge from user to component {}. Edge type is {}", userId, uniqueId, + EdgeLabelEnum.LAST_DISTRIBUTION_STATE_MODIFIER); edgeIterator.next().remove(); } } if (result == null) { - JanusGraphOperationStatus status = janusGraphDao.createEdge(userVertex, serviceVertex, EdgeLabelEnum.LAST_DISTRIBUTION_STATE_MODIFIER, null); + JanusGraphOperationStatus status = janusGraphDao + .createEdge(userVertex, serviceVertex, EdgeLabelEnum.LAST_DISTRIBUTION_STATE_MODIFIER, null); if (status != JanusGraphOperationStatus.OK) { - log.debug( "Failed to associate user {} to component {}. Edge type is {}", userId, uniqueId, EdgeLabelEnum.LAST_DISTRIBUTION_STATE_MODIFIER); + log.debug("Failed to associate user {} to component {}. Edge type is {}", userId, uniqueId, + EdgeLabelEnum.LAST_DISTRIBUTION_STATE_MODIFIER); result = Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status)); } } @@ -1446,8 +1452,10 @@ public class TopologyTemplateOperation extends ToscaElementOperation { } return result; } + /** * Returns list of ComponentInstanceProperty belonging to component instance capability specified by name, type and ownerId + * * @param componentId * @param instanceId * @param capabilityName @@ -1455,53 +1463,69 @@ public class TopologyTemplateOperation extends ToscaElementOperation { * @param ownerId * @return */ - public Either, StorageOperationStatus> getComponentInstanceCapabilityProperties(String componentId, String instanceId, String capabilityName, String capabilityType, String ownerId) { - + public Either, StorageOperationStatus> getComponentInstanceCapabilityProperties(String componentId, + String instanceId, + String capabilityName, + String capabilityType, + String ownerId) { Either, StorageOperationStatus> result = null; Map mapPropertiesDataDefinition = null; - Either componentByLabelAndId = getComponentByLabelAndId(componentId, ToscaElementTypeEnum.TOPOLOGY_TEMPLATE, JsonParseFlagEnum.NoParse); + Either componentByLabelAndId = getComponentByLabelAndId(componentId, + ToscaElementTypeEnum.TOPOLOGY_TEMPLATE, JsonParseFlagEnum.NoParse); if (componentByLabelAndId.isRight()) { result = Either.right(componentByLabelAndId.right().value()); } - if(componentByLabelAndId.isLeft()){ - Either, JanusGraphOperationStatus> getDataRes = getDataFromGraph(componentByLabelAndId.left().value(), EdgeLabelEnum.CALCULATED_CAP_PROPERTIES); + if (componentByLabelAndId.isLeft()) { + Either, JanusGraphOperationStatus> getDataRes = getDataFromGraph(componentByLabelAndId.left().value(), + EdgeLabelEnum.CALCULATED_CAP_PROPERTIES); if (getDataRes.isRight()) { result = Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(getDataRes.right().value())); } else { mapPropertiesDataDefinition = getDataRes.left().value(); } } - if(isNotEmptyMapOfProperties(instanceId, mapPropertiesDataDefinition)){ - result = Either.left(findComponentInstanceCapabilityProperties(instanceId, capabilityName, capabilityType, ownerId, mapPropertiesDataDefinition.get(instanceId).getMapToscaDataDefinition())); + if (isNotEmptyMapOfProperties(instanceId, mapPropertiesDataDefinition)) { + result = Either.left(findComponentInstanceCapabilityProperties(instanceId, capabilityName, capabilityType, ownerId, + mapPropertiesDataDefinition.get(instanceId).getMapToscaDataDefinition())); } return result; } - public StorageOperationStatus updateComponentInstanceCapabilityProperties(Component containerComponent, String componentInstanceId, MapCapabilityProperty instanceProperties) { - return updateToscaDataDeepElementsBlockToToscaElement(containerComponent.getUniqueId(), EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, instanceProperties, componentInstanceId); + public StorageOperationStatus updateComponentInstanceCapabilityProperties(Component containerComponent, String componentInstanceId, + MapCapabilityProperty instanceProperties) { + return updateToscaDataDeepElementsBlockToToscaElement(containerComponent.getUniqueId(), EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, + instanceProperties, componentInstanceId); } - public StorageOperationStatus updateComponentInstanceInterfaces(Component containerComponent, - String componentInstanceId, - MapInterfaceDataDefinition instanceInterfaces) { + public StorageOperationStatus updateComponentInstanceInterfaces(Component containerComponent, String componentInstanceId, + MapInterfaceDataDefinition instanceInterfaces) { if (MapUtils.isNotEmpty(instanceInterfaces.getMapToscaDataDefinition())) { - return updateToscaDataDeepElementsBlockToToscaElement(containerComponent.getUniqueId(), - EdgeLabelEnum.INST_INTERFACES, instanceInterfaces, componentInstanceId); + return updateToscaDataDeepElementsBlockToToscaElement(containerComponent.getUniqueId(), EdgeLabelEnum.INST_INTERFACES, instanceInterfaces, + componentInstanceId); } return StorageOperationStatus.OK; } + public StorageOperationStatus updateComponentInterfaces(final String componentId, final MapInterfaceDataDefinition instanceInterfaces, + final String componentInterfaceUpdatedKey) { + if (MapUtils.isNotEmpty(instanceInterfaces.getMapToscaDataDefinition())) { + return updateToscaDataDeepElementsBlockToToscaElement(componentId, EdgeLabelEnum.INTERFACE_ARTIFACTS, instanceInterfaces, + componentInterfaceUpdatedKey); + } + return StorageOperationStatus.OK; + } + private boolean isNotEmptyMapOfProperties(String instanceId, Map mapPropertiesDataDefinition) { - return MapUtils.isNotEmpty(mapPropertiesDataDefinition) && - instanceId != null && - mapPropertiesDataDefinition.get(instanceId) != null && - MapUtils.isNotEmpty(mapPropertiesDataDefinition.get(instanceId).getMapToscaDataDefinition()); + return MapUtils.isNotEmpty(mapPropertiesDataDefinition) && instanceId != null && mapPropertiesDataDefinition.get(instanceId) != null + && MapUtils.isNotEmpty(mapPropertiesDataDefinition.get(instanceId).getMapToscaDataDefinition()); } - private List findComponentInstanceCapabilityProperties(String instanceId, String capabilityName, String capabilityType, String ownerId, Map propertiesMap) { + private List findComponentInstanceCapabilityProperties(String instanceId, String capabilityName, String capabilityType, + String ownerId, + Map propertiesMap) { List capPropsList = null; - for(Entry capProp : propertiesMap.entrySet()){ + for (Entry capProp : propertiesMap.entrySet()) { if (isBelongingPropertyMap(instanceId, capabilityName, capabilityType, ownerId, capProp)) { Map capMap = capProp.getValue().getMapToscaDataDefinition(); if (capMap != null && !capMap.isEmpty()) { @@ -1510,27 +1534,30 @@ public class TopologyTemplateOperation extends ToscaElementOperation { } } } - if(capPropsList == null){ + if (capPropsList == null) { capPropsList = new ArrayList<>(); } return capPropsList; } - private boolean isBelongingPropertyMap(String instanceId, String capabilityName, String capabilityType, String ownerId, Entry capProp) { + private boolean isBelongingPropertyMap(String instanceId, String capabilityName, String capabilityType, String ownerId, + Entry capProp) { if (capProp != null) { - String[] path = capProp.getKey().split(ModelConverter.CAP_PROP_DELIM ); + String[] path = capProp.getKey().split(ModelConverter.CAP_PROP_DELIM); if (path.length < 4) { log.debug("wrong key format for capabilty, key {}", capProp); return false; } - return path[path.length - 2].equals(capabilityType) && path[path.length - 1].equals(capabilityName) && path[1].equals(ownerId) && path[0].equals(instanceId); + return path[path.length - 2].equals(capabilityType) && path[path.length - 1].equals(capabilityName) && path[1].equals(ownerId) && path[0] + .equals(instanceId); } return false; } public StorageOperationStatus addPolicyToToscaElement(GraphVertex componentV, PolicyDefinition policyDefinition, int counter) { fillPolicyDefinition(componentV, policyDefinition, counter); - return addToscaDataToToscaElement(componentV, EdgeLabelEnum.POLICIES, VertexTypeEnum.POLICIES, policyDefinition, JsonPresentationFields.UNIQUE_ID); + return addToscaDataToToscaElement(componentV, EdgeLabelEnum.POLICIES, VertexTypeEnum.POLICIES, policyDefinition, + JsonPresentationFields.UNIQUE_ID); } public StorageOperationStatus addPoliciesToToscaElement(GraphVertex componentV, List policies) { @@ -1538,24 +1565,31 @@ public class TopologyTemplateOperation extends ToscaElementOperation { } public StorageOperationStatus updatePolicyOfToscaElement(GraphVertex componentV, PolicyDefinition policyDefinition) { - return updateToscaDataOfToscaElement(componentV, EdgeLabelEnum.POLICIES, VertexTypeEnum.POLICIES, policyDefinition, JsonPresentationFields.UNIQUE_ID); + return updateToscaDataOfToscaElement(componentV, EdgeLabelEnum.POLICIES, VertexTypeEnum.POLICIES, policyDefinition, + JsonPresentationFields.UNIQUE_ID); } public StorageOperationStatus updatePoliciesOfToscaElement(GraphVertex componentV, List policiesDefinitions) { - return updateToscaDataOfToscaElement(componentV, EdgeLabelEnum.POLICIES, VertexTypeEnum.POLICIES, policiesDefinitions, JsonPresentationFields.UNIQUE_ID); + return updateToscaDataOfToscaElement(componentV, EdgeLabelEnum.POLICIES, VertexTypeEnum.POLICIES, policiesDefinitions, + JsonPresentationFields.UNIQUE_ID); } public StorageOperationStatus removePolicyFromToscaElement(GraphVertex componentV, String policyId) { - return deleteToscaDataElement(componentV, EdgeLabelEnum.POLICIES, VertexTypeEnum.POLICIES, policyId, JsonPresentationFields.UNIQUE_ID); + return deleteToscaDataElement(componentV, EdgeLabelEnum.POLICIES, policyId); } public StorageOperationStatus updateGroupOfToscaElement(GraphVertex componentV, GroupDefinition groupDefinition) { - return updateToscaDataOfToscaElement(componentV, EdgeLabelEnum.GROUPS, VertexTypeEnum.GROUPS, groupDefinition, JsonPresentationFields.CI_INVARIANT_NAME); + return updateToscaDataOfToscaElement(componentV, EdgeLabelEnum.GROUPS, VertexTypeEnum.GROUPS, groupDefinition, + JsonPresentationFields.CI_INVARIANT_NAME); } private void fillPolicyDefinition(GraphVertex componentV, PolicyDefinition policyDefinition, int counter) { - String policyName = buildSubComponentName((String) componentV.getJsonMetadataField(JsonPresentationFields.NAME), policyDefinition.getPolicyTypeName(), counter); - policyDefinition.setName(policyName); + String policyName = policyDefinition.getName(); + if (StringUtils.isBlank(policyName)) { + policyName = buildSubComponentName((String) componentV.getJsonMetadataField(JsonPresentationFields.NAME), + policyDefinition.getPolicyTypeName(), counter); + policyDefinition.setName(policyName); + } policyDefinition.setInvariantName(policyName); policyDefinition.setComponentName((String) componentV.getJsonMetadataField(JsonPresentationFields.NAME)); policyDefinition.setUniqueId(UniqueIdBuilder.buildPolicyUniqueId(componentV.getUniqueId(), policyName)); @@ -1563,43 +1597,50 @@ public class TopologyTemplateOperation extends ToscaElementOperation { policyDefinition.setPolicyUUID(UniqueIdBuilder.generateUUID()); } - public static String buildSubComponentName(String componentName, String subComponentTypeName, int counter) { - String normalizedComponentName = ValidationUtils.normalizeComponentInstanceName(componentName); - String typeSuffix = subComponentTypeName.substring(subComponentTypeName.lastIndexOf('.') + 1, subComponentTypeName.length()); - return normalizedComponentName + Constants.GROUP_POLICY_NAME_DELIMETER + typeSuffix + Constants.GROUP_POLICY_NAME_DELIMETER + counter; - } - - void revertNamesOfCalculatedCapabilitiesRequirements(String componentId, TopologyTemplate toscaElement) { - if(MapUtils.isNotEmpty(toscaElement.getComponentInstances()) || MapUtils.isNotEmpty(toscaElement.getGroups())){ - GraphVertex toscaElementV = janusGraphDao.getVertexById(componentId, JsonParseFlagEnum.NoParse) - .left() - .on(this::throwStorageException); - if(MapUtils.isNotEmpty(toscaElement.getComponentInstances())){ - toscaElement.getComponentInstances().values().forEach(i -> CapabilityRequirementNameResolver.revertNamesOfCalculatedCapabilitiesRequirements(toscaElement, i.getUniqueId(), this::getOriginToscaElement)); + protected void revertNamesOfCalculatedCapabilitiesRequirements(String componentId, TopologyTemplate toscaElement) { + if (MapUtils.isNotEmpty(toscaElement.getComponentInstances()) || MapUtils.isNotEmpty(toscaElement.getGroups())) { + GraphVertex toscaElementV = janusGraphDao.getVertexById(componentId, JsonParseFlagEnum.NoParse).left().on(this::throwStorageException); + if (MapUtils.isNotEmpty(toscaElement.getComponentInstances())) { + toscaElement.getComponentInstances().values().forEach(i -> CapabilityRequirementNameResolver + .revertNamesOfCalculatedCapabilitiesRequirements(toscaElement, i.getUniqueId(), this::getOriginToscaElement)); } - if(MapUtils.isNotEmpty(toscaElement.getGroups())){ - toscaElement.getGroups().values().forEach(g -> CapabilityRequirementNameResolver.revertNamesOfCalculatedCapabilitiesRequirements(toscaElement, g.getUniqueId(), this::getOriginToscaElement)); + if (MapUtils.isNotEmpty(toscaElement.getGroups())) { + toscaElement.getGroups().values().forEach(g -> CapabilityRequirementNameResolver + .revertNamesOfCalculatedCapabilitiesRequirements(toscaElement, g.getUniqueId(), this::getOriginToscaElement)); } - topologyTemplateOperation.updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_CAPABILITIES, VertexTypeEnum.CALCULATED_CAPABILITIES, toscaElement.getCalculatedCapabilities()); - topologyTemplateOperation.updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_REQUIREMENTS, VertexTypeEnum.CALCULATED_REQUIREMENTS, toscaElement.getCalculatedRequirements()); - topologyTemplateOperation.updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, VertexTypeEnum.CALCULATED_CAP_PROPERTIES, toscaElement.getCalculatedCapabilitiesProperties()); + topologyTemplateOperation + .updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_CAPABILITIES, VertexTypeEnum.CALCULATED_CAPABILITIES, + toscaElement.getCalculatedCapabilities()); + topologyTemplateOperation + .updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_REQUIREMENTS, VertexTypeEnum.CALCULATED_REQUIREMENTS, + toscaElement.getCalculatedRequirements()); + topologyTemplateOperation + .updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, VertexTypeEnum.CALCULATED_CAP_PROPERTIES, + toscaElement.getCalculatedCapabilitiesProperties()); } } public void updateNamesOfCalculatedCapabilitiesRequirements(String componentId, TopologyTemplate toscaElement) { - if(MapUtils.isNotEmpty(toscaElement.getComponentInstances()) || MapUtils.isNotEmpty(toscaElement.getGroups())){ - GraphVertex toscaElementV = janusGraphDao.getVertexById(componentId, JsonParseFlagEnum.NoParse) - .left() - .on(this::throwStorageException); - if(MapUtils.isNotEmpty(toscaElement.getComponentInstances())){ - toscaElement.getComponentInstances().values().forEach(i -> CapabilityRequirementNameResolver.updateNamesOfCalculatedCapabilitiesRequirements(toscaElement, i.getUniqueId(), i.getNormalizedName(), this::getOriginToscaElement)); + if (MapUtils.isNotEmpty(toscaElement.getComponentInstances()) || MapUtils.isNotEmpty(toscaElement.getGroups())) { + GraphVertex toscaElementV = janusGraphDao.getVertexById(componentId, JsonParseFlagEnum.NoParse).left().on(this::throwStorageException); + if (MapUtils.isNotEmpty(toscaElement.getComponentInstances())) { + toscaElement.getComponentInstances().values().forEach(i -> CapabilityRequirementNameResolver + .updateNamesOfCalculatedCapabilitiesRequirements(toscaElement, i.getUniqueId(), i.getNormalizedName(), + this::getOriginToscaElement)); } - if(MapUtils.isNotEmpty(toscaElement.getGroups())){ - toscaElement.getGroups().values().forEach(g -> CapabilityRequirementNameResolver.updateNamesOfCalculatedCapabilitiesRequirements(toscaElement, g.getUniqueId(), g.getName(), this::getOriginToscaElement)); + if (MapUtils.isNotEmpty(toscaElement.getGroups())) { + toscaElement.getGroups().values().forEach(g -> CapabilityRequirementNameResolver + .updateNamesOfCalculatedCapabilitiesRequirements(toscaElement, g.getUniqueId(), g.getName(), this::getOriginToscaElement)); } - topologyTemplateOperation.updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_CAPABILITIES, VertexTypeEnum.CALCULATED_CAPABILITIES, toscaElement.getCalculatedCapabilities()); - topologyTemplateOperation.updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_REQUIREMENTS, VertexTypeEnum.CALCULATED_REQUIREMENTS, toscaElement.getCalculatedRequirements()); - topologyTemplateOperation.updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, VertexTypeEnum.CALCULATED_CAP_PROPERTIES, toscaElement.getCalculatedCapabilitiesProperties()); + topologyTemplateOperation + .updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_CAPABILITIES, VertexTypeEnum.CALCULATED_CAPABILITIES, + toscaElement.getCalculatedCapabilities()); + topologyTemplateOperation + .updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_REQUIREMENTS, VertexTypeEnum.CALCULATED_REQUIREMENTS, + toscaElement.getCalculatedRequirements()); + topologyTemplateOperation + .updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, VertexTypeEnum.CALCULATED_CAP_PROPERTIES, + toscaElement.getCalculatedCapabilitiesProperties()); } } @@ -1607,13 +1648,12 @@ public class TopologyTemplateOperation extends ToscaElementOperation { log.debug("#getOriginToscaElement - origin name: {}", instance.getComponentName()); ToscaElementTypeEnum elementType = detectToscaType(instance.getOriginType()); Either getOriginRes; - if(elementType == ToscaElementTypeEnum.TOPOLOGY_TEMPLATE){ + if (elementType == ToscaElementTypeEnum.TOPOLOGY_TEMPLATE) { getOriginRes = this.getToscaElement(CapabilityRequirementNameResolver.getActualComponentUid(instance), getFilter()); - } else { getOriginRes = nodeTypeOperation.getToscaElement(CapabilityRequirementNameResolver.getActualComponentUid(instance), getFilter()); } - if(getOriginRes.isRight()){ + if (getOriginRes.isRight()) { log.debug("Failed to get an origin component with uniqueId {}", CapabilityRequirementNameResolver.getActualComponentUid(instance)); throw new StorageException(getOriginRes.right().value()); } @@ -1622,11 +1662,8 @@ public class TopologyTemplateOperation extends ToscaElementOperation { private ToscaElementTypeEnum detectToscaType(OriginTypeEnum originType) { log.debug("#detectToscaType - type: {}", originType); - if(originType == OriginTypeEnum.VFC - || originType == OriginTypeEnum.CP - || originType == OriginTypeEnum.VL - || originType == OriginTypeEnum.Configuration - || originType == OriginTypeEnum.VFCMT){ + if (originType == OriginTypeEnum.VFC || originType == OriginTypeEnum.CP || originType == OriginTypeEnum.VL + || originType == OriginTypeEnum.Configuration || originType == OriginTypeEnum.VFCMT) { return ToscaElementTypeEnum.NODE_TYPE; } else { return ToscaElementTypeEnum.TOPOLOGY_TEMPLATE; @@ -1640,43 +1677,38 @@ public class TopologyTemplateOperation extends ToscaElementOperation { filter.setIgnoreRequirements(false); return filter; } + public void updateCapReqPropertiesOwnerId(String componentId, TopologyTemplate toscaElement) { - GraphVertex toscaElementV = janusGraphDao.getVertexById(componentId, JsonParseFlagEnum.NoParse) - .left().on(this::throwStorageException); + GraphVertex toscaElementV = janusGraphDao.getVertexById(componentId, JsonParseFlagEnum.NoParse).left().on(this::throwStorageException); updateCapOwnerId(toscaElement, componentId); updateReqOwnerId(toscaElement, componentId); updatePropertiesOwnerId(toscaElement, componentId); topologyTemplateOperation - - .updateFullToscaData(toscaElementV, EdgeLabelEnum.CAPABILITIES, - VertexTypeEnum.CAPABILITIES, toscaElement.getCapabilities()); + .updateFullToscaData(toscaElementV, EdgeLabelEnum.CAPABILITIES, VertexTypeEnum.CAPABILITIES, toscaElement.getCapabilities()); topologyTemplateOperation - .updateFullToscaData(toscaElementV, EdgeLabelEnum.REQUIREMENTS, - VertexTypeEnum.REQUIREMENTS, toscaElement.getRequirements()); + .updateFullToscaData(toscaElementV, EdgeLabelEnum.REQUIREMENTS, VertexTypeEnum.REQUIREMENTS, toscaElement.getRequirements()); topologyTemplateOperation - .updateFullToscaData(toscaElementV, EdgeLabelEnum.PROPERTIES, - VertexTypeEnum.PROPERTIES, toscaElement.getProperties()); + .updateFullToscaData(toscaElementV, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, toscaElement.getProperties()); } private void updateCapOwnerId(ToscaElement toscaElement, String ownerId) { - if(MapUtils.isNotEmpty(toscaElement.getCapabilities())) { + if (MapUtils.isNotEmpty(toscaElement.getCapabilities())) { toscaElement.getCapabilities().values().stream().flatMap(listCapDef -> listCapDef.getListToscaDataDefinition().stream()) - .forEach(capabilityDefinition -> capabilityDefinition.setOwnerId(ownerId)); + .forEach(capabilityDefinition -> capabilityDefinition.setOwnerId(ownerId)); } } private void updateReqOwnerId(ToscaElement toscaElement, String ownerId) { - if(MapUtils.isNotEmpty(toscaElement.getRequirements())) { + if (MapUtils.isNotEmpty(toscaElement.getRequirements())) { toscaElement.getRequirements().values().stream().flatMap(listReqDef -> listReqDef.getListToscaDataDefinition().stream()) - .forEach(requirementDefinition -> requirementDefinition.setOwnerId(ownerId)); + .forEach(requirementDefinition -> requirementDefinition.setOwnerId(ownerId)); } } private void updatePropertiesOwnerId(ToscaElement toscaElement, String ownerId) { Map properties = toscaElement.getProperties(); - if(MapUtils.isNotEmpty(properties)) { + if (MapUtils.isNotEmpty(properties)) { properties.values().forEach(propertyDataDefinition -> propertyDataDefinition.setParentUniqueId(ownerId)); } } - }