From 1ecdbf74427467327de0b1e11cd0a839d6dc05bd Mon Sep 17 00:00:00 2001 From: priyanshu Date: Mon, 6 Aug 2018 14:31:02 +0530 Subject: 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 --- .../impl/InterfaceOperationBusinessLogic.java | 397 +++++++-------------- .../ResourceInterfaceOperationServlet.java | 148 +++----- .../impl/InterfaceOperationBusinessLogicTest.java | 89 +---- .../test/utils/InterfaceOperationTestUtils.java | 26 +- .../sdc/be/dao/jsongraph/types/EdgeLabelEnum.java | 4 +- .../sdc/be/dao/jsongraph/types/VertexTypeEnum.java | 4 +- .../jsontitan/operations/ArtifactsOperations.java | 2 +- .../jsontitan/operations/InterfaceOperation.java | 253 +++++++++---- .../operations/TopologyTemplateOperation.java | 4 +- .../be/model/jsontitan/utils/InterfaceUtils.java | 32 +- .../model/jsontitan/utils/InterfaceUtilsTest.java | 20 -- 11 files changed, 416 insertions(+), 563 deletions(-) diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogic.java index 3fd5df0ba9..803cdbf277 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogic.java @@ -17,37 +17,39 @@ package org.openecomp.sdc.be.components.impl; -import com.google.common.collect.Sets; import fj.data.Either; -import org.apache.commons.collections.CollectionUtils; -import org.apache.commons.collections.MapUtils; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Optional; import org.apache.commons.lang.StringUtils; -import org.apache.commons.lang3.tuple.Pair; import org.openecomp.sdc.be.components.validation.InterfaceOperationValidation; import org.openecomp.sdc.be.dao.api.ActionStatus; -import org.openecomp.sdc.be.dao.cassandra.ArtifactCassandraDao; -import org.openecomp.sdc.be.dao.cassandra.CassandraOperationStatus; import org.openecomp.sdc.be.datamodel.utils.UiComponentDataConverter; import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum; -import org.openecomp.sdc.be.model.*; +import org.openecomp.sdc.be.model.ComponentInstance; +import org.openecomp.sdc.be.model.ComponentParametersView; +import org.openecomp.sdc.be.model.InterfaceDefinition; +import org.openecomp.sdc.be.model.Operation; +import org.openecomp.sdc.be.model.Resource; +import org.openecomp.sdc.be.model.User; import org.openecomp.sdc.be.model.jsontitan.operations.InterfaceOperation; import org.openecomp.sdc.be.model.jsontitan.utils.InterfaceUtils; import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; import org.openecomp.sdc.be.ui.model.UiComponentDataTransfer; -import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum; -import org.openecomp.sdc.common.api.ArtifactTypeEnum; import org.openecomp.sdc.exception.ResponseFormat; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; -import java.util.*; - @Component("interfaceOperationBusinessLogic") public class InterfaceOperationBusinessLogic extends ComponentBusinessLogic{ + private static final Logger LOGGER = LoggerFactory.getLogger(InterfaceOperationBusinessLogic.class); + public static final String FAILED_TO_LOCK_COMPONENT_RESPONSE_IS = "Failed to lock component {}. Response is {}. "; + @Autowired private InterfaceOperationValidation interfaceOperationValidation; @@ -57,9 +59,6 @@ public class InterfaceOperationBusinessLogic extends ComponentBusinessLogic{ @Autowired private InterfaceOperation interfaceOperation; - @Autowired - private ArtifactCassandraDao artifactCassandraDao; - @Autowired private UiComponentDataConverter uiComponentDataConverter; @@ -67,323 +66,226 @@ public class InterfaceOperationBusinessLogic extends ComponentBusinessLogic{ this.interfaceOperation = interfaceOperation; } - public InterfaceOperationValidation getInterfaceOperationValidation() { - return interfaceOperationValidation; - } - - public void setInterfaceOperationValidation( - InterfaceOperationValidation interfaceOperationValidation) { + public void setInterfaceOperationValidation(InterfaceOperationValidation interfaceOperationValidation) { this.interfaceOperationValidation = interfaceOperationValidation; } - - public void setArtifactCassandraDao(ArtifactCassandraDao artifactCassandraDao) { - this.artifactCassandraDao = artifactCassandraDao; - } - - public Either deleteInterfaceOperation(String resourceId, Set interfaceOperationToDelete, User user, boolean lock) { - Resource resourceToDelete = initResourceToDeleteWFOp(resourceId, interfaceOperationToDelete); - validateUserAndRole(resourceToDelete, user, "deleteInterfaceOperation"); - if (CollectionUtils.isEmpty(interfaceOperationToDelete)){ + public Either deleteInterfaceOperation(String componentId, String interfaceOperationToDelete, User user, boolean lock) { + if (StringUtils.isEmpty(interfaceOperationToDelete)){ LOGGER.debug("Invalid parameter interfaceOperationToDelete was empty"); return Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_PROPERTY)); } - Either storageStatus = toscaOperationFacade.getToscaElement(resourceId); - if (storageStatus.isRight()) { - return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(storageStatus.right().value(), - ComponentTypeEnum.RESOURCE), StringUtils.EMPTY)); + Either componentEither = getComponentDetails(componentId); + if (componentEither.isRight()){ + return Either.right(componentEither.right().value()); } - Resource resource = storageStatus.left().value(); + org.openecomp.sdc.be.model.Component storedComponent = componentEither.left().value(); + validateUserAndRole(storedComponent, user, "deleteInterfaceOperation"); + if (lock) { - Either lockResult = lockComponent(resource.getUniqueId(), resource, - "Delete interface Operation on a resource"); + Either lockResult = lockComponent(storedComponent.getUniqueId(), storedComponent, "Delete interface Operation on a storedComponent"); if (lockResult.isRight()) { - LOGGER.debug("Failed to lock resource {}. Response is {}. ", resource.getName(), lockResult.right().value().getFormattedMessage()); + LOGGER.debug(FAILED_TO_LOCK_COMPONENT_RESPONSE_IS, storedComponent.getName(), lockResult.right().value().getFormattedMessage()); titanDao.rollback(); return Either.right(lockResult.right().value()); } } try { - Optional optionalInterface = InterfaceUtils - .getInterfaceDefinitionFromToscaName(resource.getInterfaces().values(), resource.getName()); - Either sValue = getInterfaceDefinition(resource, optionalInterface.orElse(null)); + Optional optionalInterface = InterfaceUtils.getInterfaceDefinitionFromToscaName(((Resource)storedComponent).getInterfaces().values(), storedComponent.getName()); + Either sValue = getInterfaceDefinition(storedComponent, optionalInterface.orElse(null)); if (sValue.isRight()) { return Either.right(sValue.right().value()); } InterfaceDefinition interfaceDefinition = sValue.left().value(); - for(String operationToDelete : interfaceOperationToDelete) { - Either, ResponseFormat> deleteEither = deleteOperationFromInterface(interfaceDefinition, operationToDelete); - if (deleteEither.isRight()){ - return Either.right(deleteEither.right().value()); - } - - Operation deletedOperation = deleteEither.left().value().getValue(); - ArtifactDefinition implementationArtifact = deletedOperation.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); - ResponseFormat responseFormatByArtifactId = componentsUtils.getResponseFormatByArtifactId( - componentsUtils.convertFromStorageResponse(componentsUtils.convertToStorageOperationStatus(cassandraStatus)), - implementationArtifact.getArtifactDisplayName()); - return Either.right(responseFormatByArtifactId); - } + Either deleteEither = interfaceOperation.deleteInterfaceOperation(componentId, interfaceDefinition, interfaceOperationToDelete); + if (deleteEither.isRight()){ + LOGGER.error("Failed to delete interface operation from storedComponent {}. Response is {}. ", storedComponent.getName(), deleteEither.right().value()); + return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(deleteEither.right().value(), ComponentTypeEnum.RESOURCE))); + } + titanDao.commit(); + return Either.left(deleteEither.left().value()); + } catch (Exception e){ + LOGGER.error("Exception occurred during delete interface operation : {}", e.getMessage(), e); + titanDao.rollback(); + return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR)); + } finally { + graphLockOperation.unlockComponent(storedComponent.getUniqueId(), NodeTypeEnum.Resource); + } + } + + public Either getInterfaceOperation(String componentId, String interfaceOperationToGet, User user, boolean lock) { + if (StringUtils.isEmpty(interfaceOperationToGet)){ + LOGGER.debug("Invalid parameter interfaceOperationToGet was empty"); + return Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_PROPERTY)); + } + Either componentEither = getComponentDetails(componentId); + if (componentEither.isRight()){ + return Either.right(componentEither.right().value()); + } + org.openecomp.sdc.be.model.Component storedComponent = componentEither.left().value(); + validateUserAndRole(storedComponent, user, "getInterfaceOperation"); + if (lock) { + Either lockResult = lockComponent(storedComponent.getUniqueId(), storedComponent, "Get interface Operation on a storedComponent"); + if (lockResult.isRight()) { + LOGGER.debug(FAILED_TO_LOCK_COMPONENT_RESPONSE_IS, storedComponent.getName(), lockResult.right().value().getFormattedMessage()); + titanDao.rollback(); + return Either.right(lockResult.right().value()); } + } - Either interfaceUpdate = interfaceOperation.updateInterface(resource.getUniqueId(), interfaceDefinition); - if (interfaceUpdate.isRight()) { - LOGGER.debug("Failed to delete interface operation from resource {}. Response is {}. ", resource.getName(), interfaceUpdate.right().value()); - titanDao.rollback(); - return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(interfaceUpdate.right().value(), ComponentTypeEnum.RESOURCE))); + try { + Optional optionalInterface = InterfaceUtils.getInterfaceDefinitionFromToscaName(((Resource)storedComponent).getInterfaces().values(), storedComponent.getName()); + Either sValue = getInterfaceDefinition(storedComponent, optionalInterface.orElse(null)); + if (sValue.isRight()) { + return Either.right(sValue.right().value()); } + InterfaceDefinition interfaceDefinition = sValue.left().value(); - if(interfaceDefinition.getOperationsMap().isEmpty()){ - Either, StorageOperationStatus> deleteInterface = interfaceOperation.deleteInterface(resource, Sets.newHashSet(interfaceDefinition.getUniqueId())); - if (deleteInterface.isRight()) { - LOGGER.debug("Failed to delete interface from resource {}. Response is {}. ", resource.getName(), deleteInterface.right().value()); - titanDao.rollback(); - return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(deleteInterface.right().value(), ComponentTypeEnum.RESOURCE))); - } + Either getEither = interfaceOperation.getInterfaceOperation(interfaceDefinition, interfaceOperationToGet); + if (getEither.isRight()){ + LOGGER.error("Failed to get interface operation from storedComponent {}. Response is {}. ", storedComponent.getName(), getEither.right().value()); + return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(getEither.right().value(), ComponentTypeEnum.RESOURCE))); } titanDao.commit(); - + return Either.left(getEither.left().value()); } catch (Exception e){ - LOGGER.error("Exception occurred during delete interface operation : {}", e.getMessage(), e); + LOGGER.error("Exception occurred during get interface operation : {}", e.getMessage(), e); titanDao.rollback(); return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR)); } finally { - graphLockOperation.unlockComponent(resource.getUniqueId(), NodeTypeEnum.Resource); + graphLockOperation.unlockComponent(storedComponent.getUniqueId(), NodeTypeEnum.Resource); } - return Either.left(resource); } - public Either getInterfaceDefinition(Resource resource, - InterfaceDefinition interfaceDef) { + public Either getInterfaceDefinition(org.openecomp.sdc.be.model.Component component, InterfaceDefinition interfaceDef) { if (interfaceDef != null){ return Either.left(interfaceDef); } else { InterfaceDefinition interfaceDefinition = new InterfaceDefinition(); - interfaceDefinition.setToscaResourceName(InterfaceUtils.createInterfaceToscaResourceName(resource.getName())); - Either interfaceCreateEither = interfaceOperation - .addInterface(resource.getUniqueId(), interfaceDefinition); + interfaceDefinition.setToscaResourceName(InterfaceUtils.createInterfaceToscaResourceName(component.getName())); + Either interfaceCreateEither = interfaceOperation.addInterface(component.getUniqueId(), interfaceDefinition); if (interfaceCreateEither.isRight()){ StorageOperationStatus sValue = interfaceCreateEither.right().value(); return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(sValue, - ComponentTypeEnum.RESOURCE), "")); - + ComponentTypeEnum.RESOURCE), "")); } return Either.left(interfaceCreateEither.left().value()); } } - private Either,ResponseFormat> deleteOperationFromInterface(InterfaceDefinition interfaceDefinition, String operationId){ - Optional> operationToRemove = interfaceDefinition.getOperationsMap().entrySet().stream() - .filter(entry -> entry.getValue().getUniqueId().equals(operationId)).findAny(); - if (operationToRemove.isPresent()){ - Map.Entry stringOperationEntry = operationToRemove.get(); - Map tempMap = interfaceDefinition.getOperationsMap(); - tempMap.remove(stringOperationEntry.getKey()); - interfaceDefinition.setOperationsMap(tempMap); - return Either.left(Pair.of(interfaceDefinition,stringOperationEntry.getValue())); - } - LOGGER.debug("Failed to delete interface operation"); - return Either.right(componentsUtils.getResponseFormat(ActionStatus.INTERFACE_OPERATION_NOT_FOUND)); + public Either createInterfaceOperation(String componentId, Operation operation, User user, boolean lock) { + return createOrUpdateInterfaceOperation(componentId, operation, user, false, "createInterfaceOperation", lock); } - - private Either addOperationToInterface(InterfaceDefinition interfaceDefinition, Operation interfaceOperation){ - if(interfaceOperation.getUniqueId() == null) - interfaceOperation.setUniqueId(UUID.randomUUID().toString()); - if (interfaceOperation.getImplementationArtifact() == null){ - initNewOperation(interfaceOperation); - } - Map tempMap = interfaceDefinition.getOperationsMap(); - tempMap.put(interfaceOperation.getUniqueId(), interfaceOperation); - interfaceDefinition.setOperationsMap(tempMap); - return Either.left(interfaceDefinition); + public Either updateInterfaceOperation(String componentId, Operation operation, User user, boolean lock) { + return createOrUpdateInterfaceOperation(componentId, operation, user, true, "updateInterfaceOperation", lock); } - private Either updateOperationInInterface(InterfaceDefinition interfaceDefinition, Operation interfaceOperation){ - Optional> operationToUpdate = interfaceDefinition.getOperationsMap().entrySet().stream() - .filter(entry -> entry.getValue().getUniqueId().equals(interfaceOperation.getUniqueId())).findAny(); - if (operationToUpdate.isPresent()){ - Operation updatedOperation = updateOperation(operationToUpdate.get().getValue(),interfaceOperation); - Map tempMap = interfaceDefinition.getOperationsMap(); - tempMap.remove(updatedOperation.getUniqueId()); - tempMap.put(updatedOperation.getUniqueId(), updatedOperation); - interfaceDefinition.setOperationsMap(tempMap); - return Either.left(interfaceDefinition); - } - LOGGER.debug("Failed to update interface operation"); - return Either.right(componentsUtils.getResponseFormat(ActionStatus.INTERFACE_OPERATION_NOT_FOUND)); - } - - private Operation updateOperation(Operation dbOperation, Operation updatedOperation) { - dbOperation.setName(updatedOperation.getName()); - dbOperation.setDescription(updatedOperation.getDescription()); - dbOperation.setInputs(updatedOperation.getInputs()); - dbOperation.setOutputs(updatedOperation.getOutputs()); - dbOperation.setWorkflowId(updatedOperation.getWorkflowId()); - dbOperation.setWorkflowVersionId(updatedOperation.getWorkflowVersionId()); - return dbOperation; - } - - public Either updateInterfaceOperation(String resourceId, Resource resourceUpdate, User user, boolean lock) { - return createOrUpdateInterfaceOperation(resourceId, resourceUpdate, user, true, "updateInterfaceOperation", lock); - } - - public Either createInterfaceOperation(String resourceId, Resource resourceUpdate, User user, boolean lock) { - return createOrUpdateInterfaceOperation(resourceId, resourceUpdate, user, false, "createInterfaceOperation", lock); - } - - private Either createOrUpdateInterfaceOperation(String resourceId, Resource resourceUpdate, User user, boolean isUpdate, String errorContext, boolean lock) { - validateUserAndRole(resourceUpdate, user, errorContext); - - Either resourceEither = getResourceDetails(resourceId); - if (resourceEither.isRight()){ - return resourceEither; - } - - Resource storedResource = resourceEither.left().value(); - - Map interfaceOperations = InterfaceUtils - .getInterfaceOperationsFromInterfaces(resourceUpdate.getInterfaces(), storedResource); - if(MapUtils.isEmpty(interfaceOperations) ) { - LOGGER.debug("Failed to fetch interface operations from resource {}, error {}",resourceUpdate.getUniqueId(), - ActionStatus.INTERFACE_OPERATION_NOT_FOUND); - return Either.right(componentsUtils.getResponseFormat(ActionStatus.INTERFACE_OPERATION_NOT_FOUND, - resourceUpdate.getUniqueId())); + private Either createOrUpdateInterfaceOperation(String componentId, Operation operation, User user, boolean isUpdate, String errorContext, boolean lock) { + Either componentEither = getComponentDetails(componentId); + if (componentEither.isRight()){ + return Either.right(componentEither.right().value()); } + org.openecomp.sdc.be.model.Component storedComponent = componentEither.left().value(); + validateUserAndRole(storedComponent, user, errorContext); + InterfaceUtils.createInputOutput(operation, storedComponent.getInputs()); Either interfaceOperationValidationResponseEither = interfaceOperationValidation - .validateInterfaceOperations( interfaceOperations.values(), resourceId, isUpdate); - + .validateInterfaceOperations(Arrays.asList(operation), componentId, isUpdate); if(interfaceOperationValidationResponseEither.isRight()) { return Either.right(interfaceOperationValidationResponseEither.right().value()); } Either lockResult = null; if (lock) { - lockResult = lockComponent(storedResource.getUniqueId(), storedResource, - "Create or Update interface Operation on Resource"); + lockResult = lockComponent(storedComponent.getUniqueId(), storedComponent, "Create or Update interface Operation on Component"); if (lockResult.isRight()) { - LOGGER.debug("Failed to lock resource {}. Response is {}. ", storedResource.getName(), lockResult.right().value().getFormattedMessage()); + LOGGER.debug(FAILED_TO_LOCK_COMPONENT_RESPONSE_IS, storedComponent.getName(), lockResult.right().value().getFormattedMessage()); titanDao.rollback(); return Either.right(lockResult.right().value()); - } else { - LOGGER.debug("The resource with system name {} locked. ", storedResource.getSystemName()); } } - Either result; - Map resultMap = new HashMap<>(); - + Either result; try { - Optional optionalInterface = InterfaceUtils - .getInterfaceDefinitionFromToscaName(storedResource.getInterfaces().values(), storedResource.getName()); - Either sValue = getInterfaceDefinition(storedResource, optionalInterface.orElse(null)); + Optional optionalInterface = InterfaceUtils.getInterfaceDefinitionFromToscaName(((Resource)storedComponent).getInterfaces().values(), storedComponent.getName()); + Either sValue = getInterfaceDefinition(storedComponent, optionalInterface.orElse(null)); if (sValue.isRight()) { return Either.right(sValue.right().value()); } InterfaceDefinition interfaceDefinition = sValue.left().value(); - for (Operation interfaceOperation : interfaceOperations.values()) { - if (isUpdate) { - result = updateOperationInInterface(interfaceDefinition, interfaceOperation); - } else { - result = addOperationToInterface(interfaceDefinition, interfaceOperation); - } - if (result.isRight()) { - titanDao.rollback(); - return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR)); - } else { - interfaceDefinition = result.left().value(); - resultMap.put(interfaceDefinition.getUniqueId(), interfaceDefinition); - } + if (isUpdate) { + result = interfaceOperation.updateInterfaceOperation(componentId, interfaceDefinition, operation); + } else { + result = interfaceOperation.addInterfaceOperation(componentId, interfaceDefinition, operation); } - - Either interfaceUpdate = interfaceOperation - .updateInterface(storedResource.getUniqueId(), interfaceDefinition); - if (interfaceUpdate.isRight()) { - LOGGER.debug("Failed to add or update interface operation on resource {}. Response is {}. ", storedResource.getName(), interfaceUpdate.right().value()); + if (result.isRight()) { titanDao.rollback(); - return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(interfaceUpdate.right().value(), ComponentTypeEnum.RESOURCE))); + LOGGER.debug("Failed to add/update interface operation on component {}. Response is {}. ", storedComponent.getName(), result.right().value()); + return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(result.right().value(), ComponentTypeEnum.RESOURCE))); } titanDao.commit(); - - Resource resource = createVFWithInterfaceOperationForResponse(resourceId, resultMap); - return Either.left(resource); + return Either.left(result.left().value()); } catch (Exception e) { titanDao.rollback(); - LOGGER.error("Exception occurred during add or update interface operation property values:{}", - e.getMessage(), e); + LOGGER.error("Exception occurred during add or update interface operation property values:{}", e.getMessage(), e); return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR)); } finally { if (lockResult != null && lockResult.isLeft() && lockResult.left().value()) { - graphLockOperation.unlockComponent(storedResource.getUniqueId(), NodeTypeEnum.Resource); + graphLockOperation.unlockComponent(storedComponent.getUniqueId(), NodeTypeEnum.Resource); } } } - 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); + private void validateUserAndRole(org.openecomp.sdc.be.model.Component component, User user, String errorContext) { + user = validateUser(user, errorContext, component, null, false); + validateUserRole(user, component, new ArrayList<>(), null, null); } - private Resource initResourceToDeleteWFOp(String resourceId, Collection interfaceOperationsToDelete) { - InterfaceDefinition id = new InterfaceDefinition(); - id.setUniqueId(UUID.randomUUID().toString()); - interfaceOperationsToDelete.forEach(interfaceOpToDelete -> id.getOperationsMap().put(interfaceOpToDelete, new Operation())); - Map interfaceDefinitionMap = new HashMap<>(); - interfaceDefinitionMap.put(id.getUniqueId(), id); - - Resource resourceToDelete = new Resource(); - resourceToDelete.setUniqueId(resourceId); - resourceToDelete.setInterfaces(interfaceDefinitionMap); - - return resourceToDelete; - } - - private void validateUserAndRole(Resource resourceUpdate, User user, String errorContext) { - user = validateUser(user, errorContext, resourceUpdate, null, false); - validateUserRole(user, resourceUpdate, new ArrayList<>(), null, null); + private Either getComponentDetails(String componentId){ + Either componentStorageOperationStatusEither = toscaOperationFacade.getToscaElement(componentId); + if (componentStorageOperationStatusEither.isRight()) { + StorageOperationStatus errorStatus = componentStorageOperationStatusEither.right().value(); + LOGGER.error("Failed to fetch component information by component id {}, error {}", componentId, errorStatus); + return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(errorStatus))); + } + return Either.left(componentStorageOperationStatusEither.left().value()); } + @Override + public Either getUiComponentDataTransferByComponentId(String componentId, List dataParamsToReturn) { + ComponentParametersView paramsToRetuen = new ComponentParametersView(dataParamsToReturn); + Either componentResultEither = toscaOperationFacade.getToscaElement(componentId, paramsToRetuen); + if (componentResultEither.isRight()) { + if (componentResultEither.right().value().equals(StorageOperationStatus.NOT_FOUND)) { + LOGGER.error("Failed to found component with id {} ", componentId); + Either.right(componentsUtils.getResponseFormat(ActionStatus.RESOURCE_NOT_FOUND, componentId)); + } + LOGGER.error("failed to get component by id {} with filters {}", componentId, dataParamsToReturn); + return Either.right(componentsUtils.getResponseFormatByResource(componentsUtils.convertFromStorageResponse(componentResultEither.right().value()), "")); + } - private Resource createVFWithInterfaceOperationForResponse(String resourceId, Map interfaceDefinitionMap) { - Resource resource = new Resource(); - resource.setUniqueId(resourceId); - resource.setInterfaces(interfaceDefinitionMap); - return resource; + org.openecomp.sdc.be.model.Component component = componentResultEither.left().value(); + UiComponentDataTransfer dataTransfer = uiComponentDataConverter.getUiDataTransferFromResourceByParams((Resource)component, dataParamsToReturn); + return Either.left(dataTransfer); } - public Either getResourceDetails(String resourceId){ - Either resourceStorageOperationStatusEither = - toscaOperationFacade.getToscaElement(resourceId); - if (resourceStorageOperationStatusEither.isRight()) { - StorageOperationStatus errorStatus = resourceStorageOperationStatusEither.right().value(); - LOGGER.error("Failed to fetch resource information by resource id {}, error {}", resourceId, errorStatus); - return Either.right(componentsUtils - .getResponseFormat(componentsUtils.convertFromStorageResponse(errorStatus))); - } - return Either.left(resourceStorageOperationStatusEither.left().value()); + @Override + public Either, ResponseFormat> getComponentInstancesFilteredByPropertiesAndInputs( + String componentId, String userId) { + return null; } - @Override public Either, ResponseFormat> deleteMarkedComponents() { return deleteMarkedComponents(ComponentTypeEnum.RESOURCE); @@ -394,35 +296,4 @@ public class InterfaceOperationBusinessLogic extends ComponentBusinessLogic{ return componentInstanceBusinessLogic; } - @Override - public Either getUiComponentDataTransferByComponentId(String resourceId, - List dataParamsToReturn) { - ComponentParametersView paramsToRetuen = new ComponentParametersView(dataParamsToReturn); - Either resourceResultEither = toscaOperationFacade.getToscaElement(resourceId, - paramsToRetuen); - - if (resourceResultEither.isRight()) { - if (resourceResultEither.right().value().equals(StorageOperationStatus.NOT_FOUND)) { - LOGGER.error("Failed to found resource with id {} ", resourceId); - Either.right(componentsUtils.getResponseFormat(ActionStatus.RESOURCE_NOT_FOUND, resourceId)); - } - - LOGGER.error("failed to get resource by id {} with filters {}", resourceId, dataParamsToReturn); - return Either.right(componentsUtils.getResponseFormatByResource( - componentsUtils.convertFromStorageResponse(resourceResultEither.right().value()), "")); - } - - Resource resource = resourceResultEither.left().value(); - UiComponentDataTransfer dataTransfer = uiComponentDataConverter.getUiDataTransferFromResourceByParams(resource, - dataParamsToReturn); - return Either.left(dataTransfer); - } - - @Override - public Either, ResponseFormat> getComponentInstancesFilteredByPropertiesAndInputs( - String componentId, String userId) { - return null; - } - - } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ResourceInterfaceOperationServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ResourceInterfaceOperationServlet.java index d5d65a39c5..4d84e2c1a0 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ResourceInterfaceOperationServlet.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ResourceInterfaceOperationServlet.java @@ -16,41 +16,45 @@ package org.openecomp.sdc.be.servlets; -import com.google.common.collect.Sets; import com.jcabi.aspects.Loggable; import fj.data.Either; -import io.swagger.annotations.*; -import org.apache.commons.collections.CollectionUtils; -import org.apache.commons.collections.MapUtils; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; +import io.swagger.annotations.ApiResponse; +import io.swagger.annotations.ApiResponses; +import java.util.Optional; +import java.util.UUID; +import javax.inject.Singleton; +import javax.servlet.ServletContext; +import javax.servlet.http.HttpServletRequest; +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.HeaderParam; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; import org.openecomp.sdc.be.components.impl.InterfaceOperationBusinessLogic; import org.openecomp.sdc.be.config.BeEcompErrorManager; import org.openecomp.sdc.be.dao.api.ActionStatus; import org.openecomp.sdc.be.datamodel.utils.InterfaceUIDataConverter; import org.openecomp.sdc.be.datatypes.elements.InterfaceOperationDataDefinition; -import org.openecomp.sdc.be.datatypes.enums.ComponentFieldsEnum; import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; -import org.openecomp.sdc.be.model.InterfaceDefinition; import org.openecomp.sdc.be.model.Operation; -import org.openecomp.sdc.be.model.Resource; import org.openecomp.sdc.be.model.User; -import org.openecomp.sdc.be.model.jsontitan.utils.InterfaceUtils; import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum; -import org.openecomp.sdc.be.ui.model.UiComponentDataTransfer; import org.openecomp.sdc.be.ui.model.UiResourceDataTransfer; import org.openecomp.sdc.common.api.Constants; import org.openecomp.sdc.exception.ResponseFormat; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.inject.Singleton; -import javax.servlet.ServletContext; -import javax.servlet.http.HttpServletRequest; -import javax.ws.rs.*; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import java.util.*; - @Loggable(prepend = true, value = Loggable.DEBUG, trim = false) @Path("/v1/catalog/resources/{resourceId}/interfaceOperations") @Consumes(MediaType.APPLICATION_JSON) @@ -78,7 +82,6 @@ public class ResourceInterfaceOperationServlet extends AbstractValidationsServle return createOrUpdate(data, resourceId, request, userId, false); } - @PUT @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @@ -95,7 +98,6 @@ public class ResourceInterfaceOperationServlet extends AbstractValidationsServle return createOrUpdate(data, resourceId, request, userId, true); } - @DELETE @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @@ -137,20 +139,24 @@ public class ResourceInterfaceOperationServlet extends AbstractValidationsServle modifier.setUserId(userId); log.debug("Start get request of {} with modifier id {}", url, userId); + Response response; + try { + String resourceIdLower = resourceId.toLowerCase(); InterfaceOperationBusinessLogic businessLogic = getInterfaceOperationBL(context); - Either resourceResponse = businessLogic.getComponentDataFilteredByParams(resourceId, modifier, Collections - .singletonList(ComponentFieldsEnum.INTERFACES.getValue())); - if (resourceResponse.isRight()) { - return buildErrorResponse(resourceResponse.right().value()); - } - - UiResourceDataTransfer uiResourceDataTransfer = (UiResourceDataTransfer) resourceResponse.left().value(); - InterfaceOperationDataDefinition interfaceOperationDataDefinition = getInterfaceOperationForResponse(interfaceOperationId, uiResourceDataTransfer.getInterfaces()); - return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), RepresentationUtils.toFilteredRepresentation(interfaceOperationDataDefinition)); + Either actionResponse = businessLogic.getInterfaceOperation(resourceIdLower, interfaceOperationId, modifier, true); + if (actionResponse.isRight()) { + log.debug("failed to get interface operation"); + response = buildErrorResponse(actionResponse.right().value()); + return response; + } - } catch (Exception e) { + InterfaceOperationDataDefinition interfaceOperationDataDefinition = InterfaceUIDataConverter.convertOperationDataToInterfaceData(actionResponse.left().value()); + Object result = RepresentationUtils.toFilteredRepresentation(interfaceOperationDataDefinition); + return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result); + } + catch (Exception e) { BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Resource interface operations"); log.debug("get resource interface operations failed with exception", e); return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR)); @@ -173,25 +179,22 @@ public class ResourceInterfaceOperationServlet extends AbstractValidationsServle String resourceIdLower = resourceId.toLowerCase(); InterfaceOperationBusinessLogic businessLogic = getInterfaceOperationBL(context); - Either actionResponse = businessLogic.deleteInterfaceOperation(resourceIdLower, Sets.newHashSet(interfaceOperationId), modifier, true); - + Either actionResponse = businessLogic.deleteInterfaceOperation(resourceIdLower, interfaceOperationId, modifier, true); if (actionResponse.isRight()) { log.debug("failed to delete interface operation"); response = buildErrorResponse(actionResponse.right().value()); return response; } - Resource resource = actionResponse.left().value(); - InterfaceOperationDataDefinition interfaceOperationDataDefinition = getInterfaceOperationForResponse(interfaceOperationId, resource.getInterfaces()); + InterfaceOperationDataDefinition interfaceOperationDataDefinition = InterfaceUIDataConverter.convertOperationDataToInterfaceData(actionResponse.left().value()); Object result = RepresentationUtils.toFilteredRepresentation(interfaceOperationDataDefinition); return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result); - - } catch (Exception e) { + } + catch (Exception e) { BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Delete Interface Operation"); log.debug("Delete interface operation with an error", e); response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR)); return response; - } } @@ -208,22 +211,12 @@ public class ResourceInterfaceOperationServlet extends AbstractValidationsServle String resourceIdLower = resourceId.toLowerCase(); InterfaceOperationBusinessLogic businessLogic = getInterfaceOperationBL(context); - Either resourceEither = businessLogic.getResourceDetails(resourceId); - Resource origResource = resourceEither.left().value(); - - Either convertResponse = parseToResource(data, origResource, isUpdate, modifier); - if (convertResponse.isRight()) { - log.debug("failed to parse resource"); - response = buildErrorResponse(convertResponse.right().value()); - return response; - } - - Resource updatedResource = convertResponse.left().value(); - Either actionResponse ; + Operation operation = getMappedOperationData(data, isUpdate, modifier); + Either actionResponse ; if (isUpdate) { - actionResponse = businessLogic.updateInterfaceOperation(resourceIdLower, updatedResource, modifier, true); + actionResponse = businessLogic.updateInterfaceOperation(resourceIdLower, operation, modifier, true); } else { - actionResponse = businessLogic.createInterfaceOperation(resourceIdLower, updatedResource, modifier, true); + actionResponse = businessLogic.createInterfaceOperation(resourceIdLower, operation, modifier, true); } if (actionResponse.isRight()) { @@ -232,67 +225,28 @@ public class ResourceInterfaceOperationServlet extends AbstractValidationsServle return response; } - Resource resource = actionResponse.left().value(); - List operationData = InterfaceUtils.getOperationsFromInterface(updatedResource.getInterfaces()); - InterfaceOperationDataDefinition interfaceOperationDataDefinition = getInterfaceOperationForResponse(operationData.get(0).getUniqueId(), resource.getInterfaces()); - + InterfaceOperationDataDefinition interfaceOperationDataDefinition = InterfaceUIDataConverter.convertOperationDataToInterfaceData(actionResponse.left().value()); Object result = RepresentationUtils.toFilteredRepresentation(interfaceOperationDataDefinition); return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result); - - } catch (Exception e) { + } + catch (Exception e) { BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Interface Operation Creation or update"); log.debug("create or update interface Operation with an error", e); response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR)); return response; - } } - private Either parseToResource(String resourceJson, Resource origResource, boolean isUpdate, User user) { - - Resource resource = convertToResourceObject(resourceJson, user).left().value(); - - Either uiResourceEither = getComponentsUtils().convertJsonToObjectUsingObjectMapper(resourceJson, user, UiResourceDataTransfer.class, AuditingActionEnum.CREATE_RESOURCE, ComponentTypeEnum.RESOURCE); + private Operation getMappedOperationData(String inputJson, boolean isUpdate, User user){ + Either uiResourceEither = getComponentsUtils().convertJsonToObjectUsingObjectMapper(inputJson, user, UiResourceDataTransfer.class, AuditingActionEnum.CREATE_RESOURCE, ComponentTypeEnum.RESOURCE); Optional opDef = uiResourceEither.left().value().getInterfaceOperations().values().stream().findFirst(); - InterfaceOperationDataDefinition interfaceOperationDataDefinition; + InterfaceOperationDataDefinition interfaceOperationDataDefinition = new InterfaceOperationDataDefinition(); if(opDef.isPresent()) { interfaceOperationDataDefinition = opDef.get(); - if(!isUpdate) interfaceOperationDataDefinition.setUniqueId(UUID.randomUUID().toString()); - - Map interfaceOperations = new HashMap<>(); - interfaceOperations.put(interfaceOperationDataDefinition.getUniqueId(), InterfaceUIDataConverter.convertInterfaceDataToOperationData(interfaceOperationDataDefinition)); - InterfaceDefinition interfaceDefinition = new InterfaceDefinition(); - interfaceDefinition.setUniqueId(UUID.randomUUID().toString()); - interfaceDefinition.setToscaResourceName(InterfaceUtils.createInterfaceToscaResourceName(origResource.getName())); - interfaceDefinition.setOperationsMap(interfaceOperations); - - Map interfaceMap = new HashMap<>(); - interfaceMap.put(interfaceDefinition.getUniqueId(), interfaceDefinition); - - resource.setInterfaces(interfaceMap); - } - - return Either.left(resource); - } - - private Either convertToResourceObject(String resourceJson, User user) { - return getComponentsUtils().convertJsonToObjectUsingObjectMapper(resourceJson, user, Resource.class, AuditingActionEnum.CREATE_RESOURCE, ComponentTypeEnum.RESOURCE); - } - - private InterfaceOperationDataDefinition getInterfaceOperationForResponse(String interfaceOperationId, Map interfaces){ - InterfaceOperationDataDefinition interfaceOperationDataDefinition = new InterfaceOperationDataDefinition(); - if(!MapUtils.isEmpty(interfaces)){ - List operationData = InterfaceUtils.getOperationsFromInterface(interfaces); - if(CollectionUtils.isNotEmpty(operationData)){ - Optional matchedOp = operationData.stream().filter(a -> a.getUniqueId().equals(interfaceOperationId)).findAny(); - if(matchedOp.isPresent()) { - interfaceOperationDataDefinition = InterfaceUIDataConverter.convertOperationDataToInterfaceData(matchedOp.get()); - } - } } - return interfaceOperationDataDefinition; + return InterfaceUIDataConverter.convertInterfaceDataToOperationData(interfaceOperationDataDefinition); } } diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogicTest.java index dd67921970..b9e0b594ea 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogicTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogicTest.java @@ -70,10 +70,10 @@ public class InterfaceOperationBusinessLogicTest { public static final String RESOURCE_CATEGORY1 = "Network Layer 2-3"; public static final String RESOURCE_SUBCATEGORY = "Router"; - private String resourceId = "resourceId1"; private String operationId = "uniqueId1"; Resource resourceUpdate; + Operation operation; public static final String RESOURCE_NAME = "My-Resource_Name with space"; @@ -102,7 +102,6 @@ public class InterfaceOperationBusinessLogicTest { ArtifactsBusinessLogic artifactManager = new ArtifactsBusinessLogic(); private GenericTypeBusinessLogic genericTypeBusinessLogic = Mockito.mock(GenericTypeBusinessLogic.class); - @InjectMocks InterfaceOperationBusinessLogic bl = new InterfaceOperationBusinessLogic(); @@ -167,12 +166,14 @@ public class InterfaceOperationBusinessLogicTest { when(applicationDataTypeCache.getAll()).thenReturn(Either.left(emptyDataTypes)); //InterfaceOperation - when(operationValidator.validateInterfaceOperations(anyCollection(), anyString(), anyBoolean())).thenReturn(Either.left(true)); when(interfaceOperation.addInterface(anyString(), anyObject())).thenReturn(Either.left(InterfaceOperationTestUtils.mockInterfaceDefinitionToReturn(RESOURCE_NAME))); when(interfaceOperation.updateInterface(anyString(), anyObject())).thenReturn(Either.left(InterfaceOperationTestUtils.mockInterfaceDefinitionToReturn(RESOURCE_NAME))); - when(interfaceOperation.deleteInterface(anyObject(), anyObject())).thenReturn(Either.left(new HashSet<>())); - when(interfaceOperation.deleteInterface(any(),any())).thenReturn(Either.left(new HashSet<>())); + when(interfaceOperation.addInterfaceOperation(anyObject(), anyObject(), anyObject())).thenReturn(Either.left(InterfaceOperationTestUtils.mockOperationToReturn(RESOURCE_NAME))); + when(interfaceOperation.updateInterfaceOperation(anyObject(), anyObject(), anyObject())).thenReturn(Either.left(InterfaceOperationTestUtils.mockOperationToReturn(RESOURCE_NAME))); + when(interfaceOperation.getInterfaceOperation(anyObject(), anyObject())).thenReturn(Either.left(InterfaceOperationTestUtils.mockOperationToReturn(RESOURCE_NAME))); + when(interfaceOperation.deleteInterfaceOperation(anyObject(), anyObject(), anyObject())).thenReturn(Either.left(InterfaceOperationTestUtils.mockOperationToReturn(RESOURCE_NAME))); + when(interfaceOperation.deleteInterfaceOperation(any(),any(), any())).thenReturn(Either.left(InterfaceOperationTestUtils.mockOperationToReturn(RESOURCE_NAME))); when(interfaceOperation.updateInterface(any(),any())).thenReturn(Either.left(InterfaceOperationTestUtils.mockInterfaceDefinitionToReturn(RESOURCE_NAME))); when(mockTitanDao.commit()).thenReturn(TitanOperationStatus.OK); @@ -191,13 +192,11 @@ public class InterfaceOperationBusinessLogicTest { bl.setUserValidations(userValidations); bl.setInterfaceOperation(interfaceOperation); bl.setInterfaceOperationValidation(operationValidator); - bl.setArtifactCassandraDao(artifactCassandraDao); Resource resourceCsar = createResourceObjectCsar(true); setCanWorkOnResource(resourceCsar); Either oldResourceRes = Either.left(resourceCsar); when(toscaOperationFacade.getToscaFullElement(resourceCsar.getUniqueId())).thenReturn(oldResourceRes); responseManager = ResponseFormatManager.getInstance(); - } @Test @@ -206,30 +205,24 @@ public class InterfaceOperationBusinessLogicTest { resource.setComponentType(ComponentTypeEnum.RESOURCE); validateUserRoles(Role.ADMIN, Role.DESIGNER); when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(resource)); - resourceUpdate = setUpResourceMock(); - Either interfaceOperation = bl.createInterfaceOperation(resourceId, resourceUpdate, user, true); + operation = InterfaceOperationTestUtils.createMockOperation(); + Either interfaceOperation = bl.createInterfaceOperation(resourceId, operation, user, true); Assert.assertTrue(interfaceOperation.isLeft()); - Map interfaceOperationsFromInterfaces = InterfaceUtils - .getInterfaceOperationsFromInterfaces(interfaceOperation.left().value().getInterfaces(), - interfaceOperation.left().value()); - for(Operation operation : interfaceOperationsFromInterfaces.values()) { - Assert.assertNotNull(operation.getWorkflowId()); - Assert.assertNotNull(operation.getWorkflowVersionId()); - } + Assert.assertNotNull(interfaceOperation.left().value().getWorkflowId()); + Assert.assertNotNull(interfaceOperation.left().value().getWorkflowVersionId()); } @Test public void updateInterfaceOperationTest() { validateUserRoles(Role.ADMIN, Role.DESIGNER); - resourceUpdate = setUpResourceMock(); + operation = InterfaceOperationTestUtils.createMockOperation(); Resource resource = createResourceForInterfaceOperation(); resource.setComponentType(ComponentTypeEnum.RESOURCE); when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(resource)); - Either interfaceOperation = bl.updateInterfaceOperation(resourceId, resourceUpdate, user, true); + Either interfaceOperation = bl.updateInterfaceOperation(resourceId, operation, user, true); Assert.assertTrue(interfaceOperation.isLeft()); } - @Test public void deleteInterfaceOperationTest() { Resource resource = createResourceForInterfaceOperation(); @@ -237,71 +230,23 @@ public class InterfaceOperationBusinessLogicTest { validateUserRoles(Role.ADMIN, Role.DESIGNER); when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(resource)); when(artifactCassandraDao.deleteArtifact(any(String.class))).thenReturn(CassandraOperationStatus.OK); - Set idsToDelete = new HashSet<>(); - idsToDelete.add(operationId); - - Either deleteResourceResponseFormatEither = bl.deleteInterfaceOperation(resourceId, idsToDelete, user, true); + Either deleteResourceResponseFormatEither = bl.deleteInterfaceOperation(resourceId, operationId, user, true); Assert.assertTrue(deleteResourceResponseFormatEither.isLeft()); } @Test - public void deleteInterfaceOperationTestShouldFailWrongId() { - validateUserRoles(Role.ADMIN, Role.DESIGNER); - Set idsToDelete = new HashSet<>(); + public void getInterfaceOperationTest() { Resource resource = createResourceForInterfaceOperation(); resource.setComponentType(ComponentTypeEnum.RESOURCE); - when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(resource)); - idsToDelete.add(resourceId); - Either deleteResourceResponseFormatEither = bl.deleteInterfaceOperation(resourceId, idsToDelete, user, true); - Assert.assertFalse(deleteResourceResponseFormatEither.isLeft()); - } - - - @Test - public void deleteInterfaceOperationFailToDeleteArtifactTest() { - Resource resource = createResourceForInterfaceOperation(); - resource.setComponentType(ComponentTypeEnum.RESOURCE); - when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(resource)); - when(artifactCassandraDao.deleteArtifact(any(String.class))).thenReturn(CassandraOperationStatus.GENERAL_ERROR); - validateUserRoles(Role.ADMIN, Role.DESIGNER); - Set idsToDelete = new HashSet<>(); - idsToDelete.add(operationId); - - Either deleteResourceResponseFormatEither = bl.deleteInterfaceOperation(resourceId, idsToDelete, user, true); - Assert.assertTrue(deleteResourceResponseFormatEither.isRight()); - } - - @Test - public void interfaceOperationFailedScenarioTest() { validateUserRoles(Role.ADMIN, Role.DESIGNER); - Resource resourceWithoutInterface = new Resource(); - resourceWithoutInterface.setUniqueId(resourceId); - when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(resourceWithoutInterface)); - Either interfaceOperation = bl.updateInterfaceOperation(resourceId, resourceWithoutInterface, user, true); - Assert.assertTrue(interfaceOperation.isRight()); + when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(resource)); + Either getResourceResponseFormatEither = bl.getInterfaceOperation(resourceId, operationId, user, true); + Assert.assertTrue(getResourceResponseFormatEither.isLeft()); } private void validateUserRoles(Role... roles) { List listOfRoles = Stream.of(roles).collect(Collectors.toList()); } - private Resource createMockResourceForAddInterface () { - Resource resource = new Resource(); - resource.setUniqueId(resourceId); - resource.setName(RESOURCE_NAME); - resource.addCategory(RESOURCE_CATEGORY1, RESOURCE_SUBCATEGORY); - resource.setDescription("My short description"); - - Map operationMap = new HashMap<>(); - Map interfaceDefinitionMap = new HashMap<>(); - interfaceDefinitionMap.put("int1", InterfaceOperationTestUtils.createInterface("int1", "Interface 1", - "lifecycle", "org.openecomp.interfaces.node.lifecycle." + RESOURCE_NAME, operationMap)); - resource.setInterfaces(interfaceDefinitionMap); - List inputDefinitionList = new ArrayList<>(); - inputDefinitionList.add(createInputDefinition("uniqueId1")); - resource.setInputs(inputDefinitionList); - - return resource; - } private Resource setCanWorkOnResource(Resource resource) { resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT); diff --git a/catalog-be/src/test/java/org/openecomp/sdc/test/utils/InterfaceOperationTestUtils.java b/catalog-be/src/test/java/org/openecomp/sdc/test/utils/InterfaceOperationTestUtils.java index d5bb4b36c6..76e73bab75 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/test/utils/InterfaceOperationTestUtils.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/test/utils/InterfaceOperationTestUtils.java @@ -38,12 +38,6 @@ public class InterfaceOperationTestUtils { return id; } - public static InterfaceDefinition mockInterfaceDefinitionToReturn(String resourceNamme) { - Map operationMap = createMockOperationMap(); - return createInterface("int1", "Interface 1", - "lifecycle", "org.openecomp.interfaces.node.lifecycle." + resourceNamme, operationMap); - } - public static Operation createInterfaceOperation(String uniqueID, String description, ArtifactDefinition artifactDefinition, ListDataDefinition inputs, ListDataDefinition outputs, String name) { @@ -57,8 +51,23 @@ public class InterfaceOperationTestUtils { return operation; } + public static InterfaceDefinition mockInterfaceDefinitionToReturn(String resourceNamme) { + Map operationMap = createMockOperationMap(); + return createInterface("int1", "Interface 1", + "lifecycle", "org.openecomp.interfaces.node.lifecycle." + resourceNamme, operationMap); + } + + public static Operation mockOperationToReturn(String resourceNamme) { + return createMockOperation(); + } public static Map createMockOperationMap() { + Map operationMap = new HashMap<>(); + operationMap.put("op1", createMockOperation()); + return operationMap; + } + + public static Operation createMockOperation() { Operation operation = new Operation(); ListDataDefinition operationInputDefinitionList = new ListDataDefinition<>(); operationInputDefinitionList.add(createMockOperationInputDefinition("label1")); @@ -77,9 +86,7 @@ public class InterfaceOperationTestUtils { operation.setImplementation(implementation); operation.setWorkflowId("workflowId"); operation.setWorkflowVersionId("workflowVersionId"); - Map operationMap = new HashMap<>(); - operationMap.put("op1", operation); - return operationMap; + return operation; } public static OperationInputDefinition createMockOperationInputDefinition(String name) { @@ -101,7 +108,6 @@ public class InterfaceOperationTestUtils { Map interfaceDefinitionMap = new HashMap<>(); interfaceDefinitionMap.put("int1", createInterface("int1", "Interface 1", "lifecycle", "org.openecomp.interfaces.node.lifecycle." + resourceName, operationMap)); - return interfaceDefinitionMap; } diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/jsongraph/types/EdgeLabelEnum.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/jsongraph/types/EdgeLabelEnum.java index 1621a13c67..c7a2f2eae7 100644 --- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/jsongraph/types/EdgeLabelEnum.java +++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/jsongraph/types/EdgeLabelEnum.java @@ -61,7 +61,9 @@ public enum EdgeLabelEnum { ARCHIVE_ELEMENT, INSTANCE_OF, PROXY_OF, - ALLOTTED_OF; + ALLOTTED_OF, + INTERFACE, + INTERFACE_OPERATION; /** * Returns EdgeLabelEnum according received name diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/jsongraph/types/VertexTypeEnum.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/jsongraph/types/VertexTypeEnum.java index 3917179d5e..aa4de11375 100644 --- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/jsongraph/types/VertexTypeEnum.java +++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/jsongraph/types/VertexTypeEnum.java @@ -58,7 +58,9 @@ public enum VertexTypeEnum { POLICIES ("policies", PolicyDataDefinition.class), EXTERNAL_REF ("componentInstanceExtRefs", MapComponentInstanceExternalRefs.class), CATALOG_ROOT ("catalogRoot", null), - ARCHIVE_ROOT ("archiveRoot", null); + ARCHIVE_ROOT ("archiveRoot", null), + INTERFACE ("interface", InterfaceDataDefinition.class), + INTERFACE_OPERATION ("interfaceOperation", OperationDataDefinition.class); private String name; private Class classOfJson; 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, TitanOperationStatus> dataFromGraph = getDataFromGraph(parentId, EdgeLabelEnum.INTERFACE_ARTIFACTS); + Either, 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, StorageOperationStatus> deleteInterface(Resource resource, - Set interfacesToDelete) { - Either, StorageOperationStatus> result = null; - Either getComponentVertex; - StorageOperationStatus status = null; + public Either 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 updateInterface(String componentId, + InterfaceDefinition interfaceDefinition) { + return addOrUpdateInterface(true, componentId, interfaceDefinition); + } - status = deleteToscaDataElements(resource.getUniqueId(), EdgeLabelEnum.INTERFACE_ARTIFACTS, - new ArrayList<>(interfacesToDelete)); + private Either addOrUpdateInterface( + boolean isUpdateAction, String componentId, InterfaceDefinition interfaceDefinition) { - if (status != StorageOperationStatus.OK) { - result = Either.right(status); - } - } + StorageOperationStatus statusRes; + Either 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 addInterfaceOperation(String componentId, InterfaceDefinition interfaceDef, Operation interfaceOperation) { + return addOrUpdateInterfaceOperation(false, componentId, interfaceDef, interfaceOperation); + } + + public Either updateInterfaceOperation(String componentId, InterfaceDefinition interfaceDef, Operation interfaceOperation) { + return addOrUpdateInterfaceOperation(true, componentId, interfaceDef, interfaceOperation); + } + + private Either addOrUpdateInterfaceOperation(boolean isUpdateAction, String componentId, InterfaceDefinition interfaceDef, Operation operation) { + + StorageOperationStatus statusRes; + Either getToscaElementRes; + Either 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 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 updateInterface(String resourceId, - InterfaceDefinition interfaceDefinition) { - return addOrUpdateInterface(true, resourceId, interfaceDefinition); + getUpdatedInterfaceDef(interfaceDef, operation, operation.getUniqueId()); + Either 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 addOrUpdateInterface( - boolean isUpdateAction, String resourceId, InterfaceDefinition interfaceDefinition) { + return Either.left(operation); + } - StorageOperationStatus statusRes; - Either getToscaElementRes; + public Either deleteInterfaceOperation(String componentId, InterfaceDefinition interfaceDef, String operationToDelete) { + Either getInterfaceVertex; + Either 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> operationToRemove = interfaceDef.getOperationsMap().entrySet().stream() + .filter(entry -> entry.getValue().getUniqueId().equals(operationToDelete)).findAny(); + if (operationToRemove.isPresent()){ + Map.Entry 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 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 intUpdateStatus = updateInterface(componentId, interfaceDef); + if (intUpdateStatus.isRight() && !intUpdateStatus.right().value().equals(StorageOperationStatus.OK)) { + return Either.right(status); + } + } } - + return Either.left(operation); + } + + public Either getInterfaceOperation(InterfaceDefinition interfaceDef, String operationToGet) { + Operation operation = new Operation(); + Optional> operationToFetch = interfaceDef.getOperationsMap().entrySet().stream() + .filter(entry -> entry.getValue().getUniqueId().equals(operationToGet)).findAny(); + if (operationToFetch.isPresent()){ + Map.Entry stringOperationEntry = operationToFetch.get(); + operation = stringOperationEntry.getValue(); + } + return Either.left(operation); + } + + private StorageOperationStatus performUpdateToscaAction(boolean isUpdate, GraphVertex graphVertex, + List 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 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, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INTERFACE_ARTIFACTS); + Either, 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 interfaceMap) { if (interfaceMap != null && !interfaceMap.isEmpty()) { - Either assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INTERFACE_ARTIFACTS, EdgeLabelEnum.INTERFACE_ARTIFACTS, interfaceMap); + Either 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 getInterfaceOperationsFromInterfaces( - Map interfaces, - Resource resource) throws IllegalStateException { - if (MapUtils.isEmpty(interfaces)) { - return Collections.EMPTY_MAP; - } - Optional 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 inputs) throws IllegalStateException { + public static void createInputOutput(Operation operation, List inputs) throws IllegalStateException { ListDataDefinition 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 getOperationsFromInterface(Map interfaces) { - List 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; - } + } diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/utils/InterfaceUtilsTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/utils/InterfaceUtilsTest.java index 9d44232cd0..fbf01bc91d 100644 --- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/utils/InterfaceUtilsTest.java +++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/utils/InterfaceUtilsTest.java @@ -47,24 +47,4 @@ public class InterfaceUtilsTest { // default test result = InterfaceUtils.createInterfaceToscaResourceName(resourceName); } - - - @Test - public void testGetInterfaceOperationsFromInterfaces() throws Exception { - Map interfaces = null; - Resource resource = null; - Map result; - - // default test - result = InterfaceUtils.getInterfaceOperationsFromInterfaces(interfaces, resource); - } - - @Test - public void testGetOperationsFromInterface() throws Exception { - Map interfaces = null; - List result; - - // default test - result = InterfaceUtils.getOperationsFromInterface(interfaces); - } } \ No newline at end of file -- cgit 1.2.3-korg