Search in sources :

Example 86 with RpcResult

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

the class OF13DeviceInitializer method initializeNodeInformation.

@Override
protected Future<Void> initializeNodeInformation(@Nonnull final DeviceContext deviceContext, final boolean switchFeaturesMandatory, final boolean skipTableFeatures, @Nullable final MultipartWriterProvider multipartWriterProvider, @Nullable final ConvertorExecutor convertorExecutor) {
    final ConnectionContext connectionContext = Preconditions.checkNotNull(deviceContext.getPrimaryConnectionContext());
    final DeviceState deviceState = Preconditions.checkNotNull(deviceContext.getDeviceState());
    final DeviceInfo deviceInfo = Preconditions.checkNotNull(deviceContext.getDeviceInfo());
    final Capabilities capabilities = connectionContext.getFeatures().getCapabilities();
    LOG.debug("Setting capabilities for device {}", deviceInfo);
    DeviceStateUtil.setDeviceStateBasedOnV13Capabilities(deviceState, capabilities);
    // First process description reply, write data to DS and write consequent data if successful
    return Futures.transformAsync(requestMultipart(MultipartType.OFPMPDESC, deviceContext), (AsyncFunction<RpcResult<List<OfHeader>>, Void>) input -> {
        translateAndWriteResult(MultipartType.OFPMPDESC, input.getResult(), deviceContext, multipartWriterProvider, convertorExecutor);
        final List<ListenableFuture<RpcResult<List<OfHeader>>>> futures = new ArrayList<>();
        futures.add(requestAndProcessMultipart(MultipartType.OFPMPMETERFEATURES, deviceContext, skipTableFeatures, multipartWriterProvider, convertorExecutor));
        futures.add(requestAndProcessMultipart(MultipartType.OFPMPGROUPFEATURES, deviceContext, skipTableFeatures, multipartWriterProvider, convertorExecutor));
        futures.add(requestAndProcessMultipart(MultipartType.OFPMPTABLEFEATURES, deviceContext, skipTableFeatures, multipartWriterProvider, convertorExecutor));
        futures.add(requestAndProcessMultipart(MultipartType.OFPMPPORTDESC, deviceContext, skipTableFeatures, multipartWriterProvider, convertorExecutor));
        return Futures.transform(switchFeaturesMandatory ? Futures.allAsList(futures) : Futures.successfulAsList(futures), new Function<List<RpcResult<List<OfHeader>>>, Void>() {

            @Nullable
            @Override
            public Void apply(@Nullable final List<RpcResult<List<OfHeader>>> input) {
                LOG.info("Static node {} successfully finished collecting", deviceContext.getDeviceInfo());
                return null;
            }
        }, MoreExecutors.directExecutor());
    }, MoreExecutors.directExecutor());
}
Also used : MoreExecutors(com.google.common.util.concurrent.MoreExecutors) MultipartWriterProvider(org.opendaylight.openflowplugin.impl.datastore.MultipartWriterProvider) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) ConvertorExecutor(org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) MeterFeatures(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterFeatures) LoggerFactory(org.slf4j.LoggerFactory) MultiLayerMultipartCollectorService(org.opendaylight.openflowplugin.impl.services.multilayer.MultiLayerMultipartCollectorService) DeviceState(org.opendaylight.openflowplugin.api.openflow.device.DeviceState) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) DeviceStateUtil(org.opendaylight.openflowplugin.impl.util.DeviceStateUtil) Capabilities(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Capabilities) DeviceContext(org.opendaylight.openflowplugin.api.openflow.device.DeviceContext) OfHeader(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) SingleLayerMultipartCollectorService(org.opendaylight.openflowplugin.impl.services.singlelayer.SingleLayerMultipartCollectorService) ConnectionContext(org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext) Function(com.google.common.base.Function) Logger(org.slf4j.Logger) MultipartReplyTranslatorUtil(org.opendaylight.openflowplugin.impl.common.MultipartReplyTranslatorUtil) DeviceInitializationUtil(org.opendaylight.openflowplugin.impl.util.DeviceInitializationUtil) Collectors(java.util.stream.Collectors) FutureCallback(com.google.common.util.concurrent.FutureCallback) Objects(java.util.Objects) DeviceInfo(org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo) Futures(com.google.common.util.concurrent.Futures) List(java.util.List) RpcResultBuilder(org.opendaylight.yangtools.yang.common.RpcResultBuilder) MultipartType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType) Optional(java.util.Optional) Preconditions(com.google.common.base.Preconditions) AsyncFunction(com.google.common.util.concurrent.AsyncFunction) Function(com.google.common.base.Function) AsyncFunction(com.google.common.util.concurrent.AsyncFunction) DeviceState(org.opendaylight.openflowplugin.api.openflow.device.DeviceState) Capabilities(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Capabilities) OfHeader(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader) DeviceInfo(org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) ArrayList(java.util.ArrayList) List(java.util.List) ConnectionContext(org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext) Nullable(javax.annotation.Nullable)

Example 87 with RpcResult

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

the class SalAsyncConfigServiceImplTest method testGetAsyncTest.

