From 216ea4998de9ae4ee603d7f8f5f6725b218ca710 Mon Sep 17 00:00:00 2001 From: vasraz Date: Sat, 22 Jul 2023 13:07:27 +0100 Subject: Implement 'Update Service by importing Tosca Template'-story Signed-off-by: Vasyl Razinkov Change-Id: Ia2842c49cc81eb30174d783805261d0e73835e48 Issue-ID: SDC-4576 --- .../openecomp/sdc/be/model/UploadServiceInfo.java | 5 +- .../operations/TopologyTemplateOperation.java | 96 ++++++++++------------ 2 files changed, 46 insertions(+), 55 deletions(-) (limited to 'catalog-model') diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/UploadServiceInfo.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/UploadServiceInfo.java index d709947cfa..f19463ea77 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/UploadServiceInfo.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/UploadServiceInfo.java @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; import lombok.Getter; +import lombok.NoArgsConstructor; import lombok.Setter; import org.openecomp.sdc.be.model.category.CategoryDefinition; import org.openecomp.sdc.be.model.category.SubCategoryDefinition; @@ -30,6 +31,7 @@ import org.openecomp.sdc.common.api.UploadArtifactInfo; @Getter @Setter +@NoArgsConstructor public class UploadServiceInfo { private String payloadData; @@ -67,9 +69,6 @@ public class UploadServiceInfo { private String derivedFromGenericType; private String derivedFromGenericVersion; - public UploadServiceInfo() { - } - public void addSubCategory(String category, String subCategory) { if (category != null || subCategory != null) { if (categories == null) { 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 603e09b590..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 @@ -109,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) { @@ -188,6 +190,10 @@ public class TopologyTemplateOperation extends ToscaElementOperation { 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) { @@ -197,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()); @@ -414,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, - uniqueKeys, pathKeys); - 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); } @@ -468,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); @@ -542,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); @@ -602,8 +576,8 @@ public class TopologyTemplateOperation extends ToscaElementOperation { } public StorageOperationStatus associateOutputsToComponent(final GraphVertex nodeTypeVertex, - final Map outputs, - final String id) { + 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()))); @@ -883,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); @@ -1333,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; @@ -1403,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); @@ -1467,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, @@ -1495,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); @@ -1511,7 +1503,7 @@ public class TopologyTemplateOperation extends ToscaElementOperation { public StorageOperationStatus updateComponentInterfaces(final String componentId, final MapInterfaceDataDefinition instanceInterfaces, - final String componentInterfaceUpdatedKey) { + final String componentInterfaceUpdatedKey) { if (MapUtils.isNotEmpty(instanceInterfaces.getMapToscaDataDefinition())) { return updateToscaDataDeepElementsBlockToToscaElement(componentId, EdgeLabelEnum.INTERFACE_ARTIFACTS, instanceInterfaces, componentInterfaceUpdatedKey); @@ -1600,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())) { -- cgit 1.2.3-korg