use of org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction in project genius by opendaylight.
the class AlivenessMonitor method removeMonitorIdFromInterfaceAssociation.
private void removeMonitorIdFromInterfaceAssociation(final Long monitorId, final String interfaceName) {
LOG.debug("Remove monitorId {} from Interface association {}", monitorId, interfaceName);
final ReadWriteTransaction tx = dataBroker.newReadWriteTransaction();
ListenableFuture<Optional<InterfaceMonitorEntry>> readFuture = tx.read(LogicalDatastoreType.OPERATIONAL, getInterfaceMonitorMapId(interfaceName));
ListenableFuture<Void> updateFuture = Futures.transformAsync(readFuture, optEntry -> {
if (optEntry.isPresent()) {
InterfaceMonitorEntry entry = optEntry.get();
List<Long> monitorIds = entry.getMonitorIds();
monitorIds.remove(monitorId);
InterfaceMonitorEntry newEntry = new InterfaceMonitorEntryBuilder(entry).setKey(new InterfaceMonitorEntryKey(interfaceName)).setMonitorIds(monitorIds).build();
tx.put(LogicalDatastoreType.OPERATIONAL, getInterfaceMonitorMapId(interfaceName), newEntry, CREATE_MISSING_PARENT);
return tx.submit();
} else {
LOG.warn("No Interface map entry found {} to remove monitorId {}", interfaceName, monitorId);
tx.cancel();
return Futures.immediateFuture(null);
}
}, MoreExecutors.directExecutor());
Futures.addCallback(updateFuture, new FutureCallbackImpl(String.format("Dis-association of monitorId %d with Interface %s", monitorId, interfaceName)), MoreExecutors.directExecutor());
}
use of org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction in project genius by opendaylight.
the class AlivenessMonitor method processReceivedMonitorKey.
private void processReceivedMonitorKey(final String monitorKey) {
Preconditions.checkNotNull(monitorKey, "Monitor Key required to process the state");
LOG.debug("Processing monitorKey: {} for received packet", monitorKey);
final Semaphore lock = lockMap.get(monitorKey);
LOG.debug("Acquiring lock for monitor key : {} to process monitor packet", monitorKey);
acquireLock(lock);
final ReadWriteTransaction tx = dataBroker.newReadWriteTransaction();
ListenableFuture<Optional<MonitoringState>> stateResult = tx.read(LogicalDatastoreType.OPERATIONAL, getMonitorStateId(monitorKey));
// READ Callback
Futures.addCallback(stateResult, new FutureCallback<Optional<MonitoringState>>() {
@Override
public void onSuccess(@Nonnull Optional<MonitoringState> optState) {
if (optState.isPresent()) {
final MonitoringState currentState = optState.get();
if (LOG.isTraceEnabled()) {
LOG.trace("OnPacketReceived : Monitoring state from ODS : {} ", currentState);
}
// Long responsePendingCount = currentState.getResponsePendingCount();
//
// Need to relook at the pending count logic to support N
// out of M scenarios
// if (currentState.getState() != LivenessState.Up) {
// //Reset responsePendingCount when state changes from DOWN
// to UP
// responsePendingCount = INITIAL_COUNT;
// }
//
// if (responsePendingCount > INITIAL_COUNT) {
// responsePendingCount =
// currentState.getResponsePendingCount() - 1;
// }
Long responsePendingCount = INITIAL_COUNT;
final boolean stateChanged = currentState.getState() == LivenessState.Down || currentState.getState() == LivenessState.Unknown;
final MonitoringState state = new MonitoringStateBuilder().setMonitorKey(monitorKey).setState(LivenessState.Up).setResponsePendingCount(responsePendingCount).build();
tx.merge(LogicalDatastoreType.OPERATIONAL, getMonitorStateId(monitorKey), state);
ListenableFuture<Void> writeResult = tx.submit();
// WRITE Callback
Futures.addCallback(writeResult, new FutureCallback<Void>() {
@Override
public void onSuccess(Void noarg) {
releaseLock(lock);
if (stateChanged) {
// send notifications
if (LOG.isTraceEnabled()) {
LOG.trace("Sending notification for monitor Id : {} with Current State: {}", currentState.getMonitorId(), LivenessState.Up);
}
publishNotification(currentState.getMonitorId(), LivenessState.Up);
} else {
if (LOG.isTraceEnabled()) {
LOG.trace("Successful in writing monitoring state {} to ODS", state);
}
}
}
@Override
public void onFailure(Throwable error) {
releaseLock(lock);
LOG.warn("Error in writing monitoring state : {} to Datastore", monitorKey, error);
if (LOG.isTraceEnabled()) {
LOG.trace("Error in writing monitoring state: {} to Datastore", state);
}
}
}, callbackExecutorService);
} else {
if (LOG.isTraceEnabled()) {
LOG.trace("Monitoring State not available for key: {} to process the Packet received", monitorKey);
}
// Complete the transaction
tx.submit();
releaseLock(lock);
}
}
@Override
public void onFailure(Throwable error) {
LOG.error("Error when reading Monitoring State for key: {} to process the Packet received", monitorKey, error);
// FIXME: Not sure if the transaction status is valid to cancel
tx.cancel();
releaseLock(lock);
}
}, callbackExecutorService);
}
use of org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction in project genius by opendaylight.
the class HwVtepTunnelsStateHandler method update.
@Override
public void update(@Nonnull Tunnels oldTunnelInfo, @Nonnull Tunnels updatedTunnelInfo) {
List<BfdStatus> oldBfdStatus = oldTunnelInfo.getBfdStatus();
List<BfdStatus> newBfdStatus = updatedTunnelInfo.getBfdStatus();
LivenessState oldTunnelOpState = getTunnelOpState(oldBfdStatus);
final LivenessState newTunnelOpState = getTunnelOpState(newBfdStatus);
if (oldTunnelOpState == newTunnelOpState) {
LOG.debug("Tunnel state of old tunnel {} and update tunnel {} are same", oldTunnelInfo, updatedTunnelInfo);
return;
}
updatedTunnelInfo.getTunnelUuid();
String interfaceName = "<TODO>";
// TODO: find out the corresponding interface using tunnelIdentifier or
// any attributes of tunnelInfo object
final String monitorKey = getBfdMonitorKey(interfaceName);
LOG.debug("Processing monitorKey: {} for received Tunnels update DCN", monitorKey);
final Semaphore lock = alivenessMonitor.getLock(monitorKey);
LOG.debug("Acquiring lock for monitor key : {} to process monitor DCN", monitorKey);
alivenessMonitor.acquireLock(lock);
final ReadWriteTransaction tx = dataBroker.newReadWriteTransaction();
ListenableFuture<Optional<MonitoringState>> stateResult = tx.read(LogicalDatastoreType.OPERATIONAL, getMonitorStateId(monitorKey));
Futures.addCallback(stateResult, new FutureCallback<Optional<MonitoringState>>() {
@Override
public void onSuccess(@Nonnull Optional<MonitoringState> optState) {
if (optState.isPresent()) {
final MonitoringState currentState = optState.get();
if (currentState.getState() == newTunnelOpState) {
return;
}
final boolean stateChanged = true;
final MonitoringState state = new MonitoringStateBuilder().setMonitorKey(monitorKey).setState(newTunnelOpState).build();
tx.merge(LogicalDatastoreType.OPERATIONAL, getMonitorStateId(monitorKey), state);
ListenableFuture<Void> writeResult = tx.submit();
// WRITE Callback
Futures.addCallback(writeResult, new FutureCallback<Void>() {
@Override
public void onSuccess(Void arg0) {
alivenessMonitor.releaseLock(lock);
if (stateChanged) {
// send notifications
LOG.info("Sending notification for monitor Id : {} with Current State: {}", currentState.getMonitorId(), newTunnelOpState);
alivenessMonitor.publishNotification(currentState.getMonitorId(), newTunnelOpState);
} else {
if (LOG.isTraceEnabled()) {
LOG.trace("Successful in writing monitoring state {} to ODS", state);
}
}
}
@Override
public void onFailure(@Nonnull Throwable error) {
alivenessMonitor.releaseLock(lock);
LOG.warn("Error in writing monitoring state : {} to Datastore", monitorKey, error);
if (LOG.isTraceEnabled()) {
LOG.trace("Error in writing monitoring state: {} to Datastore", state);
}
}
}, MoreExecutors.directExecutor());
} else {
LOG.warn("Monitoring State not available for key: {} to process the Packet received", monitorKey);
// Complete the transaction
tx.submit();
alivenessMonitor.releaseLock(lock);
}
}
@Override
public void onFailure(@Nonnull Throwable error) {
LOG.error("Error when reading Monitoring State for key: {} to process the Packet received", monitorKey, error);
// FIXME: Not sure if the transaction status is valid to cancel
tx.cancel();
alivenessMonitor.releaseLock(lock);
}
}, MoreExecutors.directExecutor());
}
use of org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction in project genius by opendaylight.
the class TestInterfaceManager method addTunnelInterface.
public void addTunnelInterface(TunnelInterfaceDetails tunnelInterfaceDetails) throws TransactionCommitFailedException {
InterfaceInfo interfaceInfo = tunnelInterfaceDetails.getInterfaceInfo();
interfaceInfos.put(interfaceInfo.getInterfaceName(), interfaceInfo);
if (optDataBroker.isPresent()) {
// Can't use ifPresent() here because of checked exception from tx.submit().checkedGet();
DataBroker dataBroker = optDataBroker.get();
Interface iface = InterfaceHelper.buildVxlanTunnelInterfaceFromInfo(tunnelInterfaceDetails);
ReadWriteTransaction tx = dataBroker.newReadWriteTransaction();
tx.put(LogicalDatastoreType.CONFIGURATION, InterfaceHelper.buildIId(interfaceInfo.getInterfaceName()), iface);
tx.put(LogicalDatastoreType.OPERATIONAL, InterfaceStateHelper.buildStateInterfaceIid(interfaceInfo.getInterfaceName()), InterfaceStateHelper.buildStateFromInterfaceInfo(interfaceInfo));
tx.submit().checkedGet();
externalInterfaces.put(interfaceInfo.getInterfaceName(), true);
addInterface(iface);
}
}
use of org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction in project genius by opendaylight.
the class TestInterfaceManager method addInterfaceInfo.
public void addInterfaceInfo(InterfaceInfo interfaceInfo) throws TransactionCommitFailedException {
interfaceInfos.put(interfaceInfo.getInterfaceName(), interfaceInfo);
if (optDataBroker.isPresent()) {
// Can't use ifPresent() here because of checked exception from tx.submit().checkedGet();
DataBroker dataBroker = optDataBroker.get();
ReadWriteTransaction tx = dataBroker.newReadWriteTransaction();
Interface iface = InterfaceHelper.buildVlanInterfaceFromInfo(interfaceInfo);
// Add the interface to config ds so that if the application reads from configds it finds it there
tx.put(LogicalDatastoreType.CONFIGURATION, InterfaceHelper.buildIId(interfaceInfo.getInterfaceName()), iface);
// Add the interface to oper ds so that if the application reads from configds it finds it there
tx.put(LogicalDatastoreType.OPERATIONAL, InterfaceStateHelper.buildStateInterfaceIid(interfaceInfo.getInterfaceName()), InterfaceStateHelper.buildStateFromInterfaceInfo(interfaceInfo));
tx.submit().checkedGet();
addInterface(iface);
}
}
Aggregations