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.bpmn.infrastructure.service.level.impl.ServiceLevelConstants;
25 import org.onap.so.client.exception.ExceptionBuilder;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
28 import org.springframework.beans.factory.annotation.Autowired;
29 import java.util.ArrayList;
30 import java.util.List;
33 * Abstract class for Service level upgrade Execution, it should be extended for service level upgrade tasks.
35 public abstract class AbstractServiceLevelPreparable {
37 protected static final Logger LOG = LoggerFactory.getLogger(AbstractServiceLevelPreparable.class);
40 protected ExceptionBuilder exceptionBuilder;
43 * This method fetches workflow names to be invoked based on the controller scope .
45 * @param scope Controller scope
46 * @return String value of Workflow name
48 protected abstract String fetchWorkflowUsingScope(DelegateExecution execution, final String scope);
51 * This method validates the execution parameters to be passed for health check workflow.
53 * @param execution Delegate execution obj
54 * @param scope Controller scope * Throws workflow exception if validation fails
56 protected void validateParamsWithScope(DelegateExecution execution, final String scope, List<String> params) {
57 List<String> invalidVariables = new ArrayList<>();
58 for (String param : params) {
59 if (!execution.hasVariable(param) || execution.getVariable(param) == null
60 || String.valueOf(execution.getVariable(param)).isEmpty()) {
61 invalidVariables.add(param);
64 if (invalidVariables.size() > 0) {
65 LOG.error("Validation error for the {} health check attributes: {}", scope, invalidVariables);
66 exceptionBuilder.buildAndThrowWorkflowException(execution, ServiceLevelConstants.ERROR_CODE,
67 "Validation of health check workflow parameters failed for the scope: " + scope);