aboutsummaryrefslogtreecommitdiffstats
path: root/bpmn/so-bpmn-tasks
diff options
context:
space:
mode:
Diffstat (limited to 'bpmn/so-bpmn-tasks')
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnf/tasks/CnfAdapterCreateTasks.java121
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/ServiceLevelPreparable.java (renamed from bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/AbstractServiceLevelPreparable.java)55
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/impl/ServiceLevelConstants.java58
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/impl/ServiceLevelPostcheck.java13
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/impl/ServiceLevelPreparation.java66
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/impl/ServiceLevelRequestDispatcher.java131
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/impl/ServiceLevelUpgrade.java67
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/impl/UpdateServiceInstanceInAai.java123
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowAction.java53
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/CnfAdapterClient.java97
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/CnfAdapterClientException.java34
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/entities/GVK.java49
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/entities/InstanceRequest.java95
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/entities/InstanceResponse.java62
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/entities/Labels.java25
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/entities/Resource.java37
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/vnf/mapper/Attributes.java23
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/vnf/mapper/VnfAdapterVfModuleObjectMapper.java2
-rw-r--r--bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/service/level/ServiceLevelPreparationTest.java116
-rw-r--r--bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionTest.java73
20 files changed, 1199 insertions, 101 deletions
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnf/tasks/CnfAdapterCreateTasks.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnf/tasks/CnfAdapterCreateTasks.java
new file mode 100644
index 0000000000..93d30512b6
--- /dev/null
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnf/tasks/CnfAdapterCreateTasks.java
@@ -0,0 +1,121 @@
+/*-
+ * ============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 java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import org.onap.so.bpmn.common.BuildingBlockExecution;
+import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion;
+import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
+import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
+import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
+import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock;
+import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
+import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext;
+import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
+import org.onap.so.client.adapter.cnf.CnfAdapterClient;
+import org.onap.so.client.adapter.cnf.entities.InstanceRequest;
+import org.onap.so.client.adapter.cnf.entities.InstanceResponse;
+import org.onap.so.client.adapter.vnf.mapper.AttributeNameValue;
+import org.onap.so.client.adapter.vnf.mapper.Attributes;
+import org.onap.so.client.adapter.vnf.mapper.VnfAdapterVfModuleObjectMapper;
+import org.onap.so.client.exception.ExceptionBuilder;
+import org.onap.so.openstack.utils.MsoMulticloudUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+import com.fasterxml.jackson.core.JsonParseException;
+import com.fasterxml.jackson.databind.JsonMappingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+@Component
+public class CnfAdapterCreateTasks {
+ private static final Logger logger = LoggerFactory.getLogger(CnfAdapterCreateTasks.class);
+ public static final String SDNCQUERY_RESPONSE = "SDNCQueryResponse_";
+
+ @Autowired
+ private ExtractPojosForBB extractPojosForBB;
+ @Autowired
+ private ExceptionBuilder exceptionUtil;
+ @Autowired
+ private CnfAdapterClient cnfAdapterClient;
+ @Autowired
+ private VnfAdapterVfModuleObjectMapper vfModuleMapper;
+
+ private ObjectMapper mapper = new ObjectMapper();
+
+ /**
+ * This method is used for creating the request for an Instance in Multicloud K8s Plugin.
+ *
+ * @param execution
+ * @return
+ */
+ public void createInstance(BuildingBlockExecution execution) {
+ try {
+ GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock();
+ ServiceInstance serviceInstance =
+ gBBInput.getCustomer().getServiceSubscription().getServiceInstances().get(0);
+ GenericVnf genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
+ VfModule vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID);
+ RequestContext requestContext = gBBInput.getRequestContext();
+ CloudRegion cloudRegion = gBBInput.getCloudRegion();
+ String sdncVfModuleQueryResponse = execution.getVariable(SDNCQUERY_RESPONSE + vfModule.getVfModuleId());
+ String sdncVnfQueryResponse = execution.getVariable(SDNCQUERY_RESPONSE + genericVnf.getVnfId());
+ Map<String, Object> paramsMap = vfModuleMapper.buildVfModuleParamsMap(requestContext, serviceInstance,
+ genericVnf, vfModule, sdncVnfQueryResponse, sdncVfModuleQueryResponse);
+ Map<String, String> sdncDirectives = getSdncDirectives(paramsMap);
+ InstanceRequest createInstanceRequest = createInstanceRequest(vfModule, cloudRegion, sdncDirectives);
+ InstanceResponse response = cnfAdapterClient.createVfModule(createInstanceRequest);
+ execution.setVariable("heatStackId", response.getId());
+ } catch (Exception ex) {
+ logger.error("Exception occurred", ex);
+ exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
+ }
+ }
+
+ protected Map<String, String> getSdncDirectives(Map<String, Object> paramsMap)
+ throws JsonParseException, JsonMappingException, IOException {
+ Map<String, String> sdncDirectivesMap = new HashMap<>();
+ String sdncDirectivesString = (String) paramsMap.get(MsoMulticloudUtils.SDNC_DIRECTIVES);
+ Attributes sdncDirectives = mapper.readValue(sdncDirectivesString, Attributes.class);
+ for (AttributeNameValue nameVal : sdncDirectives.getAttributes()) {
+ sdncDirectivesMap.put(nameVal.getAttributeName(), (String) nameVal.getAttributeValue());
+ }
+ return sdncDirectivesMap;
+ }
+
+ protected InstanceRequest createInstanceRequest(VfModule vfModule, CloudRegion cloudRegion,
+ Map<String, String> sdncDirectives) {
+ InstanceRequest request = new InstanceRequest();
+ request.setRbName(vfModule.getModelInfoVfModule().getModelInvariantUUID());
+ request.setRbVersion(vfModule.getModelInfoVfModule().getModelUUID());
+ request.setCloudRegion(cloudRegion.getLcpCloudRegionId());
+ request.setReleaseName(vfModule.getVfModuleId());
+ request.setProfileName(sdncDirectives.get("k8s-rb-profile-name"));
+ request.setOverrideValues(sdncDirectives);
+ return request;
+ }
+
+}
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/AbstractServiceLevelPreparable.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/ServiceLevelPreparable.java
index 36db549486..e26195158d 100644
--- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/AbstractServiceLevelPreparable.java
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/ServiceLevelPreparable.java
@@ -20,40 +20,58 @@
package org.onap.so.bpmn.infrastructure.service.level;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Optional;
import org.camunda.bpm.engine.delegate.DelegateExecution;
+import org.onap.so.bpmn.infrastructure.service.level.impl.ServiceLevelConstants;
import org.onap.so.client.exception.ExceptionBuilder;
+import org.onap.so.db.catalog.beans.Workflow;
+import org.onap.so.db.catalog.client.CatalogDbClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
-import java.util.ArrayList;
-import java.util.List;
/**
- * Abstract class for Service level upgrade Execution, it should be extended for service level upgrade tasks.
+ * Parent class for Service level upgrade Execution, it should be extended for service level upgrade tasks.
*/
-public abstract class AbstractServiceLevelPreparable {
+public class ServiceLevelPreparable {
- protected static final String WORKFLOW_TO_INVOKE = "healthCheckWorkflow";
- protected static final String GENERIC_PNF_HEALTH_CHECK_WORKFLOW = "GenericPnfHealthCheck";
- protected static final String GENERIC_PNF_SOFTWARE_UPGRADE_WORKFLOW = "GenericPnfSoftwareUpgrade";
- protected static final String RESOURCE_TYPE = "RESOURCE_TYPE";
- protected static final int ERROR_CODE = 601;
-
- // TODO This value needs to be updated once vnf health check workflow is available
- protected static final String GENERIC_VNF_HEALTH_CHECK_WORKFLOW = "GenericVNFHealthCheck";
-
- protected static final Logger LOG = LoggerFactory.getLogger(AbstractServiceLevelPreparable.class);
+ protected static final Logger LOG = LoggerFactory.getLogger(ServiceLevelPreparable.class);
@Autowired
protected ExceptionBuilder exceptionBuilder;
+ @Autowired
+ protected CatalogDbClient catalogDbClient;
+
/**
- * This method fetches workflow names to be invoked based on the controller scope .
+ * Fetches workflow names based on the controller scope and operation name.
*
* @param scope Controller scope
+ * @param operationName healthcheck/softwareUpgrade
* @return String value of Workflow name
*/
- protected abstract String fetchWorkflowUsingScope(DelegateExecution execution, final String scope);
+ protected String fetchWorkflowUsingScope(final String scope, String operationName) {
+ Optional<String> wflName = Optional.empty();
+ try {
+ List<Workflow> workflows = catalogDbClient.findWorkflowByOperationName(operationName);
+ if (!workflows.isEmpty()) {
+ wflName = Optional.ofNullable(
+ workflows.stream().filter(workflow -> workflow.getResourceTarget().equalsIgnoreCase(scope))
+ .findFirst().get().getName());
+ }
+ } catch (Exception e) {
+ // do nothing and assign the default workflow in finally
+ LOG.error("Error occurred while fetching workflow name from CatalogDb {}", e);
+ } finally {
+ if (wflName.isEmpty()) {
+ wflName = Optional.of(ServiceLevelConstants.WORKFLOW_OPERATIONS_MAP.get(operationName).get(scope));
+ }
+ }
+ return wflName.get();
+
+ }
/**
* This method validates the execution parameters to be passed for health check workflow.
@@ -61,8 +79,7 @@ public abstract class AbstractServiceLevelPreparable {
* @param execution Delegate execution obj
* @param scope Controller scope * Throws workflow exception if validation fails
*/
- protected void validateParamsWithScope(DelegateExecution execution, final String scope, List<String> params)
- throws Exception {
+ protected void validateParamsWithScope(DelegateExecution execution, final String scope, List<String> params) {
List<String> invalidVariables = new ArrayList<>();
for (String param : params) {
if (!execution.hasVariable(param) || execution.getVariable(param) == null
@@ -72,7 +89,7 @@ public abstract class AbstractServiceLevelPreparable {
}
if (invalidVariables.size() > 0) {
LOG.error("Validation error for the {} health check attributes: {}", scope, invalidVariables);
- exceptionBuilder.buildAndThrowWorkflowException(execution, ERROR_CODE,
+ exceptionBuilder.buildAndThrowWorkflowException(execution, ServiceLevelConstants.ERROR_CODE,
"Validation of health check workflow parameters failed for the scope: " + scope);
}
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/impl/ServiceLevelConstants.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/impl/ServiceLevelConstants.java
new file mode 100644
index 0000000000..7b73fff20c
--- /dev/null
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/impl/ServiceLevelConstants.java
@@ -0,0 +1,58 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 Nordix Foundation.
+ * ================================================================================
+ * 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.service.level.impl;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+
+public class ServiceLevelConstants {
+ public static final String BPMN_REQUEST = "bpmnRequest";
+ public static final String RESOURCE_TYPE = "resourceType";
+ public static final String SERVICE_INSTANCE_ID = "serviceInstanceId";
+ public static final String PNF_NAME = "pnfName";
+ public static final String PNF = "pnf";
+ public static final String VNF = "vnf";
+ public static final String EMPTY_STRING = "";
+ public static final String HEALTH_CHECK_WORKFLOW_TO_INVOKE = "healthCheckWorkflow";
+ public static final String SOFTWARE_WORKFLOW_TO_INVOKE = "softwareUpgradeWorkflow";
+ public static final String HEALTH_CHECK_OPERATION = "ResourceHealthCheck";
+ public static final String SW_UP_OPERATION = "ResourceSoftwareUpgrade";
+ public static final String CONTROLLER_STATUS = "ControllerStatus";
+ public static final int ERROR_CODE = 601;
+
+ // TODO GenericVNFHealthCheck and GenericVnfSoftwareUpgrade workflow names should be updated once the workflow is
+ // implemented.
+ public static final Map<String, String> DEFAULT_HEALTH_CHECK_WORKFLOWS =
+ Map.of(PNF, "GenericPnfHealthCheck", VNF, "GenericVNFHealthCheck");
+
+ public static final Map<String, String> DEFAULT_SOFTWARE_UP_WORKFLOWS =
+ Map.of(PNF, "GenericPnfSoftwareUpgrade", VNF, "GenericVnfSoftwareUpgrade");
+
+ // Maps operation name with workflows
+ public static final Map<String, Map<String, String>> WORKFLOW_OPERATIONS_MAP = Map.of(HEALTH_CHECK_OPERATION,
+ DEFAULT_HEALTH_CHECK_WORKFLOWS, SW_UP_OPERATION, DEFAULT_SOFTWARE_UP_WORKFLOWS);
+
+ public static final List<String> VALID_CONTROLLER_SCOPE = Arrays.asList(PNF, VNF);
+
+
+
+}
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/impl/ServiceLevelPostcheck.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/impl/ServiceLevelPostcheck.java
new file mode 100644
index 0000000000..fad28e315e
--- /dev/null
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/impl/ServiceLevelPostcheck.java
@@ -0,0 +1,13 @@
+package org.onap.so.bpmn.infrastructure.service.level.impl;
+
+import org.camunda.bpm.engine.delegate.DelegateExecution;
+import org.camunda.bpm.engine.delegate.JavaDelegate;
+import org.springframework.stereotype.Component;
+
+@Component
+public class ServiceLevelPostcheck implements JavaDelegate {
+ @Override
+ public void execute(DelegateExecution delegateExecution) throws Exception {
+ // TODO : Set serviceInstance to aai
+ }
+}
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/impl/ServiceLevelPreparation.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/impl/ServiceLevelPreparation.java
index 52521ce16b..59884ecbc2 100644
--- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/impl/ServiceLevelPreparation.java
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/impl/ServiceLevelPreparation.java
@@ -20,12 +20,14 @@
package org.onap.so.bpmn.infrastructure.service.level.impl;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.camunda.bpm.engine.delegate.JavaDelegate;
-import org.onap.so.bpmn.infrastructure.service.level.AbstractServiceLevelPreparable;
+import org.onap.so.bpmn.infrastructure.service.level.ServiceLevelPreparable;
import org.springframework.stereotype.Component;
-import java.util.Arrays;
-import java.util.List;
/**
@@ -33,45 +35,39 @@ import java.util.List;
* validation.
*/
@Component("ServiceLevelPreparation")
-public class ServiceLevelPreparation extends AbstractServiceLevelPreparable implements JavaDelegate {
+public class ServiceLevelPreparation extends ServiceLevelPreparable implements JavaDelegate {
+
+ private static final List<String> PNF_HEALTH_CHECK_PARAMS = Arrays.asList(ServiceLevelConstants.SERVICE_INSTANCE_ID,
+ ServiceLevelConstants.RESOURCE_TYPE, ServiceLevelConstants.BPMN_REQUEST, ServiceLevelConstants.PNF_NAME);
- // Health check parameters to be validated for pnf resource
- private static final List<String> PNF_HC_PARAMS = Arrays.asList("SERVICE_MODEL_INFO", "SERVICE_INSTANCE_NAME",
- "PNF_CORRELATION_ID", "MODEL_UUID", "PNF_UUID", "PRC_BLUEPRINT_NAME", "PRC_BLUEPRINT_VERSION",
- "PRC_CUSTOMIZATION_UUID", "RESOURCE_CUSTOMIZATION_UUID_PARAM", "PRC_INSTANCE_NAME", "PRC_CONTROLLER_ACTOR",
- "REQUEST_PAYLOAD");
+ // TODO Update the list with vnf health check parameters if any validation needed
+ private static final List<String> VNF_HEALTH_CHECK_PARAMS = Collections.emptyList();
+
+ private static final Map<String, List<String>> HEALTH_CHECK_PARAMS_MAP = Map.of(ServiceLevelConstants.PNF,
+ PNF_HEALTH_CHECK_PARAMS, ServiceLevelConstants.VNF, VNF_HEALTH_CHECK_PARAMS);
@Override
public void execute(DelegateExecution execution) throws Exception {
- if (execution.hasVariable(RESOURCE_TYPE) && execution.getVariable(RESOURCE_TYPE) != null) {
- final String controllerScope = (String) execution.getVariable(RESOURCE_TYPE);
+ if (execution.hasVariable(ServiceLevelConstants.RESOURCE_TYPE)
+ && execution.getVariable(ServiceLevelConstants.RESOURCE_TYPE) != null) {
+ final String controllerScope = (String) execution.getVariable(ServiceLevelConstants.RESOURCE_TYPE);
LOG.debug("Scope retrieved from delegate execution: " + controllerScope);
- final String wflName = fetchWorkflowUsingScope(execution, controllerScope);
- LOG.debug("Health check workflow fetched for the scope: {}", wflName);
- validateParamsWithScope(execution, controllerScope, PNF_HC_PARAMS);
- LOG.info("Parameters validated successfully for {}", wflName);
- execution.setVariable(WORKFLOW_TO_INVOKE, wflName);
+ if (ServiceLevelConstants.VALID_CONTROLLER_SCOPE.contains(controllerScope)) {
+ final String wflName =
+ fetchWorkflowUsingScope(controllerScope, ServiceLevelConstants.HEALTH_CHECK_OPERATION);
+ LOG.debug("Health check workflow fetched for the scope: {} is: {}", controllerScope, wflName);
+ validateParamsWithScope(execution, controllerScope, HEALTH_CHECK_PARAMS_MAP.get(controllerScope));
+ LOG.info("Parameters validated successfully for {}", wflName);
+ execution.setVariable(ServiceLevelConstants.HEALTH_CHECK_WORKFLOW_TO_INVOKE, wflName);
+ execution.setVariable(ServiceLevelConstants.CONTROLLER_STATUS, ServiceLevelConstants.EMPTY_STRING);
+ } else {
+ exceptionBuilder.buildAndThrowWorkflowException(execution, ServiceLevelConstants.ERROR_CODE,
+ "Invalid Controller scope to prepare resource level health check");
+ }
} else {
- exceptionBuilder.buildAndThrowWorkflowException(execution, ERROR_CODE,
- "Controller scope not found to invoke resource level health check");
- }
- }
-
- @Override
- public String fetchWorkflowUsingScope(DelegateExecution execution, final String scope) {
- String wflName = null;
- switch (scope.toLowerCase()) {
- case "pnf":
- wflName = GENERIC_PNF_HEALTH_CHECK_WORKFLOW;
- break;
- case "vnf":
- wflName = GENERIC_VNF_HEALTH_CHECK_WORKFLOW;
- break;
- default:
- exceptionBuilder.buildAndThrowWorkflowException(execution, ERROR_CODE,
- "No valid health check work flow retrieved for the scope: " + scope);
+ exceptionBuilder.buildAndThrowWorkflowException(execution, ServiceLevelConstants.ERROR_CODE,
+ "Resource type not found in the execution to invoke resource level health check");
}
- return wflName;
}
}
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/impl/ServiceLevelRequestDispatcher.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/impl/ServiceLevelRequestDispatcher.java
new file mode 100644
index 0000000000..5b20a86cb7
--- /dev/null
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/impl/ServiceLevelRequestDispatcher.java
@@ -0,0 +1,131 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 Nordix Foundation.
+ * ================================================================================
+ * 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.service.level.impl;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.camunda.bpm.engine.delegate.DelegateExecution;
+import org.camunda.bpm.engine.delegate.JavaDelegate;
+import org.onap.aai.domain.yang.ServiceInstance;
+import org.onap.aaiclient.client.aai.AAIRestClientI;
+import org.onap.aaiclient.client.aai.AAIRestClientImpl;
+import org.onap.so.bpmn.core.json.JsonUtils;
+import org.onap.so.client.exception.ExceptionBuilder;
+import org.onap.so.serviceinstancebeans.RequestDetails;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+import java.io.IOException;
+import java.util.Optional;
+import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.*;
+
+/**
+ * This implementation of {@link JavaDelegate} is used to populate the execution object for Service level upgrade
+ */
+@Component
+public class ServiceLevelRequestDispatcher implements JavaDelegate {
+
+ private final Logger logger = LoggerFactory.getLogger(getClass());
+
+ @Autowired
+ private ExceptionBuilder exceptionUtil;
+
+ @Autowired
+ private ObjectMapper mapper;
+
+ @Override
+ public void execute(DelegateExecution delegateExecution) throws Exception {
+ logger.debug("Running execute block for activity id: {}, name: {}", delegateExecution.getCurrentActivityId(),
+ delegateExecution.getCurrentActivityName());
+
+ RequestDetails bpmnRequestDetails = requestVerification(delegateExecution);
+
+ final String serviceInstanceId = String.valueOf(delegateExecution.getVariable(SERVICE_INSTANCE_ID));
+ final String serviceType = bpmnRequestDetails.getRequestParameters().getSubscriptionServiceType();
+ final String globalSubscriberId = bpmnRequestDetails.getSubscriberInfo().getGlobalSubscriberId();
+
+ final String modelInvariantId = bpmnRequestDetails.getModelInfo().getModelInvariantId();
+ final String modelId = bpmnRequestDetails.getModelInfo().getModelUuid();
+ final String modelVersion = bpmnRequestDetails.getModelInfo().getModelVersion();
+
+ if (ServiceLevelConstants.PNF.equalsIgnoreCase(serviceType)) {
+ getAndSetPnfNameFromServiceInstance(serviceInstanceId, serviceType, globalSubscriberId, delegateExecution);
+ }
+
+ // TODO : handling for vnf
+
+ logger.trace("Completed dispatcher request for ServiceLevelUpgrade.");
+ }
+
+ private void getAndSetPnfNameFromServiceInstance(final String serviceInstanceId, final String serviceType,
+ final String globalSubscriberId, DelegateExecution delegateExecution) {
+
+ AAIRestClientI restClient = new AAIRestClientImpl();
+
+ Optional<ServiceInstance> optionalSi =
+ restClient.getServiceInstanceById(serviceInstanceId, serviceType, globalSubscriberId);
+
+ if (!optionalSi.isPresent()) {
+
+ }
+
+ optionalSi.ifPresentOrElse(serviceInstance -> {
+ final String pnfName = serviceInstance.getRelationshipList().getRelationship().stream()
+ .filter(x -> x.getRelatedTo().contains("pnf")).findFirst().get().getRelationshipData().stream()
+ .filter(data -> data.getRelationshipKey().contains("pnf.pnf-name")).findFirst().get()
+ .getRelationshipValue();
+ if (pnfName == null || pnfName.isEmpty()) {
+ logger.warn(
+ "Unable to find the PNF for service instance id: " + serviceInstance.getServiceInstanceId());
+ return;
+ }
+ delegateExecution.setVariable(ServiceLevelConstants.PNF_NAME, pnfName);
+ delegateExecution.setVariable(ServiceLevelConstants.RESOURCE_TYPE, ServiceLevelConstants.PNF);
+ }, () -> {
+ throwExceptionWithWarn(delegateExecution, "Unable to find the service instance: " + serviceInstanceId);
+ });
+ }
+
+ private RequestDetails requestVerification(DelegateExecution delegateExecution) throws IOException {
+ RequestDetails bpmnRequestDetails = mapper.readValue(JsonUtils.getJsonValue(
+ String.valueOf(delegateExecution.getVariable(ServiceLevelConstants.BPMN_REQUEST)), "requestDetails"),
+ RequestDetails.class);
+
+ throwIfNull(delegateExecution, bpmnRequestDetails.getModelInfo(), SERVICE_MODEL_INFO);
+ throwIfNull(delegateExecution, bpmnRequestDetails.getRequestInfo(), "RequestInfo");
+ throwIfNull(delegateExecution, bpmnRequestDetails.getRequestParameters(), "RequestParameters");
+ throwIfNull(delegateExecution, bpmnRequestDetails.getRequestParameters().getUserParams(), "UserParams");
+
+ return bpmnRequestDetails;
+ }
+
+ private void throwIfNull(DelegateExecution delegateExecution, Object obj, String param) {
+ if (obj == null) {
+ throwExceptionWithWarn(delegateExecution,
+ "Unable to find the parameter: " + param + " in the execution context");
+ }
+ }
+
+ private void throwExceptionWithWarn(DelegateExecution delegateExecution, String exceptionMsg) {
+ logger.warn(exceptionMsg);
+ exceptionUtil.buildAndThrowWorkflowException(delegateExecution, ServiceLevelConstants.ERROR_CODE, exceptionMsg);
+ }
+}
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/impl/ServiceLevelUpgrade.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/impl/ServiceLevelUpgrade.java
new file mode 100644
index 0000000000..9d7d8efb65
--- /dev/null
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/impl/ServiceLevelUpgrade.java
@@ -0,0 +1,67 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 Nordix Foundation.
+ * ================================================================================
+ * 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.service.level.impl;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import org.camunda.bpm.engine.delegate.DelegateExecution;
+import org.camunda.bpm.engine.delegate.JavaDelegate;
+import org.onap.so.bpmn.infrastructure.service.level.ServiceLevelPreparable;
+import org.springframework.stereotype.Component;
+
+@Component
+public class ServiceLevelUpgrade extends ServiceLevelPreparable implements JavaDelegate {
+
+ private static final List<String> PNF_SOFTWARE_UP_PARAMS = Arrays.asList(ServiceLevelConstants.SERVICE_INSTANCE_ID,
+ ServiceLevelConstants.RESOURCE_TYPE, ServiceLevelConstants.BPMN_REQUEST, ServiceLevelConstants.PNF_NAME);
+
+ // TODO Update the list with vnf software upgrade parameters if any validation needed
+ private static final List<String> VNF_SOFTWARE_UP_PARAMS = Collections.emptyList();
+
+ private static final Map<String, List<String>> SOFTWARE_UP_PARAMS_MAP = Map.of(ServiceLevelConstants.PNF,
+ PNF_SOFTWARE_UP_PARAMS, ServiceLevelConstants.VNF, VNF_SOFTWARE_UP_PARAMS);
+
+
+ @Override
+ public void execute(DelegateExecution execution) throws Exception {
+ if (execution.hasVariable(ServiceLevelConstants.RESOURCE_TYPE)
+ && execution.getVariable(ServiceLevelConstants.RESOURCE_TYPE) != null) {
+ final String controllerScope = (String) execution.getVariable(ServiceLevelConstants.RESOURCE_TYPE);
+ LOG.debug("Scope retrieved from delegate execution: " + controllerScope);
+ if (ServiceLevelConstants.VALID_CONTROLLER_SCOPE.contains(controllerScope)) {
+ final String wflName = fetchWorkflowUsingScope(controllerScope, ServiceLevelConstants.SW_UP_OPERATION);
+ LOG.debug("Software Upgrade workflow fetched for the scope: {} is: {}", controllerScope, wflName);
+ validateParamsWithScope(execution, controllerScope, SOFTWARE_UP_PARAMS_MAP.get(controllerScope));
+ LOG.info("Parameters validated successfully for {}", wflName);
+ execution.setVariable(ServiceLevelConstants.SOFTWARE_WORKFLOW_TO_INVOKE, wflName);
+ execution.setVariable(ServiceLevelConstants.CONTROLLER_STATUS, "");
+ } else {
+ exceptionBuilder.buildAndThrowWorkflowException(execution, ServiceLevelConstants.ERROR_CODE,
+ "Invalid Controller scope for resource level software upgrade");
+ }
+ } else {
+ exceptionBuilder.buildAndThrowWorkflowException(execution, ServiceLevelConstants.ERROR_CODE,
+ "Resource type not found in the execution to invoke resource level software upgrade");
+ }
+ }
+}
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/impl/UpdateServiceInstanceInAai.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/impl/UpdateServiceInstanceInAai.java
new file mode 100644
index 0000000000..c9bd607b8b
--- /dev/null
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/impl/UpdateServiceInstanceInAai.java
@@ -0,0 +1,123 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 Nordix Foundation.
+ * ================================================================================
+ * 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.service.level.impl;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.camunda.bpm.engine.delegate.DelegateExecution;
+import org.camunda.bpm.engine.delegate.JavaDelegate;
+import org.onap.aai.domain.yang.ServiceInstance;
+import org.onap.aaiclient.client.aai.AAIRestClientI;
+import org.onap.aaiclient.client.aai.AAIRestClientImpl;
+import org.onap.so.bpmn.core.json.JsonUtils;
+import org.onap.so.client.exception.ExceptionBuilder;
+import org.onap.so.serviceinstancebeans.RequestDetails;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+import java.io.IOException;
+import java.util.Optional;
+import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.SERVICE_MODEL_INFO;
+
+@Component
+public class UpdateServiceInstanceInAai implements JavaDelegate {
+
+ @Autowired
+ private ExceptionBuilder exceptionUtil;
+
+ private final Logger logger = LoggerFactory.getLogger(getClass());
+ private static final String BPMN_REQUEST = "bpmnRequest";
+ private static final String PNF_RESOURCE = "pnf";
+ private static final String SERVICE_INSTANCE_ID = "serviceInstanceId";
+
+ // ERROR CODE for variable not found in the delegation Context
+ private static final int ERROR_CODE = 601;
+
+ @Autowired
+ private ObjectMapper mapper;
+
+ @Override
+ public void execute(DelegateExecution delegateExecution) throws Exception {
+ logger.debug("Running execute block for activity id: {}, name: {}", delegateExecution.getCurrentActivityId(),
+ delegateExecution.getCurrentActivityName());
+
+ RequestDetails bpmnRequestDetails = requestVerification(delegateExecution);
+
+ final String serviceInstanceId = String.valueOf(delegateExecution.getVariable(SERVICE_INSTANCE_ID));
+ final String serviceType = bpmnRequestDetails.getRequestParameters().getSubscriptionServiceType();
+ final String globalSubscriberId = bpmnRequestDetails.getSubscriberInfo().getGlobalSubscriberId();
+
+ final String modelId = bpmnRequestDetails.getModelInfo().getModelUuid();
+
+ if (PNF_RESOURCE.equalsIgnoreCase(serviceType)) {
+ getAndSetServiceInstance(serviceInstanceId, serviceType, globalSubscriberId, modelId);
+ }
+
+ // TODO : handling for vnf
+
+ logger.trace("Completed updating request for ServiceLevelUpgrade.");
+ }
+
+ private void getAndSetServiceInstance(final String serviceInstanceId, final String serviceType,
+ final String globalSubscriberId, String modelVersionId) {
+
+ AAIRestClientI restClient = new AAIRestClientImpl();
+
+ Optional<ServiceInstance> optionalSi =
+ restClient.getServiceInstanceById(serviceInstanceId, serviceType, globalSubscriberId);
+
+ if (!optionalSi.isPresent()) {
+ // throwExceptionWithWarn(delegateExecution, "Unable to find the service instance: " + serviceInstanceId);
+ }
+
+ ServiceInstance serviceInstance = optionalSi.get();
+
+ serviceInstance.setModelVersionId(modelVersionId);
+
+ restClient.updateServiceInstance(serviceInstanceId, serviceType, globalSubscriberId, serviceInstance);
+
+ }
+
+ private RequestDetails requestVerification(DelegateExecution delegateExecution) throws IOException {
+ RequestDetails bpmnRequestDetails = mapper.readValue(
+ JsonUtils.getJsonValue(String.valueOf(delegateExecution.getVariable(BPMN_REQUEST)), "requestDetails"),
+ RequestDetails.class);
+
+ throwIfNull(delegateExecution, bpmnRequestDetails.getModelInfo(), SERVICE_MODEL_INFO);
+ throwIfNull(delegateExecution, bpmnRequestDetails.getRequestInfo(), "RequestInfo");
+ throwIfNull(delegateExecution, bpmnRequestDetails.getRequestParameters(), "RequestParameters");
+ throwIfNull(delegateExecution, bpmnRequestDetails.getRequestParameters().getUserParams(), "UserParams");
+
+ return bpmnRequestDetails;
+ }
+
+ private void throwIfNull(DelegateExecution delegateExecution, Object obj, String param) {
+ if (obj == null) {
+ throwExceptionWithWarn(delegateExecution,
+ "Unable to find the parameter: " + param + " in the execution context");
+ }
+ }
+
+ private void throwExceptionWithWarn(DelegateExecution delegateExecution, String exceptionMsg) {
+ logger.warn(exceptionMsg);
+ exceptionUtil.buildAndThrowWorkflowException(delegateExecution, ERROR_CODE, exceptionMsg);
+ }
+
+}
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 75d3ddf2e6..9b9433afdb 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
@@ -300,6 +300,9 @@ public class WorkflowAction {
|| ("recreateInstance".equalsIgnoreCase(requestAction)))) {
traverseAAIVnf(execution, resourceList, workflowResourceIds.getServiceInstanceId(),
workflowResourceIds.getVnfId(), aaiResourceIds);
+ } else if (resourceType == WorkflowType.VNF && "updateInstance".equalsIgnoreCase(requestAction)) {
+ customTraverseAAIVnf(execution, resourceList, workflowResourceIds.getServiceInstanceId(),
+ workflowResourceIds.getVnfId(), aaiResourceIds);
} else {
buildAndThrowException(execution, "Current Macro Request is not supported");
}
@@ -568,6 +571,10 @@ public class WorkflowAction {
WorkflowResourceIds workflowIdsCopy = SerializationUtils.clone(dataObj.getWorkflowResourceIds());
org.onap.aai.domain.yang.Configuration configuration = getRelatedResourcesInVnfc(vnfc,
org.onap.aai.domain.yang.Configuration.class, AAIObjectType.CONFIGURATION);
+ if (configuration == null) {
+ logger.warn(String.format("No configuration found for VNFC %s in AAI", vnfc.getVnfcName()));
+ continue;
+ }
workflowIdsCopy.setConfigurationId(configuration.getConfigurationId());
for (OrchestrationFlow orchFlow : result) {
dataObj.getResourceKey().setVfModuleCustomizationId(vfModuleCustomizationUUID);
@@ -584,7 +591,6 @@ public class WorkflowAction {
dataObj.getRequestAction(), dataObj.isaLaCarte(), dataObj.getVnfType(), workflowIdsCopy,
dataObj.getRequestDetails(), false, null, vnfcName, true, null);
flowsToExecuteConfigs.add(ebb);
-
}
}
return flowsToExecuteConfigs;
@@ -1108,6 +1114,51 @@ public class WorkflowAction {
}
}
+ private void customTraverseAAIVnf(DelegateExecution execution, List<Resource> resourceList, String serviceId,
+ String vnfId, List<Pair<WorkflowType, String>> aaiResourceIds) {
+ try {
+ ServiceInstance serviceInstanceAAI = bbInputSetupUtils.getAAIServiceInstanceById(serviceId);
+ org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance serviceInstanceMSO =
+ bbInputSetup.getExistingServiceInstance(serviceInstanceAAI);
+ resourceList.add(new Resource(WorkflowType.SERVICE, serviceInstanceMSO.getServiceInstanceId(), false));
+ if (serviceInstanceMSO.getVnfs() != null) {
+ for (org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf vnf : serviceInstanceMSO.getVnfs()) {
+ if (vnf.getVnfId().equals(vnfId)) {
+ aaiResourceIds.add(new Pair<>(WorkflowType.VNF, vnf.getVnfId()));
+
+ String vnfCustomizationUUID =
+ bbInputSetupUtils.getAAIGenericVnf(vnfId).getModelCustomizationId();
+ resourceList.add(new Resource(WorkflowType.VNF, vnfCustomizationUUID, false));
+
+ if (vnf.getVfModules() != null) {
+ for (VfModule vfModule : vnf.getVfModules()) {
+ aaiResourceIds.add(new Pair<>(WorkflowType.VFMODULE, vfModule.getVfModuleId()));
+ resourceList.add(new Resource(WorkflowType.VFMODULE, vfModule.getVfModuleId(), false));
+ findConfigurationsInsideVfModule(execution, vnf.getVnfId(), vfModule.getVfModuleId(),
+ resourceList, aaiResourceIds);
+ }
+ }
+ if (vnf.getVolumeGroups() != null) {
+ for (org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup volumeGroup : vnf
+ .getVolumeGroups()) {
+ aaiResourceIds
+ .add(new Pair<>(WorkflowType.VOLUMEGROUP, volumeGroup.getVolumeGroupId()));
+ resourceList.add(
+ new Resource(WorkflowType.VOLUMEGROUP, volumeGroup.getVolumeGroupId(), false));
+ }
+ }
+ break;
+ }
+ }
+ }
+ } catch (Exception ex) {
+ logger.error("Exception in customTraverseAAIVnf", ex);
+ buildAndThrowException(execution,
+ "Could not find existing Vnf or related Instances to execute the request on.");
+ }
+
+ }
+
private void findConfigurationsInsideVfModule(DelegateExecution execution, String vnfId, String vfModuleId,
List<Resource> resourceList, List<Pair<WorkflowType, String>> aaiResourceIds) {
try {
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
new file mode 100644
index 0000000000..f44c15ac54
--- /dev/null
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/CnfAdapterClient.java
@@ -0,0 +1,97 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.client.adapter.cnf;
+
+import java.util.ArrayList;
+import java.util.List;
+import javax.persistence.EntityNotFoundException;
+import javax.ws.rs.core.UriBuilder;
+import org.apache.http.HttpStatus;
+import org.onap.so.client.adapter.cnf.entities.InstanceRequest;
+import org.onap.so.client.adapter.cnf.entities.InstanceResponse;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.env.Environment;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.ResponseEntity;
+import org.springframework.retry.annotation.Backoff;
+import org.springframework.retry.annotation.Retryable;
+import org.springframework.stereotype.Component;
+import org.springframework.web.client.HttpClientErrorException;
+import org.springframework.web.client.HttpServerErrorException;
+import org.springframework.web.client.RestTemplate;
+
+@Component
+public class CnfAdapterClient {
+
+ private static final Logger logger = LoggerFactory.getLogger(CnfAdapterClient.class);
+
+ @Autowired
+ private RestTemplate restTemplate;
+
+ @Autowired
+ private Environment env;
+
+ private static final String INSTANCE_CREATE_PATH = "/api/multicloud-k8s/v1/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 endpoint = UriBuilder.fromUri(uri).path(INSTANCE_CREATE_PATH).build().toString();
+ HttpEntity<?> entity = getHttpEntity(request);
+ ResponseEntity<InstanceResponse> result =
+ restTemplate.exchange(endpoint, HttpMethod.POST, entity, InstanceResponse.class);
+ return result.getBody();
+ } 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;
+ }
+ }
+
+ protected HttpHeaders getHttpHeaders() {
+ HttpHeaders headers = new HttpHeaders();
+ List<org.springframework.http.MediaType> acceptableMediaTypes = new ArrayList<>();
+ acceptableMediaTypes.add(org.springframework.http.MediaType.APPLICATION_JSON);
+ headers.setAccept(acceptableMediaTypes);
+ /*
+ * try { String userCredentials = CryptoUtils.decrypt(env.getRequiredProperty("mso.cnf.adapter.auth"),
+ * env.getRequiredProperty("mso.msoKey")); if (userCredentials != null) { headers.add(HttpHeaders.AUTHORIZATION,
+ * "Basic " + DatatypeConverter.printBase64Binary(userCredentials.getBytes())); } } catch
+ * (GeneralSecurityException e) { logger.error("Security exception", e); }
+ */
+ return headers;
+ }
+
+ protected HttpEntity<?> getHttpEntity(InstanceRequest request) {
+ HttpHeaders headers = getHttpHeaders();
+ return new HttpEntity<>(request, headers);
+ }
+
+}
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/CnfAdapterClientException.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/CnfAdapterClientException.java
new file mode 100644
index 0000000000..d716070ffa
--- /dev/null
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/CnfAdapterClientException.java
@@ -0,0 +1,34 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.client.adapter.cnf;
+
+public class CnfAdapterClientException extends Exception {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = -7154784472485852602L;
+
+ public CnfAdapterClientException(String message) {
+ super(message);
+ }
+
+}
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/entities/GVK.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/entities/GVK.java
new file mode 100644
index 0000000000..3ed6894fcf
--- /dev/null
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/entities/GVK.java
@@ -0,0 +1,49 @@
+
+package org.onap.so.client.adapter.cnf.entities;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.annotation.JsonPropertyOrder;
+
+@JsonInclude(JsonInclude.Include.NON_NULL)
+@JsonPropertyOrder({"Group", "Version", "Kind"})
+public class GVK {
+
+ @JsonProperty("Group")
+ private String group;
+ @JsonProperty("Version")
+ private String version;
+ @JsonProperty("Kind")
+ private String kind;
+
+ @JsonProperty("Group")
+ public String getGroup() {
+ return group;
+ }
+
+ @JsonProperty("Group")
+ public void setGroup(String group) {
+ this.group = group;
+ }
+
+ @JsonProperty("Version")
+ public String getVersion() {
+ return version;
+ }
+
+ @JsonProperty("Version")
+ public void setVersion(String version) {
+ this.version = version;
+ }
+
+ @JsonProperty("Kind")
+ public String getKind() {
+ return kind;
+ }
+
+ @JsonProperty("Kind")
+ public void setKind(String kind) {
+ this.kind = kind;
+ }
+
+}
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/entities/InstanceRequest.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/entities/InstanceRequest.java
new file mode 100644
index 0000000000..e4058097ab
--- /dev/null
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/entities/InstanceRequest.java
@@ -0,0 +1,95 @@
+
+package org.onap.so.client.adapter.cnf.entities;
+
+import java.util.Map;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.annotation.JsonPropertyOrder;
+
+@JsonInclude(JsonInclude.Include.NON_NULL)
+@JsonPropertyOrder({"rb-name", "rb-version", "profile-name", "release-name", "cloud-region", "labels",
+ "override-values"})
+public class InstanceRequest {
+
+ @JsonProperty("rb-name")
+ private String rbName;
+ @JsonProperty("rb-version")
+ private String rbVersion;
+ @JsonProperty("profile-name")
+ private String profileName;
+ @JsonProperty("release-name")
+ private String releaseName;
+ @JsonProperty("cloud-region")
+ private String cloudRegion;
+ @JsonProperty("labels")
+ private Labels labels;
+ @JsonProperty(value = "override-values")
+ private Map<String, String> overrideValues;
+
+ @JsonProperty("rb-name")
+ public String getRbName() {
+ return rbName;
+ }
+
+ @JsonProperty("rb-name")
+ public void setRbName(String rbName) {
+ this.rbName = rbName;
+ }
+
+ @JsonProperty("rb-version")
+ public String getRbVersion() {
+ return rbVersion;
+ }
+
+ @JsonProperty("rb-version")
+ public void setRbVersion(String rbVersion) {
+ this.rbVersion = rbVersion;
+ }
+
+ @JsonProperty("profile-name")
+ public String getProfileName() {
+ return profileName;
+ }
+
+ @JsonProperty("profile-name")
+ public void setProfileName(String profileName) {
+ this.profileName = profileName;
+ }
+
+ @JsonProperty("cloud-region")
+ public String getCloudRegion() {
+ return cloudRegion;
+ }
+
+ @JsonProperty("cloud-region")
+ public void setCloudRegion(String cloudRegion) {
+ this.cloudRegion = cloudRegion;
+ }
+
+ @JsonProperty("labels")
+ public Labels getLabels() {
+ return labels;
+ }
+
+ @JsonProperty("labels")
+ public void setLabels(Labels labels) {
+ this.labels = labels;
+ }
+
+ public String getReleaseName() {
+ return releaseName;
+ }
+
+ public void setReleaseName(String releaseName) {
+ this.releaseName = releaseName;
+ }
+
+ public Map<String, String> getOverrideValues() {
+ return overrideValues;
+ }
+
+ public void setOverrideValues(Map<String, String> overrideValues) {
+ this.overrideValues = overrideValues;
+ }
+
+}
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
new file mode 100644
index 0000000000..e38bcc2664
--- /dev/null
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/entities/InstanceResponse.java
@@ -0,0 +1,62 @@
+
+package org.onap.so.client.adapter.cnf.entities;
+
+import java.util.List;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.annotation.JsonPropertyOrder;
+
+@JsonInclude(JsonInclude.Include.NON_NULL)
+@JsonPropertyOrder({"id", "request", "namespace", "resources"})
+public class InstanceResponse {
+
+ @JsonProperty("id")
+ private String id;
+ @JsonProperty("request")
+ private InstanceRequest request;
+ @JsonProperty("namespace")
+ private String namespace;
+ @JsonProperty("resources")
+ private List<Resource> resources = null;
+
+ @JsonProperty("id")
+ public String getId() {
+ return id;
+ }
+
+ @JsonProperty("id")
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ @JsonProperty("request")
+ public InstanceRequest getRequest() {
+ return request;
+ }
+
+ @JsonProperty("request")
+ public void setRequest(InstanceRequest request) {
+ this.request = request;
+ }
+
+ @JsonProperty("namespace")
+ public String getNamespace() {
+ return namespace;
+ }
+
+ @JsonProperty("namespace")
+ public void setNamespace(String namespace) {
+ this.namespace = namespace;
+ }
+
+ @JsonProperty("resources")
+ public List<Resource> getResources() {
+ return resources;
+ }
+
+ @JsonProperty("resources")
+ public void setResources(List<Resource> resources) {
+ this.resources = resources;
+ }
+
+}
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/entities/Labels.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/entities/Labels.java
new file mode 100644
index 0000000000..1df2e59459
--- /dev/null
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/entities/Labels.java
@@ -0,0 +1,25 @@
+
+package org.onap.so.client.adapter.cnf.entities;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.annotation.JsonPropertyOrder;
+
+@JsonInclude(JsonInclude.Include.NON_NULL)
+@JsonPropertyOrder({"testCaseName"})
+public class Labels {
+
+ @JsonProperty("testCaseName")
+ private String testCaseName;
+
+ @JsonProperty("testCaseName")
+ public String getTestCaseName() {
+ return testCaseName;
+ }
+
+ @JsonProperty("testCaseName")
+ public void setTestCaseName(String testCaseName) {
+ this.testCaseName = testCaseName;
+ }
+
+}
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/entities/Resource.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/entities/Resource.java
new file mode 100644
index 0000000000..bde495aaa2
--- /dev/null
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/entities/Resource.java
@@ -0,0 +1,37 @@
+
+package org.onap.so.client.adapter.cnf.entities;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.annotation.JsonPropertyOrder;
+
+@JsonInclude(JsonInclude.Include.NON_NULL)
+@JsonPropertyOrder({"GVK", "Name"})
+public class Resource {
+
+ @JsonProperty("GVK")
+ private GVK gVK;
+ @JsonProperty("Name")
+ private String name;
+
+ @JsonProperty("GVK")
+ public GVK getGVK() {
+ return gVK;
+ }
+
+ @JsonProperty("GVK")
+ public void setGVK(GVK gVK) {
+ this.gVK = gVK;
+ }
+
+ @JsonProperty("Name")
+ public String getName() {
+ return name;
+ }
+
+ @JsonProperty("Name")
+ public void setName(String name) {
+ this.name = name;
+ }
+
+}
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/vnf/mapper/Attributes.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/vnf/mapper/Attributes.java
new file mode 100644
index 0000000000..6d79c20616
--- /dev/null
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/vnf/mapper/Attributes.java
@@ -0,0 +1,23 @@
+package org.onap.so.client.adapter.vnf.mapper;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+public class Attributes implements Serializable {
+
+ private static final long serialVersionUID = -5782985934617532582L;
+
+ @JsonProperty("attributes")
+ private List<AttributeNameValue> attributes = new ArrayList<>();
+
+ public List<AttributeNameValue> getAttributes() {
+ return attributes;
+ }
+
+ public void setAttributes(List<AttributeNameValue> attributes) {
+ this.attributes = attributes;
+ }
+
+}
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 bc618e17de..59da22f8e1 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
@@ -178,7 +178,7 @@ public class VnfAdapterVfModuleObjectMapper {
return msoRequest;
}
- private Map<String, Object> buildVfModuleParamsMap(RequestContext requestContext, ServiceInstance serviceInstance,
+ public Map<String, Object> buildVfModuleParamsMap(RequestContext requestContext, ServiceInstance serviceInstance,
GenericVnf genericVnf, VfModule vfModule, String sdncVnfQueryResponse, String sdncVfModuleQueryResponse)
throws IOException, MissingValueTagException {
diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/service/level/ServiceLevelPreparationTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/service/level/ServiceLevelPreparationTest.java
index a99ee7d2df..0b1c5b0f5e 100644
--- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/service/level/ServiceLevelPreparationTest.java
+++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/service/level/ServiceLevelPreparationTest.java
@@ -20,6 +20,13 @@
package org.onap.so.bpmn.infrastructure.service.level;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.when;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
import org.camunda.bpm.engine.delegate.BpmnError;
import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake;
@@ -27,86 +34,79 @@ import org.junit.Before;
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.Spy;
+import org.onap.so.bpmn.BaseTaskTest;
+import org.onap.so.bpmn.infrastructure.service.level.impl.ServiceLevelConstants;
import org.onap.so.bpmn.infrastructure.service.level.impl.ServiceLevelPreparation;
import org.onap.so.client.exception.ExceptionBuilder;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.onap.so.bpmn.infrastructure.service.level.AbstractServiceLevelPreparable.RESOURCE_TYPE;
-import static org.onap.so.bpmn.infrastructure.service.level.AbstractServiceLevelPreparable.WORKFLOW_TO_INVOKE;
-
+import org.onap.so.db.catalog.beans.Workflow;
-@RunWith(SpringJUnit4ClassRunner.class)
-@ContextConfiguration(classes = {ServiceLevelPreparation.class, ExceptionBuilder.class})
-public class ServiceLevelPreparationTest {
+public class ServiceLevelPreparationTest extends BaseTaskTest {
private static final String TEST_PNF_SCOPE = "pnf";
private static final String TEST_PROCESS_KEY = "testProcessKey";
private static final String PROCESS_KEY_VALUE = "testProcessKeyValue";
- private static final List<String> PNF_HEALTH_CHECK_PARAMS = Arrays.asList("SERVICE_MODEL_INFO",
- "SERVICE_INSTANCE_NAME", "PNF_CORRELATION_ID", "MODEL_UUID", "PNF_UUID", "PRC_BLUEPRINT_NAME",
- "PRC_BLUEPRINT_VERSION", "PRC_CUSTOMIZATION_UUID", "RESOURCE_CUSTOMIZATION_UUID_PARAM", "PRC_INSTANCE_NAME",
- "PRC_CONTROLLER_ACTOR", "REQUEST_PAYLOAD");
- private Map<String, String> pnfHealthCheckTestParams = new HashMap<>();
+ private static final String BPMN_REQUEST = "bpmnRequest";
+ private static final String RESOURCE_TYPE = "resourceType";
+ private static final String SERVICE_INSTANCE_ID = "serviceInstanceId";
+ private static final String PNF_NAME = "pnfName";
+ private static final String HEALTH_CHECK_OPERATION = "ResourceHealthCheck";
+ private static final String PNF_HEALTH_CHECK_WORKFLOW = "PNFHealthCheck";
+ private static final Map<String, List<String>> HEALTH_CHECK_PARAMS_MAP = Map.of(TEST_PNF_SCOPE,
+ Arrays.asList(SERVICE_INSTANCE_ID, RESOURCE_TYPE, BPMN_REQUEST, PNF_NAME), "vnf", Collections.emptyList());
- @Autowired
- private ServiceLevelPreparation serviceLevelPrepare;
-
- @Autowired
- private ExceptionBuilder exceptionBuilder;
+ private List<Workflow> workflowList = new ArrayList<>();
@Rule
public ExpectedException thrown = ExpectedException.none();
+ @InjectMocks
+ private ServiceLevelPreparation serviceLevelPrepare;
+
+ @InjectMocks
+ @Spy
+ private ExceptionBuilder exceptionBuilder;
+
private DelegateExecution execution = new DelegateExecutionFake();
private DelegateExecution invalidExecution = new DelegateExecutionFake();
@Before
public void setUpPnfUpgradeTest() {
- pnfHealthCheckTestParams.put("TEST_SERVICE_MODEL_INFO", "d4c6855e-3be2-5dtu-9390-c999a38829bc");
- pnfHealthCheckTestParams.put("TEST_SERVICE_INSTANCE_NAME", "test_service_id");
- pnfHealthCheckTestParams.put("TEST_PNF_CORRELATION_ID", "pnfCorrelationId");
- pnfHealthCheckTestParams.put("TEST_MODEL_UUID", "6bc0b04d-1873-4721-b53d-6615225b2a28");
- pnfHealthCheckTestParams.put("TEST_PNF_UUID", "c93g70d9-8de3-57f1-7de1-f5690ac2b005");
- pnfHealthCheckTestParams.put("TEST_PRC_BLUEPRINT_NAME", "serviceUpgrade");
- pnfHealthCheckTestParams.put("TEST_PRC_BLUEPRINT_VERSION", "1.0.2");
- pnfHealthCheckTestParams.put("TEST_PRC_CUSTOMIZATION_UUID", "PRC_customizationUuid");
- pnfHealthCheckTestParams.put("TEST_RESOURCE_CUSTOMIZATION_UUID_PARAM", "9acb3a83-8a52-412c-9a45-901764938144");
- pnfHealthCheckTestParams.put("TEST_PRC_INSTANCE_NAME", "Demo_pnf");
- pnfHealthCheckTestParams.put("TEST_PRC_CONTROLLER_ACTOR", "cds");
- pnfHealthCheckTestParams.put("TEST_REQUEST_PAYLOAD", "test_payload");
-
- for (String param : PNF_HEALTH_CHECK_PARAMS) {
- execution.setVariable(param, pnfHealthCheckTestParams.get("TEST_" + param));
- }
execution.setVariable(RESOURCE_TYPE, TEST_PNF_SCOPE);
execution.setVariable(TEST_PROCESS_KEY, PROCESS_KEY_VALUE);
+ execution.setVariable(BPMN_REQUEST, "bpmnRequestValue");
+ execution.setVariable(SERVICE_INSTANCE_ID, "serviceInstanceIdValue");
+ execution.setVariable(PNF_NAME, "PnfDemo");
invalidExecution.setVariables(execution.getVariables());
+
+ Workflow pnfWorkflow = new Workflow();
+ pnfWorkflow.setName(PNF_HEALTH_CHECK_WORKFLOW);
+ pnfWorkflow.setOperationName(HEALTH_CHECK_OPERATION);
+ pnfWorkflow.setResourceTarget(TEST_PNF_SCOPE);
+ workflowList.add(pnfWorkflow);
+
+ when(catalogDbClient.findWorkflowByOperationName(HEALTH_CHECK_OPERATION)).thenReturn(workflowList);
}
@Test
public void executePnfUpgradeSuccessTest() throws Exception {
serviceLevelPrepare.execute(execution);
// Expect the pnf health check workflow to be set in to execution if validation is successful
- assertThat(String.valueOf(execution.getVariable(WORKFLOW_TO_INVOKE))).isEqualTo("GenericPnfHealthCheck");
+ assertThat(String.valueOf(execution.getVariable(ServiceLevelConstants.HEALTH_CHECK_WORKFLOW_TO_INVOKE)))
+ .isEqualTo("PNFHealthCheck");
}
@Test
public void validateFailureParamsForPnfTest() throws Exception {
- invalidExecution.removeVariable("PNF_UUID");
- invalidExecution.setVariable("PRC_BLUEPRINT_NAME", null);
+ invalidExecution.removeVariable(BPMN_REQUEST);
// BPMN exception is thrown in case of validation failure or invalid execution
thrown.expect(BpmnError.class);
- serviceLevelPrepare.validateParamsWithScope(invalidExecution, TEST_PNF_SCOPE, PNF_HEALTH_CHECK_PARAMS);
+ serviceLevelPrepare.validateParamsWithScope(invalidExecution, TEST_PNF_SCOPE,
+ HEALTH_CHECK_PARAMS_MAP.get(TEST_PNF_SCOPE));
}
@Test
@@ -125,6 +125,32 @@ public class ServiceLevelPreparationTest {
}
+ @Test
+ public void validateDefaultWorkflowIsSetWithoutDBData() throws Exception {
+ // Mock empty workflow list in db response
+ when(catalogDbClient.findWorkflowByOperationName(HEALTH_CHECK_OPERATION)).thenReturn(new ArrayList<Workflow>());
+ serviceLevelPrepare.execute(execution);
+ // Expect default workflow gets assigned when workflow name not found in db.
+ assertThat(String.valueOf(execution.getVariable(ServiceLevelConstants.HEALTH_CHECK_WORKFLOW_TO_INVOKE)))
+ .isEqualTo(ServiceLevelConstants.DEFAULT_HEALTH_CHECK_WORKFLOWS.get(TEST_PNF_SCOPE));
+ }
+
+ @Test
+ public void validateWorkflowSetFromDb() throws Exception {
+ Workflow vnfWorkflow = new Workflow();
+ vnfWorkflow.setName("VNFHealthCheck");
+ vnfWorkflow.setOperationName(HEALTH_CHECK_OPERATION);
+ vnfWorkflow.setResourceTarget("vnf");
+ workflowList.add(vnfWorkflow);
+ // Mock db response with multiple worklfows mapped with same operation name
+ when(catalogDbClient.findWorkflowByOperationName(HEALTH_CHECK_OPERATION)).thenReturn(workflowList);
+ serviceLevelPrepare.execute(execution);
+
+ // Expect right workflow gets assigned from db based on the controller scope.
+ assertThat(String.valueOf(execution.getVariable(ServiceLevelConstants.HEALTH_CHECK_WORKFLOW_TO_INVOKE)))
+ .isEqualTo(PNF_HEALTH_CHECK_WORKFLOW);
+ }
+
}
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 407a844c4e..c1970ec32c 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
@@ -1601,6 +1601,79 @@ public class WorkflowActionTest extends BaseTaskTest {
}
@Test
+ public void getConfigBuildingBlocksNullConfigurationTest() throws Exception {
+ String gAction = "deleteInstance";
+ ObjectMapper mapper = new ObjectMapper();
+ mapper.disable(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES);
+
+ WorkflowType resourceType = WorkflowType.VFMODULE;
+ execution.setVariable("mso-request-id", "00f704ca-c5e5-4f95-a72c-6889db7b0688");
+ execution.setVariable("requestAction", gAction);
+ String bpmnRequest =
+ new String(Files.readAllBytes(Paths.get("src/test/resources/__files/VfModuleCreateWithFabric.json")));
+ execution.setVariable("bpmnRequest", bpmnRequest);
+ execution.setVariable("vnfId", "1234");
+ execution.setVariable("vfModuleId", "vfModuleId1234");
+ execution.setVariable("requestUri",
+ "v7/serviceInstances/f647e3ef-6d2e-4cd3-bff4-8df4634208de/vnfs/b80b16a5-f80d-4ffa-91c8-bd47c7438a3d/vfModules");
+ ServiceInstancesRequest sIRequest = mapper.readValue(bpmnRequest, ServiceInstancesRequest.class);
+ RequestDetails requestDetails = sIRequest.getRequestDetails();
+ String requestAction = "deleteInstance";
+ String requestId = "9c944122-d161-4280-8594-48c06a9d96d5";
+ boolean aLaCarte = true;
+ String apiVersion = "7";
+ String vnfType = "vnfType";
+ String key = "00d15ebb-c80e-43c1-80f0-90c40dde70b0";
+ String resourceId = "d1d35800-783d-42d3-82f6-d654c5054a6e";
+ Resource resourceKey = new Resource(resourceType, key, aLaCarte);
+ WorkflowResourceIds workflowResourceIds = SPY_workflowAction.populateResourceIdsFromApiHandler(execution);
+
+ List<OrchestrationFlow> orchFlows = createFlowList("DeactivateVfModuleBB", "DeleteVfModuleBB",
+ "UnassignVfModuleBB", "DeleteFabricConfigurationBB");
+
+ ConfigBuildingBlocksDataObject dataObj = new ConfigBuildingBlocksDataObject().setsIRequest(sIRequest)
+ .setOrchFlows(orchFlows).setRequestId(requestId).setResourceKey(resourceKey).setApiVersion(apiVersion)
+ .setResourceId(resourceId).setRequestAction(requestAction).setaLaCarte(aLaCarte).setVnfType(vnfType)
+ .setWorkflowResourceIds(workflowResourceIds).setRequestDetails(requestDetails).setExecution(execution);
+
+ org.onap.aai.domain.yang.GenericVnf vnf = new org.onap.aai.domain.yang.GenericVnf();
+ vnf.setVnfId("vnf0");
+ vnf.setModelCustomizationId("modelCustomizationId");
+ when(bbSetupUtils.getAAIGenericVnf(any())).thenReturn(vnf);
+
+ org.onap.aai.domain.yang.VfModule vfModule = new org.onap.aai.domain.yang.VfModule();
+ vfModule.setModelCustomizationId("modelCustomizationId");
+
+ /* this is a test case where configuration for vnfc is null */
+ org.onap.aai.domain.yang.Configuration config1 = null;
+ org.onap.aai.domain.yang.Configuration config2 = new org.onap.aai.domain.yang.Configuration();
+ config2.setConfigurationId("config2");
+
+ List<org.onap.aai.domain.yang.Vnfc> vnfcs = new ArrayList<org.onap.aai.domain.yang.Vnfc>();
+ org.onap.aai.domain.yang.Vnfc vnfc1 = new org.onap.aai.domain.yang.Vnfc();
+ vnfc1.setVnfcName("zauk53avetd02svm001");
+ org.onap.aai.domain.yang.Vnfc vnfc2 = new org.onap.aai.domain.yang.Vnfc();
+ vnfc2.setVnfcName("zauk53avetd02tvm001");
+ vnfcs.add(vnfc1);
+ vnfcs.add(vnfc2);
+
+ when(bbSetupUtils.getAAIVfModule(any(), any())).thenReturn(vfModule);
+ doReturn(vnfcs).when(SPY_workflowAction).getRelatedResourcesInVfModule(any(), any(),
+ eq(org.onap.aai.domain.yang.Vnfc.class), eq(AAIObjectType.VNFC));
+ doReturn(config1).when(SPY_workflowAction).getRelatedResourcesInVnfc(eq(vnfc1),
+ eq(org.onap.aai.domain.yang.Configuration.class), eq(AAIObjectType.CONFIGURATION));
+ doReturn(config2).when(SPY_workflowAction).getRelatedResourcesInVnfc(eq(vnfc2),
+ eq(org.onap.aai.domain.yang.Configuration.class), eq(AAIObjectType.CONFIGURATION));
+
+ List<ExecuteBuildingBlock> results = SPY_workflowAction.getConfigBuildingBlocks(dataObj);
+
+ assertFalse(results.isEmpty());
+ assertEquals(1, results.size());
+ assertEquals("config2", results.get(0).getWorkflowResourceIds().getConfigurationId());
+ assertEquals("zauk53avetd02tvm001", results.get(0).getConfigurationResourceKeys().getVnfcName());
+ }
+
+ @Test
public void selectExecutionListALaCarteVfModuleNoFabricDeleteTest() throws Exception {
String gAction = "deleteInstance";
String resource = "VfModule";