2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2022 Ericsson. All rights reserved.
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=========================================================
20 package org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks;
22 import static org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.Constants.INPUT_PARAMETER;
23 import java.util.HashMap;
24 import java.util.List;
26 import org.onap.so.bpmn.common.BuildingBlockExecution;
27 import org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.utils.InputParameter;
28 import org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.utils.InputParametersProvider;
29 import org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.utils.NullInputParameter;
30 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
31 import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
32 import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
35 import org.springframework.beans.factory.annotation.Autowired;
36 import org.springframework.stereotype.Component;
39 * This class performs CNF Instantiation
41 * @author sagar.shetty@est.tech
44 public class CnfInstantiateTask {
45 private static final Logger LOGGER = LoggerFactory.getLogger(CnfInstantiateTask.class);
46 private final InputParametersProvider<GenericVnf> sdncInputParametersProvider;
47 private final ExtractPojosForBB extractPojosForBB;
48 private final InputParametersProvider<Map<String, Object>> userParamInputParametersProvider;
51 public CnfInstantiateTask(final InputParametersProvider<GenericVnf> inputParametersProvider,
52 final InputParametersProvider<Map<String, Object>> userParamInputParametersProvider,
53 final ExtractPojosForBB extractPojosForBB) {
54 this.sdncInputParametersProvider = inputParametersProvider;
55 this.userParamInputParametersProvider = userParamInputParametersProvider;
56 this.extractPojosForBB = extractPojosForBB;
59 public void handleCnfInstatiate(final BuildingBlockExecution execution) {
61 LOGGER.debug("Executing handleCnfInstatiate ...");
62 final InputParameter userParamsInputParameter = getUserParamsInputParameter(execution);
63 LOGGER.debug("Finished executing handleCnfInstatiate ...");
64 } catch (final Exception exception) {
65 LOGGER.error("Unable to get input parameters", exception);
66 execution.setVariable(INPUT_PARAMETER, NullInputParameter.NULL_INSTANCE);
70 private InputParameter getUserParamsInputParameter(final BuildingBlockExecution execution) {
71 final GeneralBuildingBlock generalBuildingBlock = execution.getGeneralBuildingBlock();
72 if (generalBuildingBlock != null && generalBuildingBlock.getRequestContext() != null
73 && generalBuildingBlock.getRequestContext().getRequestParameters() != null) {
74 final List<Map<String, Object>> userParams =
75 generalBuildingBlock.getRequestContext().getRequestParameters().getUserParams();
76 if (userParams != null) {
77 final Map<String, Object> params = new HashMap<>();
78 userParams.stream().forEach(obj -> {
81 LOGGER.info("User params found : {}", params);
82 if (userParams != null && !userParams.isEmpty()) {
83 return userParamInputParametersProvider.getInputParameter(params);
87 LOGGER.warn("No input parameters found in userparams ...");
88 return NullInputParameter.NULL_INSTANCE;