1 package org.onap.so.bpmn.infrastructure.service.level.impl;
 
   3 import org.camunda.bpm.engine.delegate.DelegateExecution;
 
   4 import org.camunda.bpm.engine.delegate.JavaDelegate;
 
   5 import org.onap.so.bpmn.infrastructure.service.level.AbstractServiceLevelPreparable;
 
   6 import org.springframework.stereotype.Component;
 
   7 import java.util.Arrays;
 
  11 public class ServiceLevelUpgrade extends AbstractServiceLevelPreparable implements JavaDelegate {
 
  13     private static final List<String> PNF_SWU_PARAMS = Arrays.asList(ServiceLevelConstants.SERVICE_INSTANCE_ID,
 
  14             ServiceLevelConstants.RESOURCE_TYPE, ServiceLevelConstants.BPMN_REQUEST, ServiceLevelConstants.PNF_NAME);
 
  17     protected String fetchWorkflowUsingScope(DelegateExecution execution, String scope) {
 
  18         String wflName = null;
 
  19         switch (scope.toLowerCase()) {
 
  20             case ServiceLevelConstants.PNF:
 
  21                 wflName = ServiceLevelConstants.PNF_SOFTWARE_UPGRADE_WORKFLOW;
 
  23             case ServiceLevelConstants.VNF:
 
  24                 wflName = ServiceLevelConstants.GENERIC_VNF_HEALTH_CHECK_WORKFLOW;
 
  27                 exceptionBuilder.buildAndThrowWorkflowException(execution, ServiceLevelConstants.ERROR_CODE,
 
  28                         "No valid health check work flow retrieved for the scope: " + scope);
 
  34     public void execute(DelegateExecution execution) throws Exception {
 
  35         if (execution.hasVariable(ServiceLevelConstants.RESOURCE_TYPE)
 
  36                 && execution.getVariable(ServiceLevelConstants.RESOURCE_TYPE) != null) {
 
  37             final String controllerScope = (String) execution.getVariable(ServiceLevelConstants.RESOURCE_TYPE);
 
  38             LOG.debug("Scope retrieved from delegate execution: " + controllerScope);
 
  39             final String wflName = fetchWorkflowUsingScope(execution, controllerScope);
 
  40             LOG.debug("Health check workflow fetched for the scope: {} is: {}", controllerScope, wflName);
 
  42             if ("pnf".equalsIgnoreCase(controllerScope)) {
 
  43                 validateParamsWithScope(execution, controllerScope, PNF_SWU_PARAMS);
 
  44                 LOG.info("Parameters validated successfully for {}", wflName);
 
  45                 execution.setVariable(ServiceLevelConstants.SOFTWARE_WORKFLOW_TO_INVOKE, wflName);
 
  46                 execution.setVariable(ServiceLevelConstants.CONTROLLER_STATUS, "");
 
  50             exceptionBuilder.buildAndThrowWorkflowException(execution, ServiceLevelConstants.ERROR_CODE,
 
  51                     "Controller scope not found to invoke resource level health check");