dd3690013914677282a7e282aa96d89e64ccd0d4
[so.git] /
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 static final String ORIGINATOR_ID = "SO";
44     private static final String ACTION_NAME = "config-deploy";
45     private static final 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.getModelInfoGenericVnf().getBlueprintName();
96             String blueprintVersion = vnf.getModelInfoGenericVnf().getBlueprintVersion();
97             logger.debug(" BlueprintName : " + blueprintName + " BlueprintVersion : " + blueprintVersion);
98
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 }