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());
74 vnfRequestInput.setCloudOwner(cloudRegion.getCloudOwner());
76 if (StringUtils.isNotBlank(vnf.getVnfName())) {
77 vnfRequestInput.setVnfName(vnf.getVnfName());
80 req.setRequestInformation(requestInformation);
81 req.setSdncRequestHeader(sdncRequestHeader);
82 req.setServiceInformation(serviceInformation);
83 req.setVnfInformation(vnfInformation);
85 GenericResourceApiParam vnfInputParameters = new GenericResourceApiParam();
86 if (requestContext.getUserParams() != null) {
87 for (Map.Entry<String, String> entry : requestContext.getUserParams().entrySet()) {
88 GenericResourceApiParamParam paramItem = new GenericResourceApiParamParam();
89 paramItem.setName(entry.getKey());
90 paramItem.setValue(entry.getValue());
91 vnfInputParameters.addParamItem(paramItem);
92 vnfRequestInput.setVnfInputParameters(vnfInputParameters);
95 if (vnf.getCloudParams() != null) {
96 for (Map.Entry<String, String> entry : vnf.getCloudParams().entrySet()) {
97 GenericResourceApiParamParam paramItem = new GenericResourceApiParamParam();
98 paramItem.setName(entry.getKey());
99 paramItem.setValue(entry.getValue());
100 vnfInputParameters.addParamItem(paramItem);
104 License license = vnf.getLicense();
105 if (license != null) {
106 if(license.getEntitlementPoolUuids() != null && !license.getEntitlementPoolUuids().isEmpty()) {
107 String entitlementPoolUuid = license.getEntitlementPoolUuids().get(0);
108 GenericResourceApiParamParam paramItem = new GenericResourceApiParamParam();
109 paramItem.setName("entitlement_assignment_group_uuid");
110 paramItem.setValue(entitlementPoolUuid);
111 vnfInputParameters.addParamItem(paramItem);
113 if (license.getLicenseKeyGroupUuids() != null && !license.getLicenseKeyGroupUuids().isEmpty()) {
114 String licenseKeyGroupUuid = license.getLicenseKeyGroupUuids().get(0);
115 GenericResourceApiParamParam paramItem2 = new GenericResourceApiParamParam();
116 paramItem2.setName("license_assignment_group_uuid");
117 paramItem2.setValue(licenseKeyGroupUuid);
118 vnfInputParameters.addParamItem(paramItem2);
122 List<InstanceGroup> instanceGroups = vnf.getInstanceGroups();
123 List<GenericResourceApiVnfrequestinputVnfrequestinputVnfNetworkInstanceGroupIds> networkInstanceGroupIdList = new ArrayList<GenericResourceApiVnfrequestinputVnfrequestinputVnfNetworkInstanceGroupIds>();
125 for (InstanceGroup instanceGroup : instanceGroups) {
126 if (ModelInfoInstanceGroup.TYPE_NETWORK_INSTANCE_GROUP
127 .equalsIgnoreCase(instanceGroup.getModelInfoInstanceGroup().getType())) {
128 GenericResourceApiVnfrequestinputVnfrequestinputVnfNetworkInstanceGroupIds instanceGroupId = new GenericResourceApiVnfrequestinputVnfrequestinputVnfNetworkInstanceGroupIds();
129 instanceGroupId.setVnfNetworkInstanceGroupId(instanceGroup.getId());
130 networkInstanceGroupIdList.add(instanceGroupId);
134 vnfRequestInput.setVnfNetworkInstanceGroupIds(networkInstanceGroupIdList);
135 vnfRequestInput.setVnfInputParameters(vnfInputParameters);
136 req.setVnfRequestInput(vnfRequestInput);