Search in sources :

Example 1 with UpdateTableOutput

use of org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableOutput in project openflowplugin by opendaylight.

the class TableForwarderTest method testUpdate.

@Test
public void testUpdate() throws Exception {
    Mockito.when(salTableService.updateTable(updateTableInputCpt.capture())).thenReturn(RpcResultBuilder.success(new UpdateTableOutputBuilder().setTransactionId(txId).build()).buildFuture());
    final TableFeatures tableFeaturesUpdate = new TableFeaturesBuilder(tableFeatures).setName("another-table").build();
    final Future<RpcResult<UpdateTableOutput>> updateResult = tableForwarder.update(tableFeaturesPath, tableFeatures, tableFeaturesUpdate, flowCapableNodePath);
    Mockito.verify(salTableService).updateTable(Matchers.<UpdateTableInput>any());
    Assert.assertTrue(updateResult.isDone());
    final RpcResult<UpdateTableOutput> updateTableResult = updateResult.get(2, TimeUnit.SECONDS);
    Assert.assertTrue(updateTableResult.isSuccessful());
    Assert.assertEquals(1, updateTableResult.getResult().getTransactionId().getValue().intValue());
    final UpdateTableInput updateTableInput = updateTableInputCpt.getValue();
    Assert.assertEquals(tablePath, updateTableInput.getTableRef().getValue());
    Assert.assertEquals(nodePath, updateTableInput.getNode().getValue());
    Assert.assertEquals(1, updateTableInput.getOriginalTable().getTableFeatures().size());
    Assert.assertEquals("test-table", updateTableInput.getOriginalTable().getTableFeatures().get(0).getName());
    Assert.assertEquals(1, updateTableInput.getUpdatedTable().getTableFeatures().size());
    Assert.assertEquals("another-table", updateTableInput.getUpdatedTable().getTableFeatures().get(0).getName());
}
Also used : UpdateTableOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableOutput) TableFeatures(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.TableFeatures) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) TableFeaturesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.TableFeaturesBuilder) UpdateTableInput(org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableInput) UpdateTableOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableOutputBuilder) Test(org.junit.Test)

Example 2 with UpdateTableOutput

use of org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableOutput in project openflowplugin by opendaylight.

the class TableForwarder method update.

@Override
public Future<RpcResult<UpdateTableOutput>> update(final InstanceIdentifier<TableFeatures> identifier, final TableFeatures original, final TableFeatures update, final InstanceIdentifier<FlowCapableNode> nodeIdent) {
    LOG.debug("Forwarding Table Update request [Tbl id, node Id {} {}", identifier, nodeIdent);
    final UpdateTableInputBuilder builder = new UpdateTableInputBuilder();
    builder.setNode(new NodeRef(nodeIdent.firstIdentifierOf(Node.class)));
    final InstanceIdentifier<Table> iiToTable = nodeIdent.child(Table.class, new TableKey(identifier.firstKeyOf(TableFeatures.class).getTableId()));
    builder.setTableRef(new TableRef(iiToTable));
    builder.setUpdatedTable(new UpdatedTableBuilder().setTableFeatures(Collections.singletonList(update)).build());
    builder.setOriginalTable(new OriginalTableBuilder().setTableFeatures(Collections.singletonList(original)).build());
    LOG.debug("Invoking SalTableService {} ", nodeIdent);
    return salTableService.updateTable(builder.build());
}
Also used : NodeRef(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef) Table(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table) OriginalTableBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.table.update.OriginalTableBuilder) TableFeatures(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.TableFeatures) UpdatedTableBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.table.update.UpdatedTableBuilder) TableKey(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey) UpdateTableInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableInputBuilder) TableRef(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TableRef)

Example 3 with UpdateTableOutput

use of org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableOutput in project openflowplugin by opendaylight.

the class TableForwarder method update.

@Override
public void update(final InstanceIdentifier<TableFeatures> identifier, final TableFeatures original, final TableFeatures update, final InstanceIdentifier<FlowCapableNode> nodeIdent) {
    LOG.debug("Received the Table Update request [Tbl id, node Id, original, upd" + " " + identifier + " " + nodeIdent + " " + original + " " + update);
    final TableFeatures originalTableFeatures = original;
    TableFeatures updatedTableFeatures;
    if (null == update) {
        updatedTableFeatures = original;
    } else {
        updatedTableFeatures = update;
    }
    final UpdateTableInputBuilder builder = new UpdateTableInputBuilder();
    builder.setNode(new NodeRef(nodeIdent.firstIdentifierOf(Node.class)));
    // TODO: reconsider model - this particular field is not used in service
    // implementation
    builder.setTableRef(new TableRef(identifier));
    builder.setTransactionUri(new Uri(provider.getNewTransactionId()));
    builder.setUpdatedTable(new UpdatedTableBuilder().setTableFeatures(Collections.singletonList(updatedTableFeatures)).build());
    builder.setOriginalTable(new OriginalTableBuilder().setTableFeatures(Collections.singletonList(originalTableFeatures)).build());
    LOG.debug("Invoking SalTableService ");
    if (this.provider.getSalTableService() != null) {
        LOG.debug(" Handle to SalTableServices" + this.provider.getSalTableService());
    }
    final Future<RpcResult<UpdateTableOutput>> resultFuture = this.provider.getSalTableService().updateTable(builder.build());
    JdkFutures.addErrorLogging(resultFuture, LOG, "updateTable");
}
Also used : NodeRef(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef) OriginalTableBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.table.update.OriginalTableBuilder) TableFeatures(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.TableFeatures) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) UpdatedTableBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.table.update.UpdatedTableBuilder) UpdateTableInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableInputBuilder) Uri(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri) TableRef(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TableRef)

