From eb4b9fb0f4d3b62f3b9e2da81ebe581e7d0fc6eb Mon Sep 17 00:00:00 2001 From: mojahidi Date: Tue, 10 Apr 2018 12:32:47 +0530 Subject: Fixed Review Comments - operation Business logic Added interface operation Business logic and amended validation logic Change-Id: Ia98c625d732a31b03dec2d24504ecabb367e0582 Issue-ID: SDC-1060 Signed-off-by: mojahidi --- .../jsontitan/datamodel/TopologyTemplate.java | 8 +++ .../operations/TopologyTemplateOperation.java | 65 +++++++++++++++++++++- .../be/model/jsontitan/utils/ModelConverter.java | 22 ++++++++ .../sdc/be/ui/model/UiResourceDataTransfer.java | 8 +++ 4 files changed, 102 insertions(+), 1 deletion(-) (limited to 'catalog-model/src/main') diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/datamodel/TopologyTemplate.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/datamodel/TopologyTemplate.java index 6b5f1157fc..bb36595578 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/datamodel/TopologyTemplate.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/datamodel/TopologyTemplate.java @@ -55,6 +55,7 @@ public class TopologyTemplate extends ToscaElement{ private Map instDeploymentArtifacts; private Map instanceArtifacts; + private Map interfaces; //Component Instances External References (instanceId -> ExternalRefsMap) //----------------------------------------------------------------------- @@ -67,6 +68,13 @@ public class TopologyTemplate extends ToscaElement{ } //----------------------------------------------------------------------- + public Map getInterfaces() { + return interfaces; + } + + public void setInterfaces(Map interfaces) { + this.interfaces = interfaces; + } public Map getInputs() { return inputs; diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/TopologyTemplateOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/TopologyTemplateOperation.java index 9ad3053d66..355a6e28a5 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/TopologyTemplateOperation.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/TopologyTemplateOperation.java @@ -30,7 +30,21 @@ 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.dao.titan.TitanOperationStatus; -import org.openecomp.sdc.be.datatypes.elements.*; +import org.openecomp.sdc.be.datatypes.elements.AdditionalInfoParameterDataDefinition; +import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition; +import org.openecomp.sdc.be.datatypes.elements.ComponentInstanceDataDefinition; +import org.openecomp.sdc.be.datatypes.elements.CompositionDataDefinition; +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.MapArtifactDataDefinition; +import org.openecomp.sdc.be.datatypes.elements.MapCapabiltyProperty; +import org.openecomp.sdc.be.datatypes.elements.MapGroupsDataDefinition; +import org.openecomp.sdc.be.datatypes.elements.MapListCapabiltyDataDefinition; +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.enums.ComponentTypeEnum; import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum; import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields; @@ -175,6 +189,13 @@ public class TopologyTemplateOperation extends ToscaElementOperation { result = Either.right(associateCapProperties); return result; } + + StorageOperationStatus associateInterfaces = associateInterfacesToResource(topologyTemplateVertex, topologyTemplate); + if (associateInterfaces != StorageOperationStatus.OK) { + result = Either.right(associateInterfaces); + return result; + } + StorageOperationStatus associatePathProperties = associateForwardingPathToResource(topologyTemplateVertex, topologyTemplate); if (associateCapProperties != StorageOperationStatus.OK) { result = Either.right(associatePathProperties); @@ -665,9 +686,51 @@ public class TopologyTemplateOperation extends ToscaElementOperation { } } + if (!componentParametersView.isIgnoreInterfaces()) { + TitanOperationStatus storageStatus = setInterfcesFromGraph(componentV, toscaElement); + if (storageStatus != TitanOperationStatus.OK) { + return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(storageStatus)); + } + } + return Either.left(toscaElement); } + private TitanOperationStatus setInterfcesFromGraph(GraphVertex componentV, + TopologyTemplate topologyTemplate) { + Either, TitanOperationStatus> result = getDataFromGraph + (componentV, + EdgeLabelEnum.INTERFACE_ARTIFACTS); + if (result.isLeft()) { + topologyTemplate.setInterfaces(result.left().value()); + } else { + if (result.right().value() != TitanOperationStatus.NOT_FOUND) { + return result.right().value(); + } + } + return TitanOperationStatus.OK; + } + + private StorageOperationStatus associateInterfacesToResource(GraphVertex topologyTemplateVertex, + TopologyTemplate topologyTemplate) { + Map interfaces = topologyTemplate.getInterfaces(); + return associateInterfacesToComponent(topologyTemplateVertex,interfaces); + } + + public StorageOperationStatus associateInterfacesToComponent(GraphVertex nodeTypeVertex, + Map + interfaceMap) { + if (interfaceMap != null && !interfaceMap.isEmpty()) { + Either assosiateElementToData = assosiateElementToData + (nodeTypeVertex, VertexTypeEnum.INTERFACE_ARTIFACTS, EdgeLabelEnum.INTERFACE_ARTIFACTS, interfaceMap); + if (assosiateElementToData.isRight()) { + return assosiateElementToData.right().value(); + } + } + return StorageOperationStatus.OK; + } + + private TitanOperationStatus setPoliciesFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) { Either, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.POLICIES); if (result.isLeft()) { diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/utils/ModelConverter.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/utils/ModelConverter.java index 71f0b77902..023d3fe2bd 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/utils/ModelConverter.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/utils/ModelConverter.java @@ -222,6 +222,7 @@ public class ModelConverter { resource.setCsarUUID((String) topologyTemplate.getMetadataValue(JsonPresentationFields.CSAR_UUID)); resource.setCsarVersion((String) topologyTemplate.getMetadataValue(JsonPresentationFields.CSAR_VERSION)); resource.setImportedToscaChecksum((String) topologyTemplate.getMetadataValue(JsonPresentationFields.IMPORTED_TOSCA_CHECKSUM)); + convertInterfaces(topologyTemplate, resource); } convertComponentInstances(topologyTemplate, resource); @@ -236,6 +237,17 @@ public class ModelConverter { return resource; } + private static void convertInterfaces(TopologyTemplate toscaElement, Resource resource) { + Map interfaces = toscaElement.getInterfaces(); + Map copy; + if (interfaces != null) { + copy = interfaces.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> new InterfaceDefinition(e.getValue()))); + } else { + copy = new HashMap<>(); + } + resource.setInterfaces(copy); + } + private static void convertAttributes(NodeType nodeType, Resource resource) { Map attributes = nodeType.getAttributes(); if (attributes != null) { @@ -897,6 +909,7 @@ public class ModelConverter { topologyTemplate.setMetadataValue(JsonPresentationFields.CSAR_UUID, resource.getCsarUUID()); topologyTemplate.setMetadataValue(JsonPresentationFields.CSAR_VERSION, resource.getCsarVersion()); topologyTemplate.setMetadataValue(JsonPresentationFields.IMPORTED_TOSCA_CHECKSUM, resource.getImportedToscaChecksum()); + convertInterfaces(resource, topologyTemplate); } if (componentType == ComponentTypeEnum.SERVICE) { convertServiceSpecificEntities((Service) component, topologyTemplate); @@ -917,6 +930,15 @@ public class ModelConverter { return topologyTemplate; } + private static void convertInterfaces(Resource resource, TopologyTemplate topologyTemplate) { + Map interfaces = resource.getInterfaces(); + if (interfaces != null && !interfaces.isEmpty()) { + Map copy = interfaces.entrySet().stream() + .collect(Collectors.toMap(Map.Entry::getKey, e -> new InterfaceDataDefinition(e.getValue()))); + topologyTemplate.setInterfaces(copy); + } + } + private static void convertServiceSpecificEntities(Service service, TopologyTemplate topologyTemplate) { convertServiceMetaData(service, topologyTemplate); convertServiceApiArtifacts(service, topologyTemplate); diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/ui/model/UiResourceDataTransfer.java b/catalog-model/src/main/java/org/openecomp/sdc/be/ui/model/UiResourceDataTransfer.java index 5eef21b3a5..9c0d25b228 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/ui/model/UiResourceDataTransfer.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/ui/model/UiResourceDataTransfer.java @@ -23,6 +23,7 @@ package org.openecomp.sdc.be.ui.model; import java.util.List; import java.util.Map; +import org.openecomp.sdc.be.datatypes.elements.InterfaceOperationDataDefinition; import org.openecomp.sdc.be.model.AdditionalInformationDefinition; import org.openecomp.sdc.be.model.InterfaceDefinition; import org.openecomp.sdc.be.model.PropertyDefinition; @@ -44,6 +45,7 @@ public class UiResourceDataTransfer extends UiComponentDataTransfer{ private List defaultCapabilities; private List additionalInformation; + private Map interfaceOperations; public UiResourceDataTransfer(){} @@ -110,5 +112,11 @@ public class UiResourceDataTransfer extends UiComponentDataTransfer{ public void setDefaultCapabilities(List defaultCapabilities) { this.defaultCapabilities = defaultCapabilities; } + public Map getInterfaceOperations() { + return interfaceOperations; + } + public void setInterfaceOperations(Map interfaceOperations) { + this.interfaceOperations = interfaceOperations; + } } -- cgit 1.2.3-korg