From c469756a1092194adedd590d35f0f1f8feac3a36 Mon Sep 17 00:00:00 2001 From: vasraz Date: Thu, 7 Sep 2023 10:17:14 +0100 Subject: Implement 'Update Service by importing Tosca Model'-story Signed-off-by: Vasyl Razinkov Change-Id: I34414caeb53c4dcc6499d3639e4ea8f80407a6f6 Issue-ID: SDC-4579 --- .../jsonjanusgraph/operations/BaseOperation.java | 9 +++--- .../operations/TopologyTemplateOperation.java | 9 ++++-- .../operations/ToscaOperationFacade.java | 34 +++++++++++----------- 3 files changed, 28 insertions(+), 24 deletions(-) (limited to 'catalog-model') diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/BaseOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/BaseOperation.java index af8414dc81..2bf1c96abb 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/BaseOperation.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/BaseOperation.java @@ -1423,16 +1423,15 @@ public abstract class BaseOperation { mergedToscaDataMap.putAll(existingToscaDataMap); } for (T toscaDataElement : toscaDataList) { - status = handleToscaDataElement(toscaElement, mapKeyField, mergedToscaDataMap, toscaDataElement, isUpdate); + status = handleToscaDataElement(toscaElement.getUniqueId(), mapKeyField, mergedToscaDataMap, toscaDataElement, isUpdate); if (status != StorageOperationStatus.OK) { - result = Either.right(status); - break; + return Either.right(status); } } return result; } - private StorageOperationStatus handleToscaDataElement(GraphVertex toscaElement, + private StorageOperationStatus handleToscaDataElement(String toscaElementId, JsonPresentationFields mapKeyField, Map mergedToscaDataMap, T toscaDataElement, boolean isUpdate) { @@ -1450,7 +1449,7 @@ public abstract class BaseOperation { status = StorageOperationStatus.BAD_REQUEST; } else if (!isUpdate && mergedToscaDataMap.containsKey(currKey)) { CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, - "Failed to add tosca data to tosca element {}. The element with the same key {} already exists. ", toscaElement.getUniqueId(), + "Failed to add tosca data to tosca element {}. The element with the same key {} already exists. ", toscaElementId, currKey); status = StorageOperationStatus.BAD_REQUEST; } 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 15d741b156..a253d815ad 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 @@ -1219,9 +1219,9 @@ public class TopologyTemplateOperation extends ToscaElementOperation { 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); + status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_OUTPUTS); if (status != JanusGraphOperationStatus.OK) { - log.debug("Failed to disassociate instances inputs for {} error {}", toscaElementVertex.getUniqueId(), status); + log.debug("Failed to disassociate instances outputs for {} error {}", toscaElementVertex.getUniqueId(), status); Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status)); } status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.GROUPS); @@ -1244,6 +1244,11 @@ public class TopologyTemplateOperation extends ToscaElementOperation { log.debug("Failed to disassociate inputs for {} error {}", toscaElementVertex.getUniqueId(), status); Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status)); } + status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.OUTPUTS); + if (status != JanusGraphOperationStatus.OK) { + log.debug("Failed to disassociate outputs 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); diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java index d654f23fbb..951dc5aaed 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java @@ -1791,25 +1791,25 @@ public class ToscaOperationFacade { } public Either>, StorageOperationStatus> addComponentInstanceAttributesToComponent( - final Component containerComponent, final Map> instProperties) { - requireNonNull(instProperties); - for (final Entry> entry : instProperties.entrySet()) { - final List props = entry.getValue(); - if (isEmpty(props)) { + final Component containerComponent, final Map> componentInstanceAttribute) { + requireNonNull(componentInstanceAttribute); + for (final Entry> entry : componentInstanceAttribute.entrySet()) { + final List attributes = entry.getValue(); + if (isEmpty(attributes)) { continue; } final String componentInstanceId = entry.getKey(); - final List originalComponentInstProps = containerComponent.getComponentInstancesAttributes() + final List componentInstanceAttributes = containerComponent.getComponentInstancesAttributes() .get(componentInstanceId); - for (final ComponentInstanceAttribute property : props) { + for (final ComponentInstanceAttribute attribute : attributes) { final StorageOperationStatus status = updateOrAddComponentInstanceAttribute(containerComponent, componentInstanceId, - originalComponentInstProps, property); + componentInstanceAttributes, attribute); if (status != StorageOperationStatus.OK) { return Either.right(status); } } } - return Either.left(instProperties); + return Either.left(componentInstanceAttribute); } private StorageOperationStatus populateAndUpdateInstanceCapProperty(Component containerComponent, String componentInstanceId, @@ -1847,19 +1847,19 @@ public class ToscaOperationFacade { } private StorageOperationStatus updateOrAddComponentInstanceAttribute(Component containerComponent, String componentInstanceId, - List originalComponentInstProps, - ComponentInstanceAttribute property) { + List componentInstanceAttributes, + ComponentInstanceAttribute attribute) { StorageOperationStatus status; - // check if the property already exists or not - Optional instanceProperty = originalComponentInstProps.stream() - .filter(p -> p.getUniqueId().equals(property.getUniqueId())).findAny(); + // check if the attribute already exists or not + Optional instanceProperty = componentInstanceAttributes.stream() + .filter(p -> p.getUniqueId().equals(attribute.getUniqueId())).findAny(); if (instanceProperty.isPresent()) { - status = updateComponentInstanceAttribute(containerComponent, componentInstanceId, property); + status = updateComponentInstanceAttribute(containerComponent, componentInstanceId, attribute); } else { - status = addComponentInstanceAttribute(containerComponent, componentInstanceId, property); + status = addComponentInstanceAttribute(containerComponent, componentInstanceId, attribute); } if (status != StorageOperationStatus.OK) { - log.debug("Failed to update instance property {} for instance {} error {} ", property, componentInstanceId, status); + log.debug("Failed to update instance attribute {} for instance {} error {} ", attribute, componentInstanceId, status); } return status; } -- cgit 1.2.3-korg