69fc633bbdcb3d6fcdb3cdc7783ae4fc6e5b4680
[so.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
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.adapter.vnf.tasks;
22
23 import org.onap.so.adapters.vnfrest.CreateVfModuleRequest;
24 import org.onap.so.adapters.vnfrest.CreateVolumeGroupRequest;
25 import org.onap.so.bpmn.common.BuildingBlockExecution;
26 import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion;
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.bbobjects.VfModule;
30 import org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup;
31 import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock;
32 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
33 import org.onap.so.bpmn.servicedecomposition.generalobjects.OrchestrationContext;
34 import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext;
35 import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
36 import org.onap.so.client.exception.BBObjectNotFoundException;
37 import org.onap.so.client.exception.ExceptionBuilder;
38 import org.onap.so.client.orchestration.VnfAdapterVfModuleResources;
39 import org.onap.so.client.orchestration.VnfAdapterVolumeGroupResources;
40 import org.onap.so.logger.MsoLogger;
41 import org.springframework.beans.factory.annotation.Autowired;
42 import org.springframework.stereotype.Component;
43
44 @Component
45 public class VnfAdapterCreateTasks {
46         private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, VnfAdapterCreateTasks.class);
47         private static final String VNFREST_REQUEST = "VNFREST_Request";
48
49         @Autowired
50         private ExtractPojosForBB extractPojosForBB;
51         @Autowired
52         private VnfAdapterVolumeGroupResources vnfAdapterVolumeGroupResources;
53         @Autowired
54         private VnfAdapterVfModuleResources vnfAdapterVfModuleResources;
55     @Autowired
56     private ExceptionBuilder exceptionUtil;
57
58         public void createVolumeGroupRequest(BuildingBlockExecution execution) {
59                 try {
60                         GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock();
61
62                         ServiceInstance serviceInstance = gBBInput.getCustomer().getServiceSubscription().getServiceInstances().get(0);
63
64                         GenericVnf genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID, execution.getLookupMap().get(ResourceKey.GENERIC_VNF_ID));
65                         VolumeGroup volumeGroup = extractPojosForBB.extractByKey(execution, ResourceKey.VOLUME_GROUP_ID, execution.getLookupMap().get(ResourceKey.VOLUME_GROUP_ID));
66                         VfModule vfModule;
67                         String sdncVfModuleQueryResponse = null;
68                         try {
69                                 vfModule =  extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID, execution.getLookupMap().get(ResourceKey.VF_MODULE_ID));
70                                 if(vfModule.getSelflink() != null && !vfModule.getSelflink().isEmpty()) {
71                                         sdncVfModuleQueryResponse = execution.getVariable("SDNCQueryResponse_" + vfModule.getVfModuleId());
72                                 }
73                                 else {
74                                         throw new Exception("Vf Module " + vfModule.getVfModuleId() + " exists in gBuildingBlock but does not have a selflink value");
75                                 }
76                         } catch(BBObjectNotFoundException bbException) {
77                                 // 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
78                         }
79
80                         CreateVolumeGroupRequest createVolumeGroupRequest = vnfAdapterVolumeGroupResources.createVolumeGroupRequest(gBBInput.getRequestContext(), gBBInput.getCloudRegion(),  gBBInput.getOrchContext(), serviceInstance, genericVnf, volumeGroup, sdncVfModuleQueryResponse);
81                         execution.setVariable(VNFREST_REQUEST, createVolumeGroupRequest.toXmlString());
82                 } catch (Exception ex) {
83                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
84                 }
85         }
86
87
88         public void createVfModule(BuildingBlockExecution execution) {
89                 try {
90                         GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock();
91                         
92                         ServiceInstance serviceInstance = gBBInput.getCustomer().getServiceSubscription().getServiceInstances().get(0);
93                         VfModule vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID, execution.getLookupMap().get(ResourceKey.VF_MODULE_ID));
94                         GenericVnf genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID, execution.getLookupMap().get(ResourceKey.GENERIC_VNF_ID));
95                         CloudRegion cloudRegion = gBBInput.getCloudRegion();
96                         RequestContext requestContext = gBBInput.getRequestContext();
97                         OrchestrationContext orchestrationContext = gBBInput.getOrchContext();
98                         String sdncVfModuleQueryResponse = execution.getVariable("SDNCQueryResponse_" + vfModule.getVfModuleId());
99                         String sdncVnfQueryResponse = execution.getVariable("SDNCQueryResponse_" + genericVnf.getVnfId());
100                         
101                         CreateVfModuleRequest createVfModuleRequest = vnfAdapterVfModuleResources.createVfModuleRequest(requestContext, cloudRegion, orchestrationContext, serviceInstance, genericVnf, vfModule, sdncVnfQueryResponse, sdncVfModuleQueryResponse);
102                         execution.setVariable(VNFREST_REQUEST, createVfModuleRequest.toXmlString());
103                 } catch (Exception ex) {
104                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
105                 }
106         }
107 }