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;
}
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;
}
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();
}
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());
}
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;
}
Aggregations