diff options
author | vasraz <vasyl.razinkov@est.tech> | 2020-09-04 15:27:00 +0100 |
---|---|---|
committer | Sébastien Determe <sebastien.determe@intl.att.com> | 2020-09-07 13:28:22 +0000 |
commit | 3e9a9769dd21f0b16b3f238e42349cba3b1a78de (patch) | |
tree | 1517e5266d5b9ae8e5c386d06937eb503d59d431 /catalog-model/src/main | |
parent | 84a51513bca9c41c8757db017eb45b2d801da195 (diff) |
Enable selection of requirements
Instead of all requirements of the component instances in a component being exposed outside the component, this change will enable the component designer to specifiy which should be exposed outside the component and which are to be internal to the component
Change-Id: Ib063f7b8b0aca94896e78a46f069725bae3d494d
Issue-ID: SDC-2771
Signed-off-by: MichaelMorris <michael.morris@est.tech>
Signed-off-by: Vasyl Razinkov <vasyl.razinkov@est.tech>
Diffstat (limited to 'catalog-model/src/main')
2 files changed, 73 insertions, 1 deletions
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeTemplateOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeTemplateOperation.java index df1f8fd8bf..3cd46ba846 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeTemplateOperation.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeTemplateOperation.java @@ -857,8 +857,10 @@ public class NodeTemplateOperation extends BaseOperation { calculatedRequirements.forEach((key, value) -> { Map<String, ListRequirementDataDefinition> mapByType = value.getMapToscaDataDefinition(); - mapByType.forEach((key1, value1) -> value1.getListToscaDataDefinition().forEach(req -> { + mapByType.forEach((key1, value1) -> value1.getListToscaDataDefinition().stream() + .filter(RequirementDataDefinition::isExternal).forEach(req -> { req.addToPath(componentInstance.getUniqueId()); + req.setExternal(false); allCalculatedReq.add(key1, req); })); }); @@ -927,6 +929,72 @@ public class NodeTemplateOperation extends BaseOperation { } return StorageOperationStatus.OK; } + + public StorageOperationStatus updateComponentInstanceRequirement(String componentId, String componentInstanceUniqueId, RequirementDataDefinition requirementDataDefinition) { + Either<GraphVertex, JanusGraphOperationStatus> containerVEither = janusGraphDao + .getVertexById(componentId, JsonParseFlagEnum.ParseAll); + if (containerVEither.isRight()) { + JanusGraphOperationStatus error = containerVEither.right().value(); + CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, FAILED_TO_FETCH_CONTAINER_VERTEX_ERROR, componentId, error); + return StorageOperationStatus.GENERAL_ERROR; + } + GraphVertex containerV = containerVEither.left().value(); + return updateComponentInstanceRequirement(componentId, componentInstanceUniqueId, requirementDataDefinition, containerV); + } + + private StorageOperationStatus updateComponentInstanceRequirement(String componentId, String componentInstanceUniqueId, RequirementDataDefinition requirementDataDefinition, GraphVertex containerV) { + Either<Pair<GraphVertex, Map<String, MapListRequirementDataDefinition>>, StorageOperationStatus> existingReqs = getCalculatedRequirements(componentId); + if (existingReqs.isRight()) { + return existingReqs.right().value(); + } + MapListRequirementDataDefinition componentInstanceRequirementsMap = existingReqs.left().value().getRight().get(componentInstanceUniqueId); + if (componentInstanceRequirementsMap == null) { + return StorageOperationStatus.NOT_FOUND; + } + ListRequirementDataDefinition listRequirementDataDefinition = componentInstanceRequirementsMap.getMapToscaDataDefinition().get(requirementDataDefinition.getCapability()); + + listRequirementDataDefinition.getListToscaDataDefinition().stream() + .filter(e -> requirementDataDefinition.getOwnerId().equals(e.getOwnerId()) && requirementDataDefinition.getName().equals(e.getName())) + .forEach(r -> r.setExternal(requirementDataDefinition.isExternal())); + + return updateCalculatedReqOnGraph(componentId, containerV, existingReqs); + } + + private Either<Pair<GraphVertex, Map<String, MapListRequirementDataDefinition>>, StorageOperationStatus> getCalculatedRequirements(String componentId) { + Either<Pair<GraphVertex, Map<String, MapListRequirementDataDefinition>>, StorageOperationStatus> result = null; + Either<GraphVertex, JanusGraphOperationStatus> containerVEither = janusGraphDao + .getVertexById(componentId, JsonParseFlagEnum.ParseAll); + if (containerVEither.isRight()) { + JanusGraphOperationStatus error = containerVEither.right().value(); + CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, FAILED_TO_FETCH_CONTAINER_VERTEX_ERROR, componentId, error); + result = Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(error)); + } + if (result == null) { + GraphVertex containerV = containerVEither.left().value(); + result = fetchContainerCalculatedRequirement(containerV, EdgeLabelEnum.CALCULATED_REQUIREMENTS); + } + return result; + } + + private StorageOperationStatus updateCalculatedReqOnGraph(String componentId, GraphVertex containerV, Either<Pair<GraphVertex, Map<String, MapListRequirementDataDefinition>>, StorageOperationStatus> reqResult + ) { + containerV.setJsonMetadataField(JsonPresentationFields.LAST_UPDATE_DATE, System.currentTimeMillis()); + Either<GraphVertex, JanusGraphOperationStatus> updateElement = janusGraphDao.updateVertex(containerV); + if (updateElement.isRight()) { + CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to update topology template {} with new relations error {}. ", componentId, updateElement.right().value()); + return DaoStatusConverter.convertJanusGraphStatusToStorageStatus(updateElement.right().value()); + } + + CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Update calculated requirement for container {}", containerV.getUniqueId()); + Either<GraphVertex, JanusGraphOperationStatus> status = updateOrCopyOnUpdate(reqResult.left().value().getLeft(), containerV, EdgeLabelEnum.CALCULATED_REQUIREMENTS); + if (status.isRight()) { + JanusGraphOperationStatus error = status.right().value(); + CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to update calculated requiremnt for container {} error {}", containerV.getUniqueId(), error); + return DaoStatusConverter.convertJanusGraphStatusToStorageStatus(error); + } + return StorageOperationStatus.OK; + } + private StorageOperationStatus addComponentInstanceToscaDataToNodeTypeContainer(NodeType originNodeType, ComponentInstanceDataDefinition componentInstance, GraphVertex updatedContainerVertex) { 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 aa03d761bf..dc9174e464 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 @@ -2586,6 +2586,10 @@ public class ToscaOperationFacade { .map(instanceCapProps -> topologyTemplateOperation.updateComponentInstanceCapabilityProperties(containerComponent, componentInstanceUniqueId, instanceCapProps)) .orElse(StorageOperationStatus.NOT_FOUND); } + + public StorageOperationStatus updateComponentInstanceRequirement(String containerComponentId, String componentInstanceUniqueId, RequirementDataDefinition requirementDataDefinition) { + return nodeTemplateOperation.updateComponentInstanceRequirement(containerComponentId, componentInstanceUniqueId, requirementDataDefinition); + } public StorageOperationStatus updateComponentInstanceInterfaces(Component containerComponent, String componentInstanceUniqueId) { MapInterfaceDataDefinition mapInterfaceDataDefinition = |