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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.so.bpmn.infrastructure.service.level.impl;
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;
32 * Fetches health check workflow based on the controller_scope. Invoke the corresponding health check workflow after
35 @Component("ServiceLevelPreparation")
36 public class ServiceLevelPreparation extends AbstractServiceLevelPreparable implements JavaDelegate {
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",
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);
55 exceptionBuilder.buildAndThrowWorkflowException(execution, ERROR_CODE,
56 "Controller scope not found to invoke resource level health check");
61 public String fetchWorkflowUsingScope(DelegateExecution execution, final String scope) {
62 String wflName = null;
63 switch (scope.toLowerCase()) {
65 wflName = GENERIC_PNF_HEALTH_CHECK_WORKFLOW;
68 wflName = GENERIC_VNF_HEALTH_CHECK_WORKFLOW;
71 exceptionBuilder.buildAndThrowWorkflowException(execution, ERROR_CODE,
72 "No valid health check work flow retrieved for the scope: " + scope);