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=15d741b156c27d30fe4c97e0bdb98ed8d58e7545;hb=216ea4998de9ae4ee603d7f8f5f6725b218ca710;hp=61b11b31684e7159090e0f15b5fba2a41c2bd719;hpb=0ef5f83fbe6f68cbde5530b5d58d96cac285cfa7;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 61b11b3168..15d741b156 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 @@ -31,6 +31,7 @@ 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; @@ -108,7 +109,9 @@ public class TopologyTemplateOperation extends ToscaElementOperation { } public Either createTopologyTemplate(TopologyTemplate topologyTemplate) { - topologyTemplate.generateUUID(); + if (topologyTemplate.getUUID() == null) { + topologyTemplate.generateUUID(); + } topologyTemplate = getResourceMetaDataFromResource(topologyTemplate); String resourceUniqueId = topologyTemplate.getUniqueId(); if (resourceUniqueId == null) { @@ -152,7 +155,7 @@ 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); @@ -184,9 +187,13 @@ public class TopologyTemplateOperation extends ToscaElementOperation { 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) { @@ -196,10 +203,7 @@ public class TopologyTemplateOperation extends ToscaElementOperation { } 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()); @@ -385,6 +389,23 @@ public class TopologyTemplateOperation extends ToscaElementOperation { return StorageOperationStatus.OK; } + 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 associateInstGroupsToComponent(GraphVertex nodeTypeVertex, Map instGroups) { if (instGroups != null && !instGroups.isEmpty()) { Either assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INST_GROUPS, @@ -396,43 +417,14 @@ public class TopologyTemplateOperation extends ToscaElementOperation { 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) { + 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) { + Map instArtifacts) { return associateInstanceArtifactsToComponent(nodeTypeVertex, instArtifacts, VertexTypeEnum.INSTANCE_ARTIFACTS, EdgeLabelEnum.INSTANCE_ARTIFACTS); } @@ -450,9 +442,9 @@ public class TopologyTemplateOperation extends ToscaElementOperation { } public StorageOperationStatus associateOrAddCalcCapReqToComponent(GraphVertex nodeTypeVertex, - Map calcRequirements, - Map calcCapabilty, - Map calculatedCapabilitiesProperties) { + Map calcRequirements, + Map calcCapabilty, + Map calculatedCapabilitiesProperties) { if (!MapUtils.isEmpty(calcRequirements)) { Either assosiateElementToData = associateOrAddElementToData(nodeTypeVertex, VertexTypeEnum.CALCULATED_REQUIREMENTS, EdgeLabelEnum.CALCULATED_REQUIREMENTS, calcRequirements); @@ -524,7 +516,7 @@ public class TopologyTemplateOperation extends ToscaElementOperation { } public StorageOperationStatus associateForwardingPathToComponent(GraphVertex nodeTypeVertex, - Map forwardingPathMap) { + Map forwardingPathMap) { if (forwardingPathMap != null && !forwardingPathMap.isEmpty()) { Either assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.FORWARDING_PATH, EdgeLabelEnum.FORWARDING_PATH, forwardingPathMap); @@ -583,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); @@ -609,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; @@ -773,12 +781,6 @@ public class TopologyTemplateOperation extends ToscaElementOperation { 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) { @@ -806,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()) { @@ -867,6 +857,18 @@ public class TopologyTemplateOperation extends ToscaElementOperation { return StorageOperationStatus.OK; } + 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(); + } + } + return StorageOperationStatus.OK; + } + private JanusGraphOperationStatus setForwardingGraphPropertiesFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) { Either, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.FORWARDING_PATH); @@ -984,7 +986,7 @@ public class TopologyTemplateOperation extends ToscaElementOperation { if (MapUtils.isEmpty(filters)) { return JanusGraphOperationStatus.OK; } - if(filters.values().size() > 1) { + 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; @@ -1168,14 +1170,16 @@ 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); + final Object useServiceSubstitutionForNestedServices = metadataProperties.get(GraphPropertyEnum.USE_SUBSTITUTION_FOR_NESTED_SERVICES); category.setUseServiceSubstitutionForNestedServices( - useServiceSubstitutionForNestedServices == null ? false : useServiceSubstitutionForNestedServices); + useServiceSubstitutionForNestedServices != null && (boolean) useServiceSubstitutionForNestedServices); Type listTypeCat = new TypeToken>() { }.getType(); - List iconsfromJsonCat = getGson().fromJson((String) metadataProperties.get(GraphPropertyEnum.ICONS.getProperty()), listTypeCat); - category.setIcons(iconsfromJsonCat); + 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() @@ -1315,6 +1319,12 @@ 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; @@ -1385,7 +1395,7 @@ public class TopologyTemplateOperation extends ToscaElementOperation { } public Either updateDistributionStatus(String uniqueId, User user, - DistributionStatusEnum distributionStatus) { + DistributionStatusEnum distributionStatus) { Either result = null; String userId = user.getUserId(); Either getRes = findUserVertex(userId); @@ -1449,10 +1459,10 @@ public class TopologyTemplateOperation extends ToscaElementOperation { * @return */ public Either, StorageOperationStatus> getComponentInstanceCapabilityProperties(String componentId, - String instanceId, - String capabilityName, - String capabilityType, - String ownerId) { + String instanceId, + String capabilityName, + String capabilityType, + String ownerId) { Either, StorageOperationStatus> result = null; Map mapPropertiesDataDefinition = null; Either componentByLabelAndId = getComponentByLabelAndId(componentId, @@ -1477,13 +1487,13 @@ public class TopologyTemplateOperation extends ToscaElementOperation { } public StorageOperationStatus updateComponentInstanceCapabilityProperties(Component containerComponent, String componentInstanceId, - MapCapabilityProperty instanceProperties) { + MapCapabilityProperty instanceProperties) { return updateToscaDataDeepElementsBlockToToscaElement(containerComponent.getUniqueId(), EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, instanceProperties, componentInstanceId); } public StorageOperationStatus updateComponentInstanceInterfaces(Component containerComponent, String componentInstanceId, - MapInterfaceDataDefinition instanceInterfaces) { + MapInterfaceDataDefinition instanceInterfaces) { if (MapUtils.isNotEmpty(instanceInterfaces.getMapToscaDataDefinition())) { return updateToscaDataDeepElementsBlockToToscaElement(containerComponent.getUniqueId(), EdgeLabelEnum.INST_INTERFACES, instanceInterfaces, componentInstanceId); @@ -1491,6 +1501,16 @@ public class TopologyTemplateOperation extends ToscaElementOperation { 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()); @@ -1550,7 +1570,7 @@ public class TopologyTemplateOperation extends ToscaElementOperation { } 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) { @@ -1559,9 +1579,12 @@ public class TopologyTemplateOperation extends ToscaElementOperation { } 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)); @@ -1569,7 +1592,7 @@ public class TopologyTemplateOperation extends ToscaElementOperation { policyDefinition.setPolicyUUID(UniqueIdBuilder.generateUUID()); } - void revertNamesOfCalculatedCapabilitiesRequirements(String componentId, TopologyTemplate toscaElement) { + 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())) {