dfc77d6f0c0344e38e1d028daa663c0069eb2388
[so.git] /
1 package org.onap.so.bpmn.infrastructure.service.level.impl;
2
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;
8 import java.util.List;
9
10 @Component
11 public class ServiceLevelUpgrade extends AbstractServiceLevelPreparable implements JavaDelegate {
12
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);
15
16     @Override
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;
22                 break;
23             case ServiceLevelConstants.VNF:
24                 wflName = ServiceLevelConstants.GENERIC_VNF_HEALTH_CHECK_WORKFLOW;
25                 break;
26             default:
27                 exceptionBuilder.buildAndThrowWorkflowException(execution, ServiceLevelConstants.ERROR_CODE,
28                         "No valid health check work flow retrieved for the scope: " + scope);
29         }
30         return wflName;
31     }
32
33     @Override
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);
41
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, "");
47             }
48
49         } else {
50             exceptionBuilder.buildAndThrowWorkflowException(execution, ServiceLevelConstants.ERROR_CODE,
51                     "Controller scope not found to invoke resource level health check");
52         }
53     }
54 }