2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 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
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 * SPDX-License-Identifier: Apache-2.0
17 * ============LICENSE_END=========================================================
20 package org.onap.so.bpmn.infrastructure.pnf.delegate;
22 import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.MODEL_UUID;
23 import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.PRC_BLUEPRINT_NAME;
24 import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.PRC_BLUEPRINT_VERSION;
25 import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.PRC_CUSTOMIZATION_UUID;
26 import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.PRC_INSTANCE_NAME;
27 import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.SERVICE_MODEL_INFO;
28 import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.SKIP_POST_INSTANTIATION_CONFIGURATION;
30 import java.util.List;
31 import org.camunda.bpm.engine.delegate.DelegateExecution;
32 import org.camunda.bpm.engine.delegate.JavaDelegate;
33 import org.onap.so.bpmn.core.json.JsonUtils;
34 import org.onap.so.client.exception.ExceptionBuilder;
35 import org.onap.so.db.catalog.beans.PnfResourceCustomization;
36 import org.onap.so.db.catalog.client.CatalogDbClient;
37 import org.slf4j.Logger;
38 import org.slf4j.LoggerFactory;
39 import org.springframework.beans.factory.annotation.Autowired;
40 import org.springframework.stereotype.Component;
43 * This implementation of {@link JavaDelegate} is used to check the SO catalogdb for PNF config flag.
45 * It queries the PNF resource customization table for the skip_post_instantiation_configuration for required PNF model
49 public class ConfigCheckerDelegate implements JavaDelegate {
51 private Logger logger = LoggerFactory.getLogger(ConfigCheckerDelegate.class);
53 //ERROR CODE for variable not found in the delegation Context
54 private static int ERROR_CODE = 601;
57 protected ExceptionBuilder exceptionUtil;
60 protected CatalogDbClient catalogDbClient;
63 public void execute(DelegateExecution delegateExecution) throws Exception {
65 logger.debug("Running execute block for activity id:{}, name:{}", delegateExecution.getCurrentActivityId(),
66 delegateExecution.getCurrentActivityName());
68 if (delegateExecution.hasVariable(SERVICE_MODEL_INFO)) {
69 String serviceModelInfo = (String) delegateExecution.getVariable(SERVICE_MODEL_INFO);
70 String serviceModelUuid = JsonUtils.getJsonValue(serviceModelInfo, MODEL_UUID);
71 delegateExecution.setVariable(MODEL_UUID, serviceModelUuid);
72 List<PnfResourceCustomization> pnfCustomizations = catalogDbClient
73 .getPnfResourceCustomizationByModelUuid(serviceModelUuid);
74 if (pnfCustomizations != null && pnfCustomizations.size() >= 1) {
75 PnfResourceCustomization pnfResourceCustomization = pnfCustomizations.get(0);
76 boolean skipPostInstantiationConfiguration = pnfResourceCustomization.isSkipPostInstConf();
78 .setVariable(SKIP_POST_INSTANTIATION_CONFIGURATION, skipPostInstantiationConfiguration);
79 delegateExecution.setVariable(PRC_BLUEPRINT_NAME, pnfResourceCustomization.getBlueprintName());
80 delegateExecution.setVariable(PRC_BLUEPRINT_VERSION, pnfResourceCustomization.getBlueprintVersion());
82 .setVariable(PRC_CUSTOMIZATION_UUID, pnfResourceCustomization.getModelCustomizationUUID());
83 delegateExecution.setVariable(PRC_INSTANCE_NAME, pnfResourceCustomization.getModelInstanceName());
86 .warn("Unable to find the PNF resource customizations of model service UUID: {}", serviceModelUuid);
87 exceptionUtil.buildAndThrowWorkflowException(delegateExecution, ERROR_CODE,
88 "Unable to find the PNF resource customizations of model service UUID: " + serviceModelUuid);
91 logger.warn("Unable to find the parameter: {} in the execution context", SERVICE_MODEL_INFO);
93 .buildAndThrowWorkflowException(delegateExecution, ERROR_CODE,
94 "Unable to find parameter " + SERVICE_MODEL_INFO);