854678a6a6ac611a257317fce4a408f7765ac71f
[so.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
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=========================================================
21  */
22
23 package org.onap.so.bpmn.infrastructure.flowspecific.tasks;
24
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.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
29 import org.onap.so.client.cds.AbstractCDSProcessingBBUtils;
30 import org.onap.so.client.cds.GeneratePayloadForCds;
31 import org.onap.so.client.cds.beans.AbstractCDSPropertiesBean;
32 import org.onap.so.client.exception.ExceptionBuilder;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
35 import org.springframework.beans.factory.annotation.Autowired;
36 import org.springframework.stereotype.Component;
37
38 /**
39  * This class is used in context of Building Block flow for configuration of vnf/vfmodule/service.
40  *
41  * @param - BuildingBlockExecution
42  */
43 @Component
44 public class GenericCDSProcessingBB implements ControllerRunnable<BuildingBlockExecution> {
45     private static final Logger logger = LoggerFactory.getLogger(GenericCDSProcessingBB.class);
46     private static final String EXECUTION_OBJECT = "executionObject";
47     public static final String CDS_ACTOR = "cds";
48     public static final String VNF_SCOPE = "vnf";
49     public static final String VF_MODULE_SCOPE = "vfmodule";
50
51     @Autowired
52     private ExceptionBuilder exceptionBuilder;
53
54     @Autowired
55     private AbstractCDSProcessingBBUtils cdsDispather;
56
57     @Autowired
58     private GeneratePayloadForCds generatePayloadForCds;
59
60     @Override
61     public Boolean understand(ControllerContext<BuildingBlockExecution> context) {
62         String scope = context.getControllerScope();
63         return CDS_ACTOR.equalsIgnoreCase(context.getControllerActor())
64                 && (VNF_SCOPE.equalsIgnoreCase(scope) || VF_MODULE_SCOPE.equalsIgnoreCase(scope));
65     }
66
67     @Override
68     public Boolean ready(ControllerContext<BuildingBlockExecution> context) {
69         return true;
70     }
71
72     @Override
73     public void prepare(ControllerContext<BuildingBlockExecution> context) {
74         BuildingBlockExecution buildingBlockExecution = context.getExecution();
75         try {
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);
82         }
83     }
84
85     @Override
86     public void run(ControllerContext<BuildingBlockExecution> context) {
87         BuildingBlockExecution obj = context.getExecution();
88         cdsDispather.constructExecutionServiceInputObject(obj);
89         cdsDispather.sendRequestToCDSClient(obj);
90     }
91 }