2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 Bell Canada
6 * ================================================================================
7 * Modifications Copyright (c) 2020 Tech Mahindra
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
23 package org.onap.so.bpmn.infrastructure.flowspecific.tasks;
25 import org.onap.so.bpmn.common.BuildingBlockExecution;
26 import org.onap.so.bpmn.infrastructure.decisionpoint.api.ControllerContext;
27 import org.onap.so.bpmn.infrastructure.decisionpoint.api.ControllerRunnable;
28 import org.onap.so.client.cds.AbstractCDSProcessingBBUtils;
29 import org.onap.so.client.cds.GeneratePayloadForCds;
30 import org.onap.so.client.cds.beans.AbstractCDSPropertiesBean;
31 import org.onap.so.client.exception.ExceptionBuilder;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
34 import org.springframework.beans.factory.annotation.Autowired;
35 import org.springframework.stereotype.Component;
38 * This class is used in context of Building Block flow for configuration of vnf/vfmodule/service.
40 * @param - BuildingBlockExecution
43 public class GenericCDSProcessingBB implements ControllerRunnable<BuildingBlockExecution> {
44 private static final Logger logger = LoggerFactory.getLogger(GenericCDSProcessingBB.class);
45 private static final String EXECUTION_OBJECT = "executionObject";
46 public static final String CDS_ACTOR = "cds";
47 public static final String VNF_SCOPE = "vnf";
48 public static final String VF_MODULE_SCOPE = "vfmodule";
49 public static final String SERVICE_SCOPE = "service";
52 private ExceptionBuilder exceptionBuilder;
55 private AbstractCDSProcessingBBUtils cdsDispather;
58 private GeneratePayloadForCds generatePayloadForCds;
61 public Boolean understand(ControllerContext<BuildingBlockExecution> context) {
62 String scope = context.getControllerScope();
63 return CDS_ACTOR.equalsIgnoreCase(context.getControllerActor()) && (SERVICE_SCOPE.equalsIgnoreCase(scope)
64 || VNF_SCOPE.equalsIgnoreCase(scope) || VF_MODULE_SCOPE.equalsIgnoreCase(scope));
68 public Boolean ready(ControllerContext<BuildingBlockExecution> context) {
73 public void prepare(ControllerContext<BuildingBlockExecution> context) {
74 BuildingBlockExecution buildingBlockExecution = context.getExecution();
76 AbstractCDSPropertiesBean abstractCDSPropertiesBean =
77 generatePayloadForCds.buildCdsPropertiesBean(buildingBlockExecution);
78 buildingBlockExecution.setVariable(EXECUTION_OBJECT, abstractCDSPropertiesBean);
79 } catch (Exception ex) {
80 logger.error("An exception occurred when creating payload for CDS request", ex);
81 exceptionBuilder.buildAndThrowWorkflowException(buildingBlockExecution, 7000, ex);
86 public void run(ControllerContext<BuildingBlockExecution> context) {
87 BuildingBlockExecution obj = context.getExecution();
88 cdsDispather.constructExecutionServiceInputObjectBB(obj);
89 cdsDispather.sendRequestToCDSClientBB(obj);