Search in sources :

Example 56 with RpcResult

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);
}
Also used : DataObject(org.opendaylight.yangtools.yang.binding.DataObject) SchemaPath(org.opendaylight.yangtools.yang.model.api.SchemaPath) DOMRpcResult(org.opendaylight.controller.md.sal.dom.api.DOMRpcResult) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) Nonnull(javax.annotation.Nonnull)

Example 57 with RpcResult

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);
    }
}
Also used : RpcError(org.opendaylight.yangtools.yang.common.RpcError) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) DOMDataTreeLoopException(org.opendaylight.mdsal.dom.api.DOMDataTreeLoopException) ExecutionException(java.util.concurrent.ExecutionException) ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) TimeoutException(java.util.concurrent.TimeoutException)

Example 58 with RpcResult

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
}
Also used : MakeToastInput(org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.MakeToastInput) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) MakeToastInputBuilder(org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.MakeToastInputBuilder) WheatBread(org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.WheatBread) Ignore(org.junit.Ignore) AbstractConcurrentDataBrokerTest(org.opendaylight.controller.md.sal.binding.test.AbstractConcurrentDataBrokerTest) Test(org.junit.Test)

Example 59 with RpcResult

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;
}
Also used : RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) RemoveShardReplica(org.opendaylight.controller.cluster.datastore.messages.RemoveShardReplica) Success(akka.actor.Status.Success) DataStoreType(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.DataStoreType)

Example 60 with RpcResult

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;
}
Also used : ActorRef(akka.actor.ActorRef) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) DataStoreType(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.DataStoreType) ActorContext(org.opendaylight.controller.cluster.datastore.utils.ActorContext)

Aggregations

RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)360 Test (org.junit.Test)120 ExecutionException (java.util.concurrent.ExecutionException)118 ArrayList (java.util.ArrayList)61 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)37 InOrder (org.mockito.InOrder)30 List (java.util.List)29 BigInteger (java.math.BigInteger)26 NodeRef (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef)25 FutureCallback (com.google.common.util.concurrent.FutureCallback)24 AllocateIdInput (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdInput)24 AllocateIdOutput (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdOutput)24 RpcError (org.opendaylight.yangtools.yang.common.RpcError)24 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)23 AllocateIdInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdInputBuilder)23 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)22 Future (java.util.concurrent.Future)21 Flow (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow)21 Logger (org.slf4j.Logger)21 LoggerFactory (org.slf4j.LoggerFactory)21