Generic resource API catch up
[sdnc/northbound.git] / generic-resource-api / provider / src / test / java / org / onap / sdnc / northbound / util / MDSALUtil.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * openECOMP : SDN-C
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights
6  *                             reserved.
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
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
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=========================================================
20  */
21
22 package org.onap.sdnc.northbound.util;
23
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;
76
77
78 /**
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.
81  *
82  * For Example
83  * <pre>
84  * {@code
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)
91  *                 ))
92  *                 .setRequestInformation(build(requestInformation()
93  *                         .setRequestId("request-id: xyz")
94  *                        .setRequestAction(RequestInformation.RequestAction.CreateServiceInstance)
95  *                 ))
96  *                .setServiceInformation(build(serviceInformationBuilder()
97  *                         .setServiceInstanceId("service-instance-id: xyz")
98  *                ))
99  * );
100  * }
101  * </pre>
102  */
103 public class MDSALUtil {
104
105     public static PreloadVfModuleTopologyOperationInputBuilder preloadVfModuleTopologyOperationInput() {
106         return new PreloadVfModuleTopologyOperationInputBuilder();
107     }
108
109     public static PreloadVfModuleTopologyOperationOutputBuilder preloadVfModuleTopologyOperationOutput() {
110         return new PreloadVfModuleTopologyOperationOutputBuilder();
111     }
112
113     public static PreloadNetworkTopologyOperationInputBuilder preloadNetworkTopologyOperationInput() {
114         return new PreloadNetworkTopologyOperationInputBuilder();
115     }
116
117     public static PreloadNetworkTopologyOperationOutputBuilder preloadNetworkTopologyOperationOutput() {
118         return new PreloadNetworkTopologyOperationOutputBuilder();
119     }
120
121     public static BrgTopologyOperationInputBuilder brgTopologyOperationInput() {
122         return new BrgTopologyOperationInputBuilder();
123     }
124
125     public static BrgTopologyOperationOutputBuilder brgTopologyOperationOutput() {
126         return new BrgTopologyOperationOutputBuilder();
127     }
128
129     public static TunnelxconnTopologyOperationInputBuilder tunnelxconnTopologyOperationInput() {
130         return new TunnelxconnTopologyOperationInputBuilder();
131     }
132
133     public static TunnelxconnTopologyOperationOutputBuilder tunnelxconnTopologyOperationOutput() {
134         return new TunnelxconnTopologyOperationOutputBuilder();
135     }
136
137     public static SecurityZoneTopologyOperationInputBuilder securityZoneTopologyOperationInput() {
138         return new SecurityZoneTopologyOperationInputBuilder();
139     }
140
141     public static SecurityZoneTopologyOperationOutputBuilder securityZoneTopologyOperationOutput() {
142         return new SecurityZoneTopologyOperationOutputBuilder();
143     }
144
145     public static ContrailRouteTopologyOperationInputBuilder contrailRouteTopologyOperationInput() {
146         return new ContrailRouteTopologyOperationInputBuilder();
147     }
148
149     public static ContrailRouteTopologyOperationOutputBuilder contrailRouteTopologyOperationOutput() {
150         return new ContrailRouteTopologyOperationOutputBuilder();
151     }
152
153     public static VfModuleTopologyOperationInputBuilder vfModuleTopologyOperationInput() {
154         return new VfModuleTopologyOperationInputBuilder();
155     }
156
157     public static VfModuleTopologyOperationOutputBuilder vfModuleTopologyOperationOutput() {
158         return new VfModuleTopologyOperationOutputBuilder();
159     }
160
161     public static VnfTopologyOperationInputBuilder vnfTopologyOperationInput() {
162         return new VnfTopologyOperationInputBuilder();
163     }
164
165     public static VnfTopologyOperationOutputBuilder vnfTopologyOperationOutput() {
166         return new VnfTopologyOperationOutputBuilder();
167     }
168
169     public static ServiceTopologyOperationInputBuilder serviceTopologyOperationInput() {
170         return new ServiceTopologyOperationInputBuilder();
171     }
172
173     public static ServiceTopologyOperationOutputBuilder serviceTopologyOperationOutput() {
174         return new ServiceTopologyOperationOutputBuilder();
175     }
176
177
178     public static SdncRequestHeaderBuilder sdncRequestHeader() {
179         return new SdncRequestHeaderBuilder();
180     }
181
182
183     public static RequestInformationBuilder requestInformation() {
184         return new RequestInformationBuilder();
185     }
186
187     public static ServiceResponseInformationBuilder serviceResponseInformation() {
188         return new ServiceResponseInformationBuilder();
189     }
190     
191     public static SecurityZoneResponseInformationBuilder securityZoneResponseInformation() {
192         return new SecurityZoneResponseInformationBuilder();
193     }
194
195     public static TunnelxconnResponseInformationBuilder tunnelxconnResponseInformation() {
196         return new TunnelxconnResponseInformationBuilder();
197     }
198
199     public static BrgResponseInformationBuilder brgResponseInformation() {
200         return new BrgResponseInformationBuilder();
201     }
202
203     public static ContrailRouteResponseInformationBuilder contrailRouteResponseInformation() {
204         return new ContrailRouteResponseInformationBuilder();
205     }
206
207     public static VnfResponseInformationBuilder vnfResponseInformation() {
208         return new VnfResponseInformationBuilder();
209     }
210
211     public static VfModuleResponseInformationBuilder vfModuleResponseInformation() {
212         return new VfModuleResponseInformationBuilder();
213     }
214
215     public static ServiceInformationBuilder serviceInformationBuilder() {
216         return new ServiceInformationBuilder();
217     }
218
219     public static PreloadNetworkTopologyInformationBuilder preloadNetworkTopologyInformationBuilder() {
220         return new PreloadNetworkTopologyInformationBuilder();
221     }
222
223     public static NetworkTopologyIdentifierStructureBuilder networkTopologyIdentifierStructureBuilder(){
224         return new NetworkTopologyIdentifierStructureBuilder();
225     }
226
227     public static VnfInformationBuilder vnfInformationBuilder() {
228         return new VnfInformationBuilder();
229     }
230
231     public static VfModuleInformationBuilder vfModuleInformationBuilder() {
232         return new VfModuleInformationBuilder();
233     }
234
235     public static ServiceBuilder service() {
236         return new ServiceBuilder();
237     }
238
239     public static ServiceDataBuilder serviceData() {
240         return new ServiceDataBuilder();
241     }
242
243     public static ServiceStatusBuilder serviceStatus() {
244         return new ServiceStatusBuilder();
245     }
246
247     public static NetworkInformationBuilder networkInformation() {
248         return new NetworkInformationBuilder();
249     }
250
251     public static NetworkTopologyOperationInputBuilder networkTopologyOperationInput() {
252         return new NetworkTopologyOperationInputBuilder();
253     }
254
255     public static NetworkTopologyOperationOutputBuilder networkTopologyOperationOutput() {
256         return new NetworkTopologyOperationOutputBuilder();
257     }
258
259     public static VnfTopologyIdentifierStructureBuilder vnfTopologyIdentifierStructureBuilder() {
260         return new VnfTopologyIdentifierStructureBuilder();
261     }
262
263     public static PreloadVfModuleTopologyInformationBuilder preloadVfModuleTopologyInformationBuilder() {
264         return new PreloadVfModuleTopologyInformationBuilder();
265     }
266
267     public static VfModuleTopologyBuilder vfModuleTopologyBuilder() {
268         return new VfModuleTopologyBuilder();
269     }
270     
271     public static VfModuleTopologyIdentifierBuilder vfModuleTopologyIdentifierBuilder() {
272         return new VfModuleTopologyIdentifierBuilder();
273     }
274     
275     public static NetworkResponseInformationBuilder networkResponseInformation() {
276         return new NetworkResponseInformationBuilder();
277     }
278
279     public static ConnectionAttachmentTopologyOperationInputBuilder connectionAttachmentTopologyOperationInput() {
280         return new ConnectionAttachmentTopologyOperationInputBuilder();
281     }
282
283     public static ConnectionAttachmentTopologyOperationOutputBuilder connectionAttachmentTopologyOperationOutput() {
284         return new ConnectionAttachmentTopologyOperationOutputBuilder();
285     }
286
287     public static ConnectionAttachmentResponseInformationBuilder connectionAttachmentResponseInformation() {
288         return new ConnectionAttachmentResponseInformationBuilder();
289     }
290
291     public static ServiceLevelOperStatusBuilder serviceLevelOperStatus() {
292         return new ServiceLevelOperStatusBuilder();
293     }
294
295     public static <P> P build(Builder<P> b) {
296         return b == null ? null : b.build();
297     }
298
299     public static <P, B extends Builder<P>> P build(Function<P, B> builderConstructor, P sourceDataObject) {
300         if (sourceDataObject == null) {
301             return null;
302         }
303         B bp = builderConstructor.apply(sourceDataObject);
304         return bp.build();
305     }
306
307     public static <P, B extends Builder<P>> P build(Function<P, B> builderConstructor, P sourceDataObject,
308         Consumer<B> builder) {
309         if (sourceDataObject == null) {
310             return null;
311         }
312         B bp = builderConstructor.apply(sourceDataObject);
313         builder.accept(bp);
314         return bp.build();
315     }
316
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());
321     }
322
323 }