@Test
public void testGetAsyncTest() throws Exception {
    final GetAsyncOutput getAsyncOutput = new GetAsyncOutputBuilder().build();
    final RpcResult<GetAsyncOutput> replyRpcResult = RpcResultBuilder.success(getAsyncOutput).build();
    final ListenableFuture<RpcResult<GetAsyncOutput>> replyFuture = Futures.immediateFuture(replyRpcResult);
    Mockito.when(mockedRequestContext.getFuture()).thenReturn(replyFuture);
    final Future<RpcResult<GetAsyncOutput>> getAsyncResult = salAsyncConfigService.getAsync(new GetAsyncInputBuilder().build());
    Assert.assertNotNull(getAsyncResult);
    Assert.assertTrue(getAsyncResult.isDone());
    Assert.assertTrue(getAsyncResult.get().isSuccessful());
    verify(mockedRequestContextStack).createRequestContext();
    verify(mockedOutboundQueue).commitEntry(Matchers.eq(ServiceMocking.DUMMY_XID_VALUE), Matchers.<OfHeader>any(), Matchers.<FutureCallback<OfHeader>>any());
}
Also used : GetAsyncInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.async.config.service.rev170619.GetAsyncInputBuilder) OfHeader(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) GetAsyncOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.async.config.service.rev170619.GetAsyncOutputBuilder) GetAsyncOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.async.config.service.rev170619.GetAsyncOutput) Test(org.junit.Test)

Example 88 with RpcResult

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

the class SalAsyncConfigServiceImplTest method testSetAsync.

@Test
public void testSetAsync() throws Exception {
    final SetAsyncInput setAsyncInput = new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.SetAsyncInputBuilder().build();
    final RpcResult<SetAsyncInput> replyRpcResult = RpcResultBuilder.success(setAsyncInput).build();
    final ListenableFuture<RpcResult<SetAsyncInput>> replyFuture = Futures.immediateFuture(replyRpcResult);
    Mockito.when(mockedRequestContext.getFuture()).thenReturn(replyFuture);
    final Future<RpcResult<Void>> setAsyncResult = salAsyncConfigService.setAsync(new SetAsyncInputBuilder().build());
    Assert.assertNotNull(setAsyncResult);
    Assert.assertTrue(setAsyncResult.isDone());
    Assert.assertTrue(setAsyncResult.get().isSuccessful());
    verify(mockedRequestContextStack).createRequestContext();
}
Also used : SetAsyncInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.async.config.service.rev170619.SetAsyncInputBuilder) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) SetAsyncInput(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.SetAsyncInput) Test(org.junit.Test)

Example 89 with RpcResult

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

the class SalEchoServiceImplTest method testSendEcho.

@Test
public void testSendEcho() throws Exception {
    final EchoOutput echoOut = new EchoOutputBuilder().setData(DUMMY_DATA).build();
    final RpcResult<EchoOutput> replyRpcResult = RpcResultBuilder.success(echoOut).build();
    final ListenableFuture<RpcResult<EchoOutput>> replyFt = Futures.immediateFuture(replyRpcResult);
    Mockito.when(mockedRequestContext.getFuture()).thenReturn(replyFt);
    SendEchoInput sendEchoInput = new SendEchoInputBuilder().setData(DUMMY_DATA).build();
    final Future<RpcResult<SendEchoOutput>> echoOutput = salEchoService.sendEcho(sendEchoInput);
    Assert.assertNotNull(echoOutput);
    Assert.assertTrue(echoOutput.isDone());
    Assert.assertTrue(echoOutput.get().isSuccessful());
    verify(mockedRequestContextStack).createRequestContext();
    verify(mockedOutboundQueue).commitEntry(Matchers.eq(2121L), Matchers.<OfHeader>any(), Matchers.<FutureCallback<OfHeader>>any());
}
Also used : SendEchoOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.echo.service.rev150305.SendEchoOutput) EchoOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoOutput) OfHeader(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader) SendEchoInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.echo.service.rev150305.SendEchoInputBuilder) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) EchoOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoOutputBuilder) SendEchoInput(org.opendaylight.yang.gen.v1.urn.opendaylight.echo.service.rev150305.SendEchoInput) Test(org.junit.Test)

Example 90 with RpcResult

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

the class SalFlowServiceImplTest method addFlowFailCallback.

private void addFlowFailCallback(short version) throws InterruptedException, ExecutionException {
    AddFlowInput mockedAddFlowInput = new AddFlowInputBuilder().setMatch(match).setTableId((short) 1).build();
    Mockito.doReturn(Futures.<RequestContext<Object>>immediateFailedFuture(new Exception("ut-failed-response"))).when(requestContext).getFuture();
    mockingFlowRegistryLookup();
    final Future<RpcResult<AddFlowOutput>> rpcResultFuture = mockSalFlowService(version).addFlow(mockedAddFlowInput);
    assertNotNull(rpcResultFuture);
    final RpcResult<?> addFlowOutputRpcResult = rpcResultFuture.get();
    assertNotNull(addFlowOutputRpcResult);
    assertFalse(addFlowOutputRpcResult.isSuccessful());
}
Also used : AddFlowInput(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInput) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) AddFlowInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInputBuilder) DataObject(org.opendaylight.yangtools.yang.binding.DataObject) ExecutionException(java.util.concurrent.ExecutionException)

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