aboutsummaryrefslogtreecommitdiffstats
path: root/a1-adapter/a1-adapter-api/provider/src
diff options
context:
space:
mode:
Diffstat (limited to 'a1-adapter/a1-adapter-api/provider/src')
-rw-r--r--a1-adapter/a1-adapter-api/provider/src/main/java/org/onap/ccsdk/features/a1/adapter/A1AdapterClient.java88
-rw-r--r--a1-adapter/a1-adapter-api/provider/src/main/java/org/onap/ccsdk/features/a1/adapter/A1AdapterProvider.java299
-rw-r--r--a1-adapter/a1-adapter-api/provider/src/test/java/org/onap/ccsdk/features/a1/adapter/A1AdapterClientTest.java34
-rw-r--r--a1-adapter/a1-adapter-api/provider/src/test/java/org/onap/ccsdk/features/a1/adapter/A1AdapterProviderTest.java115
4 files changed, 190 insertions, 346 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 2cf63b3c..addfa462 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,11 +24,6 @@ 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;
@@ -36,6 +31,8 @@ public class A1AdapterClient {
private static final String PARAMETERS_PASSED_TO_SLI = "Parameters passed to SLI";
private static final String PARAMETERS_RETURNED_BY_SLI = "Parameters returned by SLI";
+ private static final String FAILURE = "failure";
+ private static final String SVC_LOGIC_STATUS = "SvcLogic.status";
private static final Logger LOG = LoggerFactory.getLogger(A1AdapterClient.class);
@@ -49,10 +46,11 @@ public class A1AdapterClient {
return svcLogicService.hasGraph(module, rpc, version, mode);
}
+ @SuppressWarnings("squid:S1874") // "@Deprecated" code should not be used
public Properties execute(String module, String rpc, String version, String mode,
- GetA1PolicyTypeOutputBuilder serviceData, Properties parms) throws SvcLogicException {
+ Object policyData, Properties parms) throws SvcLogicException {
Properties localProp;
- localProp = MdsalHelper.toProperties(parms, serviceData);
+ localProp = MdsalHelper.toProperties(parms, policyData);
if (LOG.isDebugEnabled()) {
logParameters(PARAMETERS_PASSED_TO_SLI, localProp);
}
@@ -60,82 +58,10 @@ public class A1AdapterClient {
if (LOG.isDebugEnabled()) {
logParameters(PARAMETERS_RETURNED_BY_SLI, localProp);
}
- if ("failure".equalsIgnoreCase(respProps.getProperty("SvcLogic.status"))) {
+ if (FAILURE.equalsIgnoreCase(respProps.getProperty(SVC_LOGIC_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()) {
- logParameters(PARAMETERS_PASSED_TO_SLI, localProp);
- }
- Properties respProps = svcLogicService.execute(module, rpc, version, mode, localProp);
- if (LOG.isDebugEnabled()) {
- logParameters(PARAMETERS_RETURNED_BY_SLI, localProp);
- }
- 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()) {
- logParameters(PARAMETERS_PASSED_TO_SLI, localProp);
- }
- Properties respProps = svcLogicService.execute(module, rpc, version, mode, localProp);
- if (LOG.isDebugEnabled()) {
- logParameters(PARAMETERS_RETURNED_BY_SLI, localProp);
- }
- 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,
- DeleteA1PolicyOutputBuilder serviceData, Properties parms) throws SvcLogicException {
- Properties localProp;
- localProp = MdsalHelper.toProperties(parms, serviceData);
- if (LOG.isDebugEnabled()) {
- logParameters(PARAMETERS_PASSED_TO_SLI, localProp);
- }
- Properties respProps = svcLogicService.execute(module, rpc, version, mode, localProp);
- if (LOG.isDebugEnabled()) {
- logParameters(PARAMETERS_RETURNED_BY_SLI, localProp);
- }
- 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,
- PutA1PolicyOutputBuilder serviceData, Properties parms) throws SvcLogicException {
- Properties localProp;
- localProp = MdsalHelper.toProperties(parms, serviceData);
- if (LOG.isDebugEnabled()) {
- logParameters(PARAMETERS_PASSED_TO_SLI, localProp);
- }
- Properties respProps = svcLogicService.execute(module, rpc, version, mode, localProp);
- if (LOG.isDebugEnabled()) {
- logParameters(PARAMETERS_RETURNED_BY_SLI, localProp);
- }
- if ("failure".equalsIgnoreCase(respProps.getProperty("SvcLogic.status"))) {
- return respProps;
- }
- MdsalHelper.toBuilder(respProps, serviceData);
+ MdsalHelper.toBuilder(respProps, policyData);
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 e1c151a3..8693f493 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
@@ -20,13 +20,16 @@
package org.onap.ccsdk.features.a1.adapter;
+import static org.apache.http.HttpStatus.SC_INTERNAL_SERVER_ERROR;
+import static org.apache.http.HttpStatus.SC_SERVICE_UNAVAILABLE;
+
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
+import java.lang.reflect.Method;
import java.util.Properties;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.onap.ccsdk.sli.core.sli.provider.MdsalHelper;
-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.BindingAwareBroker;
import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
@@ -51,48 +54,43 @@ import org.opendaylight.yang.gen.v1.org.onap.a1.adapter.rev200122.PutA1PolicyInp
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.concepts.Builder;
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
- *
+ * This class implements the generated interface from the YANG model and implements the request model for the A1
+ * interface. This class identifies the Near-RT RIC throughout the IP passed over the payload and calls the
+ * corresponding Near-RT RIC over Rest API.
*/
@SuppressWarnings("squid:S1874") // "@Deprecated" code should not be used
public class A1AdapterProvider implements AutoCloseable, A1ADAPTERAPIService {
+ private static final String START_OPERATION_MESSAGE = "Start of {}";
+ private static final String END_OPERATION_MESSAGE = "End of {}";
+
private static final String A1_ADAPTER_API = "A1-ADAPTER-API";
private static final String RESPONSE_BODY = "responseBody";
private static final String RESPONSE_CODE = "response-code";
private static final String SYNC = "sync";
- private static final String ADDING_INPUT_DATA_MESSAGE = "Adding INPUT data for {} input: {}";
- private static final String A1_ADAPTER_CLIENT_GRAPH_MESSAGE = "A1AdapterClient has a Directed Graph for '{}'";
- private static final String SERVICE_EXCEPTION_MESSAGE = "Caught exception executing service logic for {}, {}";
- private static final String NO_SERVICE_LOGIC_ACTIVE_MESSAGE = "No service logic active for A1Adapter: '{}'";
- private static final String LOOKUP_SERVICE_LOGIC_EXCEPTION_MESSAGE = "Caught exception looking for service logic, {}";
-
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) {
+ public A1AdapterProvider(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;
@@ -105,10 +103,6 @@ public class A1AdapterProvider implements AutoCloseable, A1ADAPTERAPIService {
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);
@@ -118,192 +112,129 @@ public class A1AdapterProvider implements AutoCloseable, A1ADAPTERAPIService {
}
@Override
- public ListenableFuture<RpcResult<DeleteA1PolicyOutput>> deleteA1Policy(DeleteA1PolicyInput input) {
- log.info("Start of deleteA1Policy");
+ public ListenableFuture<RpcResult<DeleteA1PolicyOutput>> deleteA1Policy(DeleteA1PolicyInput deletePolicyInput) {
final String svcOperation = "deleteA1Policy";
- Properties parms = new Properties();
- DeleteA1PolicyOutputBuilder deleteResponse = new DeleteA1PolicyOutputBuilder();
- // add input to parms
- log.info(ADDING_INPUT_DATA_MESSAGE, svcOperation, input);
- DeleteA1PolicyInputBuilder inputBuilder = new DeleteA1PolicyInputBuilder(input);
- MdsalHelper.toProperties(parms, inputBuilder.build());
- logSliParameters(parms);
- // Call SLI sync method
- try {
- if (a1AdapterClient.hasGraph(A1_ADAPTER_API, svcOperation, null, SYNC)) {
- log.info(A1_ADAPTER_CLIENT_GRAPH_MESSAGE, svcOperation);
- try {
- Properties responseParms = a1AdapterClient.execute(A1_ADAPTER_API, svcOperation, null, SYNC, deleteResponse, parms);
- logResponse(responseParms);
- deleteResponse.setHttpStatus(Integer.valueOf(responseParms.getProperty(RESPONSE_CODE)));
- } catch (Exception e) {
- log.error(SERVICE_EXCEPTION_MESSAGE, svcOperation, e.getMessage());
- deleteResponse.setHttpStatus(500);
- }
- } else {
- log.error(NO_SERVICE_LOGIC_ACTIVE_MESSAGE, svcOperation);
- deleteResponse.setHttpStatus(503);
- }
- } catch (Exception e) {
- log.error(LOOKUP_SERVICE_LOGIC_EXCEPTION_MESSAGE, e.getMessage());
- deleteResponse.setHttpStatus(500);
- }
- RpcResult<DeleteA1PolicyOutput> rpcResult =
- RpcResultBuilder.<DeleteA1PolicyOutput>status(true).withResult(deleteResponse.build()).build();
- log.info("End of deleteA1Policy");
- return Futures.immediateFuture(rpcResult);
+ log.info(START_OPERATION_MESSAGE, svcOperation);
+ DeleteA1PolicyOutputBuilder deletePolicyResponse = new DeleteA1PolicyOutputBuilder();
+ setUpAndExecuteOperation(svcOperation, new DeleteA1PolicyInputBuilder(deletePolicyInput), deletePolicyResponse);
+
+ RpcResult<DeleteA1PolicyOutput> deletePolicyResult =
+ RpcResultBuilder.<DeleteA1PolicyOutput>status(true).withResult(deletePolicyResponse.build()).build();
+ log.info(END_OPERATION_MESSAGE, svcOperation);
+ return Futures.immediateFuture(deletePolicyResult);
}
@Override
- public ListenableFuture<RpcResult<GetA1PolicyOutput>> getA1Policy(GetA1PolicyInput input) {
- log.info("Start of getA1Policy");
+ public ListenableFuture<RpcResult<GetA1PolicyOutput>> getA1Policy(GetA1PolicyInput getPolicyInput) {
final String svcOperation = "getA1Policy";
- Properties parms = new Properties();
- GetA1PolicyOutputBuilder policyResponse = new GetA1PolicyOutputBuilder();
- // add input to parms
- log.info(ADDING_INPUT_DATA_MESSAGE, svcOperation, input);
- GetA1PolicyInputBuilder inputBuilder = new GetA1PolicyInputBuilder(input);
- MdsalHelper.toProperties(parms, inputBuilder.build());
- logSliParameters(parms);
- // Call SLI sync method
- try {
- if (a1AdapterClient.hasGraph(A1_ADAPTER_API, svcOperation, null, SYNC)) {
- log.info(A1_ADAPTER_CLIENT_GRAPH_MESSAGE, svcOperation);
- try {
- Properties responseParms = a1AdapterClient.execute(A1_ADAPTER_API, svcOperation, null, SYNC, policyResponse, parms);
- logResponse(responseParms);
- policyResponse.setBody(responseParms.getProperty(RESPONSE_BODY));
- policyResponse.setHttpStatus(Integer.valueOf(responseParms.getProperty(RESPONSE_CODE)));
- } catch (Exception e) {
- log.error(SERVICE_EXCEPTION_MESSAGE, svcOperation, e.getMessage());
- policyResponse.setHttpStatus(500);
- }
- } else {
- log.error(NO_SERVICE_LOGIC_ACTIVE_MESSAGE, svcOperation);
- policyResponse.setHttpStatus(503);
- }
- } catch (Exception e) {
- log.error(LOOKUP_SERVICE_LOGIC_EXCEPTION_MESSAGE, e.getMessage());
- policyResponse.setHttpStatus(500);
- }
- RpcResult<GetA1PolicyOutput> rpcResult =
- RpcResultBuilder.<GetA1PolicyOutput>status(true).withResult(policyResponse.build()).build();
- log.info("End of getA1Policy");
- return Futures.immediateFuture(rpcResult);
+ log.info(START_OPERATION_MESSAGE, svcOperation);
+ GetA1PolicyOutputBuilder getPolicyResponse = new GetA1PolicyOutputBuilder();
+ setUpAndExecuteOperation(svcOperation, new GetA1PolicyInputBuilder(getPolicyInput), getPolicyResponse);
+
+ RpcResult<GetA1PolicyOutput> getPolicyResult =
+ RpcResultBuilder.<GetA1PolicyOutput>status(true).withResult(getPolicyResponse.build()).build();
+ log.info(END_OPERATION_MESSAGE, svcOperation);
+ return Futures.immediateFuture(getPolicyResult);
}
@Override
- public ListenableFuture<RpcResult<GetA1PolicyStatusOutput>> getA1PolicyStatus(GetA1PolicyStatusInput input) {
- log.info("Start of getA1PolicyStatus");
+ public ListenableFuture<RpcResult<GetA1PolicyStatusOutput>> getA1PolicyStatus(
+ GetA1PolicyStatusInput getPolicyStatusInput) {
final String svcOperation = "getA1PolicyStatus";
- Properties parms = new Properties();
- GetA1PolicyStatusOutputBuilder policyStatusResponse = new GetA1PolicyStatusOutputBuilder();
- // add input to parms
- log.info(ADDING_INPUT_DATA_MESSAGE, svcOperation, input);
- GetA1PolicyStatusInputBuilder inputBuilder = new GetA1PolicyStatusInputBuilder(input);
- MdsalHelper.toProperties(parms, inputBuilder.build());
- logSliParameters(parms);
- // Call SLI sync method
- try {
- if (a1AdapterClient.hasGraph(A1_ADAPTER_API, svcOperation, null, SYNC)) {
- log.info(A1_ADAPTER_CLIENT_GRAPH_MESSAGE, svcOperation);
- try {
- Properties responseParms = a1AdapterClient.execute(A1_ADAPTER_API, svcOperation, null, SYNC, policyStatusResponse, parms);
- logResponse(responseParms);
- policyStatusResponse.setBody(responseParms.getProperty(RESPONSE_BODY));
- policyStatusResponse.setHttpStatus(Integer.valueOf(responseParms.getProperty(RESPONSE_CODE)));
- } catch (Exception e) {
- log.error(SERVICE_EXCEPTION_MESSAGE, svcOperation, e.getMessage());
- policyStatusResponse.setHttpStatus(500);
- }
- } else {
- log.error(NO_SERVICE_LOGIC_ACTIVE_MESSAGE, svcOperation);
- policyStatusResponse.setHttpStatus(503);
- }
- } catch (Exception e) {
- log.error(LOOKUP_SERVICE_LOGIC_EXCEPTION_MESSAGE, e.getMessage());
- policyStatusResponse.setHttpStatus(500);
- }
- RpcResult<GetA1PolicyStatusOutput> rpcResult =
- RpcResultBuilder.<GetA1PolicyStatusOutput>status(true).withResult(policyStatusResponse.build()).build();
- log.info("End of getA1PolicyStatus");
- return Futures.immediateFuture(rpcResult);
+ log.info(START_OPERATION_MESSAGE, svcOperation);
+ GetA1PolicyStatusOutputBuilder getPolicyStatusResponse = new GetA1PolicyStatusOutputBuilder();
+ setUpAndExecuteOperation(svcOperation, new GetA1PolicyStatusInputBuilder(getPolicyStatusInput),
+ getPolicyStatusResponse);
+
+ RpcResult<GetA1PolicyStatusOutput> getPolicyStatusResult =
+ RpcResultBuilder.<GetA1PolicyStatusOutput>status(true).withResult(getPolicyStatusResponse.build()).build();
+ log.info(END_OPERATION_MESSAGE, svcOperation);
+ return Futures.immediateFuture(getPolicyStatusResult);
}
@Override
- public ListenableFuture<RpcResult<GetA1PolicyTypeOutput>> getA1PolicyType(GetA1PolicyTypeInput input) {
- log.info("Start of getA1PolicyType");
+ public ListenableFuture<RpcResult<GetA1PolicyTypeOutput>> getA1PolicyType(GetA1PolicyTypeInput getPolicyTypeInput) {
final String svcOperation = "getA1PolicyType";
- Properties parms = new Properties();
- GetA1PolicyTypeOutputBuilder policyTypeResponse = new GetA1PolicyTypeOutputBuilder();
- // add input to parms
- log.info(ADDING_INPUT_DATA_MESSAGE, svcOperation, input);
- GetA1PolicyTypeInputBuilder inputBuilder = new GetA1PolicyTypeInputBuilder(input);
- MdsalHelper.toProperties(parms, inputBuilder.build());
- logSliParameters(parms);
- // Call SLI sync method
+ log.info(START_OPERATION_MESSAGE, svcOperation);
+ GetA1PolicyTypeOutputBuilder getPolicyTypeResponse = new GetA1PolicyTypeOutputBuilder();
+ setUpAndExecuteOperation(svcOperation, new GetA1PolicyTypeInputBuilder(getPolicyTypeInput),
+ getPolicyTypeResponse);
+
+ RpcResult<GetA1PolicyTypeOutput> getPolicyTypeResult =
+ RpcResultBuilder.<GetA1PolicyTypeOutput>status(true).withResult(getPolicyTypeResponse.build()).build();
+ log.info(END_OPERATION_MESSAGE, svcOperation);
+ return Futures.immediateFuture(getPolicyTypeResult);
+ }
+
+ @Override
+ public ListenableFuture<RpcResult<PutA1PolicyOutput>> putA1Policy(PutA1PolicyInput putPolicyInput) {
+ final String svcOperation = "putA1Policy";
+ log.info(START_OPERATION_MESSAGE, svcOperation);
+ PutA1PolicyOutputBuilder putPolicyResponse = new PutA1PolicyOutputBuilder();
+ setUpAndExecuteOperation(svcOperation, new PutA1PolicyInputBuilder(putPolicyInput), putPolicyResponse);
+
+ RpcResult<PutA1PolicyOutput> putPolicyResult =
+ RpcResultBuilder.<PutA1PolicyOutput>status(true).withResult(putPolicyResponse.build()).build();
+ log.info(END_OPERATION_MESSAGE, svcOperation);
+ return Futures.immediateFuture(putPolicyResult);
+ }
+
+ private <T> boolean hasGraph(final String svcOperation, Builder<T> response) {
try {
- if (a1AdapterClient.hasGraph(A1_ADAPTER_API, svcOperation, null, SYNC)) {
- log.info(A1_ADAPTER_CLIENT_GRAPH_MESSAGE, svcOperation);
- try {
- Properties responseParms = a1AdapterClient.execute(A1_ADAPTER_API, svcOperation, null, SYNC, policyTypeResponse, parms);
- logResponse(responseParms);
- policyTypeResponse.setBody(responseParms.getProperty(RESPONSE_BODY));
- policyTypeResponse.setHttpStatus(Integer.valueOf(responseParms.getProperty(RESPONSE_CODE)));
- } catch (Exception e) {
- log.error(SERVICE_EXCEPTION_MESSAGE, svcOperation, e.getMessage());
- policyTypeResponse.setHttpStatus(500);
- }
- } else {
- log.error(NO_SERVICE_LOGIC_ACTIVE_MESSAGE, svcOperation);
- policyTypeResponse.setHttpStatus(503);
- }
+ return a1AdapterClient.hasGraph(A1_ADAPTER_API, svcOperation, null, SYNC);
} catch (Exception e) {
- log.error(LOOKUP_SERVICE_LOGIC_EXCEPTION_MESSAGE, e.getMessage());
- policyTypeResponse.setHttpStatus(500);
+ log.error("Caught exception looking for service logic, {}", e.getMessage());
+ setHttpResponse(response, SC_INTERNAL_SERVER_ERROR);
}
- RpcResult<GetA1PolicyTypeOutput> rpcResult =
- RpcResultBuilder.<GetA1PolicyTypeOutput>status(true).withResult(policyTypeResponse.build()).build();
- log.info("End of getA1PolicyType");
- return Futures.immediateFuture(rpcResult);
+ return false;
}
- @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();
+ private <U, T> void setUpAndExecuteOperation(final String svcOperation, Builder<U> inputBuilder,
+ Builder<T> responseBuilder) {
+ log.info("Adding INPUT data for {} input: {}", svcOperation, inputBuilder);
// add input to parms
- log.info(ADDING_INPUT_DATA_MESSAGE, svcOperation, input);
- PutA1PolicyInputBuilder inputBuilder = new PutA1PolicyInputBuilder(input);
+ Properties parms = new Properties();
MdsalHelper.toProperties(parms, inputBuilder.build());
logSliParameters(parms);
// Call SLI sync method
+ if (hasGraph(svcOperation, responseBuilder)) {
+ log.info("A1AdapterClient has a Directed Graph for '{}'", svcOperation);
+ executeOperation(svcOperation, parms, responseBuilder);
+ } else {
+ log.error("No service logic active for A1Adapter: '{}'", svcOperation);
+ setHttpResponse(responseBuilder, Integer.valueOf(SC_SERVICE_UNAVAILABLE));
+ }
+ }
+
+ private <T> void executeOperation(final String svcOperation, Properties parms, Builder<T> response) {
try {
- if (a1AdapterClient.hasGraph(A1_ADAPTER_API, svcOperation, null, SYNC)) {
- log.info(A1_ADAPTER_CLIENT_GRAPH_MESSAGE, svcOperation);
- try {
- Properties responseParms = a1AdapterClient.execute(A1_ADAPTER_API, svcOperation, null, SYNC, policyResponse, parms);
- logResponse(responseParms);
- policyResponse.setBody(responseParms.getProperty(RESPONSE_BODY));
- policyResponse.setHttpStatus(Integer.valueOf(responseParms.getProperty(RESPONSE_CODE)));
- } catch (Exception e) {
- log.error(SERVICE_EXCEPTION_MESSAGE, svcOperation, e.getMessage());
- policyResponse.setHttpStatus(500);
- }
- } else {
- log.error(NO_SERVICE_LOGIC_ACTIVE_MESSAGE, svcOperation);
- policyResponse.setHttpStatus(503);
- }
+ Properties responseParms =
+ a1AdapterClient.execute(A1_ADAPTER_API, svcOperation, null, SYNC, response, parms);
+ logResponse(responseParms);
+ setBody(response, responseParms.getProperty(RESPONSE_BODY));
+ setHttpResponse(response, Integer.valueOf(responseParms.getProperty(RESPONSE_CODE)));
} catch (Exception e) {
- log.error(LOOKUP_SERVICE_LOGIC_EXCEPTION_MESSAGE, e.getMessage());
- policyResponse.setHttpStatus(500);
+ log.error("Caught exception executing service logic for {}, {}", svcOperation, e.getMessage());
+ setHttpResponse(response, Integer.valueOf(SC_INTERNAL_SERVER_ERROR));
+ }
+ }
+
+ private <T> void setBody(Builder<T> responseBuilder, String body) {
+ try {
+ Method method = responseBuilder.getClass().getMethod("setBody", String.class);
+ method.invoke(responseBuilder, body);
+ } catch (Exception reflectionException) {
+ throw new MissingResponseMethodRuntimeException(reflectionException);
+ }
+ }
+
+ private <T> void setHttpResponse(Builder<T> responseBuilder, Integer response) {
+ try {
+ Method method = responseBuilder.getClass().getMethod("setHttpStatus", Integer.class);
+ method.invoke(responseBuilder, response);
+ } catch (Exception reflectionException) {
+ throw new MissingResponseMethodRuntimeException(reflectionException);
}
- RpcResult<PutA1PolicyOutput> rpcResult =
- RpcResultBuilder.<PutA1PolicyOutput>status(true).withResult(policyResponse.build()).build();
- log.info("End of putA1Policy");
- return Futures.immediateFuture(rpcResult);
}
private void logSliParameters(Properties parms) {
@@ -320,4 +251,12 @@ public class A1AdapterProvider implements AutoCloseable, A1ADAPTERAPIService {
log.info("responseCode::{}", responseParms.getProperty(RESPONSE_CODE));
log.info("responseMessage::{}", responseParms.getProperty("response-message"));
}
+
+ public class MissingResponseMethodRuntimeException extends RuntimeException {
+ private static final long serialVersionUID = -6803869291161765099L;
+
+ MissingResponseMethodRuntimeException(Exception e) {
+ super(e);
+ }
+ }
}
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
index 5c4b2857..50f44f0a 100644
--- 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
@@ -20,17 +20,18 @@
package org.onap.ccsdk.features.a1.adapter;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.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.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.junit.jupiter.MockitoExtension;
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;
@@ -41,13 +42,8 @@ import org.opendaylight.yang.gen.v1.org.onap.a1.adapter.rev200122.PutA1PolicyOut
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-/**
- * This class Tests all the methods in A1AdapterClientTest
- *
- */
-
-@RunWith(MockitoJUnitRunner.Silent.class)
-public class A1AdapterClientTest {
+@ExtendWith(MockitoExtension.class)
+class A1AdapterClientTest {
protected static final Logger LOG = LoggerFactory.getLogger(A1AdapterClientTest.class);
@@ -57,13 +53,13 @@ public class A1AdapterClientTest {
private static String module = "A1-ADAPTER-API";
private static String mode = "sync";
- @Before
- public void setUp() throws Exception {
+ @BeforeEach
+ void setUp() {
a1AdapterClient = new A1AdapterClient(svcLogicService);
}
@Test
- public void test_execute_getPolicyType() throws SvcLogicException, InterruptedException, ExecutionException {
+ void getPolicyType() throws Exception {
String rpc = "deleteA1Policy";
Properties params = new Properties();
Properties respProps = new Properties();
@@ -75,7 +71,7 @@ public class A1AdapterClientTest {
}
@Test
- public void test_execute_getPolicyStatus() throws SvcLogicException, InterruptedException, ExecutionException {
+ void getPolicyStatus() throws Exception {
String rpc = "getA1PolicyStatus";
Properties params = new Properties();
Properties respProps = new Properties();
@@ -87,7 +83,7 @@ public class A1AdapterClientTest {
}
@Test
- public void test_execute_getPolicy() throws SvcLogicException, InterruptedException, ExecutionException {
+ void getPolicy() throws Exception {
String rpc = "getA1Policy";
Properties params = new Properties();
Properties respProps = new Properties();
@@ -99,7 +95,7 @@ public class A1AdapterClientTest {
}
@Test
- public void test_execute_deletePolicy() throws SvcLogicException, InterruptedException, ExecutionException {
+ void deletePolicy() throws Exception {
String rpc = "deleteA1Policy";
Properties params = new Properties();
Properties respProps = new Properties();
@@ -111,7 +107,7 @@ public class A1AdapterClientTest {
}
@Test
- public void test_execute_putPolicy() throws SvcLogicException, InterruptedException, ExecutionException {
+ void putPolicy() throws Exception {
String rpc = "putA1Policy";
Properties params = new Properties();
Properties respProps = new Properties();
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 a6588ea8..96bad81b 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
@@ -20,64 +20,45 @@
package org.onap.ccsdk.features.a1.adapter;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.when;
+
import com.google.common.util.concurrent.ListenableFuture;
import java.util.Properties;
-import java.util.concurrent.ExecutionException;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.Mockito;
-import org.mockito.junit.MockitoJUnitRunner;
-import org.onap.ccsdk.sli.core.sli.SvcLogicException;
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.mockito.junit.jupiter.MockitoExtension;
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.concepts.Builder;
import org.opendaylight.yangtools.yang.common.RpcResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-/**
- * This class Tests all the methods in A1AdapterProvider
- *
- */
+@ExtendWith(MockitoExtension.class)
+class A1AdapterProviderTest {
-@RunWith(MockitoJUnitRunner.Silent.class)
-public class A1AdapterProviderTest {
+ private static final String RESPONSE_CODE = "response-code";
+ private static final String OK_RESPONSE = "200";
protected static final Logger LOG = LoggerFactory.getLogger(A1AdapterProviderTest.class);
- class A1AdapterProviderMock extends A1AdapterProvider {
-
- 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;
+ private A1AdapterProvider a1AdapterProviderMock = null;
@Mock
private NotificationPublishService mockNotificationPublishService;
@Mock
@@ -87,80 +68,82 @@ public class A1AdapterProviderTest {
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);
-
+ @BeforeEach
+ void setUp() {
+ a1AdapterProviderMock = Mockito.spy(new A1AdapterProvider(mockNotificationPublishService,
+ mockRpcProviderRegistry, a1AdapterClient));
}
@Test
- public void test_deleteA1PolicyType() throws SvcLogicException, InterruptedException, ExecutionException {
+ void deleteA1PolicyType() throws Exception {
String rpc = "deleteA1Policy";
Properties respProps = new Properties();
- respProps.setProperty("response-code", "200");
+ respProps.setProperty(RESPONSE_CODE, OK_RESPONSE);
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);
+ when(
+ a1AdapterClient.execute(eq(module), eq(rpc), eq(null), eq(mode), any(Builder.class), any(Properties.class)))
+ .thenReturn(respProps);
ListenableFuture<RpcResult<DeleteA1PolicyOutput>> result =
- a1AdapterProviderMock.deleteA1Policy(inputBuilder.build());
- assertEquals("200", String.valueOf(result.get().getResult().getHttpStatus()));
+ a1AdapterProviderMock.deleteA1Policy(inputBuilder.build());
+ assertEquals(OK_RESPONSE, String.valueOf(result.get().getResult().getHttpStatus()));
}
@Test
- public void test_getA1Policy() throws SvcLogicException, InterruptedException, ExecutionException {
+ void getA1Policy() throws Exception {
String rpc = "getA1Policy";
Properties respProps = new Properties();
- respProps.setProperty("response-code", "200");
+ respProps.setProperty(RESPONSE_CODE, OK_RESPONSE);
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);
+ when(
+ a1AdapterClient.execute(eq(module), eq(rpc), eq(null), eq(mode), any(Builder.class), any(Properties.class)))
+ .thenReturn(respProps);
ListenableFuture<RpcResult<GetA1PolicyOutput>> result = a1AdapterProviderMock.getA1Policy(inputBuilder.build());
- assertEquals("200", String.valueOf(result.get().getResult().getHttpStatus()));
+ assertEquals(OK_RESPONSE, String.valueOf(result.get().getResult().getHttpStatus()));
}
@Test
- public void test_getA1PolicyType() throws SvcLogicException, InterruptedException, ExecutionException {
+ void getA1PolicyType() throws Exception {
String rpc = "getA1PolicyType";
Properties respProps = new Properties();
- respProps.setProperty("response-code", "200");
+ respProps.setProperty(RESPONSE_CODE, OK_RESPONSE);
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);
+ when(
+ a1AdapterClient.execute(eq(module), eq(rpc), eq(null), eq(mode), any(Builder.class), any(Properties.class)))
+ .thenReturn(respProps);
ListenableFuture<RpcResult<GetA1PolicyTypeOutput>> result =
- a1AdapterProviderMock.getA1PolicyType(inputBuilder.build());
- assertEquals("200", String.valueOf(result.get().getResult().getHttpStatus()));
+ a1AdapterProviderMock.getA1PolicyType(inputBuilder.build());
+ assertEquals(OK_RESPONSE, String.valueOf(result.get().getResult().getHttpStatus()));
}
@Test
- public void test_getA1PolicyStatus() throws SvcLogicException, InterruptedException, ExecutionException {
+ void getA1PolicyStatus() throws Exception {
String rpc = "getA1PolicyStatus";
Properties respProps = new Properties();
- respProps.setProperty("response-code", "200");
+ respProps.setProperty(RESPONSE_CODE, OK_RESPONSE);
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);
+ when(
+ a1AdapterClient.execute(eq(module), eq(rpc), eq(null), eq(mode), any(Builder.class), any(Properties.class)))
+ .thenReturn(respProps);
ListenableFuture<RpcResult<GetA1PolicyStatusOutput>> result =
- a1AdapterProviderMock.getA1PolicyStatus(inputBuilder.build());
- assertEquals("200", String.valueOf(result.get().getResult().getHttpStatus()));
+ a1AdapterProviderMock.getA1PolicyStatus(inputBuilder.build());
+ assertEquals(OK_RESPONSE, String.valueOf(result.get().getResult().getHttpStatus()));
}
@Test
- public void test_putA1Policy() throws SvcLogicException, InterruptedException, ExecutionException {
+ void putA1Policy() throws Exception {
String rpc = "putA1Policy";
Properties respProps = new Properties();
- respProps.setProperty("response-code", "200");
+ respProps.setProperty(RESPONSE_CODE, OK_RESPONSE);
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);
+ when(
+ a1AdapterClient.execute(eq(module), eq(rpc), eq(null), eq(mode), any(Builder.class), any(Properties.class)))
+ .thenReturn(respProps);
ListenableFuture<RpcResult<PutA1PolicyOutput>> result = a1AdapterProviderMock.putA1Policy(inputBuilder.build());
- assertEquals("200", String.valueOf(result.get().getResult().getHttpStatus()));
+ assertEquals(OK_RESPONSE, String.valueOf(result.get().getResult().getHttpStatus()));
}
}