From 517d06a213dd00f919c17d023718ed2d85d424bc Mon Sep 17 00:00:00 2001 From: priyanshu Date: Thu, 2 Aug 2018 17:11:25 +0300 Subject: Interface operations on VF Interface operations on VF Fixed the broken code after merge Change-Id: I08381c0e69fbe85e1df26fb7ecbf93af43f906b2 Issue-ID: SDC-1586 Signed-off-by: priyanshu --- .../jsontitan/datamodel/TopologyTemplate.java | 8 ++++ .../operations/TopologyTemplateOperation.java | 43 ++++++++++++++++++++++ .../be/model/jsontitan/utils/ModelConverter.java | 21 +++++++++++ 3 files changed, 72 insertions(+) (limited to 'catalog-model/src/main/java/org/openecomp') 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 36d597e7be..0d7b14abd1 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 @@ -53,6 +53,7 @@ public class TopologyTemplate extends ToscaElement{ private Map calculatedCapabilitiesProperties; 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 9fe59d95f1..e01e02397f 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 @@ -172,6 +172,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); @@ -691,10 +698,46 @@ 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 = associateElementToData(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 041d3f0d77..3b2cb97132 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 @@ -180,6 +180,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); @@ -193,6 +194,17 @@ public class ModelConverter { convertAdditionalInformation(toscaElement, resource); 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) { @@ -881,6 +893,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); @@ -901,6 +914,14 @@ 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); -- cgit 1.2.3-korg