X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsamples%2Fclustering-test-app%2Fprovider%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fclustering%2Fit%2Fprovider%2FMdsalLowLevelTestProvider.java;h=bae07376cfa824422570a179c9c070f0b348ea56;hp=0c0a3b241089b8da2eb4110471fa5c13736f7bb2;hb=3d015d355cda26098cf70ac6f123f437ed8a175c;hpb=7e62b4a59f9e43bcd0585845f1aeb55c44199f27 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 0c0a3b2410..bae07376cf 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 @@ -144,7 +144,6 @@ import org.opendaylight.yang.gen.v1.tag.opendaylight.org._2017.controller.yang.l import org.opendaylight.yang.gen.v1.tag.opendaylight.org._2017.controller.yang.lowlevel.control.rev170215.WriteTransactionsOutput; import org.opendaylight.yangtools.concepts.ListenerRegistration; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.opendaylight.yangtools.yang.common.RpcError; import org.opendaylight.yangtools.yang.common.RpcError.ErrorType; import org.opendaylight.yangtools.yang.common.RpcResult; import org.opendaylight.yangtools.yang.common.RpcResultBuilder; @@ -233,37 +232,30 @@ public class MdsalLowLevelTestProvider implements OdlMdsalLowlevelControlService @SuppressWarnings("checkstyle:IllegalCatch") public ListenableFuture> unregisterSingletonConstant( final UnregisterSingletonConstantInput input) { - LOG.debug("unregister-singleton-constant"); + LOG.info("In unregisterSingletonConstant"); 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 RpcResult result = - RpcResultBuilder.failed().withRpcError(rpcError).build(); - return Futures.immediateFuture(result); + return RpcResultBuilder.failed().withError(ErrorType.RPC, "data-missing", + "No prior RPC was registered").buildFuture(); } try { getSingletonConstantRegistration.close(); getSingletonConstantRegistration = null; - return Futures.immediateFuture(RpcResultBuilder.success( - new UnregisterSingletonConstantOutputBuilder().build()).build()); + return RpcResultBuilder.success(new UnregisterSingletonConstantOutputBuilder().build()).buildFuture(); } 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 RpcResult result = - RpcResultBuilder.failed().withRpcError(rpcError).build(); - return Futures.immediateFuture(result); + String msg = "Error closing the singleton constant service"; + LOG.error(msg, e); + return RpcResultBuilder.failed().withError( + ErrorType.APPLICATION, msg, e).buildFuture(); } } @Override public ListenableFuture> startPublishNotifications( final StartPublishNotificationsInput input) { - LOG.debug("publish-notifications, input: {}", input); + LOG.info("In startPublishNotifications - input: {}", input); final PublishNotificationsTask task = new PublishNotificationsTask(notificationPublishService, input.getId(), input.getSeconds(), input.getNotificationsPerSecond()); @@ -272,17 +264,16 @@ public class MdsalLowLevelTestProvider implements OdlMdsalLowlevelControlService task.start(); - return Futures.immediateFuture(RpcResultBuilder.success(new StartPublishNotificationsOutputBuilder().build()) - .build()); + return RpcResultBuilder.success(new StartPublishNotificationsOutputBuilder().build()).buildFuture(); } @Override public ListenableFuture> subscribeDtcl(final SubscribeDtclInput input) { + LOG.info("In subscribeDtcl - input: {}", input); if (dtclReg != null) { - final RpcError error = RpcResultBuilder.newError(ErrorType.RPC, "Registration present.", - "There is already dataTreeChangeListener registered on id-ints list."); - return Futures.immediateFuture(RpcResultBuilder.failed().withRpcError(error).build()); + return RpcResultBuilder.failed().withError(ErrorType.RPC, + "data-exists", "There is already a DataTreeChangeListener registered for id-ints").buildFuture(); } idIntsListener = new IdIntsListener(); @@ -293,12 +284,11 @@ public class MdsalLowLevelTestProvider implements OdlMdsalLowlevelControlService CONTROLLER_CONFIG, WriteTransactionsHandler.ID_INT_YID), idIntsListener); - return Futures.immediateFuture(RpcResultBuilder.success(new SubscribeDtclOutputBuilder().build()).build()); + return RpcResultBuilder.success(new SubscribeDtclOutputBuilder().build()).buildFuture(); } @Override public ListenableFuture> writeTransactions(final WriteTransactionsInput input) { - LOG.debug("write-transactions, input: {}", input); return WriteTransactionsHandler.start(domDataBroker, input); } @@ -315,24 +305,22 @@ public class MdsalLowLevelTestProvider implements OdlMdsalLowlevelControlService @Override public ListenableFuture> subscribeYnl(final SubscribeYnlInput input) { - - LOG.debug("subscribe-ynl, input: {}", input); + LOG.info("In subscribeYnl - input: {}", input); if (ynlRegistrations.containsKey(input.getId())) { - final RpcError error = RpcResultBuilder.newError(ErrorType.RPC, "Registration present.", - "There is already ynl listener registered for this id: " + input.getId()); - return Futures.immediateFuture(RpcResultBuilder.failed().withRpcError(error).build()); + return RpcResultBuilder.failed().withError(ErrorType.RPC, + "data-exists", "There is already a listener registered for id: " + input.getId()).buildFuture(); } ynlRegistrations.put(input.getId(), notificationService.registerNotificationListener(new YnlListener(input.getId()))); - return Futures.immediateFuture(RpcResultBuilder.success(new SubscribeYnlOutputBuilder().build()).build()); + return RpcResultBuilder.success(new SubscribeYnlOutputBuilder().build()).buildFuture(); } @Override public ListenableFuture> removePrefixShard(final RemovePrefixShardInput input) { - LOG.debug("remove-prefix-shard, input: {}", input); + LOG.info("In removePrefixShard - input: {}", input); return prefixShardHandler.onRemovePrefixShard(input); } @@ -340,7 +328,7 @@ public class MdsalLowLevelTestProvider implements OdlMdsalLowlevelControlService @Override public ListenableFuture> becomePrefixLeader( final BecomePrefixLeaderInput input) { - LOG.debug("become-prefix-leader, input: {}", input); + LOG.info("n becomePrefixLeader - input: {}", input); return prefixLeaderHandler.makeLeaderLocal(input); } @@ -348,43 +336,34 @@ public class MdsalLowLevelTestProvider implements OdlMdsalLowlevelControlService @Override public ListenableFuture> unregisterBoundConstant( final UnregisterBoundConstantInput input) { - LOG.debug("unregister-bound-constant, {}", input); + LOG.info("In unregisterBoundConstant - {}", input); final DOMRpcImplementationRegistration rpcRegistration = routedRegistrations.remove(input.getContext()); 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 RpcResult result = - RpcResultBuilder.failed().withRpcError(rpcError).build(); - return Futures.immediateFuture(result); + return RpcResultBuilder.failed().withError( + ErrorType.RPC, "data-missing", "No prior RPC was registered for " + input.getContext()).buildFuture(); } rpcRegistration.close(); - return Futures.immediateFuture(RpcResultBuilder.success(new UnregisterBoundConstantOutputBuilder().build()) - .build()); + return RpcResultBuilder.success(new UnregisterBoundConstantOutputBuilder().build()).buildFuture(); } @Override public ListenableFuture> registerSingletonConstant( final RegisterSingletonConstantInput input) { - - LOG.debug("Received register-singleton-constant rpc, input: {}", input); + LOG.info("In registerSingletonConstant - input: {}", input); if (input.getConstant() == null) { - final RpcError error = RpcResultBuilder.newError( - ErrorType.RPC, "Invalid input.", "Constant value is null"); - return Futures.immediateFuture(RpcResultBuilder.failed() - .withRpcError(error).build()); + return RpcResultBuilder.failed().withError( + ErrorType.RPC, "invalid-value", "Constant value is null").buildFuture(); } getSingletonConstantRegistration = SingletonGetConstantService.registerNew(singletonService, domRpcService, input.getConstant()); - return Futures.immediateFuture(RpcResultBuilder.success(new RegisterSingletonConstantOutputBuilder().build()) - .build()); + return RpcResultBuilder.success(new RegisterSingletonConstantOutputBuilder().build()).buildFuture(); } @Override @@ -396,12 +375,11 @@ public class MdsalLowLevelTestProvider implements OdlMdsalLowlevelControlService @Override public ListenableFuture> unregisterConstant( final UnregisterConstantInput input) { + LOG.info("In unregisterConstant"); if (globalGetConstantRegistration == null) { - final RpcError rpcError = RpcResultBuilder.newError(ErrorType.APPLICATION, "missing-registration", - "No get-constant rpc registration present."); - return Futures.immediateFuture(RpcResultBuilder.failed().withRpcError(rpcError) - .build()); + return RpcResultBuilder.failed().withError( + ErrorType.RPC, "data-missing", "No prior RPC was registered").buildFuture(); } globalGetConstantRegistration.close(); @@ -413,23 +391,18 @@ public class MdsalLowLevelTestProvider implements OdlMdsalLowlevelControlService @Override public ListenableFuture> unregisterFlappingSingleton( final UnregisterFlappingSingletonInput input) { - LOG.debug("unregister-flapping-singleton received."); + LOG.info("In unregisterFlappingSingleton"); if (flappingSingletonService == null) { - 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); + return RpcResultBuilder.failed().withError( + ErrorType.RPC, "data-missing", "No prior RPC was registered").buildFuture(); } final long flapCount = flappingSingletonService.setInactive(); flappingSingletonService = null; - final UnregisterFlappingSingletonOutput output = - new UnregisterFlappingSingletonOutputBuilder().setFlapCount(flapCount).build(); - - return Futures.immediateFuture(RpcResultBuilder.success(output).build()); + return RpcResultBuilder.success(new UnregisterFlappingSingletonOutputBuilder().setFlapCount(flapCount).build()) + .buildFuture(); } @Override @@ -439,11 +412,11 @@ public class MdsalLowLevelTestProvider implements OdlMdsalLowlevelControlService @Override public ListenableFuture> subscribeDdtl(final SubscribeDdtlInput input) { + LOG.info("In subscribeDdtl"); if (ddtlReg != null) { - final RpcError error = RpcResultBuilder.newError(ErrorType.RPC, "Registration present.", - "There is already dataTreeChangeListener registered on id-ints list."); - return Futures.immediateFuture(RpcResultBuilder.failed().withRpcError(error).build()); + return RpcResultBuilder.failed().withError(ErrorType.RPC, + "data-exists", "There is already a listener registered for id-ints").buildFuture(); } idIntsDdtl = new IdIntsDOMDataTreeLIstener(); @@ -454,36 +427,32 @@ public class MdsalLowLevelTestProvider implements OdlMdsalLowlevelControlService ProduceTransactionsHandler.ID_INT_YID)), true, Collections.emptyList()); } catch (DOMDataTreeLoopException e) { - LOG.error("Failed to register DOMDataTreeListener.", e); + LOG.error("Failed to register DOMDataTreeListener", e); + return RpcResultBuilder.failed().withError( + ErrorType.APPLICATION, "Failed to register DOMDataTreeListener", e).buildFuture(); } - return Futures.immediateFuture(RpcResultBuilder.success(new SubscribeDdtlOutputBuilder().build()).build()); + return RpcResultBuilder.success(new SubscribeDdtlOutputBuilder().build()).buildFuture(); } @Override public ListenableFuture> registerBoundConstant( final RegisterBoundConstantInput input) { - LOG.debug("register-bound-constant: {}", input); + LOG.info("In registerBoundConstant - input: {}", input); if (input.getContext() == null) { - final RpcError error = RpcResultBuilder.newError( - ErrorType.RPC, "Invalid input.", "Context value is null"); - return Futures.immediateFuture(RpcResultBuilder.failed().withRpcError(error) - .build()); + return RpcResultBuilder.failed().withError( + ErrorType.RPC, "invalid-value", "Context value is null").buildFuture(); } if (input.getConstant() == null) { - final RpcError error = RpcResultBuilder.newError( - ErrorType.RPC, "Invalid input.", "Constant value is null"); - return Futures.immediateFuture(RpcResultBuilder.failed().withRpcError(error) - .build()); + return RpcResultBuilder.failed().withError( + ErrorType.RPC, "invalid-value", "Constant value is null").buildFuture(); } if (routedRegistrations.containsKey(input.getContext())) { - final RpcError error = RpcResultBuilder.newError(ErrorType.RPC, "Registration present.", - "There is already a rpc registered for context: " + input.getContext()); - return Futures.immediateFuture(RpcResultBuilder.failed().withRpcError(error) - .build()); + return RpcResultBuilder.failed().withError(ErrorType.RPC, + "data-exists", "There is already an rpc registered for context: " + input.getContext()).buildFuture(); } final DOMRpcImplementationRegistration rpcRegistration = @@ -491,57 +460,48 @@ public class MdsalLowLevelTestProvider implements OdlMdsalLowlevelControlService input.getConstant(), input.getContext()); routedRegistrations.put(input.getContext(), rpcRegistration); - return Futures.immediateFuture(RpcResultBuilder.success(new RegisterBoundConstantOutputBuilder().build()) - .build()); + return RpcResultBuilder.success(new RegisterBoundConstantOutputBuilder().build()).buildFuture(); } @Override public ListenableFuture> registerFlappingSingleton( final RegisterFlappingSingletonInput input) { - LOG.debug("Received register-flapping-singleton."); + LOG.info("In registerFlappingSingleton"); if (flappingSingletonService != null) { - final RpcError error = RpcResultBuilder.newError( - ErrorType.RPC, "Registration present.", "flapping-singleton already registered"); - return Futures.immediateFuture(RpcResultBuilder.failed() - .withRpcError(error).build()); + return RpcResultBuilder.failed().withError(ErrorType.RPC, + "data-exists", "There is already an rpc registered").buildFuture(); } flappingSingletonService = new FlappingSingletonService(singletonService); - return Futures.immediateFuture(RpcResultBuilder.success(new RegisterFlappingSingletonOutputBuilder().build()) - .build()); + return RpcResultBuilder.success(new RegisterFlappingSingletonOutputBuilder().build()).buildFuture(); } @Override public ListenableFuture> unsubscribeDtcl(final UnsubscribeDtclInput input) { - LOG.debug("Received unsubscribe-dtcl"); + LOG.info("In unsubscribeDtcl"); 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 RpcResultBuilder.failed().withError( + ErrorType.RPC, "data-missing", "No prior listener was registered").buildFuture(); } + long timeout = 120L; try { - idIntsListener.tryFinishProcessing().get(120, TimeUnit.SECONDS); + idIntsListener.tryFinishProcessing().get(timeout, 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()); + LOG.error("Unable to finish notification processing", e); + return RpcResultBuilder.failed().withError(ErrorType.APPLICATION, + "Unable to finish notification processing in " + timeout + " seconds", e).buildFuture(); } dtclReg.close(); dtclReg = null; if (!idIntsListener.hasTriggered()) { - final RpcError error = RpcResultBuilder.newError( - ErrorType.APPLICATION, "No notification received.", "id-ints listener has not received" - + "any notifications."); - return Futures.immediateFuture(RpcResultBuilder.failed() - .withRpcError(error).build()); + return RpcResultBuilder.failed().withError(ErrorType.APPLICATION, "operation-failed", + "id-ints listener has not received any notifications.").buildFuture(); } final DOMDataReadOnlyTransaction rTx = domDataBroker.newReadOnlyTransaction(); @@ -550,28 +510,29 @@ public class MdsalLowLevelTestProvider implements OdlMdsalLowlevelControlService rTx.read(CONTROLLER_CONFIG, WriteTransactionsHandler.ID_INT_YID).get(); if (!readResult.isPresent()) { - final RpcError error = RpcResultBuilder.newError( - ErrorType.APPLICATION, "Final read empty.", "No data read from id-ints list."); - return Futures.immediateFuture(RpcResultBuilder.failed() - .withRpcError(error).build()); + return RpcResultBuilder.failed().withError(ErrorType.APPLICATION, "data-missing", + "No data read from id-ints list").buildFuture(); } - return Futures.immediateFuture( - RpcResultBuilder.success(new UnsubscribeDtclOutputBuilder() - .setCopyMatches(idIntsListener.checkEqual(readResult.get()))).build()); + final boolean nodesEqual = idIntsListener.checkEqual(readResult.get()); + if (!nodesEqual) { + LOG.error("Final read of id-int does not match IdIntsListener's copy. {}", + idIntsListener.diffWithLocalCopy(readResult.get())); + } - } catch (final InterruptedException | ExecutionException e) { - final RpcError error = RpcResultBuilder.newError( - ErrorType.APPLICATION, "Read failed.", "Final read from id-ints failed."); - return Futures.immediateFuture(RpcResultBuilder.failed() - .withRpcError(error).build()); + return RpcResultBuilder.success(new UnsubscribeDtclOutputBuilder().setCopyMatches(nodesEqual)) + .buildFuture(); + } catch (final InterruptedException | ExecutionException e) { + LOG.error("Final read of id-ints failed", e); + return RpcResultBuilder.failed().withError(ErrorType.APPLICATION, + "Final read of id-ints failed", e).buildFuture(); } } @Override public ListenableFuture> createPrefixShard(final CreatePrefixShardInput input) { - LOG.debug("create-prefix-shard, input: {}", input); + LOG.info("In createPrefixShard - input: {}", input); return prefixShardHandler.onCreatePrefixShard(input); } @@ -584,14 +545,11 @@ public class MdsalLowLevelTestProvider implements OdlMdsalLowlevelControlService @Override public ListenableFuture> unsubscribeYnl(final UnsubscribeYnlInput input) { - LOG.debug("Received unsubscribe-ynl, input: {}", input); + LOG.info("In unsubscribeYnl - input: {}", input); if (!ynlRegistrations.containsKey(input.getId())) { - 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); + return RpcResultBuilder.failed().withError( + ErrorType.RPC, "data-missing", "No prior listener was registered for " + input.getId()).buildFuture(); } final ListenerRegistration reg = ynlRegistrations.remove(input.getId()); @@ -599,12 +557,13 @@ public class MdsalLowLevelTestProvider implements OdlMdsalLowlevelControlService reg.close(); - return Futures.immediateFuture(RpcResultBuilder.success().withResult(output).build()); + return RpcResultBuilder.success().withResult(output).buildFuture(); } @Override public ListenableFuture> checkPublishNotifications( final CheckPublishNotificationsInput input) { + LOG.info("In checkPublishNotifications - input: {}", input); final PublishNotificationsTask task = publishNotificationsTasks.get(input.getId()); @@ -624,27 +583,25 @@ public class MdsalLowLevelTestProvider implements OdlMdsalLowlevelControlService final CheckPublishNotificationsOutput output = checkPublishNotificationsOutputBuilder.setPublishCount(task.getCurrentNotif()).build(); - return Futures.immediateFuture(RpcResultBuilder.success(output).build()); + return RpcResultBuilder.success(output).buildFuture(); } @Override public ListenableFuture> produceTransactions( final ProduceTransactionsInput input) { - LOG.debug("producer-transactions, input: {}", input); + LOG.info("In produceTransactions - input: {}", input); return ProduceTransactionsHandler.start(domDataTreeService, input); } @Override public ListenableFuture> shutdownShardReplica( final ShutdownShardReplicaInput input) { - LOG.debug("Received shutdown-shard-replica rpc, input: {}", input); + LOG.info("In shutdownShardReplica - input: {}", input); final String shardName = input.getShardName(); if (Strings.isNullOrEmpty(shardName)) { - final RpcError rpcError = RpcResultBuilder.newError(ErrorType.APPLICATION, "bad-element", - "A valid shard name must be specified"); - return Futures.immediateFuture(RpcResultBuilder.failed().withRpcError(rpcError) - .build()); + return RpcResultBuilder.failed().withError(ErrorType.RPC, "bad-element", + shardName + "is not a valid shard name").buildFuture(); } return shutdownShardGracefully(shardName, new ShutdownShardReplicaOutputBuilder().build()); @@ -653,15 +610,13 @@ public class MdsalLowLevelTestProvider implements OdlMdsalLowlevelControlService @Override public ListenableFuture> shutdownPrefixShardReplica( final ShutdownPrefixShardReplicaInput input) { - LOG.debug("Received shutdown-prefix-shard-replica rpc, input: {}", input); + LOG.info("shutdownPrefixShardReplica - input: {}", input); final InstanceIdentifier shardPrefix = input.getPrefix(); if (shardPrefix == null) { - final RpcError rpcError = RpcResultBuilder.newError(ErrorType.APPLICATION, "bad-element", - "A valid shard prefix must be specified"); - return Futures.immediateFuture(RpcResultBuilder.failed() - .withRpcError(rpcError).build()); + return RpcResultBuilder.failed().withError(ErrorType.RPC, "bad-element", + "A valid shard prefix must be specified").buildFuture(); } final YangInstanceIdentifier shardPath = bindingNormalizedNodeSerializer.toYangInstanceIdentifier(shardPrefix); @@ -681,7 +636,7 @@ public class MdsalLowLevelTestProvider implements OdlMdsalLowlevelControlService context.findLocalShardAsync(shardName).onComplete(new OnComplete() { @Override - public void onComplete(final Throwable throwable, final ActorRef actorRef) throws Throwable { + public void onComplete(final Throwable throwable, final ActorRef actorRef) { if (throwable != null) { shutdownShardAsk.failure(throwable); } else { @@ -692,7 +647,7 @@ public class MdsalLowLevelTestProvider implements OdlMdsalLowlevelControlService shutdownShardAsk.future().onComplete(new OnComplete() { @Override - public void onComplete(final Throwable throwable, final Boolean gracefulStopResult) throws Throwable { + public void onComplete(final Throwable throwable, final Boolean gracefulStopResult) { if (throwable != null) { final RpcResult failedResult = RpcResultBuilder.failed() .withError(ErrorType.APPLICATION, "Failed to gracefully shutdown shard", throwable).build(); @@ -709,25 +664,20 @@ public class MdsalLowLevelTestProvider implements OdlMdsalLowlevelControlService @Override public ListenableFuture> registerConstant(final RegisterConstantInput input) { - - LOG.debug("Received register-constant rpc, input: {}", input); + LOG.info("In registerConstant - input: {}", input); if (input.getConstant() == null) { - final RpcError error = RpcResultBuilder.newError( - ErrorType.RPC, "Invalid input.", "Constant value is null"); - return Futures.immediateFuture(RpcResultBuilder.failed().withRpcError(error) - .build()); + return RpcResultBuilder.failed().withError( + ErrorType.RPC, "invalid-value", "Constant value is null").buildFuture(); } if (globalGetConstantRegistration != null) { - final RpcError error = RpcResultBuilder.newError(ErrorType.RPC, "Registration present.", - "There is already a get-constant rpc registered."); - return Futures.immediateFuture(RpcResultBuilder.failed().withRpcError(error) - .build()); + return RpcResultBuilder.failed().withError(ErrorType.RPC, + "data-exists", "There is already an rpc registered").buildFuture(); } globalGetConstantRegistration = GetConstantService.registerNew(domRpcService, input.getConstant()); - return Futures.immediateFuture(RpcResultBuilder.success(new RegisterConstantOutputBuilder().build()).build()); + return RpcResultBuilder.success(new RegisterConstantOutputBuilder().build()).buildFuture(); } @Override @@ -739,33 +689,28 @@ public class MdsalLowLevelTestProvider implements OdlMdsalLowlevelControlService @Override @SuppressWarnings("checkstyle:IllegalCatch") public ListenableFuture> unsubscribeDdtl(final UnsubscribeDdtlInput input) { - LOG.debug("Received unsubscribe-ddtl."); + LOG.info("In unsubscribeDdtl"); 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 RpcResultBuilder.failed().withError( + ErrorType.RPC, "data-missing", "No prior listener was registered").buildFuture(); } + long timeout = 120L; try { - idIntsDdtl.tryFinishProcessing().get(120, TimeUnit.SECONDS); + idIntsDdtl.tryFinishProcessing().get(timeout, 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()); + LOG.error("Unable to finish notification processing", e); + return RpcResultBuilder.failed().withError(ErrorType.APPLICATION, + "Unable to finish notification processing in " + timeout + " seconds", e).buildFuture(); } ddtlReg.close(); ddtlReg = null; if (!idIntsDdtl.hasTriggered()) { - final RpcError error = RpcResultBuilder.newError( - ErrorType.APPLICATION, "No notification received.", "id-ints listener has not received" - + "any notifications."); - return Futures.immediateFuture(RpcResultBuilder.failed() - .withRpcError(error).build()); + return RpcResultBuilder.failed().withError(ErrorType.APPLICATION, + "No notification received.", "id-ints listener has not received any notifications").buildFuture(); } final String shardName = ClusterUtils.getCleanShardName(ProduceTransactionsHandler.ID_INTS_YID); @@ -784,11 +729,8 @@ public class MdsalLowLevelTestProvider implements OdlMdsalLowlevelControlService } catch (RuntimeException e) { LOG.error("Failed to get actor for {}", distributedDataStoreClientProps, e); clientActor.tell(PoisonPill.getInstance(), noSender()); - final RpcError error = RpcResultBuilder.newError( - ErrorType.APPLICATION, "Unable to create ds client for read.", - "Unable to create ds client for read."); - return Futures.immediateFuture(RpcResultBuilder.failed() - .withRpcError(error).build()); + return RpcResultBuilder.failed() + .withError(ErrorType.APPLICATION, "Unable to create DataStoreClient for read", e).buildFuture(); } final ClientLocalHistory localHistory = distributedDataStoreClient.createLocalHistory(); @@ -801,23 +743,17 @@ public class MdsalLowLevelTestProvider implements OdlMdsalLowlevelControlService try { final java.util.Optional> optional = read.get(); if (!optional.isPresent()) { - LOG.warn("Final read from client is empty."); - final RpcError error = RpcResultBuilder.newError( - ErrorType.APPLICATION, "Read failed.", "Final read from id-ints is empty."); - return Futures.immediateFuture(RpcResultBuilder.failed() - .withRpcError(error).build()); + return RpcResultBuilder.failed().withError(ErrorType.APPLICATION, + "data-missing", "Final read from id-ints is empty").buildFuture(); } - return Futures.immediateFuture( - RpcResultBuilder.success(new UnsubscribeDdtlOutputBuilder() - .setCopyMatches(idIntsDdtl.checkEqual(optional.get()))).build()); + return RpcResultBuilder.success(new UnsubscribeDdtlOutputBuilder().setCopyMatches( + idIntsDdtl.checkEqual(optional.get()))).buildFuture(); } catch (InterruptedException | ExecutionException e) { - LOG.error("Unable to read data to verify ddtl data.", e); - final RpcError error = RpcResultBuilder.newError( - ErrorType.APPLICATION, "Read failed.", "Final read from id-ints failed."); - return Futures.immediateFuture(RpcResultBuilder.failed() - .withRpcError(error).build()); + LOG.error("Unable to read data to verify ddtl data", e); + return RpcResultBuilder.failed() + .withError(ErrorType.APPLICATION, "Final read from id-ints failed", e).buildFuture(); } finally { distributedDataStoreClient.close(); clientActor.tell(PoisonPill.getInstance(), noSender());