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.UUID;
25 import org.onap.sdnc.northbound.client.model.GenericResourceApiNetworkOperationInformation;
26 import org.onap.sdnc.northbound.client.model.GenericResourceApiNetworkinformationNetworkInformation;
27 import org.onap.sdnc.northbound.client.model.GenericResourceApiNetworkrequestinputNetworkRequestInput;
28 import org.onap.sdnc.northbound.client.model.GenericResourceApiParam;
29 import org.onap.sdnc.northbound.client.model.GenericResourceApiParamParam;
30 import org.onap.sdnc.northbound.client.model.GenericResourceApiRequestActionEnumeration;
31 import org.onap.sdnc.northbound.client.model.GenericResourceApiRequestinformationRequestInformation;
32 import org.onap.sdnc.northbound.client.model.GenericResourceApiSdncrequestheaderSdncRequestHeader;
33 import org.onap.sdnc.northbound.client.model.GenericResourceApiServiceinformationServiceInformation;
34 import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion;
35 import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer;
36 import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network;
37 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
38 import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext;
39 import org.onap.so.client.sdnc.beans.SDNCSvcAction;
40 import org.onap.so.client.sdnc.beans.SDNCSvcOperation;
41 import org.springframework.beans.factory.annotation.Autowired;
42 import org.springframework.stereotype.Component;
45 * Mapper creating SDNC request
49 public class NetworkTopologyOperationRequestMapper {
52 private GeneralTopologyObjectMapper generalTopologyObjectMapper;
54 public GenericResourceApiNetworkOperationInformation reqMapper(SDNCSvcOperation svcOperation,
55 SDNCSvcAction svcAction, GenericResourceApiRequestActionEnumeration reqAction, L3Network network,
56 ServiceInstance serviceInstance, Customer customer, RequestContext requestContext,
57 CloudRegion cloudRegion) {
58 GenericResourceApiNetworkOperationInformation req = new GenericResourceApiNetworkOperationInformation();
59 String sdncReqId = UUID.randomUUID().toString();
60 String msoRequestId = UUID.randomUUID().toString();
61 if (requestContext != null && requestContext.getMsoRequestId() != null) {
62 msoRequestId = requestContext.getMsoRequestId();
64 GenericResourceApiSdncrequestheaderSdncRequestHeader sdncRequestHeader =
65 generalTopologyObjectMapper.buildSdncRequestHeader(svcAction, sdncReqId);
66 GenericResourceApiRequestinformationRequestInformation requestInformation = generalTopologyObjectMapper
67 .buildGenericResourceApiRequestinformationRequestInformation(msoRequestId, reqAction);
68 GenericResourceApiServiceinformationServiceInformation serviceInformation =
69 generalTopologyObjectMapper.buildServiceInformation(serviceInstance, requestContext, customer, true);
70 GenericResourceApiNetworkinformationNetworkInformation networkInformation =
71 generalTopologyObjectMapper.buildNetworkInformation(network);
72 GenericResourceApiNetworkrequestinputNetworkRequestInput networkRequestInput =
73 buildNetworkRequestInput(network, serviceInstance, cloudRegion);
75 req.setRequestInformation(requestInformation);
76 req.setSdncRequestHeader(sdncRequestHeader);
77 req.setServiceInformation(serviceInformation);
78 req.setNetworkInformation(networkInformation);
80 if (requestContext != null && requestContext.getUserParams() != null) {
81 for (Map.Entry<String, Object> entry : requestContext.getUserParams().entrySet()) {
82 GenericResourceApiParam networkInputParameters = new GenericResourceApiParam();
83 GenericResourceApiParamParam paramItem = new GenericResourceApiParamParam();
84 paramItem.setName(entry.getKey());
85 paramItem.setValue(generalTopologyObjectMapper.mapUserParamValue(entry.getValue()));
86 networkInputParameters.addParamItem(paramItem);
87 networkRequestInput.setNetworkInputParameters(networkInputParameters);
91 req.setNetworkRequestInput(networkRequestInput);
96 * Private helper to build GenericResourceApiNetworkrequestinputNetworkRequestInput
98 private GenericResourceApiNetworkrequestinputNetworkRequestInput buildNetworkRequestInput(L3Network network,
99 ServiceInstance serviceInstance, CloudRegion cloudRegion) {
100 GenericResourceApiNetworkrequestinputNetworkRequestInput networkRequestInput =
101 new GenericResourceApiNetworkrequestinputNetworkRequestInput();
102 networkRequestInput.setTenant(cloudRegion.getTenantId());
103 networkRequestInput.setCloudOwner(cloudRegion.getCloudOwner());
104 networkRequestInput.setAicCloudRegion(cloudRegion.getLcpCloudRegionId());
105 if (network.getNetworkName() != null && !network.getNetworkName().equals("")) {
106 networkRequestInput.setNetworkName(network.getNetworkName());
108 if (serviceInstance.getCollection() != null && serviceInstance.getCollection().getInstanceGroup() != null) {
109 // set only for network created as part of the collection/instance since 1806
110 networkRequestInput.setNetworkInstanceGroupId(serviceInstance.getCollection().getInstanceGroup().getId());
112 return networkRequestInput;