use of org.opendaylight.yangtools.yang.common.RpcResult in project controller by opendaylight.
the class ClusterAdminRpcService method getShardRole.
@Override
public Future<RpcResult<GetShardRoleOutput>> getShardRole(final GetShardRoleInput 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");
}
LOG.info("Getting role for shard {}, datastore type {}", shardName, dataStoreType);
final SettableFuture<RpcResult<GetShardRoleOutput>> returnFuture = SettableFuture.create();
ListenableFuture<GetShardRoleReply> future = sendMessageToShardManager(dataStoreType, new GetShardRole(shardName));
Futures.addCallback(future, new FutureCallback<GetShardRoleReply>() {
@Override
public void onSuccess(final GetShardRoleReply reply) {
if (reply == null) {
returnFuture.set(ClusterAdminRpcService.<GetShardRoleOutput>newFailedRpcResultBuilder("No Shard role present. Please retry..").build());
return;
}
LOG.info("Successfully received role:{} for shard {}", reply.getRole(), shardName);
final GetShardRoleOutputBuilder builder = new GetShardRoleOutputBuilder();
if (reply.getRole() != null) {
builder.setRole(reply.getRole());
}
returnFuture.set(newSuccessfulResult(builder.build()));
}
@Override
public void onFailure(final Throwable failure) {
returnFuture.set(ClusterAdminRpcService.<GetShardRoleOutput>newFailedRpcResultBuilder("Failed to get shard role.", failure).build());
}
}, MoreExecutors.directExecutor());
return returnFuture;
}
use of org.opendaylight.yangtools.yang.common.RpcResult in project controller by opendaylight.
the class ClusterAdminRpcService method removeAllShardReplicas.
@Override
public Future<RpcResult<RemoveAllShardReplicasOutput>> removeAllShardReplicas(RemoveAllShardReplicasInput input) {
LOG.info("Removing replicas for all shards");
final String memberName = input.getMemberName();
if (Strings.isNullOrEmpty(memberName)) {
return newFailedRpcResultFuture("A valid member name must be specified");
}
final List<Entry<ListenableFuture<Success>, ShardResultBuilder>> shardResultData = new ArrayList<>();
Function<String, Object> messageSupplier = shardName -> new RemoveShardReplica(shardName, MemberName.forName(memberName));
sendMessageToManagerForConfiguredShards(DataStoreType.Config, shardResultData, messageSupplier);
sendMessageToManagerForConfiguredShards(DataStoreType.Operational, shardResultData, messageSupplier);
return waitForShardResults(shardResultData, shardResults -> new RemoveAllShardReplicasOutputBuilder().setShardResult(shardResults).build(), " Failed to remove replica");
}
use of org.opendaylight.yangtools.yang.common.RpcResult in project controller by opendaylight.
the class ClusterAdminRpcService method addShardReplica.
@Override
public Future<RpcResult<Void>> addShardReplica(final AddShardReplicaInput 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");
}
LOG.info("Adding replica for shard {}", shardName);
final SettableFuture<RpcResult<Void>> returnFuture = SettableFuture.create();
ListenableFuture<Success> future = sendMessageToShardManager(dataStoreType, new AddShardReplica(shardName));
Futures.addCallback(future, new FutureCallback<Success>() {
@Override
public void onSuccess(Success success) {
LOG.info("Successfully added replica for shard {}", shardName);
returnFuture.set(newSuccessfulResult());
}
@Override
public void onFailure(Throwable failure) {
onMessageFailure(String.format("Failed to add 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 changeMemberVotingStatesForShard.
@Override
public Future<RpcResult<Void>> changeMemberVotingStatesForShard(ChangeMemberVotingStatesForShardInput 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");
}
List<MemberVotingState> memberVotingStates = input.getMemberVotingState();
if (memberVotingStates == null || memberVotingStates.isEmpty()) {
return newFailedRpcResultFuture("No member voting state input was specified");
}
ChangeShardMembersVotingStatus changeVotingStatus = toChangeShardMembersVotingStatus(shardName, memberVotingStates);
LOG.info("Change member voting states for shard {}: {}", shardName, changeVotingStatus.getMeberVotingStatusMap());
final SettableFuture<RpcResult<Void>> returnFuture = SettableFuture.create();
ListenableFuture<Success> future = sendMessageToShardManager(dataStoreType, changeVotingStatus);
Futures.addCallback(future, new FutureCallback<Success>() {
@Override
public void onSuccess(Success success) {
LOG.info("Successfully changed member voting states for shard {}", shardName);
returnFuture.set(newSuccessfulResult());
}
@Override
public void onFailure(Throwable failure) {
onMessageFailure(String.format("Failed to change member voting states 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 DOMRpcServiceTestBugfix560 method test.
@Test
public void test() throws ExecutionException, InterruptedException {
// FIXME: This is made to only make sure instance identifier codec for path is instantiated.
domMountPointService.createMountPoint(BI_MOUNT_ID).addService(DOMRpcService.class, new DOMRpcService() {
@Override
public <T extends DOMRpcAvailabilityListener> ListenerRegistration<T> registerRpcListener(final T arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public CheckedFuture<DOMRpcResult, DOMRpcException> invokeRpc(final SchemaPath arg0, final NormalizedNode<?, ?> arg1) {
final DOMRpcResult result = new DefaultDOMRpcResult((NormalizedNode<?, ?>) null);
return Futures.immediateCheckedFuture(result);
}
}).register();
final Optional<MountPoint> mountInstance = bindingMountPointService.getMountPoint(BA_MOUNT_ID);
assertTrue(mountInstance.isPresent());
final Optional<RpcConsumerRegistry> rpcRegistry = mountInstance.get().getService(RpcConsumerRegistry.class);
assertTrue(rpcRegistry.isPresent());
final OpendaylightTestRpcServiceService rpcService = rpcRegistry.get().getRpcService(OpendaylightTestRpcServiceService.class);
assertNotNull(rpcService);
try {
final Future<RpcResult<Void>> result = rpcService.rockTheHouse(new RockTheHouseInputBuilder().build());
assertTrue(result.get().isSuccessful());
} catch (final IllegalStateException ex) {
fail("OpendaylightTestRpcServiceService class doesn't contain rockTheHouse method!");
}
}
Aggregations