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 java.util.Arrays;
24 import java.util.Collections;
25 import java.util.List;
27 import org.camunda.bpm.engine.delegate.DelegateExecution;
28 import org.camunda.bpm.engine.delegate.JavaDelegate;
29 import org.onap.so.bpmn.infrastructure.service.level.ServiceLevelPreparable;
30 import org.springframework.stereotype.Component;
34 * Fetches health check workflow based on the controller_scope. Invoke the corresponding health check workflow after
37 @Component("ServiceLevelPreparation")
38 public class ServiceLevelPreparation extends ServiceLevelPreparable implements JavaDelegate {
40 private static final List<String> PNF_HEALTH_CHECK_PARAMS = Arrays.asList(ServiceLevelConstants.SERVICE_INSTANCE_ID,
41 ServiceLevelConstants.RESOURCE_TYPE, ServiceLevelConstants.BPMN_REQUEST, ServiceLevelConstants.PNF_NAME);
43 // TODO Update the list with vnf health check parameters if any validation needed
44 private static final List<String> VNF_HEALTH_CHECK_PARAMS = Collections.emptyList();
46 private static final Map<String, List<String>> HEALTH_CHECK_PARAMS_MAP = Map.of(ServiceLevelConstants.PNF,
47 PNF_HEALTH_CHECK_PARAMS, ServiceLevelConstants.VNF, VNF_HEALTH_CHECK_PARAMS);
50 public void execute(DelegateExecution execution) throws Exception {
51 if (execution.hasVariable(ServiceLevelConstants.RESOURCE_TYPE)
52 && execution.getVariable(ServiceLevelConstants.RESOURCE_TYPE) != null) {
53 final String controllerScope = (String) execution.getVariable(ServiceLevelConstants.RESOURCE_TYPE);
54 LOG.debug("Scope retrieved from delegate execution: " + controllerScope);
55 if (ServiceLevelConstants.VALID_CONTROLLER_SCOPE.contains(controllerScope)) {
56 final String wflName =
57 fetchWorkflowUsingScope(controllerScope, ServiceLevelConstants.HEALTH_CHECK_OPERATION);
58 LOG.debug("Health check workflow fetched for the scope: {} is: {}", controllerScope, wflName);
59 validateParamsWithScope(execution, controllerScope, HEALTH_CHECK_PARAMS_MAP.get(controllerScope));
60 LOG.info("Parameters validated successfully for {}", wflName);
61 execution.setVariable(ServiceLevelConstants.HEALTH_CHECK_WORKFLOW_TO_INVOKE, wflName);
62 execution.setVariable(ServiceLevelConstants.CONTROLLER_STATUS, ServiceLevelConstants.EMPTY_STRING);
64 exceptionBuilder.buildAndThrowWorkflowException(execution, ServiceLevelConstants.ERROR_CODE,
65 "Invalid Controller scope to prepare resource level health check");
68 exceptionBuilder.buildAndThrowWorkflowException(execution, ServiceLevelConstants.ERROR_CODE,
69 "Resource type not found in the execution to invoke resource level health check");