use of org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier in project controller by opendaylight.
the class ClusterAdminRpcService method getPrefixShardRole.
@Override
public Future<RpcResult<GetPrefixShardRoleOutput>> getPrefixShardRole(final GetPrefixShardRoleInput input) {
final InstanceIdentifier<?> identifier = input.getShardPrefix();
if (identifier == null) {
return newFailedRpcResultFuture("A valid shard identifier must be specified");
}
final DataStoreType dataStoreType = input.getDataStoreType();
if (dataStoreType == null) {
return newFailedRpcResultFuture("A valid DataStoreType must be specified");
}
LOG.info("Getting prefix shard role for shard: {}, datastore type {}", identifier, dataStoreType);
final YangInstanceIdentifier prefix = serializer.toYangInstanceIdentifier(identifier);
final String shardName = ClusterUtils.getCleanShardName(prefix);
final SettableFuture<RpcResult<GetPrefixShardRoleOutput>> 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.<GetPrefixShardRoleOutput>newFailedRpcResultBuilder("No Shard role present. Please retry..").build());
return;
}
LOG.info("Successfully received role:{} for shard {}", reply.getRole(), shardName);
final GetPrefixShardRoleOutputBuilder builder = new GetPrefixShardRoleOutputBuilder();
if (reply.getRole() != null) {
builder.setRole(reply.getRole());
}
returnFuture.set(newSuccessfulResult(builder.build()));
}
@Override
public void onFailure(final Throwable failure) {
returnFuture.set(ClusterAdminRpcService.<GetPrefixShardRoleOutput>newFailedRpcResultBuilder("Failed to get shard role.", failure).build());
}
}, MoreExecutors.directExecutor());
return returnFuture;
}
use of org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier in project controller by opendaylight.
the class ClusterAdminRpcService method addPrefixShardReplica.
@Override
public Future<RpcResult<Void>> addPrefixShardReplica(final AddPrefixShardReplicaInput input) {
final InstanceIdentifier<?> identifier = input.getShardPrefix();
if (identifier == null) {
return newFailedRpcResultFuture("A valid shard identifier must be specified");
}
final DataStoreType dataStoreType = input.getDataStoreType();
if (dataStoreType == null) {
return newFailedRpcResultFuture("A valid DataStoreType must be specified");
}
LOG.info("Adding replica for shard {}, datastore type {}", identifier, dataStoreType);
final YangInstanceIdentifier prefix = serializer.toYangInstanceIdentifier(identifier);
final SettableFuture<RpcResult<Void>> returnFuture = SettableFuture.create();
ListenableFuture<Success> future = sendMessageToShardManager(dataStoreType, new AddPrefixShardReplica(prefix));
Futures.addCallback(future, new FutureCallback<Success>() {
@Override
public void onSuccess(Success success) {
LOG.info("Successfully added replica for shard {}", prefix);
returnFuture.set(newSuccessfulResult());
}
@Override
public void onFailure(Throwable failure) {
onMessageFailure(String.format("Failed to add replica for shard %s", prefix), returnFuture, failure);
}
}, MoreExecutors.directExecutor());
return returnFuture;
}
use of org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier in project controller by opendaylight.
the class ClusterAdminRpcService method removePrefixShardReplica.
@Override
public Future<RpcResult<Void>> removePrefixShardReplica(final RemovePrefixShardReplicaInput input) {
final InstanceIdentifier<?> identifier = input.getShardPrefix();
if (identifier == null) {
return newFailedRpcResultFuture("A valid shard identifier must be specified");
}
final 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 {}", identifier, memberName, dataStoreType);
final YangInstanceIdentifier prefix = serializer.toYangInstanceIdentifier(identifier);
final SettableFuture<RpcResult<Void>> returnFuture = SettableFuture.create();
final ListenableFuture<Success> future = sendMessageToShardManager(dataStoreType, new RemovePrefixShardReplica(prefix, MemberName.forName(memberName)));
Futures.addCallback(future, new FutureCallback<Success>() {
@Override
public void onSuccess(final Success success) {
LOG.info("Successfully removed replica for shard {}", prefix);
returnFuture.set(newSuccessfulResult());
}
@Override
public void onFailure(final Throwable failure) {
onMessageFailure(String.format("Failed to remove replica for shard %s", prefix), returnFuture, failure);
}
}, MoreExecutors.directExecutor());
return returnFuture;
}
use of org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier in project controller by opendaylight.
the class AbstractDataTreeModificationCursor method exit.
@Override
public final void exit(final int depth) {
Preconditions.checkArgument(depth >= 0);
YangInstanceIdentifier next = current;
for (int i = 0; i < depth; ++i) {
next = next.getParent();
Preconditions.checkState(next != null);
}
current = next;
}
use of org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier in project controller by opendaylight.
the class PrefixShardHandler method onCreatePrefixShard.
public ListenableFuture<RpcResult<Void>> onCreatePrefixShard(final CreatePrefixShardInput input) {
final SettableFuture<RpcResult<Void>> future = SettableFuture.create();
final CompletionStage<DistributedShardRegistration> completionStage;
final YangInstanceIdentifier identifier = serializer.toYangInstanceIdentifier(input.getPrefix());
try {
completionStage = shardFactory.createDistributedShard(new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, identifier), input.getReplicas().stream().map(MemberName::forName).collect(Collectors.toList()));
completionStage.thenAccept(registration -> {
LOG.debug("Shard[{}] created successfully.", identifier);
registrations.put(identifier, registration);
final ListenableFuture<Void> ensureFuture = ensureListExists();
Futures.addCallback(ensureFuture, new FutureCallback<Void>() {
@Override
public void onSuccess(@Nullable final Void result) {
LOG.debug("Initial list write successful.");
future.set(RpcResultBuilder.<Void>success().build());
}
@Override
public void onFailure(final Throwable throwable) {
LOG.warn("Shard[{}] creation failed:", identifier, throwable);
final RpcError error = RpcResultBuilder.newError(RpcError.ErrorType.APPLICATION, "create-shard-failed", "Shard creation failed", "cluster-test-app", "", throwable);
future.set(RpcResultBuilder.<Void>failed().withRpcError(error).build());
}
}, MoreExecutors.directExecutor());
});
completionStage.exceptionally(throwable -> {
LOG.warn("Shard[{}] creation failed:", identifier, throwable);
final RpcError error = RpcResultBuilder.newError(RpcError.ErrorType.APPLICATION, "create-shard-failed", "Shard creation failed", "cluster-test-app", "", throwable);
future.set(RpcResultBuilder.<Void>failed().withRpcError(error).build());
return null;
});
} catch (final DOMDataTreeShardingConflictException e) {
LOG.warn("Unable to register shard for: {}.", identifier);
final RpcError error = RpcResultBuilder.newError(RpcError.ErrorType.APPLICATION, "create-shard-failed", "Sharding conflict", "cluster-test-app", "", e);
future.set(RpcResultBuilder.<Void>failed().withRpcError(error).build());
}
return future;
}
Aggregations