2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.sdnc.northbound.util;
24 import java.util.concurrent.Future;
25 import java.util.function.Consumer;
26 import java.util.function.Function;
27 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.BrgTopologyOperationInputBuilder;
28 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.BrgTopologyOperationOutputBuilder;
29 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.ConnectionAttachmentTopologyOperationInputBuilder;
30 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.ConnectionAttachmentTopologyOperationOutputBuilder;
31 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.ContrailRouteTopologyOperationInputBuilder;
32 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.ContrailRouteTopologyOperationOutputBuilder;
33 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.NetworkTopologyOperationInputBuilder;
34 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.NetworkTopologyOperationOutputBuilder;
35 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.PreloadNetworkTopologyOperationInputBuilder;
36 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.PreloadNetworkTopologyOperationOutputBuilder;
37 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.PreloadVfModuleTopologyOperationInputBuilder;
38 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.PreloadVfModuleTopologyOperationOutputBuilder;
39 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.SecurityZoneTopologyOperationInputBuilder;
40 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.SecurityZoneTopologyOperationOutputBuilder;
41 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.ServiceTopologyOperationInputBuilder;
42 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.ServiceTopologyOperationOutputBuilder;
43 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.TunnelxconnTopologyOperationInputBuilder;
44 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.TunnelxconnTopologyOperationOutputBuilder;
45 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.VfModuleTopologyOperationInputBuilder;
46 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.VfModuleTopologyOperationOutputBuilder;
47 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.VnfTopologyOperationInputBuilder;
48 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.VnfTopologyOperationOutputBuilder;
49 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.brg.response.information.BrgResponseInformationBuilder;
50 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.connection.attachment.response.information.ConnectionAttachmentResponseInformationBuilder;
51 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.contrail.route.response.information.ContrailRouteResponseInformationBuilder;
52 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.network.information.NetworkInformationBuilder;
53 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.network.response.information.NetworkResponseInformationBuilder;
54 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.network.topology.identifier.structure.NetworkTopologyIdentifierStructureBuilder;
55 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.preload.network.topology.information.PreloadNetworkTopologyInformationBuilder;
56 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.preload.vf.module.topology.information.PreloadVfModuleTopologyInformationBuilder;
57 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.request.information.RequestInformationBuilder;
58 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.sdnc.request.header.SdncRequestHeaderBuilder;
59 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.security.zone.response.information.SecurityZoneResponseInformationBuilder;
60 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.service.data.ServiceDataBuilder;
61 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.service.information.ServiceInformationBuilder;
62 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.service.level.oper.status.ServiceLevelOperStatusBuilder;
63 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.service.model.infrastructure.ServiceBuilder;
64 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.service.response.information.ServiceResponseInformationBuilder;
65 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.service.status.ServiceStatusBuilder;
66 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.tunnelxconn.response.information.TunnelxconnResponseInformationBuilder;
67 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.vf.module.information.VfModuleInformationBuilder;
68 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.vf.module.response.information.VfModuleResponseInformationBuilder;
69 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.vf.module.topology.VfModuleTopologyBuilder;
70 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.vf.module.topology.identifier.VfModuleTopologyIdentifierBuilder;
71 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.vnf.information.VnfInformationBuilder;
72 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.vnf.response.information.VnfResponseInformationBuilder;
73 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.vnf.topology.identifier.structure.VnfTopologyIdentifierStructureBuilder;
74 import org.opendaylight.yangtools.concepts.Builder;
75 import org.opendaylight.yangtools.yang.common.RpcResult;
79 * This uill class provides utility to build yang objects using a recursive syntax that resembles the tree structure
80 * when defining the same yang object in json format.
85 * import static org.onap.sdnc.northbound.util.MDSALUtil.*;
86 * ServiceTopologyOperationInput input = build(
87 * serviceTopologyOperationInput()
88 * .setSdncRequestHeader(build(sdncRequestHeader()
89 * .setSvcRequestId("svc-request-id: xyz")
90 * .setSvcAction(SvcAction.Assign)
92 * .setRequestInformation(build(requestInformation()
93 * .setRequestId("request-id: xyz")
94 * .setRequestAction(RequestInformation.RequestAction.CreateServiceInstance)
96 * .setServiceInformation(build(serviceInformationBuilder()
97 * .setServiceInstanceId("service-instance-id: xyz")
103 public class MDSALUtil {
105 public static PreloadVfModuleTopologyOperationInputBuilder preloadVfModuleTopologyOperationInput() {
106 return new PreloadVfModuleTopologyOperationInputBuilder();
109 public static PreloadVfModuleTopologyOperationOutputBuilder preloadVfModuleTopologyOperationOutput() {
110 return new PreloadVfModuleTopologyOperationOutputBuilder();
113 public static PreloadNetworkTopologyOperationInputBuilder preloadNetworkTopologyOperationInput() {
114 return new PreloadNetworkTopologyOperationInputBuilder();
117 public static PreloadNetworkTopologyOperationOutputBuilder preloadNetworkTopologyOperationOutput() {
118 return new PreloadNetworkTopologyOperationOutputBuilder();
121 public static BrgTopologyOperationInputBuilder brgTopologyOperationInput() {
122 return new BrgTopologyOperationInputBuilder();
125 public static BrgTopologyOperationOutputBuilder brgTopologyOperationOutput() {
126 return new BrgTopologyOperationOutputBuilder();
129 public static TunnelxconnTopologyOperationInputBuilder tunnelxconnTopologyOperationInput() {
130 return new TunnelxconnTopologyOperationInputBuilder();
133 public static TunnelxconnTopologyOperationOutputBuilder tunnelxconnTopologyOperationOutput() {
134 return new TunnelxconnTopologyOperationOutputBuilder();
137 public static SecurityZoneTopologyOperationInputBuilder securityZoneTopologyOperationInput() {
138 return new SecurityZoneTopologyOperationInputBuilder();
141 public static SecurityZoneTopologyOperationOutputBuilder securityZoneTopologyOperationOutput() {
142 return new SecurityZoneTopologyOperationOutputBuilder();
145 public static ContrailRouteTopologyOperationInputBuilder contrailRouteTopologyOperationInput() {
146 return new ContrailRouteTopologyOperationInputBuilder();
149 public static ContrailRouteTopologyOperationOutputBuilder contrailRouteTopologyOperationOutput() {
150 return new ContrailRouteTopologyOperationOutputBuilder();
153 public static VfModuleTopologyOperationInputBuilder vfModuleTopologyOperationInput() {
154 return new VfModuleTopologyOperationInputBuilder();
157 public static VfModuleTopologyOperationOutputBuilder vfModuleTopologyOperationOutput() {
158 return new VfModuleTopologyOperationOutputBuilder();
161 public static VnfTopologyOperationInputBuilder vnfTopologyOperationInput() {
162 return new VnfTopologyOperationInputBuilder();
165 public static VnfTopologyOperationOutputBuilder vnfTopologyOperationOutput() {
166 return new VnfTopologyOperationOutputBuilder();
169 public static ServiceTopologyOperationInputBuilder serviceTopologyOperationInput() {
170 return new ServiceTopologyOperationInputBuilder();
173 public static ServiceTopologyOperationOutputBuilder serviceTopologyOperationOutput() {
174 return new ServiceTopologyOperationOutputBuilder();
178 public static SdncRequestHeaderBuilder sdncRequestHeader() {
179 return new SdncRequestHeaderBuilder();
183 public static RequestInformationBuilder requestInformation() {
184 return new RequestInformationBuilder();
187 public static ServiceResponseInformationBuilder serviceResponseInformation() {
188 return new ServiceResponseInformationBuilder();
191 public static SecurityZoneResponseInformationBuilder securityZoneResponseInformation() {
192 return new SecurityZoneResponseInformationBuilder();
195 public static TunnelxconnResponseInformationBuilder tunnelxconnResponseInformation() {
196 return new TunnelxconnResponseInformationBuilder();
199 public static BrgResponseInformationBuilder brgResponseInformation() {
200 return new BrgResponseInformationBuilder();
203 public static ContrailRouteResponseInformationBuilder contrailRouteResponseInformation() {
204 return new ContrailRouteResponseInformationBuilder();
207 public static VnfResponseInformationBuilder vnfResponseInformation() {
208 return new VnfResponseInformationBuilder();
211 public static VfModuleResponseInformationBuilder vfModuleResponseInformation() {
212 return new VfModuleResponseInformationBuilder();
215 public static ServiceInformationBuilder serviceInformationBuilder() {
216 return new ServiceInformationBuilder();
219 public static PreloadNetworkTopologyInformationBuilder preloadNetworkTopologyInformationBuilder() {
220 return new PreloadNetworkTopologyInformationBuilder();
223 public static NetworkTopologyIdentifierStructureBuilder networkTopologyIdentifierStructureBuilder(){
224 return new NetworkTopologyIdentifierStructureBuilder();
227 public static VnfInformationBuilder vnfInformationBuilder() {
228 return new VnfInformationBuilder();
231 public static VfModuleInformationBuilder vfModuleInformationBuilder() {
232 return new VfModuleInformationBuilder();
235 public static ServiceBuilder service() {
236 return new ServiceBuilder();
239 public static ServiceDataBuilder serviceData() {
240 return new ServiceDataBuilder();
243 public static ServiceStatusBuilder serviceStatus() {
244 return new ServiceStatusBuilder();
247 public static NetworkInformationBuilder networkInformation() {
248 return new NetworkInformationBuilder();
251 public static NetworkTopologyOperationInputBuilder networkTopologyOperationInput() {
252 return new NetworkTopologyOperationInputBuilder();
255 public static NetworkTopologyOperationOutputBuilder networkTopologyOperationOutput() {
256 return new NetworkTopologyOperationOutputBuilder();
259 public static VnfTopologyIdentifierStructureBuilder vnfTopologyIdentifierStructureBuilder() {
260 return new VnfTopologyIdentifierStructureBuilder();
263 public static PreloadVfModuleTopologyInformationBuilder preloadVfModuleTopologyInformationBuilder() {
264 return new PreloadVfModuleTopologyInformationBuilder();
267 public static VfModuleTopologyBuilder vfModuleTopologyBuilder() {
268 return new VfModuleTopologyBuilder();
271 public static VfModuleTopologyIdentifierBuilder vfModuleTopologyIdentifierBuilder() {
272 return new VfModuleTopologyIdentifierBuilder();
275 public static NetworkResponseInformationBuilder networkResponseInformation() {
276 return new NetworkResponseInformationBuilder();
279 public static ConnectionAttachmentTopologyOperationInputBuilder connectionAttachmentTopologyOperationInput() {
280 return new ConnectionAttachmentTopologyOperationInputBuilder();
283 public static ConnectionAttachmentTopologyOperationOutputBuilder connectionAttachmentTopologyOperationOutput() {
284 return new ConnectionAttachmentTopologyOperationOutputBuilder();
287 public static ConnectionAttachmentResponseInformationBuilder connectionAttachmentResponseInformation() {
288 return new ConnectionAttachmentResponseInformationBuilder();
291 public static ServiceLevelOperStatusBuilder serviceLevelOperStatus() {
292 return new ServiceLevelOperStatusBuilder();
295 public static <P> P build(Builder<P> b) {
296 return b == null ? null : b.build();
299 public static <P, B extends Builder<P>> P build(Function<P, B> builderConstructor, P sourceDataObject) {
300 if (sourceDataObject == null) {
303 B bp = builderConstructor.apply(sourceDataObject);
307 public static <P, B extends Builder<P>> P build(Function<P, B> builderConstructor, P sourceDataObject,
308 Consumer<B> builder) {
309 if (sourceDataObject == null) {
312 B bp = builderConstructor.apply(sourceDataObject);
317 public static <I, O> O exec(Function<I, Future<RpcResult<O>>> rpc, I rpcParameter,
318 Function<RpcResult<O>, O> rpcResult) throws Exception {
319 Future<RpcResult<O>> future = rpc.apply(rpcParameter);
320 return rpcResult.apply(future.get());