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.ccsdk.features.sdnr.northbound.oofpcipoc;
24 import java.util.Properties;
25 import java.util.concurrent.ExecutorService;
26 import java.util.concurrent.Executors;
28 import org.onap.ccsdk.sli.core.sli.provider.MdsalHelper;
29 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
30 import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
31 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
32 import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
33 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
34 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RpcRegistration;
35 import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev190308.*;
37 import com.google.common.base.Preconditions;
38 import org.opendaylight.yangtools.yang.common.RpcResult;
39 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
40 import org.slf4j.Logger;
41 import org.slf4j.LoggerFactory;
43 import com.google.common.base.Preconditions;
44 import com.google.common.util.concurrent.Futures;
45 import com.google.common.util.concurrent.ListenableFuture;
48 * Defines a base implementation for your provider. This class extends from a helper class
49 * which provides storage for the most commonly used components of the MD-SAL. Additionally the
50 * base class provides some basic logging and initialization / clean up methods.
53 public class OofpcipocProvider implements AutoCloseable, OofpcipocApiService {
55 private static final Logger LOG = LoggerFactory.getLogger(OofpcipocProvider.class);
57 private static final String APPLICATION_NAME = "Oofpcipoc";
59 private final ExecutorService executor;
61 protected DataBroker dataBroker;
62 protected NotificationPublishService notificationService;
63 protected RpcProviderRegistry rpcRegistry;
64 protected BindingAwareBroker.RpcRegistration<OofpcipocApiService> rpcRegistration;
65 private final OofpcipocClient OofpcipocClient;
68 public OofpcipocProvider(final DataBroker dataBroker,
69 final NotificationPublishService notificationPublishService,
70 final RpcProviderRegistry rpcProviderRegistry,
71 final OofpcipocClient OofpcipocClient) {
73 this.LOG.info( "Creating provider for {}", APPLICATION_NAME);
74 executor = Executors.newFixedThreadPool(1);
75 this.dataBroker = dataBroker;
76 this.notificationService = notificationPublishService;
77 this.rpcRegistry = rpcProviderRegistry;
78 this.OofpcipocClient = OofpcipocClient;
82 public void initialize(){
83 LOG.info( "Initializing provider for {}", APPLICATION_NAME);
84 rpcRegistration = rpcRegistry.addRpcImplementation(OofpcipocApiService.class, this);
85 LOG.info( "Initialization complete for {}", APPLICATION_NAME);
88 protected void initializeChild() {
89 //Override if you have custom initialization intelligence
93 public void close() throws Exception {
94 LOG.info( "Closing provider for {}", APPLICATION_NAME);
96 rpcRegistration.close();
97 LOG.info( "Successfully closed provider for {}", APPLICATION_NAME);
101 public ListenableFuture<RpcResult<GreetingOutput>> greeting(
102 GreetingInput input) {
103 final String svcOperation = "greeting";
105 Properties parms = new Properties();
106 GreetingOutputBuilder serviceDataBuilder = new GreetingOutputBuilder();
108 LOG.info( "Reached RPC greeting");
110 LOG.info( svcOperation +" called." );
113 LOG.debug("exiting " +svcOperation+ " because of invalid input");
114 serviceDataBuilder.setResponse("Input is null");
115 RpcResult<GreetingOutput> rpcResult =
116 RpcResultBuilder.<GreetingOutput> status(true).withResult(serviceDataBuilder.build()).build();
117 return Futures.immediateFuture(rpcResult);
120 // add input to parms
121 LOG.info("Adding INPUT data for "+svcOperation+" input: " + input);
122 GreetingInputBuilder inputBuilder = new GreetingInputBuilder(input);
123 MdsalHelper.toProperties(parms, inputBuilder.build());
125 // Call SLI sync method
128 if (OofpcipocClient.hasGraph("Oofpcipoc", svcOperation , null, "sync"))
130 LOG.info( "OofpcipocClient has a Directed Graph for '" + svcOperation + "'");
133 OofpcipocClient.execute("Oofpcipoc", svcOperation, null, "sync", serviceDataBuilder, parms);
137 LOG.error("Caught exception executing service logic for "+ svcOperation, e);
138 serviceDataBuilder.setResponse("500");
141 LOG.error("No service logic active for Oofpcipoc: '" + svcOperation + "'");
142 serviceDataBuilder.setResponse("503");
147 LOG.error("Caught exception looking for service logic", e);
148 serviceDataBuilder.setResponse("500");
151 String errorCode = serviceDataBuilder.getResponse();
153 if (!("0".equals(errorCode) || "200".equals(errorCode))) {
154 LOG.error("Returned FAILED for "+svcOperation+" error code: '" + errorCode + "'");
156 LOG.info("Returned SUCCESS for "+svcOperation+" ");
157 serviceDataBuilder.setResponse("Welcome OOF POC " + input.getSalutation());
160 RpcResult<GreetingOutput> rpcResult =
161 RpcResultBuilder.<GreetingOutput> status(true).withResult(serviceDataBuilder.build()).build();
163 LOG.info("Successful exit from greeting ");
165 return Futures.immediateFuture(rpcResult);
168 // RPC configuration-phy-cell-id
170 public ListenableFuture<RpcResult<ConfigurationPhyCellIdOutput>> configurationPhyCellId(
171 ConfigurationPhyCellIdInput input) {
172 final String svcOperation = "configuration-phy-cell-id";
174 Properties parms = new Properties();
175 ConfigurationPhyCellIdOutputBuilder serviceDataBuilder = new ConfigurationPhyCellIdOutputBuilder();
177 LOG.info( "Reached RPC configurationPhyCellId");
179 LOG.info( svcOperation +" called." );
182 LOG.debug("exiting " +svcOperation+ " because of invalid input");
183 serviceDataBuilder.setResponseCode("Input is null");
184 RpcResult<ConfigurationPhyCellIdOutput> rpcResult =
185 RpcResultBuilder.<ConfigurationPhyCellIdOutput> status(true).withResult(serviceDataBuilder.build()).build();
186 return Futures.immediateFuture(rpcResult);
189 // add input to parms
190 LOG.info("Adding INPUT data for "+svcOperation+" input: " + input);
191 ConfigurationPhyCellIdInputBuilder inputBuilder = new ConfigurationPhyCellIdInputBuilder(input);
192 MdsalHelper.toProperties(parms, inputBuilder.build());
194 // Call SLI sync method
198 if (OofpcipocClient.hasGraph("Oofpcipoc", svcOperation , null, "sync"))
200 LOG.info( "OofpcipocClient has a Directed Graph for '" + svcOperation + "'");
204 OofpcipocClient.execute("Oofpcipoc", svcOperation, null, "sync", serviceDataBuilder, parms);
208 LOG.error("Caught exception executing service logic for "+ svcOperation, e);
209 serviceDataBuilder.setResponseCode("500");
212 LOG.error("No service logic active for Oofpcipoc: '" + svcOperation + "'");
213 serviceDataBuilder.setResponseCode("503");
218 LOG.error("Caught exception looking for service logic", e);
219 serviceDataBuilder.setResponseCode("500");
222 String errorCode = serviceDataBuilder.getResponseCode();
224 if (!("0".equals(errorCode) || "200".equals(errorCode))) {
225 LOG.error("Returned FAILED for "+svcOperation+" error code: '" + errorCode + "'");
227 LOG.info("Returned SUCCESS for "+svcOperation+" ");
228 serviceDataBuilder.setResponseCode("Welcome OOF POC. Number of FAP entries " + input.getFapServiceNumberOfEntries());
231 RpcResult<ConfigurationPhyCellIdOutput> rpcResult =
232 RpcResultBuilder.<ConfigurationPhyCellIdOutput> status(true).withResult(serviceDataBuilder.build()).build();
234 return Futures.immediateFuture(rpcResult);
239 public ListenableFuture<RpcResult<AddNeighborOutput>> addNeighbor(
240 AddNeighborInput input) {
241 final String svcOperation = "add-neighbor";
243 Properties parms = new Properties();
244 AddNeighborOutputBuilder serviceDataBuilder = new AddNeighborOutputBuilder();
246 LOG.info( "Reached RPC addNeighbor");
248 LOG.info( svcOperation +" called." );
251 LOG.debug("exiting " +svcOperation+ " because of invalid input");
252 serviceDataBuilder.setResponseCode("Input is null");
253 RpcResult<AddNeighborOutput> rpcResult =
254 RpcResultBuilder.<AddNeighborOutput> status(true).withResult(serviceDataBuilder.build()).build();
255 return Futures.immediateFuture(rpcResult);
258 // add input to parms
259 LOG.info("Adding INPUT data for "+svcOperation+" input: " + input);
260 AddNeighborInputBuilder inputBuilder = new AddNeighborInputBuilder(input);
261 MdsalHelper.toProperties(parms, inputBuilder.build());
263 // Call SLI sync method
267 if (OofpcipocClient.hasGraph("Oofpcipoc", svcOperation , null, "sync"))
269 LOG.info( "OofpcipocClient has a Directed Graph for '" + svcOperation + "'");
273 OofpcipocClient.execute("Oofpcipoc", svcOperation, null, "sync", serviceDataBuilder, parms);
277 LOG.error("Caught exception executing service logic for "+ svcOperation, e);
278 serviceDataBuilder.setResponseCode("500");
281 LOG.error("No service logic active for Oofpcipoc: '" + svcOperation + "'");
282 serviceDataBuilder.setResponseCode("503");
287 LOG.error("Caught exception looking for service logic", e);
288 serviceDataBuilder.setResponseCode("500");
291 String errorCode = serviceDataBuilder.getResponseCode();
293 if (!("0".equals(errorCode) || "200".equals(errorCode))) {
294 LOG.error("Returned FAILED for "+svcOperation+" error code: '" + errorCode + "'");
296 LOG.info("Returned SUCCESS for "+svcOperation+" ");
297 serviceDataBuilder.setResponseCode("Welcome OOF POC. Number of Neighbor entries to be added " + input.getLteCellNumberOfEntries());
300 RpcResult<AddNeighborOutput> rpcResult =
301 RpcResultBuilder.<AddNeighborOutput> status(true).withResult(serviceDataBuilder.build()).build();
303 return Futures.immediateFuture(rpcResult);
306 // RPC delete-neighbor
308 public ListenableFuture<RpcResult<DeleteNeighborOutput>> deleteNeighbor(
309 DeleteNeighborInput input) {
310 final String svcOperation = "delete-neighbor";
312 Properties parms = new Properties();
313 DeleteNeighborOutputBuilder serviceDataBuilder = new DeleteNeighborOutputBuilder();
315 LOG.info( "Reached RPC deleteNeighbor");
317 LOG.info( svcOperation +" called." );
320 LOG.debug("exiting " +svcOperation+ " because of invalid input");
321 serviceDataBuilder.setResponseCode("Input is null");
322 RpcResult<DeleteNeighborOutput> rpcResult =
323 RpcResultBuilder.<DeleteNeighborOutput> status(true).withResult(serviceDataBuilder.build()).build();
324 return Futures.immediateFuture(rpcResult);
327 // add input to parms
328 LOG.info("Adding INPUT data for "+svcOperation+" input: " + input);
329 DeleteNeighborInputBuilder inputBuilder = new DeleteNeighborInputBuilder(input);
330 MdsalHelper.toProperties(parms, inputBuilder.build());
332 // Call SLI sync method
336 if (OofpcipocClient.hasGraph("Oofpcipoc", svcOperation , null, "sync"))
338 LOG.info( "OofpcipocClient has a Directed Graph for '" + svcOperation + "'");
342 OofpcipocClient.execute("Oofpcipoc", svcOperation, null, "sync", serviceDataBuilder, parms);
346 LOG.error("Caught exception executing service logic for "+ svcOperation, e);
347 serviceDataBuilder.setResponseCode("500");
350 LOG.error("No service logic active for Oofpcipoc: '" + svcOperation + "'");
351 serviceDataBuilder.setResponseCode("503");
356 LOG.error("Caught exception looking for service logic", e);
357 serviceDataBuilder.setResponseCode("500");
360 String errorCode = serviceDataBuilder.getResponseCode();
362 if (!("0".equals(errorCode) || "200".equals(errorCode))) {
363 LOG.error("Returned FAILED for "+svcOperation+" error code: '" + errorCode + "'");
365 LOG.info("Returned SUCCESS for "+svcOperation+" ");
366 serviceDataBuilder.setResponseCode("Welcome OOF POC. Number of Neighbor entries to be deleted " + input.getLteCellNumberOfEntries());
369 RpcResult<DeleteNeighborOutput> rpcResult =
370 RpcResultBuilder.<DeleteNeighborOutput> status(true).withResult(serviceDataBuilder.build()).build();
372 return Futures.immediateFuture(rpcResult);
375 // RPC generic-neighbor-configuration
377 public ListenableFuture<RpcResult<GenericNeighborConfigurationOutput>> genericNeighborConfiguration(
378 GenericNeighborConfigurationInput input) {
379 final String svcOperation = "generic-neighbor-configuration";
381 Properties parms = new Properties();
382 GenericNeighborConfigurationOutputBuilder serviceDataBuilder = new GenericNeighborConfigurationOutputBuilder();
384 LOG.info( "Reached RPC genericNeighborConfiguration");
386 LOG.info( svcOperation +" called." );
389 LOG.debug("exiting " +svcOperation+ " because of invalid input");
390 serviceDataBuilder.setResponseCode("Input is null");
391 RpcResult<GenericNeighborConfigurationOutput> rpcResult =
392 RpcResultBuilder.<GenericNeighborConfigurationOutput> status(true).withResult(serviceDataBuilder.build()).build();
393 return Futures.immediateFuture(rpcResult);
396 // add input to parms
397 LOG.info("Adding INPUT data for "+svcOperation+" input: " + input);
398 GenericNeighborConfigurationInputBuilder inputBuilder = new GenericNeighborConfigurationInputBuilder(input);
399 MdsalHelper.toProperties(parms, inputBuilder.build());
401 // Call SLI sync method
405 if (OofpcipocClient.hasGraph("Oofpcipoc", svcOperation , null, "sync"))
407 LOG.info( "OofpcipocClient has a Directed Graph for '" + svcOperation + "'");
411 OofpcipocClient.execute("Oofpcipoc", svcOperation, null, "sync", serviceDataBuilder, parms);
415 LOG.error("Caught exception executing service logic for "+ svcOperation, e);
416 serviceDataBuilder.setResponseCode("500");
419 LOG.error("No service logic active for Oofpcipoc: '" + svcOperation + "'");
420 serviceDataBuilder.setResponseCode("503");
425 LOG.error("Caught exception looking for service logic", e);
426 serviceDataBuilder.setResponseCode("500");
429 String errorCode = serviceDataBuilder.getResponseCode();
431 if (!("0".equals(errorCode) || "200".equals(errorCode))) {
432 LOG.error("Returned FAILED for "+svcOperation+" error code: '" + errorCode + "'");
434 LOG.info("Returned SUCCESS for "+svcOperation+" ");
435 serviceDataBuilder.setResponseCode("Welcome OOF POC. Number of Neighbor entries to be configured " + input.getLteCellNumberOfEntries());
438 RpcResult<GenericNeighborConfigurationOutput> rpcResult =
439 RpcResultBuilder.<GenericNeighborConfigurationOutput> status(true).withResult(serviceDataBuilder.build()).build();
441 return Futures.immediateFuture(rpcResult);
444 // RPC handle-nbrlist-change-notif
446 public ListenableFuture<RpcResult<HandleNbrlistChangeNotifOutput>> handleNbrlistChangeNotif(
447 HandleNbrlistChangeNotifInput input) {
448 final String svcOperation = "handle-nbrlist-change-notif";
450 Properties parms = new Properties();
451 HandleNbrlistChangeNotifOutputBuilder serviceDataBuilder = new HandleNbrlistChangeNotifOutputBuilder();
453 LOG.info( "Reached RPC handle-nbrlist-change-notif");
455 LOG.info( svcOperation +" called." );
458 LOG.debug("exiting " +svcOperation+ " because of invalid input");
459 serviceDataBuilder.setResponseCode("Input is null");
460 RpcResult<HandleNbrlistChangeNotifOutput> rpcResult =
461 RpcResultBuilder.<HandleNbrlistChangeNotifOutput> status(true).withResult(serviceDataBuilder.build()).build();
462 return Futures.immediateFuture(rpcResult);
465 // add input to parms
466 LOG.info("Adding INPUT data for "+svcOperation+" input: " + input);
467 HandleNbrlistChangeNotifInputBuilder inputBuilder = new HandleNbrlistChangeNotifInputBuilder(input);
468 MdsalHelper.toProperties(parms, inputBuilder.build());
470 // Call SLI sync method
473 if (OofpcipocClient.hasGraph("Oofpcipoc", svcOperation , null, "sync"))
475 LOG.info( "OofpcipocClient has a Directed Graph for '" + svcOperation + "'");
478 OofpcipocClient.execute("Oofpcipoc", svcOperation, null, "sync", serviceDataBuilder, parms);
482 LOG.error("Caught exception executing service logic for "+ svcOperation, e);
483 serviceDataBuilder.setResponseCode("500");
486 LOG.error("No service logic active for Oofpcipoc: '" + svcOperation + "'");
487 serviceDataBuilder.setResponseCode("503");
492 LOG.error("Caught exception looking for service logic", e);
493 serviceDataBuilder.setResponseCode("500");
496 String errorCode = serviceDataBuilder.getResponseCode();
498 if (!("0".equals(errorCode) || "200".equals(errorCode))) {
499 LOG.error("Returned FAILED for "+svcOperation+" error code: '" + errorCode + "'");
501 LOG.info("Returned SUCCESS for "+svcOperation+" ");
502 serviceDataBuilder.setResponseCode("Welcome OOF POC. Number of FAP services changed = " + input.getFapServiceNumberOfEntriesChanged());
505 RpcResult<HandleNbrlistChangeNotifOutput> rpcResult =
506 RpcResultBuilder.<HandleNbrlistChangeNotifOutput> status(true).withResult(serviceDataBuilder.build()).build();
508 LOG.info("Successful exit from handle-nbrlist-change-notif ");
510 return Futures.immediateFuture(rpcResult);