From e01546664d8d945ae83c625ab278b04ee0b9a331 Mon Sep 17 00:00:00 2001 From: tragait Date: Thu, 23 Jul 2020 17:49:06 +0100 Subject: [SO] create service upgrade workflow Issue-ID: SO-2925 Signed-off-by: tragait Change-Id: Ia10497fed1f42dea3e0469bc08ba0169862d3e71 Signed-off-by: tragait --- .../level/AbstractServiceLevelPreparable.java | 15 +-- .../service/level/impl/ServiceLevelConstants.java | 20 ++++ .../service/level/impl/ServiceLevelPostcheck.java | 13 ++ .../level/impl/ServiceLevelPreparation.java | 37 +++--- .../level/impl/ServiceLevelRequestDispatcher.java | 131 +++++++++++++++++++++ .../service/level/impl/ServiceLevelUpgrade.java | 54 +++++++++ .../level/impl/UpdateServiceInstanceInAai.java | 123 +++++++++++++++++++ 7 files changed, 363 insertions(+), 30 deletions(-) create mode 100644 bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/impl/ServiceLevelConstants.java create mode 100644 bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/impl/ServiceLevelPostcheck.java create mode 100644 bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/impl/ServiceLevelRequestDispatcher.java create mode 100644 bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/impl/ServiceLevelUpgrade.java create mode 100644 bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/impl/UpdateServiceInstanceInAai.java (limited to 'bpmn/so-bpmn-tasks/src/main') 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/AbstractServiceLevelPreparable.java index 36db549486..0671354bd6 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/AbstractServiceLevelPreparable.java @@ -21,6 +21,7 @@ package org.onap.so.bpmn.infrastructure.service.level; 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.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -33,15 +34,6 @@ import java.util.List; */ public abstract class AbstractServiceLevelPreparable { - 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); @Autowired @@ -61,8 +53,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 params) - throws Exception { + protected void validateParamsWithScope(DelegateExecution execution, final String scope, List params) { List invalidVariables = new ArrayList<>(); for (String param : params) { if (!execution.hasVariable(param) || execution.getVariable(param) == null @@ -72,7 +63,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..34ebb308c3 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/impl/ServiceLevelConstants.java @@ -0,0 +1,20 @@ +package org.onap.so.bpmn.infrastructure.service.level.impl; + +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 WORKFLOW_TO_INVOKE = "healthCheckWorkflow"; + public static final String SOFTWARE_WORKFLOW_TO_INVOKE = "softwareUpgradeWorkflow"; + public static final String GENERIC_PNF_HEALTH_CHECK_WORKFLOW = "GenericPnfHealthCheck"; + public static final String PNF_SOFTWARE_UPGRADE_WORKFLOW = "PNFSoftwareUpgrade"; + public static final String CONTROLLER_STATUS = "ControllerStatus"; + public 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"; + +} 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..5b772760f0 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 @@ -27,7 +27,6 @@ import org.springframework.stereotype.Component; import java.util.Arrays; import java.util.List; - /** * Fetches health check workflow based on the controller_scope. Invoke the corresponding health check workflow after * validation. @@ -35,24 +34,26 @@ import java.util.List; @Component("ServiceLevelPreparation") public class ServiceLevelPreparation extends AbstractServiceLevelPreparable implements JavaDelegate { - // Health check parameters to be validated for pnf resource - private static final List 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"); + private static final List PNF_HC_PARAMS = Arrays.asList(ServiceLevelConstants.SERVICE_INSTANCE_ID, + ServiceLevelConstants.RESOURCE_TYPE, ServiceLevelConstants.BPMN_REQUEST, ServiceLevelConstants.PNF_NAME); @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); + LOG.debug("Health check workflow fetched for the scope: {} is: {}", controllerScope, wflName); + + if (ServiceLevelConstants.PNF.equalsIgnoreCase(controllerScope)) { + validateParamsWithScope(execution, controllerScope, PNF_HC_PARAMS); + LOG.info("Parameters validated successfully for {}", wflName); + } + execution.setVariable(ServiceLevelConstants.WORKFLOW_TO_INVOKE, wflName); + execution.setVariable(ServiceLevelConstants.CONTROLLER_STATUS, ServiceLevelConstants.EMPTY_STRING); } else { - exceptionBuilder.buildAndThrowWorkflowException(execution, ERROR_CODE, + exceptionBuilder.buildAndThrowWorkflowException(execution, ServiceLevelConstants.ERROR_CODE, "Controller scope not found to invoke resource level health check"); } } @@ -61,14 +62,14 @@ public class ServiceLevelPreparation extends AbstractServiceLevelPreparable impl public String fetchWorkflowUsingScope(DelegateExecution execution, final String scope) { String wflName = null; switch (scope.toLowerCase()) { - case "pnf": - wflName = GENERIC_PNF_HEALTH_CHECK_WORKFLOW; + case ServiceLevelConstants.PNF: + wflName = ServiceLevelConstants.GENERIC_PNF_HEALTH_CHECK_WORKFLOW; break; - case "vnf": - wflName = GENERIC_VNF_HEALTH_CHECK_WORKFLOW; + case ServiceLevelConstants.VNF: + wflName = ServiceLevelConstants.GENERIC_VNF_HEALTH_CHECK_WORKFLOW; break; default: - exceptionBuilder.buildAndThrowWorkflowException(execution, ERROR_CODE, + exceptionBuilder.buildAndThrowWorkflowException(execution, ServiceLevelConstants.ERROR_CODE, "No valid health check work flow retrieved for the scope: " + scope); } 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 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..dfc77d6f0c --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/impl/ServiceLevelUpgrade.java @@ -0,0 +1,54 @@ +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.onap.so.bpmn.infrastructure.service.level.AbstractServiceLevelPreparable; +import org.springframework.stereotype.Component; +import java.util.Arrays; +import java.util.List; + +@Component +public class ServiceLevelUpgrade extends AbstractServiceLevelPreparable implements JavaDelegate { + + private static final List PNF_SWU_PARAMS = Arrays.asList(ServiceLevelConstants.SERVICE_INSTANCE_ID, + ServiceLevelConstants.RESOURCE_TYPE, ServiceLevelConstants.BPMN_REQUEST, ServiceLevelConstants.PNF_NAME); + + @Override + protected String fetchWorkflowUsingScope(DelegateExecution execution, String scope) { + String wflName = null; + switch (scope.toLowerCase()) { + case ServiceLevelConstants.PNF: + wflName = ServiceLevelConstants.PNF_SOFTWARE_UPGRADE_WORKFLOW; + break; + case ServiceLevelConstants.VNF: + wflName = ServiceLevelConstants.GENERIC_VNF_HEALTH_CHECK_WORKFLOW; + break; + default: + exceptionBuilder.buildAndThrowWorkflowException(execution, ServiceLevelConstants.ERROR_CODE, + "No valid health check work flow retrieved for the scope: " + scope); + } + return wflName; + } + + @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); + final String wflName = fetchWorkflowUsingScope(execution, controllerScope); + LOG.debug("Health check workflow fetched for the scope: {} is: {}", controllerScope, wflName); + + if ("pnf".equalsIgnoreCase(controllerScope)) { + validateParamsWithScope(execution, controllerScope, PNF_SWU_PARAMS); + 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, + "Controller scope not found to invoke resource level health check"); + } + } +} 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 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); + } + +} -- cgit 1.2.3-korg