Fix ConfigAssign/Deploy null return of BlueprintName/Version
[so.git] / bpmn / so-bpmn-tasks / src / main / java / org / onap / so / bpmn / infrastructure / flowspecific / tasks / ConfigAssignVnf.java
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.List;
24 import java.util.Map;
25 import java.util.UUID;
26 import org.onap.so.bpmn.common.BuildingBlockExecution;
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.ConfigAssignPropertiesForVnf;
34 import org.onap.so.client.cds.beans.ConfigAssignRequestVnf;
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 assign
44  *
45  */
46 @Component
47 public class ConfigAssignVnf {
48
49     private static final Logger logger = LoggerFactory.getLogger(ConfigAssignVnf.class);
50     private static final String ORIGINATOR_ID = "SO";
51     private static final String ACTION_NAME = "config-assign";
52     private static final String MODE = "sync";
53
54     @Autowired
55     private ExceptionBuilder exceptionUtil;
56     @Autowired
57     private ExtractPojosForBB extractPojosForBB;
58
59     /**
60      * Getting the vnf data, blueprint name, blueprint version etc and setting them in execution object and calling the
61      * subprocess.
62      * 
63      * @param execution
64      */
65     public void preProcessAbstractCDSProcessing(BuildingBlockExecution execution) {
66         logger.info("Start preProcessAbstractCDSProcessing ");
67         try {
68             GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
69             ServiceInstance serviceInstance =
70                     extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
71
72             List<Map<String, Object>> userParams =
73                     execution.getGeneralBuildingBlock().getRequestContext().getRequestParameters().getUserParams();
74
75             ConfigAssignPropertiesForVnf configAssignPropertiesForVnf = new ConfigAssignPropertiesForVnf();
76             configAssignPropertiesForVnf.setServiceInstanceId(serviceInstance.getServiceInstanceId());
77             configAssignPropertiesForVnf
78                     .setServiceModelUuid(serviceInstance.getModelInfoServiceInstance().getModelUuid());
79             configAssignPropertiesForVnf
80                     .setVnfCustomizationUuid(vnf.getModelInfoGenericVnf().getModelCustomizationUuid());
81             configAssignPropertiesForVnf.setVnfId(vnf.getVnfId());
82             configAssignPropertiesForVnf.setVnfName(vnf.getVnfName());
83
84             for (Map<String, Object> params : userParams) {
85                 for (Map.Entry<String, Object> entry : params.entrySet()) {
86                     configAssignPropertiesForVnf.setUserParam(entry.getKey(), entry.getValue());
87                 }
88             }
89
90             ConfigAssignRequestVnf configAssignRequestVnf = new ConfigAssignRequestVnf();
91             configAssignRequestVnf.setResolutionKey(vnf.getVnfName());
92             configAssignRequestVnf.setConfigAssignPropertiesForVnf(configAssignPropertiesForVnf);
93
94             String blueprintName = vnf.getModelInfoGenericVnf().getBlueprintName();
95             String blueprintVersion = vnf.getModelInfoGenericVnf().getBlueprintVersion();
96             logger.debug(" BlueprintName : " + blueprintName + " BlueprintVersion : " + blueprintVersion);
97
98             AbstractCDSPropertiesBean abstractCDSPropertiesBean = new AbstractCDSPropertiesBean();
99
100             abstractCDSPropertiesBean.setBlueprintName(blueprintName);
101             abstractCDSPropertiesBean.setBlueprintVersion(blueprintVersion);
102             abstractCDSPropertiesBean.setRequestObject(configAssignRequestVnf.toString());
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             execution.setVariable("executionObject", abstractCDSPropertiesBean);
112
113         } catch (Exception ex) {
114             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
115         }
116     }
117
118 }