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.vnfapi.util;
24 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.VnfTopologyOperationInputBuilder;
25 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.VnfTopologyOperationOutputBuilder;
26 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.sdnc.request.header.SdncRequestHeaderBuilder;
27 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.service.data.ServiceDataBuilder;
28 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.service.information.ServiceInformationBuilder;
29 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.vnf.information.VnfInformationBuilder;
30 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.vnf.model.infrastructure.VnfListBuilder;
31 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.vnf.request.information.VnfRequestInformationBuilder;
32 import org.opendaylight.yangtools.concepts.Builder;
33 import org.opendaylight.yangtools.yang.common.RpcResult;
35 import java.util.concurrent.Future;
36 import java.util.function.Consumer;
37 import java.util.function.Function;
41 * This uill class provides utility to build yang objects using a recursive syntax that resembles the tree structure
42 * when defining the same yang object in json format.
47 * import static org.onap.sdnc.northbound.util.MDSALUtil.*;
48 * VnfTopologyOperationInput input = build(vnfTopologyOperationInput()
49 * .setServiceInformation(
50 * build(serviceInformation()
51 * .setServiceId("serviceId: xyz")
52 * .setServiceInstanceId("serviceInstanceId: xyz")
53 * .setServiceType("serviceType: xyz")
54 * .setSubscriberName("subscriberName: xyz")
57 * .setVnfRequestInformation(
58 * build(vnfRequestInformation()
59 * .setVnfId("vnfId: xyz")
60 * .setVnfName("vnfName: xyz")//defect if missing
61 * .setVnfType("vnfType: xyz")//defect if missing
64 * .setSdncRequestHeader(
65 * build(sdncRequestHeader()
66 * .setSvcAction(SvcAction.Delete)
74 public class MDSALUtil {
76 public static VnfTopologyOperationInputBuilder vnfTopologyOperationInput(){return new VnfTopologyOperationInputBuilder();}
77 public static VnfTopologyOperationOutputBuilder vnfTopologyOperationOutput(){return new VnfTopologyOperationOutputBuilder();}
79 public static ServiceInformationBuilder serviceInformation(){return new ServiceInformationBuilder();}
80 public static VnfRequestInformationBuilder vnfRequestInformation(){return new VnfRequestInformationBuilder();}
81 public static VnfListBuilder vnfList(){return new VnfListBuilder();}
82 public static ServiceDataBuilder serviceData() { return new ServiceDataBuilder();}
83 public static SdncRequestHeaderBuilder sdncRequestHeader(){return new SdncRequestHeaderBuilder();}
84 public static VnfInformationBuilder vnfInformation(){return new VnfInformationBuilder();}
87 public static <P> P build(Builder<P> b) {
88 return b == null? null :b.build();
91 public static <P,B extends Builder<P>> P build(Function<P,B> builderConstructor,P sourceDataObject){
92 if(sourceDataObject == null){
95 B bp = builderConstructor.apply(sourceDataObject);
99 public static <P,B extends Builder<P>> P build(Function<P,B> builderConstructor,P sourceDataObject,Consumer<B> builder){
100 if(sourceDataObject == null){
103 B bp = builderConstructor.apply(sourceDataObject);
108 public static <I,O> O exec(Function<I,Future<RpcResult<O>>> rpc,I rpcParameter,Function<RpcResult<O>,O> rpcResult) throws Exception {
109 Future<RpcResult<O>> future = rpc.apply(rpcParameter);
110 return rpcResult.apply(future.get());