Search in sources :

Example 21 with RpcError

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

the class MockPlugin method getSwitchFeatures.

protected void getSwitchFeatures() {
    GetFeaturesInputBuilder featuresBuilder = new GetFeaturesInputBuilder();
    featuresBuilder.setVersion((short) 4);
    featuresBuilder.setXid(3L);
    GetFeaturesInput featuresInput = featuresBuilder.build();
    try {
        LOGGER.debug("Requesting features ");
        RpcResult<GetFeaturesOutput> rpcResult = adapter.getFeatures(featuresInput).get(2500, TimeUnit.MILLISECONDS);
        if (rpcResult.isSuccessful()) {
            byte[] byteArray = rpcResult.getResult().getDatapathId().toByteArray();
            LOGGER.debug("DatapathId: {}", Arrays.toString(byteArray));
        } else {
            RpcError rpcError = rpcResult.getErrors().iterator().next();
            LOGGER.warn("rpcResult failed", rpcError.getCause());
        }
    } catch (InterruptedException | ExecutionException | TimeoutException e) {
        LOGGER.error("getSwitchFeatures() exception caught: ", e.getMessage(), e);
    }
}
Also used : GetFeaturesInput(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesInput) GetFeaturesOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput) GetFeaturesInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesInputBuilder) RpcError(org.opendaylight.yangtools.yang.common.RpcError) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException)

Example 22 with RpcError

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

the class MappingServiceTest method getMappingTest_withNullMapRecord.

/**
 * Tests {@link MappingService#getMapping} method with null MappingRecord.
 */
@Test
public void getMappingTest_withNullMapRecord() throws ExecutionException, InterruptedException {
    // input
    final GetMappingInput getMappingInput = new GetMappingInputBuilder().setEid(IPV4_EID).build();
    Mockito.when(mappingSystem.getMapping(getMappingInput.getEid())).thenReturn(null);
    final RpcResult<Object> rpc = RpcResultBuilder.failed().withError(RpcError.ErrorType.APPLICATION, "data-missing", "No mapping was found in the mapping database").build();
    final RpcError error = rpc.getErrors().iterator().next();
    // result
    final Future<RpcResult<GetMappingOutput>> result = (mappingService.getMapping(getMappingInput));
    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 : GetMappingInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.GetMappingInputBuilder) GetMappingInput(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.GetMappingInput) RpcError(org.opendaylight.yangtools.yang.common.RpcError) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) Test(org.junit.Test)

Example 23 with RpcError

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

the class MappingServiceTest method updateKeyTest_withNullMapAuthkey.

/**
 * Tests {@link MappingService#updateKey} method with null MappingAuthkey.
 */
@Test
public void updateKeyTest_withNullMapAuthkey() throws ExecutionException, InterruptedException {
    final UpdateKeyInput updateKeyInput = new UpdateKeyInputBuilder().setEid(IPV4_EID).build();
    Mockito.when(mappingSystem.getAuthenticationKey(IPV4_EID)).thenReturn(null);
    // input
    final RpcResult<Object> rpc = RpcResultBuilder.failed().withError(RpcError.ErrorType.PROTOCOL, "data-missing", "Key doesn't exist! Please use add-key if you want to create a new authentication key.").build();
    final RpcError error = rpc.getErrors().iterator().next();
    // result
    final Future<RpcResult<Void>> result = mappingService.updateKey(updateKeyInput);
    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 : UpdateKeyInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.UpdateKeyInputBuilder) RpcError(org.opendaylight.yangtools.yang.common.RpcError) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) UpdateKeyInput(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.UpdateKeyInput) Test(org.junit.Test)

Example 24 with RpcError

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

the class MappingServiceTest method getKeyTest_withNullMappingAuthkey.

/**
 * Tests {@link MappingService#getKey} method with null MappingAuthkey.
 */
@Test
public void getKeyTest_withNullMappingAuthkey() throws ExecutionException, InterruptedException {
    // input
    final GetKeyInput getKeyInput = new GetKeyInputBuilder().setEid(IPV4_EID).build();
    Mockito.when(mappingSystem.getAuthenticationKey(getKeyInput.getEid())).thenReturn(null);
    final RpcResult<Object> rpc = RpcResultBuilder.failed().withError(RpcError.ErrorType.APPLICATION, "data-missing", "Key was not found in the mapping database").build();
    final RpcError error = rpc.getErrors().iterator().next();
    // result
    final Future<RpcResult<GetKeyOutput>> result = mappingService.getKey(getKeyInput);
    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 : GetKeyInput(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.GetKeyInput) RpcError(org.opendaylight.yangtools.yang.common.RpcError) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) GetKeyInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.GetKeyInputBuilder) Test(org.junit.Test)

Example 25 with RpcError

use of org.opendaylight.yangtools.yang.common.RpcError 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;
}
Also used : DistributedShardRegistration(org.opendaylight.controller.cluster.sharding.DistributedShardFactory.DistributedShardRegistration) DOMDataTreeIdentifier(org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) RpcError(org.opendaylight.yangtools.yang.common.RpcError) DOMDataTreeShardingConflictException(org.opendaylight.mdsal.dom.api.DOMDataTreeShardingConflictException) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)

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