X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsamples%2Fclustering-test-app%2Fprovider%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fclustering%2Fit%2Fprovider%2FMdsalLowLevelTestProvider.java;h=c5427bef595e355983658c2946c6fbb5953951be;hb=e2607370f5ac443a5a2f1f00f693f82a0b57161d;hp=688e7c0a51dab318a2fbb17f62d3e92980ac924e;hpb=8ad63ef6b2f81a098c66eabf4d04d7b216c1a9dd;p=controller.git diff --git a/opendaylight/md-sal/samples/clustering-test-app/provider/src/main/java/org/opendaylight/controller/clustering/it/provider/MdsalLowLevelTestProvider.java b/opendaylight/md-sal/samples/clustering-test-app/provider/src/main/java/org/opendaylight/controller/clustering/it/provider/MdsalLowLevelTestProvider.java index 688e7c0a51..c5427bef59 100644 --- a/opendaylight/md-sal/samples/clustering-test-app/provider/src/main/java/org/opendaylight/controller/clustering/it/provider/MdsalLowLevelTestProvider.java +++ b/opendaylight/md-sal/samples/clustering-test-app/provider/src/main/java/org/opendaylight/controller/clustering/it/provider/MdsalLowLevelTestProvider.java @@ -26,8 +26,10 @@ import java.io.StringWriter; import java.util.Collections; import java.util.HashMap; import java.util.Map; +import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; import org.opendaylight.controller.cluster.ActorSystemProvider; import org.opendaylight.controller.cluster.databroker.actors.dds.ClientLocalHistory; import org.opendaylight.controller.cluster.databroker.actors.dds.ClientTransaction; @@ -135,17 +137,17 @@ public class MdsalLowLevelTestProvider implements OdlMdsalLowlevelControlService private final DOMDataTreeChangeService domDataTreeChangeService; private final ActorSystem actorSystem; - private Map, DOMRpcImplementationRegistration> routedRegistrations = - new HashMap<>(); + private final Map, DOMRpcImplementationRegistration> + routedRegistrations = new HashMap<>(); - private Map> ynlRegistrations = new HashMap<>(); + private final Map> ynlRegistrations = new HashMap<>(); private DOMRpcImplementationRegistration globalGetConstantRegistration = null; private ClusterSingletonServiceRegistration getSingletonConstantRegistration; private FlappingSingletonService flappingSingletonService; private ListenerRegistration dtclReg; private IdIntsListener idIntsListener; - private Map publishNotificationsTasks = new HashMap<>(); + private final Map publishNotificationsTasks = new HashMap<>(); private ListenerRegistration ddtlReg; private IdIntsDOMDataTreeLIstener idIntsDdtl; @@ -188,13 +190,14 @@ public class MdsalLowLevelTestProvider implements OdlMdsalLowlevelControlService } @Override + @SuppressWarnings("checkstyle:IllegalCatch") public Future> unregisterSingletonConstant() { LOG.debug("unregister-singleton-constant"); if (getSingletonConstantRegistration == null) { LOG.debug("No get-singleton-constant registration present."); - final RpcError rpcError = RpcResultBuilder - .newError(ErrorType.APPLICATION, "missing-registration", "No get-singleton-constant rpc registration present."); + final RpcError rpcError = RpcResultBuilder.newError(ErrorType.APPLICATION, "missing-registration", + "No get-singleton-constant rpc registration present."); final RpcResult result = RpcResultBuilder.failed().withRpcError(rpcError).build(); return Futures.immediateFuture(result); } @@ -204,10 +207,10 @@ public class MdsalLowLevelTestProvider implements OdlMdsalLowlevelControlService getSingletonConstantRegistration = null; return Futures.immediateFuture(RpcResultBuilder.success().build()); - } catch (final Exception e) { + } catch (Exception e) { LOG.debug("There was a problem closing the singleton constant service", e); - final RpcError rpcError = RpcResultBuilder - .newError(ErrorType.APPLICATION, "error-closing", "There was a problem closing get-singleton-constant"); + final RpcError rpcError = RpcResultBuilder.newError(ErrorType.APPLICATION, "error-closing", + "There was a problem closing get-singleton-constant"); final RpcResult result = RpcResultBuilder.failed().withRpcError(rpcError).build(); return Futures.immediateFuture(result); } @@ -250,13 +253,7 @@ public class MdsalLowLevelTestProvider implements OdlMdsalLowlevelControlService @Override public Future> writeTransactions(final WriteTransactionsInput input) { LOG.debug("write-transactions, input: {}", input); - - final WriteTransactionsHandler writeTransactionsHandler = new WriteTransactionsHandler(domDataBroker, input); - - final SettableFuture> settableFuture = SettableFuture.create(); - writeTransactionsHandler.start(settableFuture); - - return settableFuture; + return WriteTransactionsHandler.start(domDataBroker, input); } @Override @@ -265,7 +262,7 @@ public class MdsalLowLevelTestProvider implements OdlMdsalLowlevelControlService } @Override - public Future> removeShardReplica(RemoveShardReplicaInput input) { + public Future> removeShardReplica(final RemoveShardReplicaInput input) { return null; } @@ -304,18 +301,18 @@ public class MdsalLowLevelTestProvider implements OdlMdsalLowlevelControlService public Future> unregisterBoundConstant(final UnregisterBoundConstantInput input) { LOG.debug("unregister-bound-constant, {}", input); - final DOMRpcImplementationRegistration registration = + final DOMRpcImplementationRegistration rpcRegistration = routedRegistrations.remove(input.getContext()); - if (registration == null) { + if (rpcRegistration == null) { LOG.debug("No get-contexted-constant registration for context: {}", input.getContext()); - final RpcError rpcError = RpcResultBuilder - .newError(ErrorType.APPLICATION, "missing-registration", "No get-constant rpc registration present."); + final RpcError rpcError = RpcResultBuilder.newError(ErrorType.APPLICATION, "missing-registration", + "No get-constant rpc registration present."); final RpcResult result = RpcResultBuilder.failed().withRpcError(rpcError).build(); return Futures.immediateFuture(result); } - registration.close(); + rpcRegistration.close(); return Futures.immediateFuture(RpcResultBuilder.success().build()); } @@ -337,7 +334,7 @@ public class MdsalLowLevelTestProvider implements OdlMdsalLowlevelControlService } @Override - public Future> registerDefaultConstant(RegisterDefaultConstantInput input) { + public Future> registerDefaultConstant(final RegisterDefaultConstantInput input) { return null; } @@ -345,8 +342,8 @@ public class MdsalLowLevelTestProvider implements OdlMdsalLowlevelControlService public Future> unregisterConstant() { if (globalGetConstantRegistration == null) { - final RpcError rpcError = RpcResultBuilder - .newError(ErrorType.APPLICATION, "missing-registration", "No get-constant rpc registration present."); + final RpcError rpcError = RpcResultBuilder.newError(ErrorType.APPLICATION, "missing-registration", + "No get-constant rpc registration present."); final RpcResult result = RpcResultBuilder.failed().withRpcError(rpcError).build(); return Futures.immediateFuture(result); } @@ -362,8 +359,8 @@ public class MdsalLowLevelTestProvider implements OdlMdsalLowlevelControlService LOG.debug("unregister-flapping-singleton received."); if (flappingSingletonService == null) { - final RpcError rpcError = RpcResultBuilder - .newError(ErrorType.APPLICATION, "missing-registration", "No flapping-singleton registration present."); + final RpcError rpcError = RpcResultBuilder.newError(ErrorType.APPLICATION, "missing-registration", + "No flapping-singleton registration present."); final RpcResult result = RpcResultBuilder.failed().withRpcError(rpcError).build(); return Futures.immediateFuture(result); @@ -379,7 +376,7 @@ public class MdsalLowLevelTestProvider implements OdlMdsalLowlevelControlService } @Override - public Future> addShardReplica(AddShardReplicaInput input) { + public Future> addShardReplica(final AddShardReplicaInput input) { return null; } @@ -395,11 +392,10 @@ public class MdsalLowLevelTestProvider implements OdlMdsalLowlevelControlService idIntsDdtl = new IdIntsDOMDataTreeLIstener(); try { - ddtlReg = - domDataTreeService.registerListener(idIntsDdtl, - Collections.singleton(new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, - ProduceTransactionsHandler.ID_INT_YID)) - , true, Collections.emptyList()); + ddtlReg = domDataTreeService.registerListener(idIntsDdtl, + Collections.singleton(new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, + ProduceTransactionsHandler.ID_INT_YID)), + true, Collections.emptyList()); } catch (DOMDataTreeLoopException e) { LOG.error("Failed to register DOMDataTreeListener.", e); @@ -430,11 +426,11 @@ public class MdsalLowLevelTestProvider implements OdlMdsalLowlevelControlService return Futures.immediateFuture(RpcResultBuilder.failed().withRpcError(error).build()); } - final DOMRpcImplementationRegistration registration = + final DOMRpcImplementationRegistration rpcRegistration = RoutedGetConstantService.registerNew(bindingNormalizedNodeSerializer, domRpcService, input.getConstant(), input.getContext()); - routedRegistrations.put(input.getContext(), registration); + routedRegistrations.put(input.getContext(), rpcRegistration); return Futures.immediateFuture(RpcResultBuilder.success().build()); } @@ -460,7 +456,17 @@ public class MdsalLowLevelTestProvider implements OdlMdsalLowlevelControlService if (idIntsListener == null || dtclReg == null) { final RpcError error = RpcResultBuilder.newError( ErrorType.RPC, "Dtcl missing.", "No DataTreeChangeListener registered."); - return Futures.immediateFuture(RpcResultBuilder.failed().withRpcError(error).build()); + return Futures.immediateFuture(RpcResultBuilder.failed() + .withRpcError(error).build()); + } + + try { + idIntsListener.tryFinishProcessing().get(120, TimeUnit.SECONDS); + } catch (InterruptedException | ExecutionException | TimeoutException e) { + final RpcError error = RpcResultBuilder.newError(ErrorType.RPC, "resource-denied-transport", + "Unable to finish notification processing in 120 seconds.", "clustering-it", "clustering-it", e); + return Futures.immediateFuture(RpcResultBuilder.failed() + .withRpcError(error).build()); } dtclReg.close(); @@ -468,8 +474,8 @@ public class MdsalLowLevelTestProvider implements OdlMdsalLowlevelControlService if (!idIntsListener.hasTriggered()) { final RpcError error = RpcResultBuilder.newError( - ErrorType.APPLICATION, "No notification received.", "id-ints listener has not received" + - "any notifications."); + ErrorType.APPLICATION, "No notification received.", "id-ints listener has not received" + + "any notifications."); return Futures.immediateFuture(RpcResultBuilder.failed() .withRpcError(error).build()); } @@ -516,17 +522,17 @@ public class MdsalLowLevelTestProvider implements OdlMdsalLowlevelControlService LOG.debug("Received unsubscribe-ynl, input: {}", input); if (!ynlRegistrations.containsKey(input.getId())) { - final RpcError rpcError = RpcResultBuilder - .newError(ErrorType.APPLICATION, "missing-registration", "No ynl listener with this id registered."); + final RpcError rpcError = RpcResultBuilder.newError(ErrorType.APPLICATION, "missing-registration", + "No ynl listener with this id registered."); final RpcResult result = RpcResultBuilder.failed().withRpcError(rpcError).build(); return Futures.immediateFuture(result); } - final ListenerRegistration registration = ynlRegistrations.remove(input.getId()); - final UnsubscribeYnlOutput output = registration.getInstance().getOutput(); + final ListenerRegistration reg = ynlRegistrations.remove(input.getId()); + final UnsubscribeYnlOutput output = reg.getInstance().getOutput(); - registration.close(); + reg.close(); return Futures.immediateFuture(RpcResultBuilder.success().withResult(output).build()); } @@ -548,7 +554,7 @@ public class MdsalLowLevelTestProvider implements OdlMdsalLowlevelControlService if (task.getLastError() != null) { final StringWriter sw = new StringWriter(); final PrintWriter pw = new PrintWriter(sw); - task.getLastError().printStackTrace(pw); + LOG.error("Last error for {}", task, task.getLastError()); checkPublishNotificationsOutputBuilder.setLastError(task.getLastError().toString() + sw.toString()); } @@ -561,14 +567,7 @@ public class MdsalLowLevelTestProvider implements OdlMdsalLowlevelControlService @Override public Future> produceTransactions(final ProduceTransactionsInput input) { LOG.debug("producer-transactions, input: {}", input); - - final ProduceTransactionsHandler handler = - new ProduceTransactionsHandler(domDataTreeService, input); - - final SettableFuture> settableFuture = SettableFuture.create(); - handler.start(settableFuture); - - return settableFuture; + return ProduceTransactionsHandler.start(domDataTreeService, input); } @Override @@ -589,7 +588,7 @@ public class MdsalLowLevelTestProvider implements OdlMdsalLowlevelControlService public Future> shutdownPrefixShardReplica(final ShutdownPrefixShardReplicaInput input) { LOG.debug("Received shutdown-prefix-shard-replica rpc, input: {}", input); - final InstanceIdentifier shardPrefix = input.getPrefix(); + final InstanceIdentifier shardPrefix = input.getPrefix(); if (shardPrefix == null) { final RpcError rpcError = RpcResultBuilder.newError(ErrorType.APPLICATION, "bad-element", @@ -667,13 +666,24 @@ public class MdsalLowLevelTestProvider implements OdlMdsalLowlevelControlService } @Override + @SuppressWarnings("checkstyle:IllegalCatch") public Future> unsubscribeDdtl() { LOG.debug("Received unsubscribe-ddtl."); if (idIntsDdtl == null || ddtlReg == null) { final RpcError error = RpcResultBuilder.newError( ErrorType.RPC, "Ddtl missing.", "No DOMDataTreeListener registered."); - return Futures.immediateFuture(RpcResultBuilder.failed().withRpcError(error).build()); + return Futures.immediateFuture(RpcResultBuilder.failed() + .withRpcError(error).build()); + } + + try { + idIntsDdtl.tryFinishProcessing().get(120, TimeUnit.SECONDS); + } catch (InterruptedException | ExecutionException | TimeoutException e) { + final RpcError error = RpcResultBuilder.newError(ErrorType.RPC, "resource-denied-transport", + "Unable to finish notification processing in 120 seconds.", "clustering-it", "clustering-it", e); + return Futures.immediateFuture(RpcResultBuilder.failed() + .withRpcError(error).build()); } ddtlReg.close(); @@ -681,8 +691,8 @@ public class MdsalLowLevelTestProvider implements OdlMdsalLowlevelControlService if (!idIntsDdtl.hasTriggered()) { final RpcError error = RpcResultBuilder.newError( - ErrorType.APPLICATION, "No notification received.", "id-ints listener has not received" + - "any notifications."); + ErrorType.APPLICATION, "No notification received.", "id-ints listener has not received" + + "any notifications."); return Futures.immediateFuture(RpcResultBuilder.failed() .withRpcError(error).build()); } @@ -700,7 +710,7 @@ public class MdsalLowLevelTestProvider implements OdlMdsalLowlevelControlService try { distributedDataStoreClient = SimpleDataStoreClientActor .getDistributedDataStoreClient(clientActor, 30, TimeUnit.SECONDS); - } catch (final Exception e) { + } catch (RuntimeException e) { LOG.error("Failed to get actor for {}", distributedDataStoreClientProps, e); clientActor.tell(PoisonPill.getInstance(), noSender()); final RpcError error = RpcResultBuilder.newError(