2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.so.client.sdnc.mapper;
24 import java.util.ArrayList;
25 import java.util.List;
27 import java.util.UUID;
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;
53 public class VnfTopologyOperationRequestMapper {
56 private GeneralTopologyObjectMapper generalTopologyObjectMapper;
59 * This method is used for creating the vnf request.
61 * By these parameter it will get he detailas and prepare the request.
65 * @param requestAction
67 * @param serviceInstance
70 * @param requestContext
74 public GenericResourceApiVnfOperationInformation reqMapper(SDNCSvcOperation svcOperation, SDNCSvcAction svcAction,
75 GenericResourceApiRequestActionEnumeration requestAction, GenericVnf vnf, ServiceInstance serviceInstance,
76 Customer customer, CloudRegion cloudRegion, RequestContext requestContext, boolean homing,
78 String sdncReqId = UUID.randomUUID().toString();
79 String msoRequestId = UUID.randomUUID().toString();
80 if (requestContext != null && requestContext.getMsoRequestId() != null) {
81 msoRequestId = requestContext.getMsoRequestId();
83 GenericResourceApiVnfOperationInformation req = new GenericResourceApiVnfOperationInformation();
84 GenericResourceApiSdncrequestheaderSdncRequestHeader sdncRequestHeader =
85 generalTopologyObjectMapper.buildSdncRequestHeader(svcAction, sdncReqId, callbackUrl.toString());
86 GenericResourceApiRequestinformationRequestInformation requestInformation = generalTopologyObjectMapper
87 .buildGenericResourceApiRequestinformationRequestInformation(msoRequestId, requestAction);
88 GenericResourceApiServiceinformationServiceInformation serviceInformation =
89 generalTopologyObjectMapper.buildServiceInformation(serviceInstance, requestContext, customer, true);
90 GenericResourceApiVnfinformationVnfInformation vnfInformation =
91 generalTopologyObjectMapper.buildVnfInformation(vnf, serviceInstance, true);
92 GenericResourceApiVnfrequestinputVnfRequestInput vnfRequestInput =
93 new GenericResourceApiVnfrequestinputVnfRequestInput();
95 vnfRequestInput.setTenant(cloudRegion.getTenantId());
96 vnfRequestInput.setAicCloudRegion(cloudRegion.getLcpCloudRegionId());
97 vnfRequestInput.setCloudOwner(cloudRegion.getCloudOwner());
99 if (StringUtils.isNotBlank(vnf.getVnfName())) {
100 vnfRequestInput.setVnfName(vnf.getVnfName());
103 req.setRequestInformation(requestInformation);
104 req.setSdncRequestHeader(sdncRequestHeader);
105 req.setServiceInformation(serviceInformation);
106 req.setVnfInformation(vnfInformation);
108 GenericResourceApiParam vnfInputParameters = new GenericResourceApiParam();
109 if (requestContext != null && requestContext.getUserParams() != null) {
110 for (Map.Entry<String, Object> entry : requestContext.getUserParams().entrySet()) {
111 GenericResourceApiParamParam paramItem = new GenericResourceApiParamParam();
112 paramItem.setName(entry.getKey());
113 paramItem.setValue(generalTopologyObjectMapper.mapUserParamValue(entry.getValue()));
114 vnfInputParameters.addParamItem(paramItem);
115 vnfRequestInput.setVnfInputParameters(vnfInputParameters);
118 if (vnf.getCloudParams() != null) {
119 for (Map.Entry<String, String> entry : vnf.getCloudParams().entrySet()) {
120 GenericResourceApiParamParam paramItem = new GenericResourceApiParamParam();
121 paramItem.setName(entry.getKey());
122 paramItem.setValue(entry.getValue());
123 vnfInputParameters.addParamItem(paramItem);
127 License license = vnf.getLicense();
128 if (license != null) {
129 if (license.getEntitlementPoolUuids() != null && !license.getEntitlementPoolUuids().isEmpty()) {
130 String entitlementPoolUuid = license.getEntitlementPoolUuids().get(0);
131 GenericResourceApiParamParam paramItem = new GenericResourceApiParamParam();
132 paramItem.setName("entitlement_assignment_group_uuid");
133 paramItem.setValue(entitlementPoolUuid);
134 vnfInputParameters.addParamItem(paramItem);
136 if (license.getLicenseKeyGroupUuids() != null && !license.getLicenseKeyGroupUuids().isEmpty()) {
137 String licenseKeyGroupUuid = license.getLicenseKeyGroupUuids().get(0);
138 GenericResourceApiParamParam paramItem2 = new GenericResourceApiParamParam();
139 paramItem2.setName("license_assignment_group_uuid");
140 paramItem2.setValue(licenseKeyGroupUuid);
141 vnfInputParameters.addParamItem(paramItem2);
145 List<InstanceGroup> instanceGroups = vnf.getInstanceGroups();
146 List<GenericResourceApiVnfrequestinputVnfrequestinputVnfNetworkInstanceGroupIds> networkInstanceGroupIdList =
149 for (InstanceGroup instanceGroup : instanceGroups) {
150 if (ModelInfoInstanceGroup.TYPE_L3_NETWORK
151 .equalsIgnoreCase(instanceGroup.getModelInfoInstanceGroup().getType())) {
152 GenericResourceApiVnfrequestinputVnfrequestinputVnfNetworkInstanceGroupIds instanceGroupId =
153 new GenericResourceApiVnfrequestinputVnfrequestinputVnfNetworkInstanceGroupIds();
154 instanceGroupId.setVnfNetworkInstanceGroupId(instanceGroup.getId());
155 networkInstanceGroupIdList.add(instanceGroupId);
159 vnfRequestInput.setVnfNetworkInstanceGroupIds(networkInstanceGroupIdList);
160 vnfRequestInput.setVnfInputParameters(vnfInputParameters);
161 req.setVnfRequestInput(vnfRequestInput);