Replaced all tabs with spaces in java and pom.xml
[so.git] / bpmn / so-bpmn-tasks / src / main / java / org / onap / so / bpmn / infrastructure / flowspecific / tasks / ConfigDeployVnf.java
1 /*
2  * ============LICENSE_START======================================================= ONAP : SO
3  * ================================================================================ Copyright 2019 TechMahindra
4  * ================================================================================= Licensed under the Apache License,
5  * Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy
6  * of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
11  * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
12  * specific language governing permissions and limitations under the License.
13  * ============LICENSE_END=========================================================
14  */
15
16 package org.onap.so.bpmn.infrastructure.flowspecific.tasks;
17
18 import java.util.UUID;
19 import org.onap.so.bpmn.common.BuildingBlockExecution;
20 import org.onap.so.bpmn.infrastructure.aai.tasks.AAIUpdateTasks;
21 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
22 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
23 import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock;
24 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
25 import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
26 import org.onap.so.client.cds.beans.AbstractCDSPropertiesBean;
27 import org.onap.so.client.cds.beans.ConfigDeployPropertiesForVnf;
28 import org.onap.so.client.cds.beans.ConfigDeployRequestVnf;
29 import org.onap.so.client.exception.ExceptionBuilder;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32 import org.springframework.beans.factory.annotation.Autowired;
33 import org.springframework.stereotype.Component;
34
35 /**
36  * 
37  * Get vnf related data and config Deploy
38  *
39  */
40 @Component
41 public class ConfigDeployVnf {
42     private static final Logger logger = LoggerFactory.getLogger(ConfigDeployVnf.class);
43     private final static String ORIGINATOR_ID = "SO";
44     private final static String ACTION_NAME = "config-deploy";
45     private final static String MODE = "async";
46
47     @Autowired
48     private ExceptionBuilder exceptionUtil;
49     @Autowired
50     private ExtractPojosForBB extractPojosForBB;
51     @Autowired
52     private AAIUpdateTasks aaiUpdateTask;
53
54     /**
55      * Update vnf orch status to configure in AAI
56      * 
57      * @param execution
58      */
59     public void updateAAIConfigure(BuildingBlockExecution execution) {
60         aaiUpdateTask.updateOrchestrationStausConfigDeployConfigureVnf(execution);
61
62     }
63
64     /**
65      * Getting the vnf object and set in execution object
66      * 
67      * @param execution
68      * 
69      * 
70      */
71     public void preProcessAbstractCDSProcessing(BuildingBlockExecution execution) {
72
73
74         logger.info("Start preProcessAbstractCDSProcessing");
75         try {
76             GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
77
78             ServiceInstance serviceInstance =
79                     extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
80
81             ConfigDeployPropertiesForVnf configDeployPropertiesForVnf = new ConfigDeployPropertiesForVnf();
82             configDeployPropertiesForVnf.setServiceInstanceId(serviceInstance.getServiceInstanceId());
83             configDeployPropertiesForVnf
84                     .setServiceModelUuid(serviceInstance.getModelInfoServiceInstance().getModelUuid());
85             configDeployPropertiesForVnf
86                     .setVnfCustomizationUuid(vnf.getModelInfoGenericVnf().getModelCustomizationUuid());
87             configDeployPropertiesForVnf.setVnfId(vnf.getVnfId());
88             configDeployPropertiesForVnf.setVnfName(vnf.getVnfName());
89
90             ConfigDeployRequestVnf configDeployRequestVnf = new ConfigDeployRequestVnf();
91
92             configDeployRequestVnf.setResolutionKey(vnf.getVnfName());
93             configDeployRequestVnf.setConfigDeployPropertiesForVnf(configDeployPropertiesForVnf);
94
95             String blueprintName = vnf.getBlueprintName();
96             String blueprintVersion = vnf.getBlueprintVersion();
97             AbstractCDSPropertiesBean abstractCDSPropertiesBean = new AbstractCDSPropertiesBean();
98
99             abstractCDSPropertiesBean.setBlueprintName(blueprintName);
100             abstractCDSPropertiesBean.setBlueprintVersion(blueprintVersion);
101             abstractCDSPropertiesBean.setRequestObject(configDeployRequestVnf.toString());
102
103
104             GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock();
105
106             abstractCDSPropertiesBean.setOriginatorId(ORIGINATOR_ID);
107             abstractCDSPropertiesBean.setRequestId(gBBInput.getRequestContext().getMsoRequestId());
108             abstractCDSPropertiesBean.setSubRequestId(UUID.randomUUID().toString());
109             abstractCDSPropertiesBean.setActionName(ACTION_NAME);
110             abstractCDSPropertiesBean.setMode(MODE);
111
112             execution.setVariable("executionObject", abstractCDSPropertiesBean);
113
114         } catch (Exception ex) {
115             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
116         }
117     }
118
119     /**
120      * Update vnf orch status to configured in AAI
121      * 
122      * @param execution
123      */
124     public void updateAAIConfigured(BuildingBlockExecution execution) {
125         aaiUpdateTask.updateOrchestrationStausConfigDeployConfiguredVnf(execution);
126
127     }
128 }