/*- * ============LICENSE_START======================================================= * SDC * ================================================================================ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * 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.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.tinkerpop.gremlin.structure.Direction; import org.apache.tinkerpop.gremlin.structure.Edge; import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus; import org.openecomp.sdc.be.dao.jsongraph.GraphVertex; 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.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; import org.openecomp.sdc.be.datatypes.elements.DataTypeDataDefinition; import org.openecomp.sdc.be.datatypes.elements.ForwardingPathDataDefinition; import org.openecomp.sdc.be.datatypes.elements.GroupDataDefinition; 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; import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition; import org.openecomp.sdc.be.datatypes.elements.SubstitutionFilterDataDefinition; import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum; import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields; import org.openecomp.sdc.be.datatypes.enums.OriginTypeEnum; import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition; import org.openecomp.sdc.be.model.Component; import org.openecomp.sdc.be.model.ComponentInstanceProperty; import org.openecomp.sdc.be.model.ComponentParametersView; import org.openecomp.sdc.be.model.DistributionStatusEnum; import org.openecomp.sdc.be.model.GroupDefinition; import org.openecomp.sdc.be.model.PolicyDefinition; import org.openecomp.sdc.be.model.User; import org.openecomp.sdc.be.model.category.CategoryDefinition; import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.TopologyTemplate; import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.ToscaElement; import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.ToscaElementTypeEnum; import org.openecomp.sdc.be.model.jsonjanusgraph.utils.CapabilityRequirementNameResolver; import org.openecomp.sdc.be.model.jsonjanusgraph.utils.ModelConverter; import org.openecomp.sdc.be.model.operations.StorageException; import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; import org.openecomp.sdc.be.model.operations.impl.DaoStatusConverter; 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.EcompErrorSeverity; 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 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) { 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); 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); } StorageOperationStatus associateGroups = associateGroupsToComponent(topologyTemplateVertex, topologyTemplate); if (associateGroups != StorageOperationStatus.OK) { return Either.right(associateGroups); } StorageOperationStatus associatePolicies = associatePoliciesToComponent(topologyTemplateVertex, topologyTemplate); if (associatePolicies != StorageOperationStatus.OK) { return Either.right(associatePolicies); } StorageOperationStatus associateInstAttr = associateInstAttributesToComponent(topologyTemplateVertex, topologyTemplate); if (associateInstAttr != StorageOperationStatus.OK) { return Either.right(associateInstAttr); } StorageOperationStatus associateInstProperties = associateInstPropertiesToComponent(topologyTemplateVertex, topologyTemplate); if (associateInstProperties != StorageOperationStatus.OK) { return Either.right(associateInstProperties); } StorageOperationStatus associateInstInputs = associateInstInputsToComponent(topologyTemplateVertex, topologyTemplate); if (associateInstProperties != 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); } StorageOperationStatus associateCapProperties = associateCapPropertiesToResource(topologyTemplateVertex, topologyTemplate); 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) { return Either.right(associatePathProperties); } return Either.left(topologyTemplate); } private StorageOperationStatus associatePoliciesToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) { return associatePoliciesToComponent(nodeTypeVertex, topologyTemplate.getPolicies()); } private StorageOperationStatus associatePoliciesToComponent(GraphVertex nodeTypeVertex, Map policies) { 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); if (assosiateElementToData.isRight()) { return assosiateElementToData.right().value(); } } return StorageOperationStatus.OK; } private StorageOperationStatus associateForwardingPathToResource(GraphVertex topologyTemplateVertex, TopologyTemplate topologyTemplate) { Map forwardingPaths = topologyTemplate.getForwardingPaths(); return associateForwardingPathToComponent(topologyTemplateVertex, forwardingPaths); } private StorageOperationStatus associateCapPropertiesToResource(GraphVertex topologyTemplateVertex, TopologyTemplate topologyTemplate) { Map calculatedCapProperties = topologyTemplate.getCalculatedCapabilitiesProperties(); if (MapUtils.isNotEmpty(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); if (associateElementToData.isRight()) { return associateElementToData.right().value(); } } return StorageOperationStatus.OK; } 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); 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); 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 (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); 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); 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 (associateElementToData.isRight()) { return associateElementToData.right().value(); } } return StorageOperationStatus.OK; } 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()); a.setUniqueId(uniqueId); }); 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); 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); 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 (associateElementToData.isRight()) { return associateElementToData.right().value(); } } return StorageOperationStatus.OK; } 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); if (assosiateElementToData.isRight()) { return assosiateElementToData.right().value(); } } return StorageOperationStatus.OK; } public StorageOperationStatus associateInstPropertiesToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) { Map instProps = topologyTemplate.getInstProperties(); return associateInstPropertiesToComponent(nodeTypeVertex, instProps); } public StorageOperationStatus associateInstInputsToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) { Map instProps = topologyTemplate.getInstInputs(); return associateInstInputsToComponent(nodeTypeVertex, instProps); } public StorageOperationStatus associateInstGroupsToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) { Map instGroups = topologyTemplate.getInstGroups(); 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); if (assosiateElementToData.isRight()) { return assosiateElementToData.right().value(); } } return StorageOperationStatus.OK; } public StorageOperationStatus associateInstInputsToComponent(GraphVertex nodeTypeVertex, Map instInputs) { if (instInputs != null && !instInputs.isEmpty()) { Either assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INST_INPUTS, EdgeLabelEnum.INST_INPUTS, instInputs); if (assosiateElementToData.isRight()) { return assosiateElementToData.right().value(); } } 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(); } } 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; } }); } return StorageOperationStatus.OK; } public 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); } private StorageOperationStatus associateInstanceArtifactsToComponent(GraphVertex nodeTypeVertex, Map instProps, VertexTypeEnum vertexType, EdgeLabelEnum edgeLabel) { if (instProps != null && !instProps.isEmpty()) { Either assosiateElementToData = associateElementToData(nodeTypeVertex, vertexType, edgeLabel, instProps); if (assosiateElementToData.isRight()) { return assosiateElementToData.right().value(); } } return StorageOperationStatus.OK; } 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); if (assosiateElementToData.isRight()) { return assosiateElementToData.right().value(); } Map fullFilled = new HashMap<>(); 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); if (assosiateElementToData.isRight()) { return assosiateElementToData.right().value(); } Map fullFilled = new HashMap<>(); 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); } return StorageOperationStatus.OK; } 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)); } 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()) { return Either.right(error.get()); } return Either.left(dataVertex); } private StorageOperationStatus associateInstAttributesToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) { Map instAttr = topologyTemplate.getInstAttributes(); return associateInstAttributeToComponent(nodeTypeVertex, instAttr); } public StorageOperationStatus associateForwardingPathToComponent(GraphVertex nodeTypeVertex, Map forwardingPathMap) { if (forwardingPathMap != null && !forwardingPathMap.isEmpty()) { Either assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.FORWARDING_PATH, EdgeLabelEnum.FORWARDING_PATH, forwardingPathMap); if (assosiateElementToData.isRight()) { return assosiateElementToData.right().value(); } } return StorageOperationStatus.OK; } public StorageOperationStatus associateInstAttributeToComponent(GraphVertex nodeTypeVertex, Map instAttr) { if (instAttr != null && !instAttr.isEmpty()) { Either assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INST_ATTRIBUTES, EdgeLabelEnum.INST_ATTRIBUTES, instAttr); if (assosiateElementToData.isRight()) { return assosiateElementToData.right().value(); } } return StorageOperationStatus.OK; } 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); if (assosiateElementToData.isRight()) { return assosiateElementToData.right().value(); } } return StorageOperationStatus.OK; } private StorageOperationStatus associateGroupsToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) { return associateGroupsToComponent(nodeTypeVertex, topologyTemplate.getGroups()); } public StorageOperationStatus associateInputsToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) { Map inputs = topologyTemplate.getInputs(); return associateInputsToComponent(nodeTypeVertex, inputs, topologyTemplate.getUniqueId()); } 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); if (assosiateElementToData.isRight()) { return assosiateElementToData.right().value(); } } return StorageOperationStatus.OK; } private GraphVertex fillMetadata(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate, JsonParseFlagEnum flag) { nodeTypeVertex.setLabel(VertexTypeEnum.TOPOLOGY_TEMPLATE); fillCommonMetadata(nodeTypeVertex, topologyTemplate); if (flag == JsonParseFlagEnum.ParseAll || flag == JsonParseFlagEnum.ParseJson) { nodeTypeVertex.setJson(topologyTemplate.getCompositions()); } nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.CSAR_UUID, topologyTemplate.getMetadataValue(JsonPresentationFields.CSAR_UUID)); nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.DISTRIBUTION_STATUS, topologyTemplate.getMetadataValue(JsonPresentationFields.DISTRIBUTION_STATUS)); return nodeTypeVertex; } private StorageOperationStatus assosiateMetadataToCategory(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) { if (topologyTemplate.getResourceType() == null) { // service return associateServiceMetadataToCategory(nodeTypeVertex, topologyTemplate); } else { // VF return assosiateResourceMetadataToCategory(nodeTypeVertex, topologyTemplate); } } private StorageOperationStatus associateServiceMetadataToCategory(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) { String categoryName = topologyTemplate.getCategories().get(0).getName(); 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; } 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()); return DaoStatusConverter.convertJanusGraphStatusToStorageStatus(createEdge); } return StorageOperationStatus.OK; } @Override public Either getToscaElement(String uniqueId, ComponentParametersView componentParametersView) { JsonParseFlagEnum parseFlag = componentParametersView.detectParseFlag(); 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()) { status = setCreatorFromGraph(componentV, toscaElement); if (status != JanusGraphOperationStatus.OK) { return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status)); } status = setLastModifierFromGraph(componentV, toscaElement); if (status != JanusGraphOperationStatus.OK) { return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status)); } } if (!componentParametersView.isIgnoreCategories()) { status = setTopologyTempalteCategoriesFromGraph(componentV, toscaElement); if (status != JanusGraphOperationStatus.OK) { return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status)); } } if (!componentParametersView.isIgnoreArtifacts()) { JanusGraphOperationStatus storageStatus = setAllArtifactsFromGraph(componentV, toscaElement); if (storageStatus != JanusGraphOperationStatus.OK) { return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(storageStatus)); } } if (!componentParametersView.isIgnoreComponentInstancesProperties()) { status = setComponentInstancesPropertiesFromGraph(componentV, toscaElement); if (status != JanusGraphOperationStatus.OK) { return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status)); } } if (!componentParametersView.isIgnoreComponentInstancesAttributes()) { status = setComponentInstancesAttributesFromGraph(componentV, toscaElement); if (status != JanusGraphOperationStatus.OK) { return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status)); } } if (!componentParametersView.isIgnoreCapabilities()) { status = setCapabilitiesFromGraph(componentV, toscaElement); if (status != JanusGraphOperationStatus.OK) { return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status)); } } if (!componentParametersView.isIgnoreRequirements()) { status = setRequirementsFromGraph(componentV, toscaElement); if (status != JanusGraphOperationStatus.OK) { return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status)); } } if (!componentParametersView.isIgnoreAllVersions()) { status = setAllVersions(componentV, toscaElement); if (status != JanusGraphOperationStatus.OK) { return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status)); } } if (!componentParametersView.isIgnoreAdditionalInformation()) { status = setAdditionalInformationFromGraph(componentV, toscaElement); if (status != JanusGraphOperationStatus.OK) { 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); 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); } private JanusGraphOperationStatus setDataTypesFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) { Either, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.DATA_TYPES); if (result.isLeft()) { toscaElement.setDataTypes(result.left().value()); } else { if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) { return result.right().value(); } } 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()) { toscaElement.setPolicies(result.left().value()); } else { if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) { return result.right().value(); } } return JanusGraphOperationStatus.OK; } private JanusGraphOperationStatus setInterfacesFromGraph(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 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())); } else { if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) { return result.right().value(); } } return JanusGraphOperationStatus.OK; } 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); if (assosiateElementToData.isRight()) { return assosiateElementToData.right().value(); } } return StorageOperationStatus.OK; } private JanusGraphOperationStatus setForwardingGraphPropertiesFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) { Either, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.FORWARDING_PATH); if (result.isLeft()) { topologyTemplate.setForwardingPaths(result.left().value()); } else { if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) { return result.right().value(); } } return JanusGraphOperationStatus.OK; } private JanusGraphOperationStatus setComponentInstancesCapPropertiesFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) { Either, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES); if (result.isLeft()) { topologyTemplate.setCalculatedCapabilitiesProperties(result.left().value()); } else { if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) { return result.right().value(); } } Either, JanusGraphOperationStatus> capPropResult = getDataFromGraph(componentV, EdgeLabelEnum.CAPABILITIES_PROPERTIES); if (capPropResult.isLeft()) { topologyTemplate.setCapabilitiesProperties(capPropResult.left().value()); } else { if (capPropResult.right().value() != JanusGraphOperationStatus.NOT_FOUND) { return capPropResult.right().value(); } } return JanusGraphOperationStatus.OK; } private JanusGraphOperationStatus setPropertiesFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) { Either, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.PROPERTIES); if (result.isLeft()) { toscaElement.setProperties(result.left().value()); } else { if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) { return result.right().value(); } } return JanusGraphOperationStatus.OK; } private JanusGraphOperationStatus setInstGroupsFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) { Either, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INST_GROUPS); if (result.isLeft()) { topologyTemplate.setInstGroups(result.left().value()); } else { if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) { return result.right().value(); } } return JanusGraphOperationStatus.OK; } private JanusGraphOperationStatus setComponentInstancesPropertiesFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) { Either, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INST_PROPERTIES); if (result.isLeft()) { topologyTemplate.setInstProperties(result.left().value()); } else { if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) { return result.right().value(); } } return JanusGraphOperationStatus.OK; } private JanusGraphOperationStatus setComponentInstancesAttributesFromGraph(final GraphVertex componentV, final TopologyTemplate topologyTemplate) { 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) { return result.right().value(); } return JanusGraphOperationStatus.OK; } private JanusGraphOperationStatus setComponentInstancesInputsFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) { Either, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INST_INPUTS); if (result.isLeft()) { topologyTemplate.setInstInputs(result.left().value()); } else { if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) { return result.right().value(); } } return JanusGraphOperationStatus.OK; } 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 { if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) { return result.right().value(); } } return JanusGraphOperationStatus.OK; } private JanusGraphOperationStatus setSubstitutionFilterComponentFromGraph(final GraphVertex componentV, final TopologyTemplate topologyTemplate) { final Either, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.SUBSTITUTION_FILTER_TEMPLATE); if (result.isLeft()) { 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(); } } return JanusGraphOperationStatus.OK; } @Override protected JanusGraphOperationStatus setRequirementsFromGraph(GraphVertex componentV, T toscaElement) { Either, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.CALCULATED_REQUIREMENTS); if (result.isLeft()) { ((TopologyTemplate) toscaElement).setCalculatedRequirements(result.left().value()); } else { if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) { return result.right().value(); } } result = getDataFromGraph(componentV, EdgeLabelEnum.FULLFILLED_REQUIREMENTS); if (result.isLeft()) { ((TopologyTemplate) toscaElement).setFullfilledRequirements(result.left().value()); } else { if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) { return result.right().value(); } } Either, JanusGraphOperationStatus> requirementResult = getDataFromGraph(componentV, EdgeLabelEnum.REQUIREMENTS); if (requirementResult.isLeft()) { toscaElement.setRequirements(requirementResult.left().value()); } else { if (requirementResult.right().value() != JanusGraphOperationStatus.NOT_FOUND) { return requirementResult.right().value(); } } return JanusGraphOperationStatus.OK; } protected JanusGraphOperationStatus setCapabilitiesFromGraph(GraphVertex componentV, T toscaElement) { Either, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.CALCULATED_CAPABILITIES); if (result.isLeft()) { ((TopologyTemplate) toscaElement).setCalculatedCapabilities(result.left().value()); } else { if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) { return result.right().value(); } } result = getDataFromGraph(componentV, EdgeLabelEnum.FULLFILLED_CAPABILITIES); if (result.isLeft()) { ((TopologyTemplate) toscaElement).setFullfilledCapabilities(result.left().value()); } else { if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) { return result.right().value(); } } Either, JanusGraphOperationStatus> capabilitiesResult = getDataFromGraph(componentV, EdgeLabelEnum.CAPABILITIES); if (capabilitiesResult.isLeft()) { toscaElement.setCapabilities(capabilitiesResult.left().value()); } else { if (capabilitiesResult.right().value() != JanusGraphOperationStatus.NOT_FOUND) { return capabilitiesResult.right().value(); } } return JanusGraphOperationStatus.OK; } private JanusGraphOperationStatus setAllArtifactsFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) { JanusGraphOperationStatus storageStatus = setArtifactsFromGraph(componentV, toscaElement); if (storageStatus != JanusGraphOperationStatus.OK) { return storageStatus; } Either, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.SERVICE_API_ARTIFACTS); if (result.isLeft()) { toscaElement.setServiceApiArtifacts(result.left().value()); } else { if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) { return result.right().value(); } } Either, JanusGraphOperationStatus> resultInstArt = getDataFromGraph(componentV, EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS); if (resultInstArt.isLeft()) { toscaElement.setInstDeploymentArtifacts(resultInstArt.left().value()); } else { if (resultInstArt.right().value() != JanusGraphOperationStatus.NOT_FOUND) { return resultInstArt.right().value(); } } Either, JanusGraphOperationStatus> instanceArt = getDataFromGraph(componentV, EdgeLabelEnum.INSTANCE_ARTIFACTS); if (instanceArt.isLeft()) { toscaElement.setInstanceArtifacts(instanceArt.left().value()); } else { if (instanceArt.right().value() != JanusGraphOperationStatus.NOT_FOUND) { return instanceArt.right().value(); } } return JanusGraphOperationStatus.OK; } private JanusGraphOperationStatus setInputsFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) { Either, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INPUTS); if (result.isLeft()) { toscaElement.setInputs(result.left().value()); } else { if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) { return result.right().value(); } } Either, JanusGraphOperationStatus> capabilitiesResult = getDataFromGraph(componentV, EdgeLabelEnum.CAPABILITIES); if (capabilitiesResult.isLeft()) { toscaElement.setCapabilities(capabilitiesResult.left().value()); } else { if (capabilitiesResult.right().value() != JanusGraphOperationStatus.NOT_FOUND) { return capabilitiesResult.right().value(); } } 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()) { toscaElement.setGroups(result.left().value()); } else { if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) { return result.right().value(); } } return JanusGraphOperationStatus.OK; } 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; } return JanusGraphOperationStatus.OK; } 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()); return childVertex.right().value(); } GraphVertex categoryV = childVertex.left().value(); Map metadataProperties = categoryV.getMetadataProperties(); CategoryDefinition category = new CategoryDefinition(); 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); 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; } @Override public Either deleteToscaElement(GraphVertex toscaElementVertex) { Either nodeType = getToscaElement(toscaElementVertex, new ComponentParametersView()); if (nodeType.isRight()) { log.debug("Failed to fetch tosca element {} error {}", toscaElementVertex.getUniqueId(), nodeType.right().value()); return nodeType; } JanusGraphOperationStatus status = disassociateAndDeleteCommonElements(toscaElementVertex); if (status != JanusGraphOperationStatus.OK) { Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status)); } status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_ATTRIBUTES); if (status != JanusGraphOperationStatus.OK) { log.debug("Failed to disassociate instances attributes for {} error {}", toscaElementVertex.getUniqueId(), status); Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status)); } status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_PROPERTIES); if (status != JanusGraphOperationStatus.OK) { 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); if (status != JanusGraphOperationStatus.OK) { log.debug("Failed to disassociate instances inputs 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); Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status)); } status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.POLICIES); if (status != JanusGraphOperationStatus.OK) { log.debug("Failed to disassociate policies for {} error {}", toscaElementVertex.getUniqueId(), status); Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status)); } status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_GROUPS); if (status != JanusGraphOperationStatus.OK) { log.debug("Failed to disassociate instance groups for {} error {}", toscaElementVertex.getUniqueId(), status); Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status)); } status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INPUTS); if (status != JanusGraphOperationStatus.OK) { log.debug("Failed to disassociate inputs 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); Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status)); } status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.CAPABILITIES_PROPERTIES); if (status != JanusGraphOperationStatus.OK) { log.debug("Failed to disassociate capabilities properties for {} error {}", toscaElementVertex.getUniqueId(), status); Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status)); } status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.CALCULATED_CAPABILITIES); if (status != JanusGraphOperationStatus.OK) { log.debug("Failed to disassociate calculated capabiliites for {} error {}", toscaElementVertex.getUniqueId(), status); Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status)); } status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.FULLFILLED_CAPABILITIES); if (status != JanusGraphOperationStatus.OK) { log.debug("Failed to disassociate fullfilled capabilities for {} error {}", toscaElementVertex.getUniqueId(), status); Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status)); } status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES); if (status != JanusGraphOperationStatus.OK) { log.debug("Failed to disassociate calculated capabiliites properties for {} error {}", toscaElementVertex.getUniqueId(), status); Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status)); } status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.CALCULATED_REQUIREMENTS); if (status != JanusGraphOperationStatus.OK) { log.debug("Failed to disassociate calculated requirements for {} error {}", toscaElementVertex.getUniqueId(), status); Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status)); } status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.FULLFILLED_REQUIREMENTS); if (status != JanusGraphOperationStatus.OK) { log.debug("Failed to disassociate full filled requirements for {} error {}", toscaElementVertex.getUniqueId(), status); Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status)); } status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS); if (status != JanusGraphOperationStatus.OK) { log.debug("Failed to disassociate instance artifacts for {} error {}", toscaElementVertex.getUniqueId(), status); Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status)); } status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.SERVICE_API_ARTIFACTS); if (status != JanusGraphOperationStatus.OK) { log.debug("Failed to disassociate service api artifacts for {} error {}", toscaElementVertex.getUniqueId(), status); Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status)); } status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.FORWARDING_PATH); if (status != JanusGraphOperationStatus.OK) { log.debug("Failed to disassociate service api artifacts for {} error {}", toscaElementVertex.getUniqueId(), status); Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status)); } status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INTERFACE); if (status != JanusGraphOperationStatus.OK) { log.debug("Failed to disassociate interfaces for {} error {}", toscaElementVertex.getUniqueId(), status); return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status)); } status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INSTANCE_ARTIFACTS); if (status != JanusGraphOperationStatus.OK) { 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); if (status != JanusGraphOperationStatus.OK) { 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); if (status != JanusGraphOperationStatus.OK) { 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); if (status != JanusGraphOperationStatus.OK) { log.debug("Failed to disassociate instances interfaces 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; } @SuppressWarnings("unchecked") @Override public Either createToscaElement(ToscaElement toscaElement) { return createTopologyTemplate((TopologyTemplate) toscaElement); } @Override protected JanusGraphOperationStatus setCategoriesFromGraph(GraphVertex vertexComponent, T toscaElement) { return setTopologyTempalteCategoriesFromGraph(vertexComponent, toscaElement); } @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); } else { // Resource return validateResourceCategory(toscaElementToUpdate, elementV); } } @Override protected StorageOperationStatus updateDerived(T toscaElementToUpdate, GraphVertex updateElementV) { // not relevant now for topology template return StorageOperationStatus.OK; } @Override public void fillToscaElementVertexData(GraphVertex elementV, T toscaElementToUpdate, JsonParseFlagEnum flag) { fillMetadata(elementV, (TopologyTemplate) toscaElementToUpdate, flag); } private StorageOperationStatus validateServiceCategory(T toscaElementToUpdate, GraphVertex elementV) { StorageOperationStatus status = StorageOperationStatus.OK; List newCategoryList = toscaElementToUpdate.getCategories(); CategoryDefinition newCategory = newCategoryList.get(0); 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()); 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); if (getCategoryVertex.isRight()) { return getCategoryVertex.right().value(); } GraphVertex newCategoryV = getCategoryVertex.left().value(); status = moveCategoryEdge(elementV, newCategoryV); log.debug("Going to update the category of the resource from {} to {}. status is {}", categoryNameCurrent, newCategory, status); } return status; } public Either updateDistributionStatus(String uniqueId, User user, DistributionStatusEnum distributionStatus) { Either result = null; String userId = user.getUserId(); Either getRes = findUserVertex(userId); GraphVertex userVertex = null; GraphVertex serviceVertex = null; if (getRes.isRight()) { JanusGraphOperationStatus status = getRes.right().value(); CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Cannot find user {} in the graph. status is {}", userId, status); result = Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status)); } if (result == null) { userVertex = getRes.left().value(); 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); result = Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status)); } } if (result == null) { 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); edgeIterator.next().remove(); } } if (result == 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); result = Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status)); } } if (result == null) { serviceVertex.addMetadataProperty(GraphPropertyEnum.DISTRIBUTION_STATUS, distributionStatus.name()); long lastUpdateDate = System.currentTimeMillis(); serviceVertex.setJsonMetadataField(JsonPresentationFields.LAST_UPDATE_DATE, lastUpdateDate); Either updateRes = janusGraphDao.updateVertex(serviceVertex); if (updateRes.isRight()) { result = Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(updateRes.right().value())); } } if (result == null) { result = Either.left(serviceVertex); } return result; } /** * Returns list of ComponentInstanceProperty belonging to component instance capability specified by name, type and ownerId * * @param componentId * @param instanceId * @param capabilityName * @param capabilityType * @param ownerId * @return */ 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); if (componentByLabelAndId.isRight()) { result = Either.right(componentByLabelAndId.right().value()); } 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())); } return result; } 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) { if (MapUtils.isNotEmpty(instanceInterfaces.getMapToscaDataDefinition())) { return updateToscaDataDeepElementsBlockToToscaElement(containerComponent.getUniqueId(), EdgeLabelEnum.INST_INTERFACES, instanceInterfaces, componentInstanceId); } 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()); } private List findComponentInstanceCapabilityProperties(String instanceId, String capabilityName, String capabilityType, String ownerId, Map propertiesMap) { List capPropsList = null; for (Entry capProp : propertiesMap.entrySet()) { if (isBelongingPropertyMap(instanceId, capabilityName, capabilityType, ownerId, capProp)) { Map capMap = capProp.getValue().getMapToscaDataDefinition(); if (capMap != null && !capMap.isEmpty()) { capPropsList = capMap.values().stream().map(ComponentInstanceProperty::new).collect(Collectors.toList()); break; } } } if (capPropsList == null) { capPropsList = new ArrayList<>(); } return capPropsList; } 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); 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 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); } public StorageOperationStatus addPoliciesToToscaElement(GraphVertex componentV, List policies) { return addToscaDataToToscaElement(componentV, EdgeLabelEnum.POLICIES, VertexTypeEnum.POLICIES, policies, JsonPresentationFields.UNIQUE_ID); } public StorageOperationStatus updatePolicyOfToscaElement(GraphVertex componentV, PolicyDefinition policyDefinition) { 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); } public StorageOperationStatus removePolicyFromToscaElement(GraphVertex componentV, String policyId) { return deleteToscaDataElement(componentV, EdgeLabelEnum.POLICIES, VertexTypeEnum.POLICIES, policyId, JsonPresentationFields.UNIQUE_ID); } public StorageOperationStatus updateGroupOfToscaElement(GraphVertex componentV, GroupDefinition groupDefinition) { 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); policyDefinition.setInvariantName(policyName); policyDefinition.setComponentName((String) componentV.getJsonMetadataField(JsonPresentationFields.NAME)); policyDefinition.setUniqueId(UniqueIdBuilder.buildPolicyUniqueId(componentV.getUniqueId(), policyName)); policyDefinition.setInvariantUUID(UniqueIdBuilder.buildInvariantUUID()); policyDefinition.setPolicyUUID(UniqueIdBuilder.generateUUID()); } 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)); } 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.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()); } } private ToscaElement getOriginToscaElement(ComponentInstanceDataDefinition instance) { log.debug("#getOriginToscaElement - origin name: {}", instance.getComponentName()); ToscaElementTypeEnum elementType = detectToscaType(instance.getOriginType()); Either getOriginRes; if (elementType == ToscaElementTypeEnum.TOPOLOGY_TEMPLATE) { getOriginRes = this.getToscaElement(CapabilityRequirementNameResolver.getActualComponentUid(instance), getFilter()); } else { getOriginRes = nodeTypeOperation.getToscaElement(CapabilityRequirementNameResolver.getActualComponentUid(instance), getFilter()); } if (getOriginRes.isRight()) { log.debug("Failed to get an origin component with uniqueId {}", CapabilityRequirementNameResolver.getActualComponentUid(instance)); throw new StorageException(getOriginRes.right().value()); } return getOriginRes.left().value(); } 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) { return ToscaElementTypeEnum.NODE_TYPE; } else { return ToscaElementTypeEnum.TOPOLOGY_TEMPLATE; } } private ComponentParametersView getFilter() { ComponentParametersView filter = new ComponentParametersView(); filter.setIgnoreCapabilities(false); filter.setIgnoreCapabiltyProperties(false); filter.setIgnoreRequirements(false); return filter; } public void updateCapReqPropertiesOwnerId(String componentId, TopologyTemplate toscaElement) { 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()); topologyTemplateOperation .updateFullToscaData(toscaElementV, EdgeLabelEnum.REQUIREMENTS, VertexTypeEnum.REQUIREMENTS, toscaElement.getRequirements()); topologyTemplateOperation .updateFullToscaData(toscaElementV, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, toscaElement.getProperties()); } private void updateCapOwnerId(ToscaElement toscaElement, String ownerId) { if (MapUtils.isNotEmpty(toscaElement.getCapabilities())) { toscaElement.getCapabilities().values().stream().flatMap(listCapDef -> listCapDef.getListToscaDataDefinition().stream()) .forEach(capabilityDefinition -> capabilityDefinition.setOwnerId(ownerId)); } } private void updateReqOwnerId(ToscaElement toscaElement, String ownerId) { if (MapUtils.isNotEmpty(toscaElement.getRequirements())) { toscaElement.getRequirements().values().stream().flatMap(listReqDef -> listReqDef.getListToscaDataDefinition().stream()) .forEach(requirementDefinition -> requirementDefinition.setOwnerId(ownerId)); } } private void updatePropertiesOwnerId(ToscaElement toscaElement, String ownerId) { Map properties = toscaElement.getProperties(); if (MapUtils.isNotEmpty(properties)) { properties.values().forEach(propertyDataDefinition -> propertyDataDefinition.setParentUniqueId(ownerId)); } } }