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