Search in sources :

Example 46 with RpcError

use of org.opendaylight.yangtools.yang.common.RpcError in project openflowplugin by opendaylight.

the class RoleService method submitRoleChange.

public Future<RpcResult<SetRoleOutput>> submitRoleChange(final OfpRole ofpRole, final Short version, final BigInteger generationId) {
    LOG.info("submitRoleChange called for device:{}, role:{}", getDeviceInfo().getNodeId(), ofpRole);
    final RoleRequestInputBuilder roleRequestInputBuilder = new RoleRequestInputBuilder();
    roleRequestInputBuilder.setRole(toOFJavaRole(ofpRole));
    roleRequestInputBuilder.setVersion(version);
    roleRequestInputBuilder.setGenerationId(generationId);
    final ListenableFuture<RpcResult<RoleRequestOutput>> roleListenableFuture = handleServiceCall(roleRequestInputBuilder);
    final SettableFuture<RpcResult<SetRoleOutput>> finalFuture = SettableFuture.create();
    Futures.addCallback(roleListenableFuture, new FutureCallback<RpcResult<RoleRequestOutput>>() {

        @Override
        public void onSuccess(@Nonnull final RpcResult<RoleRequestOutput> roleRequestOutputRpcResult) {
            LOG.info("submitRoleChange onSuccess for device:{}, role:{}", getDeviceInfo().getNodeId(), ofpRole);
            final RoleRequestOutput roleRequestOutput = roleRequestOutputRpcResult.getResult();
            final Collection<RpcError> rpcErrors = roleRequestOutputRpcResult.getErrors();
            if (roleRequestOutput != null) {
                final SetRoleOutputBuilder setRoleOutputBuilder = new SetRoleOutputBuilder();
                setRoleOutputBuilder.setTransactionId(new TransactionId(BigInteger.valueOf(roleRequestOutput.getXid())));
                finalFuture.set(RpcResultBuilder.<SetRoleOutput>success().withResult(setRoleOutputBuilder.build()).build());
            } else if (rpcErrors != null) {
                LOG.trace("roleRequestOutput is null , rpcErrors={}", rpcErrors);
                for (RpcError rpcError : rpcErrors) {
                    LOG.warn("RpcError on submitRoleChange for {}: {}", deviceContext.getPrimaryConnectionContext().getNodeId(), rpcError.toString());
                }
                finalFuture.set(RpcResultBuilder.<SetRoleOutput>failed().withRpcErrors(rpcErrors).build());
            }
        }

        @Override
        public void onFailure(final Throwable throwable) {
            LOG.error("submitRoleChange onFailure for device:{}, role:{}", getDeviceInfo().getNodeId(), ofpRole, throwable);
            finalFuture.setException(throwable);
        }
    }, MoreExecutors.directExecutor());
    return finalFuture;
}
Also used : RoleRequestOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestOutput) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) RpcError(org.opendaylight.yangtools.yang.common.RpcError) TransactionId(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.TransactionId) SetRoleOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.SetRoleOutputBuilder) SetRoleOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.SetRoleOutput) RoleRequestInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestInputBuilder) Collection(java.util.Collection)

Example 47 with RpcError

use of org.opendaylight.yangtools.yang.common.RpcError in project lispflowmapping by opendaylight.

the class MappingServiceTest method addKeyTest.

/**
 * Tests {@link MappingService#addKey} method.
 */
@Test
public void addKeyTest() throws ExecutionException, InterruptedException {
    final MappingAuthkey mappingAuthkey = new MappingAuthkeyBuilder().setKeyString("dummy-password").setKeyType(2).build();
    final AddKeyInput addKeyInput = new AddKeyInputBuilder().setMappingAuthkey(mappingAuthkey).setEid(IPV4_EID).build();
    Mockito.when(mappingSystem.getAuthenticationKey(IPV4_EID)).thenReturn(MAPPING_AUTHKEY);
    // input
    final RpcResult<Object> rpc = RpcResultBuilder.failed().withError(RpcError.ErrorType.PROTOCOL, "data-exists", "Key already exists! Please use update-key if you want to change it.").build();
    // equals() not implemented int RpcError
    final RpcError error = rpc.getErrors().iterator().next();
    // result
    final Future<RpcResult<Void>> result = mappingService.addKey(addKeyInput);
    final RpcError errorResult = result.get().getErrors().iterator().next();
    assertEquals(1, result.get().getErrors().size());
    assertEquals(error.getMessage(), errorResult.getMessage());
    assertEquals(error.getApplicationTag(), errorResult.getApplicationTag());
    assertEquals(error.getCause(), errorResult.getCause());
    assertEquals(error.getErrorType(), errorResult.getErrorType());
    assertEquals(error.getInfo(), errorResult.getInfo());
    assertEquals(error.getTag(), errorResult.getTag());
    assertEquals(error.getSeverity(), errorResult.getSeverity());
    assertEquals(rpc.getResult(), result.get().getResult());
    assertEquals(rpc.isSuccessful(), result.get().isSuccessful());
}
Also used : AddKeyInput(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.AddKeyInput) MappingAuthkey(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.authkey.container.MappingAuthkey) RpcError(org.opendaylight.yangtools.yang.common.RpcError) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) MappingAuthkeyBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.authkey.container.MappingAuthkeyBuilder) AddKeyInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.AddKeyInputBuilder) Test(org.junit.Test)

