summaryrefslogtreecommitdiffstats
path: root/bpmn/so-bpmn-tasks/src
diff options
context:
space:
mode:
Diffstat (limited to 'bpmn/so-bpmn-tasks/src')
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/AbstractControllerExecution.java10
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/buildingblock/ControllerExecutionBB.java2
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/ControllerExecution.java7
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/GenericCDSProcessingBB.java5
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/Resource.java14
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowAction.java1
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionConstants.java1
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/ServiceEBBLoader.java5
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/listeners/SkipCDSBuildingBlockListener.java12
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/validators/UpgradePreWorkflowValidator.java114
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIServiceInstanceResources.java18
-rw-r--r--bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/listeners/SkipCDSBuildingBlockListenerTest.java14
-rw-r--r--bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/validators/UpgradePreWorkflowValidatorTest.java156
13 files changed, 350 insertions, 9 deletions
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/AbstractControllerExecution.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/AbstractControllerExecution.java
index f3b767a8f1..1da9ad584a 100644
--- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/AbstractControllerExecution.java
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/AbstractControllerExecution.java
@@ -157,6 +157,16 @@ public abstract class AbstractControllerExecution<T> {
}
/**
+ * Check whether the controller scope is SERVICE
+ *
+ * @param controllerScope controller scope, e.g, pnf, vnf, vfModule, service
+ * @return true if the controller scope is service, else return false
+ */
+ protected boolean isServiceResourceScope(final String controllerScope) {
+ return "service".equalsIgnoreCase(controllerScope);
+ }
+
+ /**
* Check whether the controller scope is VNF resource related.
*
* @param controllerScope controller scope, e.g, pnf, vnf, vfModule
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/buildingblock/ControllerExecutionBB.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/buildingblock/ControllerExecutionBB.java
index 39a695b0b6..92be824691 100644
--- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/buildingblock/ControllerExecutionBB.java
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/buildingblock/ControllerExecutionBB.java
@@ -109,6 +109,8 @@ public class ControllerExecutionBB extends AbstractControllerExecution<BuildingB
PnfResourceCustomization pnfResourceCustomization =
catalogDbClient.getPnfResourceCustomizationByModelCustomizationUUID(resourceCustomizationUuid);
controllerActor = pnfResourceCustomization.getControllerActor();
+ } else if (isServiceResourceScope(controllerScope)) {
+ return controllerActor;
} else if (isVnfResourceScope(controllerScope)) {
VnfResourceCustomization vnfResourceCustomization =
catalogDbClient.getVnfResourceCustomizationByModelCustomizationUUID(resourceCustomizationUuid);
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/ControllerExecution.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/ControllerExecution.java
index c56ab3e71d..f2f3b5da08 100644
--- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/ControllerExecution.java
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/ControllerExecution.java
@@ -26,7 +26,9 @@ import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
import org.onap.so.bpmn.servicedecomposition.bbobjects.Pnf;
import org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock;
import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock;
+import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock;
import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
+import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoServiceInstance;
import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
import org.onap.so.client.exception.BBObjectNotFoundException;
import org.onap.so.client.exception.ExceptionBuilder;
@@ -87,6 +89,11 @@ public class ControllerExecution {
execution.getGeneralBuildingBlock().getRequestContext().getMsoRequestId());
execution.setVariable(PRC_BLUEPRINT_VERSION, pnfResourceCustomization.getBlueprintVersion());
execution.setVariable(PRC_BLUEPRINT_NAME, pnfResourceCustomization.getBlueprintName());
+ } else if ("service".equalsIgnoreCase(scope)) {
+ GeneralBuildingBlock gbb = execution.getGeneralBuildingBlock();
+ ModelInfoServiceInstance modelInfoServiceInstance =
+ gbb.getServiceInstance().getModelInfoServiceInstance();
+ controllerActor = Optional.ofNullable(modelInfoServiceInstance.getControllerActor()).orElse("CDS");
} else {
GenericVnf genericVnf = getGenericVnf(execution);
String modelUuid = genericVnf.getModelInfoGenericVnf().getModelCustomizationUuid();
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/GenericCDSProcessingBB.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/GenericCDSProcessingBB.java
index 1fae5ce06c..5442f444ee 100644
--- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/GenericCDSProcessingBB.java
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/GenericCDSProcessingBB.java
@@ -46,6 +46,7 @@ public class GenericCDSProcessingBB implements ControllerRunnable<BuildingBlockE
public static final String CDS_ACTOR = "cds";
public static final String VNF_SCOPE = "vnf";
public static final String VF_MODULE_SCOPE = "vfmodule";
+ public static final String SERVICE_SCOPE = "service";
@Autowired
private ExceptionBuilder exceptionBuilder;
@@ -59,8 +60,8 @@ public class GenericCDSProcessingBB implements ControllerRunnable<BuildingBlockE
@Override
public Boolean understand(ControllerContext<BuildingBlockExecution> context) {
String scope = context.getControllerScope();
- return CDS_ACTOR.equalsIgnoreCase(context.getControllerActor())
- && (VNF_SCOPE.equalsIgnoreCase(scope) || VF_MODULE_SCOPE.equalsIgnoreCase(scope));
+ return CDS_ACTOR.equalsIgnoreCase(context.getControllerActor()) && (SERVICE_SCOPE.equalsIgnoreCase(scope)
+ || VNF_SCOPE.equalsIgnoreCase(scope) || VF_MODULE_SCOPE.equalsIgnoreCase(scope));
}
@Override
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/Resource.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/Resource.java
index 99cff932c5..2a8852a4bd 100644
--- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/Resource.java
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/Resource.java
@@ -22,12 +22,14 @@
package org.onap.so.bpmn.infrastructure.workflow.tasks;
+import java.io.Serializable;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
-public class Resource {
+public class Resource implements Serializable {
+ private static final long serialVersionUID = 4259534487473481127L;
private String resourceId;
private WorkflowType resourceType;
private boolean generated;
@@ -37,6 +39,7 @@ public class Resource {
private String vfModuleCustomizationId;
private String cvnfModuleCustomizationId;
private String instanceName;
+ private String modelInvariantId;
private int processingPriority;
private Resource parent;
private List<Resource> children;
@@ -129,6 +132,15 @@ public class Resource {
this.instanceName = instanceName;
}
+ public String getModelInvariantId() {
+ return modelInvariantId;
+ }
+
+ public void setModelInvariantId(String modelInvariantId) {
+ this.modelInvariantId = modelInvariantId;
+ }
+
+
public int getProcessingPriority() {
return processingPriority == 0 ? (isBaseVfModule() ? Integer.MIN_VALUE + 1 : 0) : processingPriority;
}
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowAction.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowAction.java
index e49aed8b25..02508b8867 100644
--- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowAction.java
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowAction.java
@@ -355,6 +355,7 @@ public class WorkflowAction {
} else {
updateResourceIdsFromAAITraversal(flowsToExecute, resourceList, aaiResourceIds, serviceInstanceId);
}
+ execution.setVariable("resources", resourceList);
return flowsToExecute;
}
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionConstants.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionConstants.java
index 38ba0077e2..8c6fb2b38b 100644
--- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionConstants.java
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionConstants.java
@@ -39,6 +39,7 @@ public final class WorkflowActionConstants {
public static final String CREATE_INSTANCE = "createInstance";
public static final String DEACTIVATE_INSTANCE = "deactivateInstance";
public static final String DELETE_INSTANCE = "deleteInstance";
+ public static final String UPGRADE_INSTANCE = "upgradeInstance";
public static final String FABRIC_CONFIGURATION = "FabricConfiguration";
public static final String NETWORKCOLLECTION = "NetworkCollection";
public static final String RECREATE_INSTANCE = "recreateInstance";
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/ServiceEBBLoader.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/ServiceEBBLoader.java
index e4c6d2951f..c000e9475c 100644
--- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/ServiceEBBLoader.java
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/ServiceEBBLoader.java
@@ -61,6 +61,7 @@ import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConst
import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.DEACTIVATE_INSTANCE;
import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.DELETE_INSTANCE;
import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.UNASSIGN_INSTANCE;
+import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.UPGRADE_INSTANCE;
import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.WORKFLOW_ACTION_ERROR_MESSAGE;
import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.CREATE_INSTANCE;
import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.FABRIC_CONFIGURATION;
@@ -136,6 +137,7 @@ public class ServiceEBBLoader {
}
} else if ((ACTIVATE_INSTANCE.equalsIgnoreCase(requestAction)
|| UNASSIGN_INSTANCE.equalsIgnoreCase(requestAction) || DELETE_INSTANCE.equalsIgnoreCase(requestAction)
+ || UPGRADE_INSTANCE.equalsIgnoreCase(requestAction)
|| requestAction.equalsIgnoreCase("activate" + FABRIC_CONFIGURATION))) {
// SERVICE-MACRO-ACTIVATE, SERVICE-MACRO-UNASSIGN, and
// SERVICE-MACRO-DELETE
@@ -193,8 +195,9 @@ public class ServiceEBBLoader {
ServiceInstance serviceInstanceAAI = bbInputSetupUtils.getAAIServiceInstanceById(resourceId);
org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance serviceInstanceMSO =
bbInputSetup.getExistingServiceInstance(serviceInstanceAAI);
- Resource serviceResource =
+ var serviceResource =
new Resource(WorkflowType.SERVICE, serviceInstanceMSO.getServiceInstanceId(), false, null);
+ serviceResource.setModelInvariantId(serviceInstanceAAI.getModelInvariantId());
resourceList.add(serviceResource);
traverseServiceInstanceMSOVnfs(resourceList, serviceResource, aaiResourceIds, serviceInstanceMSO);
traverseServiceInstanceMSOPnfs(resourceList, serviceResource, aaiResourceIds, serviceInstanceMSO);
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/listeners/SkipCDSBuildingBlockListener.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/listeners/SkipCDSBuildingBlockListener.java
index 272c6189b4..ff6c113af3 100644
--- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/listeners/SkipCDSBuildingBlockListener.java
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/listeners/SkipCDSBuildingBlockListener.java
@@ -29,8 +29,10 @@ import org.onap.so.bpmn.common.BBConstants;
import org.onap.so.bpmn.common.BuildingBlockExecution;
import org.onap.so.bpmn.common.listener.flowmanipulator.FlowManipulatorListenerRunner;
import org.onap.so.bpmn.common.listener.flowmanipulator.PreFlowManipulator;
+import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock;
import org.onap.so.db.catalog.beans.PnfResourceCustomization;
+import org.onap.so.db.catalog.beans.Service;
import org.onap.so.db.catalog.beans.VfModuleCustomization;
import org.onap.so.db.catalog.beans.VnfResourceCustomization;
import org.onap.so.db.catalog.client.CatalogDbClient;
@@ -76,11 +78,11 @@ public class SkipCDSBuildingBlockListener implements PreFlowManipulator {
BuildingBlockExecution execution) {
String customizationUUID = currentBB.getBuildingBlock().getKey();
- if (Strings.isEmpty(customizationUUID)) {
- return;
- }
-
- if (currentBB.getBuildingBlock().getBpmnScope().equalsIgnoreCase("VNF")
+ if ("SERVICE".equalsIgnoreCase(currentBB.getBuildingBlock().getBpmnScope())) {
+ String modelUUID = currentBB.getRequestDetails().getModelInfo().getModelUuid();
+ Service service = catalogDbClient.getServiceByID(modelUUID);
+ currentSequenceSkipCheck(execution, service.getSkipPostInstConf());
+ } else if (currentBB.getBuildingBlock().getBpmnScope().equalsIgnoreCase("VNF")
&& containsIgnoreCaseAction(currentBB, vnfActions)) {
List<VnfResourceCustomization> vnfResourceCustomizations =
catalogDbClient.getVnfResourceCustomizationByModelUuid(
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/validators/UpgradePreWorkflowValidator.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/validators/UpgradePreWorkflowValidator.java
new file mode 100644
index 0000000000..5e82b4f284
--- /dev/null
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/validators/UpgradePreWorkflowValidator.java
@@ -0,0 +1,114 @@
+package org.onap.so.bpmn.infrastructure.workflow.tasks.validators;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import java.io.IOException;
+import java.util.List;
+import java.util.Optional;
+import java.util.Set;
+import java.util.function.Function;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+import org.onap.so.bpmn.common.BBConstants;
+import org.onap.so.bpmn.common.BuildingBlockExecution;
+import org.onap.so.bpmn.common.listener.validation.PreWorkflowValidator;
+import org.onap.so.bpmn.infrastructure.workflow.tasks.Resource;
+import org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowType;
+import org.onap.so.db.catalog.beans.Service;
+import org.onap.so.db.catalog.beans.VnfResourceCustomization;
+import org.onap.so.db.catalog.client.CatalogDbClient;
+import org.onap.so.serviceinstancebeans.RequestDetails;
+import org.onap.so.serviceinstancebeans.ServiceInstancesRequest;
+import org.springframework.stereotype.Component;
+
+@Component
+public class UpgradePreWorkflowValidator implements PreWorkflowValidator {
+
+ private static final String ERR_MSG_INVARIANT_MISMATCH =
+ "Request service modelInvariantId: %s does not match AAI service modelInvariantId: %s";
+ private static final String ERR_MSG_EXISTING_VNFS_NOT_SUPPORTED =
+ "Existing vnfs in AAI are not supported by service model. Unsupported vnfCustomizationIds: %s";
+
+ private final CatalogDbClient catalogDbClient;
+
+ private static final Function<WorkflowType, Predicate<Resource>> resourceType =
+ workflowType -> resource -> resource.getResourceType() == workflowType;
+
+ public UpgradePreWorkflowValidator(CatalogDbClient catalogDbClient) {
+ this.catalogDbClient = catalogDbClient;
+ }
+
+ @Override
+ public boolean shouldRunFor(String requestAction) {
+ return "upgradeInstance".equalsIgnoreCase(requestAction);
+ }
+
+ @Override
+ public Optional<String> validate(BuildingBlockExecution execution) {
+ final String bpmnRequest = execution.getVariable(BBConstants.G_BPMN_REQUEST);
+ List<Resource> resources = execution.getVariable("resources");
+
+ Optional<ServiceInstancesRequest> sir = parseBpmnRequest(bpmnRequest);
+ if (sir.isEmpty()) {
+ return Optional.of("Failed to parse bpmnRequest");
+ }
+ var requestDetails = sir.get().getRequestDetails();
+ String requestModelInvariantId = requestDetails.getModelInfo().getModelInvariantId();
+
+ Optional<String> modelInvariantMismatch = validateInvariantId(resources, requestModelInvariantId);
+ if (modelInvariantMismatch.isPresent()) {
+ return modelInvariantMismatch;
+ }
+
+ List<Resource> aaiVnfResources = getVnfResources(resources);
+ if (aaiVnfResources.isEmpty()) {
+ return Optional.empty();
+ }
+
+ String serviceModelUuid = requestDetails.getModelInfo().getModelUuid();
+ Optional<List<VnfResourceCustomization>> vnfResourceCustomizations =
+ getVnfResourceCustomizations(serviceModelUuid);
+ if (vnfResourceCustomizations.isEmpty()) {
+ return Optional.of(String.format("Service model: %s does not exist in catalog db.", serviceModelUuid));
+ }
+
+ return validateExistingVnfsSupported(aaiVnfResources, vnfResourceCustomizations.get());
+ }
+
+ private Optional<ServiceInstancesRequest> parseBpmnRequest(String bpmnRequest) {
+ try {
+ return Optional.of(new ObjectMapper().readValue(bpmnRequest, ServiceInstancesRequest.class));
+ } catch (IOException e) {
+ return Optional.empty();
+ }
+ }
+
+ private Optional<String> validateInvariantId(List<Resource> resources, String requestModelInvariantId) {
+ return resources.stream().filter(resourceType.apply(WorkflowType.SERVICE)).findFirst()
+ .filter(r -> !r.getModelInvariantId().equals(requestModelInvariantId))
+ .map(r -> String.format(ERR_MSG_INVARIANT_MISMATCH, requestModelInvariantId, r.getModelInvariantId()));
+ }
+
+ private Optional<List<VnfResourceCustomization>> getVnfResourceCustomizations(String serviceModelUuid) {
+ return Optional.ofNullable(catalogDbClient.getServiceByModelUUID(serviceModelUuid))
+ .map(Service::getVnfCustomizations);
+ }
+
+ private List<Resource> getVnfResources(List<Resource> resources) {
+ return resources.stream().filter(resourceType.apply(WorkflowType.VNF)).collect(Collectors.toList());
+ }
+
+ private Optional<String> validateExistingVnfsSupported(List<Resource> vnfResources,
+ List<VnfResourceCustomization> vnfResourceCustomizations) {
+ Set<String> modeledVnfCustomizationIds = vnfResourceCustomizations.stream()
+ .map(VnfResourceCustomization::getModelCustomizationUUID).collect(Collectors.toSet());
+
+ String unsupportedVnfCustomizationIds = vnfResources.stream().map(Resource::getVnfCustomizationId)
+ .filter(id -> !modeledVnfCustomizationIds.contains(id)).collect(Collectors.joining(","));
+
+ if (unsupportedVnfCustomizationIds.isEmpty()) {
+ return Optional.empty();
+ }
+ return Optional.of(String.format(ERR_MSG_EXISTING_VNFS_NOT_SUPPORTED, unsupportedVnfCustomizationIds));
+ }
+
+}
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIServiceInstanceResources.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIServiceInstanceResources.java
index cc99f178bd..8c1e8f6d62 100644
--- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIServiceInstanceResources.java
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIServiceInstanceResources.java
@@ -181,9 +181,27 @@ public class AAIServiceInstanceResources {
.createResourceUri(Types.SERVICE_INSTANCE.getFragment(serviceInstance.getServiceInstanceId()));
org.onap.aai.domain.yang.ServiceInstance aaiServiceInstance =
aaiObjectMapper.mapServiceInstance(serviceInstance);
+ mapEmptyStringsToNull(aaiServiceInstance);
injectionHelper.getAaiClient().update(serviceInstanceURI, aaiServiceInstance);
}
+ /*
+ * Per serialization configurations in GraphInventoryCommonObjectMapperPatchProvider, empty strings are mapped to
+ * null and included in the payload. Null values are on the other hand excluded. Passing null values in a PATCH
+ * request to AAI will fail. We need to map empty strings to null before serialization in order to exclude these
+ * values from the payload.
+ */
+ private void mapEmptyStringsToNull(org.onap.aai.domain.yang.ServiceInstance serviceInstance) {
+ if (serviceInstance != null) {
+ if ("".equals(serviceInstance.getServiceType()))
+ serviceInstance.setServiceType(null);
+ if ("".equals(serviceInstance.getServiceRole()))
+ serviceInstance.setServiceRole(null);
+ if ("".equals(serviceInstance.getServiceFunction()))
+ serviceInstance.setServiceFunction(null);
+ }
+ }
+
public boolean checkInstanceServiceNameInUse(ServiceInstance serviceInstance) {
AAIPluralResourceUri uriSI = AAIUriFactory.createNodesUri(Types.SERVICE_INSTANCES.getFragment())
.queryParam("service-instance-name", serviceInstance.getServiceInstanceName());
diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/listeners/SkipCDSBuildingBlockListenerTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/listeners/SkipCDSBuildingBlockListenerTest.java
index fdf4d36c89..b23147e351 100644
--- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/listeners/SkipCDSBuildingBlockListenerTest.java
+++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/listeners/SkipCDSBuildingBlockListenerTest.java
@@ -37,6 +37,7 @@ import org.onap.so.bpmn.common.DelegateExecutionImpl;
import org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock;
import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock;
import org.onap.so.db.catalog.beans.PnfResourceCustomization;
+import org.onap.so.db.catalog.beans.Service;
import org.onap.so.db.catalog.beans.VfModuleCustomization;
import org.onap.so.db.catalog.beans.VnfResourceCustomization;
import org.onap.so.db.catalog.client.CatalogDbClient;
@@ -46,6 +47,7 @@ import org.onap.so.serviceinstancebeans.RequestDetails;
@RunWith(MockitoJUnitRunner.Silent.class)
public class SkipCDSBuildingBlockListenerTest {
+ private static final String SERVICE_SCOPE = "service";
private static final String VNF_SCOPE = "VNF";
private static final String VF_SCOPE = "VFModule";
private static final String PNF_SCOPE = "pnf";
@@ -90,6 +92,18 @@ public class SkipCDSBuildingBlockListenerTest {
}
@Test
+ public void testSkipCDSforService() {
+ setBuildingBlockAndCurrentSequence(SERVICE_SCOPE, "service-config-assign", 0);
+ Service service = new Service();
+ when(catalogDbClient.getServiceByID(TEST_MODELUUID)).thenReturn(service);
+
+ skipCDSBuildingBlockListener.run(flowsToExecute, executeBuildingBlock, buildingBlockExecution);
+
+ actual = buildingBlockExecution.getVariable(BBConstants.G_CURRENT_SEQUENCE);
+ assertEquals(1, actual);
+ }
+
+ @Test
public void testProcessForVNFToSkipCDSBB() {
// given
setBuildingBlockAndCurrentSequence(VNF_SCOPE, VNF_TEST_ACTION, 0);
diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/validators/UpgradePreWorkflowValidatorTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/validators/UpgradePreWorkflowValidatorTest.java
new file mode 100644
index 0000000000..1066ca1317
--- /dev/null
+++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/validators/UpgradePreWorkflowValidatorTest.java
@@ -0,0 +1,156 @@
+package org.onap.so.bpmn.infrastructure.workflow.tasks.validators;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.when;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Optional;
+import java.util.UUID;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.onap.so.bpmn.common.BBConstants;
+import org.onap.so.bpmn.common.BuildingBlockExecution;
+import org.onap.so.bpmn.infrastructure.workflow.tasks.Resource;
+import org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowType;
+import org.onap.so.db.catalog.beans.Service;
+import org.onap.so.db.catalog.beans.VnfResourceCustomization;
+import org.onap.so.db.catalog.client.CatalogDbClient;
+import org.onap.so.serviceinstancebeans.ModelInfo;
+import org.onap.so.serviceinstancebeans.RequestDetails;
+import org.onap.so.serviceinstancebeans.ServiceInstancesRequest;
+
+public class UpgradePreWorkflowValidatorTest {
+
+ @Mock
+ private CatalogDbClient catalogDbClient;
+
+ private UpgradePreWorkflowValidator validator;
+
+ private ObjectMapper objectMapper;
+
+ @Before
+ public void setup() {
+ MockitoAnnotations.initMocks(this);
+ validator = new UpgradePreWorkflowValidator(catalogDbClient);
+ objectMapper = new ObjectMapper();
+ }
+
+ @Test
+ public void shouldRunFor() {
+ assertTrue(validator.shouldRunFor("upgradeInstance"));
+ assertFalse(validator.shouldRunFor("createInstance"));
+ }
+
+ private BuildingBlockExecution createExecution(ServiceInstancesRequest sir, List<Resource> resourceList)
+ throws JsonProcessingException {
+ BuildingBlockExecution mock = Mockito.mock(BuildingBlockExecution.class);
+ String jsonSir = objectMapper.writer().writeValueAsString(sir);
+ when(mock.getVariable(BBConstants.G_BPMN_REQUEST)).thenReturn(jsonSir);
+ when(mock.getVariable("resources")).thenReturn(resourceList);
+ return mock;
+ }
+
+ @Test
+ public void validateModelInvariantMismatch() throws JsonProcessingException {
+ ServiceInstancesRequest sir = new ServiceInstancesRequest();
+ sir.setRequestDetails(new RequestDetails());
+ sir.getRequestDetails().setModelInfo(new ModelInfo());
+ sir.getRequestDetails().getModelInfo().setModelInvariantId(UUID.randomUUID().toString());
+
+ Resource serviceResource = new Resource(WorkflowType.SERVICE, "", false, null);
+ String aaiModelInvariantId = UUID.randomUUID().toString();
+ serviceResource.setModelInvariantId(aaiModelInvariantId);
+
+ BuildingBlockExecution execution = createExecution(sir, Arrays.asList(serviceResource));
+
+ Optional<String> message = validator.validate(execution);
+
+ assertTrue(message.isPresent());
+ assertTrue(message.get().startsWith("Request service modelInvariantId"));
+ }
+
+ @Test
+ public void validateNoVnfsInAAI() throws JsonProcessingException {
+ ServiceInstancesRequest sir = new ServiceInstancesRequest();
+ sir.setRequestDetails(new RequestDetails());
+ sir.getRequestDetails().setModelInfo(new ModelInfo());
+ String modelInvariantId = UUID.randomUUID().toString();
+ sir.getRequestDetails().getModelInfo().setModelInvariantId(modelInvariantId);
+
+ Resource serviceResource = new Resource(WorkflowType.SERVICE, "", false, null);
+ serviceResource.setModelInvariantId(modelInvariantId);
+
+ BuildingBlockExecution execution = createExecution(sir, Arrays.asList(serviceResource));
+
+ Optional<String> message = validator.validate(execution);
+
+ assertThat(message).isEmpty();
+ }
+
+ @Test
+ public void validateAAIVnfsNotSupported() throws JsonProcessingException {
+ ServiceInstancesRequest sir = new ServiceInstancesRequest();
+ sir.setRequestDetails(new RequestDetails());
+ sir.getRequestDetails().setModelInfo(new ModelInfo());
+ sir.getRequestDetails().getModelInfo().setModelUuid(UUID.randomUUID().toString());
+ String modelInvariantId = UUID.randomUUID().toString();
+ sir.getRequestDetails().getModelInfo().setModelInvariantId(modelInvariantId);
+
+ Resource serviceResource = new Resource(WorkflowType.SERVICE, "", false, null);
+ serviceResource.setModelInvariantId(modelInvariantId);
+ Resource vnfResource = new Resource(WorkflowType.VNF, "", false, serviceResource);
+ vnfResource.setVnfCustomizationId(UUID.randomUUID().toString());
+
+ Service service = new Service();
+ VnfResourceCustomization vnfCustomization = new VnfResourceCustomization();
+ vnfCustomization.setModelCustomizationUUID(UUID.randomUUID().toString());
+ service.setVnfCustomizations(Arrays.asList(vnfCustomization));
+
+ when(catalogDbClient.getServiceByModelUUID(anyString())).thenReturn(service);
+
+ BuildingBlockExecution execution = createExecution(sir, Arrays.asList(serviceResource, vnfResource));
+
+ Optional<String> message = validator.validate(execution);
+
+ assertTrue(message.isPresent());
+ assertTrue(message.get().startsWith("Existing vnfs in AAI are not supported by service model"));
+ }
+
+ @Test
+ public void validateHappyCase() throws JsonProcessingException {
+ ServiceInstancesRequest sir = new ServiceInstancesRequest();
+ sir.setRequestDetails(new RequestDetails());
+ sir.getRequestDetails().setModelInfo(new ModelInfo());
+ sir.getRequestDetails().getModelInfo().setModelUuid(UUID.randomUUID().toString());
+ String modelInvariantId = UUID.randomUUID().toString();
+ sir.getRequestDetails().getModelInfo().setModelInvariantId(modelInvariantId);
+
+ Resource serviceResource = new Resource(WorkflowType.SERVICE, "", false, null);
+ serviceResource.setModelInvariantId(modelInvariantId);
+ Resource vnfResource = new Resource(WorkflowType.VNF, "", false, serviceResource);
+ String vnfCustomiationId = UUID.randomUUID().toString();
+ vnfResource.setVnfCustomizationId(vnfCustomiationId);
+
+ Service service = new Service();
+ VnfResourceCustomization vnfCustomization = new VnfResourceCustomization();
+ vnfCustomization.setModelCustomizationUUID(vnfCustomiationId);
+ service.setVnfCustomizations(Arrays.asList(vnfCustomization));
+
+ when(catalogDbClient.getServiceByModelUUID(anyString())).thenReturn(service);
+
+ BuildingBlockExecution execution = createExecution(sir, Arrays.asList(serviceResource, vnfResource));
+
+ Optional<String> message = validator.validate(execution);
+
+ assertFalse(message.isPresent());
+ }
+
+}