932558d8ad5c7bcf6211894455bc43b03ee01f05
[so.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Modifications Copyright (c) 2019 Samsung
8  * ================================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  * 
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  * 
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * ============LICENSE_END=========================================================
21  */
22
23 package org.onap.so.bpmn.infrastructure.adapter.vnf.tasks;
24
25 import org.onap.so.adapters.vnfrest.CreateVfModuleRequest;
26 import org.onap.so.adapters.vnfrest.CreateVolumeGroupRequest;
27 import org.onap.so.bpmn.common.BuildingBlockExecution;
28 import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion;
29 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
30 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
31 import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
32 import org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup;
33 import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock;
34 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
35 import org.onap.so.bpmn.servicedecomposition.generalobjects.OrchestrationContext;
36 import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext;
37 import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
38 import org.onap.so.client.exception.BBObjectNotFoundException;
39 import org.onap.so.client.exception.ExceptionBuilder;
40 import org.onap.so.client.orchestration.VnfAdapterVfModuleResources;
41 import org.onap.so.client.orchestration.VnfAdapterVolumeGroupResources;
42 import org.slf4j.Logger;
43 import org.slf4j.LoggerFactory;
44 import org.springframework.beans.factory.annotation.Autowired;
45 import org.springframework.stereotype.Component;
46
47 @Component
48 public class VnfAdapterCreateTasks {
49         private static final Logger logger = LoggerFactory.getLogger(VnfAdapterCreateTasks.class);
50         private static final String VNFREST_REQUEST = "VNFREST_Request";
51
52         @Autowired
53         private ExtractPojosForBB extractPojosForBB;
54         @Autowired
55         private VnfAdapterVolumeGroupResources vnfAdapterVolumeGroupResources;
56         @Autowired
57         private VnfAdapterVfModuleResources vnfAdapterVfModuleResources;
58     @Autowired
59     private ExceptionBuilder exceptionUtil;
60
61         public void createVolumeGroupRequest(BuildingBlockExecution execution) {
62                 try {
63                         GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock();
64
65                         ServiceInstance serviceInstance = gBBInput.getCustomer().getServiceSubscription().getServiceInstances().get(0);
66
67                         GenericVnf genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID, execution.getLookupMap().get(ResourceKey.GENERIC_VNF_ID));
68                         VolumeGroup volumeGroup = extractPojosForBB.extractByKey(execution, ResourceKey.VOLUME_GROUP_ID, execution.getLookupMap().get(ResourceKey.VOLUME_GROUP_ID));
69                         VfModule vfModule;
70                         String sdncVfModuleQueryResponse = null;
71                         try {
72                                 vfModule =  extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID, execution.getLookupMap().get(ResourceKey.VF_MODULE_ID));
73                                 if(vfModule.getSelflink() != null && !vfModule.getSelflink().isEmpty()) {
74                                         sdncVfModuleQueryResponse = execution.getVariable("SDNCQueryResponse_" + vfModule.getVfModuleId());
75                                 }
76                                 else {
77                                         throw new Exception("Vf Module " + vfModule.getVfModuleId() + " exists in gBuildingBlock but does not have a selflink value");
78                                 }
79                         } catch(BBObjectNotFoundException bbException) {
80                                 // If there is not a vf module in the general building block (in aLaCarte case), we will not retrieve the SDNCQueryResponse and proceed as normal without throwing an error
81                         }
82
83                         CreateVolumeGroupRequest createVolumeGroupRequest = vnfAdapterVolumeGroupResources.createVolumeGroupRequest(gBBInput.getRequestContext(), gBBInput.getCloudRegion(),  gBBInput.getOrchContext(), serviceInstance, genericVnf, volumeGroup, sdncVfModuleQueryResponse);
84                         execution.setVariable(VNFREST_REQUEST, createVolumeGroupRequest.toXmlString());
85                 } catch (Exception ex) {
86                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
87                 }
88         }
89
90
91         public void createVfModule(BuildingBlockExecution execution) {
92                 try {
93                         GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock();
94                         
95                         ServiceInstance serviceInstance = gBBInput.getCustomer().getServiceSubscription().getServiceInstances().get(0);
96                         VfModule vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID, execution.getLookupMap().get(ResourceKey.VF_MODULE_ID));
97                         GenericVnf genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID, execution.getLookupMap().get(ResourceKey.GENERIC_VNF_ID));
98                         VolumeGroup volumeGroup = null;
99                         try {
100                                 volumeGroup = extractPojosForBB.extractByKey(execution, ResourceKey.VOLUME_GROUP_ID, execution.getLookupMap().get(ResourceKey.VOLUME_GROUP_ID));
101                         } catch(BBObjectNotFoundException bbException) {                                
102                         }
103                         CloudRegion cloudRegion = gBBInput.getCloudRegion();
104                         RequestContext requestContext = gBBInput.getRequestContext();
105                         OrchestrationContext orchestrationContext = gBBInput.getOrchContext();
106                         String sdncVfModuleQueryResponse = execution.getVariable("SDNCQueryResponse_" + vfModule.getVfModuleId());
107                         String sdncVnfQueryResponse = execution.getVariable("SDNCQueryResponse_" + genericVnf.getVnfId());
108                         
109                         CreateVfModuleRequest createVfModuleRequest = vnfAdapterVfModuleResources.createVfModuleRequest(requestContext, cloudRegion, orchestrationContext, serviceInstance, genericVnf, vfModule, volumeGroup, sdncVnfQueryResponse, sdncVfModuleQueryResponse);
110                         execution.setVariable(VNFREST_REQUEST, createVfModuleRequest.toXmlString());
111                 } catch (Exception ex) {
112                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
113                 }
114         }
115 }