summaryrefslogtreecommitdiffstats
path: root/a1-adapter
diff options
context:
space:
mode:
authorLathish <lathishbabu.ganesan@est.tech>2020-08-14 17:18:05 +0100
committerLathish <lathishbabu.ganesan@est.tech>2020-08-17 09:48:07 +0100
commit00d7a8cf9bf7ff836abb0c758e1a0ec9498c779e (patch)
tree2cd2953ce602dddd8561e9848caccebe7a7b8ff1 /a1-adapter
parent5d0ad5f3d3158357183849ca329ac6999be6281d (diff)
Add A1 implementation
Issue-ID: CCSDK-2604 Change-Id: Iad40153e7a8a0468c4512ae284de47cf42ee31bd Signed-off-by: Lathish <lathishbabu.ganesan@est.tech>
Diffstat (limited to 'a1-adapter')
-rw-r--r--a1-adapter/a1-adapter-api/provider/src/main/java/org/onap/ccsdk/features/a1/adapter/A1AdapterClient.java189
-rw-r--r--a1-adapter/a1-adapter-api/provider/src/main/java/org/onap/ccsdk/features/a1/adapter/A1AdapterProvider.java360
-rw-r--r--a1-adapter/a1-adapter-api/provider/src/test/java/org/onap/ccsdk/features/a1/adapter/A1AdapterClientTest.java124
-rw-r--r--a1-adapter/a1-adapter-api/provider/src/test/java/org/onap/ccsdk/features/a1/adapter/A1AdapterProviderTest.java144
4 files changed, 633 insertions, 184 deletions
diff --git a/a1-adapter/a1-adapter-api/provider/src/main/java/org/onap/ccsdk/features/a1/adapter/A1AdapterClient.java b/a1-adapter/a1-adapter-api/provider/src/main/java/org/onap/ccsdk/features/a1/adapter/A1AdapterClient.java
index fb21de4c..f1b2eaee 100644
--- a/a1-adapter/a1-adapter-api/provider/src/main/java/org/onap/ccsdk/features/a1/adapter/A1AdapterClient.java
+++ b/a1-adapter/a1-adapter-api/provider/src/main/java/org/onap/ccsdk/features/a1/adapter/A1AdapterClient.java
@@ -24,52 +24,175 @@ import java.util.Properties;
import org.onap.ccsdk.sli.core.sli.SvcLogicException;
import org.onap.ccsdk.sli.core.sli.provider.MdsalHelper;
import org.onap.ccsdk.sli.core.sli.provider.SvcLogicService;
+import org.opendaylight.yang.gen.v1.org.onap.a1.adapter.rev200122.DeleteA1PolicyOutputBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.a1.adapter.rev200122.GetA1PolicyOutputBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.a1.adapter.rev200122.GetA1PolicyStatusOutputBuilder;
import org.opendaylight.yang.gen.v1.org.onap.a1.adapter.rev200122.GetA1PolicyTypeOutputBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.a1.adapter.rev200122.PutA1PolicyOutputBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class A1AdapterClient {
- private static final Logger LOG = LoggerFactory.getLogger(A1AdapterClient.class);
+ private static final Logger LOG = LoggerFactory.getLogger(A1AdapterClient.class);
- private SvcLogicService svcLogicService = null;
+ private SvcLogicService svcLogicService = null;
- public A1AdapterClient(final SvcLogicService svcLogicService) {
- this.svcLogicService = svcLogicService;
- }
+ public A1AdapterClient(final SvcLogicService svcLogicService) {
+ this.svcLogicService = svcLogicService;
+ }
+
+ public boolean hasGraph(String module, String rpc, String version, String mode) throws SvcLogicException {
+ return svcLogicService.hasGraph(module, rpc, version, mode);
+ }
+
+ public Properties execute(String module, String rpc, String version, String mode,
+ GetA1PolicyTypeOutputBuilder serviceData, Properties parms) throws SvcLogicException {
+ Properties localProp;
+ localProp = MdsalHelper.toProperties(parms, serviceData);
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Parameters passed to SLI");
+
+ for (Object key : localProp.keySet()) {
+ String parmName = (String) key;
+ String parmValue = localProp.getProperty(parmName);
+
+ LOG.debug(parmName + " = " + parmValue);
+ }
+ }
+ Properties respProps = svcLogicService.execute(module, rpc, version, mode, localProp);
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Parameters returned by SLI");
+ for (Object key : respProps.keySet()) {
+ String parmName = (String) key;
+ String parmValue = respProps.getProperty(parmName);
+ LOG.debug(parmName + " = " + parmValue);
+ }
+ }
+ if ("failure".equalsIgnoreCase(respProps.getProperty("SvcLogic.status"))) {
+ return respProps;
+ }
+ MdsalHelper.toBuilder(respProps, serviceData);
+ return respProps;
+ }
+
+ public Properties execute(String module, String rpc, String version, String mode,
+ GetA1PolicyStatusOutputBuilder serviceData, Properties parms) throws SvcLogicException {
+ Properties localProp;
+ localProp = MdsalHelper.toProperties(parms, serviceData);
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Parameters passed to SLI");
- public boolean hasGraph(String module, String rpc, String version, String mode)
- throws SvcLogicException {
- return svcLogicService.hasGraph(module, rpc, version, mode);
- }
+ for (Object key : localProp.keySet()) {
+ String parmName = (String) key;
+ String parmValue = localProp.getProperty(parmName);
- public Properties execute(String module, String rpc, String version, String mode,
- GetA1PolicyTypeOutputBuilder serviceData, Properties parms) throws SvcLogicException {
- Properties localProp;
- localProp = MdsalHelper.toProperties(parms, serviceData);
- if (LOG.isDebugEnabled()) {
- LOG.debug("Parameters passed to SLI");
+ LOG.debug(parmName + " = " + parmValue);
+ }
+ }
+ Properties respProps = svcLogicService.execute(module, rpc, version, mode, localProp);
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Parameters returned by SLI");
+ for (Object key : respProps.keySet()) {
+ String parmName = (String) key;
+ String parmValue = respProps.getProperty(parmName);
+ LOG.debug(parmName + " = " + parmValue);
+ }
+ }
+ if ("failure".equalsIgnoreCase(respProps.getProperty("SvcLogic.status"))) {
+ return respProps;
+ }
+ MdsalHelper.toBuilder(respProps, serviceData);
+ return respProps;
+ }
+
+ public Properties execute(String module, String rpc, String version, String mode,
+ GetA1PolicyOutputBuilder serviceData, Properties parms) throws SvcLogicException {
+ Properties localProp;
+ localProp = MdsalHelper.toProperties(parms, serviceData);
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Parameters passed to SLI");
- for (Object key : localProp.keySet()) {
- String parmName = (String) key;
- String parmValue = localProp.getProperty(parmName);
+ for (Object key : localProp.keySet()) {
+ String parmName = (String) key;
+ String parmValue = localProp.getProperty(parmName);
- LOG.debug(parmName + " = " + parmValue);
- }
+ LOG.debug(parmName + " = " + parmValue);
+ }
+ }
+ Properties respProps = svcLogicService.execute(module, rpc, version, mode, localProp);
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Parameters returned by SLI");
+ for (Object key : respProps.keySet()) {
+ String parmName = (String) key;
+ String parmValue = respProps.getProperty(parmName);
+ LOG.debug(parmName + " = " + parmValue);
+ }
+ }
+ if ("failure".equalsIgnoreCase(respProps.getProperty("SvcLogic.status"))) {
+ return respProps;
+ }
+ MdsalHelper.toBuilder(respProps, serviceData);
+ return respProps;
}
- Properties respProps = svcLogicService.execute(module, rpc, version, mode, localProp);
- if (LOG.isDebugEnabled()) {
- LOG.debug("Parameters returned by SLI");
- for (Object key : respProps.keySet()) {
- String parmName = (String) key;
- String parmValue = respProps.getProperty(parmName);
- LOG.debug(parmName + " = " + parmValue);
- }
+
+ public Properties execute(String module, String rpc, String version, String mode,
+ DeleteA1PolicyOutputBuilder serviceData, Properties parms) throws SvcLogicException {
+ Properties localProp;
+ localProp = MdsalHelper.toProperties(parms, serviceData);
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Parameters passed to SLI");
+
+ for (Object key : localProp.keySet()) {
+ String parmName = (String) key;
+ String parmValue = localProp.getProperty(parmName);
+
+ LOG.debug(parmName + " = " + parmValue);
+ }
+ }
+ Properties respProps = svcLogicService.execute(module, rpc, version, mode, localProp);
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Parameters returned by SLI");
+ for (Object key : respProps.keySet()) {
+ String parmName = (String) key;
+ String parmValue = respProps.getProperty(parmName);
+ LOG.debug(parmName + " = " + parmValue);
+ }
+ }
+ if ("failure".equalsIgnoreCase(respProps.getProperty("SvcLogic.status"))) {
+ return respProps;
+ }
+ MdsalHelper.toBuilder(respProps, serviceData);
+ return respProps;
}
- if ("failure".equalsIgnoreCase(respProps.getProperty("SvcLogic.status"))) {
- return respProps;
+
+ public Properties execute(String module, String rpc, String version, String mode,
+ PutA1PolicyOutputBuilder serviceData, Properties parms) throws SvcLogicException {
+ Properties localProp;
+ localProp = MdsalHelper.toProperties(parms, serviceData);
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Parameters passed to SLI");
+
+ for (Object key : localProp.keySet()) {
+ String parmName = (String) key;
+ String parmValue = localProp.getProperty(parmName);
+
+ LOG.debug(parmName + " = " + parmValue);
+ }
+ }
+ Properties respProps = svcLogicService.execute(module, rpc, version, mode, localProp);
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Parameters returned by SLI");
+ for (Object key : respProps.keySet()) {
+ String parmName = (String) key;
+ String parmValue = respProps.getProperty(parmName);
+ LOG.debug(parmName + " = " + parmValue);
+ }
+ }
+ if ("failure".equalsIgnoreCase(respProps.getProperty("SvcLogic.status"))) {
+ return respProps;
+ }
+ MdsalHelper.toBuilder(respProps, serviceData);
+ return respProps;
}
- MdsalHelper.toBuilder(respProps, serviceData);
- return respProps;
- }
}
diff --git a/a1-adapter/a1-adapter-api/provider/src/main/java/org/onap/ccsdk/features/a1/adapter/A1AdapterProvider.java b/a1-adapter/a1-adapter-api/provider/src/main/java/org/onap/ccsdk/features/a1/adapter/A1AdapterProvider.java
index a1b9ef92..ed7bc95e 100644
--- a/a1-adapter/a1-adapter-api/provider/src/main/java/org/onap/ccsdk/features/a1/adapter/A1AdapterProvider.java
+++ b/a1-adapter/a1-adapter-api/provider/src/main/java/org/onap/ccsdk/features/a1/adapter/A1AdapterProvider.java
@@ -32,27 +32,34 @@ import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
import org.opendaylight.yang.gen.v1.org.onap.a1.adapter.rev200122.A1ADAPTERAPIService;
import org.opendaylight.yang.gen.v1.org.onap.a1.adapter.rev200122.DeleteA1PolicyInput;
+import org.opendaylight.yang.gen.v1.org.onap.a1.adapter.rev200122.DeleteA1PolicyInputBuilder;
import org.opendaylight.yang.gen.v1.org.onap.a1.adapter.rev200122.DeleteA1PolicyOutput;
+import org.opendaylight.yang.gen.v1.org.onap.a1.adapter.rev200122.DeleteA1PolicyOutputBuilder;
import org.opendaylight.yang.gen.v1.org.onap.a1.adapter.rev200122.GetA1PolicyInput;
+import org.opendaylight.yang.gen.v1.org.onap.a1.adapter.rev200122.GetA1PolicyInputBuilder;
import org.opendaylight.yang.gen.v1.org.onap.a1.adapter.rev200122.GetA1PolicyOutput;
+import org.opendaylight.yang.gen.v1.org.onap.a1.adapter.rev200122.GetA1PolicyOutputBuilder;
import org.opendaylight.yang.gen.v1.org.onap.a1.adapter.rev200122.GetA1PolicyStatusInput;
+import org.opendaylight.yang.gen.v1.org.onap.a1.adapter.rev200122.GetA1PolicyStatusInputBuilder;
import org.opendaylight.yang.gen.v1.org.onap.a1.adapter.rev200122.GetA1PolicyStatusOutput;
+import org.opendaylight.yang.gen.v1.org.onap.a1.adapter.rev200122.GetA1PolicyStatusOutputBuilder;
import org.opendaylight.yang.gen.v1.org.onap.a1.adapter.rev200122.GetA1PolicyTypeInput;
import org.opendaylight.yang.gen.v1.org.onap.a1.adapter.rev200122.GetA1PolicyTypeInputBuilder;
import org.opendaylight.yang.gen.v1.org.onap.a1.adapter.rev200122.GetA1PolicyTypeOutput;
import org.opendaylight.yang.gen.v1.org.onap.a1.adapter.rev200122.GetA1PolicyTypeOutputBuilder;
import org.opendaylight.yang.gen.v1.org.onap.a1.adapter.rev200122.PutA1PolicyInput;
+import org.opendaylight.yang.gen.v1.org.onap.a1.adapter.rev200122.PutA1PolicyInputBuilder;
import org.opendaylight.yang.gen.v1.org.onap.a1.adapter.rev200122.PutA1PolicyOutput;
+import org.opendaylight.yang.gen.v1.org.onap.a1.adapter.rev200122.PutA1PolicyOutputBuilder;
import org.opendaylight.yangtools.yang.common.RpcResult;
import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
- * Defines a base implementation for your provider. This class overrides the generated interface
- * from the YANG model and implements the request model for the A1 interface. This class identifies
- * the Near-RT RIC throught the IP passed over the payload and calls the corresponding Near-RT RIC
- * over Rest API
+ * Defines a base implementation for your provider. This class overrides the generated interface from the YANG model and
+ * implements the request model for the A1 interface. This class identifies the Near-RT RIC throught the IP passed over
+ * the payload and calls the corresponding Near-RT RIC over Rest API
*
* <pre>
*
@@ -60,115 +67,250 @@ import org.slf4j.LoggerFactory;
@SuppressWarnings("squid:S1874") // "@Deprecated" code should not be used
public class A1AdapterProvider implements AutoCloseable, A1ADAPTERAPIService {
- private static final Logger log = LoggerFactory.getLogger(A1AdapterProvider.class);
-
- private static final String APPLICATION_NAME = "a1Adapter-api";
-
- private final ExecutorService executor;
- protected DataBroker dataBroker;
- protected NotificationPublishService notificationService;
- protected RpcProviderRegistry rpcRegistry;
- protected BindingAwareBroker.RpcRegistration<A1ADAPTERAPIService> rpcRegistration;
- private final A1AdapterClient a1AdapterClient;
-
- public A1AdapterProvider(final DataBroker dataBroker,
- final NotificationPublishService notificationPublishService,
- final RpcProviderRegistry rpcProviderRegistry, final A1AdapterClient a1AdapterClient) {
-
- log.info("Creating provider for {}", APPLICATION_NAME);
- executor = Executors.newFixedThreadPool(1);
- this.dataBroker = dataBroker;
- this.notificationService = notificationPublishService;
- this.rpcRegistry = rpcProviderRegistry;
- this.a1AdapterClient = a1AdapterClient;
- initialize();
- }
-
- public void initialize() {
- log.info("Initializing provider for {}", APPLICATION_NAME);
- rpcRegistration = rpcRegistry.addRpcImplementation(A1ADAPTERAPIService.class, this);
- log.info("Initialization complete for {}", APPLICATION_NAME);
- }
-
- protected void initializeChild() {
- // Override if you have custom initialization intelligence
- }
-
- @Override
- public void close() throws Exception {
- log.info("Closing provider for {}", APPLICATION_NAME);
- executor.shutdown();
- rpcRegistration.close();
- log.info("Successfully closed provider for {}", APPLICATION_NAME);
- }
-
- @Override
- public ListenableFuture<RpcResult<DeleteA1PolicyOutput>> deleteA1Policy(
- DeleteA1PolicyInput input) {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public ListenableFuture<RpcResult<GetA1PolicyOutput>> getA1Policy(GetA1PolicyInput input) {
- log.info("Start of getA1Policy");
- return null;
- }
-
- @Override
- public ListenableFuture<RpcResult<GetA1PolicyStatusOutput>> getA1PolicyStatus(
- GetA1PolicyStatusInput input) {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public ListenableFuture<RpcResult<GetA1PolicyTypeOutput>> getA1PolicyType(
- GetA1PolicyTypeInput input) {
- log.info("Start of getA1PolicyType");
- final String svcOperation = "getA1PolicyType";
- Properties parms = new Properties();
- GetA1PolicyTypeOutputBuilder policyTypeResponse = new GetA1PolicyTypeOutputBuilder();
- // add input to parms
- log.info("Adding INPUT data for " + svcOperation + " input: " + input);
- GetA1PolicyTypeInputBuilder inputBuilder = new GetA1PolicyTypeInputBuilder(input);
- MdsalHelper.toProperties(parms, inputBuilder.build());
- log.info("Printing SLI parameters to be passed");
- // iterate properties file to get key-value pairs
- for (String key : parms.stringPropertyNames()) {
- String value = parms.getProperty(key);
- log.info("The SLI parameter in " + key + " is: " + value);
+ private static final Logger log = LoggerFactory.getLogger(A1AdapterProvider.class);
+
+ private static final String APPLICATION_NAME = "a1Adapter-api";
+
+ private final ExecutorService executor;
+ protected DataBroker dataBroker;
+ protected NotificationPublishService notificationService;
+ protected RpcProviderRegistry rpcRegistry;
+ protected BindingAwareBroker.RpcRegistration<A1ADAPTERAPIService> rpcRegistration;
+ private final A1AdapterClient a1AdapterClient;
+
+ public A1AdapterProvider(final DataBroker dataBroker, final NotificationPublishService notificationPublishService,
+ final RpcProviderRegistry rpcProviderRegistry, final A1AdapterClient a1AdapterClient) {
+
+ log.info("Creating provider for {}", APPLICATION_NAME);
+ executor = Executors.newFixedThreadPool(1);
+ this.dataBroker = dataBroker;
+ this.notificationService = notificationPublishService;
+ this.rpcRegistry = rpcProviderRegistry;
+ this.a1AdapterClient = a1AdapterClient;
+ initialize();
+ }
+
+ public void initialize() {
+ log.info("Initializing provider for {}", APPLICATION_NAME);
+ rpcRegistration = rpcRegistry.addRpcImplementation(A1ADAPTERAPIService.class, this);
+ log.info("Initialization complete for {}", APPLICATION_NAME);
+ }
+
+ protected void initializeChild() {
+ // Override if you have custom initialization intelligence
+ }
+
+ @Override
+ public void close() throws Exception {
+ log.info("Closing provider for {}", APPLICATION_NAME);
+ executor.shutdown();
+ rpcRegistration.close();
+ log.info("Successfully closed provider for {}", APPLICATION_NAME);
+ }
+
+ @Override
+ public ListenableFuture<RpcResult<DeleteA1PolicyOutput>> deleteA1Policy(DeleteA1PolicyInput input) {
+ log.info("Start of deleteA1Policy");
+ final String svcOperation = "deleteA1Policy";
+ Properties parms = new Properties();
+ DeleteA1PolicyOutputBuilder deleteResponse = new DeleteA1PolicyOutputBuilder();
+ // add input to parms
+ log.info("Adding INPUT data for " + svcOperation + " input: " + input);
+ DeleteA1PolicyInputBuilder inputBuilder = new DeleteA1PolicyInputBuilder(input);
+ MdsalHelper.toProperties(parms, inputBuilder.build());
+ log.info("Printing SLI parameters to be passed");
+ // iterate properties file to get key-value pairs
+ for (String key : parms.stringPropertyNames()) {
+ String value = parms.getProperty(key);
+ log.info("The SLI parameter in " + key + " is: " + value);
+ }
+ // Call SLI sync method
+ try {
+ if (a1AdapterClient.hasGraph("A1-ADAPTER-API", svcOperation, null, "sync")) {
+ log.info("A1AdapterClient has a Directed Graph for '" + svcOperation + "'");
+ try {
+ a1AdapterClient.execute("A1-ADAPTER-API", svcOperation, null, "sync", deleteResponse, parms);
+ deleteResponse.setHttpStatus(200);
+ } catch (Exception e) {
+ log.error("Caught exception executing service logic for " + svcOperation, e);
+ deleteResponse.setHttpStatus(500);
+ }
+ } else {
+ log.error("No service logic active for A1Adapter: '" + svcOperation + "'");
+ deleteResponse.setHttpStatus(503);
+ }
+ } catch (Exception e) {
+ log.error("Caught exception looking for service logic", e);
+ deleteResponse.setHttpStatus(500);
+ }
+ RpcResult<DeleteA1PolicyOutput> rpcResult =
+ RpcResultBuilder.<DeleteA1PolicyOutput>status(true).withResult(deleteResponse.build()).build();
+ log.info("End of getA1Policy");
+ return Futures.immediateFuture(rpcResult);
+ }
+
+ @Override
+ public ListenableFuture<RpcResult<GetA1PolicyOutput>> getA1Policy(GetA1PolicyInput input) {
+ log.info("Start of getA1Policy");
+ final String svcOperation = "getA1Policy";
+ Properties parms = new Properties();
+ GetA1PolicyOutputBuilder policyResponse = new GetA1PolicyOutputBuilder();
+ // add input to parms
+ log.info("Adding INPUT data for " + svcOperation + " input: " + input);
+ GetA1PolicyInputBuilder inputBuilder = new GetA1PolicyInputBuilder(input);
+ MdsalHelper.toProperties(parms, inputBuilder.build());
+ log.info("Printing SLI parameters to be passed");
+ // iterate properties file to get key-value pairs
+ for (String key : parms.stringPropertyNames()) {
+ String value = parms.getProperty(key);
+ log.info("The SLI parameter in " + key + " is: " + value);
+ }
+ // Call SLI sync method
+ try {
+ if (a1AdapterClient.hasGraph("A1-ADAPTER-API", svcOperation, null, "sync")) {
+ log.info("A1AdapterClient has a Directed Graph for '" + svcOperation + "'");
+ try {
+ a1AdapterClient.execute("A1-ADAPTER-API", svcOperation, null, "sync", policyResponse, parms);
+ policyResponse.setHttpStatus(200);
+ } catch (Exception e) {
+ log.error("Caught exception executing service logic for " + svcOperation, e);
+ policyResponse.setHttpStatus(500);
+ }
+ } else {
+ log.error("No service logic active for A1Adapter: '" + svcOperation + "'");
+ policyResponse.setHttpStatus(503);
+ }
+ } catch (Exception e) {
+ log.error("Caught exception looking for service logic", e);
+ policyResponse.setHttpStatus(500);
+ }
+ RpcResult<GetA1PolicyOutput> rpcResult =
+ RpcResultBuilder.<GetA1PolicyOutput>status(true).withResult(policyResponse.build()).build();
+ log.info("End of getA1Policy");
+ return Futures.immediateFuture(rpcResult);
+ }
+
+ @Override
+ public ListenableFuture<RpcResult<GetA1PolicyStatusOutput>> getA1PolicyStatus(GetA1PolicyStatusInput input) {
+ log.info("Start of getA1PolicyStatus");
+ final String svcOperation = "getA1PolicyStatus";
+ Properties parms = new Properties();
+ GetA1PolicyStatusOutputBuilder policyStatusResponse = new GetA1PolicyStatusOutputBuilder();
+ // add input to parms
+ log.info("Adding INPUT data for " + svcOperation + " input: " + input);
+ GetA1PolicyStatusInputBuilder inputBuilder = new GetA1PolicyStatusInputBuilder(input);
+ MdsalHelper.toProperties(parms, inputBuilder.build());
+ log.info("Printing SLI parameters to be passed");
+ // iterate properties file to get key-value pairs
+ for (String key : parms.stringPropertyNames()) {
+ String value = parms.getProperty(key);
+ log.info("The SLI parameter in " + key + " is: " + value);
+ }
+ // Call SLI sync method
+ try {
+ if (a1AdapterClient.hasGraph("A1-ADAPTER-API", svcOperation, null, "sync")) {
+ log.info("A1AdapterClient has a Directed Graph for '" + svcOperation + "'");
+ try {
+ a1AdapterClient.execute("A1-ADAPTER-API", svcOperation, null, "sync", policyStatusResponse, parms);
+ policyStatusResponse.setHttpStatus(200);
+ } catch (Exception e) {
+ log.error("Caught exception executing service logic for " + svcOperation, e);
+ policyStatusResponse.setHttpStatus(500);
+ }
+ } else {
+ log.error("No service logic active for A1Adapter: '" + svcOperation + "'");
+ policyStatusResponse.setHttpStatus(503);
+ }
+ } catch (Exception e) {
+ log.error("Caught exception looking for service logic", e);
+ policyStatusResponse.setHttpStatus(500);
+ }
+ RpcResult<GetA1PolicyStatusOutput> rpcResult =
+ RpcResultBuilder.<GetA1PolicyStatusOutput>status(true).withResult(policyStatusResponse.build()).build();
+ log.info("End of getA1PolicyStatus");
+ return Futures.immediateFuture(rpcResult);
}
- // Call SLI sync method
- try {
- if (a1AdapterClient.hasGraph("A1-ADAPTER-API", svcOperation, null, "sync")) {
- log.info("A1AdapterClient has a Directed Graph for '" + svcOperation + "'");
+
+ @Override
+ public ListenableFuture<RpcResult<GetA1PolicyTypeOutput>> getA1PolicyType(GetA1PolicyTypeInput input) {
+ log.info("Start of getA1PolicyType");
+ final String svcOperation = "getA1PolicyType";
+ Properties parms = new Properties();
+ GetA1PolicyTypeOutputBuilder policyTypeResponse = new GetA1PolicyTypeOutputBuilder();
+ // add input to parms
+ log.info("Adding INPUT data for " + svcOperation + " input: " + input);
+ GetA1PolicyTypeInputBuilder inputBuilder = new GetA1PolicyTypeInputBuilder(input);
+ MdsalHelper.toProperties(parms, inputBuilder.build());
+ log.info("Printing SLI parameters to be passed");
+ // iterate properties file to get key-value pairs
+ for (String key : parms.stringPropertyNames()) {
+ String value = parms.getProperty(key);
+ log.info("The SLI parameter in " + key + " is: " + value);
+ }
+ // Call SLI sync method
+ try {
+ if (a1AdapterClient.hasGraph("A1-ADAPTER-API", svcOperation, null, "sync")) {
+ log.info("A1AdapterClient has a Directed Graph for '" + svcOperation + "'");
+ try {
+ a1AdapterClient.execute("A1-ADAPTER-API", svcOperation, null, "sync", policyTypeResponse, parms);
+ policyTypeResponse.setHttpStatus(200);
+ } catch (Exception e) {
+ log.error("Caught exception executing service logic for " + svcOperation, e);
+ policyTypeResponse.setHttpStatus(500);
+ }
+ } else {
+ log.error("No service logic active for A1Adapter: '" + svcOperation + "'");
+ policyTypeResponse.setHttpStatus(503);
+ }
+ } catch (Exception e) {
+ log.error("Caught exception looking for service logic", e);
+ policyTypeResponse.setHttpStatus(500);
+ }
+ RpcResult<GetA1PolicyTypeOutput> rpcResult =
+ RpcResultBuilder.<GetA1PolicyTypeOutput>status(true).withResult(policyTypeResponse.build()).build();
+ log.info("End of getA1PolicyType");
+ return Futures.immediateFuture(rpcResult);
+ }
+
+ @Override
+ public ListenableFuture<RpcResult<PutA1PolicyOutput>> putA1Policy(PutA1PolicyInput input) {
+ log.info("Start of putA1Policy");
+ final String svcOperation = "putA1Policy";
+ Properties parms = new Properties();
+ PutA1PolicyOutputBuilder policyResponse = new PutA1PolicyOutputBuilder();
+ // add input to parms
+ log.info("Adding INPUT data for " + svcOperation + " input: " + input);
+ PutA1PolicyInputBuilder inputBuilder = new PutA1PolicyInputBuilder(input);
+ MdsalHelper.toProperties(parms, inputBuilder.build());
+ log.info("Printing SLI parameters to be passed");
+ // iterate properties file to get key-value pairs
+ for (String key : parms.stringPropertyNames()) {
+ String value = parms.getProperty(key);
+ log.info("The SLI parameter in " + key + " is: " + value);
+ }
+ // Call SLI sync method
try {
- a1AdapterClient.execute("A1-ADAPTER-API", svcOperation, null, "sync", policyTypeResponse,
- parms);
- policyTypeResponse.setHttpStatus(200);
+ if (a1AdapterClient.hasGraph("A1-ADAPTER-API", svcOperation, null, "sync")) {
+ log.info("A1AdapterClient has a Directed Graph for '" + svcOperation + "'");
+ try {
+ a1AdapterClient.execute("A1-ADAPTER-API", svcOperation, null, "sync", policyResponse, parms);
+ policyResponse.setHttpStatus(200);
+ } catch (Exception e) {
+ log.error("Caught exception executing service logic for " + svcOperation, e);
+ policyResponse.setHttpStatus(500);
+ }
+ } else {
+ log.error("No service logic active for A1Adapter: '" + svcOperation + "'");
+ policyResponse.setHttpStatus(503);
+ }
} catch (Exception e) {
- log.error("Caught exception executing service logic for " + svcOperation, e);
- policyTypeResponse.setHttpStatus(500);
+ log.error("Caught exception looking for service logic", e);
+ policyResponse.setHttpStatus(500);
}
- } else {
- log.error("No service logic active for A1Adapter: '" + svcOperation + "'");
- policyTypeResponse.setHttpStatus(503);
- }
- } catch (Exception e) {
- log.error("Caught exception looking for service logic", e);
- policyTypeResponse.setHttpStatus(500);
+ RpcResult<PutA1PolicyOutput> rpcResult =
+ RpcResultBuilder.<PutA1PolicyOutput>status(true).withResult(policyResponse.build()).build();
+ log.info("End of putA1Policy");
+ return Futures.immediateFuture(rpcResult);
}
- RpcResult<GetA1PolicyTypeOutput> rpcResult = RpcResultBuilder
- .<GetA1PolicyTypeOutput>status(true).withResult(policyTypeResponse.build()).build();
- log.info("End of getA1PolicyType");
- return Futures.immediateFuture(rpcResult);
- }
-
- @Override
- public ListenableFuture<RpcResult<PutA1PolicyOutput>> putA1Policy(PutA1PolicyInput input) {
- // TODO Auto-generated method stub
- return null;
- }
}
diff --git a/a1-adapter/a1-adapter-api/provider/src/test/java/org/onap/ccsdk/features/a1/adapter/A1AdapterClientTest.java b/a1-adapter/a1-adapter-api/provider/src/test/java/org/onap/ccsdk/features/a1/adapter/A1AdapterClientTest.java
new file mode 100644
index 00000000..5c4b2857
--- /dev/null
+++ b/a1-adapter/a1-adapter-api/provider/src/test/java/org/onap/ccsdk/features/a1/adapter/A1AdapterClientTest.java
@@ -0,0 +1,124 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.ccsdk.features.a1.adapter;
+
+import static org.junit.Assert.assertNotNull;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.when;
+import java.util.Properties;
+import java.util.concurrent.ExecutionException;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.ccsdk.sli.core.sli.SvcLogicException;
+import org.onap.ccsdk.sli.core.sli.provider.SvcLogicService;
+import org.opendaylight.yang.gen.v1.org.onap.a1.adapter.rev200122.DeleteA1PolicyOutputBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.a1.adapter.rev200122.GetA1PolicyOutputBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.a1.adapter.rev200122.GetA1PolicyStatusOutputBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.a1.adapter.rev200122.GetA1PolicyTypeOutputBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.a1.adapter.rev200122.PutA1PolicyOutputBuilder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * This class Tests all the methods in A1AdapterClientTest
+ *
+ */
+
+@RunWith(MockitoJUnitRunner.Silent.class)
+public class A1AdapterClientTest {
+
+ protected static final Logger LOG = LoggerFactory.getLogger(A1AdapterClientTest.class);
+
+ @Mock
+ private SvcLogicService svcLogicService = null;
+ private A1AdapterClient a1AdapterClient;
+ private static String module = "A1-ADAPTER-API";
+ private static String mode = "sync";
+
+ @Before
+ public void setUp() throws Exception {
+ a1AdapterClient = new A1AdapterClient(svcLogicService);
+ }
+
+ @Test
+ public void test_execute_getPolicyType() throws SvcLogicException, InterruptedException, ExecutionException {
+ String rpc = "deleteA1Policy";
+ Properties params = new Properties();
+ Properties respProps = new Properties();
+ GetA1PolicyTypeOutputBuilder serviceData = new GetA1PolicyTypeOutputBuilder();
+ when(svcLogicService.execute(eq(module), eq(rpc), eq(null), eq(mode), any(Properties.class)))
+ .thenReturn(respProps);
+ Properties response = a1AdapterClient.execute(module, rpc, null, mode, serviceData, params);
+ assertNotNull(response);
+ }
+
+ @Test
+ public void test_execute_getPolicyStatus() throws SvcLogicException, InterruptedException, ExecutionException {
+ String rpc = "getA1PolicyStatus";
+ Properties params = new Properties();
+ Properties respProps = new Properties();
+ GetA1PolicyStatusOutputBuilder serviceData = new GetA1PolicyStatusOutputBuilder();
+ when(svcLogicService.execute(eq(module), eq(rpc), eq(null), eq(mode), any(Properties.class)))
+ .thenReturn(respProps);
+ Properties response = a1AdapterClient.execute(module, rpc, null, mode, serviceData, params);
+ assertNotNull(response);
+ }
+
+ @Test
+ public void test_execute_getPolicy() throws SvcLogicException, InterruptedException, ExecutionException {
+ String rpc = "getA1Policy";
+ Properties params = new Properties();
+ Properties respProps = new Properties();
+ GetA1PolicyOutputBuilder serviceData = new GetA1PolicyOutputBuilder();
+ when(svcLogicService.execute(eq(module), eq(rpc), eq(null), eq(mode), any(Properties.class)))
+ .thenReturn(respProps);
+ Properties response = a1AdapterClient.execute(module, rpc, null, mode, serviceData, params);
+ assertNotNull(response);
+ }
+
+ @Test
+ public void test_execute_deletePolicy() throws SvcLogicException, InterruptedException, ExecutionException {
+ String rpc = "deleteA1Policy";
+ Properties params = new Properties();
+ Properties respProps = new Properties();
+ DeleteA1PolicyOutputBuilder serviceData = new DeleteA1PolicyOutputBuilder();
+ when(svcLogicService.execute(eq(module), eq(rpc), eq(null), eq(mode), any(Properties.class)))
+ .thenReturn(respProps);
+ Properties response = a1AdapterClient.execute(module, rpc, null, mode, serviceData, params);
+ assertNotNull(response);
+ }
+
+ @Test
+ public void test_execute_putPolicy() throws SvcLogicException, InterruptedException, ExecutionException {
+ String rpc = "putA1Policy";
+ Properties params = new Properties();
+ Properties respProps = new Properties();
+ PutA1PolicyOutputBuilder serviceData = new PutA1PolicyOutputBuilder();
+ when(svcLogicService.execute(eq(module), eq(rpc), eq(null), eq(mode), any(Properties.class)))
+ .thenReturn(respProps);
+ Properties response = a1AdapterClient.execute(module, rpc, null, mode, serviceData, params);
+ assertNotNull(response);
+ }
+}
diff --git a/a1-adapter/a1-adapter-api/provider/src/test/java/org/onap/ccsdk/features/a1/adapter/A1AdapterProviderTest.java b/a1-adapter/a1-adapter-api/provider/src/test/java/org/onap/ccsdk/features/a1/adapter/A1AdapterProviderTest.java
index 901bc008..8901ab07 100644
--- a/a1-adapter/a1-adapter-api/provider/src/test/java/org/onap/ccsdk/features/a1/adapter/A1AdapterProviderTest.java
+++ b/a1-adapter/a1-adapter-api/provider/src/test/java/org/onap/ccsdk/features/a1/adapter/A1AdapterProviderTest.java
@@ -37,9 +37,21 @@ import org.onap.ccsdk.sli.core.sli.SvcLogicException;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
+import org.opendaylight.yang.gen.v1.org.onap.a1.adapter.rev200122.DeleteA1PolicyInputBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.a1.adapter.rev200122.DeleteA1PolicyOutput;
+import org.opendaylight.yang.gen.v1.org.onap.a1.adapter.rev200122.DeleteA1PolicyOutputBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.a1.adapter.rev200122.GetA1PolicyInputBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.a1.adapter.rev200122.GetA1PolicyOutput;
+import org.opendaylight.yang.gen.v1.org.onap.a1.adapter.rev200122.GetA1PolicyOutputBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.a1.adapter.rev200122.GetA1PolicyStatusInputBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.a1.adapter.rev200122.GetA1PolicyStatusOutput;
+import org.opendaylight.yang.gen.v1.org.onap.a1.adapter.rev200122.GetA1PolicyStatusOutputBuilder;
import org.opendaylight.yang.gen.v1.org.onap.a1.adapter.rev200122.GetA1PolicyTypeInputBuilder;
import org.opendaylight.yang.gen.v1.org.onap.a1.adapter.rev200122.GetA1PolicyTypeOutput;
import org.opendaylight.yang.gen.v1.org.onap.a1.adapter.rev200122.GetA1PolicyTypeOutputBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.a1.adapter.rev200122.PutA1PolicyInputBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.a1.adapter.rev200122.PutA1PolicyOutput;
+import org.opendaylight.yang.gen.v1.org.onap.a1.adapter.rev200122.PutA1PolicyOutputBuilder;
import org.opendaylight.yangtools.yang.common.RpcResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -52,50 +64,98 @@ import org.slf4j.LoggerFactory;
@RunWith(MockitoJUnitRunner.Silent.class)
public class A1AdapterProviderTest {
- protected static final Logger LOG = LoggerFactory.getLogger(A1AdapterProviderTest.class);
+ protected static final Logger LOG = LoggerFactory.getLogger(A1AdapterProviderTest.class);
- class A1AdapterProviderMock extends A1AdapterProvider {
+ class A1AdapterProviderMock extends A1AdapterProvider {
- A1AdapterProviderMock(final DataBroker dataBroker,
- final NotificationPublishService notificationPublishService,
- final RpcProviderRegistry rpcProviderRegistry, final A1AdapterClient A1AdapterClient) {
- super(dataBroker, mockNotificationPublishService, mockRpcProviderRegistry, a1AdapterClient);
+ A1AdapterProviderMock(final DataBroker dataBroker, final NotificationPublishService notificationPublishService,
+ final RpcProviderRegistry rpcProviderRegistry, final A1AdapterClient A1AdapterClient) {
+ super(dataBroker, mockNotificationPublishService, mockRpcProviderRegistry, a1AdapterClient);
+ }
+
+ }
+
+ private A1AdapterProviderMock a1AdapterProviderMock = null;
+ @Mock
+ private DataBroker dataBroker;
+ @Mock
+ private NotificationPublishService mockNotificationPublishService;
+ @Mock
+ private RpcProviderRegistry mockRpcProviderRegistry;
+ @Mock
+ private A1AdapterClient a1AdapterClient;
+ private static String module = "A1-ADAPTER-API";
+ private static String mode = "sync";
+
+ @Before
+ public void setUp() throws Exception {
+
+ a1AdapterProviderMock = new A1AdapterProviderMock(dataBroker, mockNotificationPublishService,
+ mockRpcProviderRegistry, a1AdapterClient);
+ a1AdapterProviderMock = Mockito.spy(a1AdapterProviderMock);
+
+ }
+
+ @Test
+ public void test_deleteA1PolicyType() throws SvcLogicException, InterruptedException, ExecutionException {
+ String rpc = "deleteA1Policy";
+ Properties respProps = new Properties();
+ DeleteA1PolicyInputBuilder inputBuilder = new DeleteA1PolicyInputBuilder();
+ when(a1AdapterClient.hasGraph(module, rpc, null, mode)).thenReturn(true);
+ when(a1AdapterClient.execute(eq(module), eq(rpc), eq(null), eq(mode), any(DeleteA1PolicyOutputBuilder.class),
+ any(Properties.class))).thenReturn(respProps);
+ ListenableFuture<RpcResult<DeleteA1PolicyOutput>> result =
+ a1AdapterProviderMock.deleteA1Policy(inputBuilder.build());
+ assertEquals("200", String.valueOf(result.get().getResult().getHttpStatus()));
}
- }
-
- private A1AdapterProviderMock a1AdapterProviderMock = null;
- @Mock
- private DataBroker dataBroker;
- @Mock
- private NotificationPublishService mockNotificationPublishService;
- @Mock
- private RpcProviderRegistry mockRpcProviderRegistry;
- @Mock
- private A1AdapterClient a1AdapterClient;
- private static String module = "A1-ADAPTER-API";
- private static String mode = "sync";
-
- @Before
- public void setUp() throws Exception {
-
- a1AdapterProviderMock = new A1AdapterProviderMock(dataBroker, mockNotificationPublishService,
- mockRpcProviderRegistry, a1AdapterClient);
- a1AdapterProviderMock = Mockito.spy(a1AdapterProviderMock);
-
- }
-
- @Test
- public void test_getA1PolicyType()
- throws SvcLogicException, InterruptedException, ExecutionException {
- String rpc = "getA1PolicyType";
- Properties respProps = new Properties();
- GetA1PolicyTypeInputBuilder inputBuilder = new GetA1PolicyTypeInputBuilder();
- when(a1AdapterClient.hasGraph(module, rpc, null, mode)).thenReturn(true);
- when(a1AdapterClient.execute(eq(module), eq(rpc), eq(null), eq(mode),
- any(GetA1PolicyTypeOutputBuilder.class), any(Properties.class))).thenReturn(respProps);
- ListenableFuture<RpcResult<GetA1PolicyTypeOutput>> result =
- a1AdapterProviderMock.getA1PolicyType(inputBuilder.build());
- assertEquals("200", String.valueOf(result.get().getResult().getHttpStatus()));
- }
+ @Test
+ public void test_getA1Policy() throws SvcLogicException, InterruptedException, ExecutionException {
+ String rpc = "getA1Policy";
+ Properties respProps = new Properties();
+ GetA1PolicyInputBuilder inputBuilder = new GetA1PolicyInputBuilder();
+ when(a1AdapterClient.hasGraph(module, rpc, null, mode)).thenReturn(true);
+ when(a1AdapterClient.execute(eq(module), eq(rpc), eq(null), eq(mode), any(GetA1PolicyOutputBuilder.class),
+ any(Properties.class))).thenReturn(respProps);
+ ListenableFuture<RpcResult<GetA1PolicyOutput>> result = a1AdapterProviderMock.getA1Policy(inputBuilder.build());
+ assertEquals("200", String.valueOf(result.get().getResult().getHttpStatus()));
+ }
+
+ @Test
+ public void test_getA1PolicyType() throws SvcLogicException, InterruptedException, ExecutionException {
+ String rpc = "getA1PolicyType";
+ Properties respProps = new Properties();
+ GetA1PolicyTypeInputBuilder inputBuilder = new GetA1PolicyTypeInputBuilder();
+ when(a1AdapterClient.hasGraph(module, rpc, null, mode)).thenReturn(true);
+ when(a1AdapterClient.execute(eq(module), eq(rpc), eq(null), eq(mode), any(GetA1PolicyTypeOutputBuilder.class),
+ any(Properties.class))).thenReturn(respProps);
+ ListenableFuture<RpcResult<GetA1PolicyTypeOutput>> result =
+ a1AdapterProviderMock.getA1PolicyType(inputBuilder.build());
+ assertEquals("200", String.valueOf(result.get().getResult().getHttpStatus()));
+ }
+
+ @Test
+ public void test_getA1PolicyStatus() throws SvcLogicException, InterruptedException, ExecutionException {
+ String rpc = "getA1PolicyStatus";
+ Properties respProps = new Properties();
+ GetA1PolicyStatusInputBuilder inputBuilder = new GetA1PolicyStatusInputBuilder();
+ when(a1AdapterClient.hasGraph(module, rpc, null, mode)).thenReturn(true);
+ when(a1AdapterClient.execute(eq(module), eq(rpc), eq(null), eq(mode), any(GetA1PolicyStatusOutputBuilder.class),
+ any(Properties.class))).thenReturn(respProps);
+ ListenableFuture<RpcResult<GetA1PolicyStatusOutput>> result =
+ a1AdapterProviderMock.getA1PolicyStatus(inputBuilder.build());
+ assertEquals("200", String.valueOf(result.get().getResult().getHttpStatus()));
+ }
+
+ @Test
+ public void test_putA1Policy() throws SvcLogicException, InterruptedException, ExecutionException {
+ String rpc = "putA1Policy";
+ Properties respProps = new Properties();
+ PutA1PolicyInputBuilder inputBuilder = new PutA1PolicyInputBuilder();
+ when(a1AdapterClient.hasGraph(module, rpc, null, mode)).thenReturn(true);
+ when(a1AdapterClient.execute(eq(module), eq(rpc), eq(null), eq(mode), any(PutA1PolicyOutputBuilder.class),
+ any(Properties.class))).thenReturn(respProps);
+ ListenableFuture<RpcResult<PutA1PolicyOutput>> result = a1AdapterProviderMock.putA1Policy(inputBuilder.build());
+ assertEquals("200", String.valueOf(result.get().getResult().getHttpStatus()));
+ }
}