Search in sources :

Example 21 with CommitInfo

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

the class ServerSessionManager method start.

// Initialize the operational view of the topology.
final ListenableFuture<Boolean> start() {
    LOG.info("Creating PCEP Topology {}", topologyId());
    final var tx = dependencies.getDataBroker().newWriteOnlyTransaction();
    tx.put(LogicalDatastoreType.OPERATIONAL, topology, new TopologyBuilder().withKey(topology.getKey()).setTopologyTypes(new TopologyTypesBuilder().addAugmentation(new TopologyTypes1Builder().setTopologyPcep(new TopologyPcepBuilder().build()).build()).build()).build());
    final var future = SettableFuture.<Boolean>create();
    final var txFuture = tx.commit();
    txFuture.addCallback(new FutureCallback<CommitInfo>() {

        @Override
        public void onSuccess(final CommitInfo result) {
            LOG.info("PCEP Topology {} created successfully.", topologyId());
            isClosed.set(false);
            future.set(Boolean.TRUE);
        }

        @Override
        public void onFailure(final Throwable failure) {
            LOG.error("Failed to create PCEP Topology {}.", topologyId(), failure);
            isClosed.set(true);
            future.set(Boolean.FALSE);
        }
    }, MoreExecutors.directExecutor());
    return future;
}
Also used : TopologyTypesBuilder(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.TopologyTypesBuilder) TopologyBuilder(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyBuilder) TopologyTypes1Builder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev200120.TopologyTypes1Builder) CommitInfo(org.opendaylight.mdsal.common.api.CommitInfo) TopologyPcepBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev200120.topology.pcep.type.TopologyPcepBuilder) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean)

Example 22 with CommitInfo

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

the class ServerSessionManager method stop.

final synchronized FluentFuture<? extends CommitInfo> stop() {
    if (isClosed.getAndSet(true)) {
        LOG.error("Session Manager has already been closed.");
        return CommitInfo.emptyFluentFuture();
    }
    for (final TopologySessionListener node : nodes.values()) {
        node.close();
    }
    nodes.clear();
    for (final TopologyNodeState topologyNodeState : state.values()) {
        topologyNodeState.close();
    }
    state.clear();
    final WriteTransaction t = dependencies.getDataBroker().newWriteOnlyTransaction();
    t.delete(LogicalDatastoreType.OPERATIONAL, topology);
    final FluentFuture<? extends CommitInfo> future = t.commit();
    future.addCallback(new FutureCallback<CommitInfo>() {

        @Override
        public void onSuccess(final CommitInfo result) {
            LOG.debug("Topology {} removed", topology);
        }

        @Override
        public void onFailure(final Throwable throwable) {
            LOG.warn("Failed to remove Topology {}", topology, throwable);
        }
    }, MoreExecutors.directExecutor());
    return future;
}
Also used : WriteTransaction(org.opendaylight.mdsal.binding.api.WriteTransaction) CommitInfo(org.opendaylight.mdsal.common.api.CommitInfo)

Example 23 with CommitInfo

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

the class TopologyNodeState method released.

synchronized void released(final boolean persist) {
    // We might want to persist topology node for later re-use.
    if (!persist) {
        final WriteTransaction trans = this.chain.newWriteOnlyTransaction();
        trans.delete(LogicalDatastoreType.OPERATIONAL, this.nodeId);
        trans.commit().addCallback(new FutureCallback<CommitInfo>() {

            @Override
            public void onSuccess(final CommitInfo result) {
                LOG.trace("Internal state for node {} cleaned up successfully", TopologyNodeState.this.nodeId);
            }

            @Override
            public void onFailure(final Throwable throwable) {
                LOG.error("Failed to cleanup internal state for session {}", TopologyNodeState.this.nodeId, throwable);
            }
        }, MoreExecutors.directExecutor());
    }
    close();
    this.lastReleased = System.nanoTime();
}
Also used : WriteTransaction(org.opendaylight.mdsal.binding.api.WriteTransaction) CommitInfo(org.opendaylight.mdsal.common.api.CommitInfo)

Example 24 with CommitInfo

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

the class NodeChangedListener method onDataTreeChanged.