Example 48 with RpcError

use of org.opendaylight.yangtools.yang.common.RpcError in project genius by opendaylight.

the class IdManagerTest method requestIdsConcurrently.

// OK as exceptionInExecutor can't be Exception & AssertionFailedError
@SuppressWarnings("checkstyle:IllegalThrows")
private void requestIdsConcurrently(boolean isSameKey) throws Throwable {
    int numberOfTasks = 3;
    CountDownLatch latch = new CountDownLatch(numberOfTasks);
    Set<Long> idSet = Sets.newConcurrentHashSet();
    ExecutorService executor = Executors.newCachedThreadPool("requestIdsConcurrently()", LOG);
    AtomicReference<Throwable> exceptionInExecutorAtomic = new AtomicReference<>();
    for (int i = 0; i < numberOfTasks; i++) {
        final String idKey;
        if (isSameKey) {
            idKey = TEST_KEY1;
        } else {
            idKey = TEST_KEY1 + i;
        }
        executor.execute(() -> {
            // Any exception thrown inside this background thread will not cause the test to fail
            // so you cannot use assert* here but must set the exceptionInExecutor which is checked after
            Future<RpcResult<AllocateIdOutput>> result;
            result = idManagerService.allocateId(new AllocateIdInputBuilder().setPoolName(ID_POOL_NAME).setIdKey(idKey).build());
            try {
                if (result.get().isSuccessful()) {
                    Long idValue = result.get().getResult().getIdValue();
                    idSet.add(idValue);
                    if (idValue > ID_LOW + BLOCK_SIZE) {
                        exceptionInExecutorAtomic.set(new AssertionFailedError("idValue <= ID_LOW + BLOCK_SIZE"));
                    }
                } else {
                    RpcError error = result.get().getErrors().iterator().next();
                    if (!error.getCause().getMessage().contains("Ids exhausted for pool : " + ID_POOL_NAME)) {
                        exceptionInExecutorAtomic.set(error.getCause());
                    }
                }
            } catch (InterruptedException | ExecutionException e) {
                exceptionInExecutorAtomic.set(e);
            } finally {
                latch.countDown();
            }
        });
    }
    if (!latch.await(13, SECONDS)) {
        fail("latch.await(13, SECONDS) timed out :(");
    }
    Throwable exceptionInExecutor = exceptionInExecutorAtomic.get();
    if (exceptionInExecutor != null) {
        throw exceptionInExecutor;
    }
    if (isSameKey) {
        assertEquals(1, idSet.size());
    } else {
        assertEquals(numberOfTasks, idSet.size());
    }
}
Also used : RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) RpcError(org.opendaylight.yangtools.yang.common.RpcError) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) AllocateIdInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdInputBuilder) ExecutorService(java.util.concurrent.ExecutorService) AssertionFailedError(junit.framework.AssertionFailedError) ExecutionException(java.util.concurrent.ExecutionException)

Example 49 with RpcError

use of org.opendaylight.yangtools.yang.common.RpcError in project genius by opendaylight.

the class TestFutureRpcResults method assertRpcErrorCause.

private static <T> void assertRpcErrorCause(RpcResult<T> rpcResult, Class<?> expected1stExceptionClass, String expected1stRpcErrorMessage) {
    assertThat(rpcResult.isSuccessful()).named("rpcResult.isSuccessful").isFalse();
    Collection<RpcError> errors = rpcResult.getErrors();
    assertThat(errors).named("rpcResult.errors").hasSize(1);
    RpcError error1 = errors.iterator().next();
    assertThat(error1.getErrorType()).named("rpcResult.errors[0].errorType").isEqualTo(ErrorType.APPLICATION);
    assertThat(error1.getMessage()).named("rpcResult.errors[0].message").isEqualTo(expected1stRpcErrorMessage);
    if (error1.getCause() != null) {
        // Check needed because FutureRpcResults does not propagate cause if OperationFailedException
        assertThat(error1.getCause()).named("rpcResult.errors[0].cause").isInstanceOf(expected1stExceptionClass);
    }
}
Also used : RpcError(org.opendaylight.yangtools.yang.common.RpcError)

Aggregations

RpcError (org.opendaylight.yangtools.yang.common.RpcError)49 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)20 Test (org.junit.Test)13 ExecutionException (java.util.concurrent.ExecutionException)8 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)6 ArrayList (java.util.ArrayList)5 TimeoutException (java.util.concurrent.TimeoutException)5 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)4 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)3 Collection (java.util.Collection)3 VpnInstance (org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.instances.VpnInstance)3 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)3 DistributedShardRegistration (org.opendaylight.controller.cluster.sharding.DistributedShardFactory.DistributedShardRegistration)2 RoutedGetConstantService (org.opendaylight.controller.clustering.it.provider.impl.RoutedGetConstantService)2 YnlListener (org.opendaylight.controller.clustering.it.provider.impl.YnlListener)2 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)2 ActorRef (akka.actor.ActorRef)1 Props (akka.actor.Props)1 Optional (com.google.common.base.Optional)1 Preconditions (com.google.common.base.Preconditions)1