2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights
7 * Modifications Copyright (C) 2020 Nordix Foundation.
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
23 package org.onap.ccsdk.features.sdnr.northbound.a1Adapter;
25 import com.google.common.util.concurrent.Futures;
26 import com.google.common.util.concurrent.ListenableFuture;
27 import java.util.Properties;
28 import java.util.concurrent.ExecutorService;
29 import java.util.concurrent.Executors;
30 import org.onap.ccsdk.sli.core.sli.provider.MdsalHelper;
31 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
32 import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
33 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
34 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
35 import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev191212.A1ADAPTERAPIService;
36 import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev191212.CreatePolicyInstanceInput;
37 import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev191212.CreatePolicyInstanceInputBuilder;
38 import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev191212.CreatePolicyInstanceOutput;
39 import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev191212.CreatePolicyInstanceOutputBuilder;
40 import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev191212.CreatePolicyTypeInput;
41 import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev191212.CreatePolicyTypeInputBuilder;
42 import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev191212.CreatePolicyTypeOutput;
43 import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev191212.CreatePolicyTypeOutputBuilder;
44 import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev191212.DeletePolicyInstanceInput;
45 import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev191212.DeletePolicyInstanceInputBuilder;
46 import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev191212.DeletePolicyInstanceOutput;
47 import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev191212.DeletePolicyInstanceOutputBuilder;
48 import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev191212.DeletePolicyTypeInput;
49 import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev191212.DeletePolicyTypeInputBuilder;
50 import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev191212.DeletePolicyTypeOutput;
51 import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev191212.DeletePolicyTypeOutputBuilder;
52 import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev191212.GetHealthCheckInput;
53 import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev191212.GetHealthCheckInputBuilder;
54 import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev191212.GetHealthCheckOutput;
55 import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev191212.GetHealthCheckOutputBuilder;
56 import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev191212.GetNearRTRICsInput;
57 import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev191212.GetNearRTRICsInputBuilder;
58 import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev191212.GetNearRTRICsOutput;
59 import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev191212.GetNearRTRICsOutputBuilder;
60 import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev191212.GetPolicyInstanceInput;
61 import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev191212.GetPolicyInstanceInputBuilder;
62 import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev191212.GetPolicyInstanceOutput;
63 import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev191212.GetPolicyInstanceOutputBuilder;
64 import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev191212.GetPolicyInstancesInput;
65 import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev191212.GetPolicyInstancesInputBuilder;
66 import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev191212.GetPolicyInstancesOutput;
67 import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev191212.GetPolicyInstancesOutputBuilder;
68 import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev191212.GetPolicyTypeInput;
69 import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev191212.GetPolicyTypeInputBuilder;
70 import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev191212.GetPolicyTypeOutput;
71 import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev191212.GetPolicyTypeOutputBuilder;
72 import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev191212.GetPolicyTypesInput;
73 import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev191212.GetPolicyTypesInputBuilder;
74 import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev191212.GetPolicyTypesOutput;
75 import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev191212.GetPolicyTypesOutputBuilder;
76 import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev191212.GetStatusInput;
77 import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev191212.GetStatusInputBuilder;
78 import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev191212.GetStatusOutput;
79 import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev191212.GetStatusOutputBuilder;
80 import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev191212.NotifyPolicyEnforcementUpdateInput;
81 import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev191212.NotifyPolicyEnforcementUpdateInputBuilder;
82 import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev191212.NotifyPolicyEnforcementUpdateOutput;
83 import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev191212.NotifyPolicyEnforcementUpdateOutputBuilder;
84 import org.opendaylight.yangtools.concepts.Builder;
85 import org.opendaylight.yangtools.yang.common.RpcResult;
86 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
87 import org.slf4j.Logger;
88 import org.slf4j.LoggerFactory;
91 * Defines a base implementation for your provider. This class extends from a helper class which
92 * provides storage for the most commonly used components of the MD-SAL. Additionally the base class
93 * provides some basic logging and initialization / clean up methods.
96 public class A1AdapterProvider implements AutoCloseable, A1ADAPTERAPIService {
98 private static final Logger LOG = LoggerFactory.getLogger(A1AdapterProvider.class);
100 private static final String APPLICATION_NAME = "a1Adapter-api";
101 private static final String GET_NEARRT_RICS = "getNearRT-RICs";
102 private static final String GET_HEALTH_CHECK = "getHealthCheck";
103 private static final String GET_POLICY_TYPES = "getPolicyTypes";
104 private static final String CREATE_POLICY_TYPE = "createPolicyType";
105 private static final String GET_POLICY_TYPE = "getPolicyType";
106 private static final String DELETE_POLICY_TYPE = "deletePolicyType";
107 private static final String GET_POLICY_INSTANCES = "getPolicyInstances";
108 private static final String CREATE_POLICY_INSTANCES = "createPolicyInstance";
109 private static final String GET_POLICY_INSTANCE = "getPolicyInstance";
110 private static final String DELETE_POLICY_INSTANCE = "deletePolicyInstance";
111 private static final String GET_STATUS = "getStatus";
112 private static final String NOTIFICATION_ENFORECEMENT = "notifyPolicyEnforcementUpdate";
114 private final ExecutorService executor;
115 protected DataBroker dataBroker;
116 protected NotificationPublishService notificationService;
117 protected RpcProviderRegistry rpcRegistry;
118 protected BindingAwareBroker.RpcRegistration<A1ADAPTERAPIService> rpcRegistration;
119 private final A1AdapterClient A1AdapterClient;
121 public A1AdapterProvider(final DataBroker dataBroker, final NotificationPublishService notificationPublishService,
122 final RpcProviderRegistry rpcProviderRegistry, final A1AdapterClient A1AdapterClient) {
124 LOG.info("Creating provider for {}", APPLICATION_NAME);
125 executor = Executors.newFixedThreadPool(1);
126 this.dataBroker = dataBroker;
127 this.notificationService = notificationPublishService;
128 this.rpcRegistry = rpcProviderRegistry;
129 this.A1AdapterClient = A1AdapterClient;
133 public void initialize() {
134 LOG.info("Initializing provider for {}", APPLICATION_NAME);
135 rpcRegistration = rpcRegistry.addRpcImplementation(A1ADAPTERAPIService.class, this);
136 LOG.info("Initialization complete for {}", APPLICATION_NAME);
139 protected void initializeChild() {
140 // Override if you have custom initialization intelligence
144 public void close() throws Exception {
145 LOG.info("Closing provider for {}", APPLICATION_NAME);
147 rpcRegistration.close();
148 LOG.info("Successfully closed provider for {}", APPLICATION_NAME);
151 // RPC getNearRT-RICs
154 public ListenableFuture<RpcResult<GetNearRTRICsOutput>> getNearRTRICs(GetNearRTRICsInput input) {
155 final String svcOperation = "getNearRT-RICs";
157 Properties parms = new Properties();
158 GetNearRTRICsOutputBuilder serviceDataBuilder = (GetNearRTRICsOutputBuilder) getServiceData(GET_NEARRT_RICS);
160 LOG.info("Reached RPC getNearRT-RICs");
162 LOG.info(svcOperation + " called.");
165 LOG.debug("exiting " + svcOperation + " because of invalid input");
166 serviceDataBuilder.setResponseCode("Input is null");
167 RpcResult<GetNearRTRICsOutput> rpcResult =
168 RpcResultBuilder.<GetNearRTRICsOutput>status(true).withResult(serviceDataBuilder.build()).build();
169 return Futures.immediateFuture(rpcResult);
172 // add input to parms
173 LOG.info("Adding INPUT data for " + svcOperation + " input: " + input);
174 GetNearRTRICsInputBuilder inputBuilder = new GetNearRTRICsInputBuilder(input);
175 MdsalHelper.toProperties(parms, inputBuilder.build());
177 LOG.info("Printing SLI parameters to be passed");
179 // iterate properties file to get key-value pairs
180 for (String key : parms.stringPropertyNames()) {
181 String value = parms.getProperty(key);
182 LOG.info("The SLI parameter in " + key + " is: " + value);
185 // Call SLI sync method
187 if (A1AdapterClient.hasGraph("A1-ADAPTER-API", svcOperation, null, "sync")) {
188 LOG.info("A1AdapterClient has a Directed Graph for '" + svcOperation + "'");
190 A1AdapterClient.execute("A1-ADAPTER-API", svcOperation, null, "sync", serviceDataBuilder, parms);
191 } catch (Exception e) {
192 LOG.error("Caught exception executing service logic for " + svcOperation, e);
193 serviceDataBuilder.setResponseCode("500");
196 LOG.error("No service logic active for A1Adapter: '" + svcOperation + "'");
197 serviceDataBuilder.setResponseCode("503");
199 } catch (Exception e) {
200 LOG.error("Caught exception looking for service logic", e);
201 serviceDataBuilder.setResponseCode("500");
204 String errorCode = serviceDataBuilder.getResponseCode();
206 if (!("0".equals(errorCode) || "200".equals(errorCode))) {
207 LOG.error("Returned FAILED for " + svcOperation + " error code: '" + errorCode + "'");
209 LOG.info("Returned SUCCESS for " + svcOperation + " ");
210 serviceDataBuilder.setResponseMessage("A1 Adapter Executed for GetNearRTRICs ");
213 RpcResult<GetNearRTRICsOutput> rpcResult =
214 RpcResultBuilder.<GetNearRTRICsOutput>status(true).withResult(serviceDataBuilder.build()).build();
216 LOG.info("Successful exit from getNearRT-RICs ");
218 return Futures.immediateFuture(rpcResult);
221 // RPC getHealthCheck
224 public ListenableFuture<RpcResult<GetHealthCheckOutput>> getHealthCheck(GetHealthCheckInput input) {
225 final String svcOperation = "getHealthCheck";
227 Properties parms = new Properties();
228 GetHealthCheckOutputBuilder serviceDataBuilder = (GetHealthCheckOutputBuilder) getServiceData(GET_HEALTH_CHECK);
230 LOG.info("Reached RPC getHealthCheck");
232 LOG.info(svcOperation + " called.");
235 LOG.debug("exiting " + svcOperation + " because of invalid input");
236 serviceDataBuilder.setResponseCode("Input is null");
237 RpcResult<GetHealthCheckOutput> rpcResult =
238 RpcResultBuilder.<GetHealthCheckOutput>status(true).withResult(serviceDataBuilder.build()).build();
239 return Futures.immediateFuture(rpcResult);
242 // add input to parms
243 LOG.info("Adding INPUT data for " + svcOperation + " input: " + input);
244 GetHealthCheckInputBuilder inputBuilder = new GetHealthCheckInputBuilder(input);
245 MdsalHelper.toProperties(parms, inputBuilder.build());
247 LOG.info("Printing SLI parameters to be passed");
249 // iterate properties file to get key-value pairs
250 for (String key : parms.stringPropertyNames()) {
251 String value = parms.getProperty(key);
252 LOG.info("The SLI parameter in " + key + " is: " + value);
255 // Call SLI sync method
257 if (A1AdapterClient.hasGraph("A1-ADAPTER-API", svcOperation, null, "sync")) {
258 LOG.info("A1AdapterClient has a Directed Graph for '" + svcOperation + "'");
260 A1AdapterClient.execute("A1-ADAPTER-API", svcOperation, null, "sync", serviceDataBuilder, parms);
261 } catch (Exception e) {
262 LOG.error("Caught exception executing service logic for " + svcOperation, e);
263 serviceDataBuilder.setResponseCode("500");
266 LOG.error("No service logic active for A1Adapter: '" + svcOperation + "'");
267 serviceDataBuilder.setResponseCode("503");
269 } catch (Exception e) {
270 LOG.error("Caught exception looking for service logic", e);
271 serviceDataBuilder.setResponseCode("500");
274 String errorCode = serviceDataBuilder.getResponseCode();
276 if (!("0".equals(errorCode) || "200".equals(errorCode))) {
277 LOG.error("Returned FAILED for " + svcOperation + " error code: '" + errorCode + "'");
279 LOG.info("Returned SUCCESS for " + svcOperation + " ");
280 serviceDataBuilder.setResponseMessage("A1 Adapter Executed for GetHealthCheck. ");
283 RpcResult<GetHealthCheckOutput> rpcResult =
284 RpcResultBuilder.<GetHealthCheckOutput>status(true).withResult(serviceDataBuilder.build()).build();
286 LOG.info("Successful exit from getHealthCheck ");
288 return Futures.immediateFuture(rpcResult);
291 // RPC getPolicyTypes
294 public ListenableFuture<RpcResult<GetPolicyTypesOutput>> getPolicyTypes(GetPolicyTypesInput input) {
295 final String svcOperation = "getPolicyTypes";
297 Properties parms = new Properties();
298 GetPolicyTypesOutputBuilder serviceDataBuilder = (GetPolicyTypesOutputBuilder) getServiceData(GET_POLICY_TYPES);
300 LOG.info("Reached RPC getPolicyTypes");
302 LOG.info(svcOperation + " called.");
305 LOG.debug("exiting " + svcOperation + " because of invalid input");
306 serviceDataBuilder.setResponseCode("Input is null");
307 RpcResult<GetPolicyTypesOutput> rpcResult =
308 RpcResultBuilder.<GetPolicyTypesOutput>status(true).withResult(serviceDataBuilder.build()).build();
309 return Futures.immediateFuture(rpcResult);
312 // add input to parms
313 LOG.info("Adding INPUT data for " + svcOperation + " input: " + input);
314 GetPolicyTypesInputBuilder inputBuilder = new GetPolicyTypesInputBuilder(input);
315 MdsalHelper.toProperties(parms, inputBuilder.build());
317 LOG.info("Printing SLI parameters to be passed");
319 // iterate properties file to get key-value pairs
320 for (String key : parms.stringPropertyNames()) {
321 String value = parms.getProperty(key);
322 LOG.info("The SLI parameter in " + key + " is: " + value);
325 // Call SLI sync method
327 if (A1AdapterClient.hasGraph("A1-ADAPTER-API", svcOperation, null, "sync")) {
328 LOG.info("A1AdapterClient has a Directed Graph for '" + svcOperation + "'");
330 A1AdapterClient.execute("A1-ADAPTER-API", svcOperation, null, "sync", serviceDataBuilder, parms);
331 } catch (Exception e) {
332 LOG.error("Caught exception executing service logic for " + svcOperation, e);
333 serviceDataBuilder.setResponseCode("500");
336 LOG.error("No service logic active for A1Adapter: '" + svcOperation + "'");
337 serviceDataBuilder.setResponseCode("503");
339 } catch (Exception e) {
340 LOG.error("Caught exception looking for service logic", e);
341 serviceDataBuilder.setResponseCode("500");
344 String errorCode = serviceDataBuilder.getResponseCode();
346 if (!("0".equals(errorCode) || "200".equals(errorCode))) {
347 LOG.error("Returned FAILED for " + svcOperation + " error code: '" + errorCode + "'");
349 LOG.info("Returned SUCCESS for " + svcOperation + " ");
350 serviceDataBuilder.setResponseMessage("A1 Adapter Executed for GetPolicyTypes ");
353 RpcResult<GetPolicyTypesOutput> rpcResult =
354 RpcResultBuilder.<GetPolicyTypesOutput>status(true).withResult(serviceDataBuilder.build()).build();
356 LOG.info("Successful exit from getPolicyTypes ");
358 return Futures.immediateFuture(rpcResult);
361 // RPC createPolicyType
364 public ListenableFuture<RpcResult<CreatePolicyTypeOutput>> createPolicyType(CreatePolicyTypeInput input) {
365 final String svcOperation = "createPolicyType";
367 Properties parms = new Properties();
368 CreatePolicyTypeOutputBuilder serviceDataBuilder =
369 (CreatePolicyTypeOutputBuilder) getServiceData(CREATE_POLICY_TYPE);
371 LOG.info("Reached RPC createPolicyType");
373 LOG.info(svcOperation + " called.");
376 LOG.debug("exiting " + svcOperation + " because of invalid input");
377 serviceDataBuilder.setResponseCode("Input is null");
378 RpcResult<CreatePolicyTypeOutput> rpcResult = RpcResultBuilder.<CreatePolicyTypeOutput>status(true)
379 .withResult(serviceDataBuilder.build()).build();
380 return Futures.immediateFuture(rpcResult);
383 // add input to parms
384 LOG.info("Adding INPUT data for " + svcOperation + " input: " + input);
385 CreatePolicyTypeInputBuilder inputBuilder = new CreatePolicyTypeInputBuilder(input);
386 MdsalHelper.toProperties(parms, inputBuilder.build());
388 LOG.info("Printing SLI parameters to be passed");
390 // iterate properties file to get key-value pairs
391 for (String key : parms.stringPropertyNames()) {
392 String value = parms.getProperty(key);
393 LOG.info("The SLI parameter in " + key + " is: " + value);
396 // Call SLI sync method
398 if (A1AdapterClient.hasGraph("A1-ADAPTER-API", svcOperation, null, "sync")) {
399 LOG.info("A1AdapterClient has a Directed Graph for '" + svcOperation + "'");
401 A1AdapterClient.execute("A1-ADAPTER-API", svcOperation, null, "sync", serviceDataBuilder, parms);
402 } catch (Exception e) {
403 LOG.error("Caught exception executing service logic for " + svcOperation, e);
404 serviceDataBuilder.setResponseCode("500");
407 LOG.error("No service logic active for A1Adapter: '" + svcOperation + "'");
408 serviceDataBuilder.setResponseCode("503");
410 } catch (Exception e) {
411 LOG.error("Caught exception looking for service logic", e);
412 serviceDataBuilder.setResponseCode("500");
415 String errorCode = serviceDataBuilder.getResponseCode();
417 if (!("0".equals(errorCode) || "200".equals(errorCode))) {
418 LOG.error("Returned FAILED for " + svcOperation + " error code: '" + errorCode + "'");
420 LOG.info("Returned SUCCESS for " + svcOperation + " ");
421 serviceDataBuilder.setResponseMessage("A1 Adapter Executed for CreatePolicyType");
424 RpcResult<CreatePolicyTypeOutput> rpcResult =
425 RpcResultBuilder.<CreatePolicyTypeOutput>status(true).withResult(serviceDataBuilder.build()).build();
427 LOG.info("Successful exit from createPolicyType ");
429 return Futures.immediateFuture(rpcResult);
435 public ListenableFuture<RpcResult<GetPolicyTypeOutput>> getPolicyType(GetPolicyTypeInput input) {
436 final String svcOperation = "getPolicyType";
438 Properties parms = new Properties();
439 GetPolicyTypeOutputBuilder serviceDataBuilder = (GetPolicyTypeOutputBuilder) getServiceData(GET_POLICY_TYPE);
441 LOG.info("Reached RPC getPolicyType");
443 LOG.info(svcOperation + " called.");
446 LOG.debug("exiting " + svcOperation + " because of invalid input");
447 serviceDataBuilder.setResponseCode("Input is null");
448 RpcResult<GetPolicyTypeOutput> rpcResult =
449 RpcResultBuilder.<GetPolicyTypeOutput>status(true).withResult(serviceDataBuilder.build()).build();
450 return Futures.immediateFuture(rpcResult);
453 // add input to parms
454 LOG.info("Adding INPUT data for " + svcOperation + " input: " + input);
455 GetPolicyTypeInputBuilder inputBuilder = new GetPolicyTypeInputBuilder(input);
456 MdsalHelper.toProperties(parms, inputBuilder.build());
458 LOG.info("Printing SLI parameters to be passed");
460 // iterate properties file to get key-value pairs
461 for (String key : parms.stringPropertyNames()) {
462 String value = parms.getProperty(key);
463 LOG.info("The SLI parameter in " + key + " is: " + value);
466 // Call SLI sync method
468 if (A1AdapterClient.hasGraph("A1-ADAPTER-API", svcOperation, null, "sync")) {
469 LOG.info("A1AdapterClient has a Directed Graph for '" + svcOperation + "'");
471 A1AdapterClient.execute("A1-ADAPTER-API", svcOperation, null, "sync", serviceDataBuilder, parms);
472 } catch (Exception e) {
473 LOG.error("Caught exception executing service logic for " + svcOperation, e);
474 serviceDataBuilder.setResponseCode("500");
477 LOG.error("No service logic active for A1Adapter: '" + svcOperation + "'");
478 serviceDataBuilder.setResponseCode("503");
480 } catch (Exception e) {
481 LOG.error("Caught exception looking for service logic", e);
482 serviceDataBuilder.setResponseCode("500");
485 String errorCode = serviceDataBuilder.getResponseCode();
487 if (!("0".equals(errorCode) || "200".equals(errorCode))) {
488 LOG.error("Returned FAILED for " + svcOperation + " error code: '" + errorCode + "'");
490 LOG.info("Returned SUCCESS for " + svcOperation + " ");
491 serviceDataBuilder.setResponseMessage("A1 Adapter Executed for GetPolicyType. ");
494 RpcResult<GetPolicyTypeOutput> rpcResult =
495 RpcResultBuilder.<GetPolicyTypeOutput>status(true).withResult(serviceDataBuilder.build()).build();
497 LOG.info("Successful exit from getPolicyType ");
499 return Futures.immediateFuture(rpcResult);
502 // RPC deletePolicyType
505 public ListenableFuture<RpcResult<DeletePolicyTypeOutput>> deletePolicyType(DeletePolicyTypeInput input) {
506 final String svcOperation = "deletePolicyType";
508 Properties parms = new Properties();
509 DeletePolicyTypeOutputBuilder serviceDataBuilder =
510 (DeletePolicyTypeOutputBuilder) getServiceData(DELETE_POLICY_TYPE);
512 LOG.info("Reached RPC deletePolicyType");
514 LOG.info(svcOperation + " called.");
517 LOG.debug("exiting " + svcOperation + " because of invalid input");
518 serviceDataBuilder.setResponseCode("Input is null");
519 RpcResult<DeletePolicyTypeOutput> rpcResult = RpcResultBuilder.<DeletePolicyTypeOutput>status(true)
520 .withResult(serviceDataBuilder.build()).build();
521 return Futures.immediateFuture(rpcResult);
524 // add input to parms
525 LOG.info("Adding INPUT data for " + svcOperation + " input: " + input);
526 DeletePolicyTypeInputBuilder inputBuilder = new DeletePolicyTypeInputBuilder(input);
527 MdsalHelper.toProperties(parms, inputBuilder.build());
529 LOG.info("Printing SLI parameters to be passed");
531 // iterate properties file to get key-value pairs
532 for (String key : parms.stringPropertyNames()) {
533 String value = parms.getProperty(key);
534 LOG.info("The SLI parameter in " + key + " is: " + value);
537 // Call SLI sync method
539 if (A1AdapterClient.hasGraph("A1-ADAPTER-API", svcOperation, null, "sync")) {
540 LOG.info("A1AdapterClient has a Directed Graph for '" + svcOperation + "'");
542 A1AdapterClient.execute("A1-ADAPTER-API", svcOperation, null, "sync", serviceDataBuilder, parms);
543 } catch (Exception e) {
544 LOG.error("Caught exception executing service logic for " + svcOperation, e);
545 serviceDataBuilder.setResponseCode("500");
548 LOG.error("No service logic active for A1Adapter: '" + svcOperation + "'");
549 serviceDataBuilder.setResponseCode("503");
551 } catch (Exception e) {
552 LOG.error("Caught exception looking for service logic", e);
553 serviceDataBuilder.setResponseCode("500");
556 String errorCode = serviceDataBuilder.getResponseCode();
558 if (!("0".equals(errorCode) || "200".equals(errorCode))) {
559 LOG.error("Returned FAILED for " + svcOperation + " error code: '" + errorCode + "'");
561 LOG.info("Returned SUCCESS for " + svcOperation + " ");
562 serviceDataBuilder.setResponseMessage("A1 Adapter Executed for DeletePolicyType ");
565 RpcResult<DeletePolicyTypeOutput> rpcResult =
566 RpcResultBuilder.<DeletePolicyTypeOutput>status(true).withResult(serviceDataBuilder.build()).build();
568 LOG.info("Successful exit from deletePolicyType ");
570 return Futures.immediateFuture(rpcResult);
573 // RPC getPolicyInstances
576 public ListenableFuture<RpcResult<GetPolicyInstancesOutput>> getPolicyInstances(GetPolicyInstancesInput input) {
577 final String svcOperation = "getPolicyInstances";
579 Properties parms = new Properties();
580 GetPolicyInstancesOutputBuilder serviceDataBuilder =
581 (GetPolicyInstancesOutputBuilder) getServiceData(GET_POLICY_INSTANCES);
583 LOG.info("Reached RPC getPolicyInstances");
585 LOG.info(svcOperation + " called.");
588 LOG.debug("exiting " + svcOperation + " because of invalid input");
589 serviceDataBuilder.setResponseCode("Input is null");
590 RpcResult<GetPolicyInstancesOutput> rpcResult = RpcResultBuilder.<GetPolicyInstancesOutput>status(true)
591 .withResult(serviceDataBuilder.build()).build();
592 return Futures.immediateFuture(rpcResult);
595 // add input to parms
596 LOG.info("Adding INPUT data for " + svcOperation + " input: " + input);
597 GetPolicyInstancesInputBuilder inputBuilder = new GetPolicyInstancesInputBuilder(input);
598 MdsalHelper.toProperties(parms, inputBuilder.build());
600 LOG.info("Printing SLI parameters to be passed");
602 // iterate properties file to get key-value pairs
603 for (String key : parms.stringPropertyNames()) {
604 String value = parms.getProperty(key);
605 LOG.info("The SLI parameter in " + key + " is: " + value);
608 // Call SLI sync method
610 if (A1AdapterClient.hasGraph("A1-ADAPTER-API", svcOperation, null, "sync")) {
611 LOG.info("A1AdapterClient has a Directed Graph for '" + svcOperation + "'");
613 A1AdapterClient.execute("A1-ADAPTER-API", svcOperation, null, "sync", serviceDataBuilder, parms);
614 } catch (Exception e) {
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");
622 } catch (Exception e) {
623 LOG.error("Caught exception looking for service logic", e);
624 serviceDataBuilder.setResponseCode("500");
627 String errorCode = serviceDataBuilder.getResponseCode();
629 if (!("0".equals(errorCode) || "200".equals(errorCode))) {
630 LOG.error("Returned FAILED for " + svcOperation + " error code: '" + errorCode + "'");
632 LOG.info("Returned SUCCESS for " + svcOperation + " ");
633 serviceDataBuilder.setResponseMessage("A1 Adapter Executed for GetPolicyInstances ");
636 RpcResult<GetPolicyInstancesOutput> rpcResult =
637 RpcResultBuilder.<GetPolicyInstancesOutput>status(true).withResult(serviceDataBuilder.build()).build();
639 LOG.info("Successful exit from getPolicyInstances ");
641 return Futures.immediateFuture(rpcResult);
645 // RPC createPolicyInstance
648 public ListenableFuture<RpcResult<CreatePolicyInstanceOutput>> createPolicyInstance(
649 CreatePolicyInstanceInput input) {
650 final String svcOperation = "createPolicyInstance";
652 Properties parms = new Properties();
653 CreatePolicyInstanceOutputBuilder serviceDataBuilder =
654 (CreatePolicyInstanceOutputBuilder) getServiceData(CREATE_POLICY_INSTANCES);
656 LOG.info("Reached RPC createPolicyInstance");
658 LOG.info(svcOperation + " called.");
661 LOG.debug("exiting " + svcOperation + " because of invalid input");
662 serviceDataBuilder.setResponseCode("Input is null");
663 RpcResult<CreatePolicyInstanceOutput> rpcResult = RpcResultBuilder.<CreatePolicyInstanceOutput>status(true)
664 .withResult(serviceDataBuilder.build()).build();
665 return Futures.immediateFuture(rpcResult);
668 // add input to parms
669 LOG.info("Adding INPUT data for " + svcOperation + " input: " + input);
670 CreatePolicyInstanceInputBuilder inputBuilder = new CreatePolicyInstanceInputBuilder(input);
671 MdsalHelper.toProperties(parms, inputBuilder.build());
673 LOG.info("Printing SLI parameters to be passed");
675 // iterate properties file to get key-value pairs
676 for (String key : parms.stringPropertyNames()) {
677 String value = parms.getProperty(key);
678 LOG.info("The SLI parameter in " + key + " is: " + value);
681 // Call SLI sync method
683 if (A1AdapterClient.hasGraph("A1-ADAPTER-API", svcOperation, null, "sync")) {
684 LOG.info("A1AdapterClient has a Directed Graph for '" + svcOperation + "'");
686 A1AdapterClient.execute("A1-ADAPTER-API", svcOperation, null, "sync", serviceDataBuilder, parms);
687 } catch (Exception e) {
688 LOG.error("Caught exception executing service logic for " + svcOperation, e);
689 serviceDataBuilder.setResponseCode("500");
692 LOG.error("No service logic active for A1Adapter: '" + svcOperation + "'");
693 serviceDataBuilder.setResponseCode("503");
695 } catch (Exception e) {
696 LOG.error("Caught exception looking for service logic", e);
697 serviceDataBuilder.setResponseCode("500");
700 String errorCode = serviceDataBuilder.getResponseCode();
702 if (!("0".equals(errorCode) || "200".equals(errorCode))) {
703 LOG.error("Returned FAILED for " + svcOperation + " error code: '" + errorCode + "'");
705 LOG.info("Returned SUCCESS for " + svcOperation + " ");
706 serviceDataBuilder.setResponseMessage("A1 Adapter Executed for CreatePolicyInstance. ");
709 RpcResult<CreatePolicyInstanceOutput> rpcResult = RpcResultBuilder.<CreatePolicyInstanceOutput>status(true)
710 .withResult(serviceDataBuilder.build()).build();
712 LOG.info("Successful exit from createPolicyInstance ");
714 return Futures.immediateFuture(rpcResult);
719 // RPC getPolicyInstance
722 public ListenableFuture<RpcResult<GetPolicyInstanceOutput>> getPolicyInstance(GetPolicyInstanceInput input) {
723 final String svcOperation = "getPolicyInstance";
725 Properties parms = new Properties();
726 GetPolicyInstanceOutputBuilder serviceDataBuilder =
727 (GetPolicyInstanceOutputBuilder) getServiceData(GET_POLICY_INSTANCE);
729 LOG.info("Reached RPC getPolicyInstance");
731 LOG.info(svcOperation + " called.");
734 LOG.debug("exiting " + svcOperation + " because of invalid input");
735 serviceDataBuilder.setResponseCode("Input is null");
736 RpcResult<GetPolicyInstanceOutput> rpcResult = RpcResultBuilder.<GetPolicyInstanceOutput>status(true)
737 .withResult(serviceDataBuilder.build()).build();
738 return Futures.immediateFuture(rpcResult);
741 // add input to parms
742 LOG.info("Adding INPUT data for " + svcOperation + " input: " + input);
743 GetPolicyInstanceInputBuilder inputBuilder = new GetPolicyInstanceInputBuilder(input);
744 MdsalHelper.toProperties(parms, inputBuilder.build());
746 LOG.info("Printing SLI parameters to be passed");
748 // iterate properties file to get key-value pairs
749 for (String key : parms.stringPropertyNames()) {
750 String value = parms.getProperty(key);
751 LOG.info("The SLI parameter in " + key + " is: " + value);
754 // Call SLI sync method
756 if (A1AdapterClient.hasGraph("A1-ADAPTER-API", svcOperation, null, "sync")) {
757 LOG.info("A1AdapterClient has a Directed Graph for '" + svcOperation + "'");
759 A1AdapterClient.execute("A1-ADAPTER-API", svcOperation, null, "sync", serviceDataBuilder, parms);
760 } catch (Exception e) {
761 LOG.error("Caught exception executing service logic for " + svcOperation, e);
762 serviceDataBuilder.setResponseCode("500");
765 LOG.error("No service logic active for A1Adapter: '" + svcOperation + "'");
766 serviceDataBuilder.setResponseCode("503");
768 } catch (Exception e) {
769 LOG.error("Caught exception looking for service logic", e);
770 serviceDataBuilder.setResponseCode("500");
773 String errorCode = serviceDataBuilder.getResponseCode();
775 if (!("0".equals(errorCode) || "200".equals(errorCode))) {
776 LOG.error("Returned FAILED for " + svcOperation + " error code: '" + errorCode + "'");
778 LOG.info("Returned SUCCESS for " + svcOperation + " ");
779 serviceDataBuilder.setResponseMessage("A1 Adapter Executed for GetPolicyInstance. ");
782 RpcResult<GetPolicyInstanceOutput> rpcResult =
783 RpcResultBuilder.<GetPolicyInstanceOutput>status(true).withResult(serviceDataBuilder.build()).build();
785 LOG.info("Successful exit from getPolicyInstance ");
787 return Futures.immediateFuture(rpcResult);
792 // RPC deletePolicyInstance
795 public ListenableFuture<RpcResult<DeletePolicyInstanceOutput>> deletePolicyInstance(
796 DeletePolicyInstanceInput input) {
797 final String svcOperation = "deletePolicyInstance";
799 Properties parms = new Properties();
800 DeletePolicyInstanceOutputBuilder serviceDataBuilder =
801 (DeletePolicyInstanceOutputBuilder) getServiceData(DELETE_POLICY_INSTANCE);
803 LOG.info("Reached RPC deletePolicyInstance");
805 LOG.info(svcOperation + " called.");
808 LOG.debug("exiting " + svcOperation + " because of invalid input");
809 serviceDataBuilder.setResponseCode("Input is null");
810 RpcResult<DeletePolicyInstanceOutput> rpcResult = RpcResultBuilder.<DeletePolicyInstanceOutput>status(true)
811 .withResult(serviceDataBuilder.build()).build();
812 return Futures.immediateFuture(rpcResult);
815 // add input to parms
816 LOG.info("Adding INPUT data for " + svcOperation + " input: " + input);
817 DeletePolicyInstanceInputBuilder inputBuilder = new DeletePolicyInstanceInputBuilder(input);
818 MdsalHelper.toProperties(parms, inputBuilder.build());
820 LOG.info("Printing SLI parameters to be passed");
822 // iterate properties file to get key-value pairs
823 for (String key : parms.stringPropertyNames()) {
824 String value = parms.getProperty(key);
825 LOG.info("The SLI parameter in " + key + " is: " + value);
828 // Call SLI sync method
830 if (A1AdapterClient.hasGraph("A1-ADAPTER-API", svcOperation, null, "sync")) {
831 LOG.info("A1AdapterClient has a Directed Graph for '" + svcOperation + "'");
833 A1AdapterClient.execute("A1-ADAPTER-API", svcOperation, null, "sync", serviceDataBuilder, parms);
834 } catch (Exception e) {
835 LOG.error("Caught exception executing service logic for " + svcOperation, e);
836 serviceDataBuilder.setResponseCode("500");
839 LOG.error("No service logic active for A1Adapter: '" + svcOperation + "'");
840 serviceDataBuilder.setResponseCode("503");
842 } catch (Exception e) {
843 LOG.error("Caught exception looking for service logic", e);
844 serviceDataBuilder.setResponseCode("500");
847 String errorCode = serviceDataBuilder.getResponseCode();
849 if (!("0".equals(errorCode) || "200".equals(errorCode))) {
850 LOG.error("Returned FAILED for " + svcOperation + " error code: '" + errorCode + "'");
852 LOG.info("Returned SUCCESS for " + svcOperation + " ");
853 serviceDataBuilder.setResponseMessage("A1 Adapter Executed for DeletePolicyInstance. ");
856 RpcResult<DeletePolicyInstanceOutput> rpcResult = RpcResultBuilder.<DeletePolicyInstanceOutput>status(true)
857 .withResult(serviceDataBuilder.build()).build();
859 LOG.info("Successful exit from deletePolicyInstance ");
861 return Futures.immediateFuture(rpcResult);
869 public ListenableFuture<RpcResult<GetStatusOutput>> getStatus(GetStatusInput input) {
870 final String svcOperation = "getStatus";
872 Properties parms = new Properties();
873 GetStatusOutputBuilder serviceDataBuilder = (GetStatusOutputBuilder) getServiceData(GET_STATUS);
875 LOG.info("Reached RPC getStatus");
877 LOG.info(svcOperation + " called.");
880 LOG.debug("exiting " + svcOperation + " because of invalid input");
881 serviceDataBuilder.setResponseCode("Input is null");
882 RpcResult<GetStatusOutput> rpcResult =
883 RpcResultBuilder.<GetStatusOutput>status(true).withResult(serviceDataBuilder.build()).build();
884 return Futures.immediateFuture(rpcResult);
887 // add input to parms
888 LOG.info("Adding INPUT data for " + svcOperation + " input: " + input);
889 GetStatusInputBuilder inputBuilder = new GetStatusInputBuilder(input);
890 MdsalHelper.toProperties(parms, inputBuilder.build());
892 LOG.info("Printing SLI parameters to be passed");
894 // iterate properties file to get key-value pairs
895 for (String key : parms.stringPropertyNames()) {
896 String value = parms.getProperty(key);
897 LOG.info("The SLI parameter in " + key + " is: " + value);
900 // Call SLI sync method
902 if (A1AdapterClient.hasGraph("A1-ADAPTER-API", svcOperation, null, "sync")) {
903 LOG.info("A1AdapterClient has a Directed Graph for '" + svcOperation + "'");
905 A1AdapterClient.execute("A1-ADAPTER-API", svcOperation, null, "sync", serviceDataBuilder, parms);
906 } catch (Exception e) {
907 LOG.error("Caught exception executing service logic for " + svcOperation, e);
908 serviceDataBuilder.setResponseCode("500");
911 LOG.error("No service logic active for A1Adapter: '" + svcOperation + "'");
912 serviceDataBuilder.setResponseCode("503");
914 } catch (Exception e) {
915 LOG.error("Caught exception looking for service logic", e);
916 serviceDataBuilder.setResponseCode("500");
919 String errorCode = serviceDataBuilder.getResponseCode();
921 if (!("0".equals(errorCode) || "200".equals(errorCode))) {
922 LOG.error("Returned FAILED for " + svcOperation + " error code: '" + errorCode + "'");
924 LOG.info("Returned SUCCESS for " + svcOperation + " ");
925 serviceDataBuilder.setResponseMessage("A1 Adapter Executed for GetStatus. ");
928 RpcResult<GetStatusOutput> rpcResult =
929 RpcResultBuilder.<GetStatusOutput>status(true).withResult(serviceDataBuilder.build()).build();
931 LOG.info("Successful exit from getStatus ");
933 return Futures.immediateFuture(rpcResult);
937 // RPC notifyPolicyEnforcementUpdate
940 public ListenableFuture<RpcResult<NotifyPolicyEnforcementUpdateOutput>> notifyPolicyEnforcementUpdate(
941 NotifyPolicyEnforcementUpdateInput input) {
942 final String svcOperation = "notifyPolicyEnforcementUpdate";
944 Properties parms = new Properties();
945 NotifyPolicyEnforcementUpdateOutputBuilder serviceDataBuilder =
946 (NotifyPolicyEnforcementUpdateOutputBuilder) getServiceData(NOTIFICATION_ENFORECEMENT);
948 LOG.info("Reached RPC notifyPolicyEnforcementUpdate");
950 LOG.info(svcOperation + " called.");
953 LOG.debug("exiting " + svcOperation + " because of invalid input");
954 serviceDataBuilder.setResponseCode("Input is null");
955 RpcResult<NotifyPolicyEnforcementUpdateOutput> rpcResult = RpcResultBuilder
956 .<NotifyPolicyEnforcementUpdateOutput>status(true).withResult(serviceDataBuilder.build()).build();
957 return Futures.immediateFuture(rpcResult);
960 // add input to parms
961 LOG.info("Adding INPUT data for " + svcOperation + " input: " + input);
962 NotifyPolicyEnforcementUpdateInputBuilder inputBuilder = new NotifyPolicyEnforcementUpdateInputBuilder(input);
963 MdsalHelper.toProperties(parms, inputBuilder.build());
965 LOG.info("Printing SLI parameters to be passed");
967 // iterate properties file to get key-value pairs
968 for (String key : parms.stringPropertyNames()) {
969 String value = parms.getProperty(key);
970 LOG.info("The SLI parameter in " + key + " is: " + value);
973 // Call SLI sync method
975 if (A1AdapterClient.hasGraph("A1-ADAPTER-API", svcOperation, null, "sync")) {
976 LOG.info("A1AdapterClient has a Directed Graph for '" + svcOperation + "'");
978 A1AdapterClient.execute("A1-ADAPTER-API", svcOperation, null, "sync", serviceDataBuilder, parms);
979 } catch (Exception e) {
980 LOG.error("Caught exception executing service logic for " + svcOperation, e);
981 serviceDataBuilder.setResponseCode("500");
984 LOG.error("No service logic active for A1Adapter: '" + svcOperation + "'");
985 serviceDataBuilder.setResponseCode("503");
987 } catch (Exception e) {
988 LOG.error("Caught exception looking for service logic", e);
989 serviceDataBuilder.setResponseCode("500");
992 String errorCode = serviceDataBuilder.getResponseCode();
994 if (!("0".equals(errorCode) || "200".equals(errorCode))) {
995 LOG.error("Returned FAILED for " + svcOperation + " error code: '" + errorCode + "'");
997 LOG.info("Returned SUCCESS for " + svcOperation + " ");
998 serviceDataBuilder.setResponseMessage("A1 Adapter Executed for notifyPolicyEnforcementUpdate. ");
1001 RpcResult<NotifyPolicyEnforcementUpdateOutput> rpcResult = RpcResultBuilder
1002 .<NotifyPolicyEnforcementUpdateOutput>status(true).withResult(serviceDataBuilder.build()).build();
1004 LOG.info("Successful exit from notifyPolicyEnforcementUpdate ");
1006 return Futures.immediateFuture(rpcResult);
1009 protected Builder<?> getServiceData(String svcOperation) {
1010 switch (svcOperation) {
1011 case GET_NEARRT_RICS:
1012 return new GetNearRTRICsOutputBuilder();
1013 case GET_HEALTH_CHECK:
1014 return new GetHealthCheckOutputBuilder();
1015 case GET_POLICY_TYPES:
1016 return new GetPolicyTypesOutputBuilder();
1017 case CREATE_POLICY_TYPE:
1018 return new CreatePolicyTypeOutputBuilder();
1019 case GET_POLICY_TYPE:
1020 return new GetPolicyTypeOutputBuilder();
1021 case DELETE_POLICY_TYPE:
1022 return new DeletePolicyTypeOutputBuilder();
1023 case GET_POLICY_INSTANCES:
1024 return new GetPolicyInstancesOutputBuilder();
1025 case CREATE_POLICY_INSTANCES:
1026 return new CreatePolicyInstanceOutputBuilder();
1027 case GET_POLICY_INSTANCE:
1028 return new GetPolicyInstanceOutputBuilder();
1029 case DELETE_POLICY_INSTANCE:
1030 return new DeletePolicyInstanceOutputBuilder();
1032 return new GetStatusOutputBuilder();
1033 case NOTIFICATION_ENFORECEMENT:
1034 return new NotifyPolicyEnforcementUpdateOutputBuilder();