Search in sources :

Example 36 with CommitInfo

use of org.opendaylight.mdsal.common.api.CommitInfo in project bgpcep by opendaylight.

the class BmpRouterImpl method createRouterEntry.

private synchronized void createRouterEntry() {
    Preconditions.checkState(isDatastoreWritable());
    final DOMDataTreeWriteTransaction wTx = this.domTxChain.newWriteOnlyTransaction();
    wTx.put(LogicalDatastoreType.OPERATIONAL, this.routerYangIId, Builders.mapEntryBuilder().withNodeIdentifier(NodeIdentifierWithPredicates.of(Router.QNAME, ROUTER_ID_QNAME, this.routerIp)).withChild(ImmutableNodes.leafNode(ROUTER_ID_QNAME, this.routerIp)).withChild(ImmutableNodes.leafNode(ROUTER_STATUS_QNAME, DOWN)).withChild(ImmutableNodes.mapNodeBuilder(Peer.QNAME).build()).build());
    wTx.commit().addCallback(new FutureCallback<CommitInfo>() {

        @Override
        public void onSuccess(final CommitInfo result) {
            LOG.trace("Successful commit");
        }

        @Override
        public void onFailure(final Throwable trw) {
            LOG.error("Failed commit", trw);
        }
    }, MoreExecutors.directExecutor());
}
Also used : DOMDataTreeWriteTransaction(org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction) CommitInfo(org.opendaylight.mdsal.common.api.CommitInfo)

Example 37 with CommitInfo

use of org.opendaylight.mdsal.common.api.CommitInfo in project bgpcep by opendaylight.

the class ProgrammingServiceImpl method instantiateServiceInstance.

@Override
public synchronized void instantiateServiceInstance() {
    LOG.info("Instruction Queue service {} instantiated", this.sgi.getName());
    this.reg = this.rpcProviderRegistry.registerRpcImplementation(ProgrammingService.class, this);
    final WriteTransaction wt = this.dataProvider.newWriteOnlyTransaction();
    wt.put(LogicalDatastoreType.OPERATIONAL, this.qid, new InstructionsQueueBuilder().withKey(new InstructionsQueueKey(this.instructionId)).setInstruction(Map.of()).build());
    wt.commit().addCallback(new FutureCallback<CommitInfo>() {

        @Override
        public void onSuccess(final CommitInfo result) {
            LOG.debug("Instruction Queue {} added", ProgrammingServiceImpl.this.qid);
        }

        @Override
        public void onFailure(final Throwable trw) {
            LOG.error("Failed to add Instruction Queue {}", ProgrammingServiceImpl.this.qid, trw);
        }
    }, MoreExecutors.directExecutor());
}
Also used : WriteTransaction(org.opendaylight.mdsal.binding.api.WriteTransaction) InstructionsQueueKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.InstructionsQueueKey) ProgrammingService(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.ProgrammingService) InstructionsQueueBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.InstructionsQueueBuilder) CommitInfo(org.opendaylight.mdsal.common.api.CommitInfo)

Example 38 with CommitInfo

use of org.opendaylight.mdsal.common.api.CommitInfo in project bgpcep by opendaylight.

the class ProgrammingServiceImpl method closeServiceInstance.

@Override
public synchronized FluentFuture<? extends CommitInfo> closeServiceInstance() {
    LOG.info("Closing Instruction Queue service {}", this.sgi.getName());
    if (this.reg != null) {
        this.reg.close();
        this.reg = null;
    }
    for (final InstructionImpl instruction : this.insns.values()) {
        instruction.tryCancel(null);
    }
    // Workaround for BUG-2283
    final WriteTransaction wt = this.dataProvider.newWriteOnlyTransaction();
    wt.delete(LogicalDatastoreType.OPERATIONAL, this.qid);
    final FluentFuture<? extends CommitInfo> future = wt.commit();
    future.addCallback(new FutureCallback<CommitInfo>() {

        @Override
        public void onSuccess(final CommitInfo result) {
            LOG.debug("Instruction Queue {} removed", ProgrammingServiceImpl.this.qid);
        }

        @Override
        public void onFailure(final Throwable trw) {
            LOG.error("Failed to shutdown Instruction Queue {}", ProgrammingServiceImpl.this.qid, trw);
        }
    }, MoreExecutors.directExecutor());
    return future;
}
Also used : WriteTransaction(org.opendaylight.mdsal.binding.api.WriteTransaction) CommitInfo(org.opendaylight.mdsal.common.api.CommitInfo)

Example 39 with CommitInfo

use of org.opendaylight.mdsal.common.api.CommitInfo in project bgpcep by opendaylight.

the class AppPeerBenchmark method processRoutes.

