cdbe0db57cfee06d0639fff4cf2804113faffb96
[so.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 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 import org.onap.so.bpmn.common.BuildingBlockExecution;
25 import org.onap.so.bpmn.infrastructure.aai.tasks.AAIUpdateTasks;
26 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
27 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
28 import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock;
29 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
30 import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
31 import org.onap.so.client.cds.beans.AbstractCDSPropertiesBean;
32 import org.onap.so.client.cds.beans.ConfigDeployPropertiesForVnf;
33 import org.onap.so.client.cds.beans.ConfigDeployRequestVnf;
34 import org.onap.so.client.exception.ExceptionBuilder;
35 import org.slf4j.Logger;
36 import org.slf4j.LoggerFactory;
37 import org.springframework.beans.factory.annotation.Autowired;
38 import org.springframework.stereotype.Component;
39
40 /**
41  * 
42  * Get vnf related data and config Deploy
43  *
44  */
45 @Component
46 public class ConfigDeployVnf {
47     private static final Logger logger = LoggerFactory.getLogger(ConfigDeployVnf.class);
48     private static final String ORIGINATOR_ID = "SO";
49     private static final String ACTION_NAME = "config-deploy";
50     private static final String MODE = "async";
51
52     @Autowired
53     private ExceptionBuilder exceptionUtil;
54     @Autowired
55     private ExtractPojosForBB extractPojosForBB;
56     @Autowired
57     private AAIUpdateTasks aaiUpdateTask;
58
59     /**
60      * Update vnf orch status to configure in AAI
61      * 
62      * @param execution
63      */
64     public void updateAAIConfigure(BuildingBlockExecution execution) {
65         aaiUpdateTask.updateOrchestrationStausConfigDeployConfigureVnf(execution);
66
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 =
84                     extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
85
86             ConfigDeployPropertiesForVnf configDeployPropertiesForVnf = new ConfigDeployPropertiesForVnf();
87             configDeployPropertiesForVnf.setServiceInstanceId(serviceInstance.getServiceInstanceId());
88             configDeployPropertiesForVnf
89                     .setServiceModelUuid(serviceInstance.getModelInfoServiceInstance().getModelUuid());
90             configDeployPropertiesForVnf
91                     .setVnfCustomizationUuid(vnf.getModelInfoGenericVnf().getModelCustomizationUuid());
92             configDeployPropertiesForVnf.setVnfId(vnf.getVnfId());
93             configDeployPropertiesForVnf.setVnfName(vnf.getVnfName());
94
95             ConfigDeployRequestVnf configDeployRequestVnf = new ConfigDeployRequestVnf();
96
97             configDeployRequestVnf.setResolutionKey(vnf.getVnfName());
98             configDeployRequestVnf.setConfigDeployPropertiesForVnf(configDeployPropertiesForVnf);
99
100             String blueprintName = vnf.getModelInfoGenericVnf().getBlueprintName();
101             String blueprintVersion = vnf.getModelInfoGenericVnf().getBlueprintVersion();
102             logger.debug(" BlueprintName : " + blueprintName + " BlueprintVersion : " + blueprintVersion);
103
104             AbstractCDSPropertiesBean abstractCDSPropertiesBean = new AbstractCDSPropertiesBean();
105
106             abstractCDSPropertiesBean.setBlueprintName(blueprintName);
107             abstractCDSPropertiesBean.setBlueprintVersion(blueprintVersion);
108             abstractCDSPropertiesBean.setRequestObject(configDeployRequestVnf.toString());
109
110
111             GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock();
112
113             abstractCDSPropertiesBean.setOriginatorId(ORIGINATOR_ID);
114             abstractCDSPropertiesBean.setRequestId(gBBInput.getRequestContext().getMsoRequestId());
115             abstractCDSPropertiesBean.setSubRequestId(UUID.randomUUID().toString());
116             abstractCDSPropertiesBean.setActionName(ACTION_NAME);
117             abstractCDSPropertiesBean.setMode(MODE);
118
119             execution.setVariable("executionObject", abstractCDSPropertiesBean);
120
121         } catch (Exception ex) {
122             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
123         }
124     }
125
126     /**
127      * Update vnf orch status to configured in AAI
128      * 
129      * @param execution
130      */
131     public void updateAAIConfigured(BuildingBlockExecution execution) {
132         aaiUpdateTask.updateOrchestrationStausConfigDeployConfiguredVnf(execution);
133
134     }
135 }