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.NetworkTopologyOperationInputBuilder;
28 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.NetworkTopologyOperationOutputBuilder;
29 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.ServiceTopologyOperationInputBuilder;
30 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.ServiceTopologyOperationOutputBuilder;
31 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.VnfTopologyOperationInputBuilder;
32 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.VnfTopologyOperationOutputBuilder;
33 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.network.information.NetworkInformationBuilder;
34 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.network.response.information.NetworkResponseInformationBuilder;
35 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.request.information.RequestInformationBuilder;
36 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.sdnc.request.header.SdncRequestHeaderBuilder;
37 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.service.data.ServiceDataBuilder;
38 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.service.information.ServiceInformationBuilder;
39 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.service.level.oper.status.ServiceLevelOperStatusBuilder;
40 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.service.model.infrastructure.ServiceBuilder;
41 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.service.response.information.ServiceResponseInformationBuilder;
42 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.service.status.ServiceStatusBuilder;
43 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.vnf.information.VnfInformationBuilder;
44 import org.opendaylight.yangtools.concepts.Builder;
45 import org.opendaylight.yangtools.yang.common.RpcResult;
49 * This uill class provides utility to build yang objects using a recursive syntax that resembles the tree structure
50 * when defining the same yang object in json format.
55 * import static org.onap.sdnc.northbound.util.MDSALUtil.*;
56 * ServiceTopologyOperationInput input = build(
57 * serviceTopologyOperationInput()
58 * .setSdncRequestHeader(build(sdncRequestHeader()
59 * .setSvcRequestId("svc-request-id: xyz")
60 * .setSvcAction(SvcAction.Assign)
62 * .setRequestInformation(build(requestInformation()
63 * .setRequestId("request-id: xyz")
64 * .setRequestAction(RequestInformation.RequestAction.CreateServiceInstance)
66 * .setServiceInformation(build(serviceInformationBuilder()
67 * .setServiceInstanceId("service-instance-id: xyz")
73 public class MDSALUtil {
75 public static VnfTopologyOperationInputBuilder vnfTopologyOperationInput() {
76 return new VnfTopologyOperationInputBuilder();
79 public static VnfTopologyOperationOutputBuilder vnfTopologyOperationOutput() {
80 return new VnfTopologyOperationOutputBuilder();
83 public static ServiceTopologyOperationInputBuilder serviceTopologyOperationInput() {
84 return new ServiceTopologyOperationInputBuilder();
87 public static ServiceTopologyOperationOutputBuilder serviceTopologyOperationOutput() {
88 return new ServiceTopologyOperationOutputBuilder();
92 public static SdncRequestHeaderBuilder sdncRequestHeader() {
93 return new SdncRequestHeaderBuilder();
97 public static RequestInformationBuilder requestInformation() {
98 return new RequestInformationBuilder();
101 public static ServiceResponseInformationBuilder serviceResponseInformation() {
102 return new ServiceResponseInformationBuilder();
105 public static ServiceInformationBuilder serviceInformationBuilder() {
106 return new ServiceInformationBuilder();
109 public static VnfInformationBuilder vnfInformationBuilder() {
110 return new VnfInformationBuilder();
114 public static ServiceBuilder service() {
115 return new ServiceBuilder();
119 public static ServiceDataBuilder serviceData() {
120 return new ServiceDataBuilder();
124 public static ServiceStatusBuilder serviceStatus() {
125 return new ServiceStatusBuilder();
128 public static NetworkInformationBuilder networkInformation() {
129 return new NetworkInformationBuilder();
132 public static NetworkTopologyOperationInputBuilder networkTopologyOperationInput() {
133 return new NetworkTopologyOperationInputBuilder();
136 public static NetworkTopologyOperationOutputBuilder networkTopologyOperationOutput() {
137 return new NetworkTopologyOperationOutputBuilder();
140 public static NetworkResponseInformationBuilder networkResponseInformation() {
141 return new NetworkResponseInformationBuilder();
144 public static ServiceLevelOperStatusBuilder serviceLevelOperStatus() {
145 return new ServiceLevelOperStatusBuilder();
148 public static <P> P build(Builder<P> b) {
149 return b == null ? null : b.build();
152 public static <P, B extends Builder<P>> P build(Function<P, B> builderConstructor, P sourceDataObject) {
153 if (sourceDataObject == null) {
156 B bp = builderConstructor.apply(sourceDataObject);
160 public static <P, B extends Builder<P>> P build(Function<P, B> builderConstructor, P sourceDataObject,
161 Consumer<B> builder) {
162 if (sourceDataObject == null) {
165 B bp = builderConstructor.apply(sourceDataObject);
170 public static <I, O> O exec(Function<I, Future<RpcResult<O>>> rpc, I rpcParameter,
171 Function<RpcResult<O>, O> rpcResult) throws Exception {
172 Future<RpcResult<O>> future = rpc.apply(rpcParameter);
173 return rpcResult.apply(future.get());