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