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.a1Adapter;
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.rev191212.*;
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 A1AdapterProvider implements AutoCloseable, A1ADAPTERAPIService {
55 private static final Logger LOG = LoggerFactory.getLogger(A1AdapterProvider.class);
57 private static final String APPLICATION_NAME = "a1Adapter-api";
59 private final ExecutorService executor;
61 protected DataBroker dataBroker;
62 protected NotificationPublishService notificationService;
63 protected RpcProviderRegistry rpcRegistry;
64 protected BindingAwareBroker.RpcRegistration<A1ADAPTERAPIService> rpcRegistration;
65 private final A1AdapterClient A1AdapterClient;
68 public A1AdapterProvider(final DataBroker dataBroker,
69 final NotificationPublishService notificationPublishService,
70 final RpcProviderRegistry rpcProviderRegistry,
71 final A1AdapterClient A1AdapterClient) {
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.A1AdapterClient = A1AdapterClient;
82 public void initialize(){
83 LOG.info( "Initializing provider for {}", APPLICATION_NAME);
84 rpcRegistration = rpcRegistry.addRpcImplementation(A1ADAPTERAPIService.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);
100 // RPC getNearRT-RICs
103 public ListenableFuture<RpcResult<GetNearRTRICsOutput>> getNearRTRICs(
104 GetNearRTRICsInput input) {
105 final String svcOperation = "getNearRT-RICs";
107 Properties parms = new Properties();
108 GetNearRTRICsOutputBuilder serviceDataBuilder = new GetNearRTRICsOutputBuilder();
110 LOG.info( "Reached RPC getNearRT-RICs");
112 LOG.info( svcOperation +" called." );
115 LOG.debug("exiting " +svcOperation+ " because of invalid input");
116 serviceDataBuilder.setResponseCode("Input is null");
117 RpcResult<GetNearRTRICsOutput> rpcResult =
118 RpcResultBuilder.<GetNearRTRICsOutput> status(true).withResult(serviceDataBuilder.build()).build();
119 return Futures.immediateFuture(rpcResult);
122 // add input to parms
123 LOG.info("Adding INPUT data for "+svcOperation+" input: " + input);
124 GetNearRTRICsInputBuilder inputBuilder = new GetNearRTRICsInputBuilder(input);
125 MdsalHelper.toProperties(parms, inputBuilder.build());
127 LOG.info("Printing SLI parameters to be passed");
129 // iterate properties file to get key-value pairs
130 for (String key : parms.stringPropertyNames()) {
131 String value = parms.getProperty(key);
132 LOG.info("The SLI parameter in " + key + " is: " + value);
135 // Call SLI sync method
138 if (A1AdapterClient.hasGraph("A1-ADAPTER-API", svcOperation , null, "sync"))
140 LOG.info( "A1AdapterClient has a Directed Graph for '" + svcOperation + "'");
143 A1AdapterClient.execute("A1-ADAPTER-API", svcOperation, null, "sync", serviceDataBuilder, parms);
147 LOG.error("Caught exception executing service logic for "+ svcOperation, e);
148 serviceDataBuilder.setResponseCode("500");
151 LOG.error("No service logic active for A1Adapter: '" + svcOperation + "'");
152 serviceDataBuilder.setResponseCode("503");
157 LOG.error("Caught exception looking for service logic", e);
158 serviceDataBuilder.setResponseCode("500");
161 String errorCode = serviceDataBuilder.getResponseCode();
163 if (!("0".equals(errorCode) || "200".equals(errorCode))) {
164 LOG.error("Returned FAILED for "+svcOperation+" error code: '" + errorCode + "'");
166 LOG.info("Returned SUCCESS for "+svcOperation+" ");
167 serviceDataBuilder.setResponseCode("A1 Adapter Executed for GetNearRTRICs " );
170 RpcResult<GetNearRTRICsOutput> rpcResult =
171 RpcResultBuilder.<GetNearRTRICsOutput> status(true).withResult(serviceDataBuilder.build()).build();
173 LOG.info("Successful exit from getNearRT-RICs ");
175 return Futures.immediateFuture(rpcResult);
178 // RPC getHealthCheck
181 public ListenableFuture<RpcResult<GetHealthCheckOutput>> getHealthCheck(
182 GetHealthCheckInput input) {
183 final String svcOperation = "getHealthCheck";
185 Properties parms = new Properties();
186 GetHealthCheckOutputBuilder serviceDataBuilder = new GetHealthCheckOutputBuilder();
188 LOG.info( "Reached RPC getHealthCheck");
190 LOG.info( svcOperation +" called." );
193 LOG.debug("exiting " +svcOperation+ " because of invalid input");
194 serviceDataBuilder.setResponseCode("Input is null");
195 RpcResult<GetHealthCheckOutput> rpcResult =
196 RpcResultBuilder.<GetHealthCheckOutput> status(true).withResult(serviceDataBuilder.build()).build();
197 return Futures.immediateFuture(rpcResult);
200 // add input to parms
201 LOG.info("Adding INPUT data for "+svcOperation+" input: " + input);
202 GetHealthCheckInputBuilder inputBuilder = new GetHealthCheckInputBuilder(input);
203 MdsalHelper.toProperties(parms, inputBuilder.build());
205 LOG.info("Printing SLI parameters to be passed");
207 // iterate properties file to get key-value pairs
208 for (String key : parms.stringPropertyNames()) {
209 String value = parms.getProperty(key);
210 LOG.info("The SLI parameter in " + key + " is: " + value);
213 // Call SLI sync method
216 if (A1AdapterClient.hasGraph("A1-ADAPTER-API", svcOperation , null, "sync"))
218 LOG.info( "A1AdapterClient has a Directed Graph for '" + svcOperation + "'");
221 A1AdapterClient.execute("A1-ADAPTER-API", svcOperation, null, "sync", serviceDataBuilder, parms);
225 LOG.error("Caught exception executing service logic for "+ svcOperation, e);
226 serviceDataBuilder.setResponseCode("500");
229 LOG.error("No service logic active for A1Adapter: '" + svcOperation + "'");
230 serviceDataBuilder.setResponseCode("503");
235 LOG.error("Caught exception looking for service logic", e);
236 serviceDataBuilder.setResponseCode("500");
239 String errorCode = serviceDataBuilder.getResponseCode();
241 if (!("0".equals(errorCode) || "200".equals(errorCode))) {
242 LOG.error("Returned FAILED for "+svcOperation+" error code: '" + errorCode + "'");
244 LOG.info("Returned SUCCESS for "+svcOperation+" ");
245 serviceDataBuilder.setResponseCode("A1 Adapter Executed for GetHealthCheck. " );
248 RpcResult<GetHealthCheckOutput> rpcResult =
249 RpcResultBuilder.<GetHealthCheckOutput> status(true).withResult(serviceDataBuilder.build()).build();
251 LOG.info("Successful exit from getHealthCheck ");
253 return Futures.immediateFuture(rpcResult);
256 // RPC getPolicyTypes
259 public ListenableFuture<RpcResult<GetPolicyTypesOutput>> getPolicyTypes(
260 GetPolicyTypesInput input) {
261 final String svcOperation = "getPolicyTypes";
263 Properties parms = new Properties();
264 GetPolicyTypesOutputBuilder serviceDataBuilder = new GetPolicyTypesOutputBuilder();
266 LOG.info( "Reached RPC getPolicyTypes");
268 LOG.info( svcOperation +" called." );
271 LOG.debug("exiting " +svcOperation+ " because of invalid input");
272 serviceDataBuilder.setResponseCode("Input is null");
273 RpcResult<GetPolicyTypesOutput> rpcResult =
274 RpcResultBuilder.<GetPolicyTypesOutput> status(true).withResult(serviceDataBuilder.build()).build();
275 return Futures.immediateFuture(rpcResult);
278 // add input to parms
279 LOG.info("Adding INPUT data for "+svcOperation+" input: " + input);
280 GetPolicyTypesInputBuilder inputBuilder = new GetPolicyTypesInputBuilder(input);
281 MdsalHelper.toProperties(parms, inputBuilder.build());
283 LOG.info("Printing SLI parameters to be passed");
285 // iterate properties file to get key-value pairs
286 for (String key : parms.stringPropertyNames()) {
287 String value = parms.getProperty(key);
288 LOG.info("The SLI parameter in " + key + " is: " + value);
291 // Call SLI sync method
294 if (A1AdapterClient.hasGraph("A1-ADAPTER-API", svcOperation , null, "sync"))
296 LOG.info( "A1AdapterClient has a Directed Graph for '" + svcOperation + "'");
299 A1AdapterClient.execute("A1-ADAPTER-API", svcOperation, null, "sync", serviceDataBuilder, parms);
303 LOG.error("Caught exception executing service logic for "+ svcOperation, e);
304 serviceDataBuilder.setResponseCode("500");
307 LOG.error("No service logic active for A1Adapter: '" + svcOperation + "'");
308 serviceDataBuilder.setResponseCode("503");
313 LOG.error("Caught exception looking for service logic", e);
314 serviceDataBuilder.setResponseCode("500");
317 String errorCode = serviceDataBuilder.getResponseCode();
319 if (!("0".equals(errorCode) || "200".equals(errorCode))) {
320 LOG.error("Returned FAILED for "+svcOperation+" error code: '" + errorCode + "'");
322 LOG.info("Returned SUCCESS for "+svcOperation+" ");
323 serviceDataBuilder.setResponseCode("A1 Adapter Executed for GetPolicyTypes ");
326 RpcResult<GetPolicyTypesOutput> rpcResult =
327 RpcResultBuilder.<GetPolicyTypesOutput> status(true).withResult(serviceDataBuilder.build()).build();
329 LOG.info("Successful exit from getPolicyTypes ");
331 return Futures.immediateFuture(rpcResult);
334 // RPC createPolicyType
337 public ListenableFuture<RpcResult<CreatePolicyTypeOutput>> createPolicyType(
338 CreatePolicyTypeInput input) {
339 final String svcOperation = "createPolicyType";
341 Properties parms = new Properties();
342 CreatePolicyTypeOutputBuilder serviceDataBuilder = new CreatePolicyTypeOutputBuilder();
344 LOG.info( "Reached RPC createPolicyType");
346 LOG.info( svcOperation +" called." );
349 LOG.debug("exiting " +svcOperation+ " because of invalid input");
350 serviceDataBuilder.setResponseCode("Input is null");
351 RpcResult<CreatePolicyTypeOutput> rpcResult =
352 RpcResultBuilder.<CreatePolicyTypeOutput> status(true).withResult(serviceDataBuilder.build()).build();
353 return Futures.immediateFuture(rpcResult);
356 // add input to parms
357 LOG.info("Adding INPUT data for "+svcOperation+" input: " + input);
358 CreatePolicyTypeInputBuilder inputBuilder = new CreatePolicyTypeInputBuilder(input);
359 MdsalHelper.toProperties(parms, inputBuilder.build());
361 LOG.info("Printing SLI parameters to be passed");
363 // iterate properties file to get key-value pairs
364 for (String key : parms.stringPropertyNames()) {
365 String value = parms.getProperty(key);
366 LOG.info("The SLI parameter in " + key + " is: " + value);
369 // Call SLI sync method
372 if (A1AdapterClient.hasGraph("A1-ADAPTER-API", svcOperation , null, "sync"))
374 LOG.info( "A1AdapterClient has a Directed Graph for '" + svcOperation + "'");
377 A1AdapterClient.execute("A1-ADAPTER-API", svcOperation, null, "sync", serviceDataBuilder, parms);
381 LOG.error("Caught exception executing service logic for "+ svcOperation, e);
382 serviceDataBuilder.setResponseCode("500");
385 LOG.error("No service logic active for A1Adapter: '" + svcOperation + "'");
386 serviceDataBuilder.setResponseCode("503");
391 LOG.error("Caught exception looking for service logic", e);
392 serviceDataBuilder.setResponseCode("500");
395 String errorCode = serviceDataBuilder.getResponseCode();
397 if (!("0".equals(errorCode) || "200".equals(errorCode))) {
398 LOG.error("Returned FAILED for "+svcOperation+" error code: '" + errorCode + "'");
400 LOG.info("Returned SUCCESS for "+svcOperation+" ");
401 serviceDataBuilder.setResponseCode("A1 Adapter Executed for CreatePolicyType" );
404 RpcResult<CreatePolicyTypeOutput> rpcResult =
405 RpcResultBuilder.<CreatePolicyTypeOutput> status(true).withResult(serviceDataBuilder.build()).build();
407 LOG.info("Successful exit from createPolicyType ");
409 return Futures.immediateFuture(rpcResult);
415 public ListenableFuture<RpcResult<GetPolicyTypeOutput>> getPolicyType(
416 GetPolicyTypeInput input) {
417 final String svcOperation = "getPolicyType";
419 Properties parms = new Properties();
420 GetPolicyTypeOutputBuilder serviceDataBuilder = new GetPolicyTypeOutputBuilder();
422 LOG.info( "Reached RPC getPolicyType");
424 LOG.info( svcOperation +" called." );
427 LOG.debug("exiting " +svcOperation+ " because of invalid input");
428 serviceDataBuilder.setResponseCode("Input is null");
429 RpcResult<GetPolicyTypeOutput> rpcResult =
430 RpcResultBuilder.<GetPolicyTypeOutput> status(true).withResult(serviceDataBuilder.build()).build();
431 return Futures.immediateFuture(rpcResult);
434 // add input to parms
435 LOG.info("Adding INPUT data for "+svcOperation+" input: " + input);
436 GetPolicyTypeInputBuilder inputBuilder = new GetPolicyTypeInputBuilder(input);
437 MdsalHelper.toProperties(parms, inputBuilder.build());
439 LOG.info("Printing SLI parameters to be passed");
441 // iterate properties file to get key-value pairs
442 for (String key : parms.stringPropertyNames()) {
443 String value = parms.getProperty(key);
444 LOG.info("The SLI parameter in " + key + " is: " + value);
447 // Call SLI sync method
450 if (A1AdapterClient.hasGraph("A1-ADAPTER-API", svcOperation , null, "sync"))
452 LOG.info( "A1AdapterClient has a Directed Graph for '" + svcOperation + "'");
455 A1AdapterClient.execute("A1-ADAPTER-API", svcOperation, null, "sync", serviceDataBuilder, parms);
459 LOG.error("Caught exception executing service logic for "+ svcOperation, e);
460 serviceDataBuilder.setResponseCode("500");
463 LOG.error("No service logic active for A1Adapter: '" + svcOperation + "'");
464 serviceDataBuilder.setResponseCode("503");
469 LOG.error("Caught exception looking for service logic", e);
470 serviceDataBuilder.setResponseCode("500");
473 String errorCode = serviceDataBuilder.getResponseCode();
475 if (!("0".equals(errorCode) || "200".equals(errorCode))) {
476 LOG.error("Returned FAILED for "+svcOperation+" error code: '" + errorCode + "'");
478 LOG.info("Returned SUCCESS for "+svcOperation+" ");
479 serviceDataBuilder.setResponseCode("A1 Adapter Executed for GetPolicyType. " );
482 RpcResult<GetPolicyTypeOutput> rpcResult =
483 RpcResultBuilder.<GetPolicyTypeOutput> status(true).withResult(serviceDataBuilder.build()).build();
485 LOG.info("Successful exit from getPolicyType ");
487 return Futures.immediateFuture(rpcResult);
490 // RPC deletePolicyType
493 public ListenableFuture<RpcResult<DeletePolicyTypeOutput>> deletePolicyType(
494 DeletePolicyTypeInput input) {
495 final String svcOperation = "deletePolicyType";
497 Properties parms = new Properties();
498 DeletePolicyTypeOutputBuilder serviceDataBuilder = new DeletePolicyTypeOutputBuilder();
500 LOG.info( "Reached RPC deletePolicyType");
502 LOG.info( svcOperation +" called." );
505 LOG.debug("exiting " +svcOperation+ " because of invalid input");
506 serviceDataBuilder.setResponseCode("Input is null");
507 RpcResult<DeletePolicyTypeOutput> rpcResult =
508 RpcResultBuilder.<DeletePolicyTypeOutput> status(true).withResult(serviceDataBuilder.build()).build();
509 return Futures.immediateFuture(rpcResult);
512 // add input to parms
513 LOG.info("Adding INPUT data for "+svcOperation+" input: " + input);
514 DeletePolicyTypeInputBuilder inputBuilder = new DeletePolicyTypeInputBuilder(input);
515 MdsalHelper.toProperties(parms, inputBuilder.build());
517 LOG.info("Printing SLI parameters to be passed");
519 // iterate properties file to get key-value pairs
520 for (String key : parms.stringPropertyNames()) {
521 String value = parms.getProperty(key);
522 LOG.info("The SLI parameter in " + key + " is: " + value);
525 // Call SLI sync method
528 if (A1AdapterClient.hasGraph("A1-ADAPTER-API", svcOperation , null, "sync"))
530 LOG.info( "A1AdapterClient has a Directed Graph for '" + svcOperation + "'");
533 A1AdapterClient.execute("A1-ADAPTER-API", svcOperation, null, "sync", serviceDataBuilder, parms);
537 LOG.error("Caught exception executing service logic for "+ svcOperation, e);
538 serviceDataBuilder.setResponseCode("500");
541 LOG.error("No service logic active for A1Adapter: '" + svcOperation + "'");
542 serviceDataBuilder.setResponseCode("503");
547 LOG.error("Caught exception looking for service logic", e);
548 serviceDataBuilder.setResponseCode("500");
551 String errorCode = serviceDataBuilder.getResponseCode();
553 if (!("0".equals(errorCode) || "200".equals(errorCode))) {
554 LOG.error("Returned FAILED for "+svcOperation+" error code: '" + errorCode + "'");
556 LOG.info("Returned SUCCESS for "+svcOperation+" ");
557 serviceDataBuilder.setResponseCode("A1 Adapter Executed for DeletePolicyType ");
560 RpcResult<DeletePolicyTypeOutput> rpcResult =
561 RpcResultBuilder.<DeletePolicyTypeOutput> status(true).withResult(serviceDataBuilder.build()).build();
563 LOG.info("Successful exit from deletePolicyType ");
565 return Futures.immediateFuture(rpcResult);
568 // RPC getPolicyInstances
571 public ListenableFuture<RpcResult<GetPolicyInstancesOutput>> getPolicyInstances(
572 GetPolicyInstancesInput input) {
573 final String svcOperation = "getPolicyInstances";
575 Properties parms = new Properties();
576 GetPolicyInstancesOutputBuilder serviceDataBuilder = new GetPolicyInstancesOutputBuilder();
578 LOG.info( "Reached RPC getPolicyInstances");
580 LOG.info( svcOperation +" called." );
583 LOG.debug("exiting " +svcOperation+ " because of invalid input");
584 serviceDataBuilder.setResponseCode("Input is null");
585 RpcResult<GetPolicyInstancesOutput> rpcResult =
586 RpcResultBuilder.<GetPolicyInstancesOutput> status(true).withResult(serviceDataBuilder.build()).build();
587 return Futures.immediateFuture(rpcResult);
590 // add input to parms
591 LOG.info("Adding INPUT data for "+svcOperation+" input: " + input);
592 GetPolicyInstancesInputBuilder inputBuilder = new GetPolicyInstancesInputBuilder(input);
593 MdsalHelper.toProperties(parms, inputBuilder.build());
595 LOG.info("Printing SLI parameters to be passed");
597 // iterate properties file to get key-value pairs
598 for (String key : parms.stringPropertyNames()) {
599 String value = parms.getProperty(key);
600 LOG.info("The SLI parameter in " + key + " is: " + value);
603 // Call SLI sync method
606 if (A1AdapterClient.hasGraph("A1-ADAPTER-API", svcOperation , null, "sync"))
608 LOG.info( "A1AdapterClient has a Directed Graph for '" + svcOperation + "'");
611 A1AdapterClient.execute("A1-ADAPTER-API", svcOperation, null, "sync", serviceDataBuilder, parms);
615 LOG.error("Caught exception executing service logic for "+ svcOperation, e);
616 serviceDataBuilder.setResponseCode("500");
619 LOG.error("No service logic active for A1Adapter: '" + svcOperation + "'");
620 serviceDataBuilder.setResponseCode("503");
625 LOG.error("Caught exception looking for service logic", e);
626 serviceDataBuilder.setResponseCode("500");
629 String errorCode = serviceDataBuilder.getResponseCode();
631 if (!("0".equals(errorCode) || "200".equals(errorCode))) {
632 LOG.error("Returned FAILED for "+svcOperation+" error code: '" + errorCode + "'");
634 LOG.info("Returned SUCCESS for "+svcOperation+" ");
635 serviceDataBuilder.setResponseCode("A1 Adapter Executed for GetPolicyInstances " );
638 RpcResult<GetPolicyInstancesOutput> rpcResult =
639 RpcResultBuilder.<GetPolicyInstancesOutput> status(true).withResult(serviceDataBuilder.build()).build();
641 LOG.info("Successful exit from getPolicyInstances ");
643 return Futures.immediateFuture(rpcResult);
647 // RPC createPolicyInstance
650 public ListenableFuture<RpcResult<CreatePolicyInstanceOutput>> createPolicyInstance(
651 CreatePolicyInstanceInput input) {
652 final String svcOperation = "createPolicyInstance";
654 Properties parms = new Properties();
655 CreatePolicyInstanceOutputBuilder serviceDataBuilder = new CreatePolicyInstanceOutputBuilder();
657 LOG.info( "Reached RPC createPolicyInstance");
659 LOG.info( svcOperation +" called." );
662 LOG.debug("exiting " +svcOperation+ " because of invalid input");
663 serviceDataBuilder.setResponseCode("Input is null");
664 RpcResult<CreatePolicyInstanceOutput> rpcResult =
665 RpcResultBuilder.<CreatePolicyInstanceOutput> status(true).withResult(serviceDataBuilder.build()).build();
666 return Futures.immediateFuture(rpcResult);
669 // add input to parms
670 LOG.info("Adding INPUT data for "+svcOperation+" input: " + input);
671 CreatePolicyInstanceInputBuilder inputBuilder = new CreatePolicyInstanceInputBuilder(input);
672 MdsalHelper.toProperties(parms, inputBuilder.build());
674 LOG.info("Printing SLI parameters to be passed");
676 // iterate properties file to get key-value pairs
677 for (String key : parms.stringPropertyNames()) {
678 String value = parms.getProperty(key);
679 LOG.info("The SLI parameter in " + key + " is: " + value);
682 // Call SLI sync method
685 if (A1AdapterClient.hasGraph("A1-ADAPTER-API", svcOperation , null, "sync"))
687 LOG.info( "A1AdapterClient has a Directed Graph for '" + svcOperation + "'");
690 A1AdapterClient.execute("A1-ADAPTER-API", svcOperation, null, "sync", serviceDataBuilder, parms);
694 LOG.error("Caught exception executing service logic for "+ svcOperation, e);
695 serviceDataBuilder.setResponseCode("500");
698 LOG.error("No service logic active for A1Adapter: '" + svcOperation + "'");
699 serviceDataBuilder.setResponseCode("503");
704 LOG.error("Caught exception looking for service logic", e);
705 serviceDataBuilder.setResponseCode("500");
708 String errorCode = serviceDataBuilder.getResponseCode();
710 if (!("0".equals(errorCode) || "200".equals(errorCode))) {
711 LOG.error("Returned FAILED for "+svcOperation+" error code: '" + errorCode + "'");
713 LOG.info("Returned SUCCESS for "+svcOperation+" ");
714 serviceDataBuilder.setResponseCode("A1 Adapter Executed for CreatePolicyInstance. " );
717 RpcResult<CreatePolicyInstanceOutput> rpcResult =
718 RpcResultBuilder.<CreatePolicyInstanceOutput> status(true).withResult(serviceDataBuilder.build()).build();
720 LOG.info("Successful exit from createPolicyInstance ");
722 return Futures.immediateFuture(rpcResult);
727 // RPC getPolicyInstance
730 public ListenableFuture<RpcResult<GetPolicyInstanceOutput>> getPolicyInstance(
731 GetPolicyInstanceInput input) {
732 final String svcOperation = "getPolicyInstance";
734 Properties parms = new Properties();
735 GetPolicyInstanceOutputBuilder serviceDataBuilder = new GetPolicyInstanceOutputBuilder();
737 LOG.info( "Reached RPC getPolicyInstance");
739 LOG.info( svcOperation +" called." );
742 LOG.debug("exiting " +svcOperation+ " because of invalid input");
743 serviceDataBuilder.setResponseCode("Input is null");
744 RpcResult<GetPolicyInstanceOutput> rpcResult =
745 RpcResultBuilder.<GetPolicyInstanceOutput> status(true).withResult(serviceDataBuilder.build()).build();
746 return Futures.immediateFuture(rpcResult);
749 // add input to parms
750 LOG.info("Adding INPUT data for "+svcOperation+" input: " + input);
751 GetPolicyInstanceInputBuilder inputBuilder = new GetPolicyInstanceInputBuilder(input);
752 MdsalHelper.toProperties(parms, inputBuilder.build());
754 LOG.info("Printing SLI parameters to be passed");
756 // iterate properties file to get key-value pairs
757 for (String key : parms.stringPropertyNames()) {
758 String value = parms.getProperty(key);
759 LOG.info("The SLI parameter in " + key + " is: " + value);
762 // Call SLI sync method
765 if (A1AdapterClient.hasGraph("A1-ADAPTER-API", svcOperation , null, "sync"))
767 LOG.info( "A1AdapterClient has a Directed Graph for '" + svcOperation + "'");
770 A1AdapterClient.execute("A1-ADAPTER-API", svcOperation, null, "sync", serviceDataBuilder, parms);
774 LOG.error("Caught exception executing service logic for "+ svcOperation, e);
775 serviceDataBuilder.setResponseCode("500");
778 LOG.error("No service logic active for A1Adapter: '" + svcOperation + "'");
779 serviceDataBuilder.setResponseCode("503");
784 LOG.error("Caught exception looking for service logic", e);
785 serviceDataBuilder.setResponseCode("500");
788 String errorCode = serviceDataBuilder.getResponseCode();
790 if (!("0".equals(errorCode) || "200".equals(errorCode))) {
791 LOG.error("Returned FAILED for "+svcOperation+" error code: '" + errorCode + "'");
793 LOG.info("Returned SUCCESS for "+svcOperation+" ");
794 serviceDataBuilder.setResponseCode("A1 Adapter Executed for GetPolicyInstance. " );
797 RpcResult<GetPolicyInstanceOutput> rpcResult =
798 RpcResultBuilder.<GetPolicyInstanceOutput> status(true).withResult(serviceDataBuilder.build()).build();
800 LOG.info("Successful exit from getPolicyInstance ");
802 return Futures.immediateFuture(rpcResult);
807 // RPC deletePolicyInstance
810 public ListenableFuture<RpcResult<DeletePolicyInstanceOutput>> deletePolicyInstance(
811 DeletePolicyInstanceInput input) {
812 final String svcOperation = "deletePolicyInstance";
814 Properties parms = new Properties();
815 DeletePolicyInstanceOutputBuilder serviceDataBuilder = new DeletePolicyInstanceOutputBuilder();
817 LOG.info( "Reached RPC deletePolicyInstance");
819 LOG.info( svcOperation +" called." );
822 LOG.debug("exiting " +svcOperation+ " because of invalid input");
823 serviceDataBuilder.setResponseCode("Input is null");
824 RpcResult<DeletePolicyInstanceOutput> rpcResult =
825 RpcResultBuilder.<DeletePolicyInstanceOutput> status(true).withResult(serviceDataBuilder.build()).build();
826 return Futures.immediateFuture(rpcResult);
829 // add input to parms
830 LOG.info("Adding INPUT data for "+svcOperation+" input: " + input);
831 DeletePolicyInstanceInputBuilder inputBuilder = new DeletePolicyInstanceInputBuilder(input);
832 MdsalHelper.toProperties(parms, inputBuilder.build());
834 LOG.info("Printing SLI parameters to be passed");
836 // iterate properties file to get key-value pairs
837 for (String key : parms.stringPropertyNames()) {
838 String value = parms.getProperty(key);
839 LOG.info("The SLI parameter in " + key + " is: " + value);
842 // Call SLI sync method
845 if (A1AdapterClient.hasGraph("A1-ADAPTER-API", svcOperation , null, "sync"))
847 LOG.info( "A1AdapterClient has a Directed Graph for '" + svcOperation + "'");
850 A1AdapterClient.execute("A1-ADAPTER-API", svcOperation, null, "sync", serviceDataBuilder, parms);
854 LOG.error("Caught exception executing service logic for "+ svcOperation, e);
855 serviceDataBuilder.setResponseCode("500");
858 LOG.error("No service logic active for A1Adapter: '" + svcOperation + "'");
859 serviceDataBuilder.setResponseCode("503");
864 LOG.error("Caught exception looking for service logic", e);
865 serviceDataBuilder.setResponseCode("500");
868 String errorCode = serviceDataBuilder.getResponseCode();
870 if (!("0".equals(errorCode) || "200".equals(errorCode))) {
871 LOG.error("Returned FAILED for "+svcOperation+" error code: '" + errorCode + "'");
873 LOG.info("Returned SUCCESS for "+svcOperation+" ");
874 serviceDataBuilder.setResponseCode("A1 Adapter Executed for DeletePolicyInstance. ");
877 RpcResult<DeletePolicyInstanceOutput> rpcResult =
878 RpcResultBuilder.<DeletePolicyInstanceOutput> status(true).withResult(serviceDataBuilder.build()).build();
880 LOG.info("Successful exit from deletePolicyInstance ");
882 return Futures.immediateFuture(rpcResult);
890 public ListenableFuture<RpcResult<GetStatusOutput>> getStatus(
891 GetStatusInput input) {
892 final String svcOperation = "getStatus";
894 Properties parms = new Properties();
895 GetStatusOutputBuilder serviceDataBuilder = new GetStatusOutputBuilder();
897 LOG.info( "Reached RPC getStatus");
899 LOG.info( svcOperation +" called." );
902 LOG.debug("exiting " +svcOperation+ " because of invalid input");
903 serviceDataBuilder.setResponseCode("Input is null");
904 RpcResult<GetStatusOutput> rpcResult =
905 RpcResultBuilder.<GetStatusOutput> status(true).withResult(serviceDataBuilder.build()).build();
906 return Futures.immediateFuture(rpcResult);
909 // add input to parms
910 LOG.info("Adding INPUT data for "+svcOperation+" input: " + input);
911 GetStatusInputBuilder inputBuilder = new GetStatusInputBuilder(input);
912 MdsalHelper.toProperties(parms, inputBuilder.build());
914 LOG.info("Printing SLI parameters to be passed");
916 // iterate properties file to get key-value pairs
917 for (String key : parms.stringPropertyNames()) {
918 String value = parms.getProperty(key);
919 LOG.info("The SLI parameter in " + key + " is: " + value);
922 // Call SLI sync method
925 if (A1AdapterClient.hasGraph("A1-ADAPTER-API", svcOperation , null, "sync"))
927 LOG.info( "A1AdapterClient has a Directed Graph for '" + svcOperation + "'");
930 A1AdapterClient.execute("A1-ADAPTER-API", svcOperation, null, "sync", serviceDataBuilder, parms);
934 LOG.error("Caught exception executing service logic for "+ svcOperation, e);
935 serviceDataBuilder.setResponseCode("500");
938 LOG.error("No service logic active for A1Adapter: '" + svcOperation + "'");
939 serviceDataBuilder.setResponseCode("503");
944 LOG.error("Caught exception looking for service logic", e);
945 serviceDataBuilder.setResponseCode("500");
948 String errorCode = serviceDataBuilder.getResponseCode();
950 if (!("0".equals(errorCode) || "200".equals(errorCode))) {
951 LOG.error("Returned FAILED for "+svcOperation+" error code: '" + errorCode + "'");
953 LOG.info("Returned SUCCESS for "+svcOperation+" ");
954 serviceDataBuilder.setResponseCode("A1 Adapter Executed for GetStatus. " );
957 RpcResult<GetStatusOutput> rpcResult =
958 RpcResultBuilder.<GetStatusOutput> status(true).withResult(serviceDataBuilder.build()).build();
960 LOG.info("Successful exit from getStatus ");
962 return Futures.immediateFuture(rpcResult);