aboutsummaryrefslogtreecommitdiffstats
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/adapter/cnf/tasks/CnfAdapterDeleteTasks.java66
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnf/tasks/VnfAdapterCreateTasks.java3
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/AaiResourceIdValidator.java220
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ExecuteBuildingBlockBuilder.java217
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/UserParamsServiceTraversal.java232
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowAction.java681
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasks.java70
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionConstants.java47
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/listeners/SkipCDSBuildingBlockListener.java2
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/listeners/SkipConfigVnfListener.java2
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/CnfAdapterClient.java25
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/entities/InstanceResponse.java18
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/vnf/mapper/AttributeNameValue.java8
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/vnf/mapper/VnfAdapterVfModuleObjectMapper.java5
-rw-r--r--bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/BaseTaskTest.java4
-rw-r--r--bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/buildingblock/controller/sdnc/prepare/PrepareSdncUpgradePreCheckPnfBBTest.java88
-rw-r--r--bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/AaiResourceIdValidatorTest.java765
-rw-r--r--bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ExecuteBuildingBlockBuilderTest.java90
-rw-r--r--bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasksTest.java261
-rw-r--r--bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionExtractResourcesAAITest.java102
-rw-r--r--bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionTest.java1021
21 files changed, 2340 insertions, 1587 deletions
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnf/tasks/CnfAdapterDeleteTasks.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnf/tasks/CnfAdapterDeleteTasks.java
new file mode 100644
index 0000000000..87466bbbd4
--- /dev/null
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnf/tasks/CnfAdapterDeleteTasks.java
@@ -0,0 +1,66 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Modifications Copyright (c) 2019 Samsung
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.bpmn.infrastructure.adapter.cnf.tasks;
+
+import org.onap.so.bpmn.common.BuildingBlockExecution;
+import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
+import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
+import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
+import org.onap.so.client.adapter.cnf.CnfAdapterClient;
+import org.onap.so.client.exception.ExceptionBuilder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+@Component
+public class CnfAdapterDeleteTasks {
+ private static final Logger logger = LoggerFactory.getLogger(CnfAdapterDeleteTasks.class);
+
+ @Autowired
+ private ExtractPojosForBB extractPojosForBB;
+ @Autowired
+ private ExceptionBuilder exceptionUtil;
+ @Autowired
+ private CnfAdapterClient cnfAdapterClient;
+
+ /**
+ * This method is used for deleting the instance with Multicloud K8s Plugin.
+ *
+ * @param execution
+ * @return
+ */
+ public void deleteInstance(BuildingBlockExecution execution) {
+ try {
+ logger.debug("Running delete instance - Helm");
+ VfModule vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID);
+ String heatStackId = vfModule.getHeatStackId();
+ execution.setVariable("heatStackId", heatStackId);
+ cnfAdapterClient.deleteVfModule(heatStackId);
+ } catch (Exception ex) {
+ logger.error("Exception occurred", ex);
+ exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
+ }
+ }
+
+}
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnf/tasks/VnfAdapterCreateTasks.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnf/tasks/VnfAdapterCreateTasks.java
index 663b097b78..685dbe2dca 100644
--- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnf/tasks/VnfAdapterCreateTasks.java
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnf/tasks/VnfAdapterCreateTasks.java
@@ -121,8 +121,7 @@ public class VnfAdapterCreateTasks {
try {
volumeGroup = extractPojosForBB.extractByKey(execution, ResourceKey.VOLUME_GROUP_ID);
} catch (BBObjectNotFoundException bbException) {
- logger.error("Exception occurred if bb object not found in VnfAdapterCreateTasks createVfModule ",
- bbException);
+ logger.info("Volume Group not found in GBB. ");
}
CloudRegion cloudRegion = gBBInput.getCloudRegion();
RequestContext requestContext = gBBInput.getRequestContext();
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/AaiResourceIdValidator.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/AaiResourceIdValidator.java
new file mode 100644
index 0000000000..6d90070b96
--- /dev/null
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/AaiResourceIdValidator.java
@@ -0,0 +1,220 @@
+package org.onap.so.bpmn.infrastructure.workflow.tasks;
+
+import java.util.Map;
+import java.util.Optional;
+import org.onap.aai.domain.yang.GenericVnf;
+import org.onap.aai.domain.yang.GenericVnfs;
+import org.onap.aai.domain.yang.L3Network;
+import org.onap.aai.domain.yang.ServiceInstance;
+import org.onap.aai.domain.yang.ServiceInstances;
+import org.onap.aai.domain.yang.VolumeGroup;
+import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder;
+import org.onap.so.bpmn.servicedecomposition.entities.WorkflowResourceIds;
+import org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetupUtils;
+import org.onap.so.bpmn.servicedecomposition.tasks.exceptions.DuplicateNameException;
+import org.onap.so.bpmn.servicedecomposition.tasks.exceptions.MultipleObjectsFoundException;
+import org.onap.so.serviceinstancebeans.RequestDetails;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+
+@Component
+public class AaiResourceIdValidator {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(AaiResourceIdValidator.class);
+
+ private static final String SERVICE_INSTANCE = "serviceInstance";
+ private static final String NAME_EXISTS_WITH_DIFF_VERSION_ID = "(%s) and different version id (%s)";
+ private static final String WORKFLOW_ACTION_WAS_UNABLE_TO_VERIFY_IF_THE_INSTANCE_NAME_ALREADY_EXIST_IN_AAI =
+ "WorkflowAction was unable to verify if the instance name already exist in AAI.";
+ private static final String NAME_EXISTS_MULTIPLE =
+ "(%s) and multiple combination of model-version-id + service-type + global-customer-id";
+ private static final String NAME_EXISTS_WITH_DIFF_COMBINATION =
+ "(%s) and global-customer-id (%s), service-type (%s), model-version-id (%s)";
+ private static final String NAME_EXISTS_WITH_DIFF_CUSTOMIZATION_ID =
+ "(%s), same parent and different customization id (%s)";
+ private static final String NAME_EXISTS_WITH_DIFF_PARENT = "(%s) id (%s) and different parent relationship";
+
+
+ private final BBInputSetupUtils bbInputSetupUtils;
+
+ public AaiResourceIdValidator(BBInputSetupUtils bbInputSetupUtils) {
+ this.bbInputSetupUtils = bbInputSetupUtils;
+ }
+
+ protected String validateResourceIdInAAI(String generatedResourceId, WorkflowType type, String instanceName,
+ RequestDetails reqDetails, WorkflowResourceIds workflowResourceIds) throws Exception {
+ try {
+ if ("SERVICE".equalsIgnoreCase(type.toString())) {
+ return validateServiceResourceIdInAAI(generatedResourceId, instanceName, reqDetails);
+ } else if ("NETWORK".equalsIgnoreCase(type.toString())) {
+ return validateNetworkResourceIdInAAI(generatedResourceId, instanceName, reqDetails,
+ workflowResourceIds);
+ } else if ("VNF".equalsIgnoreCase(type.toString())) {
+ return validateVnfResourceIdInAAI(generatedResourceId, instanceName, reqDetails, workflowResourceIds);
+ } else if ("VFMODULE".equalsIgnoreCase(type.toString())) {
+ return validateVfModuleResourceIdInAAI(generatedResourceId, instanceName, reqDetails,
+ workflowResourceIds);
+ } else if ("VOLUMEGROUP".equalsIgnoreCase(type.toString())) {
+ return validateVolumeGroupResourceIdInAAI(generatedResourceId, instanceName, reqDetails,
+ workflowResourceIds);
+ } else if ("CONFIGURATION".equalsIgnoreCase(type.toString())) {
+ return validateConfigurationResourceIdInAAI(generatedResourceId, instanceName, reqDetails,
+ workflowResourceIds);
+ }
+ return generatedResourceId;
+ } catch (DuplicateNameException dne) {
+ throw dne;
+ } catch (Exception ex) {
+ LOGGER.error(WORKFLOW_ACTION_WAS_UNABLE_TO_VERIFY_IF_THE_INSTANCE_NAME_ALREADY_EXIST_IN_AAI, ex);
+ throw new IllegalStateException(
+ WORKFLOW_ACTION_WAS_UNABLE_TO_VERIFY_IF_THE_INSTANCE_NAME_ALREADY_EXIST_IN_AAI);
+ }
+ }
+
+ protected String validateServiceResourceIdInAAI(String generatedResourceId, String instanceName,
+ RequestDetails reqDetails) throws DuplicateNameException {
+ String globalCustomerId = reqDetails.getSubscriberInfo().getGlobalSubscriberId();
+ String serviceType = reqDetails.getRequestParameters().getSubscriptionServiceType();
+ if (instanceName != null) {
+ Optional<ServiceInstance> serviceInstanceAAI =
+ bbInputSetupUtils.getAAIServiceInstanceByName(globalCustomerId, serviceType, instanceName);
+ if (serviceInstanceAAI.isPresent()) {
+ if (serviceInstanceAAI.get().getModelVersionId()
+ .equalsIgnoreCase(reqDetails.getModelInfo().getModelVersionId())) {
+ return serviceInstanceAAI.get().getServiceInstanceId();
+ } else {
+ throw new DuplicateNameException(SERVICE_INSTANCE, String.format(NAME_EXISTS_WITH_DIFF_VERSION_ID,
+ instanceName, reqDetails.getModelInfo().getModelVersionId()));
+ }
+ } else {
+ ServiceInstances aaiServiceInstances =
+ bbInputSetupUtils.getAAIServiceInstancesGloballyByName(instanceName);
+ if (aaiServiceInstances != null) {
+ if (aaiServiceInstances.getServiceInstance() != null
+ && !aaiServiceInstances.getServiceInstance().isEmpty()) {
+ if (aaiServiceInstances.getServiceInstance().size() > 1) {
+ throw new DuplicateNameException(SERVICE_INSTANCE,
+ String.format(NAME_EXISTS_MULTIPLE, instanceName));
+ } else {
+ ServiceInstance si = aaiServiceInstances.getServiceInstance().stream().findFirst().get();
+ Map<String, String> keys =
+ bbInputSetupUtils.getURIKeysFromServiceInstance(si.getServiceInstanceId());
+
+ throw new DuplicateNameException(SERVICE_INSTANCE, String.format(
+ NAME_EXISTS_WITH_DIFF_COMBINATION, instanceName,
+ keys.get(AAIFluentTypeBuilder.Types.CUSTOMER.getUriParams().globalCustomerId),
+ keys.get(
+ AAIFluentTypeBuilder.Types.SERVICE_SUBSCRIPTION.getUriParams().serviceType),
+ si.getModelVersionId()));
+ }
+ }
+ }
+ }
+ }
+ return generatedResourceId;
+ }
+
+ protected String validateNetworkResourceIdInAAI(String generatedResourceId, String instanceName,
+ RequestDetails reqDetails, WorkflowResourceIds workflowResourceIds)
+ throws DuplicateNameException, MultipleObjectsFoundException {
+ Optional<L3Network> network = bbInputSetupUtils
+ .getRelatedNetworkByNameFromServiceInstance(workflowResourceIds.getServiceInstanceId(), instanceName);
+ if (network.isPresent()) {
+ if (network.get().getModelCustomizationId()
+ .equalsIgnoreCase(reqDetails.getModelInfo().getModelCustomizationId())) {
+ return network.get().getNetworkId();
+ } else {
+ throw new DuplicateNameException("l3Network", String.format(NAME_EXISTS_WITH_DIFF_CUSTOMIZATION_ID,
+ instanceName, network.get().getModelCustomizationId()));
+ }
+ }
+ if (bbInputSetupUtils.existsAAINetworksGloballyByName(instanceName)) {
+ throw new DuplicateNameException("l3Network", String.format(NAME_EXISTS_WITH_DIFF_PARENT, instanceName,
+ workflowResourceIds.getServiceInstanceId()));
+ }
+ return generatedResourceId;
+ }
+
+ protected String validateVnfResourceIdInAAI(String generatedResourceId, String instanceName,
+ RequestDetails reqDetails, WorkflowResourceIds workflowResourceIds) throws DuplicateNameException {
+ Optional<GenericVnf> vnf = bbInputSetupUtils
+ .getRelatedVnfByNameFromServiceInstance(workflowResourceIds.getServiceInstanceId(), instanceName);
+ if (vnf.isPresent()) {
+ if (vnf.get().getModelCustomizationId()
+ .equalsIgnoreCase(reqDetails.getModelInfo().getModelCustomizationId())) {
+ return vnf.get().getVnfId();
+ } else {
+ throw new DuplicateNameException("generic-vnf", String.format(NAME_EXISTS_WITH_DIFF_CUSTOMIZATION_ID,
+ instanceName, vnf.get().getModelCustomizationId()));
+ }
+ }
+ GenericVnfs vnfs = bbInputSetupUtils.getAAIVnfsGloballyByName(instanceName);
+ if (vnfs != null) {
+ throw new DuplicateNameException("generic-vnf",
+ String.format(NAME_EXISTS_WITH_DIFF_PARENT, instanceName, vnfs.getGenericVnf().get(0).getVnfId()));
+ }
+ return generatedResourceId;
+ }
+
+ protected String validateVfModuleResourceIdInAAI(String generatedResourceId, String instanceName,
+ RequestDetails reqDetails, WorkflowResourceIds workflowResourceIds) throws DuplicateNameException {
+ GenericVnf vnf = bbInputSetupUtils.getAAIGenericVnf(workflowResourceIds.getVnfId());
+ if (vnf != null && vnf.getVfModules() != null) {
+ for (org.onap.aai.domain.yang.VfModule vfModule : vnf.getVfModules().getVfModule()) {
+ if (vfModule.getVfModuleName().equalsIgnoreCase(instanceName)) {
+ if (vfModule.getModelCustomizationId()
+ .equalsIgnoreCase(reqDetails.getModelInfo().getModelCustomizationId())) {
+ return vfModule.getVfModuleId();
+ } else {
+ throw new DuplicateNameException("vfModule",
+ String.format(NAME_EXISTS_WITH_DIFF_CUSTOMIZATION_ID, instanceName,
+ reqDetails.getModelInfo().getModelCustomizationId()));
+ }
+ }
+ }
+ }
+ if (bbInputSetupUtils.existsAAIVfModuleGloballyByName(instanceName)) {
+ throw new DuplicateNameException("vfModule", instanceName);
+ }
+ return generatedResourceId;
+ }
+
+ protected String validateVolumeGroupResourceIdInAAI(String generatedResourceId, String instanceName,
+ RequestDetails reqDetails, WorkflowResourceIds workflowResourceIds) throws DuplicateNameException {
+ Optional<VolumeGroup> volumeGroup =
+ bbInputSetupUtils.getRelatedVolumeGroupByNameFromVnf(workflowResourceIds.getVnfId(), instanceName);
+ if (volumeGroup.isPresent()) {
+ if (volumeGroup.get().getVfModuleModelCustomizationId()
+ .equalsIgnoreCase(reqDetails.getModelInfo().getModelCustomizationId())) {
+ return volumeGroup.get().getVolumeGroupId();
+ } else {
+ throw new DuplicateNameException("volumeGroup", volumeGroup.get().getVolumeGroupName());
+ }
+ }
+ if (bbInputSetupUtils.existsAAIVolumeGroupGloballyByName(instanceName)) {
+ throw new DuplicateNameException("volumeGroup", instanceName);
+ }
+ return generatedResourceId;
+ }
+
+ protected String validateConfigurationResourceIdInAAI(String generatedResourceId, String instanceName,
+ RequestDetails reqDetails, WorkflowResourceIds workflowResourceIds) throws DuplicateNameException {
+ Optional<org.onap.aai.domain.yang.Configuration> configuration =
+ bbInputSetupUtils.getRelatedConfigurationByNameFromServiceInstance(
+ workflowResourceIds.getServiceInstanceId(), instanceName);
+ if (configuration.isPresent()) {
+ if (configuration.get().getModelCustomizationId()
+ .equalsIgnoreCase(reqDetails.getModelInfo().getModelCustomizationId())) {
+ return configuration.get().getConfigurationId();
+ } else {
+ throw new DuplicateNameException("configuration", String.format(NAME_EXISTS_WITH_DIFF_CUSTOMIZATION_ID,
+ instanceName, configuration.get().getConfigurationId()));
+ }
+ }
+ if (bbInputSetupUtils.existsAAIConfigurationGloballyByName(instanceName)) {
+ throw new DuplicateNameException("configuration", instanceName);
+ }
+ return generatedResourceId;
+ }
+}
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ExecuteBuildingBlockBuilder.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ExecuteBuildingBlockBuilder.java
new file mode 100644
index 0000000000..b8699838e2
--- /dev/null
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ExecuteBuildingBlockBuilder.java
@@ -0,0 +1,217 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Modifications Copyright (c) 2019 Samsung
+ * ================================================================================
+ * Modifications Copyright (c) 2021 Nokia
+ * ================================================================================
+ * Modifications Copyright (c) 2020 Tech Mahindra
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.bpmn.infrastructure.workflow.tasks;
+
+import org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock;
+import org.onap.so.bpmn.servicedecomposition.entities.ConfigurationResourceKeys;
+import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock;
+import org.onap.so.bpmn.servicedecomposition.entities.WorkflowResourceIds;
+import org.onap.so.db.catalog.beans.macro.OrchestrationFlow;
+import org.onap.so.serviceinstancebeans.RequestDetails;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Optional;
+import java.util.UUID;
+import java.util.stream.Collectors;
+import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.ASSIGNINSTANCE;
+import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.CONFIGURATION;
+import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.CONTROLLER;
+import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.CREATE_INSTANCE;
+import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.NETWORKCOLLECTION;
+import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.REPLACEINSTANCE;
+import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.REPLACEINSTANCERETAINASSIGNMENTS;
+import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.SERVICE;
+import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.VOLUMEGROUP;
+
+@Component
+public class ExecuteBuildingBlockBuilder {
+
+ private static final Logger logger = LoggerFactory.getLogger(ExecuteBuildingBlockBuilder.class);
+
+ private static final String VNF = "Vnf";
+ private static final String PNF = "Pnf";
+ private static final String VFMODULE = "VfModule";
+ private static final String NETWORK = "Network";
+
+ protected List<ExecuteBuildingBlock> buildExecuteBuildingBlockList(List<OrchestrationFlow> orchFlows,
+ List<Resource> resourceList, String requestId, String apiVersion, String resourceId, String requestAction,
+ String vnfType, WorkflowResourceIds workflowResourceIds, RequestDetails requestDetails,
+ boolean replaceVnf) {
+ List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
+ for (OrchestrationFlow orchFlow : orchFlows) {
+ if (orchFlow.getFlowName().contains(SERVICE)) {
+ if (!replaceVnf) {
+ workflowResourceIds.setServiceInstanceId(resourceId);
+ }
+ addBuildingBlockToExecuteBBList(flowsToExecute, resourceList, WorkflowType.SERVICE, orchFlow, requestId,
+ apiVersion, resourceId, requestAction, vnfType, workflowResourceIds, requestDetails, false,
+ false);
+ } else if (orchFlow.getFlowName().contains(VNF) || (orchFlow.getFlowName().contains(CONTROLLER)
+ && (VNF).equalsIgnoreCase(orchFlow.getBpmnScope()))) {
+ addBuildingBlockToExecuteBBList(flowsToExecute, resourceList, WorkflowType.VNF, orchFlow, requestId,
+ apiVersion, resourceId, requestAction, vnfType, workflowResourceIds, requestDetails, false,
+ false);
+ } else if (orchFlow.getFlowName().contains(PNF) || (orchFlow.getFlowName().contains(CONTROLLER)
+ && (PNF).equalsIgnoreCase(orchFlow.getBpmnScope()))) {
+ addBuildingBlockToExecuteBBList(flowsToExecute, resourceList, WorkflowType.PNF, orchFlow, requestId,
+ apiVersion, resourceId, requestAction, vnfType, workflowResourceIds, requestDetails, false,
+ false);
+ } else if (orchFlow.getFlowName().contains(NETWORK)
+ && !orchFlow.getFlowName().contains(NETWORKCOLLECTION)) {
+ addBuildingBlockToExecuteBBList(flowsToExecute, resourceList, WorkflowType.NETWORK, orchFlow, requestId,
+ apiVersion, resourceId, requestAction, vnfType, workflowResourceIds, requestDetails, false,
+ false);
+ addBuildingBlockToExecuteBBList(flowsToExecute, resourceList, WorkflowType.VIRTUAL_LINK, orchFlow,
+ requestId, apiVersion, resourceId, requestAction, vnfType, workflowResourceIds, requestDetails,
+ true, false);
+ } else if (orchFlow.getFlowName().contains(VFMODULE) || (orchFlow.getFlowName().contains(CONTROLLER)
+ && (VFMODULE).equalsIgnoreCase(orchFlow.getBpmnScope()))) {
+ List<Resource> vfModuleResourcesSorted;
+ if (requestAction.equals(CREATE_INSTANCE) || requestAction.equals(ASSIGNINSTANCE)
+ || requestAction.equals("activateInstance")) {
+ vfModuleResourcesSorted = sortVfModulesByBaseFirst(resourceList.stream()
+ .filter(x -> WorkflowType.VFMODULE == x.getResourceType()).collect(Collectors.toList()));
+ } else {
+ vfModuleResourcesSorted = sortVfModulesByBaseLast(resourceList.stream()
+ .filter(x -> WorkflowType.VFMODULE == x.getResourceType()).collect(Collectors.toList()));
+ }
+ for (Resource resource : vfModuleResourcesSorted) {
+ flowsToExecute.add(buildExecuteBuildingBlock(orchFlow, requestId, resource, apiVersion, resourceId,
+ requestAction, false, vnfType, workflowResourceIds, requestDetails, false, null, null,
+ false, null));
+ }
+ } else if (orchFlow.getFlowName().contains(VOLUMEGROUP)) {
+ if (requestAction.equalsIgnoreCase(REPLACEINSTANCE)
+ || requestAction.equalsIgnoreCase(REPLACEINSTANCERETAINASSIGNMENTS)) {
+ logger.debug("Replacing workflow resource id by volume group id");
+ resourceId = workflowResourceIds.getVolumeGroupId();
+ }
+ addBuildingBlockToExecuteBBList(flowsToExecute, resourceList, WorkflowType.VOLUMEGROUP, orchFlow,
+ requestId, apiVersion, resourceId, requestAction, vnfType, workflowResourceIds, requestDetails,
+ false, false);
+ } else if (orchFlow.getFlowName().contains(NETWORKCOLLECTION)) {
+ addBuildingBlockToExecuteBBList(flowsToExecute, resourceList, WorkflowType.NETWORKCOLLECTION, orchFlow,
+ requestId, apiVersion, resourceId, requestAction, vnfType, workflowResourceIds, requestDetails,
+ false, false);
+ } else if (orchFlow.getFlowName().contains(CONFIGURATION)) {
+ addBuildingBlockToExecuteBBList(flowsToExecute, resourceList, WorkflowType.CONFIGURATION, orchFlow,
+ requestId, apiVersion, resourceId, requestAction, vnfType, workflowResourceIds, requestDetails,
+ false, true);
+ } else {
+ flowsToExecute
+ .add(buildExecuteBuildingBlock(orchFlow, requestId, null, apiVersion, resourceId, requestAction,
+ false, vnfType, workflowResourceIds, requestDetails, false, null, null, false, null));
+ }
+ }
+ return flowsToExecute;
+ }
+
+ protected ExecuteBuildingBlock buildExecuteBuildingBlock(OrchestrationFlow orchFlow, String requestId,
+ Resource resource, String apiVersion, String resourceId, String requestAction, boolean aLaCarte,
+ String vnfType, WorkflowResourceIds workflowResourceIds, RequestDetails requestDetails,
+ boolean isVirtualLink, String virtualLinkKey, String vnfcName, boolean isConfiguration,
+ ReplaceInstanceRelatedInformation replaceInfo) {
+
+ BuildingBlock buildingBlock =
+ new BuildingBlock().setBpmnFlowName(orchFlow.getFlowName()).setMsoId(UUID.randomUUID().toString())
+ .setIsVirtualLink(isVirtualLink).setVirtualLinkKey(virtualLinkKey)
+ .setKey(Optional.ofNullable(resource).map(Resource::getResourceId).orElse(""));
+ Optional.ofNullable(orchFlow.getBpmnAction()).ifPresent(buildingBlock::setBpmnAction);
+ Optional.ofNullable(orchFlow.getBpmnScope()).ifPresent(buildingBlock::setBpmnScope);
+ String oldVolumeGroupName = "";
+ if (replaceInfo != null) {
+ oldVolumeGroupName = replaceInfo.getOldVolumeGroupName();
+ }
+ if (resource != null
+ && (orchFlow.getFlowName().contains(VOLUMEGROUP) && (requestAction.equalsIgnoreCase(REPLACEINSTANCE)
+ || requestAction.equalsIgnoreCase(REPLACEINSTANCERETAINASSIGNMENTS)))) {
+ logger.debug("Setting resourceId to volume group id for volume group flow on replace");
+ resourceId = workflowResourceIds.getVolumeGroupId();
+ }
+
+ ExecuteBuildingBlock executeBuildingBlock = new ExecuteBuildingBlock().setApiVersion(apiVersion)
+ .setaLaCarte(aLaCarte).setRequestAction(requestAction).setResourceId(resourceId).setVnfType(vnfType)
+ .setWorkflowResourceIds(workflowResourceIds).setRequestId(requestId).setBuildingBlock(buildingBlock)
+ .setRequestDetails(requestDetails).setOldVolumeGroupName(oldVolumeGroupName);
+
+ if (resource != null && (isConfiguration || resource.getResourceType().equals(WorkflowType.CONFIGURATION))) {
+ ConfigurationResourceKeys configurationResourceKeys = getConfigurationResourceKeys(resource, vnfcName);
+ executeBuildingBlock.setConfigurationResourceKeys(configurationResourceKeys);
+ }
+ return executeBuildingBlock;
+ }
+
+ protected List<Resource> sortVfModulesByBaseFirst(List<Resource> vfModuleResources) {
+ int count = 0;
+ for (Resource resource : vfModuleResources) {
+ if (resource.isBaseVfModule()) {
+ Collections.swap(vfModuleResources, 0, count);
+ break;
+ }
+ count++;
+ }
+ return vfModuleResources;
+ }
+
+ protected List<Resource> sortVfModulesByBaseLast(List<Resource> vfModuleResources) {
+ int count = 0;
+ for (Resource resource : vfModuleResources) {
+ if (resource.isBaseVfModule()) {
+ Collections.swap(vfModuleResources, vfModuleResources.size() - 1, count);
+ break;
+ }
+ count++;
+ }
+ return vfModuleResources;
+ }
+
+ private void addBuildingBlockToExecuteBBList(List<ExecuteBuildingBlock> flowsToExecute, List<Resource> resourceList,
+ WorkflowType workflowType, OrchestrationFlow orchFlow, String requestId, String apiVersion,
+ String resourceId, String requestAction, String vnfType, WorkflowResourceIds workflowResourceIds,
+ RequestDetails requestDetails, boolean isVirtualLink, boolean isConfiguration) {
+
+ resourceList.stream().filter(resource -> resource.getResourceType().equals(workflowType))
+ .forEach(resource -> flowsToExecute.add(buildExecuteBuildingBlock(orchFlow, requestId, resource,
+ apiVersion, resourceId, requestAction, false, vnfType, workflowResourceIds, requestDetails,
+ isVirtualLink, resource.getVirtualLinkKey(), null, isConfiguration, null)));
+ }
+
+ private ConfigurationResourceKeys getConfigurationResourceKeys(Resource resource, String vnfcName) {
+ ConfigurationResourceKeys configurationResourceKeys = new ConfigurationResourceKeys();
+ Optional.ofNullable(vnfcName).ifPresent(configurationResourceKeys::setVnfcName);
+ configurationResourceKeys.setCvnfcCustomizationUUID(resource.getCvnfModuleCustomizationId());
+ configurationResourceKeys.setVfModuleCustomizationUUID(resource.getVfModuleCustomizationId());
+ configurationResourceKeys.setVnfResourceCustomizationUUID(resource.getVnfCustomizationId());
+ return configurationResourceKeys;
+ }
+
+
+}
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/UserParamsServiceTraversal.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/UserParamsServiceTraversal.java
new file mode 100644
index 0000000000..3556cc024c
--- /dev/null
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/UserParamsServiceTraversal.java
@@ -0,0 +1,232 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Modifications Copyright (c) 2019 Samsung
+ * ================================================================================
+ * Modifications Copyright (c) 2020 Nokia
+ * ================================================================================
+ * Modifications Copyright (c) 2020 Tech Mahindra
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.bpmn.infrastructure.workflow.tasks;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.camunda.bpm.engine.delegate.DelegateExecution;
+import org.onap.so.client.exception.ExceptionBuilder;
+import org.onap.so.db.catalog.beans.CollectionResourceCustomization;
+import org.onap.so.db.catalog.beans.CvnfcConfigurationCustomization;
+import org.onap.so.db.catalog.beans.CvnfcCustomization;
+import org.onap.so.db.catalog.beans.VfModuleCustomization;
+import org.onap.so.db.catalog.client.CatalogDbClient;
+import org.onap.so.serviceinstancebeans.Networks;
+import org.onap.so.serviceinstancebeans.Pnfs;
+import org.onap.so.serviceinstancebeans.Service;
+import org.onap.so.serviceinstancebeans.VfModules;
+import org.onap.so.serviceinstancebeans.Vnfs;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.CREATE_INSTANCE;
+import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.FABRIC_CONFIGURATION;
+import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.USER_PARAM_SERVICE;
+import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.WORKFLOW_ACTION_ERROR_MESSAGE;
+
+@Component
+public class UserParamsServiceTraversal {
+
+ private static final Logger logger = LoggerFactory.getLogger(UserParamsServiceTraversal.class);
+
+ private final CatalogDbClient catalogDbClient;
+ private final ExceptionBuilder exceptionBuilder;
+
+ UserParamsServiceTraversal(CatalogDbClient catalogDbClient, ExceptionBuilder exceptionBuilder) {
+ this.catalogDbClient = catalogDbClient;
+ this.exceptionBuilder = exceptionBuilder;
+ }
+
+ protected List<Resource> getResourceListFromUserParams(DelegateExecution execution,
+ List<Map<String, Object>> userParams, String serviceModelVersionId, String requestAction)
+ throws IOException {
+ List<Resource> resourceList = new ArrayList<>();
+ boolean foundVfModuleOrVG = false;
+ String vnfCustomizationUUID = "";
+ String vfModuleCustomizationUUID = "";
+ if (userParams != null) {
+ for (Map<String, Object> params : userParams) {
+ if (params.containsKey(USER_PARAM_SERVICE)) {
+ ObjectMapper obj = new ObjectMapper();
+ String input = obj.writeValueAsString(params.get(USER_PARAM_SERVICE));
+ Service validate = obj.readValue(input, Service.class);
+ resourceList.add(
+ new Resource(WorkflowType.SERVICE, validate.getModelInfo().getModelVersionId(), false));
+ if (validate.getResources().getVnfs() != null) {
+ for (Vnfs vnf : validate.getResources().getVnfs()) {
+ resourceList.add(new Resource(WorkflowType.VNF,
+ vnf.getModelInfo().getModelCustomizationId(), false));
+ if (vnf.getModelInfo() != null && vnf.getModelInfo().getModelCustomizationUuid() != null) {
+ vnfCustomizationUUID = vnf.getModelInfo().getModelCustomizationUuid();
+ }
+ if (vnf.getVfModules() != null) {
+ for (VfModules vfModule : vnf.getVfModules()) {
+ VfModuleCustomization vfModuleCustomization =
+ catalogDbClient.getVfModuleCustomizationByModelCuztomizationUUID(
+ vfModule.getModelInfo().getModelCustomizationUuid());
+ if (vfModuleCustomization != null) {
+
+ if (vfModuleCustomization.getVfModule() != null
+ && vfModuleCustomization.getVfModule().getVolumeHeatTemplate() != null
+ && vfModuleCustomization.getVolumeHeatEnv() != null) {
+ resourceList.add(new Resource(WorkflowType.VOLUMEGROUP,
+ vfModuleCustomization.getModelCustomizationUUID(), false));
+ foundVfModuleOrVG = true;
+ }
+
+ if ((vfModuleCustomization.getVfModule() != null)
+ && ((vfModuleCustomization.getVfModule().getModuleHeatTemplate() != null
+ && vfModuleCustomization.getHeatEnvironment() != null))
+ || (vfModuleCustomization.getVfModule().getModelName() != null
+ && vfModuleCustomization.getVfModule().getModelName()
+ .contains("helm"))) {
+ foundVfModuleOrVG = true;
+ Resource resource = new Resource(WorkflowType.VFMODULE,
+ vfModuleCustomization.getModelCustomizationUUID(), false);
+ resource.setBaseVfModule(
+ vfModuleCustomization.getVfModule().getIsBase() != null
+ && vfModuleCustomization.getVfModule().getIsBase());
+ resourceList.add(resource);
+ if (vfModule.getModelInfo() != null
+ && vfModule.getModelInfo().getModelCustomizationUuid() != null) {
+ vfModuleCustomizationUUID =
+ vfModule.getModelInfo().getModelCustomizationUuid();
+ }
+ if (!vnfCustomizationUUID.isEmpty()
+ && !vfModuleCustomizationUUID.isEmpty()) {
+ List<CvnfcConfigurationCustomization> configs =
+ traverseCatalogDbForConfiguration(
+ validate.getModelInfo().getModelVersionId(),
+ vnfCustomizationUUID, vfModuleCustomizationUUID);
+ for (CvnfcConfigurationCustomization config : configs) {
+ Resource configResource = new Resource(WorkflowType.CONFIGURATION,
+ config.getConfigurationResource().getModelUUID(), false);
+ resource.setVnfCustomizationId(
+ vnf.getModelInfo().getModelCustomizationId());
+ resource.setVfModuleCustomizationId(
+ vfModule.getModelInfo().getModelCustomizationId());
+ resourceList.add(configResource);
+ }
+ }
+ }
+ if (!foundVfModuleOrVG) {
+ buildAndThrowException(execution,
+ "Could not determine if vfModule was a vfModule or volume group. Heat template and Heat env are null");
+ }
+ }
+ }
+ }
+ }
+ }
+ if (validate.getResources().getPnfs() != null) {
+ for (Pnfs pnf : validate.getResources().getPnfs()) {
+ resourceList.add(new Resource(WorkflowType.PNF,
+ pnf.getModelInfo().getModelCustomizationId(), false));
+ }
+ }
+ if (validate.getResources().getNetworks() != null) {
+ for (Networks network : validate.getResources().getNetworks()) {
+ resourceList.add(new Resource(WorkflowType.NETWORK,
+ network.getModelInfo().getModelCustomizationId(), false));
+ }
+ if (requestAction.equals(CREATE_INSTANCE)) {
+ String networkColCustId =
+ queryCatalogDbForNetworkCollection(execution, serviceModelVersionId);
+ if (networkColCustId != null) {
+ resourceList.add(new Resource(WorkflowType.NETWORKCOLLECTION, networkColCustId, false));
+ }
+ }
+ }
+ break;
+ }
+ }
+ }
+ return resourceList;
+ }
+
+
+ private List<CvnfcConfigurationCustomization> traverseCatalogDbForConfiguration(String serviceModelUUID,
+ String vnfCustomizationUUID, String vfModuleCustomizationUUID) {
+ List<CvnfcConfigurationCustomization> configurations = new ArrayList<>();
+ try {
+ List<CvnfcCustomization> cvnfcCustomizations = catalogDbClient.getCvnfcCustomization(serviceModelUUID,
+ vnfCustomizationUUID, vfModuleCustomizationUUID);
+ for (CvnfcCustomization cvnfc : cvnfcCustomizations) {
+ for (CvnfcConfigurationCustomization customization : cvnfc.getCvnfcConfigurationCustomization()) {
+ if (customization.getConfigurationResource().getToscaNodeType().contains(FABRIC_CONFIGURATION)) {
+ configurations.add(customization);
+ }
+ }
+ }
+ logger.debug("found {} fabric configuration(s)", configurations.size());
+ return configurations;
+ } catch (Exception ex) {
+ logger.error("Error in finding configurations", ex);
+ return configurations;
+ }
+ }
+
+ private String queryCatalogDbForNetworkCollection(DelegateExecution execution, String serviceModelVersionId) {
+ org.onap.so.db.catalog.beans.Service service = catalogDbClient.getServiceByID(serviceModelVersionId);
+ if (service != null) {
+ CollectionResourceCustomization networkCollection = this.findCatalogNetworkCollection(execution, service);
+ if (networkCollection != null) {
+ return networkCollection.getModelCustomizationUUID();
+ }
+ }
+ return null;
+ }
+
+ private CollectionResourceCustomization findCatalogNetworkCollection(DelegateExecution execution,
+ org.onap.so.db.catalog.beans.Service service) {
+ CollectionResourceCustomization networkCollection = null;
+ int count = 0;
+ for (CollectionResourceCustomization collectionCustom : service.getCollectionResourceCustomizations()) {
+ if (catalogDbClient.getNetworkCollectionResourceCustomizationByID(
+ collectionCustom.getModelCustomizationUUID()) != null) {
+ networkCollection = collectionCustom;
+ count++;
+ }
+ }
+ if (count == 0) {
+ return null;
+ } else if (count > 1) {
+ buildAndThrowException(execution,
+ "Found multiple Network Collections in the Service model, only one per Service is supported.");
+ }
+ return networkCollection;
+ }
+
+ private void buildAndThrowException(DelegateExecution execution, String msg) {
+ logger.error(msg);
+ execution.setVariable(WORKFLOW_ACTION_ERROR_MESSAGE, msg);
+ exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, msg);
+ }
+}
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 5d95f973bf..aad8b51a48 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
@@ -6,7 +6,7 @@
* ================================================================================
* Modifications Copyright (c) 2019 Samsung
* ================================================================================
- * Modifications Copyright (c) 2020 Nokia
+ * Modifications Copyright (c) 2021 Nokia
* ================================================================================
* Modifications Copyright (c) 2020 Tech Mahindra
* ================================================================================
@@ -26,27 +26,13 @@
package org.onap.so.bpmn.infrastructure.workflow.tasks;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
-import java.util.UUID;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-import java.util.stream.Collectors;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.lang3.SerializationUtils;
import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.javatuples.Pair;
-import org.onap.aai.domain.yang.GenericVnf;
-import org.onap.aai.domain.yang.GenericVnfs;
-import org.onap.aai.domain.yang.L3Network;
import org.onap.aai.domain.yang.Relationship;
import org.onap.aai.domain.yang.ServiceInstance;
-import org.onap.aai.domain.yang.ServiceInstances;
import org.onap.aai.domain.yang.Vnfc;
import org.onap.aai.domain.yang.VolumeGroup;
import org.onap.aai.domain.yang.VpnBinding;
@@ -62,22 +48,17 @@ import org.onap.so.bpmn.common.BBConstants;
import org.onap.so.bpmn.infrastructure.workflow.tasks.utils.WorkflowResourceIdsUtils;
import org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration;
import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
-import org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock;
import org.onap.so.bpmn.servicedecomposition.entities.ConfigurationResourceKeys;
import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock;
import org.onap.so.bpmn.servicedecomposition.entities.WorkflowResourceIds;
import org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetup;
import org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetupUtils;
-import org.onap.so.bpmn.servicedecomposition.tasks.exceptions.DuplicateNameException;
-import org.onap.so.bpmn.servicedecomposition.tasks.exceptions.MultipleObjectsFoundException;
import org.onap.so.client.exception.ExceptionBuilder;
import org.onap.so.client.orchestration.AAIConfigurationResources;
import org.onap.so.client.orchestration.AAIEntityNotFoundException;
import org.onap.so.db.catalog.beans.CollectionNetworkResourceCustomization;
import org.onap.so.db.catalog.beans.CollectionResourceCustomization;
import org.onap.so.db.catalog.beans.CollectionResourceInstanceGroupCustomization;
-import org.onap.so.db.catalog.beans.CvnfcConfigurationCustomization;
-import org.onap.so.db.catalog.beans.CvnfcCustomization;
import org.onap.so.db.catalog.beans.InstanceGroup;
import org.onap.so.db.catalog.beans.VfModuleCustomization;
import org.onap.so.db.catalog.beans.macro.NorthBoundRequest;
@@ -86,68 +67,56 @@ import org.onap.so.db.catalog.client.CatalogDbClient;
import org.onap.so.serviceinstancebeans.CloudConfiguration;
import org.onap.so.serviceinstancebeans.ModelInfo;
import org.onap.so.serviceinstancebeans.ModelType;
-import org.onap.so.serviceinstancebeans.Networks;
-import org.onap.so.serviceinstancebeans.Pnfs;
import org.onap.so.serviceinstancebeans.RelatedInstance;
import org.onap.so.serviceinstancebeans.RelatedInstanceList;
import org.onap.so.serviceinstancebeans.RequestDetails;
-import org.onap.so.serviceinstancebeans.Service;
import org.onap.so.serviceinstancebeans.ServiceInstancesRequest;
-import org.onap.so.serviceinstancebeans.VfModules;
-import org.onap.so.serviceinstancebeans.Vnfs;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.UUID;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.ASSIGNINSTANCE;
+import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.CONTROLLER;
+import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.CREATE_INSTANCE;
+import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.FABRIC_CONFIGURATION;
+import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.NETWORKCOLLECTION;
+import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.REPLACEINSTANCE;
+import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.REPLACEINSTANCERETAINASSIGNMENTS;
+import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.SERVICE;
+import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.USER_PARAM_SERVICE;
+import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.WORKFLOW_ACTION_ERROR_MESSAGE;
@Component
public class WorkflowAction {
- private static final String WORKFLOW_ACTION_ERROR_MESSAGE = "WorkflowActionErrorMessage";
+ private static final Logger logger = LoggerFactory.getLogger(WorkflowAction.class);
+
private static final String SERVICE_INSTANCES = "serviceInstances";
- private static final String SERVICE_INSTANCE = "serviceInstance";
private static final String VF_MODULES = "vfModules";
- private static final String WORKFLOW_ACTION_WAS_UNABLE_TO_VERIFY_IF_THE_INSTANCE_NAME_ALREADY_EXIST_IN_AAI =
- "WorkflowAction was unable to verify if the instance name already exist in AAI.";
private static final String VNF_TYPE = "vnfType";
- private static final String SERVICE = "Service";
- private static final String VNF = "Vnf";
- private static final String PNF = "Pnf";
- private static final String VFMODULE = "VfModule";
- private static final String VOLUMEGROUP = "VolumeGroup";
- private static final String NETWORK = "Network";
- private static final String NETWORKCOLLECTION = "NetworkCollection";
private static final String CONFIGURATION = "Configuration";
- private static final String ASSIGNINSTANCE = "assignInstance";
- private static final String CREATEINSTANCE = "createInstance";
- private static final String REPLACEINSTANCE = "replaceInstance";
- private static final String REPLACEINSTANCERETAINASSIGNMENTS = "replaceInstanceRetainAssignments";
- private static final String USERPARAMSERVICE = "service";
private static final String SUPPORTEDTYPES =
"vnfs|vfModules|networks|networkCollections|volumeGroups|serviceInstances|instanceGroups";
private static final String HOMINGSOLUTION = "Homing_Solution";
- private static final String FABRIC_CONFIGURATION = "FabricConfiguration";
private static final String SERVICE_TYPE_TRANSPORT = "TRANSPORT";
private static final String SERVICE_TYPE_BONDING = "BONDING";
private static final String CLOUD_OWNER = "DEFAULT";
- private static final Logger logger = LoggerFactory.getLogger(WorkflowAction.class);
- private static final String NAME_EXISTS_WITH_DIFF_VERSION_ID = "(%s) and different version id (%s)";
- private static final String NAME_EXISTS_MULTIPLE =
- "(%s) and multiple combination of model-version-id + service-type + global-customer-id";
- private static final String NAME_EXISTS_WITH_DIFF_COMBINATION =
- "(%s) and global-customer-id (%s), service-type (%s), model-version-id (%s)";
- private static final String NAME_EXISTS_WITH_DIFF_CUSTOMIZATION_ID =
- "(%s), same parent and different customization id (%s)";
- private static final String NAME_EXISTS_WITH_DIFF_PARENT = "(%s) id (%s) and different parent relationship";
private static final String CREATENETWORKBB = "CreateNetworkBB";
private static final String ACTIVATENETWORKBB = "ActivateNetworkBB";
private static final String VOLUMEGROUP_DELETE_PATTERN = "(Un|De)(.*)Volume(.*)";
private static final String VOLUMEGROUP_CREATE_PATTERN = "(A|C)(.*)Volume(.*)";
- private static final String CONTROLLER = "Controller";
private static final String DEFAULT_CLOUD_OWNER = "org.onap.so.cloud-owner";
private static final String HOMING = "homing";
@@ -167,6 +136,12 @@ public class WorkflowAction {
private VrfValidation vrfValidation;
@Autowired
private Environment environment;
+ @Autowired
+ private UserParamsServiceTraversal userParamsServiceTraversal;
+ @Autowired
+ private AaiResourceIdValidator aaiResourceIdValidator;
+ @Autowired
+ private ExecuteBuildingBlockBuilder executeBuildingBlockBuilder;
public void setBbInputSetupUtils(BBInputSetupUtils bbInputSetupUtils) {
this.bbInputSetupUtils = bbInputSetupUtils;
@@ -238,7 +213,7 @@ public class WorkflowAction {
requestDetails, requestAction, resourceId, flowsToExecute, vnfType, orchFlows,
apiVersion, resourceKey, replaceInfo);
} else {
- if (isConfiguration(orchFlows) && !requestAction.equalsIgnoreCase(CREATEINSTANCE)) {
+ if (isConfiguration(orchFlows) && !requestAction.equalsIgnoreCase(CREATE_INSTANCE)) {
addConfigBuildingBlocksToFlowsToExecuteList(execution, sIRequest, requestId,
workflowResourceIds, requestDetails, requestAction, resourceId, flowsToExecute,
vnfType, apiVersion, resourceKey, replaceInfo, orchFlows);
@@ -248,43 +223,48 @@ public class WorkflowAction {
.collect(Collectors.toList());
for (OrchestrationFlow orchFlow : orchFlows) {
- ExecuteBuildingBlock ebb = buildExecuteBuildingBlock(orchFlow, requestId, resourceKey,
- apiVersion, resourceId, requestAction, true, vnfType, workflowResourceIds,
- requestDetails, false, null, null, false, replaceInfo);
+ ExecuteBuildingBlock ebb = executeBuildingBlockBuilder.buildExecuteBuildingBlock(orchFlow,
+ requestId, resourceKey, apiVersion, resourceId, requestAction, true, vnfType,
+ workflowResourceIds, requestDetails, false, null, null, false, replaceInfo);
flowsToExecute.add(ebb);
}
}
} else {
- boolean foundRelated = false;
boolean containsService = false;
List<Resource> resourceList = new ArrayList<>();
List<Pair<WorkflowType, String>> aaiResourceIds = new ArrayList<>();
+ List<Map<String, Object>> userParams =
+ sIRequest.getRequestDetails().getRequestParameters().getUserParams();
if (resourceType == WorkflowType.SERVICE && requestAction.equalsIgnoreCase(ASSIGNINSTANCE)) {
// SERVICE-MACRO-ASSIGN will always get user params with a
// service.
- if (sIRequest.getRequestDetails().getRequestParameters().getUserParams() != null) {
+
+ if (userParams != null) {
containsService = isContainsService(sIRequest);
if (containsService) {
- traverseUserParamsService(execution, resourceList, sIRequest, requestAction);
+ resourceList = userParamsServiceTraversal.getResourceListFromUserParams(execution,
+ userParams, serviceInstanceId, requestAction);
}
} else {
buildAndThrowException(execution,
"Service-Macro-Assign request details must contain user params with a service");
}
- } else if (resourceType == WorkflowType.SERVICE && requestAction.equalsIgnoreCase(CREATEINSTANCE)) {
+ } else if (resourceType == WorkflowType.SERVICE
+ && requestAction.equalsIgnoreCase(CREATE_INSTANCE)) {
// SERVICE-MACRO-CREATE will get user params with a service,
// a service with a network, a service with a
- // networkcollection, OR an empty service.
+ // network collection, OR an empty service.
// If user params is just a service or null and macro
// queries the SI and finds a VNF, macro fails.
- if (sIRequest.getRequestDetails().getRequestParameters().getUserParams() != null) {
+ if (userParams != null) {
containsService = isContainsService(sIRequest);
}
if (containsService) {
- foundRelated = traverseUserParamsService(execution, resourceList, sIRequest, requestAction);
+ resourceList = userParamsServiceTraversal.getResourceListFromUserParams(execution,
+ userParams, serviceInstanceId, requestAction);
}
- if (!foundRelated) {
+ if (!foundRelated(resourceList)) {
traverseCatalogDbService(execution, sIRequest, resourceList, aaiResourceIds);
}
} else if (resourceType == WorkflowType.SERVICE
@@ -327,21 +307,22 @@ public class WorkflowAction {
|| REPLACEINSTANCERETAINASSIGNMENTS.equalsIgnoreCase(requestAction))) {
vnfReplace = true;
}
- flowsToExecute = buildExecuteBuildingBlockList(orchFlows, resourceList, requestId, apiVersion,
- resourceId, requestAction, vnfType, workflowResourceIds, requestDetails, vnfReplace);
+ flowsToExecute = executeBuildingBlockBuilder.buildExecuteBuildingBlockList(orchFlows, resourceList,
+ requestId, apiVersion, resourceId, requestAction, vnfType, workflowResourceIds,
+ requestDetails, vnfReplace);
if (isNetworkCollectionInTheResourceList(resourceList)) {
logger.info("Sorting for Vlan Tagging");
flowsToExecute = sortExecutionPathByObjectForVlanTagging(flowsToExecute, requestAction);
}
- // By default, enable homing at VNF level for CREATEINSTANCE and ASSIGNINSTANCE
+ // By default, enable homing at VNF level for CREATE_INSTANCE and ASSIGNINSTANCE
if (resourceType == WorkflowType.SERVICE
- && (requestAction.equals(CREATEINSTANCE) || requestAction.equals(ASSIGNINSTANCE))
+ && (requestAction.equals(CREATE_INSTANCE) || requestAction.equals(ASSIGNINSTANCE))
&& resourceList.stream().anyMatch(x -> WorkflowType.VNF.equals(x.getResourceType()))) {
execution.setVariable(HOMING, true);
execution.setVariable("calledHoming", false);
}
if (resourceType == WorkflowType.SERVICE && (requestAction.equalsIgnoreCase(ASSIGNINSTANCE)
- || requestAction.equalsIgnoreCase(CREATEINSTANCE))) {
+ || requestAction.equalsIgnoreCase(CREATE_INSTANCE))) {
generateResourceIds(flowsToExecute, resourceList, serviceInstanceId);
} else {
updateResourceIdsFromAAITraversal(flowsToExecute, resourceList, aaiResourceIds,
@@ -351,9 +332,8 @@ public class WorkflowAction {
}
// If the user set "Homing_Solution" to "none", disable homing, else if "Homing_Solution" is specified,
// enable it.
- if (sIRequest.getRequestDetails().getRequestParameters() != null
- && sIRequest.getRequestDetails().getRequestParameters().getUserParams() != null) {
- List<Map<String, Object>> userParams = getListOfUserParams(sIRequest);
+ List<Map<String, Object>> userParams = sIRequest.getRequestDetails().getRequestParameters().getUserParams();
+ if (sIRequest.getRequestDetails().getRequestParameters() != null && userParams != null) {
for (Map<String, Object> params : userParams) {
if (params.containsKey(HOMINGSOLUTION)) {
execution.setVariable(HOMING, !"none".equals(params.get(HOMINGSOLUTION)));
@@ -400,14 +380,12 @@ public class WorkflowAction {
private boolean isContainsService(ServiceInstancesRequest sIRequest) {
boolean containsService;
- List<Map<String, Object>> userParams = getListOfUserParams(sIRequest);
- containsService = userParams.stream().anyMatch(param -> param.containsKey(USERPARAMSERVICE));
+ List<Map<String, Object>> userParams = sIRequest.getRequestDetails().getRequestParameters().getUserParams();
+ containsService = userParams.stream().anyMatch(param -> param.containsKey(USER_PARAM_SERVICE));
return containsService;
}
- private List<Map<String, Object>> getListOfUserParams(ServiceInstancesRequest sIRequest) {
- return sIRequest.getRequestDetails().getRequestParameters().getUserParams();
- }
+
private List<ExecuteBuildingBlock> loadExecuteBuildingBlocks(DelegateExecution execution, String requestId,
String errorMessage) {
@@ -446,9 +424,9 @@ public class WorkflowAction {
requestDetails, requestAction, resourceId, flowsToExecute, vnfType, apiVersion, resourceKey,
replaceInfo, configOrchFlows);
} else {
- ExecuteBuildingBlock ebb = buildExecuteBuildingBlock(orchFlow, requestId, resourceKey, apiVersion,
- resourceId, requestAction, true, vnfType, workflowResourceIds, requestDetails, false, null,
- null, false, replaceInfo);
+ ExecuteBuildingBlock ebb = executeBuildingBlockBuilder.buildExecuteBuildingBlock(orchFlow, requestId,
+ resourceKey, apiVersion, resourceId, requestAction, true, vnfType, workflowResourceIds,
+ requestDetails, false, null, null, false, replaceInfo);
flowsToExecute.add(ebb);
}
}
@@ -596,35 +574,50 @@ public class WorkflowAction {
}
workflowIdsCopy.setConfigurationId(configuration.getConfigurationId());
for (OrchestrationFlow orchFlow : result) {
- if (!isReplace) {
- dataObj.getResourceKey().setVfModuleCustomizationId(vfModuleCustomizationUUID);
- dataObj.getResourceKey().setVnfCustomizationId(vnfCustomizationUUID);
- } else {
- if (orchFlow.getFlowName().contains("Delete")) {
+ if (!isReplace || (isReplace && (orchFlow.getFlowName().contains("Delete")))) {
+ if (!isReplace) {
dataObj.getResourceKey().setVfModuleCustomizationId(vfModuleCustomizationUUID);
dataObj.getResourceKey().setVnfCustomizationId(vnfCustomizationUUID);
} else {
- dataObj.getResourceKey().setVfModuleCustomizationId(replaceVfModuleCustomizationUUID);
- dataObj.getResourceKey().setVnfCustomizationId(replaceVnfModuleCustomizationUUID);
+ if (orchFlow.getFlowName().contains("Delete")) {
+ dataObj.getResourceKey().setVfModuleCustomizationId(vfModuleCustomizationUUID);
+ dataObj.getResourceKey().setVnfCustomizationId(vnfCustomizationUUID);
+ } else {
+ dataObj.getResourceKey().setVfModuleCustomizationId(replaceVfModuleCustomizationUUID);
+ dataObj.getResourceKey().setVnfCustomizationId(replaceVnfModuleCustomizationUUID);
+ }
}
+ dataObj.getResourceKey().setCvnfModuleCustomizationId(vnfc.getModelCustomizationId());
+ String vnfcName = vnfc.getVnfcName();
+ if (vnfcName == null || vnfcName.isEmpty()) {
+ buildAndThrowException(dataObj.getExecution(), "Exception in create execution list "
+ + ": VnfcName does not exist or is null while there is a configuration for the vfModule",
+ new Exception("Vnfc and Configuration do not match"));
+ }
+ ExecuteBuildingBlock ebb =
+ executeBuildingBlockBuilder.buildExecuteBuildingBlock(orchFlow, dataObj.getRequestId(),
+ dataObj.getResourceKey(), dataObj.getApiVersion(), dataObj.getResourceId(),
+ dataObj.getRequestAction(), dataObj.isaLaCarte(), dataObj.getVnfType(),
+ workflowIdsCopy, dataObj.getRequestDetails(), false, null, vnfcName, true, null);
+ flowsToExecuteConfigs.add(ebb);
}
- dataObj.getResourceKey().setCvnfModuleCustomizationId(vnfc.getModelCustomizationId());
- String vnfcName = vnfc.getVnfcName();
- if (vnfcName == null || vnfcName.isEmpty()) {
- buildAndThrowException(dataObj.getExecution(), "Exception in create execution list "
- + ": VnfcName does not exist or is null while there is a configuration for the vfModule",
- new Exception("Vnfc and Configuration do not match"));
- }
- ExecuteBuildingBlock ebb = buildExecuteBuildingBlock(orchFlow, dataObj.getRequestId(),
- dataObj.getResourceKey(), dataObj.getApiVersion(), dataObj.getResourceId(),
- dataObj.getRequestAction(), dataObj.isaLaCarte(), dataObj.getVnfType(), workflowIdsCopy,
- dataObj.getRequestDetails(), false, null, vnfcName, true, null);
- flowsToExecuteConfigs.add(ebb);
}
}
return flowsToExecuteConfigs;
}
+ protected void buildAndThrowException(DelegateExecution execution, String msg) {
+ logger.error(msg);
+ execution.setVariable(WORKFLOW_ACTION_ERROR_MESSAGE, msg);
+ exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, msg);
+ }
+
+ protected void buildAndThrowException(DelegateExecution execution, String msg, Exception ex) {
+ logger.error(msg, ex);
+ execution.setVariable(WORKFLOW_ACTION_ERROR_MESSAGE, msg + ex.getMessage());
+ exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, msg + ex.getMessage());
+ }
+
protected List<OrchestrationFlow> getVfModuleReplaceBuildingBlocks(ConfigBuildingBlocksDataObject dataObj)
throws Exception {
@@ -687,29 +680,7 @@ public class WorkflowAction {
return orchFlows;
}
- protected List<Resource> sortVfModulesByBaseFirst(List<Resource> vfModuleResources) {
- int count = 0;
- for (Resource resource : vfModuleResources) {
- if (resource.isBaseVfModule()) {
- Collections.swap(vfModuleResources, 0, count);
- break;
- }
- count++;
- }
- return vfModuleResources;
- }
- protected List<Resource> sortVfModulesByBaseLast(List<Resource> vfModuleResources) {
- int count = 0;
- for (Resource resource : vfModuleResources) {
- if (resource.isBaseVfModule()) {
- Collections.swap(vfModuleResources, vfModuleResources.size() - 1, count);
- break;
- }
- count++;
- }
- return vfModuleResources;
- }
private void updateResourceIdsFromAAITraversal(List<ExecuteBuildingBlock> flowsToExecute,
List<Resource> resourceList, List<Pair<WorkflowType, String>> aaiResourceIds, String serviceInstanceId) {
@@ -1214,150 +1185,6 @@ public class WorkflowAction {
}
}
- protected boolean traverseUserParamsService(DelegateExecution execution, List<Resource> resourceList,
- ServiceInstancesRequest sIRequest, String requestAction) throws IOException {
- boolean foundRelated = false;
- boolean foundVfModuleOrVG = false;
- String vnfCustomizationUUID = "";
- String vfModuleCustomizationUUID = "";
- if (sIRequest.getRequestDetails().getRequestParameters().getUserParams() != null) {
- List<Map<String, Object>> userParams = getListOfUserParams(sIRequest);
- for (Map<String, Object> params : userParams) {
- if (params.containsKey(USERPARAMSERVICE)) {
- ObjectMapper obj = new ObjectMapper();
- String input = obj.writeValueAsString(params.get(USERPARAMSERVICE));
- Service validate = obj.readValue(input, Service.class);
- resourceList.add(
- new Resource(WorkflowType.SERVICE, validate.getModelInfo().getModelVersionId(), false));
- if (validate.getResources().getVnfs() != null) {
- for (Vnfs vnf : validate.getResources().getVnfs()) {
- resourceList.add(new Resource(WorkflowType.VNF,
- vnf.getModelInfo().getModelCustomizationId(), false));
- foundRelated = true;
- if (vnf.getModelInfo() != null && vnf.getModelInfo().getModelCustomizationUuid() != null) {
- vnfCustomizationUUID = vnf.getModelInfo().getModelCustomizationUuid();
- }
- if (vnf.getVfModules() != null) {
- for (VfModules vfModule : vnf.getVfModules()) {
- VfModuleCustomization vfModuleCustomization =
- catalogDbClient.getVfModuleCustomizationByModelCuztomizationUUID(
- vfModule.getModelInfo().getModelCustomizationUuid());
- if (vfModuleCustomization != null) {
-
- if (vfModuleCustomization.getVfModule() != null
- && vfModuleCustomization.getVfModule().getVolumeHeatTemplate() != null
- && vfModuleCustomization.getVolumeHeatEnv() != null) {
- resourceList.add(new Resource(WorkflowType.VOLUMEGROUP,
- vfModuleCustomization.getModelCustomizationUUID(), false));
- foundVfModuleOrVG = true;
- }
-
- if ((vfModuleCustomization.getVfModule() != null)
- && ((vfModuleCustomization.getVfModule().getModuleHeatTemplate() != null
- && vfModuleCustomization.getHeatEnvironment() != null))
- || (vfModuleCustomization.getVfModule().getModelName() != null
- && vfModuleCustomization.getVfModule().getModelName()
- .contains("helm"))) {
- foundVfModuleOrVG = true;
- Resource resource = new Resource(WorkflowType.VFMODULE,
- vfModuleCustomization.getModelCustomizationUUID(), false);
- resource.setBaseVfModule(
- vfModuleCustomization.getVfModule().getIsBase() != null
- && vfModuleCustomization.getVfModule().getIsBase());
- resourceList.add(resource);
- if (vfModule.getModelInfo() != null
- && vfModule.getModelInfo().getModelCustomizationUuid() != null) {
- vfModuleCustomizationUUID =
- vfModule.getModelInfo().getModelCustomizationUuid();
- }
- if (!vnfCustomizationUUID.isEmpty()
- && !vfModuleCustomizationUUID.isEmpty()) {
- List<CvnfcConfigurationCustomization> configs =
- traverseCatalogDbForConfiguration(
- validate.getModelInfo().getModelVersionId(),
- vnfCustomizationUUID, vfModuleCustomizationUUID);
- for (CvnfcConfigurationCustomization config : configs) {
- Resource configResource = new Resource(WorkflowType.CONFIGURATION,
- config.getConfigurationResource().getModelUUID(), false);
- resource.setVnfCustomizationId(
- vnf.getModelInfo().getModelCustomizationId());
- resource.setVfModuleCustomizationId(
- vfModule.getModelInfo().getModelCustomizationId());
- resourceList.add(configResource);
- }
- }
- }
- if (!foundVfModuleOrVG) {
- buildAndThrowException(execution,
- "Could not determine if vfModule was a vfModule or volume group. Heat template and Heat env are null");
- }
- }
- }
- }
- }
- }
- if (validate.getResources().getPnfs() != null) {
- for (Pnfs pnf : validate.getResources().getPnfs()) {
- resourceList.add(new Resource(WorkflowType.PNF,
- pnf.getModelInfo().getModelCustomizationId(), false));
- foundRelated = true;
- }
- }
- if (validate.getResources().getNetworks() != null) {
- for (Networks network : validate.getResources().getNetworks()) {
- resourceList.add(new Resource(WorkflowType.NETWORK,
- network.getModelInfo().getModelCustomizationId(), false));
- foundRelated = true;
- }
- if (requestAction.equals(CREATEINSTANCE)) {
- String networkColCustId = queryCatalogDBforNetworkCollection(execution, sIRequest);
- if (networkColCustId != null) {
- resourceList.add(new Resource(WorkflowType.NETWORKCOLLECTION, networkColCustId, false));
- foundRelated = true;
- }
- }
- }
- break;
- }
- }
- }
- return foundRelated;
- }
-
- protected List<CvnfcConfigurationCustomization> traverseCatalogDbForConfiguration(String serviceModelUUID,
- String vnfCustomizationUUID, String vfModuleCustomizationUUID) {
- List<CvnfcConfigurationCustomization> configurations = new ArrayList<>();
- try {
- List<CvnfcCustomization> cvnfcCustomizations = catalogDbClient.getCvnfcCustomization(serviceModelUUID,
- vnfCustomizationUUID, vfModuleCustomizationUUID);
- for (CvnfcCustomization cvnfc : cvnfcCustomizations) {
- for (CvnfcConfigurationCustomization customization : cvnfc.getCvnfcConfigurationCustomization()) {
- if (customization.getConfigurationResource().getToscaNodeType().contains(FABRIC_CONFIGURATION)) {
- configurations.add(customization);
- }
- }
- }
- logger.debug("found {} fabric configuration(s)", configurations.size());
- return configurations;
- } catch (Exception ex) {
- logger.error("Error in finding configurations", ex);
- return configurations;
- }
- }
-
- protected String queryCatalogDBforNetworkCollection(DelegateExecution execution,
- ServiceInstancesRequest sIRequest) {
- org.onap.so.db.catalog.beans.Service service =
- catalogDbClient.getServiceByID(sIRequest.getRequestDetails().getModelInfo().getModelVersionId());
- if (service != null) {
- CollectionResourceCustomization networkCollection = this.findCatalogNetworkCollection(execution, service);
- if (networkCollection != null) {
- return networkCollection.getModelCustomizationUUID();
- }
- }
- return null;
- }
-
protected WorkflowResourceIds populateResourceIdsFromApiHandler(DelegateExecution execution) {
return WorkflowResourceIdsUtils.getWorkflowResourceIdsFromExecution(execution);
}
@@ -1397,36 +1224,6 @@ public class WorkflowAction {
}
}
- protected String validateResourceIdInAAI(String generatedResourceId, WorkflowType type, String instanceName,
- RequestDetails reqDetails, WorkflowResourceIds workflowResourceIds) throws Exception {
- try {
- if ("SERVICE".equalsIgnoreCase(type.toString())) {
- return validateServiceResourceIdInAAI(generatedResourceId, instanceName, reqDetails);
- } else if ("NETWORK".equalsIgnoreCase(type.toString())) {
- return validateNetworkResourceIdInAAI(generatedResourceId, instanceName, reqDetails,
- workflowResourceIds);
- } else if ("VNF".equalsIgnoreCase(type.toString())) {
- return validateVnfResourceIdInAAI(generatedResourceId, instanceName, reqDetails, workflowResourceIds);
- } else if ("VFMODULE".equalsIgnoreCase(type.toString())) {
- return validateVfModuleResourceIdInAAI(generatedResourceId, instanceName, reqDetails,
- workflowResourceIds);
- } else if ("VOLUMEGROUP".equalsIgnoreCase(type.toString())) {
- return validateVolumeGroupResourceIdInAAI(generatedResourceId, instanceName, reqDetails,
- workflowResourceIds);
- } else if ("CONFIGURATION".equalsIgnoreCase(type.toString())) {
- return validateConfigurationResourceIdInAAI(generatedResourceId, instanceName, reqDetails,
- workflowResourceIds);
- }
- return generatedResourceId;
- } catch (DuplicateNameException dne) {
- throw dne;
- } catch (Exception ex) {
- logger.error(WORKFLOW_ACTION_WAS_UNABLE_TO_VERIFY_IF_THE_INSTANCE_NAME_ALREADY_EXIST_IN_AAI, ex);
- throw new IllegalStateException(
- WORKFLOW_ACTION_WAS_UNABLE_TO_VERIFY_IF_THE_INSTANCE_NAME_ALREADY_EXIST_IN_AAI);
- }
- }
-
protected String convertTypeFromPlural(String type) {
if (!type.matches(SUPPORTEDTYPES)) {
return type;
@@ -1442,7 +1239,7 @@ public class WorkflowAction {
protected List<ExecuteBuildingBlock> sortExecutionPathByObjectForVlanTagging(List<ExecuteBuildingBlock> orchFlows,
String requestAction) {
List<ExecuteBuildingBlock> sortedOrchFlows = new ArrayList<>();
- if (requestAction.equals(CREATEINSTANCE)) {
+ if (requestAction.equals(CREATE_INSTANCE)) {
for (ExecuteBuildingBlock ebb : orchFlows) {
if (ebb.getBuildingBlock().getBpmnFlowName().equals("AssignNetworkBB")) {
String key = ebb.getBuildingBlock().getKey();
@@ -1510,125 +1307,6 @@ public class WorkflowAction {
return sortedOrchFlows;
}
- private void addBuildingBlockToExecuteBBList(List<ExecuteBuildingBlock> flowsToExecute, List<Resource> resourceList,
- WorkflowType workflowType, OrchestrationFlow orchFlow, String requestId, String apiVersion,
- String resourceId, String requestAction, String vnfType, WorkflowResourceIds workflowResourceIds,
- RequestDetails requestDetails, boolean isVirtualLink, boolean isConfiguration) {
-
- resourceList.stream().filter(resource -> resource.getResourceType().equals(workflowType))
- .forEach(resource -> flowsToExecute.add(buildExecuteBuildingBlock(orchFlow, requestId, resource,
- apiVersion, resourceId, requestAction, false, vnfType, workflowResourceIds, requestDetails,
- isVirtualLink, resource.getVirtualLinkKey(), null, isConfiguration, null)));
- }
-
- protected List<ExecuteBuildingBlock> buildExecuteBuildingBlockList(List<OrchestrationFlow> orchFlows,
- List<Resource> resourceList, String requestId, String apiVersion, String resourceId, String requestAction,
- String vnfType, WorkflowResourceIds workflowResourceIds, RequestDetails requestDetails,
- boolean replaceVnf) {
- List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
- for (OrchestrationFlow orchFlow : orchFlows) {
- if (orchFlow.getFlowName().contains(SERVICE)) {
- if (!replaceVnf) {
- workflowResourceIds.setServiceInstanceId(resourceId);
- }
- addBuildingBlockToExecuteBBList(flowsToExecute, resourceList, WorkflowType.SERVICE, orchFlow, requestId,
- apiVersion, resourceId, requestAction, vnfType, workflowResourceIds, requestDetails, false,
- false);
- } else if (orchFlow.getFlowName().contains(VNF) || (orchFlow.getFlowName().contains(CONTROLLER)
- && (VNF).equalsIgnoreCase(orchFlow.getBpmnScope()))) {
- addBuildingBlockToExecuteBBList(flowsToExecute, resourceList, WorkflowType.VNF, orchFlow, requestId,
- apiVersion, resourceId, requestAction, vnfType, workflowResourceIds, requestDetails, false,
- false);
- } else if (orchFlow.getFlowName().contains(PNF) || (orchFlow.getFlowName().contains(CONTROLLER)
- && (PNF).equalsIgnoreCase(orchFlow.getBpmnScope()))) {
- addBuildingBlockToExecuteBBList(flowsToExecute, resourceList, WorkflowType.PNF, orchFlow, requestId,
- apiVersion, resourceId, requestAction, vnfType, workflowResourceIds, requestDetails, false,
- false);
- } else if (orchFlow.getFlowName().contains(NETWORK)
- && !orchFlow.getFlowName().contains(NETWORKCOLLECTION)) {
- addBuildingBlockToExecuteBBList(flowsToExecute, resourceList, WorkflowType.NETWORK, orchFlow, requestId,
- apiVersion, resourceId, requestAction, vnfType, workflowResourceIds, requestDetails, false,
- false);
- addBuildingBlockToExecuteBBList(flowsToExecute, resourceList, WorkflowType.VIRTUAL_LINK, orchFlow,
- requestId, apiVersion, resourceId, requestAction, vnfType, workflowResourceIds, requestDetails,
- true, false);
- } else if (orchFlow.getFlowName().contains(VFMODULE) || (orchFlow.getFlowName().contains(CONTROLLER)
- && (VFMODULE).equalsIgnoreCase(orchFlow.getBpmnScope()))) {
- List<Resource> vfModuleResourcesSorted;
- if (requestAction.equals(CREATEINSTANCE) || requestAction.equals(ASSIGNINSTANCE)
- || requestAction.equals("activateInstance")) {
- vfModuleResourcesSorted = sortVfModulesByBaseFirst(resourceList.stream()
- .filter(x -> WorkflowType.VFMODULE == x.getResourceType()).collect(Collectors.toList()));
- } else {
- vfModuleResourcesSorted = sortVfModulesByBaseLast(resourceList.stream()
- .filter(x -> WorkflowType.VFMODULE == x.getResourceType()).collect(Collectors.toList()));
- }
- for (Resource resource : vfModuleResourcesSorted) {
- flowsToExecute.add(buildExecuteBuildingBlock(orchFlow, requestId, resource, apiVersion, resourceId,
- requestAction, false, vnfType, workflowResourceIds, requestDetails, false, null, null,
- false, null));
- }
- } else if (orchFlow.getFlowName().contains(VOLUMEGROUP)) {
- if (requestAction.equalsIgnoreCase(REPLACEINSTANCE)
- || requestAction.equalsIgnoreCase(REPLACEINSTANCERETAINASSIGNMENTS)) {
- logger.debug("Replacing workflow resource id by volume group id");
- resourceId = workflowResourceIds.getVolumeGroupId();
- }
- addBuildingBlockToExecuteBBList(flowsToExecute, resourceList, WorkflowType.VOLUMEGROUP, orchFlow,
- requestId, apiVersion, resourceId, requestAction, vnfType, workflowResourceIds, requestDetails,
- false, false);
- } else if (orchFlow.getFlowName().contains(NETWORKCOLLECTION)) {
- addBuildingBlockToExecuteBBList(flowsToExecute, resourceList, WorkflowType.NETWORKCOLLECTION, orchFlow,
- requestId, apiVersion, resourceId, requestAction, vnfType, workflowResourceIds, requestDetails,
- false, false);
- } else if (orchFlow.getFlowName().contains(CONFIGURATION)) {
- addBuildingBlockToExecuteBBList(flowsToExecute, resourceList, WorkflowType.CONFIGURATION, orchFlow,
- requestId, apiVersion, resourceId, requestAction, vnfType, workflowResourceIds, requestDetails,
- false, true);
- } else {
- flowsToExecute
- .add(buildExecuteBuildingBlock(orchFlow, requestId, null, apiVersion, resourceId, requestAction,
- false, vnfType, workflowResourceIds, requestDetails, false, null, null, false, null));
- }
- }
- return flowsToExecute;
- }
-
- protected ExecuteBuildingBlock buildExecuteBuildingBlock(OrchestrationFlow orchFlow, String requestId,
- Resource resource, String apiVersion, String resourceId, String requestAction, boolean aLaCarte,
- String vnfType, WorkflowResourceIds workflowResourceIds, RequestDetails requestDetails,
- boolean isVirtualLink, String virtualLinkKey, String vnfcName, boolean isConfiguration,
- ReplaceInstanceRelatedInformation replaceInfo) {
-
- BuildingBlock buildingBlock =
- new BuildingBlock().setBpmnFlowName(orchFlow.getFlowName()).setMsoId(UUID.randomUUID().toString())
- .setIsVirtualLink(isVirtualLink).setVirtualLinkKey(virtualLinkKey)
- .setKey(Optional.ofNullable(resource).map(Resource::getResourceId).orElse(""));
- Optional.ofNullable(orchFlow.getBpmnAction()).ifPresent(buildingBlock::setBpmnAction);
- Optional.ofNullable(orchFlow.getBpmnScope()).ifPresent(buildingBlock::setBpmnScope);
- String oldVolumeGroupName = "";
- if (replaceInfo != null) {
- oldVolumeGroupName = replaceInfo.getOldVolumeGroupName();
- }
- if (resource != null
- && (orchFlow.getFlowName().contains(VOLUMEGROUP) && (requestAction.equalsIgnoreCase(REPLACEINSTANCE)
- || requestAction.equalsIgnoreCase(REPLACEINSTANCERETAINASSIGNMENTS)))) {
- logger.debug("Setting resourceId to volume group id for volume group flow on replace");
- resourceId = workflowResourceIds.getVolumeGroupId();
- }
-
- ExecuteBuildingBlock executeBuildingBlock = new ExecuteBuildingBlock().setApiVersion(apiVersion)
- .setaLaCarte(aLaCarte).setRequestAction(requestAction).setResourceId(resourceId).setVnfType(vnfType)
- .setWorkflowResourceIds(workflowResourceIds).setRequestId(requestId).setBuildingBlock(buildingBlock)
- .setRequestDetails(requestDetails).setOldVolumeGroupName(oldVolumeGroupName);
-
- if (resource != null && (isConfiguration || resource.getResourceType().equals(WorkflowType.CONFIGURATION))) {
- ConfigurationResourceKeys configurationResourceKeys = getConfigurationResourceKeys(resource, vnfcName);
- executeBuildingBlock.setConfigurationResourceKeys(configurationResourceKeys);
- }
- return executeBuildingBlock;
- }
-
private ConfigurationResourceKeys getConfigurationResourceKeys(Resource resource, String vnfcName) {
ConfigurationResourceKeys configurationResourceKeys = new ConfigurationResourceKeys();
Optional.ofNullable(vnfcName).ifPresent(configurationResourceKeys::setVnfcName);
@@ -1686,18 +1364,6 @@ public class WorkflowAction {
return listToExecute;
}
- protected void buildAndThrowException(DelegateExecution execution, String msg, Exception ex) {
- logger.error(msg, ex);
- execution.setVariable(WORKFLOW_ACTION_ERROR_MESSAGE, msg + ex.getMessage());
- exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, msg + ex.getMessage());
- }
-
- protected void buildAndThrowException(DelegateExecution execution, String msg) {
- logger.error(msg);
- execution.setVariable(WORKFLOW_ACTION_ERROR_MESSAGE, msg);
- exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, msg);
- }
-
public void handleRuntimeException(DelegateExecution execution) {
StringBuilder wfeExpMsg = new StringBuilder("Runtime error ");
String runtimeErrorMessage;
@@ -1724,155 +1390,20 @@ public class WorkflowAction {
protected boolean isRequestMacroServiceResume(boolean aLaCarte, WorkflowType resourceType, String requestAction,
String serviceInstanceId) {
return (!aLaCarte && resourceType == WorkflowType.SERVICE
- && (requestAction.equalsIgnoreCase(ASSIGNINSTANCE) || requestAction.equalsIgnoreCase(CREATEINSTANCE))
+ && (requestAction.equalsIgnoreCase(ASSIGNINSTANCE) || requestAction.equalsIgnoreCase(CREATE_INSTANCE))
&& (serviceInstanceId != null && serviceInstanceId.trim().length() > 1)
&& (bbInputSetupUtils.getAAIServiceInstanceById(serviceInstanceId) != null));
}
- protected String validateServiceResourceIdInAAI(String generatedResourceId, String instanceName,
- RequestDetails reqDetails) throws DuplicateNameException {
- String globalCustomerId = reqDetails.getSubscriberInfo().getGlobalSubscriberId();
- String serviceType = reqDetails.getRequestParameters().getSubscriptionServiceType();
- if (instanceName != null) {
- Optional<ServiceInstance> serviceInstanceAAI =
- bbInputSetupUtils.getAAIServiceInstanceByName(globalCustomerId, serviceType, instanceName);
- if (serviceInstanceAAI.isPresent()) {
- if (serviceInstanceAAI.get().getModelVersionId()
- .equalsIgnoreCase(reqDetails.getModelInfo().getModelVersionId())) {
- return serviceInstanceAAI.get().getServiceInstanceId();
- } else {
- throw new DuplicateNameException(SERVICE_INSTANCE, String.format(NAME_EXISTS_WITH_DIFF_VERSION_ID,
- instanceName, reqDetails.getModelInfo().getModelVersionId()));
- }
- } else {
- ServiceInstances aaiServiceInstances =
- bbInputSetupUtils.getAAIServiceInstancesGloballyByName(instanceName);
- if (aaiServiceInstances != null) {
- if (aaiServiceInstances.getServiceInstance() != null
- && !aaiServiceInstances.getServiceInstance().isEmpty()) {
- if (aaiServiceInstances.getServiceInstance().size() > 1) {
- throw new DuplicateNameException(SERVICE_INSTANCE,
- String.format(NAME_EXISTS_MULTIPLE, instanceName));
- } else {
- ServiceInstance si = aaiServiceInstances.getServiceInstance().stream().findFirst().get();
- Map<String, String> keys =
- bbInputSetupUtils.getURIKeysFromServiceInstance(si.getServiceInstanceId());
-
- throw new DuplicateNameException(SERVICE_INSTANCE, String.format(
- NAME_EXISTS_WITH_DIFF_COMBINATION, instanceName,
- keys.get(AAIFluentTypeBuilder.Types.CUSTOMER.getUriParams().globalCustomerId),
- keys.get(
- AAIFluentTypeBuilder.Types.SERVICE_SUBSCRIPTION.getUriParams().serviceType),
- si.getModelVersionId()));
- }
- }
- }
- }
- }
- return generatedResourceId;
- }
-
- protected String validateNetworkResourceIdInAAI(String generatedResourceId, String instanceName,
- RequestDetails reqDetails, WorkflowResourceIds workflowResourceIds)
- throws DuplicateNameException, MultipleObjectsFoundException {
- Optional<L3Network> network = bbInputSetupUtils
- .getRelatedNetworkByNameFromServiceInstance(workflowResourceIds.getServiceInstanceId(), instanceName);
- if (network.isPresent()) {
- if (network.get().getModelCustomizationId()
- .equalsIgnoreCase(reqDetails.getModelInfo().getModelCustomizationId())) {
- return network.get().getNetworkId();
- } else {
- throw new DuplicateNameException("l3Network", String.format(NAME_EXISTS_WITH_DIFF_CUSTOMIZATION_ID,
- instanceName, network.get().getModelCustomizationId()));
- }
- }
- if (bbInputSetupUtils.existsAAINetworksGloballyByName(instanceName)) {
- throw new DuplicateNameException("l3Network", String.format(NAME_EXISTS_WITH_DIFF_PARENT, instanceName,
- workflowResourceIds.getServiceInstanceId()));
- }
- return generatedResourceId;
- }
-
- protected String validateVnfResourceIdInAAI(String generatedResourceId, String instanceName,
- RequestDetails reqDetails, WorkflowResourceIds workflowResourceIds) throws DuplicateNameException {
- Optional<GenericVnf> vnf = bbInputSetupUtils
- .getRelatedVnfByNameFromServiceInstance(workflowResourceIds.getServiceInstanceId(), instanceName);
- if (vnf.isPresent()) {
- if (vnf.get().getModelCustomizationId()
- .equalsIgnoreCase(reqDetails.getModelInfo().getModelCustomizationId())) {
- return vnf.get().getVnfId();
- } else {
- throw new DuplicateNameException("generic-vnf", String.format(NAME_EXISTS_WITH_DIFF_CUSTOMIZATION_ID,
- instanceName, vnf.get().getModelCustomizationId()));
- }
- }
- GenericVnfs vnfs = bbInputSetupUtils.getAAIVnfsGloballyByName(instanceName);
- if (vnfs != null) {
- throw new DuplicateNameException("generic-vnf",
- String.format(NAME_EXISTS_WITH_DIFF_PARENT, instanceName, vnfs.getGenericVnf().get(0).getVnfId()));
- }
- return generatedResourceId;
- }
-
- protected String validateVfModuleResourceIdInAAI(String generatedResourceId, String instanceName,
- RequestDetails reqDetails, WorkflowResourceIds workflowResourceIds) throws DuplicateNameException {
- GenericVnf vnf = bbInputSetupUtils.getAAIGenericVnf(workflowResourceIds.getVnfId());
- if (vnf != null && vnf.getVfModules() != null) {
- for (org.onap.aai.domain.yang.VfModule vfModule : vnf.getVfModules().getVfModule()) {
- if (vfModule.getVfModuleName().equalsIgnoreCase(instanceName)) {
- if (vfModule.getModelCustomizationId()
- .equalsIgnoreCase(reqDetails.getModelInfo().getModelCustomizationId())) {
- return vfModule.getVfModuleId();
- } else {
- throw new DuplicateNameException("vfModule",
- String.format(NAME_EXISTS_WITH_DIFF_CUSTOMIZATION_ID, instanceName,
- reqDetails.getModelInfo().getModelCustomizationId()));
- }
- }
- }
- }
- if (bbInputSetupUtils.existsAAIVfModuleGloballyByName(instanceName)) {
- throw new DuplicateNameException("vfModule", instanceName);
- }
- return generatedResourceId;
+ protected boolean foundRelated(List<Resource> resourceList) {
+ return (containsWorkflowType(resourceList, WorkflowType.VNF)
+ || containsWorkflowType(resourceList, WorkflowType.PNF)
+ || containsWorkflowType(resourceList, WorkflowType.NETWORK)
+ || containsWorkflowType(resourceList, WorkflowType.NETWORKCOLLECTION));
}
- protected String validateVolumeGroupResourceIdInAAI(String generatedResourceId, String instanceName,
- RequestDetails reqDetails, WorkflowResourceIds workflowResourceIds) throws DuplicateNameException {
- Optional<VolumeGroup> volumeGroup =
- bbInputSetupUtils.getRelatedVolumeGroupByNameFromVnf(workflowResourceIds.getVnfId(), instanceName);
- if (volumeGroup.isPresent()) {
- if (volumeGroup.get().getVfModuleModelCustomizationId()
- .equalsIgnoreCase(reqDetails.getModelInfo().getModelCustomizationId())) {
- return volumeGroup.get().getVolumeGroupId();
- } else {
- throw new DuplicateNameException("volumeGroup", volumeGroup.get().getVolumeGroupName());
- }
- }
- if (bbInputSetupUtils.existsAAIVolumeGroupGloballyByName(instanceName)) {
- throw new DuplicateNameException("volumeGroup", instanceName);
- }
- return generatedResourceId;
- }
-
- protected String validateConfigurationResourceIdInAAI(String generatedResourceId, String instanceName,
- RequestDetails reqDetails, WorkflowResourceIds workflowResourceIds) throws DuplicateNameException {
- Optional<org.onap.aai.domain.yang.Configuration> configuration =
- bbInputSetupUtils.getRelatedConfigurationByNameFromServiceInstance(
- workflowResourceIds.getServiceInstanceId(), instanceName);
- if (configuration.isPresent()) {
- if (configuration.get().getModelCustomizationId()
- .equalsIgnoreCase(reqDetails.getModelInfo().getModelCustomizationId())) {
- return configuration.get().getConfigurationId();
- } else {
- throw new DuplicateNameException("configuration", String.format(NAME_EXISTS_WITH_DIFF_CUSTOMIZATION_ID,
- instanceName, configuration.get().getConfigurationId()));
- }
- }
- if (bbInputSetupUtils.existsAAIConfigurationGloballyByName(instanceName)) {
- throw new DuplicateNameException("configuration", instanceName);
- }
- return generatedResourceId;
+ protected boolean containsWorkflowType(List<Resource> resourceList, WorkflowType workflowType) {
+ return resourceList.stream().anyMatch(resource -> resource.getResourceType().equals(workflowType));
}
private void fillExecutionDefault(DelegateExecution execution) {
@@ -1904,7 +1435,7 @@ public class WorkflowAction {
WorkflowResourceIds workflowResourceIds) throws Exception {
if (resource.isGenerated() && requestAction.equalsIgnoreCase("createInstance")
&& requestDetails.getRequestInfo().getInstanceName() != null) {
- return validateResourceIdInAAI(resource.getResourceId(), resource.getResourceType(),
+ return aaiResourceIdValidator.validateResourceIdInAAI(resource.getResourceId(), resource.getResourceType(),
requestDetails.getRequestInfo().getInstanceName(), requestDetails, workflowResourceIds);
} else {
return resource.getResourceId();
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasks.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasks.java
index 43a85051be..b756772188 100644
--- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasks.java
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasks.java
@@ -52,6 +52,9 @@ import org.onap.so.db.catalog.beans.CvnfcConfigurationCustomization;
import org.onap.so.db.catalog.client.CatalogDbClient;
import org.onap.so.db.request.beans.InfraActiveRequests;
import org.onap.so.db.request.client.RequestsDbClient;
+import org.onap.so.serviceinstancebeans.ModelType;
+import org.onap.so.serviceinstancebeans.RelatedInstance;
+import org.onap.so.serviceinstancebeans.RelatedInstanceList;
import org.onap.so.serviceinstancebeans.RequestReferences;
import org.onap.so.serviceinstancebeans.ServiceInstancesResponse;
import org.slf4j.Logger;
@@ -78,6 +81,7 @@ public class WorkflowActionBBTasks {
private static final String ROLLBACKTOCREATEDNOCONFIGURATION = "RollbackToCreatedNoConfiguration";
private static final String REPLACEINSTANCE = "replaceInstance";
private static final String VFMODULE = "VfModule";
+ private static final String CONFIGURATION_PATTERN = "(Ad|De)(.*)FabricConfiguration(.*)";
protected String maxRetries = "mso.rainyDay.maxRetries";
private static final Logger logger = LoggerFactory.getLogger(WorkflowActionBBTasks.class);
@@ -99,19 +103,26 @@ public class WorkflowActionBBTasks {
private RequestsDbListenerRunner requestsDbListener;
public void selectBB(DelegateExecution execution) {
- List<ExecuteBuildingBlock> flowsToExecute =
- (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
- execution.setVariable("MacroRollback", false);
-
- flowManipulatorListenerRunner.modifyFlows(flowsToExecute, new DelegateExecutionImpl(execution));
- int currentSequence = (int) execution.getVariable(G_CURRENT_SEQUENCE);
+ try {
+ List<ExecuteBuildingBlock> flowsToExecute =
+ (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
+ execution.setVariable("MacroRollback", false);
+ try {
+ flowManipulatorListenerRunner.modifyFlows(flowsToExecute, new DelegateExecutionImpl(execution));
+ } catch (NullPointerException ex) {
+ workflowAction.buildAndThrowException(execution, "Error in FlowManipulator Modify Flows", ex);
+ }
+ int currentSequence = (int) execution.getVariable(G_CURRENT_SEQUENCE);
- ExecuteBuildingBlock ebb = flowsToExecute.get(currentSequence);
+ ExecuteBuildingBlock ebb = flowsToExecute.get(currentSequence);
- execution.setVariable("buildingBlock", ebb);
- currentSequence++;
- execution.setVariable(COMPLETED, currentSequence >= flowsToExecute.size());
- execution.setVariable(G_CURRENT_SEQUENCE, currentSequence);
+ execution.setVariable("buildingBlock", ebb);
+ currentSequence++;
+ execution.setVariable(COMPLETED, currentSequence >= flowsToExecute.size());
+ execution.setVariable(G_CURRENT_SEQUENCE, currentSequence);
+ } catch (Exception e) {
+ workflowAction.buildAndThrowException(execution, "Internal Error occured during selectBB", e);
+ }
}
public void updateFlowStatistics(DelegateExecution execution) {
@@ -414,12 +425,9 @@ public class WorkflowActionBBTasks {
String handlingCode = (String) execution.getVariable(HANDLINGCODE);
final boolean aLaCarte = (boolean) execution.getVariable(G_ALACARTE);
int currentSequence = (int) execution.getVariable(G_CURRENT_SEQUENCE);
- String requestAction = (String) execution.getVariable(G_ACTION);
ExecuteBuildingBlock ebb = flowsToExecute.get(currentSequence - 1);
String bbFlowName = ebb.getBuildingBlock().getBpmnFlowName();
- if ("ActivateVfModuleBB".equalsIgnoreCase(bbFlowName) && aLaCarte && "Success".equalsIgnoreCase(handlingCode)
- && !(requestAction.equalsIgnoreCase("replaceInstance")
- || requestAction.equalsIgnoreCase("replaceInstanceRetainAssignments"))) {
+ if ("ActivateVfModuleBB".equalsIgnoreCase(bbFlowName) && aLaCarte && "Success".equalsIgnoreCase(handlingCode)) {
postProcessingExecuteBBActivateVfModule(execution, ebb, flowsToExecute);
}
}
@@ -427,15 +435,32 @@ public class WorkflowActionBBTasks {
protected void postProcessingExecuteBBActivateVfModule(DelegateExecution execution, ExecuteBuildingBlock ebb,
List<ExecuteBuildingBlock> flowsToExecute) {
try {
+ String requestAction = (String) execution.getVariable(G_ACTION);
String serviceInstanceId = ebb.getWorkflowResourceIds().getServiceInstanceId();
String vnfId = ebb.getWorkflowResourceIds().getVnfId();
String vfModuleId = ebb.getResourceId();
ebb.getWorkflowResourceIds().setVfModuleId(vfModuleId);
- String serviceModelUUID =
- bbInputSetupUtils.getAAIServiceInstanceById(serviceInstanceId).getModelVersionId();
- String vnfCustomizationUUID = bbInputSetupUtils.getAAIGenericVnf(vnfId).getModelCustomizationId();
- String vfModuleCustomizationUUID =
- bbInputSetupUtils.getAAIVfModule(vnfId, vfModuleId).getModelCustomizationId();
+ String serviceModelUUID = "";
+ String vnfCustomizationUUID = "";
+ String vfModuleCustomizationUUID = "";
+ if (requestAction.equalsIgnoreCase("replaceInstance")
+ || requestAction.equalsIgnoreCase("replaceInstanceRetainAssignments")) {
+ for (RelatedInstanceList relatedInstList : ebb.getRequestDetails().getRelatedInstanceList()) {
+ RelatedInstance relatedInstance = relatedInstList.getRelatedInstance();
+ if (relatedInstance.getModelInfo().getModelType().equals(ModelType.vnf)) {
+ vnfCustomizationUUID = relatedInstance.getModelInfo().getModelCustomizationId();
+ }
+ if (relatedInstance.getModelInfo().getModelType().equals(ModelType.service)) {
+ serviceModelUUID = relatedInstance.getModelInfo().getModelVersionId();
+ }
+ }
+ vfModuleCustomizationUUID = ebb.getRequestDetails().getModelInfo().getModelCustomizationId();
+ } else {
+ serviceModelUUID = bbInputSetupUtils.getAAIServiceInstanceById(serviceInstanceId).getModelVersionId();
+ vnfCustomizationUUID = bbInputSetupUtils.getAAIGenericVnf(vnfId).getModelCustomizationId();
+ vfModuleCustomizationUUID =
+ bbInputSetupUtils.getAAIVfModule(vnfId, vfModuleId).getModelCustomizationId();
+ }
List<Vnfc> vnfcs = workflowAction.getRelatedResourcesInVfModule(vnfId, vfModuleId, Vnfc.class, Types.VNFC);
logger.debug("Vnfc Size: {}", vnfcs.size());
for (Vnfc vnfc : vnfcs) {
@@ -455,8 +480,9 @@ public class WorkflowActionBBTasks {
ExecuteBuildingBlock addConfigBB = getExecuteBBForConfig(ADD_FABRIC_CONFIGURATION_BB, ebb,
configurationId, configurationResourceKeys);
flowsToExecute.add(addConfigBB);
- flowsToExecute.forEach(executeBB -> logger.info("Flows to Execute After Post Processing: {}",
- executeBB.getBuildingBlock().getBpmnFlowName()));
+ flowsToExecute.stream()
+ .forEach(executeBB -> logger.info("Flows to Execute After Post Processing: {}",
+ executeBB.getBuildingBlock().getBpmnFlowName()));
execution.setVariable("flowsToExecute", flowsToExecute);
execution.setVariable(COMPLETED, false);
} else {
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
new file mode 100644
index 0000000000..5e16097304
--- /dev/null
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionConstants.java
@@ -0,0 +1,47 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Modifications Copyright (c) 2019 Samsung
+ * ================================================================================
+ * Modifications Copyright (c) 2020 Nokia
+ * ================================================================================
+ * Modifications Copyright (c) 2020 Tech Mahindra
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.bpmn.infrastructure.workflow.tasks;
+
+public final class WorkflowActionConstants {
+
+ private WorkflowActionConstants() {
+ throw new IllegalStateException("Utility class");
+ }
+
+ static final String USER_PARAM_SERVICE = "service";
+ static final String CREATE_INSTANCE = "createInstance";
+ static final String FABRIC_CONFIGURATION = "FabricConfiguration";
+ static final String WORKFLOW_ACTION_ERROR_MESSAGE = "WorkflowActionErrorMessage";
+ static final String SERVICE = "Service";
+ static final String CONTROLLER = "Controller";
+ static final String NETWORKCOLLECTION = "NetworkCollection";
+ static final String CONFIGURATION = "Configuration";
+ static final String ASSIGNINSTANCE = "assignInstance";
+ static final String REPLACEINSTANCE = "replaceInstance";
+ static final String VOLUMEGROUP = "VolumeGroup";
+ static final String REPLACEINSTANCERETAINASSIGNMENTS = "replaceInstanceRetainAssignments";
+}
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 2119ced951..564ee91fb2 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
@@ -84,7 +84,7 @@ public class SkipCDSBuildingBlockListener implements FlowManipulator {
VnfResourceCustomization vrc = catalogDbClient.findVnfResourceCustomizationInList(customizationUUID,
vnfResourceCustomizations);
if (null != vrc) {
- boolean skipConfigVNF = vrc.isSkipPostInstConf();
+ boolean skipConfigVNF = vrc.isSkipPostInstConf().booleanValue();
currentSequenceSkipCheck(execution, skipConfigVNF);
}
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/listeners/SkipConfigVnfListener.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/listeners/SkipConfigVnfListener.java
index 6589ae77f5..83f61e3a4f 100644
--- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/listeners/SkipConfigVnfListener.java
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/listeners/SkipConfigVnfListener.java
@@ -34,7 +34,7 @@ public class SkipConfigVnfListener implements FlowManipulator {
if (vnfResourceCustomizations != null && !vnfResourceCustomizations.isEmpty()) {
VnfResourceCustomization vrc =
catalogDbClient.findVnfResourceCustomizationInList(vnfCustomizationUUID, vnfResourceCustomizations);
- boolean skipConfigVNF = vrc.isSkipPostInstConf();
+ boolean skipConfigVNF = vrc.isSkipPostInstConf().booleanValue();
if (skipConfigVNF) {
execution.setVariable(BBConstants.G_CURRENT_SEQUENCE,
((int) execution.getVariable(BBConstants.G_CURRENT_SEQUENCE)) + 1);
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/CnfAdapterClient.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/CnfAdapterClient.java
index b74aa9056d..da36a6f040 100644
--- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/CnfAdapterClient.java
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/CnfAdapterClient.java
@@ -54,14 +54,14 @@ public class CnfAdapterClient {
@Autowired
private Environment env;
- private static final String INSTANCE_CREATE_PATH = "/api/multicloud-k8s/v1/v1/instance";
+ private static final String INSTANCE_CREATE_PATH = "/api/cnf-adapter/v1/instance";
@Retryable(value = {HttpServerErrorException.class}, maxAttempts = 3, backoff = @Backoff(delay = 3000))
public InstanceResponse createVfModule(InstanceRequest request) throws CnfAdapterClientException {
try {
// String uri = env.getRequiredProperty("mso.cnf.adapter.endpoint"); //TODO: This needs to be added as well
// for configuration
- String uri = "https://localhost:32780"; // TODO: What is the correct uri?
+ String uri = "http://so-cnf-adapter:8090";
String endpoint = UriBuilder.fromUri(uri).path(INSTANCE_CREATE_PATH).build().toString();
HttpEntity<?> entity = getHttpEntity(request);
ResponseEntity<InstanceResponse> result =
@@ -76,12 +76,31 @@ public class CnfAdapterClient {
}
}
+
+ @Retryable(value = {HttpServerErrorException.class}, maxAttempts = 3, backoff = @Backoff(delay = 3000))
+ public void deleteVfModule(String heatStackId) throws CnfAdapterClientException {
+ try {
+ // String uri = env.getRequiredProperty("mso.cnf.adapter.endpoint"); //TODO: This needs to be added as well
+ // for configuration
+ String uri = "http://so-cnf-adapter:8090";
+ String endpoint = UriBuilder.fromUri(uri).path(INSTANCE_CREATE_PATH + "/" + heatStackId).build().toString();
+ HttpEntity<?> entity = new HttpEntity<>(getHttpHeaders());
+ restTemplate.exchange(endpoint, HttpMethod.DELETE, entity, String.class);
+ } catch (HttpClientErrorException e) {
+ logger.error("Error Calling CNF Adapter, e");
+ if (HttpStatus.SC_NOT_FOUND == e.getStatusCode().value()) {
+ throw new EntityNotFoundException(e.getResponseBodyAsString());
+ }
+ throw e;
+ }
+ }
+
@Retryable(value = {HttpServerErrorException.class}, maxAttempts = 3, backoff = @Backoff(delay = 3000))
public InstanceResponse healthcheck() throws CnfAdapterClientException {
try {
// String uri = env.getRequiredProperty("mso.cnf.adapter.endpoint"); //TODO: This needs to be added as well
// for configuration
- String uri = "https://localhost:32780"; // TODO: What is the correct uri?
+ String uri = "http://so-cnf-adapter:8090";
String endpoint = UriBuilder.fromUri(uri).path("/api/cnf-adapter/v1/healthcheck").build().toString();
HttpEntity<?> entity = new HttpEntity<>(getHttpHeaders());
ResponseEntity<InstanceResponse> result =
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/entities/InstanceResponse.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/entities/InstanceResponse.java
index e38bcc2664..13ccb4eb92 100644
--- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/entities/InstanceResponse.java
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/entities/InstanceResponse.java
@@ -7,15 +7,21 @@ import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
@JsonInclude(JsonInclude.Include.NON_NULL)
-@JsonPropertyOrder({"id", "request", "namespace", "resources"})
+@JsonPropertyOrder({"id", "request", "namespace", "release-name", "resources"})
public class InstanceResponse {
@JsonProperty("id")
private String id;
+
@JsonProperty("request")
private InstanceRequest request;
+
@JsonProperty("namespace")
private String namespace;
+
+ @JsonProperty("release-name")
+ private String releaseName;
+
@JsonProperty("resources")
private List<Resource> resources = null;
@@ -59,4 +65,14 @@ public class InstanceResponse {
this.resources = resources;
}
+ @JsonProperty("release-name")
+ public String getReleaseName() {
+ return releaseName;
+ }
+
+ @JsonProperty("release-name")
+ public void setReleaseName(String releaseName) {
+ this.releaseName = releaseName;
+ }
+
}
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/vnf/mapper/AttributeNameValue.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/vnf/mapper/AttributeNameValue.java
index 6278d48e03..7291b713ca 100644
--- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/vnf/mapper/AttributeNameValue.java
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/vnf/mapper/AttributeNameValue.java
@@ -21,18 +21,16 @@
package org.onap.so.client.adapter.vnf.mapper;
import java.io.Serializable;
+import com.fasterxml.jackson.annotation.JsonProperty;
public class AttributeNameValue implements Serializable {
private static final long serialVersionUID = -5215028275587848311L;
+ @JsonProperty("attribute_name")
private String attributeName;
+ @JsonProperty("attribute_value")
private transient Object attributeValue;
- public AttributeNameValue(String attributeName, Object attributeValue) {
- this.attributeName = attributeName;
- this.attributeValue = attributeValue;
- }
-
public String getAttributeName() {
return attributeName;
}
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/vnf/mapper/VnfAdapterVfModuleObjectMapper.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/vnf/mapper/VnfAdapterVfModuleObjectMapper.java
index 59da22f8e1..7c686bd165 100644
--- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/vnf/mapper/VnfAdapterVfModuleObjectMapper.java
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/vnf/mapper/VnfAdapterVfModuleObjectMapper.java
@@ -235,7 +235,10 @@ public class VnfAdapterVfModuleObjectMapper {
logger.error("No value tag found for attribute: {}", attributeName);
throw new MissingValueTagException("No value tag found for " + attributeName);
}
- directives.append(new AttributeNameValue(attributeName, attributeValue.toString()));
+ String nameValue = new StringBuilder().append("{\"attribute_name\": \"").append(attributeName)
+ .append("\", \"attribute_value\": \"").append(attributeValue.toString()).append("\"}")
+ .toString();
+ directives.append(nameValue);
if (i < (srcMap.size() - 1 + noOfDirectivesSize))
directives.append(", ");
i++;
diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/BaseTaskTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/BaseTaskTest.java
index e8ce828652..ab83acaec2 100644
--- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/BaseTaskTest.java
+++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/BaseTaskTest.java
@@ -24,7 +24,6 @@ package org.onap.so.bpmn;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
-import org.onap.so.bpmn.common.BuildingBlockExecution;
import org.onap.so.bpmn.common.InjectionHelper;
import org.onap.so.bpmn.common.data.TestDataSetup;
import org.onap.so.bpmn.infrastructure.flowspecific.tasks.AssignNetworkBBUtils;
@@ -33,8 +32,6 @@ import org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetup;
import org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetupUtils;
import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
import org.onap.aaiclient.client.aai.AAIResourcesClient;
-import org.onap.aaiclient.client.aai.entities.AAIResultWrapper;
-import org.onap.aaiclient.client.aai.entities.Relationships;
import org.onap.so.client.aai.mapper.AAIObjectMapper;
import org.onap.so.client.adapter.network.mapper.NetworkAdapterObjectMapper;
import org.onap.so.client.appc.ApplicationControllerAction;
@@ -162,5 +159,4 @@ public abstract class BaseTaskTest extends TestDataSetup {
@Mock
protected NamingRequestObject namingRequestObject;
-
}
diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/buildingblock/controller/sdnc/prepare/PrepareSdncUpgradePreCheckPnfBBTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/buildingblock/controller/sdnc/prepare/PrepareSdncUpgradePreCheckPnfBBTest.java
new file mode 100644
index 0000000000..0ba1e27f5e
--- /dev/null
+++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/buildingblock/controller/sdnc/prepare/PrepareSdncUpgradePreCheckPnfBBTest.java
@@ -0,0 +1,88 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 Nokia
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.bpmn.infrastructure.decisionpoint.impl.buildingblock.controller.sdnc.prepare;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import org.camunda.bpm.engine.delegate.DelegateExecution;
+import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake;
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.so.bpmn.common.BuildingBlockExecution;
+import org.onap.so.bpmn.common.DelegateExecutionImpl;
+import org.onap.so.bpmn.infrastructure.decisionpoint.api.ControllerContext;
+
+public class PrepareSdncUpgradePreCheckPnfBBTest {
+
+ private PrepareSdncUpgradePreCheckPnfBB testedObject;
+
+ @Before
+ public void setup() {
+ testedObject = new PrepareSdncUpgradePreCheckPnfBB();
+ }
+
+ @Test
+ public void understandTrue() {
+ ControllerContext<BuildingBlockExecution> controllerContext =
+ createControllerContext("sdnc", "UpgradePreCheck", "pnf");
+ boolean result = testedObject.understand(controllerContext);
+ assertThat(result).isTrue();
+ }
+
+ @Test
+ public void understandFalse() {
+ ControllerContext<BuildingBlockExecution> controllerContext =
+ createControllerContext("actor1", "action1", "scope1");
+ boolean result = testedObject.understand(controllerContext);
+ assertThat(result).isFalse();
+ }
+
+ @Test
+ public void prepare_jsonWithoutActionPayload() {
+ String payloadWithoutActionArray = "{\"json name\": \"test1\"}";
+ ControllerContext<BuildingBlockExecution> controllerContext =
+ createControllerContext(payloadWithoutActionArray);
+ testedObject.prepare(controllerContext);
+
+ assertThat((String) controllerContext.getExecution().getVariable("payload"))
+ .isEqualTo(payloadWithoutActionArray);
+ }
+
+ private ControllerContext<BuildingBlockExecution> createControllerContext(String actor, String action,
+ String scope) {
+ ControllerContext<BuildingBlockExecution> controllerContext = new ControllerContext<>();
+ controllerContext.setControllerActor(actor);
+ controllerContext.setControllerAction(action);
+ controllerContext.setControllerScope(scope);
+ return controllerContext;
+ }
+
+ private ControllerContext<BuildingBlockExecution> createControllerContext(String payload) {
+ ControllerContext<BuildingBlockExecution> controllerContext = new ControllerContext<>();
+ controllerContext.setExecution(prepareBuildingBlockExecution(payload));
+ return controllerContext;
+ }
+
+ private BuildingBlockExecution prepareBuildingBlockExecution(String payload) {
+ DelegateExecution execution = new DelegateExecutionFake();
+ execution.setVariable("payload", payload);
+ return new DelegateExecutionImpl(execution);
+ }
+}
diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/AaiResourceIdValidatorTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/AaiResourceIdValidatorTest.java
new file mode 100644
index 0000000000..ead6c0b4cf
--- /dev/null
+++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/AaiResourceIdValidatorTest.java
@@ -0,0 +1,765 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Modifications Copyright (c) 2019 Samsung
+ * ================================================================================
+ * Modifications Copyright (c) 2020 Nokia
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.bpmn.infrastructure.workflow.tasks;
+
+import static org.hamcrest.CoreMatchers.containsString;
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.when;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Optional;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.aai.domain.yang.GenericVnf;
+import org.onap.aai.domain.yang.GenericVnfs;
+import org.onap.aai.domain.yang.L3Network;
+import org.onap.aai.domain.yang.ServiceInstance;
+import org.onap.aai.domain.yang.ServiceInstances;
+import org.onap.aai.domain.yang.VfModule;
+import org.onap.aai.domain.yang.VfModules;
+import org.onap.aai.domain.yang.VolumeGroup;
+import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder;
+import org.onap.so.bpmn.servicedecomposition.entities.WorkflowResourceIds;
+import org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetupUtils;
+import org.onap.so.bpmn.servicedecomposition.tasks.exceptions.DuplicateNameException;
+import org.onap.so.serviceinstancebeans.ModelInfo;
+import org.onap.so.serviceinstancebeans.RequestDetails;
+import org.onap.so.serviceinstancebeans.RequestParameters;
+import org.onap.so.serviceinstancebeans.SubscriberInfo;
+
+@RunWith(MockitoJUnitRunner.class)
+public class AaiResourceIdValidatorTest {
+
+ @Mock
+ private BBInputSetupUtils bbInputSetupUtilsMock;
+
+ @InjectMocks
+ private AaiResourceIdValidator testedObject;
+
+ @Rule
+ public ExpectedException expectedException = ExpectedException.none();
+
+ @Test
+ public void validateResourceIdInAAIVnfTest() throws Exception {
+ RequestDetails reqDetails = setupRequestDetails();
+ WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds();
+ workflowResourceIds.setServiceInstanceId("siId123");
+ GenericVnf vnf = new GenericVnf();
+ vnf.setVnfId("id123");
+ vnf.setModelCustomizationId("1234567");
+ Optional<GenericVnf> opVnf = Optional.of(vnf);
+ GenericVnf vnf2 = new GenericVnf();
+ vnf2.setVnfId("id123");
+ vnf2.setModelCustomizationId("222");
+ Optional<GenericVnf> opVnf2 = Optional.of(vnf2);
+ when(bbInputSetupUtilsMock.getRelatedVnfByNameFromServiceInstance("siId123", "vnfName123")).thenReturn(opVnf);
+ when(bbInputSetupUtilsMock.getRelatedVnfByNameFromServiceInstance("siId123", "vnfName222")).thenReturn(opVnf2);
+ String id = testedObject.validateResourceIdInAAI("generatedId123", WorkflowType.VNF, "vnfName123", reqDetails,
+ workflowResourceIds);
+ assertEquals("id123", id);
+ String id2 = testedObject.validateResourceIdInAAI("generatedId123", WorkflowType.VNF, "nameTest", reqDetails,
+ workflowResourceIds);
+ assertEquals("generatedId123", id2);
+
+ this.expectedException.expect(DuplicateNameException.class);
+ this.expectedException.expectMessage(containsString(
+ "generic-vnf with name (vnfName222), same parent and different customization id (222) already exists. The name must be unique."));
+ testedObject.validateResourceIdInAAI("generatedId123", WorkflowType.VNF, "vnfName222", reqDetails,
+ workflowResourceIds);
+ }
+
+ @Test
+ public void validateResourceIdInAAIVnfNotGloballyUniqueTest() throws Exception {
+ RequestDetails reqDetails = setupRequestDetails();
+ GenericVnfs genericVnfs = new GenericVnfs();
+ GenericVnf vnf3 = new GenericVnf();
+ vnf3.setVnfId("id123");
+
+ genericVnfs.getGenericVnf().add(vnf3);
+ when(bbInputSetupUtilsMock.getAAIVnfsGloballyByName("vnfName333")).thenReturn(genericVnfs);
+
+ this.expectedException.expect(DuplicateNameException.class);
+ this.expectedException.expectMessage(containsString(
+ "generic-vnf with name (vnfName333) id (id123) and different parent relationship already exists. The name must be unique."));
+ testedObject.validateResourceIdInAAI("generatedId123", WorkflowType.VNF, "vnfName333", reqDetails,
+ new WorkflowResourceIds());
+ }
+
+ @Test
+ public void validateResourceIdInAAINetworkTest() throws Exception {
+ RequestDetails reqDetails = setupRequestDetails();
+ WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds();
+ workflowResourceIds.setServiceInstanceId("siId123");
+ L3Network network = new L3Network();
+ network.setNetworkId("id123");
+ network.setModelCustomizationId("1234567");
+ Optional<L3Network> opNetwork = Optional.of(network);
+ L3Network network2 = new L3Network();
+ network2.setNetworkId("id123");
+ network2.setModelCustomizationId("222");
+ Optional<L3Network> opNetwork2 = Optional.of(network2);
+
+ when(bbInputSetupUtilsMock.getRelatedNetworkByNameFromServiceInstance("siId123", "name123"))
+ .thenReturn(opNetwork);
+ when(bbInputSetupUtilsMock.getRelatedNetworkByNameFromServiceInstance("siId123", "networkName222"))
+ .thenReturn(opNetwork2);
+ String id = testedObject.validateResourceIdInAAI("generatedId123", WorkflowType.NETWORK, "name123", reqDetails,
+ workflowResourceIds);
+ assertEquals("id123", id);
+ String id2 = testedObject.validateResourceIdInAAI("generatedId123", WorkflowType.NETWORK, "111111", reqDetails,
+ workflowResourceIds);
+ assertEquals("generatedId123", id2);
+
+ this.expectedException.expect(DuplicateNameException.class);
+ this.expectedException.expectMessage(containsString(
+ "l3Network with name (networkName222), same parent and different customization id (222) already exists. The name must be unique."));
+ testedObject.validateResourceIdInAAI("generatedId123", WorkflowType.NETWORK, "networkName222", reqDetails,
+ workflowResourceIds);
+ }
+
+ @Test
+ public void validateNetworkResourceNameExistsInAAITest() throws Exception {
+ RequestDetails reqDetails = setupRequestDetails();
+ WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds();
+ workflowResourceIds.setServiceInstanceId("siId123");
+
+ when(bbInputSetupUtilsMock.existsAAINetworksGloballyByName("networkName333")).thenReturn(true);
+
+ this.expectedException.expect(DuplicateNameException.class);
+ this.expectedException.expectMessage(containsString(
+ "l3Network with name (networkName333) id (siId123) and different parent relationship already exists. The name must be unique."));
+ testedObject.validateResourceIdInAAI("generatedId123", WorkflowType.NETWORK, "networkName333", reqDetails,
+ workflowResourceIds);
+ }
+
+ @Test
+ public void validateResourceIdInAAIVfModuleTest() throws Exception {
+ RequestDetails reqDetails = setupRequestDetails();
+ WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds();
+ workflowResourceIds.setVnfId("id123");
+
+ GenericVnf vnf = new GenericVnf();
+ VfModules vfModules = new VfModules();
+ VfModule vfModule = new VfModule();
+ vfModule.setVfModuleId("id123");
+ vfModule.setVfModuleName("name123");
+ vfModule.setModelCustomizationId("1234567");
+ vfModules.getVfModule().add(vfModule);
+ vnf.setVfModules(vfModules);
+
+ when(bbInputSetupUtilsMock.getAAIGenericVnf("id123")).thenReturn(vnf);
+ String id = testedObject.validateResourceIdInAAI("generatedId123", WorkflowType.VFMODULE, "name123", reqDetails,
+ workflowResourceIds);
+ assertEquals("id123", id);
+
+ GenericVnf vnf1 = new GenericVnf();
+ VfModules vfModules2 = new VfModules();
+ VfModule vfModule2 = new VfModule();
+ vfModule2.setVfModuleName("vFModName222");
+ vfModule2.setModelCustomizationId("222");
+ vfModules2.getVfModule().add(vfModule2);
+ vnf1.setVfModules(vfModules2);
+ workflowResourceIds.setVnfId("id111");
+ when(bbInputSetupUtilsMock.getAAIGenericVnf("id111")).thenReturn(vnf1);
+ String id2 = testedObject.validateResourceIdInAAI("generatedId123", WorkflowType.VFMODULE, "111111", reqDetails,
+ workflowResourceIds);
+ assertEquals("generatedId123", id2);
+
+ this.expectedException.expect(DuplicateNameException.class);
+ this.expectedException.expectMessage(containsString(
+ "vfModule with name (vFModName222), same parent and different customization id (1234567) already exists. The name must be unique."));
+ testedObject.validateResourceIdInAAI("generatedId123", WorkflowType.VFMODULE, "vFModName222", reqDetails,
+ workflowResourceIds);
+ }
+
+ @Test
+ public void validateResourceIdInAAIVfModuleNotGloballyUniqueTest() throws Exception {
+ RequestDetails reqDetails = setupRequestDetails();
+
+ when(bbInputSetupUtilsMock.existsAAIVfModuleGloballyByName("vFModName333")).thenReturn(true);
+ this.expectedException.expect(DuplicateNameException.class);
+ this.expectedException.expectMessage(
+ containsString("vfModule with name vFModName333 already exists. The name must be unique."));
+ testedObject.validateResourceIdInAAI("generatedId123", WorkflowType.VFMODULE, "vFModName333", reqDetails,
+ new WorkflowResourceIds());
+ }
+
+ @Test
+ public void validateResourceIdInAAIVolumeGroupTest() throws Exception {
+ RequestDetails reqDetails = setupRequestDetails();
+ WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds();
+ workflowResourceIds.setVnfId("id123");
+ VolumeGroup volumeGroup = new VolumeGroup();
+ volumeGroup.setVolumeGroupId("id123");
+ volumeGroup.setVolumeGroupName("name123");
+ volumeGroup.setVfModuleModelCustomizationId("1234567");
+ Optional<VolumeGroup> opVolumeGroup = Optional.of(volumeGroup);
+
+ when(bbInputSetupUtilsMock.getRelatedVolumeGroupByNameFromVnf("id123", "name123")).thenReturn(opVolumeGroup);
+ String id = testedObject.validateResourceIdInAAI("generatedId123", WorkflowType.VOLUMEGROUP, "name123",
+ reqDetails, workflowResourceIds);
+ assertEquals("id123", id);
+
+ String id2 = testedObject.validateResourceIdInAAI("generatedId123", WorkflowType.VOLUMEGROUP, "111111",
+ reqDetails, workflowResourceIds);
+ assertEquals("generatedId123", id2);
+ }
+
+
+ @Test
+ public void validateSourceIdInAAIVolumeGroupNotGloballyUniqueTest() throws Exception {
+ RequestDetails reqDetails = setupRequestDetails();
+ when(bbInputSetupUtilsMock.existsAAIVolumeGroupGloballyByName("testVolumeGroup")).thenReturn(true);
+ this.expectedException.expect(DuplicateNameException.class);
+ this.expectedException.expectMessage(
+ containsString("volumeGroup with name testVolumeGroup already exists. The name must be unique."));
+ testedObject.validateResourceIdInAAI("generatedId123", WorkflowType.VOLUMEGROUP, "testVolumeGroup", reqDetails,
+ new WorkflowResourceIds());
+ }
+
+ @Test
+ public void validateResourceIdInAAIConfigurationTest() throws Exception {
+ RequestDetails reqDetails = setupRequestDetails();
+ WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds();
+ workflowResourceIds.setServiceInstanceId("siId123");
+
+ org.onap.aai.domain.yang.Configuration configuration = new org.onap.aai.domain.yang.Configuration();
+ configuration.setConfigurationId("id123");
+ configuration.setModelCustomizationId("1234567");
+ Optional<org.onap.aai.domain.yang.Configuration> opConfiguration = Optional.of(configuration);
+
+ org.onap.aai.domain.yang.Configuration configuration2 = new org.onap.aai.domain.yang.Configuration();
+ configuration2.setConfigurationId("id123");
+ configuration2.setModelCustomizationId("222");
+ Optional<org.onap.aai.domain.yang.Configuration> opConfiguration2 = Optional.of(configuration2);
+
+ when(bbInputSetupUtilsMock.getRelatedConfigurationByNameFromServiceInstance("siId123", "name123"))
+ .thenReturn(opConfiguration);
+ String id = testedObject.validateResourceIdInAAI("generatedId123", WorkflowType.CONFIGURATION, "name123",
+ reqDetails, workflowResourceIds);
+ assertEquals("id123", id);
+
+ String id2 = testedObject.validateResourceIdInAAI("generatedId123", WorkflowType.CONFIGURATION, "111111",
+ reqDetails, workflowResourceIds);
+ assertEquals("generatedId123", id2);
+
+ when(bbInputSetupUtilsMock.getRelatedConfigurationByNameFromServiceInstance("siId123", "name222"))
+ .thenReturn(opConfiguration2);
+ this.expectedException.expect(DuplicateNameException.class);
+ this.expectedException.expectMessage(containsString(
+ "configuration with name (name222), same parent and different customization id (id123) already exists. The name must be unique."));
+ testedObject.validateResourceIdInAAI("generatedId123", WorkflowType.CONFIGURATION, "name222", reqDetails,
+ workflowResourceIds);
+ }
+
+ @Test
+ public void validateResourceIdInAAIConfigurationNotGloballyUniqueTest() throws Exception {
+ RequestDetails reqDetails = setupRequestDetails();
+ when(bbInputSetupUtilsMock.existsAAIConfigurationGloballyByName("testConfig")).thenReturn(true);
+ this.expectedException.expect(DuplicateNameException.class);
+ this.expectedException.expectMessage(
+ containsString("configuration with name testConfig already exists. The name must be unique."));
+ testedObject.validateResourceIdInAAI("generatedId123", WorkflowType.CONFIGURATION, "testConfig", reqDetails,
+ new WorkflowResourceIds());
+ }
+
+ @Test
+ public void validateResourceIdInAAISITest() throws Exception {
+ RequestDetails reqDetails = setupRequestDetails();
+ reqDetails.getModelInfo().setModelVersionId("1234567");
+
+ ServiceInstance si = new ServiceInstance();
+ si.setServiceInstanceId("siId123");
+ si.setModelVersionId("1234567");
+ ServiceInstances serviceInstances = new ServiceInstances();
+ serviceInstances.getServiceInstance().add(si);
+ Optional<ServiceInstance> siOp = Optional.of(si);
+ ServiceInstance si2 = new ServiceInstance();
+ si2.setServiceInstanceId("siId222");
+ si2.setModelVersionId("22222");
+ si2.setServiceInstanceName("siName222");
+ Optional<ServiceInstance> siOp2 = Optional.of(si2);
+ ServiceInstances serviceInstances2 = new ServiceInstances();
+ serviceInstances2.getServiceInstance().add(si2);
+
+ when(bbInputSetupUtilsMock.getAAIServiceInstanceByName("id123", "subServiceType123", "siName123"))
+ .thenReturn(siOp);
+ when(bbInputSetupUtilsMock.getAAIServiceInstanceByName("id123", "subServiceType123", "siName222"))
+ .thenReturn(siOp2);
+ String id = testedObject.validateResourceIdInAAI("generatedId123", WorkflowType.SERVICE, "siName123",
+ reqDetails, new WorkflowResourceIds());
+ assertEquals("siId123", id);
+ String id2 = testedObject.validateResourceIdInAAI("generatedId123", WorkflowType.SERVICE, "111111", reqDetails,
+ new WorkflowResourceIds());
+ assertEquals("generatedId123", id2);
+
+ this.expectedException.expect(DuplicateNameException.class);
+ this.expectedException.expectMessage(containsString(
+ "serviceInstance with name (siName222) and different version id (1234567) already exists. The name must be unique."));
+ testedObject.validateResourceIdInAAI("generatedId123", WorkflowType.SERVICE, "siName222", reqDetails,
+ new WorkflowResourceIds());
+ }
+
+ @Test
+ public void validateResourceIdInAAIMultipleSITest() throws Exception {
+ RequestDetails reqDetails = setupRequestDetails();
+ reqDetails.getModelInfo().setModelVersionId("1234567");
+ ServiceInstance si = new ServiceInstance();
+ ServiceInstances serviceInstances = new ServiceInstances();
+ serviceInstances.getServiceInstance().add(si);
+ ServiceInstance si2 = new ServiceInstance();
+ serviceInstances.getServiceInstance().add(si2);
+ when(bbInputSetupUtilsMock.getAAIServiceInstancesGloballyByName("siName123")).thenReturn(serviceInstances);
+
+ this.expectedException.expect(DuplicateNameException.class);
+ this.expectedException.expectMessage(containsString(
+ "serviceInstance with name (siName123) and multiple combination of model-version-id + service-type + global-customer-id already exists. The name must be unique."));
+ testedObject.validateResourceIdInAAI("generatedId123", WorkflowType.SERVICE, "siName123", reqDetails,
+ new WorkflowResourceIds());
+ }
+
+ @Test
+ public void validateResourceIdInAAISIExistsTest() throws Exception {
+ RequestDetails reqDetails = setupRequestDetails();
+ reqDetails.getModelInfo().setModelVersionId("1234567");
+
+ ServiceInstance si = new ServiceInstance();
+ si.setServiceInstanceId("siId123");
+ si.setModelVersionId("1234567");
+ ServiceInstances serviceInstances = new ServiceInstances();
+ serviceInstances.getServiceInstance().add(si);
+
+ Map<String, String> uriKeys = new HashMap<>();
+ uriKeys.put(AAIFluentTypeBuilder.Types.CUSTOMER.getUriParams().globalCustomerId, "globalCustomerId");
+ uriKeys.put(AAIFluentTypeBuilder.Types.SERVICE_SUBSCRIPTION.getUriParams().serviceType, "serviceType");
+
+ when(bbInputSetupUtilsMock.getAAIServiceInstancesGloballyByName("siName123")).thenReturn(serviceInstances);
+ when(bbInputSetupUtilsMock.getURIKeysFromServiceInstance("siId123")).thenReturn(uriKeys);
+
+ this.expectedException.expect(DuplicateNameException.class);
+ this.expectedException.expectMessage(containsString(
+ "serviceInstance with name (siName123) and global-customer-id (globalCustomerId), service-type (serviceType), model-version-id (1234567) already exists. The name must be unique."));
+ testedObject.validateResourceIdInAAI("generatedId123", WorkflowType.SERVICE, "siName123", reqDetails,
+ new WorkflowResourceIds());
+ }
+
+ @Test
+ public void validateServiceResourceIdInAAINoDupTest() throws Exception {
+ RequestDetails reqDetails = setupRequestDetails();
+ String id = testedObject.validateServiceResourceIdInAAI("generatedId123", "siName123", reqDetails);
+ assertEquals("generatedId123", id);
+ }
+
+ @Test
+ public void validateServiceResourceIdInAAISameModelVersionId() throws Exception {
+ RequestDetails reqDetails = setupRequestDetails();
+ reqDetails.getModelInfo().setModelVersionId("1234567");
+
+ ServiceInstance si = new ServiceInstance();
+ si.setServiceInstanceId("siId123");
+ si.setModelVersionId("1234567");
+ Optional<ServiceInstance> siOp = Optional.of(si);
+
+ when(bbInputSetupUtilsMock.getAAIServiceInstanceByName("id123", "subServiceType123", "siName123"))
+ .thenReturn(siOp);
+ String id = testedObject.validateServiceResourceIdInAAI("generatedId123", "siName123", reqDetails);
+ assertEquals("siId123", id);
+ }
+
+ @Test
+ public void validateServiceResourceIdInAAIDifferentModelVersionId() throws Exception {
+ RequestDetails reqDetails = setupRequestDetails();
+ reqDetails.getModelInfo().setModelVersionId("1234567");
+
+ ServiceInstance si = new ServiceInstance();
+ si.setModelVersionId("9999999");
+ ServiceInstances serviceInstances = new ServiceInstances();
+ serviceInstances.getServiceInstance().add(si);
+ Optional<ServiceInstance> siOp = Optional.of(si);
+
+ when(bbInputSetupUtilsMock.getAAIServiceInstanceByName("id123", "subServiceType123", "siName123"))
+ .thenReturn(siOp);
+
+ this.expectedException.expect(DuplicateNameException.class);
+ this.expectedException.expectMessage(containsString(
+ "serviceInstance with name (siName123) and different version id (1234567) already exists. The name must be unique."));
+
+ String id = testedObject.validateServiceResourceIdInAAI("generatedId123", "siName123", reqDetails);
+ assertEquals("siId123", id);
+ }
+
+ @Test
+ public void validateServiceResourceIdInAAIDuplicateNameTest() throws Exception {
+ RequestDetails reqDetails = setupRequestDetails();
+ ServiceInstance si = new ServiceInstance();
+ si.setModelVersionId("1234567");
+ ServiceInstances serviceInstances = new ServiceInstances();
+ serviceInstances.getServiceInstance().add(si);
+
+ when(bbInputSetupUtilsMock.getAAIServiceInstancesGloballyByName("siName")).thenReturn(serviceInstances);
+
+ this.expectedException.expect(DuplicateNameException.class);
+ this.expectedException.expectMessage(containsString(
+ "serviceInstance with name (siName) and global-customer-id (null), service-type (null), model-version-id (1234567) already exists. The name must be unique."));
+
+ testedObject.validateServiceResourceIdInAAI("generatedId123", "siName", reqDetails);
+ }
+
+ @Test
+ public void validateServiceResourceIdInAAIDuplicateNameMultipleTest() throws Exception {
+ RequestDetails reqDetails = setupRequestDetails();
+ ServiceInstances serviceInstances = new ServiceInstances();
+ serviceInstances.getServiceInstance().add(new ServiceInstance());
+ serviceInstances.getServiceInstance().add(new ServiceInstance());
+
+ when(bbInputSetupUtilsMock.getAAIServiceInstancesGloballyByName("siName")).thenReturn(serviceInstances);
+
+ this.expectedException.expect(DuplicateNameException.class);
+ this.expectedException.expectMessage(containsString(
+ "serviceInstance with name (siName) and multiple combination of model-version-id + service-type + global-customer-id already exists. The name must be unique."));
+
+ testedObject.validateServiceResourceIdInAAI("generatedId123", "siName", reqDetails);
+ }
+
+ @Test
+ public void validateNetworkResourceIdInAAITest() throws Exception {
+ RequestDetails reqDetails = setupRequestDetails();
+ String id = testedObject.validateNetworkResourceIdInAAI("generatedId123", "name123", reqDetails,
+ new WorkflowResourceIds());
+ assertEquals("generatedId123", id);
+ }
+
+ @Test
+ public void validateNetworkResourceIdInAAISameModelCustIdTest() throws Exception {
+ RequestDetails reqDetails = setupRequestDetails();
+ WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds();
+ workflowResourceIds.setServiceInstanceId("siId123");
+ L3Network network = new L3Network();
+ network.setNetworkId("id123");
+ network.setModelCustomizationId("1234567");
+ Optional<L3Network> opNetwork = Optional.of(network);
+
+ when(bbInputSetupUtilsMock.getRelatedNetworkByNameFromServiceInstance("siId123", "name123"))
+ .thenReturn(opNetwork);
+
+ String id = testedObject.validateNetworkResourceIdInAAI("generatedId123", "name123", reqDetails,
+ workflowResourceIds);
+ assertEquals("id123", id);
+ }
+
+ @Test
+ public void validateNetworkResourceIdInAAIDuplicateNameTest() throws Exception {
+ RequestDetails reqDetails = setupRequestDetails();
+ WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds();
+ workflowResourceIds.setServiceInstanceId("siId123");
+ L3Network network = new L3Network();
+ network.setModelCustomizationId("9999999");
+ Optional<L3Network> opNetwork = Optional.of(network);
+
+ when(bbInputSetupUtilsMock.getRelatedNetworkByNameFromServiceInstance("siId123", "name123"))
+ .thenReturn(opNetwork);
+
+ this.expectedException.expect(DuplicateNameException.class);
+ this.expectedException.expectMessage(containsString(
+ "l3Network with name (name123), same parent and different customization id (9999999) already exists. The name must be unique."));
+
+ testedObject.validateNetworkResourceIdInAAI("generatedId123", "name123", reqDetails, workflowResourceIds);
+ }
+
+ @Test
+ public void validateNetworkResourceIdInAAINotGloballyUniqueTest() throws Exception {
+ RequestDetails reqDetails = setupRequestDetails();
+ WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds();
+ workflowResourceIds.setServiceInstanceId("siId123");
+
+ when(bbInputSetupUtilsMock.existsAAINetworksGloballyByName("name123")).thenReturn(true);
+
+ this.expectedException.expect(DuplicateNameException.class);
+ this.expectedException.expectMessage(containsString(
+ "l3Network with name (name123) id (siId123) and different parent relationship already exists. The name must be unique."));
+
+ testedObject.validateNetworkResourceIdInAAI("generatedId123", "name123", reqDetails, workflowResourceIds);
+ }
+
+ @Test
+ public void validateVnfResourceIdInAAITest() throws Exception {
+ RequestDetails reqDetails = setupRequestDetails();
+ String id = testedObject.validateVnfResourceIdInAAI("generatedId123", "vnfName123", reqDetails,
+ new WorkflowResourceIds());
+ assertEquals("generatedId123", id);
+ }
+
+ @Test
+ public void validateVnfResourceIdInAAISameModelCustomizationIdTest() throws Exception {
+ RequestDetails reqDetails = setupRequestDetails();
+ WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds();
+ workflowResourceIds.setServiceInstanceId("siId123");
+
+ GenericVnf vnf = new GenericVnf();
+ vnf.setVnfId("id123");
+ vnf.setModelCustomizationId("1234567");
+ Optional<GenericVnf> opVnf = Optional.of(vnf);
+
+ when(bbInputSetupUtilsMock.getRelatedVnfByNameFromServiceInstance("siId123", "vnfName123")).thenReturn(opVnf);
+ String id = testedObject.validateVnfResourceIdInAAI("generatedId123", "vnfName123", reqDetails,
+ workflowResourceIds);
+ assertEquals("id123", id);
+ }
+
+ @Test
+ public void validateVnfResourceIdInAAIDiffModelCustomizationIdTest() throws Exception {
+ RequestDetails reqDetails = setupRequestDetails();
+ WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds();
+ workflowResourceIds.setServiceInstanceId("siId123");
+ GenericVnf vnf = new GenericVnf();
+ vnf.setModelCustomizationId("9999999");
+ Optional<GenericVnf> opVnf = Optional.of(vnf);
+
+ when(bbInputSetupUtilsMock.getRelatedVnfByNameFromServiceInstance("siId123", "vnfName123")).thenReturn(opVnf);
+
+ this.expectedException.expect(DuplicateNameException.class);
+ this.expectedException.expectMessage(containsString(
+ "generic-vnf with name (vnfName123), same parent and different customization id (9999999) already exists. The name must be unique."));
+
+ testedObject.validateVnfResourceIdInAAI("generatedId123", "vnfName123", reqDetails, workflowResourceIds);
+ }
+
+ @Test
+ public void validateVnfResourceIdInAAINotGloballyUniqueTest() throws Exception {
+ RequestDetails reqDetails = setupRequestDetails();
+ GenericVnf vnf = new GenericVnf();
+ vnf.setVnfId("id123");
+ GenericVnfs genericVnfs = new GenericVnfs();
+ genericVnfs.getGenericVnf().add(vnf);
+
+ when(bbInputSetupUtilsMock.getAAIVnfsGloballyByName("vnfName123")).thenReturn(genericVnfs);
+
+ this.expectedException.expect(DuplicateNameException.class);
+ this.expectedException.expectMessage(containsString(
+ "generic-vnf with name (vnfName123) id (id123) and different parent relationship already exists. The name must be unique."));
+
+ testedObject.validateVnfResourceIdInAAI("generatedId123", "vnfName123", reqDetails, new WorkflowResourceIds());
+ }
+
+ @Test
+ public void validateVfModuleResourceIdTest() throws Exception {
+ RequestDetails reqDetails = setupRequestDetails();
+ String id = testedObject.validateVfModuleResourceIdInAAI("generatedId123", "name123", reqDetails,
+ new WorkflowResourceIds());
+ assertEquals("generatedId123", id);
+ }
+
+ @Test
+ public void validateVfModuleResourceIdSameModelCustIdTest() throws Exception {
+ RequestDetails reqDetails = setupRequestDetails();
+ WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds();
+ workflowResourceIds.setVnfId("vnfId123");
+ VfModules vfModules = new VfModules();
+ VfModule vfModule = new VfModule();
+ vfModule.setVfModuleId("id123");
+ vfModule.setVfModuleName("name123");
+ vfModule.setModelCustomizationId("1234567");
+ vfModules.getVfModule().add(vfModule);
+ GenericVnf vnf = new GenericVnf();
+ vnf.setVfModules(vfModules);
+
+ when(bbInputSetupUtilsMock.getAAIGenericVnf("vnfId123")).thenReturn(vnf);
+
+ String id = testedObject.validateVfModuleResourceIdInAAI("generatedId123", "name123", reqDetails,
+ workflowResourceIds);
+ assertEquals("id123", id);
+ }
+
+ @Test
+ public void validateVfModuleResourceIdDifferentModelCustIdTest() throws Exception {
+ RequestDetails reqDetails = setupRequestDetails();
+ WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds();
+ workflowResourceIds.setVnfId("vnfId123");
+ VfModules vfModules = new VfModules();
+ VfModule vfModule = new VfModule();
+ vfModule.setVfModuleName("name123");
+ vfModule.setModelCustomizationId("9999999");
+ vfModules.getVfModule().add(vfModule);
+ GenericVnf vnf = new GenericVnf();
+ vnf.setVfModules(vfModules);
+
+ when(bbInputSetupUtilsMock.getAAIGenericVnf("vnfId123")).thenReturn(vnf);
+
+ this.expectedException.expect(DuplicateNameException.class);
+ this.expectedException.expectMessage(containsString(
+ "vfModule with name (name123), same parent and different customization id (1234567) already exists. The name must be unique."));
+
+ testedObject.validateVfModuleResourceIdInAAI("generatedId123", "name123", reqDetails, workflowResourceIds);
+ }
+
+ @Test
+ public void validateVfModuleResourceIdNotGloballyUniqueTest() throws Exception {
+ RequestDetails reqDetails = setupRequestDetails();
+ WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds();
+ when(bbInputSetupUtilsMock.existsAAIVfModuleGloballyByName("name123")).thenReturn(true);
+
+ this.expectedException.expect(DuplicateNameException.class);
+ this.expectedException
+ .expectMessage(containsString("vfModule with name name123 already exists. The name must be unique."));
+
+ testedObject.validateVfModuleResourceIdInAAI("generatedId123", "name123", reqDetails, workflowResourceIds);
+ }
+
+ @Test
+ public void validateVolumeGroupResourceIdInAAITest() throws Exception {
+ RequestDetails reqDetails = setupRequestDetails();
+ String id = testedObject.validateVolumeGroupResourceIdInAAI("generatedId123", "name123", reqDetails,
+ new WorkflowResourceIds());
+ assertEquals("generatedId123", id);
+ }
+
+ @Test
+ public void validateVolumeGroupResourceIdInAAISameModelCustIdTest() throws Exception {
+ RequestDetails reqDetails = setupRequestDetails();
+ WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds();
+ workflowResourceIds.setVnfId("vnfId123");
+ VolumeGroup volumeGroup = new VolumeGroup();
+ volumeGroup.setVolumeGroupId("id123");
+ volumeGroup.setVfModuleModelCustomizationId("1234567");
+ Optional<VolumeGroup> opVolumeGroup = Optional.of(volumeGroup);
+
+ when(bbInputSetupUtilsMock.getRelatedVolumeGroupByNameFromVnf("vnfId123", "name123")).thenReturn(opVolumeGroup);
+ String id = testedObject.validateResourceIdInAAI("generatedId123", WorkflowType.VOLUMEGROUP, "name123",
+ reqDetails, workflowResourceIds);
+
+ assertEquals("id123", id);
+ }
+
+ @Test
+ public void validateVolumeGroupResourceIdInAAIDifferentModelCustIdTest() throws Exception {
+ RequestDetails reqDetails = setupRequestDetails();
+ WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds();
+ workflowResourceIds.setVnfId("vnfId123");
+ VolumeGroup volumeGroup = new VolumeGroup();
+ volumeGroup.setVolumeGroupName("name123");
+ volumeGroup.setVfModuleModelCustomizationId("9999999");
+ Optional<VolumeGroup> opVolumeGroup = Optional.of(volumeGroup);
+
+ when(bbInputSetupUtilsMock.getRelatedVolumeGroupByNameFromVnf("vnfId123", "name123")).thenReturn(opVolumeGroup);
+
+ this.expectedException.expect(DuplicateNameException.class);
+ this.expectedException.expectMessage(
+ containsString("volumeGroup with name name123 already exists. The name must be unique."));
+
+ testedObject.validateResourceIdInAAI("generatedId123", WorkflowType.VOLUMEGROUP, "name123", reqDetails,
+ workflowResourceIds);
+ }
+
+ @Test
+ public void validateVolumeGroupResourceIdInAAINotGloballyUniqueTest() throws Exception {
+ RequestDetails reqDetails = setupRequestDetails();
+ WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds();
+ when(bbInputSetupUtilsMock.existsAAIVolumeGroupGloballyByName("name123")).thenReturn(true);
+
+ this.expectedException.expect(DuplicateNameException.class);
+ this.expectedException.expectMessage(
+ containsString("volumeGroup with name name123 already exists. The name must be unique."));
+
+ testedObject.validateResourceIdInAAI("generatedId123", WorkflowType.VOLUMEGROUP, "name123", reqDetails,
+ workflowResourceIds);
+ }
+
+ @Test
+ public void validateConfigurationResourceIdInAAITest() throws Exception {
+ RequestDetails reqDetails = setupRequestDetails();
+ String id = testedObject.validateConfigurationResourceIdInAAI("generatedId123", "name123", reqDetails,
+ new WorkflowResourceIds());
+ assertEquals("generatedId123", id);
+ }
+
+ @Test
+ public void validateConfigurationResourceIdInAAISameModelCustIdTest() throws Exception {
+ RequestDetails reqDetails = setupRequestDetails();
+ WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds();
+ workflowResourceIds.setServiceInstanceId("siId123");
+ org.onap.aai.domain.yang.Configuration configuration = new org.onap.aai.domain.yang.Configuration();
+ configuration.setConfigurationId("id123");
+ configuration.setModelCustomizationId("1234567");
+ Optional<org.onap.aai.domain.yang.Configuration> opConfiguration = Optional.of(configuration);
+
+ when(bbInputSetupUtilsMock.getRelatedConfigurationByNameFromServiceInstance("siId123", "name123"))
+ .thenReturn(opConfiguration);
+
+ String id = testedObject.validateConfigurationResourceIdInAAI("generatedId123", "name123", reqDetails,
+ workflowResourceIds);
+ assertEquals("id123", id);
+ }
+
+ @Test
+ public void validateConfigurationResourceIdInAAIDifferentModelCustIdTest() throws Exception {
+ RequestDetails reqDetails = setupRequestDetails();
+ WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds();
+ workflowResourceIds.setServiceInstanceId("siId123");
+ org.onap.aai.domain.yang.Configuration configuration = new org.onap.aai.domain.yang.Configuration();
+ configuration.setConfigurationId("id123");
+ configuration.setModelCustomizationId("9999999");
+ Optional<org.onap.aai.domain.yang.Configuration> opConfiguration = Optional.of(configuration);
+
+ when(bbInputSetupUtilsMock.getRelatedConfigurationByNameFromServiceInstance("siId123", "name123"))
+ .thenReturn(opConfiguration);
+ this.expectedException.expect(DuplicateNameException.class);
+ this.expectedException.expectMessage(containsString(
+ "configuration with name (name123), same parent and different customization id (id123) already exists. The name must be unique."));
+
+ testedObject.validateConfigurationResourceIdInAAI("generatedId123", "name123", reqDetails, workflowResourceIds);
+ }
+
+ @Test
+ public void validateConfigurationResourceIdInAAINotGloballyUniqueTest() throws Exception {
+ RequestDetails reqDetails = setupRequestDetails();
+ WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds();
+
+ when(bbInputSetupUtilsMock.existsAAIConfigurationGloballyByName("name123")).thenReturn(true);
+ this.expectedException.expect(DuplicateNameException.class);
+ this.expectedException.expectMessage(
+ containsString("configuration with name name123 already exists. The name must be unique."));
+
+ testedObject.validateConfigurationResourceIdInAAI("generatedId123", "name123", reqDetails, workflowResourceIds);
+ }
+
+ private RequestDetails setupRequestDetails() {
+ RequestDetails reqDetails = new RequestDetails();
+ SubscriberInfo subInfo = new SubscriberInfo();
+ subInfo.setGlobalSubscriberId("id123");
+ reqDetails.setSubscriberInfo(subInfo);
+ RequestParameters reqParams = new RequestParameters();
+ reqParams.setSubscriptionServiceType("subServiceType123");
+ reqDetails.setRequestParameters(reqParams);
+ ModelInfo modelInfo = new ModelInfo();
+ modelInfo.setModelCustomizationId("1234567");
+ reqDetails.setModelInfo(modelInfo);
+ return reqDetails;
+ }
+}
diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ExecuteBuildingBlockBuilderTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ExecuteBuildingBlockBuilderTest.java
new file mode 100644
index 0000000000..c8914f6e02
--- /dev/null
+++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ExecuteBuildingBlockBuilderTest.java
@@ -0,0 +1,90 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Modifications Copyright (c) 2019 Samsung
+ * ================================================================================
+ * Modifications Copyright (c) 2021 Nokia
+ * ================================================================================
+ * Modifications Copyright (c) 2020 Tech Mahindra
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.bpmn.infrastructure.workflow.tasks;
+
+import org.junit.Test;
+import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock;
+import org.onap.so.db.catalog.beans.macro.OrchestrationFlow;
+import java.util.ArrayList;
+import java.util.List;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+
+public class ExecuteBuildingBlockBuilderTest {
+
+ final private ExecuteBuildingBlockBuilder executeBBBuilder = new ExecuteBuildingBlockBuilder();
+
+ @Test
+ public void sortVfModulesByBaseFirstTest() {
+ List<Resource> resources = new ArrayList<>();
+ Resource resource1 = new Resource(WorkflowType.VFMODULE, "111", false);
+ resource1.setBaseVfModule(false);
+ resources.add(resource1);
+ Resource resource2 = new Resource(WorkflowType.VFMODULE, "222", false);
+ resource2.setBaseVfModule(false);
+ resources.add(resource2);
+ Resource resource3 = new Resource(WorkflowType.VFMODULE, "333", false);
+ resource3.setBaseVfModule(true);
+ resources.add(resource3);
+
+ List<Resource> result = executeBBBuilder.sortVfModulesByBaseFirst(resources);
+ assertEquals("333", result.get(0).getResourceId());
+ assertEquals("222", result.get(1).getResourceId());
+ assertEquals("111", result.get(2).getResourceId());
+ }
+
+ @Test
+ public void sortVfModulesByBaseLastTest() {
+ List<Resource> resources = new ArrayList<>();
+ Resource resource1 = new Resource(WorkflowType.VFMODULE, "111", false);
+ resource1.setBaseVfModule(true);
+ resources.add(resource1);
+ Resource resource2 = new Resource(WorkflowType.VFMODULE, "222", false);
+ resource2.setBaseVfModule(false);
+ resources.add(resource2);
+ Resource resource3 = new Resource(WorkflowType.VFMODULE, "333", false);
+ resource3.setBaseVfModule(false);
+ resources.add(resource3);
+ List<Resource> result = executeBBBuilder.sortVfModulesByBaseLast(resources);
+ assertEquals("333", result.get(0).getResourceId());
+ assertEquals("222", result.get(1).getResourceId());
+ assertEquals("111", result.get(2).getResourceId());
+ }
+
+ @Test
+ public void verifyLackOfNullPointerExceptionForNullResource() {
+ ExecuteBuildingBlock result = null;
+ try {
+ result = executeBBBuilder.buildExecuteBuildingBlock(new OrchestrationFlow(), null, null, null, null, null,
+ false, null, null, null, false, null, null, true, null);
+ } catch (NullPointerException e) {
+ fail("NullPointerException should not be thrown when 'resource' is null");
+ }
+ assertNotNull(result);
+ }
+}
diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasksTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasksTest.java
index 3290bb3dce..5cd3055b5f 100644
--- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasksTest.java
+++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasksTest.java
@@ -22,6 +22,22 @@
package org.onap.so.bpmn.infrastructure.workflow.tasks;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyObject;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.isA;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Optional;
import org.camunda.bpm.engine.delegate.BpmnError;
import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake;
@@ -29,6 +45,7 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
+import org.mockito.ArgumentCaptor;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
@@ -47,24 +64,16 @@ import org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock;
import org.onap.so.bpmn.servicedecomposition.entities.ConfigurationResourceKeys;
import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock;
import org.onap.so.bpmn.servicedecomposition.entities.WorkflowResourceIds;
+import org.onap.so.db.catalog.beans.ConfigurationResource;
+import org.onap.so.db.catalog.beans.CvnfcConfigurationCustomization;
import org.onap.so.db.catalog.beans.VnfResourceCustomization;
import org.onap.so.db.request.beans.InfraActiveRequests;
import org.onap.so.serviceinstancebeans.ModelInfo;
+import org.onap.so.serviceinstancebeans.ModelType;
+import org.onap.so.serviceinstancebeans.RelatedInstance;
+import org.onap.so.serviceinstancebeans.RelatedInstanceList;
import org.onap.so.serviceinstancebeans.RequestDetails;
import org.springframework.core.env.Environment;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Optional;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.ArgumentMatchers.anyObject;
-import static org.mockito.ArgumentMatchers.anyString;
-import static org.mockito.ArgumentMatchers.isA;
-import static org.mockito.Mockito.doNothing;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.when;
public class WorkflowActionBBTasksTest extends BaseTaskTest {
@@ -96,6 +105,9 @@ public class WorkflowActionBBTasksTest extends BaseTaskTest {
@Rule
public ExpectedException thrown = ExpectedException.none();
+ @Mock
+ private DelegateExecution mockExecution;
+
@Before
public void before() throws Exception {
execution = new DelegateExecutionFake();
@@ -602,7 +614,228 @@ public class WorkflowActionBBTasksTest extends BaseTaskTest {
}
@Test
- public void postProcessingExecuteBBActivateVfModuleTest() throws CloneNotSupportedException {
+ public void postProcessingExecuteBBActivateVfModuleNotReplaceInstanceTest() throws CloneNotSupportedException {
+ WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds();
+ workflowResourceIds.setServiceInstanceId("1");
+ workflowResourceIds.setVnfId("1");
+
+ BuildingBlock bbActivateVfModule = new BuildingBlock().setBpmnFlowName("ActivateVfModuleBB");
+ ExecuteBuildingBlock ebbActivateVfModule = new ExecuteBuildingBlock().setBuildingBlock(bbActivateVfModule);
+ ebbActivateVfModule.setWorkflowResourceIds(workflowResourceIds);
+ ebbActivateVfModule.setResourceId("1");
+
+ ServiceInstance service = new ServiceInstance();
+ service.setServiceInstanceName("name");
+ service.setModelVersionId("1");
+ doReturn(service).when(bbSetupUtils).getAAIServiceInstanceById("1");
+
+ GenericVnf vnf = new GenericVnf();
+ vnf.setVnfName("name");
+ vnf.setModelCustomizationId("1");
+ doReturn(vnf).when(bbSetupUtils).getAAIGenericVnf("1");
+
+ VfModule vfModule = new VfModule();
+ vfModule.setVfModuleName("name");
+ vfModule.setModelCustomizationId("1");
+ doReturn(vfModule).when(bbSetupUtils).getAAIVfModule("1", "1");
+
+ List<org.onap.aai.domain.yang.Vnfc> vnfcs = new ArrayList<org.onap.aai.domain.yang.Vnfc>();
+ org.onap.aai.domain.yang.Vnfc vnfc = new org.onap.aai.domain.yang.Vnfc();
+ vnfc.setModelInvariantId("1");
+ vnfc.setVnfcName("name");
+ vnfc.setModelCustomizationId("2");
+ vnfcs.add(vnfc);
+ doReturn(vnfcs).when(workflowAction).getRelatedResourcesInVfModule(any(), any(), any(), any());
+
+ CvnfcConfigurationCustomization vfModuleCustomization = new CvnfcConfigurationCustomization();
+ ConfigurationResource configuration = new ConfigurationResource();
+ configuration.setToscaNodeType("FabricConfiguration");
+ configuration.setModelUUID("1");
+ vfModuleCustomization.setConfigurationResource(configuration);
+
+ doReturn(vfModuleCustomization).when(catalogDbClient).getCvnfcCustomization("1", "1", "1", "2");
+
+ prepareDelegateExecution();
+ List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
+ flowsToExecute.add(ebbActivateVfModule);
+
+ execution.setVariable("requestAction", "createInstance");
+ execution.setVariable("completed", true);
+
+ ArgumentCaptor<DelegateExecution> executionCaptor = ArgumentCaptor.forClass(DelegateExecution.class);
+ ArgumentCaptor<ExecuteBuildingBlock> bbCaptor = ArgumentCaptor.forClass(ExecuteBuildingBlock.class);
+ ArgumentCaptor<List> listCaptor = ArgumentCaptor.forClass(List.class);
+ workflowActionBBTasks.postProcessingExecuteBBActivateVfModule(execution, ebbActivateVfModule, flowsToExecute);
+ verify(workflowActionBBTasks, times(1)).postProcessingExecuteBBActivateVfModule(executionCaptor.capture(),
+ bbCaptor.capture(), listCaptor.capture());
+ assertEquals(false, executionCaptor.getAllValues().get(0).getVariable("completed"));
+ assertEquals(2, ((ArrayList) executionCaptor.getAllValues().get(0).getVariable("flowsToExecute")).size());
+ assertEquals("2",
+ ((ExecuteBuildingBlock) ((ArrayList) executionCaptor.getAllValues().get(0)
+ .getVariable("flowsToExecute")).get(1)).getConfigurationResourceKeys()
+ .getCvnfcCustomizationUUID());
+ assertEquals("AddFabricConfigurationBB", ((ExecuteBuildingBlock) ((ArrayList) executionCaptor.getAllValues()
+ .get(0).getVariable("flowsToExecute")).get(1)).getBuildingBlock().getBpmnFlowName());
+ }
+
+ @Test
+ public void postProcessingExecuteBBActivateVfModuleReplaceInstanceHasConfigurationTest()
+ throws CloneNotSupportedException {
+ RequestDetails reqDetails = new RequestDetails();
+ RelatedInstanceList[] list = new RelatedInstanceList[2];
+ RelatedInstanceList vnfList = new RelatedInstanceList();
+ RelatedInstanceList serviceList = new RelatedInstanceList();
+ list[0] = vnfList;
+ list[1] = serviceList;
+ RelatedInstance vnfInstance = new RelatedInstance();
+ RelatedInstance serviceInstance = new RelatedInstance();
+ ModelInfo vnfModelInfo = new ModelInfo();
+ vnfModelInfo.setModelType(ModelType.vnf);
+ vnfModelInfo.setModelCustomizationId("1");
+ ModelInfo serviceModelInfo = new ModelInfo();
+ serviceModelInfo.setModelType(ModelType.service);
+ serviceModelInfo.setModelVersionId("1");
+ vnfInstance.setModelInfo(vnfModelInfo);
+ serviceInstance.setModelInfo(serviceModelInfo);
+ reqDetails.setRelatedInstanceList(list);
+ vnfList.setRelatedInstance(vnfInstance);
+ serviceList.setRelatedInstance(serviceInstance);
+ ModelInfo vfModuleInfo = new ModelInfo();
+ vfModuleInfo.setModelCustomizationId("1");
+ reqDetails.setModelInfo(vfModuleInfo);
+ BuildingBlock bbAddFabric = new BuildingBlock().setBpmnFlowName("AddFabricConfigurationBB");
+ ExecuteBuildingBlock ebbAddFabric = new ExecuteBuildingBlock().setBuildingBlock(bbAddFabric);
+ WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds();
+ workflowResourceIds.setServiceInstanceId("1");
+ workflowResourceIds.setVnfId("1");
+ ebbAddFabric.setWorkflowResourceIds(workflowResourceIds);
+ ebbAddFabric.setResourceId("1");
+
+ BuildingBlock bbActivateVfModule = new BuildingBlock().setBpmnFlowName("ActivateVfModuleBB");
+ ExecuteBuildingBlock ebbActivateVfModule = new ExecuteBuildingBlock().setBuildingBlock(bbActivateVfModule);
+ ebbActivateVfModule.setWorkflowResourceIds(workflowResourceIds);
+ ebbActivateVfModule.setResourceId("1");
+ ConfigurationResourceKeys configurationResourceKeys = new ConfigurationResourceKeys();
+ ebbAddFabric.setConfigurationResourceKeys(configurationResourceKeys);
+ ebbActivateVfModule.setRequestDetails(reqDetails);
+
+ ServiceInstance service = new ServiceInstance();
+ service.setServiceInstanceName("name");
+ service.setModelVersionId("1");
+ doReturn(service).when(bbSetupUtils).getAAIServiceInstanceById("1");
+
+ GenericVnf vnf = new GenericVnf();
+ vnf.setVnfName("name");
+ vnf.setModelCustomizationId("1");
+ doReturn(vnf).when(bbSetupUtils).getAAIGenericVnf("1");
+
+ VfModule vfModule = new VfModule();
+ vfModule.setVfModuleName("name");
+ vfModule.setModelCustomizationId("1");
+ doReturn(vfModule).when(bbSetupUtils).getAAIVfModule("1", "1");
+
+ List<org.onap.aai.domain.yang.Vnfc> vnfcs = new ArrayList<org.onap.aai.domain.yang.Vnfc>();
+ org.onap.aai.domain.yang.Vnfc vnfc = new org.onap.aai.domain.yang.Vnfc();
+ vnfc.setModelInvariantId("1");
+ vnfc.setVnfcName("name");
+ vnfc.setModelCustomizationId("2");
+ vnfcs.add(vnfc);
+ doReturn(vnfcs).when(workflowAction).getRelatedResourcesInVfModule(any(), any(), any(), any());
+
+ CvnfcConfigurationCustomization vfModuleCustomization = new CvnfcConfigurationCustomization();
+ ConfigurationResource configuration = new ConfigurationResource();
+ configuration.setToscaNodeType("FabricConfiguration");
+ configuration.setModelUUID("1");
+ vfModuleCustomization.setConfigurationResource(configuration);
+
+ doReturn(vfModuleCustomization).when(catalogDbClient).getCvnfcCustomization("1", "1", "1", "2");
+
+ prepareDelegateExecution();
+ List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
+ flowsToExecute.add(ebbActivateVfModule);
+
+ ArgumentCaptor<DelegateExecution> executionCaptor = ArgumentCaptor.forClass(DelegateExecution.class);
+ ArgumentCaptor<ExecuteBuildingBlock> bbCaptor = ArgumentCaptor.forClass(ExecuteBuildingBlock.class);
+ ArgumentCaptor<List> listCaptor = ArgumentCaptor.forClass(List.class);
+
+ execution.setVariable("requestAction", "replaceInstance");
+ execution.setVariable("completed", true);
+ workflowActionBBTasks.postProcessingExecuteBBActivateVfModule(execution, ebbActivateVfModule, flowsToExecute);
+ verify(workflowActionBBTasks, times(1)).postProcessingExecuteBBActivateVfModule(executionCaptor.capture(),
+ bbCaptor.capture(), listCaptor.capture());
+ assertEquals(false, executionCaptor.getAllValues().get(0).getVariable("completed"));
+ assertEquals(2, ((ArrayList) executionCaptor.getAllValues().get(0).getVariable("flowsToExecute")).size());
+ assertEquals("2",
+ ((ExecuteBuildingBlock) ((ArrayList) executionCaptor.getAllValues().get(0)
+ .getVariable("flowsToExecute")).get(1)).getConfigurationResourceKeys()
+ .getCvnfcCustomizationUUID());
+ }
+
+ @Test
+ public void postProcessingExecuteBBActivateVfModuleReplaceInstanceHasNoConfigurationTest()
+ throws CloneNotSupportedException {
+
+ WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds();
+ workflowResourceIds.setServiceInstanceId("1");
+ workflowResourceIds.setVnfId("1");
+
+ BuildingBlock bbActivateVfModule = new BuildingBlock().setBpmnFlowName("ActivateVfModuleBB");
+ ExecuteBuildingBlock ebbActivateVfModule = new ExecuteBuildingBlock().setBuildingBlock(bbActivateVfModule);
+ ebbActivateVfModule.setWorkflowResourceIds(workflowResourceIds);
+ ebbActivateVfModule.setResourceId("1");
+
+ ServiceInstance service = new ServiceInstance();
+ service.setServiceInstanceName("name");
+ service.setModelVersionId("1");
+ doReturn(service).when(bbSetupUtils).getAAIServiceInstanceById("1");
+
+ GenericVnf vnf = new GenericVnf();
+ vnf.setVnfName("name");
+ vnf.setModelCustomizationId("1");
+ doReturn(vnf).when(bbSetupUtils).getAAIGenericVnf("1");
+
+ VfModule vfModule = new VfModule();
+ vfModule.setVfModuleName("name");
+ vfModule.setModelCustomizationId("1");
+ doReturn(vfModule).when(bbSetupUtils).getAAIVfModule("1", "1");
+
+ List<org.onap.aai.domain.yang.Vnfc> vnfcs = new ArrayList<org.onap.aai.domain.yang.Vnfc>();
+ org.onap.aai.domain.yang.Vnfc vnfc = new org.onap.aai.domain.yang.Vnfc();
+ vnfc.setModelInvariantId("1");
+ vnfc.setVnfcName("name");
+ vnfc.setModelCustomizationId("2");
+ vnfcs.add(vnfc);
+ doReturn(vnfcs).when(workflowAction).getRelatedResourcesInVfModule(any(), any(), any(), any());
+
+ CvnfcConfigurationCustomization vfModuleCustomization = new CvnfcConfigurationCustomization();
+ ConfigurationResource configuration = new ConfigurationResource();
+ configuration.setToscaNodeType("FabricConfiguration");
+ configuration.setModelUUID("1");
+ vfModuleCustomization.setConfigurationResource(configuration);
+
+ doReturn(vfModuleCustomization).when(catalogDbClient).getCvnfcCustomization("1", "1", "1", "2");
+
+ prepareDelegateExecution();
+ List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
+ flowsToExecute.add(ebbActivateVfModule);
+
+ ArgumentCaptor<DelegateExecution> executionCaptor = ArgumentCaptor.forClass(DelegateExecution.class);
+ ArgumentCaptor<ExecuteBuildingBlock> bbCaptor = ArgumentCaptor.forClass(ExecuteBuildingBlock.class);
+ ArgumentCaptor<List> listCaptor = ArgumentCaptor.forClass(List.class);
+
+ execution.setVariable("requestAction", "replaceInstance");
+ execution.setVariable("completed", true);
+
+ workflowActionBBTasks.postProcessingExecuteBBActivateVfModule(execution, ebbActivateVfModule, flowsToExecute);
+ verify(workflowActionBBTasks, times(1)).postProcessingExecuteBBActivateVfModule(executionCaptor.capture(),
+ bbCaptor.capture(), listCaptor.capture());
+ assertEquals(true, executionCaptor.getAllValues().get(0).getVariable("completed"));
+ }
+
+
+
+ @Test
+ public void getExecuteBBForConfigTest() throws CloneNotSupportedException {
BuildingBlock bbActivateVfModule = new BuildingBlock().setBpmnFlowName("ActivateVfModuleBB");
ExecuteBuildingBlock ebbActivateVfModule = new ExecuteBuildingBlock().setBuildingBlock(bbActivateVfModule);
diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionExtractResourcesAAITest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionExtractResourcesAAITest.java
new file mode 100644
index 0000000000..35a5bfefd7
--- /dev/null
+++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionExtractResourcesAAITest.java
@@ -0,0 +1,102 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Modifications Copyright (c) 2020 Nokia
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.bpmn.infrastructure.workflow.tasks;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Optional;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.aai.domain.yang.VpnBinding;
+import org.onap.aaiclient.client.aai.entities.AAIResultWrapper;
+import org.onap.aaiclient.client.aai.entities.Relationships;
+import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri;
+import org.onap.aaiclient.client.aai.entities.uri.AAISimpleUri;
+import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types;
+import org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration;
+import org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetupUtils;
+
+@RunWith(MockitoJUnitRunner.class)
+public class WorkflowActionExtractResourcesAAITest {
+
+ private static final String CONFIGURATION_ID = "configTestId";
+ private static final String VPN_ID = "vpnTestId";
+
+ @Mock
+ private BBInputSetupUtils bbInputSetupUtils;
+ @InjectMocks
+ private WorkflowActionExtractResourcesAAI testedObject;
+
+ @Test
+ public void extractRelationshipsConfigurationSuccess() {
+ // given
+ Relationships relationships = mock(Relationships.class);
+ when(relationships.getByType(Types.CONFIGURATION)).thenReturn(getConfigurationList());
+ // when
+ Optional<Configuration> resultOpt = testedObject.extractRelationshipsConfiguration(relationships);
+ // then
+ assertThat(resultOpt).isNotEmpty();
+ assertThat(resultOpt.get().getConfigurationId()).isEqualTo(CONFIGURATION_ID);
+ }
+
+ @Test
+ public void extractRelationshipsConfiguration_notFound() {
+ // given
+ Relationships relationships = mock(Relationships.class);
+ when(relationships.getByType(Types.CONFIGURATION)).thenReturn(Collections.emptyList());
+ // when
+ Optional<Configuration> resultOpt = testedObject.extractRelationshipsConfiguration(relationships);
+ // then
+ assertThat(resultOpt).isEmpty();
+ }
+
+ @Test
+ public void extractRelationshipsVpnBindingSuccess() {
+ // given
+ Relationships relationships = mock(Relationships.class);
+ AAIResourceUri aaiResourceUri = mock(AAISimpleUri.class);
+ List<AAIResourceUri> aaiResourceUriList = new ArrayList<>();
+ aaiResourceUriList.add(aaiResourceUri);
+ when(relationships.getRelatedUris(Types.VPN_BINDING)).thenReturn(aaiResourceUriList);
+ AAIResultWrapper aaiResultWrapper = new AAIResultWrapper("{\"vpn-id\" : \"" + VPN_ID + "\"}");
+ when(bbInputSetupUtils.getAAIResourceDepthOne(aaiResourceUri)).thenReturn(aaiResultWrapper);
+ // when
+ Optional<VpnBinding> resultOpt = testedObject.extractRelationshipsVpnBinding(relationships);
+ // then
+ assertThat(resultOpt).isNotEmpty();
+ assertThat(resultOpt.get().getVpnId()).isEqualTo(VPN_ID);
+ }
+
+ private List<AAIResultWrapper> getConfigurationList() {
+ List<AAIResultWrapper> configurations = new ArrayList<>();
+ AAIResultWrapper aaiResultWrapper =
+ new AAIResultWrapper("{\"configuration-id\" : \"" + CONFIGURATION_ID + "\"}");
+ configurations.add(aaiResultWrapper);
+ return configurations;
+ }
+}
diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionTest.java
index 7f22c5138e..100c32f1c2 100644
--- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionTest.java
+++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionTest.java
@@ -35,6 +35,7 @@ import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyList;
import static org.mockito.ArgumentMatchers.anyObject;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
@@ -50,9 +51,7 @@ import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.HashMap;
import java.util.List;
-import java.util.Map;
import java.util.Optional;
import java.util.UUID;
import org.camunda.bpm.engine.delegate.BpmnError;
@@ -67,15 +66,10 @@ import org.junit.rules.ExpectedException;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Spy;
-import org.onap.aai.domain.yang.GenericVnf;
-import org.onap.aai.domain.yang.GenericVnfs;
-import org.onap.aai.domain.yang.L3Network;
import org.onap.aai.domain.yang.Relationship;
import org.onap.aai.domain.yang.RelationshipList;
import org.onap.aai.domain.yang.ServiceInstance;
-import org.onap.aai.domain.yang.ServiceInstances;
import org.onap.aai.domain.yang.VfModule;
-import org.onap.aai.domain.yang.VfModules;
import org.onap.aai.domain.yang.VolumeGroup;
import org.onap.aaiclient.client.aai.entities.AAIResultWrapper;
import org.onap.aaiclient.client.aai.entities.Relationships;
@@ -107,11 +101,8 @@ import org.onap.so.db.catalog.beans.Service;
import org.onap.so.db.catalog.beans.VfModuleCustomization;
import org.onap.so.db.catalog.beans.macro.NorthBoundRequest;
import org.onap.so.db.catalog.beans.macro.OrchestrationFlow;
-import org.onap.so.serviceinstancebeans.ModelInfo;
import org.onap.so.serviceinstancebeans.RequestDetails;
-import org.onap.so.serviceinstancebeans.RequestParameters;
import org.onap.so.serviceinstancebeans.ServiceInstancesRequest;
-import org.onap.so.serviceinstancebeans.SubscriberInfo;
import org.springframework.core.env.Environment;
public class WorkflowActionTest extends BaseTaskTest {
@@ -127,14 +118,23 @@ public class WorkflowActionTest extends BaseTaskTest {
@Mock
protected Environment environment;
+ @Mock
+ protected UserParamsServiceTraversal userParamsServiceTraversal;
+
+ @Mock
+ private AaiResourceIdValidator aaiResourceIdValidator;
@InjectMocks
protected WorkflowAction workflowAction;
+
private DelegateExecution execution;
@InjectMocks
@Spy
protected WorkflowAction SPY_workflowAction;
+ @Spy
+ protected ExecuteBuildingBlockBuilder executeBuildingBlockBuilder;
+
@Rule
public ExpectedException thrown = ExpectedException.none();
@@ -163,6 +163,7 @@ public class WorkflowActionTest extends BaseTaskTest {
when(bbSetupUtils.getAAIServiceInstanceByName(anyString(), anyObject())).thenReturn(servInstance);
workflowAction.setBbInputSetupUtils(bbSetupUtils);
workflowAction.setBbInputSetup(bbInputSetup);
+
}
/**
@@ -183,6 +184,7 @@ public class WorkflowActionTest extends BaseTaskTest {
when(catalogDbClient.getNorthBoundRequestByActionAndIsALaCarteAndRequestScopeAndCloudOwner(gAction, resource,
true, "my-custom-cloud-owner")).thenReturn(northBoundRequest);
+
workflowAction.selectExecutionList(execution);
List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
assertEqualsBulkFlowName(ebbs, "AssignNetwork1802BB", "CreateNetworkBB", "ActivateNetworkBB");
@@ -203,6 +205,7 @@ public class WorkflowActionTest extends BaseTaskTest {
when(catalogDbClient.getNorthBoundRequestByActionAndIsALaCarteAndRequestScopeAndCloudOwner(gAction, resource,
true, "my-custom-cloud-owner")).thenReturn(northBoundRequest);
+
workflowAction.selectExecutionList(execution);
List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
assertEqualsBulkFlowName(ebbs, "DeactivateNetworkBB", "DeleteNetworkBB", "UnassignNetwork1802BB");
@@ -223,6 +226,7 @@ public class WorkflowActionTest extends BaseTaskTest {
when(catalogDbClient.getNorthBoundRequestByActionAndIsALaCarteAndRequestScopeAndCloudOwner(gAction, resource,
true, "my-custom-cloud-owner")).thenReturn(northBoundRequest);
+
workflowAction.selectExecutionList(execution);
List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
assertEqualsBulkFlowName(ebbs, "AssignServiceInstanceBB", "ActivateServiceInstanceBB");
@@ -237,7 +241,7 @@ public class WorkflowActionTest extends BaseTaskTest {
doThrow(new DuplicateNameException(
"serviceInstance with name (instanceName) and different version id (3c40d244-808e-42ca-b09a-256d83d19d0a) already exists. The name must be unique."))
- .when(SPY_workflowAction).validateResourceIdInAAI(anyString(), eq(WorkflowType.SERVICE),
+ .when(aaiResourceIdValidator).validateResourceIdInAAI(anyString(), eq(WorkflowType.SERVICE),
eq("test"), any(RequestDetails.class), any(WorkflowResourceIds.class));
SPY_workflowAction.selectExecutionList(execution);
@@ -286,6 +290,8 @@ public class WorkflowActionTest extends BaseTaskTest {
VfModuleCustomization vfModuleCustomization3 = vfModuleCustomization2;
vfModuleCustomization3.setModelCustomizationUUID("72d9d1cd-f46d-447a-abdb-451d6fb05fa8");
+ when(userParamsServiceTraversal.getResourceListFromUserParams(any(), anyList(), anyString(), anyString()))
+ .thenReturn(prepareListWithResources());
when(catalogDbClient.getNorthBoundRequestByActionAndIsALaCarteAndRequestScopeAndCloudOwner(gAction, resource,
false, "my-custom-cloud-owner")).thenReturn(northBoundRequest);
when(catalogDbClient.getVfModuleCustomizationByModelCuztomizationUUID("a25e8e8c-58b8-4eec-810c-97dcc1f5cb7f"))
@@ -294,6 +300,7 @@ public class WorkflowActionTest extends BaseTaskTest {
.thenReturn(vfModuleCustomization2);
when(catalogDbClient.getVfModuleCustomizationByModelCuztomizationUUID("da4d4327-fb7d-4311-ac7a-be7ba60cf969"))
.thenReturn(vfModuleCustomization3);
+
workflowAction.selectExecutionList(execution);
List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
assertEqualsBulkFlowName(ebbs, "AssignServiceInstanceBB", "AssignVnfBB", "AssignVolumeGroupBB",
@@ -334,6 +341,8 @@ public class WorkflowActionTest extends BaseTaskTest {
VfModuleCustomization vfModuleCustomization3 = vfModuleCustomization2;
vfModuleCustomization3.setModelCustomizationUUID("72d9d1cd-f46d-447a-abdb-451d6fb05fa8");
+ when(userParamsServiceTraversal.getResourceListFromUserParams(any(), anyList(), anyString(), anyString()))
+ .thenReturn(prepareListWithResources());
when(environment.getProperty("org.onap.so.cloud-owner")).thenReturn("att-aic");
when(catalogDbClient.getNorthBoundRequestByActionAndIsALaCarteAndRequestScopeAndCloudOwner(gAction, resource,
false, "att-aic")).thenReturn(northBoundRequest);
@@ -471,6 +480,7 @@ public class WorkflowActionTest extends BaseTaskTest {
doReturn(service).when(catalogDbClient).getServiceByID("3c40d244-808e-42ca-b09a-256d83d19d0a");
when(catalogDbClient.getNorthBoundRequestByActionAndIsALaCarteAndRequestScopeAndCloudOwner(gAction, resource,
false, "my-custom-cloud-owner")).thenReturn(northBoundRequest);
+
workflowAction.selectExecutionList(execution);
List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
assertEqualsBulkFlowName(ebbs, "AssignServiceInstanceBB", "AssignNetworkBB", "CreateNetworkBB",
@@ -606,6 +616,8 @@ public class WorkflowActionTest extends BaseTaskTest {
VfModuleCustomization vfModuleCustomization3 = vfModuleCustomization2;
vfModuleCustomization3.setModelCustomizationUUID("72d9d1cd-f46d-447a-abdb-451d6fb05fa8");
+ when(userParamsServiceTraversal.getResourceListFromUserParams(any(), anyList(), anyString(), anyString()))
+ .thenReturn(prepareListWithResources());
when(catalogDbClient.getNorthBoundRequestByActionAndIsALaCarteAndRequestScopeAndCloudOwner(gAction, resource,
false, "my-custom-cloud-owner")).thenReturn(northBoundRequest);
when(catalogDbClient.getVfModuleCustomizationByModelCuztomizationUUID("a25e8e8c-58b8-4eec-810c-97dcc1f5cb7f"))
@@ -622,6 +634,7 @@ public class WorkflowActionTest extends BaseTaskTest {
"ActivateVolumeGroupBB", "CreateVfModuleBB", "CreateVfModuleBB", "CreateVfModuleBB",
"ActivateVfModuleBB", "ActivateVfModuleBB", "ActivateVfModuleBB", "ActivateVnfBB",
"ActivateServiceInstanceBB");
+
assertEquals(3, ebbs.get(0).getWorkflowResourceIds().getServiceInstanceId().length());
int randomUUIDLength = UUID.randomUUID().toString().length();
assertEquals(randomUUIDLength, ebbs.get(1).getWorkflowResourceIds().getVnfId().length());
@@ -1255,8 +1268,8 @@ public class WorkflowActionTest extends BaseTaskTest {
List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
assertEqualsBulkFlowName(ebbs, "DeleteFabricConfigurationBB", "DeactivateVfModuleBB", "DeleteVfModuleATTBB",
- "UnassignVFModuleBB", "AssignVfModuleBB", "CreateVfModuleBB", "ActivateVfModuleBB",
- "AddFabricConfigurationBB", "ChangeModelVnfBB", "ChangeModelServiceInstanceBB");
+ "UnassignVFModuleBB", "AssignVfModuleBB", "CreateVfModuleBB", "ActivateVfModuleBB", "ChangeModelVnfBB",
+ "ChangeModelServiceInstanceBB");
}
@Test
@@ -2010,906 +2023,6 @@ public class WorkflowActionTest extends BaseTaskTest {
assertNull(x.getVolumeGroupId());
}
- private RequestDetails setupRequestDetails(String globalSubscriberId, String subscriptionServiceType,
- String modelCustomizationId) {
- RequestDetails reqDetails = new RequestDetails();
- SubscriberInfo subInfo = new SubscriberInfo();
- subInfo.setGlobalSubscriberId(globalSubscriberId);
- reqDetails.setSubscriberInfo(subInfo);
- RequestParameters reqParams = new RequestParameters();
- reqParams.setSubscriptionServiceType(subscriptionServiceType);
- reqDetails.setRequestParameters(reqParams);
- ModelInfo modelInfo = new ModelInfo();
- modelInfo.setModelCustomizationId(modelCustomizationId);
- reqDetails.setModelInfo(modelInfo);
- return reqDetails;
- }
-
- @Test
- public void validateResourceIdInAAIVnfTest() throws Exception {
- RequestDetails reqDetails = setupRequestDetails("id123", "subServiceType123", "1234567");
- WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds();
- workflowResourceIds.setServiceInstanceId("siId123");
- // Vnf
- GenericVnf vnf = new GenericVnf();
- vnf.setVnfId("id123");
- vnf.setVnfName("vnfName123");
- vnf.setModelCustomizationId("1234567");
- Optional<GenericVnf> opVnf = Optional.of(vnf);
- GenericVnf vnf2 = new GenericVnf();
- vnf2.setVnfId("id123");
- vnf2.setVnfName("vnfName222");
- vnf2.setModelCustomizationId("222");
- Optional<GenericVnf> opVnf2 = Optional.of(vnf2);
- when(bbSetupUtils.getRelatedVnfByNameFromServiceInstance("siId123", "vnfName123")).thenReturn(opVnf);
- when(bbSetupUtils.getRelatedVnfByNameFromServiceInstance("siId123", "vnfName222")).thenReturn(opVnf2);
- when(bbSetupUtils.getRelatedVnfByNameFromServiceInstance("siId123", "111111")).thenReturn(Optional.empty());
- String id = workflowAction.validateResourceIdInAAI("generatedId123", WorkflowType.VNF, "vnfName123", reqDetails,
- workflowResourceIds);
- assertEquals("id123", id);
- String id2 = workflowAction.validateResourceIdInAAI("generatedId123", WorkflowType.VNF, "111111", reqDetails,
- workflowResourceIds);
- assertEquals("generatedId123", id2);
-
- this.expectedException.expect(DuplicateNameException.class);
- this.expectedException.expectMessage(containsString(
- "generic-vnf with name (vnfName222), same parent and different customization id (222) already exists. The name must be unique."));
- workflowAction.validateResourceIdInAAI("generatedId123", WorkflowType.VNF, "vnfName222", reqDetails,
- workflowResourceIds);
- }
-
- @Test
- public void validateResourceIdInAAIVnfNotGloballyUniqueTest() throws Exception {
- RequestDetails reqDetails = setupRequestDetails("id123", "subServiceType123", "1234567");
- WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds();
- workflowResourceIds.setServiceInstanceId("siId123");
-
- // Vnf
- GenericVnfs genericVnfs = new GenericVnfs();
- GenericVnf vnf3 = new GenericVnf();
- vnf3.setVnfId("id123");
- vnf3.setVnfName("vnfName333");
- genericVnfs.getGenericVnf().add(vnf3);
- when(bbSetupUtils.getRelatedVnfByNameFromServiceInstance("siId123", "vnfName333")).thenReturn(Optional.empty());
- when(bbSetupUtils.getAAIVnfsGloballyByName("vnfName333")).thenReturn(genericVnfs);
-
- this.expectedException.expect(DuplicateNameException.class);
- this.expectedException.expectMessage(containsString(
- "generic-vnf with name (vnfName333) id (id123) and different parent relationship already exists. The name must be unique."));
- workflowAction.validateResourceIdInAAI("generatedId123", WorkflowType.VNF, "vnfName333", reqDetails,
- workflowResourceIds);
- }
-
- @Test
- public void validateResourceIdInAAINetworkTest() throws Exception {
- RequestDetails reqDetails = setupRequestDetails("id123", "subServiceType123", "1234567");
- WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds();
- workflowResourceIds.setServiceInstanceId("siId123");
-
- // Network
- L3Network network = new L3Network();
- network.setNetworkId("id123");
- network.setNetworkName("name123");
- network.setModelCustomizationId("1234567");
- workflowResourceIds.setServiceInstanceId("siId123");
- Optional<L3Network> opNetwork = Optional.of(network);
- L3Network network2 = new L3Network();
- network2.setNetworkId("id123");
- network2.setNetworkName("networkName222");
- network2.setModelCustomizationId("222");
- Optional<L3Network> opNetwork2 = Optional.of(network2);
- when(bbSetupUtils.getRelatedNetworkByNameFromServiceInstance("siId123", "name123")).thenReturn(opNetwork);
- when(bbSetupUtils.getRelatedNetworkByNameFromServiceInstance("siId123", "networkName222"))
- .thenReturn(opNetwork2);
- when(bbSetupUtils.getRelatedNetworkByNameFromServiceInstance("siId123", "111111")).thenReturn(Optional.empty());
- String id = workflowAction.validateResourceIdInAAI("generatedId123", WorkflowType.NETWORK, "name123",
- reqDetails, workflowResourceIds);
- assertEquals("id123", id);
- String id2 = workflowAction.validateResourceIdInAAI("generatedId123", WorkflowType.NETWORK, "111111",
- reqDetails, workflowResourceIds);
- assertEquals("generatedId123", id2);
-
- this.expectedException.expect(DuplicateNameException.class);
- this.expectedException.expectMessage(containsString(
- "l3Network with name (networkName222), same parent and different customization id (222) already exists. The name must be unique."));
- workflowAction.validateResourceIdInAAI("generatedId123", WorkflowType.NETWORK, "networkName222", reqDetails,
- workflowResourceIds);
- }
-
- @Test
- public void validateNetworkResourceNameExistsInAAITest() throws Exception {
- RequestDetails reqDetails = setupRequestDetails("id123", "subServiceType123", "1234567");
- WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds();
- workflowResourceIds.setServiceInstanceId("siId123");
-
- // Network
- L3Network network = new L3Network();
- network.setNetworkId("id123");
- network.setNetworkName("name123");
- network.setModelCustomizationId("1234567");
- workflowResourceIds.setServiceInstanceId("siId123");
-
- when(bbSetupUtils.getRelatedNetworkByNameFromServiceInstance("networkName333", "111111"))
- .thenReturn(Optional.empty());
- when(bbSetupUtils.existsAAINetworksGloballyByName("networkName333")).thenReturn(true);
-
- this.expectedException.expect(DuplicateNameException.class);
- this.expectedException.expectMessage(containsString(
- "l3Network with name (networkName333) id (siId123) and different parent relationship already exists. The name must be unique."));
- workflowAction.validateResourceIdInAAI("generatedId123", WorkflowType.NETWORK, "networkName333", reqDetails,
- workflowResourceIds);
- }
-
- @Test
- public void validateResourceIdInAAIVfModuleTest() throws Exception {
- RequestDetails reqDetails = setupRequestDetails("id123", "subServiceType123", "1234567");
- WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds();
- workflowResourceIds.setServiceInstanceId("siId123");
-
- GenericVnf vnf = new GenericVnf();
- vnf.setVnfId("id123");
- vnf.setVnfName("vnfName123");
- vnf.setModelCustomizationId("222");
-
- // VfModule
- VfModules vfModules = new VfModules();
- VfModule vfModule = new VfModule();
- vfModule.setVfModuleId("id123");
- vfModule.setVfModuleName("name123");
- vfModule.setModelCustomizationId("1234567");
- vfModules.getVfModule().add(vfModule);
- vnf.setVfModules(vfModules);
- workflowResourceIds.setVnfId("id123");
- when(bbSetupUtils.getAAIGenericVnf("id123")).thenReturn(vnf);
- String id = workflowAction.validateResourceIdInAAI("generatedId123", WorkflowType.VFMODULE, "name123",
- reqDetails, workflowResourceIds);
- assertEquals("id123", id);
-
- GenericVnf vnf1 = new GenericVnf();
- VfModules vfModules2 = new VfModules();
- VfModule vfModule2 = new VfModule();
- vfModule2.setVfModuleId("id123");
- vfModule2.setVfModuleName("vFModName222");
- vfModule2.setModelCustomizationId("222");
- vfModules2.getVfModule().add(vfModule2);
- vnf1.setVfModules(vfModules2);
- workflowResourceIds.setVnfId("id111");
- when(bbSetupUtils.getAAIGenericVnf("id111")).thenReturn(vnf1);
- String id2 = workflowAction.validateResourceIdInAAI("generatedId123", WorkflowType.VFMODULE, "111111",
- reqDetails, workflowResourceIds);
- assertEquals("generatedId123", id2);
-
- this.expectedException.expect(DuplicateNameException.class);
- this.expectedException.expectMessage(containsString(
- "vfModule with name (vFModName222), same parent and different customization id (1234567) already exists. The name must be unique."));
- workflowAction.validateResourceIdInAAI("generatedId123", WorkflowType.VFMODULE, "vFModName222", reqDetails,
- workflowResourceIds);
- }
-
- @Test
- public void validateResourceIdInAAIVfModuleNotGloballyUniqueTest() throws Exception {
- RequestDetails reqDetails = setupRequestDetails("id123", "subServiceType123", "1234567");
- WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds();
- workflowResourceIds.setVnfId("id111");
-
- GenericVnf vnf1 = new GenericVnf();
- workflowResourceIds.setVnfId("id111");
- when(bbSetupUtils.getAAIGenericVnf("id111")).thenReturn(vnf1);
-
- when(bbSetupUtils.existsAAIVfModuleGloballyByName("vFModName333")).thenReturn(true);
- this.expectedException.expect(DuplicateNameException.class);
- this.expectedException.expectMessage(
- containsString("vfModule with name vFModName333 already exists. The name must be unique."));
- workflowAction.validateResourceIdInAAI("generatedId123", WorkflowType.VFMODULE, "vFModName333", reqDetails,
- workflowResourceIds);
- }
-
- @Test
- public void validateResourceIdInAAIVolumeGroupTest() throws Exception {
- RequestDetails reqDetails = setupRequestDetails("id123", "subServiceType123", "1234567");
- WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds();
- workflowResourceIds.setServiceInstanceId("siId123");
-
- GenericVnf vnf = new GenericVnf();
- vnf.setVnfId("id123");
- vnf.setVnfName("vnfName123");
- vnf.setModelCustomizationId("1234567");
-
- GenericVnf vnf2 = new GenericVnf();
- vnf2.setVnfId("id123");
- vnf2.setVnfName("vnfName123");
- vnf2.setModelCustomizationId("222");
-
- // VolumeGroup
- VolumeGroup volumeGroup = new VolumeGroup();
- volumeGroup.setVolumeGroupId("id123");
- volumeGroup.setVolumeGroupName("name123");
- volumeGroup.setVfModuleModelCustomizationId("1234567");
- workflowResourceIds.setVnfId("id123");
- Optional<VolumeGroup> opVolumeGroup = Optional.of(volumeGroup);
-
- workflowResourceIds.setVnfId("id123");
-
- when(bbSetupUtils.getAAIGenericVnf("id123")).thenReturn(vnf);
- when(bbSetupUtils.getRelatedVolumeGroupByNameFromVnf("id123", "name123")).thenReturn(opVolumeGroup);
- String id = workflowAction.validateResourceIdInAAI("generatedId123", WorkflowType.VOLUMEGROUP, "name123",
- reqDetails, workflowResourceIds);
- assertEquals("id123", id);
-
- when(bbSetupUtils.getAAIGenericVnf("id123")).thenReturn(vnf2);
- when(bbSetupUtils.getRelatedVolumeGroupByNameFromVfModule("id123", "id123", "111111"))
- .thenReturn(opVolumeGroup);
-
- when(bbSetupUtils.getRelatedVolumeGroupByNameFromVnf("id123", "111111")).thenReturn(Optional.empty());
- String id2 = workflowAction.validateResourceIdInAAI("generatedId123", WorkflowType.VOLUMEGROUP, "111111",
- reqDetails, workflowResourceIds);
- assertEquals("generatedId123", id2);
- }
-
- @Test
- public void validatesourceIdInAAIVolumeGroupNotGloballyUniqueTest() throws Exception {
- RequestDetails reqDetails = setupRequestDetails("id123", "subServiceType123", "1234567");
- WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds();
- workflowResourceIds.setVnfId("id123");
- GenericVnf vnf = new GenericVnf();
- vnf.setVnfId("id123");
- when(bbSetupUtils.getAAIGenericVnf("id123")).thenReturn(vnf);
- when(bbSetupUtils.getRelatedVolumeGroupByNameFromVnf("id123", "testVolumeGroup")).thenReturn(Optional.empty());
-
- when(bbSetupUtils.existsAAIVolumeGroupGloballyByName("testVolumeGroup")).thenReturn(true);
- this.expectedException.expect(DuplicateNameException.class);
- this.expectedException.expectMessage(
- containsString("volumeGroup with name testVolumeGroup already exists. The name must be unique."));
- workflowAction.validateResourceIdInAAI("generatedId123", WorkflowType.VOLUMEGROUP, "testVolumeGroup",
- reqDetails, workflowResourceIds);
- }
-
- @Test
- public void validateResourceIdInAAIConfigurationTest() throws Exception {
- RequestDetails reqDetails = setupRequestDetails("id123", "subServiceType123", "1234567");
- WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds();
- workflowResourceIds.setServiceInstanceId("siId123");
-
- // Configuration
- org.onap.aai.domain.yang.Configuration configuration = new org.onap.aai.domain.yang.Configuration();
- configuration.setConfigurationId("id123");
- configuration.setConfigurationName("name123");
- configuration.setModelCustomizationId("1234567");
- Optional<org.onap.aai.domain.yang.Configuration> opConfiguration = Optional.of(configuration);
-
- org.onap.aai.domain.yang.Configuration configuration2 = new org.onap.aai.domain.yang.Configuration();
- configuration2.setConfigurationId("id123");
- configuration2.setConfigurationName("name123");
- configuration2.setModelCustomizationId("222");
- Optional<org.onap.aai.domain.yang.Configuration> opConfiguration2 = Optional.of(configuration2);
-
- workflowResourceIds.setVnfId("id123");
-
- when(bbSetupUtils.getRelatedConfigurationByNameFromServiceInstance("siId123", "name123"))
- .thenReturn(opConfiguration);
- String id = workflowAction.validateResourceIdInAAI("generatedId123", WorkflowType.CONFIGURATION, "name123",
- reqDetails, workflowResourceIds);
- assertEquals("id123", id);
-
- when(bbSetupUtils.getRelatedConfigurationByNameFromServiceInstance("siId123", "111111"))
- .thenReturn(Optional.empty());
- String id2 = workflowAction.validateResourceIdInAAI("generatedId123", WorkflowType.CONFIGURATION, "111111",
- reqDetails, workflowResourceIds);
- assertEquals("generatedId123", id2);
-
- when(bbSetupUtils.getRelatedConfigurationByNameFromServiceInstance("siId123", "name222"))
- .thenReturn(opConfiguration2);
- this.expectedException.expect(DuplicateNameException.class);
- this.expectedException.expectMessage(containsString(
- "configuration with name (name222), same parent and different customization id (id123) already exists. The name must be unique."));
- workflowAction.validateResourceIdInAAI("generatedId123", WorkflowType.CONFIGURATION, "name222", reqDetails,
- workflowResourceIds);
- }
-
- @Test
- public void validateResourceIdInAAIConfigurationNotGloballyUniqueTest() throws Exception {
- RequestDetails reqDetails = setupRequestDetails("id123", "subServiceType123", "1234567");
- WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds();
- workflowResourceIds.setServiceInstanceId("siId123");
-
- when(bbSetupUtils.getRelatedConfigurationByNameFromServiceInstance("siId123", "testConfig"))
- .thenReturn(Optional.empty());
- when(bbSetupUtils.existsAAIConfigurationGloballyByName("testConfig")).thenReturn(true);
- this.expectedException.expect(DuplicateNameException.class);
- this.expectedException.expectMessage(
- containsString("configuration with name testConfig already exists. The name must be unique."));
- workflowAction.validateResourceIdInAAI("generatedId123", WorkflowType.CONFIGURATION, "testConfig", reqDetails,
- workflowResourceIds);
- }
-
- @Test
- public void validateResourceIdInAAISITest() throws Exception {
- WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds();
- workflowResourceIds.setServiceInstanceId("siId123");
- RequestDetails reqDetails = setupRequestDetails("id123", "subServiceType123", "1234567");
- reqDetails.getModelInfo().setModelVersionId("1234567");
-
- ServiceInstance si = new ServiceInstance();
- si.setServiceInstanceId("siId123");
- si.setModelVersionId("1234567");
- ServiceInstances serviceInstances = new ServiceInstances();
- serviceInstances.getServiceInstance().add(si);
- Optional<ServiceInstance> siOp = Optional.of(si);
- ServiceInstance si2 = new ServiceInstance();
- si2.setServiceInstanceId("siId222");
- si2.setModelVersionId("22222");
- si2.setServiceInstanceName("siName222");
- Optional<ServiceInstance> siOp2 = Optional.of(si2);
- ServiceInstances serviceInstances2 = new ServiceInstances();
- serviceInstances2.getServiceInstance().add(si2);
-
- when(bbSetupUtils.getAAIServiceInstanceByName("id123", "subServiceType123", "siName123")).thenReturn(siOp);
- when(bbSetupUtils.getAAIServiceInstanceByName("id123", "subServiceType123", "siName222")).thenReturn(siOp2);
- when(bbSetupUtils.getAAIServiceInstanceByName("id123", "subServiceType123", "111111"))
- .thenReturn(Optional.empty());
-
- when(bbSetupUtils.getAAIServiceInstancesGloballyByName("siName123")).thenReturn(serviceInstances);
- String id = workflowAction.validateResourceIdInAAI("generatedId123", WorkflowType.SERVICE, "siName123",
- reqDetails, workflowResourceIds);
- assertEquals("siId123", id);
- String id2 = workflowAction.validateResourceIdInAAI("generatedId123", WorkflowType.SERVICE, "111111",
- reqDetails, workflowResourceIds);
- assertEquals("generatedId123", id2);
-
- when(bbSetupUtils.getAAIServiceInstancesGloballyByName("siName222")).thenReturn(serviceInstances2);
- this.expectedException.expect(DuplicateNameException.class);
- this.expectedException.expectMessage(containsString(
- "serviceInstance with name (siName222) and different version id (1234567) already exists. The name must be unique."));
- workflowAction.validateResourceIdInAAI("generatedId123", WorkflowType.SERVICE, "siName222", reqDetails,
- workflowResourceIds);
- }
-
- @Test
- public void validateResourceIdInAAIMultipleSITest() throws Exception {
- WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds();
- workflowResourceIds.setServiceInstanceId("siId123");
- RequestDetails reqDetails = setupRequestDetails("id123", "subServiceType123", "1234567");
- reqDetails.getModelInfo().setModelVersionId("1234567");
-
- ServiceInstance si = new ServiceInstance();
- si.setServiceInstanceId("siId123");
- si.setModelVersionId("1234567");
- ServiceInstances serviceInstances = new ServiceInstances();
- serviceInstances.getServiceInstance().add(si);
-
- ServiceInstance si2 = new ServiceInstance();
- si2.setServiceInstanceId("siId222");
- si2.setModelVersionId("22222");
- si2.setServiceInstanceName("siName222");
- serviceInstances.getServiceInstance().add(si2);
-
- when(bbSetupUtils.getAAIServiceInstanceByName("id123", "subServiceType123", "siId123"))
- .thenReturn(Optional.empty());
-
- when(bbSetupUtils.getAAIServiceInstancesGloballyByName("siName123")).thenReturn(serviceInstances);
-
- this.expectedException.expect(DuplicateNameException.class);
- this.expectedException.expectMessage(containsString(
- "serviceInstance with name (siName123) and multiple combination of model-version-id + service-type + global-customer-id already exists. The name must be unique."));
- workflowAction.validateResourceIdInAAI("generatedId123", WorkflowType.SERVICE, "siName123", reqDetails,
- workflowResourceIds);
- }
-
- @Test
- public void validateResourceIdInAAISIExistsTest() throws Exception {
- WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds();
- workflowResourceIds.setServiceInstanceId("siId123");
- RequestDetails reqDetails = setupRequestDetails("id123", "subServiceType123", "1234567");
- reqDetails.getModelInfo().setModelVersionId("1234567");
-
- ServiceInstance si = new ServiceInstance();
- si.setServiceInstanceId("siId123");
- si.setModelVersionId("1234567");
- ServiceInstances serviceInstances = new ServiceInstances();
- serviceInstances.getServiceInstance().add(si);
-
- when(bbSetupUtils.getAAIServiceInstanceByName("id123", "subServiceType123", "siId123"))
- .thenReturn(Optional.empty());
-
- when(bbSetupUtils.getAAIServiceInstancesGloballyByName("siName123")).thenReturn(serviceInstances);
-
- Map<String, String> uriKeys = new HashMap<>();
- uriKeys.put(AAIFluentTypeBuilder.Types.CUSTOMER.getUriParams().globalCustomerId, "globalCustomerId");
- uriKeys.put(AAIFluentTypeBuilder.Types.SERVICE_SUBSCRIPTION.getUriParams().serviceType, "serviceType");
-
- when(bbSetupUtils.getURIKeysFromServiceInstance("siId123")).thenReturn(uriKeys);
-
- this.expectedException.expect(DuplicateNameException.class);
- this.expectedException.expectMessage(containsString(
- "serviceInstance with name (siName123) and global-customer-id (globalCustomerId), service-type (serviceType), model-version-id (1234567) already exists. The name must be unique."));
- workflowAction.validateResourceIdInAAI("generatedId123", WorkflowType.SERVICE, "siName123", reqDetails,
- workflowResourceIds);
- }
-
- @Test
- public void validateServiceResourceIdInAAINoDupTest() throws Exception {
- RequestDetails reqDetails = setupRequestDetails("id123", "subServiceType123", "1234567");
- reqDetails.getModelInfo().setModelVersionId("1234567");
- when(bbSetupUtils.getAAIServiceInstanceByName("id123", "subServiceType123", "siName123"))
- .thenReturn(Optional.empty());
- when(bbSetupUtils.getAAIServiceInstancesGloballyByName("siName123")).thenReturn(null);
- String id = workflowAction.validateServiceResourceIdInAAI("generatedId123", "siName123", reqDetails);
- assertEquals("generatedId123", id);
- }
-
- @Test
- public void validateServiceResourceIdInAAISameModelVersionId() throws Exception {
- RequestDetails reqDetails = setupRequestDetails("id123", "subServiceType123", "1234567");
- reqDetails.getModelInfo().setModelVersionId("1234567");
-
- ServiceInstance si = new ServiceInstance();
- si.setServiceInstanceId("siId123");
- si.setModelVersionId("1234567");
- Optional<ServiceInstance> siOp = Optional.of(si);
-
- when(bbSetupUtils.getAAIServiceInstanceByName("id123", "subServiceType123", "siName123")).thenReturn(siOp);
- String id = workflowAction.validateServiceResourceIdInAAI("generatedId123", "siName123", reqDetails);
- assertEquals("siId123", id);
- }
-
- @Test
- public void validateServiceResourceIdInAAIDifferentModelVersionId() throws Exception {
- RequestDetails reqDetails = setupRequestDetails("id123", "subServiceType123", "1234567");
- reqDetails.getModelInfo().setModelVersionId("1234567");
-
- ServiceInstance si = new ServiceInstance();
- si.setServiceInstanceId("siId123");
- si.setModelVersionId("9999999");
- ServiceInstances serviceInstances = new ServiceInstances();
- serviceInstances.getServiceInstance().add(si);
- Optional<ServiceInstance> siOp = Optional.of(si);
-
- when(bbSetupUtils.getAAIServiceInstanceByName("id123", "subServiceType123", "siName123")).thenReturn(siOp);
-
- this.expectedException.expect(DuplicateNameException.class);
- this.expectedException.expectMessage(containsString(
- "serviceInstance with name (siName123) and different version id (1234567) already exists. The name must be unique."));
-
- String id = workflowAction.validateServiceResourceIdInAAI("generatedId123", "siName123", reqDetails);
- assertEquals("siId123", id);
- }
-
- @Test
- public void validateServiceResourceIdInAAIDuplicateNameTest() throws Exception {
-
- RequestDetails reqDetails = setupRequestDetails("id123", "subServiceType123", "1234567");
- reqDetails.getModelInfo().setModelVersionId("1234567");
-
- ServiceInstance si = new ServiceInstance();
- si.setServiceInstanceId("siId123");
- si.setModelVersionId("1234567");
-
- ServiceInstances serviceInstances = new ServiceInstances();
- serviceInstances.getServiceInstance().add(si);
-
- when(bbSetupUtils.getAAIServiceInstanceByName("id123", "subServiceType123", "siName"))
- .thenReturn(Optional.empty());
- when(bbSetupUtils.getAAIServiceInstancesGloballyByName("siName")).thenReturn(serviceInstances);
-
- this.expectedException.expect(DuplicateNameException.class);
- this.expectedException.expectMessage(containsString(
- "serviceInstance with name (siName) and global-customer-id (null), service-type (null), model-version-id (1234567) already exists. The name must be unique."));
-
- workflowAction.validateServiceResourceIdInAAI("generatedId123", "siName", reqDetails);
- }
-
- @Test
- public void validateServiceResourceIdInAAIDuplicateNameMultipleTest() throws Exception {
-
- RequestDetails reqDetails = setupRequestDetails("id123", "subServiceType123", "1234567");
- reqDetails.getModelInfo().setModelVersionId("1234567");
-
- ServiceInstance si = new ServiceInstance();
- si.setServiceInstanceId("siId123");
- si.setModelVersionId("1234567");
-
- ServiceInstance si2 = new ServiceInstance();
- si2.setServiceInstanceId("siId222");
- si2.setModelVersionId("22222");
- si2.setServiceInstanceName("siName222");
-
- ServiceInstances serviceInstances = new ServiceInstances();
- serviceInstances.getServiceInstance().add(si);
- serviceInstances.getServiceInstance().add(si2);
-
- when(bbSetupUtils.getAAIServiceInstanceByName("id123", "subServiceType123", "siName"))
- .thenReturn(Optional.empty());
- when(bbSetupUtils.getAAIServiceInstancesGloballyByName("siName")).thenReturn(serviceInstances);
-
- this.expectedException.expect(DuplicateNameException.class);
- this.expectedException.expectMessage(containsString(
- "serviceInstance with name (siName) and multiple combination of model-version-id + service-type + global-customer-id already exists. The name must be unique."));
-
- workflowAction.validateServiceResourceIdInAAI("generatedId123", "siName", reqDetails);
- }
-
- @Test
- public void validateNetworkResourceIdInAAITest() throws Exception {
- RequestDetails reqDetails = setupRequestDetails("id123", "subServiceType123", "1234567");
- WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds();
- workflowResourceIds.setServiceInstanceId("siId123");
-
- when(bbSetupUtils.getRelatedNetworkByNameFromServiceInstance("siId123", "name123"))
- .thenReturn(Optional.empty());
- when(bbSetupUtils.existsAAINetworksGloballyByName("name123")).thenReturn(false);
-
- String id = workflowAction.validateNetworkResourceIdInAAI("generatedId123", "name123", reqDetails,
- workflowResourceIds);
- assertEquals("generatedId123", id);
- }
-
- @Test
- public void validateNetworkResourceIdInAAISameModelCustIdTest() throws Exception {
- RequestDetails reqDetails = setupRequestDetails("id123", "subServiceType123", "1234567");
- WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds();
- workflowResourceIds.setServiceInstanceId("siId123");
-
- L3Network network = new L3Network();
- network.setNetworkId("id123");
- network.setNetworkName("name123");
- network.setModelCustomizationId("1234567");
- Optional<L3Network> opNetwork = Optional.of(network);
-
- when(bbSetupUtils.getRelatedNetworkByNameFromServiceInstance("siId123", "name123")).thenReturn(opNetwork);
-
- String id = workflowAction.validateNetworkResourceIdInAAI("generatedId123", "name123", reqDetails,
- workflowResourceIds);
- assertEquals("id123", id);
- }
-
- @Test
- public void validateNetworkResourceIdInAAIDuplicateNameTest() throws Exception {
- RequestDetails reqDetails = setupRequestDetails("id123", "subServiceType123", "1234567");
- WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds();
- workflowResourceIds.setServiceInstanceId("siId123");
-
- L3Network network = new L3Network();
- network.setNetworkId("id123");
- network.setNetworkName("name123");
- network.setModelCustomizationId("9999999");
- Optional<L3Network> opNetwork = Optional.of(network);
-
- when(bbSetupUtils.getRelatedNetworkByNameFromServiceInstance("siId123", "name123")).thenReturn(opNetwork);
-
- this.expectedException.expect(DuplicateNameException.class);
- this.expectedException.expectMessage(containsString(
- "l3Network with name (name123), same parent and different customization id (9999999) already exists. The name must be unique."));
-
- workflowAction.validateNetworkResourceIdInAAI("generatedId123", "name123", reqDetails, workflowResourceIds);
- }
-
- @Test
- public void validateNetworkResourceIdInAAINotGloballyUniqueTest() throws Exception {
- RequestDetails reqDetails = setupRequestDetails("id123", "subServiceType123", "1234567");
- WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds();
- workflowResourceIds.setServiceInstanceId("siId123");
-
- when(bbSetupUtils.getRelatedNetworkByNameFromServiceInstance("siId123", "name123"))
- .thenReturn(Optional.empty());
- when(bbSetupUtils.existsAAINetworksGloballyByName("name123")).thenReturn(true);
-
- this.expectedException.expect(DuplicateNameException.class);
- this.expectedException.expectMessage(containsString(
- "l3Network with name (name123) id (siId123) and different parent relationship already exists. The name must be unique."));
-
- workflowAction.validateNetworkResourceIdInAAI("generatedId123", "name123", reqDetails, workflowResourceIds);
- }
-
- @Test
- public void validateVnfResourceIdInAAITest() throws Exception {
- RequestDetails reqDetails = setupRequestDetails("id123", "subServiceType123", "1234567");
- WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds();
- workflowResourceIds.setServiceInstanceId("siId123");
- when(bbSetupUtils.getRelatedVnfByNameFromServiceInstance("siId123", "vnfName123")).thenReturn(Optional.empty());
- String id = workflowAction.validateVnfResourceIdInAAI("generatedId123", "vnfName123", reqDetails,
- workflowResourceIds);
- assertEquals("generatedId123", id);
- }
-
- @Test
- public void validateVnfResourceIdInAAISameModelCustomizationIdTest() throws Exception {
- RequestDetails reqDetails = setupRequestDetails("id123", "subServiceType123", "1234567");
- WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds();
- workflowResourceIds.setServiceInstanceId("siId123");
-
- GenericVnf vnf = new GenericVnf();
- vnf.setVnfId("id123");
- vnf.setVnfName("vnfName123");
- vnf.setModelCustomizationId("1234567");
- Optional<GenericVnf> opVnf = Optional.of(vnf);
-
- when(bbSetupUtils.getRelatedVnfByNameFromServiceInstance("siId123", "vnfName123")).thenReturn(opVnf);
- String id = workflowAction.validateVnfResourceIdInAAI("generatedId123", "vnfName123", reqDetails,
- workflowResourceIds);
- assertEquals("id123", id);
- }
-
- @Test
- public void validateVnfResourceIdInAAIDiffModelCustomizationIdTest() throws Exception {
- RequestDetails reqDetails = setupRequestDetails("id123", "subServiceType123", "1234567");
- WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds();
- workflowResourceIds.setServiceInstanceId("siId123");
-
- GenericVnf vnf = new GenericVnf();
- vnf.setVnfId("id123");
- vnf.setVnfName("vnfName123");
- vnf.setModelCustomizationId("9999999");
- Optional<GenericVnf> opVnf = Optional.of(vnf);
-
- when(bbSetupUtils.getRelatedVnfByNameFromServiceInstance("siId123", "vnfName123")).thenReturn(opVnf);
-
- this.expectedException.expect(DuplicateNameException.class);
- this.expectedException.expectMessage(containsString(
- "generic-vnf with name (vnfName123), same parent and different customization id (9999999) already exists. The name must be unique."));
-
- workflowAction.validateVnfResourceIdInAAI("generatedId123", "vnfName123", reqDetails, workflowResourceIds);
- }
-
- @Test
- public void validateVnfResourceIdInAAINotGloballyUniqueTest() throws Exception {
- RequestDetails reqDetails = setupRequestDetails("id123", "subServiceType123", "1234567");
- WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds();
- workflowResourceIds.setServiceInstanceId("siId123");
-
-
- GenericVnf vnf = new GenericVnf();
- vnf.setVnfId("id123");
- vnf.setVnfName("vnfName123");
- GenericVnfs genericVnfs = new GenericVnfs();
- genericVnfs.getGenericVnf().add(vnf);
-
- when(bbSetupUtils.getRelatedVnfByNameFromServiceInstance("siId123", "vnfName123")).thenReturn(Optional.empty());
- when(bbSetupUtils.getAAIVnfsGloballyByName("vnfName123")).thenReturn(genericVnfs);
-
- this.expectedException.expect(DuplicateNameException.class);
- this.expectedException.expectMessage(containsString(
- "generic-vnf with name (vnfName123) id (id123) and different parent relationship already exists. The name must be unique."));
-
- workflowAction.validateVnfResourceIdInAAI("generatedId123", "vnfName123", reqDetails, workflowResourceIds);
- }
-
- @Test
- public void validateVfModuleResourceIdTest() throws Exception {
- RequestDetails reqDetails = setupRequestDetails("id123", "subServiceType123", "1234567");
- WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds();
- workflowResourceIds.setVnfId("vnfId123");
-
- when(bbSetupUtils.getAAIGenericVnf("id123")).thenReturn(null);
- when(bbSetupUtils.existsAAIVfModuleGloballyByName("name123")).thenReturn(false);
-
- String id = workflowAction.validateVfModuleResourceIdInAAI("generatedId123", "name123", reqDetails,
- workflowResourceIds);
- assertEquals("generatedId123", id);
- }
-
- @Test
- public void validateVfModuleResourceIdSameModelCustIdTest() throws Exception {
- RequestDetails reqDetails = setupRequestDetails("id123", "subServiceType123", "1234567");
- WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds();
- workflowResourceIds.setVnfId("vnfId123");
-
- VfModules vfModules = new VfModules();
- VfModule vfModule = new VfModule();
- vfModule.setVfModuleId("id123");
- vfModule.setVfModuleName("name123");
- vfModule.setModelCustomizationId("1234567");
- vfModules.getVfModule().add(vfModule);
-
- GenericVnf vnf = new GenericVnf();
- vnf.setVnfId("id123");
- vnf.setVnfName("vnfName123");
- vnf.setVfModules(vfModules);
-
- when(bbSetupUtils.getAAIGenericVnf("vnfId123")).thenReturn(vnf);
-
- String id = workflowAction.validateVfModuleResourceIdInAAI("generatedId123", "name123", reqDetails,
- workflowResourceIds);
- assertEquals("id123", id);
- }
-
- @Test
- public void validateVfModuleResourceIdDifferentModelCustIdTest() throws Exception {
- RequestDetails reqDetails = setupRequestDetails("id123", "subServiceType123", "1234567");
- WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds();
- workflowResourceIds.setVnfId("vnfId123");
-
- VfModules vfModules = new VfModules();
- VfModule vfModule = new VfModule();
- vfModule.setVfModuleId("id123");
- vfModule.setVfModuleName("name123");
- vfModule.setModelCustomizationId("9999999");
- vfModules.getVfModule().add(vfModule);
-
- GenericVnf vnf = new GenericVnf();
- vnf.setVnfId("id123");
- vnf.setVnfName("vnfName123");
- vnf.setVfModules(vfModules);
-
- when(bbSetupUtils.getAAIGenericVnf("vnfId123")).thenReturn(vnf);
-
- this.expectedException.expect(DuplicateNameException.class);
- this.expectedException.expectMessage(containsString(
- "vfModule with name (name123), same parent and different customization id (1234567) already exists. The name must be unique."));
-
- workflowAction.validateVfModuleResourceIdInAAI("generatedId123", "name123", reqDetails, workflowResourceIds);
-
- }
-
- @Test
- public void validateVfModuleResourceIdNotGloballyUniqueTest() throws Exception {
- RequestDetails reqDetails = setupRequestDetails("id123", "subServiceType123", "1234567");
- WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds();
- workflowResourceIds.setVnfId("vnfId123");
-
- when(bbSetupUtils.getAAIGenericVnf("id123")).thenReturn(null);
- when(bbSetupUtils.existsAAIVfModuleGloballyByName("name123")).thenReturn(true);
-
- this.expectedException.expect(DuplicateNameException.class);
- this.expectedException
- .expectMessage(containsString("vfModule with name name123 already exists. The name must be unique."));
-
- workflowAction.validateVfModuleResourceIdInAAI("generatedId123", "name123", reqDetails, workflowResourceIds);
- }
-
- @Test
- public void validateVolumeGroupResourceIdInAAITest() throws Exception {
- RequestDetails reqDetails = setupRequestDetails("id123", "subServiceType123", "1234567");
- WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds();
- workflowResourceIds.setVnfId("vnfId123");
-
- when(bbSetupUtils.getRelatedVolumeGroupByNameFromVnf("id123", "name123")).thenReturn(Optional.empty());
- when(bbSetupUtils.existsAAIVolumeGroupGloballyByName("name123")).thenReturn(false);
-
- String id = workflowAction.validateVolumeGroupResourceIdInAAI("generatedId123", "name123", reqDetails,
- workflowResourceIds);
- assertEquals("generatedId123", id);
- }
-
- @Test
- public void validateVolumeGroupResourceIdInAAISameModelCustIdTest() throws Exception {
- RequestDetails reqDetails = setupRequestDetails("id123", "subServiceType123", "1234567");
- WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds();
- workflowResourceIds.setServiceInstanceId("siId123");
- workflowResourceIds.setVnfId("vnfId123");
-
- VolumeGroup volumeGroup = new VolumeGroup();
- volumeGroup.setVolumeGroupId("id123");
- volumeGroup.setVolumeGroupName("name123");
- volumeGroup.setVfModuleModelCustomizationId("1234567");
-
- Optional<VolumeGroup> opVolumeGroup = Optional.of(volumeGroup);
-
- when(bbSetupUtils.getRelatedVolumeGroupByNameFromVnf("vnfId123", "name123")).thenReturn(opVolumeGroup);
- String id = workflowAction.validateResourceIdInAAI("generatedId123", WorkflowType.VOLUMEGROUP, "name123",
- reqDetails, workflowResourceIds);
-
- assertEquals("id123", id);
- }
-
- @Test
- public void validateVolumeGroupResourceIdInAAIDifferentModelCustIdTest() throws Exception {
- RequestDetails reqDetails = setupRequestDetails("id123", "subServiceType123", "1234567");
- WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds();
- workflowResourceIds.setServiceInstanceId("siId123");
- workflowResourceIds.setVnfId("vnfId123");
-
- VolumeGroup volumeGroup = new VolumeGroup();
- volumeGroup.setVolumeGroupId("id123");
- volumeGroup.setVolumeGroupName("name123");
- volumeGroup.setVfModuleModelCustomizationId("9999999");
-
- Optional<VolumeGroup> opVolumeGroup = Optional.of(volumeGroup);
-
- when(bbSetupUtils.getRelatedVolumeGroupByNameFromVnf("vnfId123", "name123")).thenReturn(opVolumeGroup);
-
- this.expectedException.expect(DuplicateNameException.class);
- this.expectedException.expectMessage(
- containsString("volumeGroup with name name123 already exists. The name must be unique."));
-
- workflowAction.validateResourceIdInAAI("generatedId123", WorkflowType.VOLUMEGROUP, "name123", reqDetails,
- workflowResourceIds);
- }
-
- @Test
- public void validateVolumeGroupResourceIdInAAINotGloballyUniqueTest() throws Exception {
- RequestDetails reqDetails = setupRequestDetails("id123", "subServiceType123", "1234567");
- WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds();
- workflowResourceIds.setVnfId("vnfId123");
-
- when(bbSetupUtils.getRelatedVolumeGroupByNameFromVnf("vnfId123", "name123")).thenReturn(Optional.empty());
- when(bbSetupUtils.existsAAIVolumeGroupGloballyByName("name123")).thenReturn(true);
-
- this.expectedException.expect(DuplicateNameException.class);
- this.expectedException.expectMessage(
- containsString("volumeGroup with name name123 already exists. The name must be unique."));
-
- workflowAction.validateResourceIdInAAI("generatedId123", WorkflowType.VOLUMEGROUP, "name123", reqDetails,
- workflowResourceIds);
- }
-
- @Test
- public void validateConfigurationResourceIdInAAITest() throws Exception {
- RequestDetails reqDetails = setupRequestDetails("id123", "subServiceType123", "1234567");
- WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds();
- workflowResourceIds.setServiceInstanceId("siId123");
-
- when(bbSetupUtils.getRelatedConfigurationByNameFromServiceInstance("siId123", "name123"))
- .thenReturn(Optional.empty());
- when(bbSetupUtils.existsAAIConfigurationGloballyByName("name123")).thenReturn(false);
-
- String id = workflowAction.validateConfigurationResourceIdInAAI("generatedId123", "name123", reqDetails,
- workflowResourceIds);
- assertEquals("generatedId123", id);
- }
-
- @Test
- public void validateConfigurationResourceIdInAAISameModelCustIdTest() throws Exception {
- RequestDetails reqDetails = setupRequestDetails("id123", "subServiceType123", "1234567");
- WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds();
- workflowResourceIds.setServiceInstanceId("siId123");
-
- org.onap.aai.domain.yang.Configuration configuration = new org.onap.aai.domain.yang.Configuration();
- configuration.setConfigurationId("id123");
- configuration.setConfigurationName("name123");
- configuration.setModelCustomizationId("1234567");
- Optional<org.onap.aai.domain.yang.Configuration> opConfiguration = Optional.of(configuration);
-
- when(bbSetupUtils.getRelatedConfigurationByNameFromServiceInstance("siId123", "name123"))
- .thenReturn(opConfiguration);
- when(bbSetupUtils.existsAAIConfigurationGloballyByName("name123")).thenReturn(false);
-
- String id = workflowAction.validateConfigurationResourceIdInAAI("generatedId123", "name123", reqDetails,
- workflowResourceIds);
- assertEquals("id123", id);
- }
-
- @Test
- public void validateConfigurationResourceIdInAAIDifferentModelCustIdTest() throws Exception {
- RequestDetails reqDetails = setupRequestDetails("id123", "subServiceType123", "1234567");
- WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds();
- workflowResourceIds.setServiceInstanceId("siId123");
-
- org.onap.aai.domain.yang.Configuration configuration = new org.onap.aai.domain.yang.Configuration();
- configuration.setConfigurationId("id123");
- configuration.setConfigurationName("name123");
- configuration.setModelCustomizationId("9999999");
- Optional<org.onap.aai.domain.yang.Configuration> opConfiguration = Optional.of(configuration);
-
- when(bbSetupUtils.getRelatedConfigurationByNameFromServiceInstance("siId123", "name123"))
- .thenReturn(opConfiguration);
- when(bbSetupUtils.existsAAIConfigurationGloballyByName("name123")).thenReturn(false);
-
- this.expectedException.expect(DuplicateNameException.class);
- this.expectedException.expectMessage(containsString(
- "configuration with name (name123), same parent and different customization id (id123) already exists. The name must be unique."));
-
- workflowAction.validateConfigurationResourceIdInAAI("generatedId123", "name123", reqDetails,
- workflowResourceIds);
- }
-
- @Test
- public void validateConfigurationResourceIdInAAINotGloballyUniqueTest() throws Exception {
- RequestDetails reqDetails = setupRequestDetails("id123", "subServiceType123", "1234567");
- WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds();
- workflowResourceIds.setServiceInstanceId("siId123");
-
- when(bbSetupUtils.getRelatedConfigurationByNameFromServiceInstance("siId123", "name123"))
- .thenReturn(Optional.empty());
- when(bbSetupUtils.existsAAIConfigurationGloballyByName("name123")).thenReturn(true);
-
- this.expectedException.expect(DuplicateNameException.class);
- this.expectedException.expectMessage(
- containsString("configuration with name name123 already exists. The name must be unique."));
-
- workflowAction.validateConfigurationResourceIdInAAI("generatedId123", "name123", reqDetails,
- workflowResourceIds);
- }
-
@Test
public void handleRuntimeExceptionTest() {
execution.setVariable("BPMN_javaExpMsg", "test runtime error message");
@@ -2960,41 +2073,7 @@ public class WorkflowActionTest extends BaseTaskTest {
workflowAction.traverseCatalogDbService(execution, sIRequest, resourceCounter, aaiResourceIds);
}
- @Test
- public void sortVfModulesByBaseFirstTest() {
- List<Resource> resources = new ArrayList<>();
- Resource resource1 = new Resource(WorkflowType.VFMODULE, "111", false);
- resource1.setBaseVfModule(false);
- resources.add(resource1);
- Resource resource2 = new Resource(WorkflowType.VFMODULE, "222", false);
- resource2.setBaseVfModule(false);
- resources.add(resource2);
- Resource resource3 = new Resource(WorkflowType.VFMODULE, "333", false);
- resource3.setBaseVfModule(true);
- resources.add(resource3);
- List<Resource> result = workflowAction.sortVfModulesByBaseFirst(resources);
- assertEquals("333", result.get(0).getResourceId());
- assertEquals("222", result.get(1).getResourceId());
- assertEquals("111", result.get(2).getResourceId());
- }
- @Test
- public void sortVfModulesByBaseLastTest() {
- List<Resource> resources = new ArrayList<>();
- Resource resource1 = new Resource(WorkflowType.VFMODULE, "111", false);
- resource1.setBaseVfModule(true);
- resources.add(resource1);
- Resource resource2 = new Resource(WorkflowType.VFMODULE, "222", false);
- resource2.setBaseVfModule(false);
- resources.add(resource2);
- Resource resource3 = new Resource(WorkflowType.VFMODULE, "333", false);
- resource3.setBaseVfModule(false);
- resources.add(resource3);
- List<Resource> result = workflowAction.sortVfModulesByBaseLast(resources);
- assertEquals("333", result.get(0).getResourceId());
- assertEquals("222", result.get(1).getResourceId());
- assertEquals("111", result.get(2).getResourceId());
- }
@Test
public void findCatalogNetworkCollectionTest() {
@@ -3033,17 +2112,6 @@ public class WorkflowActionTest extends BaseTaskTest {
execution.getVariable("WorkflowActionErrorMessage"));
}
- @Test
- public void verifyLackOfNullPointerExceptionForNullResource() {
- ExecuteBuildingBlock result = null;
- try {
- result = workflowAction.buildExecuteBuildingBlock(new OrchestrationFlow(), null, null, null, null, null,
- false, null, null, null, false, null, null, true, null);
- } catch (NullPointerException e) {
- fail("NullPointerException should not be thrown when 'resource' is null");
- }
- assertNotNull(result);
- }
@Test
public void traverseAAIServiceTest() {
@@ -3100,6 +2168,32 @@ public class WorkflowActionTest extends BaseTaskTest {
}
}
+ @Test
+ public void foundRelatedTest() {
+ List<Resource> resourceList = new ArrayList<>();
+ resourceList.add(new Resource(WorkflowType.PNF, "model customization id", false));
+ resourceList.add(new Resource(WorkflowType.VNF, "model customization id", false));
+ resourceList.add(new Resource(WorkflowType.NETWORK, "model customization id", false));
+ resourceList.add(new Resource(WorkflowType.NETWORKCOLLECTION, "model customization id", false));
+
+ assertEquals(workflowAction.foundRelated(resourceList), true);
+ }
+
+ @Test
+ public void containsWorkflowTypeTest() {
+ List<Resource> resourceList = new ArrayList<>();
+ resourceList.add(new Resource(WorkflowType.PNF, "resource id", false));
+ resourceList.add(new Resource(WorkflowType.VNF, "model customization id", false));
+ resourceList.add(new Resource(WorkflowType.NETWORK, "model customization id", false));
+ resourceList.add(new Resource(WorkflowType.NETWORKCOLLECTION, "model customization id", false));
+
+ assertEquals(workflowAction.containsWorkflowType(resourceList, WorkflowType.PNF), true);
+ assertEquals(workflowAction.containsWorkflowType(resourceList, WorkflowType.VNF), true);
+ assertEquals(workflowAction.containsWorkflowType(resourceList, WorkflowType.NETWORK), true);
+ assertEquals(workflowAction.containsWorkflowType(resourceList, WorkflowType.NETWORKCOLLECTION), true);
+ assertEquals(workflowAction.containsWorkflowType(resourceList, WorkflowType.CONFIGURATION), false);
+ }
+
private List<Pair<WorkflowType, String>> getExpectedResourceIds() {
List<Pair<WorkflowType, String>> resourceIds = new ArrayList<>();
resourceIds.add(new Pair<WorkflowType, String>(WorkflowType.VNF, "testVnfId1"));
@@ -3141,4 +2235,15 @@ public class WorkflowActionTest extends BaseTaskTest {
private String readBpmnRequestFromFile(String fileName) throws IOException {
return new String(Files.readAllBytes(Paths.get("src/test/resources/__files/" + fileName)));
}
+
+ private List<Resource> prepareListWithResources() {
+ List<Resource> resourceList = new ArrayList<>();
+ resourceList.add(new Resource(WorkflowType.SERVICE, "3c40d244-808e-42ca-b09a-256d83d19d0a", false));
+ resourceList.add(new Resource(WorkflowType.VNF, "ab153b6e-c364-44c0-bef6-1f2982117f04", false));
+ resourceList.add(new Resource(WorkflowType.VOLUMEGROUP, "a25e8e8c-58b8-4eec-810c-97dcc1f5cb7f", false));
+ resourceList.add(new Resource(WorkflowType.VFMODULE, "72d9d1cd-f46d-447a-abdb-451d6fb05fa8", false));
+ resourceList.add(new Resource(WorkflowType.VFMODULE, "3c40d244-808e-42ca-b09a-256d83d19d0a", false));
+ resourceList.add(new Resource(WorkflowType.VFMODULE, "72d9d1cd-f46d-447a-abdb-451d6fb05fa8", false));
+ return resourceList;
+ }
}