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;
23 import org.camunda.bpm.engine.delegate.DelegateExecution;
24 import org.onap.so.client.exception.ExceptionBuilder;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
27 import org.springframework.beans.factory.annotation.Autowired;
28 import java.util.ArrayList;
29 import java.util.List;
32 * Abstract class for Service level upgrade Execution, it should be extended for service level upgrade tasks.
34 public abstract class AbstractServiceLevelPreparable {
36 protected static final String WORKFLOW_TO_INVOKE = "healthCheckWorkflow";
37 protected static final String GENERIC_PNF_HEALTH_CHECK_WORKFLOW = "GenericPnfHealthCheck";
38 protected static final String GENERIC_PNF_SOFTWARE_UPGRADE_WORKFLOW = "GenericPnfSoftwareUpgrade";
39 protected static final String RESOURCE_TYPE = "RESOURCE_TYPE";
40 protected static final int ERROR_CODE = 601;
42 // TODO This value needs to be updated once vnf health check workflow is available
43 protected static final String GENERIC_VNF_HEALTH_CHECK_WORKFLOW = "GenericVNFHealthCheck";
45 protected static final Logger LOG = LoggerFactory.getLogger(AbstractServiceLevelPreparable.class);
48 protected ExceptionBuilder exceptionBuilder;
51 * This method fetches workflow names to be invoked based on the controller scope .
53 * @param scope Controller scope
54 * @return String value of Workflow name
56 protected abstract String fetchWorkflowUsingScope(DelegateExecution execution, final String scope);
59 * This method validates the execution parameters to be passed for health check workflow.
61 * @param execution Delegate execution obj
62 * @param scope Controller scope * Throws workflow exception if validation fails
64 protected void validateParamsWithScope(DelegateExecution execution, final String scope, List<String> params)
66 List<String> invalidVariables = new ArrayList<>();
67 for (String param : params) {
68 if (!execution.hasVariable(param) || execution.getVariable(param) == null
69 || String.valueOf(execution.getVariable(param)).isEmpty()) {
70 invalidVariables.add(param);
73 if (invalidVariables.size() > 0) {
74 LOG.error("Validation error for the {} health check attributes: {}", scope, invalidVariables);
75 exceptionBuilder.buildAndThrowWorkflowException(execution, ERROR_CODE,
76 "Validation of health check workflow parameters failed for the scope: " + scope);