From ce3e2816ec3aa034bdef323c1a33b71485e87eb0 Mon Sep 17 00:00:00 2001 From: "andre.schmid" Date: Mon, 20 Jun 2022 14:59:26 +0100 Subject: Allow to delete an interface operation from VFC Issue-ID: SDC-4055 Change-Id: I43e79315dce12e2060f8b1dbdfcae29da46fc02e Signed-off-by: stasys10 Signed-off-by: Vasyl Razinkov Signed-off-by: andre.schmid --- .../be/components/impl/ArtifactsBusinessLogic.java | 20 +++---- .../impl/InterfaceOperationBusinessLogic.java | 70 ++++++++++++---------- 2 files changed, 47 insertions(+), 43 deletions(-) (limited to 'catalog-be/src/main/java') diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java index 10c50566d4..eb3561afc0 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java @@ -172,6 +172,7 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic { private static final String UPDATE_ARTIFACT = "Update Artifact"; private static final String FOUND_DEPLOYMENT_ARTIFACT = "Found deployment artifact {}"; private static final String VALID_ARTIFACT_LABEL_NAME = "'A-Z', 'a-z', '0-9', '-', '@', '+' and space."; + private final ArtifactTypeOperation artifactTypeOperation; private Gson gson = new GsonBuilder().setPrettyPrinting().create(); @javax.annotation.Resource private IInterfaceLifecycleOperation interfaceLifecycleOperation; @@ -181,7 +182,6 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic { private IElementOperation elementOperation; @javax.annotation.Resource private IHeatParametersOperation heatParametersOperation; - private final ArtifactTypeOperation artifactTypeOperation; private ArtifactCassandraDao artifactCassandraDao; private ToscaExportHandler toscaExportUtils; private CsarUtils csarUtils; @@ -3131,7 +3131,7 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic { json.put(Constants.ARTIFACT_GROUP_TYPE, artifactGroupType.getType()); json.put(Constants.REQUIRED_ARTIFACTS, (updatedRequiredArtifacts == null || updatedRequiredArtifacts.isEmpty()) ? new ArrayList<>() : updatedRequiredArtifacts.stream().filter( - e -> e.getType().equals(ArtifactTypeEnum.HEAT_ARTIFACT.getType()) || e.getType().equals(ArtifactTypeEnum.HEAT_NESTED.getType())) + e -> e.getType().equals(ArtifactTypeEnum.HEAT_ARTIFACT.getType()) || e.getType().equals(ArtifactTypeEnum.HEAT_NESTED.getType())) .map(ArtifactTemplateInfo::getFileName).collect(Collectors.toList())); json.put(Constants.ARTIFACT_HEAT_PARAMS, (heatParameters == null || heatParameters.isEmpty()) ? new ArrayList<>() : heatParameters); return json; @@ -3693,7 +3693,7 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic { operation.setImplementation(implementationArtifact); gotInterface.setOperationsMap(operationsMap); Either, StorageOperationStatus> interfaceDefinitionStorageOperationStatusEither = interfaceOperation - .updateInterfaces(storedComponent.getUniqueId(), Collections.singletonList(gotInterface)); + .updateInterfaces(storedComponent, Collections.singletonList(gotInterface)); if (interfaceDefinitionStorageOperationStatusEither.isRight()) { StorageOperationStatus storageOperationStatus = interfaceDefinitionStorageOperationStatusEither.right().value(); ActionStatus actionStatus = componentsUtils.convertFromStorageResponseForDataType(storageOperationStatus); @@ -4261,6 +4261,13 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic { return ConfigurationManager.getConfigurationManager().getConfiguration().getArtifacts(); } + public Map getAllToscaArtifacts(final String modelName) { + if (StringUtils.isNotEmpty(modelName)) { + artifactTypeOperation.validateModel(modelName); + } + return artifactTypeOperation.getAllArtifactTypes(modelName); + } + public enum ArtifactOperationEnum { CREATE, UPDATE, DELETE, DOWNLOAD, LINK; @@ -4268,11 +4275,4 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic { return operation == CREATE || operation == LINK; } } - - public Map getAllToscaArtifacts(final String modelName) { - if (StringUtils.isNotEmpty(modelName)) { - artifactTypeOperation.validateModel(modelName); - } - return artifactTypeOperation.getAllArtifactTypes(modelName); - } } 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 6b861a104e..69f7ee0f88 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 @@ -34,6 +34,7 @@ import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import java.util.Objects; import java.util.Optional; import java.util.UUID; @@ -56,6 +57,7 @@ import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition; import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum; import org.openecomp.sdc.be.model.ArtifactDefinition; import org.openecomp.sdc.be.model.CapabilityDefinition; +import org.openecomp.sdc.be.model.Component; import org.openecomp.sdc.be.model.ComponentInstanceInterface; import org.openecomp.sdc.be.model.ComponentInstanceProperty; import org.openecomp.sdc.be.model.InputDefinition; @@ -76,9 +78,8 @@ 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; -@Component("interfaceOperationBusinessLogic") +@org.springframework.stereotype.Component("interfaceOperationBusinessLogic") public class InterfaceOperationBusinessLogic extends BaseBusinessLogic { private static final Logger LOGGER = LoggerFactory.getLogger(InterfaceOperationBusinessLogic.class); @@ -105,22 +106,22 @@ public class InterfaceOperationBusinessLogic extends BaseBusinessLogic { public Either, ResponseFormat> deleteInterfaceOperation(String componentId, String interfaceId, List operationsToDelete, User user, boolean lock) { validateUserExists(user.getUserId()); - Either componentEither = getComponentDetails(componentId); + Either componentEither = getComponentDetails(componentId); if (componentEither.isRight()) { return Either.right(componentEither.right().value()); } - org.openecomp.sdc.be.model.Component storedComponent = componentEither.left().value(); + Component storedComponent = componentEither.left().value(); lockComponentResult(lock, storedComponent, DELETE_INTERFACE_OPERATION); try { Optional optionalInterface = getInterfaceDefinitionFromComponentByInterfaceId(storedComponent, interfaceId); - if (!optionalInterface.isPresent()) { + if (optionalInterface.isEmpty()) { return Either.right(componentsUtils.getResponseFormat(ActionStatus.INTERFACE_NOT_FOUND_IN_COMPONENT, interfaceId)); } InterfaceDefinition interfaceDefinition = optionalInterface.get(); Map operationsCollection = new HashMap<>(); for (String operationId : operationsToDelete) { Optional> optionalOperation = getOperationFromInterfaceDefinition(interfaceDefinition, operationId); - if (!optionalOperation.isPresent()) { + if (optionalOperation.isEmpty()) { return Either.right(componentsUtils.getResponseFormat(ActionStatus.INTERFACE_OPERATION_NOT_FOUND, storedComponent.getUniqueId())); } Operation storedOperation = optionalOperation.get().getValue(); @@ -130,7 +131,7 @@ public class InterfaceOperationBusinessLogic extends BaseBusinessLogic { return Either.right(validateDeleteOperationContainsNoMappedOutputResponse.right().value()); } String artifactUniqueId = storedOperation.getImplementation().getUniqueId(); - if (!InterfaceOperationUtils.isArtifactInUse(storedComponent, operationId, artifactUniqueId)) { + if (artifactUniqueId != null && !InterfaceOperationUtils.isArtifactInUse(storedComponent, operationId, artifactUniqueId)) { Either getArtifactEither = artifactToscaOperation .getArtifactById(storedComponent.getUniqueId(), artifactUniqueId); if (getArtifactEither.isLeft()) { @@ -155,18 +156,23 @@ public class InterfaceOperationBusinessLogic extends BaseBusinessLogic { } } operationsCollection.put(operationId, interfaceDefinition.getOperationsMap().get(operationId)); - interfaceDefinition.getOperations().remove(operationId); + final Optional operationKeyOptional = interfaceDefinition.getOperations().entrySet() + .stream().filter(entry -> operationId.equals(entry.getValue().getUniqueId())) + .map(Entry::getKey).findFirst(); + if (operationKeyOptional.isEmpty()) { + return Either.right(componentsUtils.getResponseFormat(ActionStatus.INTERFACE_OPERATION_NOT_FOUND, storedComponent.getUniqueId())); + } + interfaceDefinition.getOperations().remove(operationKeyOptional.get()); } - Either, StorageOperationStatus> deleteOperationEither = interfaceOperation - .updateInterfaces(storedComponent.getUniqueId(), Collections.singletonList(interfaceDefinition)); - if (deleteOperationEither.isRight()) { + final Either, StorageOperationStatus> updateInterfaceResultEither; + updateInterfaceResultEither = interfaceOperation.updateInterfaces(storedComponent, Collections.singletonList(interfaceDefinition)); + if (updateInterfaceResultEither.isRight()) { janusGraphDao.rollback(); return Either.right(componentsUtils.getResponseFormat( - componentsUtils.convertFromStorageResponse(deleteOperationEither.right().value(), storedComponent.getComponentType()))); + componentsUtils.convertFromStorageResponse(updateInterfaceResultEither.right().value(), storedComponent.getComponentType()))); } if (interfaceDefinition.getOperations().isEmpty()) { - Either deleteInterfaceEither = interfaceOperation - .deleteInterface(storedComponent.getUniqueId(), interfaceDefinition.getUniqueId()); + final var deleteInterfaceEither = interfaceOperation.deleteInterface(storedComponent, interfaceDefinition.getUniqueId()); if (deleteInterfaceEither.isRight()) { janusGraphDao.rollback(); return Either.right(componentsUtils.getResponseFormat( @@ -187,8 +193,8 @@ public class InterfaceOperationBusinessLogic extends BaseBusinessLogic { } } - private Either getComponentDetails(String componentId) { - Either componentStorageOperationStatusEither = toscaOperationFacade + private Either getComponentDetails(String componentId) { + Either componentStorageOperationStatusEither = toscaOperationFacade .getToscaElement(componentId); if (componentStorageOperationStatusEither.isRight()) { return Either.right( @@ -197,7 +203,7 @@ public class InterfaceOperationBusinessLogic extends BaseBusinessLogic { return Either.left(componentStorageOperationStatusEither.left().value()); } - private Either lockComponentResult(boolean lock, org.openecomp.sdc.be.model.Component component, String action) { + private Either lockComponentResult(boolean lock, Component component, String action) { if (lock) { try { lockComponent(component.getUniqueId(), component, action); @@ -212,11 +218,11 @@ public class InterfaceOperationBusinessLogic extends BaseBusinessLogic { public Either, ResponseFormat> getInterfaceOperation(String componentId, String interfaceId, List operationsToGet, User user, boolean lock) { validateUserExists(user); - Either componentEither = getComponentDetails(componentId); + Either componentEither = getComponentDetails(componentId); if (componentEither.isRight()) { return Either.right(componentEither.right().value()); } - org.openecomp.sdc.be.model.Component storedComponent = componentEither.left().value(); + Component storedComponent = componentEither.left().value(); lockComponentResult(lock, storedComponent, GET_INTERFACE_OPERATION); try { Optional optionalInterface = getInterfaceDefinitionFromComponentByInterfaceId(storedComponent, interfaceId); @@ -254,11 +260,11 @@ public class InterfaceOperationBusinessLogic extends BaseBusinessLogic { User user, boolean isUpdate, String errorContext, boolean lock) { validateUserExists(user); - Either componentEither = getComponentDetails(componentId); + Either componentEither = getComponentDetails(componentId); if (componentEither.isRight()) { return Either.right(componentEither.right().value()); } - org.openecomp.sdc.be.model.Component storedComponent = componentEither.left().value(); + Component storedComponent = componentEither.left().value(); lockComponentResult(lock, storedComponent, errorContext); Either, ResponseFormat> interfaceLifecycleTypes = getAllInterfaceLifecycleTypes(storedComponent.getModel()); if (interfaceLifecycleTypes.isRight()) { @@ -332,8 +338,7 @@ public class InterfaceOperationBusinessLogic extends BaseBusinessLogic { } interfacesCollection.add(interfaceDef); } - Either, StorageOperationStatus> addCreateOperationEither = interfaceOperation - .updateInterfaces(storedComponent.getUniqueId(), interfacesCollection); + final var addCreateOperationEither = interfaceOperation.updateInterfaces(storedComponent, interfacesCollection); if (addCreateOperationEither.isRight()) { janusGraphDao.rollback(); return Either.right(componentsUtils.getResponseFormat( @@ -365,7 +370,7 @@ public class InterfaceOperationBusinessLogic extends BaseBusinessLogic { return Either.left(interfaceLifecycleTypes.left().value()); } - private Either getOrCreateInterfaceDefinition(org.openecomp.sdc.be.model.Component component, + private Either getOrCreateInterfaceDefinition(Component component, InterfaceDefinition interfaceDefinition, InterfaceDefinition storedInterfaceDef) { if (storedInterfaceDef != null) { @@ -373,8 +378,7 @@ public class InterfaceOperationBusinessLogic extends BaseBusinessLogic { } interfaceDefinition.setUniqueId(UUID.randomUUID().toString()); interfaceDefinition.setToscaResourceName(interfaceDefinition.getType()); - Either, StorageOperationStatus> interfaceCreateEither = interfaceOperation - .addInterfaces(component.getUniqueId(), Collections.singletonList(interfaceDefinition)); + final var interfaceCreateEither = interfaceOperation.addInterfaces(component, Collections.singletonList(interfaceDefinition)); if (interfaceCreateEither.isRight()) { janusGraphDao.rollback(); return Either.right(componentsUtils @@ -383,13 +387,13 @@ public class InterfaceOperationBusinessLogic extends BaseBusinessLogic { return Either.left(interfaceCreateEither.left().value().get(0)); } - private void updateOperationInputDefs(org.openecomp.sdc.be.model.Component component, Collection interfaceOperations) { + private void updateOperationInputDefs(Component component, Collection interfaceOperations) { interfaceOperations.stream().filter(operation -> Objects.nonNull(operation.getInputs())).forEach( operation -> operation.getInputs().getListToscaDataDefinition() .forEach(inp -> component.getInputs().forEach(in -> updateOperationInputDefinition(component, inp, in)))); } - private void updateOperationInputDefinition(org.openecomp.sdc.be.model.Component component, OperationInputDefinition operationInput, + private void updateOperationInputDefinition(Component component, OperationInputDefinition operationInput, InputDefinition componentInput) { if (operationInput.getInputId().equals(componentInput.getUniqueId())) { //Set the default value, value and schema only for inputs mapped to component inputs @@ -404,7 +408,7 @@ public class InterfaceOperationBusinessLogic extends BaseBusinessLogic { operationInput.setToscaDefaultValue(getInputToscaDefaultValue(operationInput, component)); } - private String getInputToscaDefaultValue(OperationInputDefinition input, org.openecomp.sdc.be.model.Component component) { + private String getInputToscaDefaultValue(OperationInputDefinition input, Component component) { Map> defaultInputValue = null; if (isOperationInputMappedToComponentInput(input, component.getInputs())) { String propertyName = input.getInputId().substring(input.getInputId().indexOf('.') + 1); @@ -433,7 +437,7 @@ public class InterfaceOperationBusinessLogic extends BaseBusinessLogic { return new Gson().toJson(defaultInputValue); } - private void setParentPropertyTypeAndInputPath(OperationInputDefinition input, org.openecomp.sdc.be.model.Component component) { + private void setParentPropertyTypeAndInputPath(OperationInputDefinition input, Component component) { if (CollectionUtils.isEmpty(component.getInputs())) { return; } @@ -477,18 +481,18 @@ public class InterfaceOperationBusinessLogic extends BaseBusinessLogic { public Either, ResponseFormat> getInputsListForOperation(String componentId, String componentInstanceId, String interfaceId, String operationId, User user) { - Either componentEither = getComponentDetails(componentId); + Either componentEither = getComponentDetails(componentId); if (componentEither.isRight()) { return Either.right(componentEither.right().value()); } - org.openecomp.sdc.be.model.Component storedComponent = componentEither.left().value(); + Component storedComponent = componentEither.left().value(); validateUserExists(user.getUserId()); Either lockResult = lockComponentResult(true, storedComponent, GET_INTERFACE_OPERATION); if (lockResult.isRight()) { return Either.right(lockResult.right().value()); } try { - org.openecomp.sdc.be.model.Component parentComponent = componentEither.left().value(); + Component parentComponent = componentEither.left().value(); Map> componentInstanceInterfaces = parentComponent.getComponentInstancesInterfaces(); if (MapUtils.isEmpty(componentInstanceInterfaces)) { return Either.right(componentsUtils.getResponseFormat(ActionStatus.INTERFACE_OPERATION_NOT_FOUND, componentInstanceId)); -- cgit 1.2.3-korg