52521ce16bf6a0ebbb5cdd81c72f87db33146146
[so.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2020 Nordix Foundation.
4  * ================================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.so.bpmn.infrastructure.service.level.impl;
22
23 import org.camunda.bpm.engine.delegate.DelegateExecution;
24 import org.camunda.bpm.engine.delegate.JavaDelegate;
25 import org.onap.so.bpmn.infrastructure.service.level.AbstractServiceLevelPreparable;
26 import org.springframework.stereotype.Component;
27 import java.util.Arrays;
28 import java.util.List;
29
30
31 /**
32  * Fetches health check workflow based on the controller_scope. Invoke the corresponding health check workflow after
33  * validation.
34  */
35 @Component("ServiceLevelPreparation")
36 public class ServiceLevelPreparation extends AbstractServiceLevelPreparable implements JavaDelegate {
37
38     // Health check parameters to be validated for pnf resource
39     private static final List<String> PNF_HC_PARAMS = Arrays.asList("SERVICE_MODEL_INFO", "SERVICE_INSTANCE_NAME",
40             "PNF_CORRELATION_ID", "MODEL_UUID", "PNF_UUID", "PRC_BLUEPRINT_NAME", "PRC_BLUEPRINT_VERSION",
41             "PRC_CUSTOMIZATION_UUID", "RESOURCE_CUSTOMIZATION_UUID_PARAM", "PRC_INSTANCE_NAME", "PRC_CONTROLLER_ACTOR",
42             "REQUEST_PAYLOAD");
43
44     @Override
45     public void execute(DelegateExecution execution) throws Exception {
46         if (execution.hasVariable(RESOURCE_TYPE) && execution.getVariable(RESOURCE_TYPE) != null) {
47             final String controllerScope = (String) execution.getVariable(RESOURCE_TYPE);
48             LOG.debug("Scope retrieved from delegate execution: " + controllerScope);
49             final String wflName = fetchWorkflowUsingScope(execution, controllerScope);
50             LOG.debug("Health check workflow fetched for the scope: {}", wflName);
51             validateParamsWithScope(execution, controllerScope, PNF_HC_PARAMS);
52             LOG.info("Parameters validated successfully for {}", wflName);
53             execution.setVariable(WORKFLOW_TO_INVOKE, wflName);
54         } else {
55             exceptionBuilder.buildAndThrowWorkflowException(execution, ERROR_CODE,
56                     "Controller scope not found to invoke resource level health check");
57         }
58     }
59
60     @Override
61     public String fetchWorkflowUsingScope(DelegateExecution execution, final String scope) {
62         String wflName = null;
63         switch (scope.toLowerCase()) {
64             case "pnf":
65                 wflName = GENERIC_PNF_HEALTH_CHECK_WORKFLOW;
66                 break;
67             case "vnf":
68                 wflName = GENERIC_VNF_HEALTH_CHECK_WORKFLOW;
69                 break;
70             default:
71                 exceptionBuilder.buildAndThrowWorkflowException(execution, ERROR_CODE,
72                         "No valid health check work flow retrieved for the scope: " + scope);
73         }
74         return wflName;
75     }
76
77 }