use of org.opendaylight.yangtools.yang.common.RpcResult in project controller by opendaylight.
the class BindingDOMRpcImplementationAdapter method invokeRpc.
@Nonnull
@Override
public CheckedFuture<DOMRpcResult, DOMRpcException> invokeRpc(@Nonnull final DOMRpcIdentifier rpc, final NormalizedNode<?, ?> input) {
final SchemaPath schemaPath = rpc.getType();
final DataObject bindingInput = input != null ? deserialize(rpc.getType(), input) : null;
final ListenableFuture<RpcResult<?>> bindingResult = invoke(schemaPath, bindingInput);
return transformResult(bindingResult);
}
use of org.opendaylight.yangtools.yang.common.RpcResult in project controller by opendaylight.
the class MdsalLowLevelTestProvider method unregisterSingletonConstant.
@Override
@SuppressWarnings("checkstyle:IllegalCatch")
public Future<RpcResult<Void>> 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 RpcResult<Void> result = RpcResultBuilder.<Void>failed().withRpcError(rpcError).build();
return Futures.immediateFuture(result);
}
try {
getSingletonConstantRegistration.close();
getSingletonConstantRegistration = null;
return Futures.immediateFuture(RpcResultBuilder.<Void>success().build());
} 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<Void> result = RpcResultBuilder.<Void>failed().withRpcError(rpcError).build();
return Futures.immediateFuture(result);
}
}
use of org.opendaylight.yangtools.yang.common.RpcResult in project controller by opendaylight.
the class OpenDaylightToasterTest method testSomething.
@Test
// ignored because it is not a test right now. Illustrative purposes only.
@Ignore
public void testSomething() throws Exception {
MakeToastInput toastInput = new MakeToastInputBuilder().setToasterDoneness(1L).setToasterToastType(WheatBread.class).build();
// NOTE: In a real test we would want to override the Thread.sleep() to
// prevent our junit test
// for sleeping for a second...
Future<RpcResult<Void>> makeToast = toaster.makeToast(toastInput);
RpcResult<Void> rpcResult = makeToast.get();
assertNotNull(rpcResult);
assertTrue(rpcResult.isSuccessful());
// etc
}
use of org.opendaylight.yangtools.yang.common.RpcResult in project controller by opendaylight.
the class ClusterAdminRpcService method removeShardReplica.
@Override
public Future<RpcResult<Void>> removeShardReplica(RemoveShardReplicaInput input) {
final String shardName = input.getShardName();
if (Strings.isNullOrEmpty(shardName)) {
return newFailedRpcResultFuture("A valid shard name must be specified");
}
DataStoreType dataStoreType = input.getDataStoreType();
if (dataStoreType == null) {
return newFailedRpcResultFuture("A valid DataStoreType must be specified");
}
final String memberName = input.getMemberName();
if (Strings.isNullOrEmpty(memberName)) {
return newFailedRpcResultFuture("A valid member name must be specified");
}
LOG.info("Removing replica for shard {} memberName {}, datastoreType {}", shardName, memberName, dataStoreType);
final SettableFuture<RpcResult<Void>> returnFuture = SettableFuture.create();
ListenableFuture<Success> future = sendMessageToShardManager(dataStoreType, new RemoveShardReplica(shardName, MemberName.forName(memberName)));
Futures.addCallback(future, new FutureCallback<Success>() {
@Override
public void onSuccess(Success success) {
LOG.info("Successfully removed replica for shard {}", shardName);
returnFuture.set(newSuccessfulResult());
}
@Override
public void onFailure(Throwable failure) {
onMessageFailure(String.format("Failed to remove replica for shard %s", shardName), returnFuture, failure);
}
}, MoreExecutors.directExecutor());
return returnFuture;
}
use of org.opendaylight.yangtools.yang.common.RpcResult in project controller by opendaylight.
the class ClusterAdminRpcService method makeLeaderLocal.
@Override
public Future<RpcResult<Void>> makeLeaderLocal(final MakeLeaderLocalInput input) {
final String shardName = input.getShardName();
if (Strings.isNullOrEmpty(shardName)) {
return newFailedRpcResultFuture("A valid shard name must be specified");
}
DataStoreType dataStoreType = input.getDataStoreType();
if (dataStoreType == null) {
return newFailedRpcResultFuture("A valid DataStoreType must be specified");
}
ActorContext actorContext = dataStoreType == DataStoreType.Config ? configDataStore.getActorContext() : operDataStore.getActorContext();
LOG.info("Moving leader to local node {} for shard {}, datastoreType {}", actorContext.getCurrentMemberName().getName(), shardName, dataStoreType);
final scala.concurrent.Future<ActorRef> localShardReply = actorContext.findLocalShardAsync(shardName);
final scala.concurrent.Promise<Object> makeLeaderLocalAsk = akka.dispatch.Futures.promise();
localShardReply.onComplete(new OnComplete<ActorRef>() {
@Override
public void onComplete(final Throwable failure, final ActorRef actorRef) throws Throwable {
if (failure != null) {
LOG.warn("No local shard found for {} datastoreType {} - Cannot request leadership transfer to" + " local shard.", shardName, failure);
makeLeaderLocalAsk.failure(failure);
} else {
makeLeaderLocalAsk.completeWith(actorContext.executeOperationAsync(actorRef, MakeLeaderLocal.INSTANCE, makeLeaderLocalTimeout));
}
}
}, actorContext.getClientDispatcher());
final SettableFuture<RpcResult<Void>> future = SettableFuture.create();
makeLeaderLocalAsk.future().onComplete(new OnComplete<Object>() {
@Override
public void onComplete(final Throwable failure, final Object success) throws Throwable {
if (failure != null) {
LOG.error("Leadership transfer failed for shard {}.", shardName, failure);
future.set(RpcResultBuilder.<Void>failed().withError(ErrorType.APPLICATION, "leadership transfer failed", failure).build());
return;
}
LOG.debug("Leadership transfer complete");
future.set(RpcResultBuilder.<Void>success().build());
}
}, actorContext.getClientDispatcher());
return future;
}
Aggregations