private long processRoutes(final Ipv4Prefix ipv4Prefix, final Uint32 count, final Uint32 batch, final Attributes attributes) {
    WriteTransaction wt = this.txChain.newWriteOnlyTransaction();
    String address = getAdddressFromPrefix(ipv4Prefix);
    final long countLong = count.longValue();
    final long batchLong = batch.longValue();
    final Stopwatch stopwatch = Stopwatch.createStarted();
    for (int i = 1; i <= countLong; i++) {
        final Ipv4RouteKey routeKey = new Ipv4RouteKey(NON_PATH_ID, createKey(address));
        final KeyedInstanceIdentifier<Ipv4Route, Ipv4RouteKey> routeIId = this.routesIId.child(Ipv4Route.class, routeKey);
        if (attributes != null) {
            final Ipv4RouteBuilder ipv4RouteBuilder = new Ipv4RouteBuilder();
            ipv4RouteBuilder.setRouteKey(routeKey.getRouteKey());
            ipv4RouteBuilder.setPrefix(new Ipv4Prefix(routeKey.getRouteKey()));
            ipv4RouteBuilder.withKey(routeKey);
            ipv4RouteBuilder.setAttributes(attributes);
            final Ipv4Route ipv4Route = ipv4RouteBuilder.build();
            wt.put(LogicalDatastoreType.CONFIGURATION, routeIId, ipv4Route);
        } else {
            wt.delete(LogicalDatastoreType.CONFIGURATION, routeIId);
        }
        if (i % batchLong == 0) {
            wt.commit().addCallback(new FutureCallback<CommitInfo>() {

                @Override
                public void onSuccess(final CommitInfo result) {
                    LOG.trace("Successful commit");
                }

                @Override
                public void onFailure(final Throwable trw) {
                    LOG.error("Failed commit", trw);
                }
            }, MoreExecutors.directExecutor());
            wt = this.txChain.newWriteOnlyTransaction();
        }
        address = increasePrefix(address);
    }
    wt.commit().addCallback(new FutureCallback<CommitInfo>() {

        @Override
        public void onSuccess(final CommitInfo result) {
            LOG.trace("Route batch stored.");
        }

        @Override
        public void onFailure(final Throwable throwable) {
            LOG.error("Failed to store route batch.", throwable);
        }
    }, MoreExecutors.directExecutor());
    return stopwatch.stop().elapsed(TimeUnit.MILLISECONDS);
}
Also used : WriteTransaction(org.opendaylight.mdsal.binding.api.WriteTransaction) Stopwatch(com.google.common.base.Stopwatch) Ipv4RouteBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.ipv4.routes.ipv4.routes.Ipv4RouteBuilder) Ipv4RouteKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.ipv4.routes.ipv4.routes.Ipv4RouteKey) CommitInfo(org.opendaylight.mdsal.common.api.CommitInfo) Ipv4Prefix(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix) Ipv4Route(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.ipv4.routes.ipv4.routes.Ipv4Route)

Example 40 with CommitInfo

use of org.opendaylight.mdsal.common.api.CommitInfo in project bgpcep by opendaylight.

the class AppPeerBenchmark method start.

public void start() {
    LOG.debug("Instantiating App Peer Benchmark : {}", this.appRibId);
    final ApplicationRib appRib = new ApplicationRibBuilder().setId(new ApplicationRibId(new ApplicationRibId(this.appRibId))).setTables(EMPTY_TABLES).build();
    final WriteTransaction wTx = this.txChain.newWriteOnlyTransaction();
    wTx.put(LogicalDatastoreType.CONFIGURATION, this.appIID, appRib);
    wTx.commit().addCallback(new FutureCallback<CommitInfo>() {

        @Override
        public void onSuccess(final CommitInfo result) {
            LOG.info("Empty Structure created for Application Peer Benchmark {}", AppPeerBenchmark.this.appRibId);
        }

        @Override
        public void onFailure(final Throwable throwable) {
            LOG.error("Failed to create Empty Structure for Application Peer Benchmark {}", AppPeerBenchmark.this.appRibId, throwable);
        }
    }, MoreExecutors.directExecutor());
}
Also used : WriteTransaction(org.opendaylight.mdsal.binding.api.WriteTransaction) ApplicationRibBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.ApplicationRibBuilder) ApplicationRib(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.ApplicationRib) ApplicationRibId(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.ApplicationRibId) CommitInfo(org.opendaylight.mdsal.common.api.CommitInfo)

Aggregations

CommitInfo (org.opendaylight.mdsal.common.api.CommitInfo)59 DOMDataTreeWriteTransaction (org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction)26 WriteTransaction (org.opendaylight.mdsal.binding.api.WriteTransaction)23 ReadWriteTransaction (org.opendaylight.mdsal.binding.api.ReadWriteTransaction)12 ExecutionException (java.util.concurrent.ExecutionException)10 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)8 LogicalDatastoreType (org.opendaylight.mdsal.common.api.LogicalDatastoreType)7 TablesKey (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.TablesKey)5 TransactionChain (org.opendaylight.mdsal.binding.api.TransactionChain)4 DOMTransactionChain (org.opendaylight.mdsal.dom.api.DOMTransactionChain)4 NodeIdentifierWithPredicates (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates)4 FluentFuture (com.google.common.util.concurrent.FluentFuture)3 FutureCallback (com.google.common.util.concurrent.FutureCallback)3 Collection (java.util.Collection)3 Stopwatch (com.google.common.base.Stopwatch)2 Futures (com.google.common.util.concurrent.Futures)2 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)2 MoreExecutors (com.google.common.util.concurrent.MoreExecutors)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2