@Override
public void onDataTreeChanged(final Collection<DataTreeModification<Node>> changes) {
    final ReadWriteTransaction trans = this.dataProvider.newReadWriteTransaction();
    final Set<InstanceIdentifier<ReportedLsp>> lsps = new HashSet<>();
    final Set<InstanceIdentifier<Node>> nodes = new HashSet<>();
    final Map<InstanceIdentifier<?>, DataObject> original = new HashMap<>();
    final Map<InstanceIdentifier<?>, DataObject> updated = new HashMap<>();
    final Map<InstanceIdentifier<?>, DataObject> created = new HashMap<>();
    for (final DataTreeModification<?> change : changes) {
        final InstanceIdentifier<?> iid = change.getRootPath().getRootIdentifier();
        final DataObjectModification<?> rootNode = change.getRootNode();
        handleChangedNode(rootNode, iid, lsps, nodes, original, updated, created);
    }
    // Now walk all nodes, check for removals/additions and cascade them to LSPs
    for (final InstanceIdentifier<Node> iid : nodes) {
        enumerateLsps(iid, (Node) original.get(iid), lsps);
        enumerateLsps(iid, (Node) updated.get(iid), lsps);
        enumerateLsps(iid, (Node) created.get(iid), lsps);
    }
    // We now have list of all affected LSPs. Walk them create/remove them
    updateTransaction(trans, lsps, original, updated, created);
    trans.commit().addCallback(new FutureCallback<CommitInfo>() {

        @Override
        public void onSuccess(final CommitInfo result) {
            LOG.trace("Topology change committed successfully");
        }

        @Override
        public void onFailure(final Throwable throwable) {
            LOG.error("Failed to propagate a topology change, target topology became inconsistent", throwable);
        }
    }, MoreExecutors.directExecutor());
}
Also used : HashMap(java.util.HashMap) SupportingNode(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.node.attributes.SupportingNode) Node(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node) DataObject(org.opendaylight.yangtools.yang.binding.DataObject) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) ReadWriteTransaction(org.opendaylight.mdsal.binding.api.ReadWriteTransaction) CommitInfo(org.opendaylight.mdsal.common.api.CommitInfo) HashSet(java.util.HashSet)

Example 25 with CommitInfo

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

the class AssociateHwvtepToElanJob method createLogicalSwitch.

private FluentFuture<? extends @NonNull CommitInfo> createLogicalSwitch() {
    final String logicalSwitchName = ElanL2GatewayUtils.getLogicalSwitchFromElan(elanInstance.getElanInstanceName());
    String segmentationId = ElanUtils.getVxlanSegmentationId(elanInstance).toString();
    String replicationMode = "";
    LOG.trace("logical switch {} is created on {} with VNI {}", logicalSwitchName, l2GatewayDevice.getHwvtepNodeId(), segmentationId);
    NodeId hwvtepNodeId = new NodeId(l2GatewayDevice.getHwvtepNodeId());
    String dbVersion = L2GatewayUtils.getConfigDbVersion(dataBroker, hwvtepNodeId);
    try {
        dbVersion = dbVersion != null ? dbVersion : HwvtepUtils.getDbVersion(dataBroker, hwvtepNodeId);
    } catch (ExecutionException | InterruptedException e) {
        LOG.error("Failed to Read Node {} from Oper-Topo for retrieving DB version", hwvtepNodeId);
    }
    if (SouthboundUtils.compareDbVersionToMinVersion(dbVersion, "1.6.0")) {
        replicationMode = "source_node";
    }
    LOG.trace("logical switch {} has schema version {}, replication mode set to {}", logicalSwitchName, dbVersion, replicationMode);
    LogicalSwitches logicalSwitch = HwvtepSouthboundUtils.createLogicalSwitch(logicalSwitchName, elanInstance.getDescription(), segmentationId, replicationMode);
    FluentFuture<? extends @NonNull CommitInfo> lsCreateFuture = HwvtepUtils.addLogicalSwitch(dataBroker, hwvtepNodeId, logicalSwitch);
    Futures.addCallback(lsCreateFuture, new FutureCallback<CommitInfo>() {

        @Override
        public void onSuccess(CommitInfo noarg) {
            // Listener will be closed after all configuration completed
            // on hwvtep by
            // listener itself
            LOG.trace("Successful in initiating logical switch {} creation", logicalSwitchName);
        }

        @Override
        public void onFailure(Throwable error) {
            LOG.error("Failed logical switch {} creation", logicalSwitchName, error);
        }
    }, MoreExecutors.directExecutor());
    return lsCreateFuture;
}
Also used : LogicalSwitches(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LogicalSwitches) NonNull(org.eclipse.jdt.annotation.NonNull) NodeId(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId) CommitInfo(org.opendaylight.mdsal.common.api.CommitInfo) ExecutionException(java.util.concurrent.ExecutionException)

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