diff options
author | priyanshu <pagarwal@amdocs.com> | 2018-08-06 14:31:02 +0530 |
---|---|---|
committer | Avi Gaffa <avi.gaffa@amdocs.com> | 2018-08-06 16:00:45 +0000 |
commit | 1ecdbf74427467327de0b1e11cd0a839d6dc05bd (patch) | |
tree | 046179dbdf55b1de06995de2c1538e6f969969b7 /catalog-model/src/main/java/org | |
parent | b503f5b618a0c14b91714bb32de69f0957ab1f03 (diff) |
Interface operations Model update
1. Interface operations Model update
2. Removed unnecessary dependencies on resource
3. Fixed the broken code after merge
Change-Id: I2b6381493530f1d61f0803ee1d1d688648356f73
Issue-ID: SDC-1535
Signed-off-by: priyanshu <pagarwal@amdocs.com>
Diffstat (limited to 'catalog-model/src/main/java/org')
4 files changed, 192 insertions, 99 deletions
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/ArtifactsOperations.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/ArtifactsOperations.java index 009d4cac3b..3eb6a5211c 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/ArtifactsOperations.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/ArtifactsOperations.java @@ -153,7 +153,7 @@ public class ArtifactsOperations extends BaseOperation { } private ArtifactDataDefinition findInterfaceArtifact(String parentId, String id) { - Either<Map<String, InterfaceDefinition>, TitanOperationStatus> dataFromGraph = getDataFromGraph(parentId, EdgeLabelEnum.INTERFACE_ARTIFACTS); + Either<Map<String, InterfaceDefinition>, TitanOperationStatus> dataFromGraph = getDataFromGraph(parentId, EdgeLabelEnum.INTERFACE); if (dataFromGraph.isRight()){ log.debug("failed to fetch interfaces {} for tosca element with id {}, error {}", id, parentId ,dataFromGraph.right().value()); return null; diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/InterfaceOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/InterfaceOperation.java index a7587adae1..04562534a8 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/InterfaceOperation.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/InterfaceOperation.java @@ -17,105 +17,226 @@ package org.openecomp.sdc.be.model.jsontitan.operations; import fj.data.Either; +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Optional; +import java.util.UUID; +import org.openecomp.sdc.be.dao.cassandra.ArtifactCassandraDao; +import org.openecomp.sdc.be.dao.cassandra.CassandraOperationStatus; import org.openecomp.sdc.be.dao.jsongraph.GraphVertex; 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.enums.JsonPresentationFields; +import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition; +import org.openecomp.sdc.be.model.ArtifactDefinition; import org.openecomp.sdc.be.model.InterfaceDefinition; -import org.openecomp.sdc.be.model.Resource; +import org.openecomp.sdc.be.model.Operation; import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; import org.openecomp.sdc.be.model.operations.impl.DaoStatusConverter; -import org.openecomp.sdc.common.jsongraph.util.CommonUtility; +import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum; +import org.openecomp.sdc.common.api.ArtifactTypeEnum; import org.openecomp.sdc.common.log.wrappers.Logger; - -import java.util.*; +import org.springframework.beans.factory.annotation.Autowired; @org.springframework.stereotype.Component("interfaces-operation") public class InterfaceOperation extends BaseOperation { - private static final Logger logger = Logger.getLogger(InterfaceOperation.class.getName()); + private static final Logger logger = Logger.getLogger(InterfaceOperation.class.getName()); + @Autowired + private ArtifactCassandraDao artifactCassandraDao; - public Either<Set<String>, StorageOperationStatus> deleteInterface(Resource resource, - Set<String> interfacesToDelete) { - Either<Set<String>, StorageOperationStatus> result = null; - Either<GraphVertex, TitanOperationStatus> getComponentVertex; - StorageOperationStatus status = null; + public Either<InterfaceDefinition, StorageOperationStatus> addInterface(String componentId, + InterfaceDefinition interfaceDefinition) { + return addOrUpdateInterface(false, componentId, interfaceDefinition); + } - if (result == null) { - getComponentVertex = titanDao.getVertexById(resource.getUniqueId(), JsonParseFlagEnum.NoParse); - if (getComponentVertex.isRight()) { - result = Either - .right(DaoStatusConverter.convertTitanStatusToStorageStatus(getComponentVertex.right().value())); - } - } - if (result == null) { + public Either<InterfaceDefinition, StorageOperationStatus> updateInterface(String componentId, + InterfaceDefinition interfaceDefinition) { + return addOrUpdateInterface(true, componentId, interfaceDefinition); + } - status = deleteToscaDataElements(resource.getUniqueId(), EdgeLabelEnum.INTERFACE_ARTIFACTS, - new ArrayList<>(interfacesToDelete)); + private Either<InterfaceDefinition, StorageOperationStatus> addOrUpdateInterface( + boolean isUpdateAction, String componentId, InterfaceDefinition interfaceDefinition) { - if (status != StorageOperationStatus.OK) { - result = Either.right(status); - } - } + StorageOperationStatus statusRes; + Either<GraphVertex, TitanOperationStatus> getToscaElementRes; - if (result == null) { - result = Either.left(interfacesToDelete); - } - return result; + getToscaElementRes = titanDao.getVertexById(componentId, JsonParseFlagEnum.NoParse); + if (getToscaElementRes.isRight()) { + TitanOperationStatus status = getToscaElementRes.right().value(); + logger.debug("Failed to get tosca element {} while adding or updating interface. Status is {}. ", componentId, status); + statusRes = DaoStatusConverter.convertTitanStatusToStorageStatus(status); + return Either.right(statusRes); + } + GraphVertex componentVertex = getToscaElementRes.left().value(); + if (!isUpdateAction) { + interfaceDefinition.setUniqueId(UUID.randomUUID().toString()); + } + statusRes = performUpdateToscaAction(isUpdateAction, componentVertex, Arrays.asList(interfaceDefinition), EdgeLabelEnum.INTERFACE, VertexTypeEnum.INTERFACE); + if (!statusRes.equals(StorageOperationStatus.OK)) { + logger.debug("Failed to add or update interface of component {}. status is {}", componentId, statusRes); + return Either.right(statusRes); + } + return Either.left(interfaceDefinition); + } + + public Either<Operation, StorageOperationStatus> addInterfaceOperation(String componentId, InterfaceDefinition interfaceDef, Operation interfaceOperation) { + return addOrUpdateInterfaceOperation(false, componentId, interfaceDef, interfaceOperation); + } + + public Either<Operation, StorageOperationStatus> updateInterfaceOperation(String componentId, InterfaceDefinition interfaceDef, Operation interfaceOperation) { + return addOrUpdateInterfaceOperation(true, componentId, interfaceDef, interfaceOperation); + } + + private Either<Operation, StorageOperationStatus> addOrUpdateInterfaceOperation(boolean isUpdateAction, String componentId, InterfaceDefinition interfaceDef, Operation operation) { + + StorageOperationStatus statusRes; + Either<GraphVertex, TitanOperationStatus> getToscaElementRes; + Either<GraphVertex, TitanOperationStatus> getToscaElementInt; + + getToscaElementRes = titanDao.getVertexById(componentId, JsonParseFlagEnum.NoParse); + if (getToscaElementRes.isRight()) { + TitanOperationStatus status = getToscaElementRes.right().value(); + logger.debug("Failed to get tosca element {} while adding or updating operation. Status is {}. ", componentId, status); + statusRes = DaoStatusConverter.convertTitanStatusToStorageStatus(status); + return Either.right(statusRes); + } + GraphVertex componentVertex = getToscaElementRes.left().value(); + getToscaElementInt = titanDao.getChildVertex(componentVertex, EdgeLabelEnum.INTERFACE, JsonParseFlagEnum.NoParse); + if (getToscaElementInt.isRight()) { + TitanOperationStatus status = getToscaElementInt.right().value(); + logger.debug("Failed to get tosca element {} while adding or updating operation. Status is {}. ", interfaceDef.getUniqueId(), status); + statusRes = DaoStatusConverter.convertTitanStatusToStorageStatus(status); + return Either.right(statusRes); + } + GraphVertex interfaceVertex = getToscaElementInt.left().value(); + if (!isUpdateAction) { + initNewOperation(operation); } - public Either<InterfaceDefinition, StorageOperationStatus> addInterface(String resourceId, - InterfaceDefinition interfaceDefinition) { - return addOrUpdateInterface(false, resourceId, interfaceDefinition); + statusRes = performUpdateToscaAction(isUpdateAction, interfaceVertex, Arrays.asList(operation), + EdgeLabelEnum.INTERFACE_OPERATION, VertexTypeEnum.INTERFACE_OPERATION); + if (!statusRes.equals(StorageOperationStatus.OK)) { + logger.debug("Failed to add or update operation of interface {}. status is {}", interfaceDef.getUniqueId(), statusRes); + return Either.right(statusRes); } - public Either<InterfaceDefinition, StorageOperationStatus> updateInterface(String resourceId, - InterfaceDefinition interfaceDefinition) { - return addOrUpdateInterface(true, resourceId, interfaceDefinition); + getUpdatedInterfaceDef(interfaceDef, operation, operation.getUniqueId()); + Either<InterfaceDefinition, StorageOperationStatus> intUpdateStatus = updateInterface(componentId, interfaceDef); + if (intUpdateStatus.isRight() && !intUpdateStatus.right().value().equals(StorageOperationStatus.OK)) { + logger.debug("Failed to update interface details on component {}. status is {}", componentId, statusRes); + return Either.right(statusRes); } - private Either<InterfaceDefinition, StorageOperationStatus> addOrUpdateInterface( - boolean isUpdateAction, String resourceId, InterfaceDefinition interfaceDefinition) { + return Either.left(operation); + } - StorageOperationStatus statusRes; - Either<GraphVertex, TitanOperationStatus> getToscaElementRes; + public Either<Operation, StorageOperationStatus> deleteInterfaceOperation(String componentId, InterfaceDefinition interfaceDef, String operationToDelete) { + Either<GraphVertex, TitanOperationStatus> getInterfaceVertex; + Either<GraphVertex, TitanOperationStatus> getComponentVertex; + Operation operation = new Operation(); + StorageOperationStatus status = null; - getToscaElementRes = titanDao.getVertexById(resourceId, JsonParseFlagEnum.NoParse); - if (getToscaElementRes.isRight()) { - TitanOperationStatus status = getToscaElementRes.right().value(); - CommonUtility.addRecordToLog(logger, CommonUtility.LogLevelEnum.DEBUG, - "Failed to get tosca element {} upon adding the properties. Status is {}. ", resourceId, status); - statusRes = DaoStatusConverter.convertTitanStatusToStorageStatus(status); - return Either.right(statusRes); - } - GraphVertex resourceVertex = getToscaElementRes.left().value(); - if (!isUpdateAction) { - interfaceDefinition.setUniqueId(UUID.randomUUID().toString()); + getComponentVertex = titanDao.getVertexById(componentId, JsonParseFlagEnum.NoParse); + if (getComponentVertex.isRight()) { + return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(getComponentVertex.right().value())); + } + + getInterfaceVertex = titanDao.getChildVertex(getComponentVertex.left().value(), EdgeLabelEnum.INTERFACE, JsonParseFlagEnum.NoParse); + if (getInterfaceVertex.isRight()) { + return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(getInterfaceVertex.right().value())); + } + + Optional<Entry<String, Operation>> operationToRemove = interfaceDef.getOperationsMap().entrySet().stream() + .filter(entry -> entry.getValue().getUniqueId().equals(operationToDelete)).findAny(); + if (operationToRemove.isPresent()){ + Map.Entry<String, Operation> stringOperationEntry = operationToRemove.get(); + operation = stringOperationEntry.getValue(); + ArtifactDefinition implementationArtifact = operation.getImplementationArtifact(); + String artifactUUID = implementationArtifact.getArtifactUUID(); + CassandraOperationStatus cassandraStatus = artifactCassandraDao.deleteArtifact(artifactUUID); + if (cassandraStatus != CassandraOperationStatus.OK) { + logger.debug("Failed to delete the artifact {} from the database. ", artifactUUID); + return Either.right(DaoStatusConverter.convertCassandraStatusToStorageStatus(cassandraStatus)); + } + + if(interfaceDef.getOperationsMap().size() > 1){ + status = deleteToscaDataElements(getInterfaceVertex.left().value(), EdgeLabelEnum.INTERFACE_OPERATION, Arrays.asList(operationToDelete)); + if (status != StorageOperationStatus.OK) { + return Either.right(status); } - statusRes = performUpdateToscaAction(isUpdateAction, resourceVertex, Arrays.asList(interfaceDefinition), - JsonPresentationFields.INTERFACE); - if (!statusRes.equals(StorageOperationStatus.OK)) { - logger.error("Failed to find the parent capability of capability type {}. status is {}", resourceId, - statusRes); - return Either.right(statusRes); + } else { + status = removeToscaDataVertex(getInterfaceVertex.left().value(), EdgeLabelEnum.INTERFACE_OPERATION, VertexTypeEnum.INTERFACE_OPERATION); + if (status != StorageOperationStatus.OK) { + return Either.right(status); } - return Either.left(interfaceDefinition); - } + } - private StorageOperationStatus performUpdateToscaAction(boolean isUpdate, GraphVertex graphVertex, - List<InterfaceDefinition> toscaDataList, JsonPresentationFields mapKeyField) { - if (isUpdate) { - return updateToscaDataOfToscaElement(graphVertex, EdgeLabelEnum.INTERFACE_ARTIFACTS, - VertexTypeEnum.INTERFACE_ARTIFACTS, toscaDataList, JsonPresentationFields.UNIQUE_ID); - } else { - return addToscaDataToToscaElement(graphVertex, EdgeLabelEnum.INTERFACE_ARTIFACTS, - VertexTypeEnum.INTERFACE_ARTIFACTS, toscaDataList, JsonPresentationFields.UNIQUE_ID); + getUpdatedInterfaceDef(interfaceDef, null, operationToDelete); + if (interfaceDef.getOperations().isEmpty()) { + status = removeToscaDataVertex(getComponentVertex.left().value(), EdgeLabelEnum.INTERFACE, VertexTypeEnum.INTERFACE); + if (status != StorageOperationStatus.OK) { + return Either.right(status); } + } + else { + Either<InterfaceDefinition, StorageOperationStatus> intUpdateStatus = updateInterface(componentId, interfaceDef); + if (intUpdateStatus.isRight() && !intUpdateStatus.right().value().equals(StorageOperationStatus.OK)) { + return Either.right(status); + } + } } - + return Either.left(operation); + } + + public Either<Operation, StorageOperationStatus> getInterfaceOperation(InterfaceDefinition interfaceDef, String operationToGet) { + Operation operation = new Operation(); + Optional<Entry<String, Operation>> operationToFetch = interfaceDef.getOperationsMap().entrySet().stream() + .filter(entry -> entry.getValue().getUniqueId().equals(operationToGet)).findAny(); + if (operationToFetch.isPresent()){ + Map.Entry<String, Operation> stringOperationEntry = operationToFetch.get(); + operation = stringOperationEntry.getValue(); + } + return Either.left(operation); + } + + private StorageOperationStatus performUpdateToscaAction(boolean isUpdate, GraphVertex graphVertex, + List<ToscaDataDefinition> toscaDataList, EdgeLabelEnum edgeLabel, VertexTypeEnum vertexLabel) { + if (isUpdate) { + return updateToscaDataOfToscaElement(graphVertex, edgeLabel, vertexLabel, toscaDataList, JsonPresentationFields.UNIQUE_ID); + } else { + return addToscaDataToToscaElement(graphVertex, edgeLabel, vertexLabel, toscaDataList, JsonPresentationFields.UNIQUE_ID); + } + } + + private void initNewOperation(Operation operation){ + ArtifactDefinition artifactDefinition = new ArtifactDefinition(); + String artifactUUID = UUID.randomUUID().toString(); + artifactDefinition.setArtifactUUID(artifactUUID); + artifactDefinition.setUniqueId(artifactUUID); + artifactDefinition.setArtifactType(ArtifactTypeEnum.PLAN.getType()); + artifactDefinition.setArtifactGroupType(ArtifactGroupTypeEnum.LIFE_CYCLE); + operation.setImplementation(artifactDefinition); + operation.setUniqueId(UUID.randomUUID().toString()); + } + + private InterfaceDefinition getUpdatedInterfaceDef(InterfaceDefinition interfaceDef, Operation operation, String operationId){ + Map<String, Operation> operationMap = interfaceDef.getOperationsMap(); + if(operation != null && !operation.isEmpty()){ + operationMap.put(operationId, operation); + interfaceDef.setOperationsMap(operationMap); + } + else { + operationMap.remove(operationId); + interfaceDef.setOperationsMap(operationMap); + } + return interfaceDef; + } } 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 e01e02397f..0f124fd2eb 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 @@ -711,7 +711,7 @@ public class TopologyTemplateOperation extends ToscaElementOperation { } private TitanOperationStatus setInterfcesFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) { - Either<Map<String, InterfaceDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INTERFACE_ARTIFACTS); + Either<Map<String, InterfaceDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INTERFACE); if (result.isLeft()) { topologyTemplate.setInterfaces(result.left().value()); } else { @@ -730,7 +730,7 @@ public class TopologyTemplateOperation extends ToscaElementOperation { public StorageOperationStatus associateInterfacesToComponent(GraphVertex nodeTypeVertex, Map<String, InterfaceDataDefinition> interfaceMap) { if (interfaceMap != null && !interfaceMap.isEmpty()) { - Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INTERFACE_ARTIFACTS, EdgeLabelEnum.INTERFACE_ARTIFACTS, interfaceMap); + Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INTERFACE, EdgeLabelEnum.INTERFACE, interfaceMap); if (assosiateElementToData.isRight()) { return assosiateElementToData.right().value(); } diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/utils/InterfaceUtils.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/utils/InterfaceUtils.java index a350d7ea17..249de97d86 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/utils/InterfaceUtils.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/utils/InterfaceUtils.java @@ -65,27 +65,7 @@ public class InterfaceUtils { } } - public static Map<String, Operation> getInterfaceOperationsFromInterfaces( - Map<String, InterfaceDefinition> interfaces, - Resource resource) throws IllegalStateException { - if (MapUtils.isEmpty(interfaces)) { - return Collections.EMPTY_MAP; - } - Optional<InterfaceDefinition> optionalInterface = getInterfaceDefinitionFromToscaName( - interfaces.values(), resource.getName()); - if (!optionalInterface.isPresent()) { - return Collections.EMPTY_MAP; - } - InterfaceDefinition interfaceDefinition = optionalInterface.get(); - interfaceDefinition.getOperationsMap().values().stream() - .forEach(operation -> createInputOutput(operation, resource.getInputs())); - - - return interfaceDefinition.getOperationsMap(); - - } - - private static void createInputOutput(Operation operation, List<InputDefinition> inputs) throws IllegalStateException { + public static void createInputOutput(Operation operation, List<InputDefinition> inputs) throws IllegalStateException { ListDataDefinition<OperationInputDefinition> inputDefinitionListDataDefinition = operation.getInputs(); if (inputDefinitionListDataDefinition != null) { return; @@ -130,13 +110,5 @@ public class InterfaceUtils { } throw new IllegalStateException("Could not find output :"+ output.getLabel()); } - public static List<Operation> getOperationsFromInterface(Map<String, InterfaceDefinition> interfaces) { - List<Operation> operationData = new ArrayList<>(); - if (!MapUtils.isEmpty(interfaces)) { - operationData = interfaces.values().stream() - .filter(a -> MapUtils.isNotEmpty(a.getOperationsMap())) - .map(a-> new ArrayList<>(a.getOperationsMap().values())).flatMap(List::stream).collect(Collectors.toList()); - } - return operationData; - } + } |