Example 4 with UpdateTableOutput

use of org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableOutput in project openflowplugin by opendaylight.

the class SingleLayerTableMultipartServiceTest method handleAndReply.

@Test
public void handleAndReply() throws Exception {
    mockSuccessfulFuture(Collections.singletonList(new MultipartReplyBuilder().setXid(XID).setMultipartReplyBody(new MultipartReplyTableFeaturesBuilder().setTableFeatures(Collections.singletonList(new TableFeaturesBuilder().setMaxEntries(MAX_ENTRIES).build())).build()).build()));
    final UpdateTableInput input = new UpdateTableInputBuilder().setUpdatedTable(new UpdatedTableBuilder().setTableFeatures(Collections.singletonList(new TableFeaturesBuilder().setMaxEntries(MAX_ENTRIES).build())).build()).build();
    final Future<RpcResult<UpdateTableOutput>> rpcResultFuture = service.handleAndReply(input);
    final RpcResult<UpdateTableOutput> result = rpcResultFuture.get();
    assertTrue(result.isSuccessful());
    assertEquals(XID, result.getResult().getTransactionId().getValue().longValue());
}
Also used : UpdateTableOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableOutput) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) MultipartReplyBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.multipart.types.rev170112.MultipartReplyBuilder) TableFeaturesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.TableFeaturesBuilder) MultipartReplyTableFeaturesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.multipart.reply.multipart.reply.body.MultipartReplyTableFeaturesBuilder) UpdateTableInput(org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableInput) UpdatedTableBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.table.update.UpdatedTableBuilder) MultipartReplyTableFeaturesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.multipart.reply.multipart.reply.body.MultipartReplyTableFeaturesBuilder) UpdateTableInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableInputBuilder) Test(org.junit.Test)

Example 5 with UpdateTableOutput

use of org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableOutput in project openflowplugin by opendaylight.

the class MultiLayerTableMultipartService method handleAndReply.

@Override
public Future<RpcResult<UpdateTableOutput>> handleAndReply(UpdateTableInput input) {
    final ListenableFuture<RpcResult<List<MultipartReply>>> multipartFuture = handleServiceCall(input);
    final SettableFuture<RpcResult<UpdateTableOutput>> finalFuture = SettableFuture.create();
    class CallBackImpl implements FutureCallback<RpcResult<List<MultipartReply>>> {

        @Override
        @SuppressWarnings("checkstyle:IllegalCatch")
        public void onSuccess(@Nonnull final RpcResult<List<MultipartReply>> result) {
            if (result.isSuccessful()) {
                final List<MultipartReply> multipartReplies = result.getResult();
                if (multipartReplies.isEmpty()) {
                    LOG.debug("Multipart reply to table features request shouldn't be empty list.");
                    finalFuture.set(RpcResultBuilder.<UpdateTableOutput>failed().withError(ErrorType.RPC, "Multipart reply list is empty.").build());
                } else {
                    final Long xid = multipartReplies.get(0).getXid();
                    LOG.debug("OnSuccess, rpc result successful," + " multipart response for rpc update-table with xid {} obtained.", xid);
                    final UpdateTableOutputBuilder updateTableOutputBuilder = new UpdateTableOutputBuilder();
                    updateTableOutputBuilder.setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
                    finalFuture.set(RpcResultBuilder.success(updateTableOutputBuilder.build()).build());
                    try {
                        storeStatistics(convertToSalTableFeatures(multipartReplies));
                    } catch (Exception e) {
                        LOG.warn("Not able to write to operational datastore: {}", e.getMessage());
                    }
                }
            } else {
                LOG.debug("OnSuccess, rpc result unsuccessful," + " multipart response for rpc update-table was unsuccessful.");
                finalFuture.set(RpcResultBuilder.<UpdateTableOutput>failed().withRpcErrors(result.getErrors()).build());
            }
        }

        @Override
        public void onFailure(final Throwable throwable) {
            LOG.error("Failure multipart response for table features request. Exception: {}", throwable);
            finalFuture.set(RpcResultBuilder.<UpdateTableOutput>failed().withError(ErrorType.RPC, "Future error", throwable).build());
        }
    }
    Futures.addCallback(multipartFuture, new CallBackImpl(), MoreExecutors.directExecutor());
    return finalFuture;
}
Also used : Nonnull(javax.annotation.Nonnull) MultipartReply(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) ServiceException(org.opendaylight.openflowplugin.impl.services.util.ServiceException) TransactionId(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.TransactionId) ArrayList(java.util.ArrayList) List(java.util.List) UpdateTableOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableOutputBuilder) FutureCallback(com.google.common.util.concurrent.FutureCallback)

Aggregations

RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)5 UpdateTableInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableInputBuilder)4 UpdatedTableBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.table.update.UpdatedTableBuilder)4 TableFeatures (org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.TableFeatures)4 Test (org.junit.Test)3 UpdateTableInput (org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableInput)3 UpdateTableOutput (org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableOutput)3 FutureCallback (com.google.common.util.concurrent.FutureCallback)2 List (java.util.List)2 NodeRef (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef)2 MultipartReply (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply)2 OriginalTableBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.table.update.OriginalTableBuilder)2 TableRef (org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TableRef)2 SettableFuture (com.google.common.util.concurrent.SettableFuture)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 ExecutionException (java.util.concurrent.ExecutionException)1 Future (java.util.concurrent.Future)1 Nonnull (javax.annotation.Nonnull)1 Assert (org.junit.Assert)1