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;
31 * Fetches health check workflow based on the controller_scope. Invoke the corresponding health check workflow after
34 @Component("ServiceLevelPreparation")
35 public class ServiceLevelPreparation extends AbstractServiceLevelPreparable implements JavaDelegate {
37 private static final List<String> PNF_HC_PARAMS = Arrays.asList(ServiceLevelConstants.SERVICE_INSTANCE_ID,
38 ServiceLevelConstants.RESOURCE_TYPE, ServiceLevelConstants.BPMN_REQUEST, ServiceLevelConstants.PNF_NAME);
41 public void execute(DelegateExecution execution) throws Exception {
42 if (execution.hasVariable(ServiceLevelConstants.RESOURCE_TYPE)
43 && execution.getVariable(ServiceLevelConstants.RESOURCE_TYPE) != null) {
44 final String controllerScope = (String) execution.getVariable(ServiceLevelConstants.RESOURCE_TYPE);
45 LOG.debug("Scope retrieved from delegate execution: " + controllerScope);
46 final String wflName = fetchWorkflowUsingScope(execution, controllerScope);
47 LOG.debug("Health check workflow fetched for the scope: {} is: {}", controllerScope, wflName);
49 if (ServiceLevelConstants.PNF.equalsIgnoreCase(controllerScope)) {
50 validateParamsWithScope(execution, controllerScope, PNF_HC_PARAMS);
51 LOG.info("Parameters validated successfully for {}", wflName);
53 execution.setVariable(ServiceLevelConstants.WORKFLOW_TO_INVOKE, wflName);
54 execution.setVariable(ServiceLevelConstants.CONTROLLER_STATUS, ServiceLevelConstants.EMPTY_STRING);
56 exceptionBuilder.buildAndThrowWorkflowException(execution, ServiceLevelConstants.ERROR_CODE,
57 "Controller scope not found to invoke resource level health check");
62 public String fetchWorkflowUsingScope(DelegateExecution execution, final String scope) {
63 String wflName = null;
64 switch (scope.toLowerCase()) {
65 case ServiceLevelConstants.PNF:
66 wflName = ServiceLevelConstants.GENERIC_PNF_HEALTH_CHECK_WORKFLOW;
68 case ServiceLevelConstants.VNF:
69 wflName = ServiceLevelConstants.GENERIC_VNF_HEALTH_CHECK_WORKFLOW;
72 exceptionBuilder.buildAndThrowWorkflowException(execution, ServiceLevelConstants.ERROR_CODE,
73 "No valid health check work flow retrieved for the scope: " + scope);