7de393bb2fec4accf927c55e078e575d193b1572
[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.client.sdnc.mapper;
22
23 import java.util.ArrayList;
24 import java.util.List;
25 import java.util.Map;
26 import java.util.UUID;
27
28 import org.apache.commons.lang.StringUtils;
29 import org.onap.sdnc.northbound.client.model.GenericResourceApiParam;
30 import org.onap.sdnc.northbound.client.model.GenericResourceApiParamParam;
31 import org.onap.sdnc.northbound.client.model.GenericResourceApiRequestActionEnumeration;
32 import org.onap.sdnc.northbound.client.model.GenericResourceApiRequestinformationRequestInformation;
33 import org.onap.sdnc.northbound.client.model.GenericResourceApiSdncrequestheaderSdncRequestHeader;
34 import org.onap.sdnc.northbound.client.model.GenericResourceApiServiceinformationServiceInformation;
35 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfOperationInformation;
36 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfinformationVnfInformation;
37 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfrequestinputVnfRequestInput;
38 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfrequestinputVnfrequestinputVnfNetworkInstanceGroupIds;
39 import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion;
40 import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer;
41 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
42 import org.onap.so.bpmn.servicedecomposition.bbobjects.InstanceGroup;
43 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
44 import org.onap.so.bpmn.servicedecomposition.generalobjects.License;
45 import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext;
46 import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoInstanceGroup;
47 import org.onap.so.client.sdnc.beans.SDNCSvcAction;
48 import org.onap.so.client.sdnc.beans.SDNCSvcOperation;
49 import org.springframework.beans.factory.annotation.Autowired;
50 import org.springframework.stereotype.Component;
51
52 @Component
53 public class VnfTopologyOperationRequestMapper {
54
55         @Autowired
56         private GeneralTopologyObjectMapper generalTopologyObjectMapper;
57
58         public GenericResourceApiVnfOperationInformation reqMapper(SDNCSvcOperation svcOperation, SDNCSvcAction svcAction,
59                         GenericResourceApiRequestActionEnumeration requestAction, GenericVnf vnf, ServiceInstance serviceInstance,
60                         Customer customer, CloudRegion cloudRegion, RequestContext requestContext, boolean homing) {
61                 String sdncReqId = UUID.randomUUID().toString();
62                 GenericResourceApiVnfOperationInformation req = new GenericResourceApiVnfOperationInformation();
63                 GenericResourceApiSdncrequestheaderSdncRequestHeader sdncRequestHeader = generalTopologyObjectMapper
64                                 .buildSdncRequestHeader(svcAction, sdncReqId);
65                 GenericResourceApiRequestinformationRequestInformation requestInformation = generalTopologyObjectMapper
66                                 .buildGenericResourceApiRequestinformationRequestInformation(sdncReqId, requestAction);
67                 GenericResourceApiServiceinformationServiceInformation serviceInformation = generalTopologyObjectMapper
68                                 .buildServiceInformation(serviceInstance, requestContext, customer, true);
69                 GenericResourceApiVnfinformationVnfInformation vnfInformation = generalTopologyObjectMapper
70                                 .buildVnfInformation(vnf, serviceInstance, true);
71                 GenericResourceApiVnfrequestinputVnfRequestInput vnfRequestInput = new GenericResourceApiVnfrequestinputVnfRequestInput();
72
73                 vnfRequestInput.setTenant(cloudRegion.getTenantId());
74                 vnfRequestInput.setAicCloudRegion(cloudRegion.getLcpCloudRegionId());
75                 vnfRequestInput.setCloudOwner(cloudRegion.getCloudOwner());
76                 
77                 if (StringUtils.isNotBlank(vnf.getVnfName())) {
78                         vnfRequestInput.setVnfName(vnf.getVnfName());
79                 }
80
81                 req.setRequestInformation(requestInformation);
82                 req.setSdncRequestHeader(sdncRequestHeader);
83                 req.setServiceInformation(serviceInformation);
84                 req.setVnfInformation(vnfInformation);
85
86                 GenericResourceApiParam vnfInputParameters = new GenericResourceApiParam();
87                 if (requestContext.getUserParams() != null) {
88                         for (Map.Entry<String, Object> entry : requestContext.getUserParams().entrySet()) {
89                                 GenericResourceApiParamParam paramItem = new GenericResourceApiParamParam();
90                                 paramItem.setName(entry.getKey());
91                                 paramItem.setValue(generalTopologyObjectMapper.mapUserParamValue(entry.getValue()));
92                                 vnfInputParameters.addParamItem(paramItem);
93                                 vnfRequestInput.setVnfInputParameters(vnfInputParameters);
94                         }
95                 }
96                 if (vnf.getCloudParams() != null) {
97                         for (Map.Entry<String, String> entry : vnf.getCloudParams().entrySet()) {
98                                 GenericResourceApiParamParam paramItem = new GenericResourceApiParamParam();
99                                 paramItem.setName(entry.getKey());
100                                 paramItem.setValue(entry.getValue());
101                                 vnfInputParameters.addParamItem(paramItem);
102                         }
103                 }
104                 if (homing) {
105                         License license = vnf.getLicense();
106                         if (license != null) {
107                                 if(license.getEntitlementPoolUuids() != null && !license.getEntitlementPoolUuids().isEmpty()) {
108                                         String entitlementPoolUuid = license.getEntitlementPoolUuids().get(0);
109                                         GenericResourceApiParamParam paramItem = new GenericResourceApiParamParam();
110                                         paramItem.setName("entitlement_assignment_group_uuid");
111                                         paramItem.setValue(entitlementPoolUuid);
112                                         vnfInputParameters.addParamItem(paramItem);
113                                 }
114                                 if (license.getLicenseKeyGroupUuids() != null && !license.getLicenseKeyGroupUuids().isEmpty()) {
115                                         String licenseKeyGroupUuid = license.getLicenseKeyGroupUuids().get(0);
116                                         GenericResourceApiParamParam paramItem2 = new GenericResourceApiParamParam();
117                                         paramItem2.setName("license_assignment_group_uuid");
118                                         paramItem2.setValue(licenseKeyGroupUuid);
119                                         vnfInputParameters.addParamItem(paramItem2);
120                                 }
121                         }
122                 }
123                 List<InstanceGroup> instanceGroups = vnf.getInstanceGroups();
124                 List<GenericResourceApiVnfrequestinputVnfrequestinputVnfNetworkInstanceGroupIds> networkInstanceGroupIdList = new ArrayList<GenericResourceApiVnfrequestinputVnfrequestinputVnfNetworkInstanceGroupIds>();
125
126                 for (InstanceGroup instanceGroup : instanceGroups) {
127                         if (ModelInfoInstanceGroup.TYPE_L3_NETWORK
128                                         .equalsIgnoreCase(instanceGroup.getModelInfoInstanceGroup().getType())) {
129                                 GenericResourceApiVnfrequestinputVnfrequestinputVnfNetworkInstanceGroupIds instanceGroupId = new GenericResourceApiVnfrequestinputVnfrequestinputVnfNetworkInstanceGroupIds();
130                                 instanceGroupId.setVnfNetworkInstanceGroupId(instanceGroup.getId());
131                                 networkInstanceGroupIdList.add(instanceGroupId);
132                         }
133                 }
134
135                 vnfRequestInput.setVnfNetworkInstanceGroupIds(networkInstanceGroupIdList);
136                 vnfRequestInput.setVnfInputParameters(vnfInputParameters);
137                 req.setVnfRequestInput(vnfRequestInput);
138                 return req;
139         }
140 }