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.mdsal.binding.api.DataBroker;
30 import org.opendaylight.mdsal.binding.api.NotificationPublishService;
31 import org.opendaylight.mdsal.binding.api.RpcProviderService;
32 import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev190308.*;
33 import org.opendaylight.yangtools.concepts.ObjectRegistration;
34 import org.opendaylight.yangtools.yang.common.RpcResult;
35 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
36 import org.slf4j.Logger;
37 import org.slf4j.LoggerFactory;
39 import com.google.common.util.concurrent.Futures;
40 import com.google.common.util.concurrent.ListenableFuture;
43 * Defines a base implementation for your provider. This class extends from a
44 * helper class which provides storage for the most commonly used components of
45 * the MD-SAL. Additionally the base class provides some basic logging and
46 * initialization / clean up methods.
49 public class OofpcipocProvider implements AutoCloseable, OofpcipocApiService {
51 private static final Logger LOG = LoggerFactory.getLogger(OofpcipocProvider.class);
53 private static final String APPLICATION_NAME = "oofpcipoc-api";
55 private final ExecutorService executor;
57 private DataBroker dataBroker;
58 private NotificationPublishService notificationService;
59 private RpcProviderService rpcProviderService;
60 private ObjectRegistration<OofpcipocProvider> rpcRegistration;
61 private OofpcipocClient OofpcipocClient;
63 public OofpcipocProvider() {
65 LOG.info("Creating provider for {}", APPLICATION_NAME);
66 executor = Executors.newFixedThreadPool(1);
67 this.dataBroker = null;
68 this.notificationService = null;
69 this.rpcProviderService = null;
70 this.OofpcipocClient = null;
73 public void setDataBroker(DataBroker dataBroker) {
74 this.dataBroker = dataBroker;
77 public void setRpcProviderService(RpcProviderService rpcProviderRegistry) {
78 this.rpcProviderService = rpcProviderRegistry;
81 public void setNotificationPublishService(NotificationPublishService notificationPublishService) {
82 this.notificationService = notificationPublishService;
85 public void setClient(OofpcipocClient client) {
86 this.OofpcipocClient = client;
90 LOG.info("Initializing provider for {}", APPLICATION_NAME);
91 rpcRegistration = rpcProviderService.registerRpcImplementation(OofpcipocApiService.class, this);
92 LOG.info("Initialization complete for {}", APPLICATION_NAME);
96 public void close() throws Exception {
97 LOG.info("Closing provider for {}", APPLICATION_NAME);
99 if (rpcRegistration != null)
100 rpcRegistration.close();
101 LOG.info("Successfully closed provider for {}", APPLICATION_NAME);
105 public ListenableFuture<RpcResult<GreetingOutput>> greeting(GreetingInput input) {
106 final String svcOperation = "greeting";
108 Properties parms = new Properties();
109 GreetingOutputBuilder serviceDataBuilder = new GreetingOutputBuilder();
111 LOG.info("Reached RPC greeting");
113 LOG.info(svcOperation + " called.");
116 LOG.debug("exiting " + svcOperation + " because of invalid input");
117 serviceDataBuilder.setResponse("Input is null");
118 RpcResult<GreetingOutput> rpcResult = RpcResultBuilder.<GreetingOutput>status(true)
119 .withResult(serviceDataBuilder.build()).build();
120 return Futures.immediateFuture(rpcResult);
123 // add input to parms
124 LOG.info("Adding INPUT data for " + svcOperation + " input: " + input);
125 GreetingInputBuilder inputBuilder = new GreetingInputBuilder(input);
126 MdsalHelper.toProperties(parms, inputBuilder.build());
128 // Call SLI sync method
130 if (OofpcipocClient.hasGraph("oofpcipoc-api", svcOperation, null, "sync")) {
131 LOG.info("OofpcipocClient has a Directed Graph for '" + svcOperation + "'");
133 OofpcipocClient.execute("oofpcipoc-api", svcOperation, null, "sync", serviceDataBuilder, parms);
134 } catch (Exception e) {
135 LOG.error("Caught exception executing service logic for " + svcOperation, e);
136 serviceDataBuilder.setResponse("500");
139 LOG.error("No service logic active for Oofpcipoc: '" + svcOperation + "'");
140 serviceDataBuilder.setResponse("503");
142 } catch (Exception e) {
143 LOG.error("Caught exception looking for service logic", e);
144 serviceDataBuilder.setResponse("500");
147 String errorCode = serviceDataBuilder.getResponse();
149 if (!("0".equals(errorCode) || "200".equals(errorCode))) {
150 LOG.error("Returned FAILED for " + svcOperation + " error code: '" + errorCode + "'");
152 LOG.info("Returned SUCCESS for " + svcOperation + " ");
153 serviceDataBuilder.setResponse("Welcome OOF POC " + input.getSalutation());
156 RpcResult<GreetingOutput> rpcResult = RpcResultBuilder.<GreetingOutput>status(true)
157 .withResult(serviceDataBuilder.build()).build();
159 LOG.info("Successful exit from greeting ");
161 return Futures.immediateFuture(rpcResult);
164 // RPC configuration-phy-cell-id
166 public ListenableFuture<RpcResult<ConfigurationPhyCellIdOutput>> configurationPhyCellId(
167 ConfigurationPhyCellIdInput input) {
168 final String svcOperation = "configuration-phy-cell-id";
170 Properties parms = new Properties();
171 ConfigurationPhyCellIdOutputBuilder serviceDataBuilder = new ConfigurationPhyCellIdOutputBuilder();
173 LOG.info("Reached RPC configurationPhyCellId");
175 LOG.info(svcOperation + " called.");
178 LOG.debug("exiting " + svcOperation + " because of invalid input");
179 serviceDataBuilder.setResponseCode("Input is null");
180 RpcResult<ConfigurationPhyCellIdOutput> rpcResult = RpcResultBuilder
181 .<ConfigurationPhyCellIdOutput>status(true).withResult(serviceDataBuilder.build()).build();
182 return Futures.immediateFuture(rpcResult);
185 // add input to parms
186 LOG.info("Adding INPUT data for " + svcOperation + " input: " + input);
187 ConfigurationPhyCellIdInputBuilder inputBuilder = new ConfigurationPhyCellIdInputBuilder(input);
188 MdsalHelper.toProperties(parms, inputBuilder.build());
190 // Call SLI sync method
193 if (OofpcipocClient.hasGraph("oofpcipoc-api", svcOperation, null, "sync")) {
194 LOG.info("OofpcipocClient has a Directed Graph for '" + svcOperation + "'");
197 OofpcipocClient.execute("oofpcipoc-api", svcOperation, null, "sync", serviceDataBuilder, parms);
198 } catch (Exception e) {
199 LOG.error("Caught exception executing service logic for " + svcOperation, e);
200 serviceDataBuilder.setResponseCode("500");
203 LOG.error("No service logic active for Oofpcipoc: '" + svcOperation + "'");
204 serviceDataBuilder.setResponseCode("503");
206 } catch (Exception e) {
207 LOG.error("Caught exception looking for service logic", e);
208 serviceDataBuilder.setResponseCode("500");
211 String errorCode = serviceDataBuilder.getResponseCode();
213 if (!("0".equals(errorCode) || "200".equals(errorCode))) {
214 LOG.error("Returned FAILED for " + svcOperation + " error code: '" + errorCode + "'");
216 LOG.info("Returned SUCCESS for " + svcOperation + " ");
218 .setResponseCode("Welcome OOF POC. Number of FAP entries " + input.getFapServiceNumberOfEntries());
221 RpcResult<ConfigurationPhyCellIdOutput> rpcResult = RpcResultBuilder.<ConfigurationPhyCellIdOutput>status(true)
222 .withResult(serviceDataBuilder.build()).build();
224 return Futures.immediateFuture(rpcResult);
229 public ListenableFuture<RpcResult<AddNeighborOutput>> addNeighbor(AddNeighborInput input) {
230 final String svcOperation = "add-neighbor";
232 Properties parms = new Properties();
233 AddNeighborOutputBuilder serviceDataBuilder = new AddNeighborOutputBuilder();
235 LOG.info("Reached RPC addNeighbor");
237 LOG.info(svcOperation + " called.");
240 LOG.debug("exiting " + svcOperation + " because of invalid input");
241 serviceDataBuilder.setResponseCode("Input is null");
242 RpcResult<AddNeighborOutput> rpcResult = RpcResultBuilder.<AddNeighborOutput>status(true)
243 .withResult(serviceDataBuilder.build()).build();
244 return Futures.immediateFuture(rpcResult);
247 // add input to parms
248 LOG.info("Adding INPUT data for " + svcOperation + " input: " + input);
249 AddNeighborInputBuilder inputBuilder = new AddNeighborInputBuilder(input);
250 MdsalHelper.toProperties(parms, inputBuilder.build());
252 // Call SLI sync method
255 if (OofpcipocClient.hasGraph("oofpcipoc-api", svcOperation, null, "sync")) {
256 LOG.info("OofpcipocClient has a Directed Graph for '" + svcOperation + "'");
259 OofpcipocClient.execute("oofpcipoc-api", svcOperation, null, "sync", serviceDataBuilder, parms);
260 } catch (Exception e) {
261 LOG.error("Caught exception executing service logic for " + svcOperation, e);
262 serviceDataBuilder.setResponseCode("500");
265 LOG.error("No service logic active for Oofpcipoc: '" + svcOperation + "'");
266 serviceDataBuilder.setResponseCode("503");
268 } catch (Exception e) {
269 LOG.error("Caught exception looking for service logic", e);
270 serviceDataBuilder.setResponseCode("500");
273 String errorCode = serviceDataBuilder.getResponseCode();
275 if (!("0".equals(errorCode) || "200".equals(errorCode))) {
276 LOG.error("Returned FAILED for " + svcOperation + " error code: '" + errorCode + "'");
278 LOG.info("Returned SUCCESS for " + svcOperation + " ");
279 serviceDataBuilder.setResponseCode(
280 "Welcome OOF POC. Number of Neighbor entries to be added " + input.getLteCellNumberOfEntries());
283 RpcResult<AddNeighborOutput> rpcResult = RpcResultBuilder.<AddNeighborOutput>status(true)
284 .withResult(serviceDataBuilder.build()).build();
286 return Futures.immediateFuture(rpcResult);
289 // RPC delete-neighbor
291 public ListenableFuture<RpcResult<DeleteNeighborOutput>> deleteNeighbor(DeleteNeighborInput input) {
292 final String svcOperation = "delete-neighbor";
294 Properties parms = new Properties();
295 DeleteNeighborOutputBuilder serviceDataBuilder = new DeleteNeighborOutputBuilder();
297 LOG.info("Reached RPC deleteNeighbor");
299 LOG.info(svcOperation + " called.");
302 LOG.debug("exiting " + svcOperation + " because of invalid input");
303 serviceDataBuilder.setResponseCode("Input is null");
304 RpcResult<DeleteNeighborOutput> rpcResult = RpcResultBuilder.<DeleteNeighborOutput>status(true)
305 .withResult(serviceDataBuilder.build()).build();
306 return Futures.immediateFuture(rpcResult);
309 // add input to parms
310 LOG.info("Adding INPUT data for " + svcOperation + " input: " + input);
311 DeleteNeighborInputBuilder inputBuilder = new DeleteNeighborInputBuilder(input);
312 MdsalHelper.toProperties(parms, inputBuilder.build());
314 // Call SLI sync method
317 if (OofpcipocClient.hasGraph("oofpcipoc-api", svcOperation, null, "sync")) {
318 LOG.info("OofpcipocClient has a Directed Graph for '" + svcOperation + "'");
321 OofpcipocClient.execute("oofpcipoc-api", svcOperation, null, "sync", serviceDataBuilder, parms);
322 } catch (Exception e) {
323 LOG.error("Caught exception executing service logic for " + svcOperation, e);
324 serviceDataBuilder.setResponseCode("500");
327 LOG.error("No service logic active for Oofpcipoc: '" + svcOperation + "'");
328 serviceDataBuilder.setResponseCode("503");
330 } catch (Exception e) {
331 LOG.error("Caught exception looking for service logic", e);
332 serviceDataBuilder.setResponseCode("500");
335 String errorCode = serviceDataBuilder.getResponseCode();
337 if (!("0".equals(errorCode) || "200".equals(errorCode))) {
338 LOG.error("Returned FAILED for " + svcOperation + " error code: '" + errorCode + "'");
340 LOG.info("Returned SUCCESS for " + svcOperation + " ");
341 serviceDataBuilder.setResponseCode(
342 "Welcome OOF POC. Number of Neighbor entries to be deleted " + input.getLteCellNumberOfEntries());
345 RpcResult<DeleteNeighborOutput> rpcResult = RpcResultBuilder.<DeleteNeighborOutput>status(true)
346 .withResult(serviceDataBuilder.build()).build();
348 return Futures.immediateFuture(rpcResult);
351 // RPC generic-neighbor-configuration
353 public ListenableFuture<RpcResult<GenericNeighborConfigurationOutput>> genericNeighborConfiguration(
354 GenericNeighborConfigurationInput input) {
355 final String svcOperation = "generic-neighbor-configuration";
357 Properties parms = new Properties();
358 GenericNeighborConfigurationOutputBuilder serviceDataBuilder = new GenericNeighborConfigurationOutputBuilder();
360 LOG.info("Reached RPC genericNeighborConfiguration");
362 LOG.info(svcOperation + " called.");
365 LOG.debug("exiting " + svcOperation + " because of invalid input");
366 serviceDataBuilder.setResponseCode("Input is null");
367 RpcResult<GenericNeighborConfigurationOutput> rpcResult = RpcResultBuilder
368 .<GenericNeighborConfigurationOutput>status(true).withResult(serviceDataBuilder.build()).build();
369 return Futures.immediateFuture(rpcResult);
372 // add input to parms
373 LOG.info("Adding INPUT data for " + svcOperation + " input: " + input);
374 GenericNeighborConfigurationInputBuilder inputBuilder = new GenericNeighborConfigurationInputBuilder(input);
375 MdsalHelper.toProperties(parms, inputBuilder.build());
377 // Call SLI sync method
380 if (OofpcipocClient.hasGraph("oofpcipoc-api", svcOperation, null, "sync")) {
381 LOG.info("OofpcipocClient has a Directed Graph for '" + svcOperation + "'");
384 OofpcipocClient.execute("oofpcipoc-api", svcOperation, null, "sync", serviceDataBuilder, parms);
385 } catch (Exception e) {
386 LOG.error("Caught exception executing service logic for " + svcOperation, e);
387 serviceDataBuilder.setResponseCode("500");
390 LOG.error("No service logic active for Oofpcipoc: '" + svcOperation + "'");
391 serviceDataBuilder.setResponseCode("503");
393 } catch (Exception e) {
394 LOG.error("Caught exception looking for service logic", e);
395 serviceDataBuilder.setResponseCode("500");
398 String errorCode = serviceDataBuilder.getResponseCode();
400 if (!("0".equals(errorCode) || "200".equals(errorCode))) {
401 LOG.error("Returned FAILED for " + svcOperation + " error code: '" + errorCode + "'");
403 LOG.info("Returned SUCCESS for " + svcOperation + " ");
404 serviceDataBuilder.setResponseCode("Welcome OOF POC. Number of Neighbor entries to be configured "
405 + input.getLteCellNumberOfEntries());
408 RpcResult<GenericNeighborConfigurationOutput> rpcResult = RpcResultBuilder
409 .<GenericNeighborConfigurationOutput>status(true).withResult(serviceDataBuilder.build()).build();
411 return Futures.immediateFuture(rpcResult);
414 // RPC handle-nbrlist-change-notif
416 public ListenableFuture<RpcResult<HandleNbrlistChangeNotifOutput>> handleNbrlistChangeNotif(
417 HandleNbrlistChangeNotifInput input) {
418 final String svcOperation = "handle-nbrlist-change-notif";
420 Properties parms = new Properties();
421 HandleNbrlistChangeNotifOutputBuilder serviceDataBuilder = new HandleNbrlistChangeNotifOutputBuilder();
423 LOG.info("Reached RPC handle-nbrlist-change-notif");
425 LOG.info(svcOperation + " called.");
428 LOG.debug("exiting " + svcOperation + " because of invalid input");
429 serviceDataBuilder.setResponseCode("Input is null");
430 RpcResult<HandleNbrlistChangeNotifOutput> rpcResult = RpcResultBuilder
431 .<HandleNbrlistChangeNotifOutput>status(true).withResult(serviceDataBuilder.build()).build();
432 return Futures.immediateFuture(rpcResult);
435 // add input to parms
436 LOG.info("Adding INPUT data for " + svcOperation + " input: " + input);
437 HandleNbrlistChangeNotifInputBuilder inputBuilder = new HandleNbrlistChangeNotifInputBuilder(input);
438 MdsalHelper.toProperties(parms, inputBuilder.build());
440 // Call SLI sync method
442 if (OofpcipocClient.hasGraph("oofpcipoc-api", svcOperation, null, "sync")) {
443 LOG.info("OofpcipocClient has a Directed Graph for '" + svcOperation + "'");
445 OofpcipocClient.execute("oofpcipoc-api", svcOperation, null, "sync", serviceDataBuilder, parms);
446 } catch (Exception e) {
447 LOG.error("Caught exception executing service logic for " + svcOperation, e);
448 serviceDataBuilder.setResponseCode("500");
451 LOG.error("No service logic active for Oofpcipoc: '" + svcOperation + "'");
452 serviceDataBuilder.setResponseCode("503");
454 } catch (Exception e) {
455 LOG.error("Caught exception looking for service logic", e);
456 serviceDataBuilder.setResponseCode("500");
459 String errorCode = serviceDataBuilder.getResponseCode();
461 if (!("0".equals(errorCode) || "200".equals(errorCode))) {
462 LOG.error("Returned FAILED for " + svcOperation + " error code: '" + errorCode + "'");
464 LOG.info("Returned SUCCESS for " + svcOperation + " ");
465 serviceDataBuilder.setResponseCode(
466 "Welcome OOF POC. Number of FAP services changed = " + input.getFapServiceNumberOfEntriesChanged());
469 RpcResult<HandleNbrlistChangeNotifOutput> rpcResult = RpcResultBuilder
470 .<HandleNbrlistChangeNotifOutput>status(true).withResult(serviceDataBuilder.build()).build();
472 LOG.info("Successful exit from handle-nbrlist-change-notif ");
474 return Futures.immediateFuture(rpcResult);