summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactResolverImpl.java4
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java191
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogic.java80
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogic.java7
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/utils/InterfaceOperationUtils.java11
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CsarUtils.java5
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/OperationArtifactUtil.java2
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogicTest.java41
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/utils/InterfaceOperationUtilsTest.java6
9 files changed, 238 insertions, 109 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactResolverImpl.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactResolverImpl.java
index 2b23c52cd0..d0a1273210 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactResolverImpl.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactResolverImpl.java
@@ -58,9 +58,9 @@ public class ArtifactResolverImpl implements ArtifactsResolver {
if (MapUtils.isNotEmpty(interfaces)) {
interfaceArtifacts = interfaces.values().stream()
.flatMap(inte -> inte.getOperationsMap().values().stream())
- .map(operation -> operation.getImplementationArtifact())
+ .map(operation -> operation.getImplementationArtifact()).filter(Objects::nonNull)
.collect(Collectors.toMap(artifactDefinition -> artifactDefinition.getUniqueId(),
- artifactDefinition -> artifactDefinition));
+ artifactDefinition -> artifactDefinition, (a1, a2) -> a1));
}
Map<String, ArtifactDefinition> serviceApiArtifacts = Collections.emptyMap();
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 8f1f5864d5..361f6c610f 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
@@ -54,7 +54,6 @@ import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
import org.openecomp.sdc.be.info.ArtifactTemplateInfo;
import org.openecomp.sdc.be.model.*;
import org.openecomp.sdc.be.model.heat.HeatParameterType;
-import org.openecomp.sdc.be.model.jsontitan.operations.InterfaceOperation;
import org.openecomp.sdc.be.model.jsontitan.operations.NodeTemplateOperation;
import org.openecomp.sdc.be.components.utils.InterfaceOperationUtils;
import org.openecomp.sdc.be.model.operations.api.*;
@@ -3096,69 +3095,33 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
}
}
NodeTypeEnum convertParentType = convertParentType(componentType);
- // fetch the resource from storage
- Either<Component, StorageOperationStatus> componentStorageOperationStatusEither =
- toscaOperationFacade.getToscaElement(parentId);
- if (componentStorageOperationStatusEither.isRight()) {
- StorageOperationStatus errorStatus = componentStorageOperationStatusEither.right().value();
- log.debug("Failed to fetch resource information by resource id, error {}", errorStatus);
- return Either.right(componentsUtils
- .getResponseFormat(componentsUtils.convertFromStorageResponse(errorStatus)));
+ // Set additional fields for artifact
+ artifactInfo.setArtifactLabel(artifactInfo.getArtifactName());
+ artifactInfo.setArtifactDisplayName(artifactInfo.getArtifactName());
+
+ Either<ArtifactDefinition, StorageOperationStatus> updateArtifactOnResourceEither =
+ artifactToscaOperation.updateArtifactOnResource(artifactInfo, parent.getUniqueId(), artifactId, convertParentType, parentId);
+ if(updateArtifactOnResourceEither.isRight()){
+ log.debug("Failed to persist operation artifact {} in resource, error is {}",artifactInfo.getArtifactName(), updateArtifactOnResourceEither.right().value());
+ ActionStatus convertedFromStorageResponse = componentsUtils.convertFromStorageResponse(updateArtifactOnResourceEither.right().value());
+ return Either.right(componentsUtils.getResponseFormat(convertedFromStorageResponse));
}
- Component storedComponent = componentStorageOperationStatusEither.left().value();
-
- Optional<InterfaceDefinition> optionalInterface = InterfaceOperationUtils
- .getInterfaceDefinitionFromComponentByInterfaceType(storedComponent, interfaceType);
- if(!optionalInterface.isPresent()) {
- log.debug("Failed to get resource interface for resource Id {}", parentId);
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.INTERFACE_NOT_FOUND_IN_COMPONENT, interfaceType));
+ if (artifactData.getData() != null) {
+ CassandraOperationStatus cassandraOperationStatus = artifactCassandraDao.saveArtifact(artifactData);
+ if(cassandraOperationStatus != CassandraOperationStatus.OK){
+ log.debug("Failed to persist operation artifact {}, error is {}",artifactInfo.getArtifactName(),cassandraOperationStatus);
+ StorageOperationStatus storageStatus = DaoStatusConverter.convertCassandraStatusToStorageStatus(cassandraOperationStatus);
+ ActionStatus convertedFromStorageResponse = componentsUtils.convertFromStorageResponse(storageStatus);
+ return Either.right(componentsUtils.getResponseFormat(convertedFromStorageResponse));
+ }
}
- //fetch the operation from storage
- InterfaceDefinition gotInterface = optionalInterface.get();
- Map<String, Operation> operationsMap = gotInterface.getOperationsMap();
- Optional<Operation> optionalOperation = operationsMap.values()
- .stream()
- .filter(o -> o.getUniqueId().equals(operationUuid))
- .findFirst();
- if (!optionalOperation.isPresent()) {
- log.debug("Failed to get resource interface operation for resource Id {} " +
- " and operationId {}", parentId, operationUuid);
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(
- ActionStatus.INTERFACE_OPERATION_NOT_FOUND, parentId);
- handleAuditing(auditingAction, parent, parentId, user, artifactInfo, prevArtifactId,
- currArtifactId, responseFormat, componentType, null);
- return Either.right(responseFormat);
+ Either<ArtifactDefinition, ResponseFormat> updateOprEither = updateOperationArtifact(parentId, interfaceType, operationUuid, updateArtifactOnResourceEither.left().value());
+ if(updateOprEither.isRight()){
+ return Either.right(updateOprEither.right().value());
}
- Operation operation = optionalOperation.get();
- ArtifactDefinition implementationArtifact = operation.getImplementationArtifact();
- implementationArtifact.setArtifactName(artifactInfo.getArtifactName());
- implementationArtifact.setDescription(artifactInfo.getDescription());
- implementationArtifact.setArtifactType(artifactInfo.getArtifactType());
- implementationArtifact.setArtifactLabel(artifactInfo.getUniqueId());
- implementationArtifact.setEsId(artifactInfo.getEsId());
- operation.setImplementation(implementationArtifact);
- gotInterface.setOperationsMap(operationsMap);
- Either<List<InterfaceDefinition>, StorageOperationStatus> interfaceDefinitionStorageOperationStatusEither =
- interfaceOperation.updateInterfaces(storedComponent.getUniqueId(), Collections.singletonList(gotInterface));
- if (interfaceDefinitionStorageOperationStatusEither.isRight()){
- StorageOperationStatus storageOperationStatus = interfaceDefinitionStorageOperationStatusEither.right().value();
- ActionStatus actionStatus =
- componentsUtils.convertFromStorageResponseForDataType(storageOperationStatus);
- return Either.right(componentsUtils.getResponseFormat(actionStatus));
- }
-
- String uniqueId = implementationArtifact.getUniqueId();
- artifactData.setId(uniqueId);
- CassandraOperationStatus cassandraOperationStatus = artifactCassandraDao.saveArtifact(artifactData);
- if(cassandraOperationStatus != CassandraOperationStatus.OK){
- log.debug("Failed to persist operation {} artifact, error is {}",operation.getName(),cassandraOperationStatus);
- StorageOperationStatus storageStatus = DaoStatusConverter.convertCassandraStatusToStorageStatus(cassandraOperationStatus);
- ActionStatus convertedFromStorageResponse = componentsUtils.convertFromStorageResponse(storageStatus);
- return Either.right(componentsUtils.getResponseFormat(convertedFromStorageResponse));
- }
- return Either.left(Either.left(implementationArtifact));
+ return Either.left(Either.left(updateOprEither.left().value()));
}
private Either<byte[], ResponseFormat> handlePayload(ArtifactDefinition artifactInfo, boolean isArtifactMetadataUpdate) {
@@ -5007,6 +4970,58 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
return updateArtifactResult;
}
+ private Either<ArtifactDefinition, ResponseFormat> updateOperationArtifact(String componentId, String interfaceType, String operationUuid, ArtifactDefinition artifactInfo){
+ Either<Component, StorageOperationStatus> componentStorageOperationStatusEither = toscaOperationFacade.getToscaElement(componentId);
+ if (componentStorageOperationStatusEither.isRight()) {
+ StorageOperationStatus errorStatus = componentStorageOperationStatusEither.right().value();
+ log.debug("Failed to fetch resource information by resource id, error {}", errorStatus);
+ return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(errorStatus)));
+ }
+ Component storedComponent = componentStorageOperationStatusEither.left().value();
+
+ Optional<InterfaceDefinition> optionalInterface = InterfaceOperationUtils.getInterfaceDefinitionFromComponentByInterfaceType(storedComponent, interfaceType);
+ if(!optionalInterface.isPresent()) {
+ log.debug("Failed to get resource interface for resource Id {}", componentId);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.INTERFACE_NOT_FOUND_IN_COMPONENT, interfaceType));
+ }
+
+ //fetch the operation from storage
+ InterfaceDefinition gotInterface = optionalInterface.get();
+ Map<String, Operation> operationsMap = gotInterface.getOperationsMap();
+ Optional<Operation> optionalOperation = operationsMap.values()
+ .stream()
+ .filter(o -> o.getUniqueId().equals(operationUuid))
+ .findFirst();
+ if (!optionalOperation.isPresent()) {
+ log.debug("Failed to get resource interface operation for resource Id {} and operationId {}", componentId, operationUuid);
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.INTERFACE_OPERATION_NOT_FOUND, componentId);
+ return Either.right(responseFormat);
+ }
+
+ Operation operation = optionalOperation.get();
+ ArtifactDefinition implementationArtifact = operation.getImplementationArtifact();
+ implementationArtifact.setArtifactUUID(artifactInfo.getArtifactUUID());
+ implementationArtifact.setUniqueId(artifactInfo.getUniqueId());
+ implementationArtifact.setArtifactName(artifactInfo.getArtifactName());
+ implementationArtifact.setDescription(artifactInfo.getDescription());
+ implementationArtifact.setArtifactType(artifactInfo.getArtifactType());
+ implementationArtifact.setArtifactLabel(artifactInfo.getArtifactLabel());
+ implementationArtifact.setArtifactDisplayName(artifactInfo.getArtifactDisplayName());
+ implementationArtifact.setEsId(artifactInfo.getEsId());
+ operation.setImplementation(implementationArtifact);
+ gotInterface.setOperationsMap(operationsMap);
+ Either<List<InterfaceDefinition>, StorageOperationStatus> interfaceDefinitionStorageOperationStatusEither =
+ interfaceOperation.updateInterfaces(storedComponent.getUniqueId(), Collections.singletonList(gotInterface));
+ if (interfaceDefinitionStorageOperationStatusEither.isRight()){
+ StorageOperationStatus storageOperationStatus = interfaceDefinitionStorageOperationStatusEither.right().value();
+ ActionStatus actionStatus =
+ componentsUtils.convertFromStorageResponseForDataType(storageOperationStatus);
+ return Either.right(componentsUtils.getResponseFormat(actionStatus));
+ }
+
+ return Either.left(artifactInfo);
+ }
+
/**
* updates an artifact on a component by UUID
*
@@ -5030,6 +5045,8 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
ArtifactDefinition artifactInfo = RepresentationUtils.convertJsonToArtifactDefinitionForUpdate(data, ArtifactDefinition.class);
String origMd5 = request.getHeader(Constants.MD5_HEADER);
String userId = request.getHeader(Constants.USER_ID_HEADER);
+ ArtifactDefinition existingArtifactInfo = null;
+ String interfaceName = null;
Either<ComponentMetadataData, StorageOperationStatus> getComponentRes = toscaOperationFacade.getLatestComponentMetadataByUuid(componentUuid, JsonParseFlagEnum.ParseMetadata, true);
if (getComponentRes.isRight()) {
@@ -5037,6 +5054,7 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
log.debug("Could not fetch component with type {} and uuid {}. Status is {}. ", componentType, componentUuid, status);
errorWrapper.setInnerElement(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(status)));
}
+
if (errorWrapper.isEmpty()) {
componentId = getComponentRes.left().value().getMetadataDataDefinition().getUniqueId();
String componentName = getComponentRes.left().value().getMetadataDataDefinition().getName();
@@ -5054,23 +5072,52 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
}
resourceCommonInfo.setResourceName(componentName);
}
- if (errorWrapper.isEmpty()) {
- Either<String, ResponseFormat> interfaceName = fetchInterfaceName(componentId, interfaceUUID);
- if (interfaceName.isRight()) {
- errorWrapper.setInnerElement(interfaceName.right().value());
+
+ if(errorWrapper.isEmpty()){
+ Either<String, ResponseFormat> interfaceNameEither = fetchInterfaceName(componentId, interfaceUUID);
+ if (interfaceNameEither.isRight()) {
+ errorWrapper.setInnerElement(interfaceNameEither.right().value());
}
- if (errorWrapper.isEmpty()) {
- actionResult = handleArtifactRequest(componentId, userId, componentType, operation,
- artifactUUID, artifactInfo, origMd5, data, interfaceName.left().value(),
- operationUUID, null, null);
- if (actionResult.isRight()) {
- log.debug(FAILED_UPLOAD_ARTIFACT_TO_COMPONENT, componentType, componentUuid, actionResult
- .right()
- .value());
- errorWrapper.setInnerElement(actionResult.right().value());
+ else {
+ interfaceName = interfaceNameEither.left().value();
+ }
+
+ if(errorWrapper.isEmpty()){
+ Either<Component, StorageOperationStatus> toscaComponentEither = toscaOperationFacade.getToscaElement(componentId);
+ if (toscaComponentEither.isRight()) {
+ StorageOperationStatus status = toscaComponentEither.right().value();
+ log.debug("Could not fetch component with type {} and id {}. Status is {}. ", componentType, componentId, status);
+ errorWrapper.setInnerElement(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(status)));
}
+
+ if (errorWrapper.isEmpty()) {
+ NodeTypeEnum parentType = convertParentType(componentType);
+ List<ArtifactDefinition> existingDeploymentArtifacts = getDeploymentArtifacts(toscaComponentEither.left().value(), parentType,null);
+ for (ArtifactDefinition artifactDefinition: existingDeploymentArtifacts){
+ if(artifactDefinition.getArtifactName().equalsIgnoreCase(artifactInfo.getArtifactName())){
+ existingArtifactInfo = artifactDefinition;
+ break;
+ }
+ }
+ if(existingArtifactInfo != null){
+ return updateOperationArtifact(componentId, interfaceName, operationUUID, existingArtifactInfo);
+ }
+ }
+ }
+ }
+
+ if (errorWrapper.isEmpty()) {
+ actionResult = handleArtifactRequest(componentId, userId, componentType, operation,
+ artifactUUID, artifactInfo, origMd5, data, interfaceName,
+ operationUUID, null, null);
+ if (actionResult.isRight()) {
+ log.debug(FAILED_UPLOAD_ARTIFACT_TO_COMPONENT, componentType, componentUuid, actionResult
+ .right()
+ .value());
+ errorWrapper.setInnerElement(actionResult.right().value());
}
}
+
if (errorWrapper.isEmpty()) {
updateArtifact = actionResult.left().value().left().value();
updateArtifactResult = Either.left(updateArtifact);
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 71d79e0410..7f19e824e5 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
@@ -41,6 +41,7 @@ import java.util.stream.Collectors;
import fj.data.Either;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
+import org.openecomp.sdc.be.components.utils.InterfaceOperationUtils;
import org.openecomp.sdc.be.components.validation.InterfaceOperationValidation;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.dao.cassandra.ArtifactCassandraDao;
@@ -122,14 +123,34 @@ public class InterfaceOperationBusinessLogic extends BaseBusinessLogic {
if (validateDeleteOperationContainsNoMappedOutputResponse.isRight()) {
return Either.right(validateDeleteOperationContainsNoMappedOutputResponse.right().value());
}
- String artifactUuId = storedOperation.getImplementation().getArtifactUUID();
- CassandraOperationStatus cassandraStatus = artifactCassandraDao.deleteArtifact(artifactUuId);
- if (cassandraStatus != CassandraOperationStatus.OK) {
- ResponseFormat responseFormatByArtifactId = componentsUtils.getResponseFormatByArtifactId(
- componentsUtils.convertFromStorageResponse(
- componentsUtils.convertToStorageOperationStatus(cassandraStatus)),
- storedOperation.getImplementation().getArtifactDisplayName());
- return Either.right(responseFormatByArtifactId);
+
+ String artifactUniqueId = storedOperation.getImplementation().getUniqueId();
+ if(!InterfaceOperationUtils.isArtifactInUse(storedComponent, operationId, artifactUniqueId)){
+ Either<ArtifactDefinition, StorageOperationStatus> getArtifactEither =
+ artifactToscaOperation.getArtifactById(storedComponent.getUniqueId(), artifactUniqueId);
+ if(getArtifactEither.isLeft()){
+ Either<ArtifactDefinition, StorageOperationStatus> removeArifactFromComponent =
+ artifactToscaOperation.removeArifactFromResource(componentId, artifactUniqueId,
+ NodeTypeEnum.getByNameIgnoreCase(storedComponent.getComponentType().getValue()),
+ true);
+ if(removeArifactFromComponent.isRight()){
+ titanDao.rollback();
+ ResponseFormat responseFormatByArtifactId = componentsUtils.getResponseFormatByArtifactId(
+ componentsUtils.convertFromStorageResponse(removeArifactFromComponent.right().value()),
+ storedOperation.getImplementation().getArtifactDisplayName());
+ return Either.right(responseFormatByArtifactId);
+ }
+
+ CassandraOperationStatus cassandraStatus = artifactCassandraDao.deleteArtifact(artifactUniqueId);
+ if (cassandraStatus != CassandraOperationStatus.OK) {
+ titanDao.rollback();
+ ResponseFormat responseFormatByArtifactId = componentsUtils.getResponseFormatByArtifactId(
+ componentsUtils.convertFromStorageResponse(
+ componentsUtils.convertToStorageOperationStatus(cassandraStatus)),
+ storedOperation.getImplementation().getArtifactDisplayName());
+ return Either.right(responseFormatByArtifactId);
+ }
+ }
}
operationsCollection.put(operationId, interfaceDefinition.getOperationsMap().get(operationId));
@@ -317,20 +338,35 @@ public class InterfaceOperationBusinessLogic extends BaseBusinessLogic {
Operation storedOperation = optionalOperation.get().getValue();
String artifactUuId = storedOperation.getImplementation().getArtifactUUID();
- Either<Long, CassandraOperationStatus> artifactCount =
- artifactCassandraDao.getCountOfArtifactById(artifactUuId);
- if (artifactCount.isLeft()) {
- CassandraOperationStatus cassandraStatus =
- artifactCassandraDao.deleteArtifact(artifactUuId);
- if (cassandraStatus != CassandraOperationStatus.OK) {
- titanDao.rollback();
- ResponseFormat responseFormatByArtifactId =
- componentsUtils.getResponseFormatByArtifactId(
- componentsUtils.convertFromStorageResponse(
- componentsUtils.convertToStorageOperationStatus(
- cassandraStatus)),
- storedOperation.getImplementation().getArtifactDisplayName());
- return Either.right(responseFormatByArtifactId);
+ String artifactUniqueId = storedOperation.getImplementation().getUniqueId();
+
+ if(!InterfaceOperationUtils.isArtifactInUse(storedComponent, storedOperation.getUniqueId(), artifactUniqueId)){
+ Either<ArtifactDefinition, StorageOperationStatus> getArtifactEither =
+ artifactToscaOperation.getArtifactById(storedComponent.getUniqueId(), artifactUniqueId);
+ if(getArtifactEither.isLeft()){
+ Either<ArtifactDefinition, StorageOperationStatus> removeArifactFromComponent =
+ artifactToscaOperation.removeArifactFromResource(componentId, artifactUniqueId,
+ NodeTypeEnum.getByNameIgnoreCase(storedComponent.getComponentType().getValue()),
+ true);
+ if(removeArifactFromComponent.isRight()){
+ titanDao.rollback();
+ ResponseFormat responseFormatByArtifactId = componentsUtils.getResponseFormatByArtifactId(
+ componentsUtils.convertFromStorageResponse(removeArifactFromComponent.right().value()),
+ storedOperation.getImplementation().getArtifactDisplayName());
+ return Either.right(responseFormatByArtifactId);
+ }
+
+ CassandraOperationStatus cassandraStatus = artifactCassandraDao.deleteArtifact(artifactUniqueId);
+ if (cassandraStatus != CassandraOperationStatus.OK) {
+ titanDao.rollback();
+ ResponseFormat responseFormatByArtifactId =
+ componentsUtils.getResponseFormatByArtifactId(
+ componentsUtils.convertFromStorageResponse(
+ componentsUtils.convertToStorageOperationStatus(
+ cassandraStatus)),
+ storedOperation.getImplementation().getArtifactDisplayName());
+ return Either.right(responseFormatByArtifactId);
+ }
}
}
updateOperationOnInterface(interfaceDef, operation, artifactUuId);
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogic.java
index 6c0e0c9fba..ba3b8dfc45 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogic.java
@@ -2324,7 +2324,12 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
@Override
public void setDeploymentArtifactsPlaceHolder(Component component, User user) {
-
+ Service service = (Service) component;
+ Map<String, ArtifactDefinition> artifactMap = service.getDeploymentArtifacts();
+ if (artifactMap == null) {
+ artifactMap = new HashMap<>();
+ }
+ service.setDeploymentArtifacts(artifactMap);
}
@Override
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/utils/InterfaceOperationUtils.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/utils/InterfaceOperationUtils.java
index 2727a8b94a..0ee6264f4d 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/utils/InterfaceOperationUtils.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/utils/InterfaceOperationUtils.java
@@ -23,9 +23,9 @@ import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
-
+import java.util.stream.Collectors;
import org.apache.commons.collections.CollectionUtils;
-import org.apache.commons.collections.MapUtils;
+import org.apache.commons.collections4.MapUtils;
import org.openecomp.sdc.be.datatypes.elements.InterfaceDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.OperationDataDefinition;
@@ -180,4 +180,11 @@ public class InterfaceOperationUtils {
? fullOutputIdentifier.substring(fullOutputIdentifier.lastIndexOf('.') + 1)
: fullOutputIdentifier;
}
+
+ public static boolean isArtifactInUse(Component component, String operationId, String artifactUniqueId) {
+ return MapUtils.emptyIfNull(component.getInterfaces()).values().stream()
+ .filter(o -> MapUtils.isNotEmpty(o.getOperations()) && !o.getOperations().containsKey(operationId))
+ .flatMap(o -> o.getOperations().values().stream()).collect(Collectors.toList()).stream()
+ .anyMatch(op -> op.getImplementation().getUniqueId().equals(artifactUniqueId));
+ }
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CsarUtils.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CsarUtils.java
index c6dec0bcc4..7b40781f3f 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CsarUtils.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CsarUtils.java
@@ -900,6 +900,11 @@ public class CsarUtils {
for (ArtifactTypeEnum artifactTypeEnum : artifactTypeEnumKeySet) {
List<ArtifactDefinition> artifactDefinitionList = artifactTypesMap.get(artifactTypeEnum);
String artifactTypeFolder = groupTypeFolder + artifactTypeEnum.toString() + File.separator;
+
+ if(artifactTypeEnum == ArtifactTypeEnum.WORKFLOW && path.contains(ARTIFACTS_PATH + RESOURCES_PATH)){
+ // Ignore this packaging as BPMN artifacts needs to be packaged in different manner
+ continue;
+ }
if (artifactTypeEnum == ArtifactTypeEnum.WORKFLOW) {
artifactTypeFolder += OperationArtifactUtil.BPMN_ARTIFACT_PATH + File.separator;
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/OperationArtifactUtil.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/OperationArtifactUtil.java
index b10a8883d2..401c03d44f 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/OperationArtifactUtil.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/OperationArtifactUtil.java
@@ -102,7 +102,7 @@ public class OperationArtifactUtil {
.flatMap(interfaceDefinition -> interfaceDefinition.getOperationsMap().values().stream())
.map(Operation::getImplementationArtifact).filter(Objects::nonNull)
.collect(Collectors.toMap(ArtifactDataDefinition::getUniqueId,
- artifactDefinition -> artifactDefinition));
+ artifactDefinition -> artifactDefinition, (a1, a2) -> a1));
if (MapUtils.isNotEmpty(interfaceArtifacts)) {
Set<String> artifactNameSet = new HashSet<>();
for (Map.Entry<String, ArtifactDefinition> interfaceArtifactEntry : interfaceArtifacts.entrySet()) {
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 beb38889df..963823c261 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
@@ -19,7 +19,6 @@ package org.openecomp.sdc.be.components.impl;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyMap;
-import static org.mockito.ArgumentMatchers.anyObject;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.when;
@@ -49,10 +48,12 @@ import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.model.ArtifactDefinition;
import org.openecomp.sdc.be.model.InputDefinition;
import org.openecomp.sdc.be.model.InterfaceDefinition;
import org.openecomp.sdc.be.model.Resource;
import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.model.jsontitan.operations.ArtifactsOperations;
import org.openecomp.sdc.be.model.jsontitan.operations.InterfaceOperation;
import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade;
import org.openecomp.sdc.be.model.operations.api.IGraphLockOperation;
@@ -93,6 +94,8 @@ public class InterfaceOperationBusinessLogicTest {
private InterfaceOperation interfaceOperation;
@Mock
private ArtifactCassandraDao artifactCassandraDao;
+ @Mock
+ protected ArtifactsOperations artifactToscaOperation;
private User user;
private Resource resource;
@@ -110,10 +113,10 @@ public class InterfaceOperationBusinessLogicTest {
when(graphLockOperation.lockComponent(Mockito.anyString(), eq(NodeTypeEnum.Resource)))
.thenReturn(StorageOperationStatus.OK);
when(interfaceOperationValidation
- .validateInterfaceOperations(anyObject(), anyObject(), any(), anyMap(), anyBoolean()))
+ .validateInterfaceOperations(any(), any(), any(), anyMap(), anyBoolean()))
.thenReturn(Either.left(true));
when(interfaceOperationValidation
- .validateDeleteOperationContainsNoMappedOutput(anyObject(), anyObject(), any()))
+ .validateDeleteOperationContainsNoMappedOutput(any(), any(), any()))
.thenReturn(Either.left(true));
when(titanDao.commit()).thenReturn(TitanOperationStatus.OK);
}
@@ -189,7 +192,9 @@ public class InterfaceOperationBusinessLogicTest {
public void updateInterfaceOperationTestWithArtifactSuccess() {
when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes())
.thenReturn(Either.left(Collections.emptyMap()));
- when(artifactCassandraDao.getCountOfArtifactById(any(String.class))).thenReturn(Either.left(new Long(1)));
+ when(artifactToscaOperation.removeArifactFromResource(any(), any(), any(), anyBoolean()))
+ .thenReturn(Either.left(new ArtifactDefinition()));
+ when(artifactToscaOperation.getArtifactById(any(), any())).thenReturn(Either.left(new ArtifactDefinition()));
when(artifactCassandraDao.deleteArtifact(any(String.class))).thenReturn(CassandraOperationStatus.OK);
when(interfaceOperation.updateInterfaces(any(), any())).thenReturn(Either.left(
Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId, operationId, operationName))));
@@ -205,8 +210,9 @@ public class InterfaceOperationBusinessLogicTest {
public void updateInterfaceOperationTestWithArtifactFailure() {
when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes())
.thenReturn(Either.left(Collections.emptyMap()));
- when(artifactCassandraDao.getCountOfArtifactById(any(String.class))).thenReturn(Either.left(new Long(1)));
- when(artifactCassandraDao.deleteArtifact(any(String.class))).thenReturn(CassandraOperationStatus.GENERAL_ERROR);
+ when(artifactToscaOperation.getArtifactById(any(), any())).thenReturn(Either.left(new ArtifactDefinition()));
+ when(artifactToscaOperation.removeArifactFromResource(any(), any(), any(), anyBoolean()))
+ .thenReturn(Either.right(StorageOperationStatus.ARTIFACT_NOT_FOUND));
Either<List<InterfaceDefinition>, ResponseFormat> interfaceOperation =
interfaceOperationBusinessLogic.updateInterfaceOperation(resourceId,
Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId,
@@ -219,8 +225,7 @@ public class InterfaceOperationBusinessLogicTest {
public void updateInterfaceOperationTestWithoutArtifact() {
when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes())
.thenReturn(Either.left(Collections.emptyMap()));
- when(artifactCassandraDao.getCountOfArtifactById(any(String.class)))
- .thenReturn(Either.right(CassandraOperationStatus.NOT_FOUND));
+ when(artifactToscaOperation.getArtifactById(any(), any())).thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
when(interfaceOperation.updateInterfaces(any(), any())).thenReturn(Either.left(
Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId, operationId, operationName))));
Either<List<InterfaceDefinition>, ResponseFormat> interfaceOperation =
@@ -273,7 +278,7 @@ public class InterfaceOperationBusinessLogicTest {
when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes())
.thenReturn(Either.left(Collections.emptyMap()));
when(interfaceOperationValidation
- .validateInterfaceOperations(anyObject(), anyObject(), any(), anyMap(), anyBoolean()))
+ .validateInterfaceOperations(any(), any(), any(), anyMap(), anyBoolean()))
.thenReturn(Either.right(new ResponseFormat()));
Either<List<InterfaceDefinition>, ResponseFormat> interfaceOperationEither =
interfaceOperationBusinessLogic.createInterfaceOperation(resourceId,
@@ -299,6 +304,9 @@ public class InterfaceOperationBusinessLogicTest {
public void deleteInterfaceOperationTestSuccess() {
resource.getInterfaces().get(interfaceId).getOperations()
.putAll(InterfaceOperationTestUtils.createMockOperationMap(operationId1, operationName));
+ when(artifactToscaOperation.getArtifactById(any(), any())).thenReturn(Either.left(new ArtifactDefinition()));
+ when(artifactToscaOperation.removeArifactFromResource(any(), any(), any(), anyBoolean()))
+ .thenReturn(Either.left(new ArtifactDefinition()));
when(artifactCassandraDao.deleteArtifact(any(String.class))).thenReturn(CassandraOperationStatus.OK);
when(interfaceOperation.updateInterfaces(any(), any())).thenReturn(Either.left(Collections.emptyList()));
Assert.assertTrue(interfaceOperationBusinessLogic.deleteInterfaceOperation(resourceId, interfaceId,
@@ -307,6 +315,9 @@ public class InterfaceOperationBusinessLogicTest {
@Test
public void shouldFailWhenDeleteInterfaceOperationFailedTest() {
+ when(artifactToscaOperation.getArtifactById(any(), any())).thenReturn(Either.left(new ArtifactDefinition()));
+ when(artifactToscaOperation.removeArifactFromResource(any(), any(), any(), anyBoolean()))
+ .thenReturn(Either.left(new ArtifactDefinition()));
when(artifactCassandraDao.deleteArtifact(any(String.class))).thenReturn(CassandraOperationStatus.OK);
when(interfaceOperation.updateInterfaces(any(), any()))
.thenReturn(Either.right(StorageOperationStatus.GENERAL_ERROR));
@@ -316,6 +327,9 @@ public class InterfaceOperationBusinessLogicTest {
@Test
public void deleteInterfaceOperationTestFailOnArtifactDeletion() {
+ when(artifactToscaOperation.getArtifactById(any(), any())).thenReturn(Either.left(new ArtifactDefinition()));
+ when(artifactToscaOperation.removeArifactFromResource(any(), any(), any(), anyBoolean()))
+ .thenReturn(Either.left(new ArtifactDefinition()));
when(artifactCassandraDao.deleteArtifact(any(String.class))).thenReturn(CassandraOperationStatus.GENERAL_ERROR);
Assert.assertTrue(interfaceOperationBusinessLogic.deleteInterfaceOperation(resourceId, interfaceId,
Collections.singletonList(operationId), user, true).isRight());
@@ -323,6 +337,9 @@ public class InterfaceOperationBusinessLogicTest {
@Test
public void deleteInterfaceOperationTestFailOnException() {
+ when(artifactToscaOperation.getArtifactById(any(), any())).thenReturn(Either.left(new ArtifactDefinition()));
+ when(artifactToscaOperation.removeArifactFromResource(any(), any(), any(), anyBoolean()))
+ .thenReturn(Either.left(new ArtifactDefinition()));
when(artifactCassandraDao.deleteArtifact(any(String.class))).thenThrow(new RuntimeException());
Assert.assertTrue(interfaceOperationBusinessLogic.deleteInterfaceOperation(resourceId, interfaceId,
Collections.singletonList(operationId), user, true).isRight());
@@ -330,6 +347,9 @@ public class InterfaceOperationBusinessLogicTest {
@Test
public void deleteInterfaceTestSuccess() {
+ when(artifactToscaOperation.getArtifactById(any(), any())).thenReturn(Either.left(new ArtifactDefinition()));
+ when(artifactToscaOperation.removeArifactFromResource(any(), any(), any(), anyBoolean()))
+ .thenReturn(Either.left(new ArtifactDefinition()));
when(artifactCassandraDao.deleteArtifact(any(String.class))).thenReturn(CassandraOperationStatus.OK);
when(interfaceOperation.updateInterfaces(any(), any())).thenReturn(Either.left(Collections.emptyList()));
when(interfaceOperation.deleteInterface(any(), any())).thenReturn(Either.left(interfaceId));
@@ -339,6 +359,9 @@ public class InterfaceOperationBusinessLogicTest {
@Test
public void deleteInterfaceTestFailure() {
+ when(artifactToscaOperation.getArtifactById(any(), any())).thenReturn(Either.left(new ArtifactDefinition()));
+ when(artifactToscaOperation.removeArifactFromResource(any(), any(), any(), anyBoolean()))
+ .thenReturn(Either.left(new ArtifactDefinition()));
when(artifactCassandraDao.deleteArtifact(any(String.class))).thenReturn(CassandraOperationStatus.OK);
when(interfaceOperation.updateInterfaces(any(), any())).thenReturn(Either.left(Collections.emptyList()));
when(interfaceOperation.deleteInterface(any(), any()))
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/utils/InterfaceOperationUtilsTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/utils/InterfaceOperationUtilsTest.java
index 43649f64f8..1258bc04a9 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/utils/InterfaceOperationUtilsTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/utils/InterfaceOperationUtilsTest.java
@@ -123,4 +123,10 @@ public class InterfaceOperationUtilsTest {
.isPresent());
}
+ @Test
+ public void testIsArtifactInUse() {
+ Assert.assertTrue(InterfaceOperationUtils.isArtifactInUse(resource, operationId1, "uniqId"));
+ Assert.assertFalse(InterfaceOperationUtils.isArtifactInUse(resource, operationId1, "uniqId1"));
+ }
+
} \ No newline at end of file