use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411._interface.monitor.map.InterfaceMonitorEntryKey in project genius by opendaylight.
the class AlivenessMonitor method associateMonitorIdWithInterface.
private void associateMonitorIdWithInterface(final Long monitorId, final String interfaceName) {
LOG.debug("associate monitor Id {} with interface {}", 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> monitorIds1 = entry.getMonitorIds();
monitorIds1.add(monitorId);
InterfaceMonitorEntry newEntry1 = new InterfaceMonitorEntryBuilder().setKey(new InterfaceMonitorEntryKey(interfaceName)).setMonitorIds(monitorIds1).build();
tx.merge(LogicalDatastoreType.OPERATIONAL, getInterfaceMonitorMapId(interfaceName), newEntry1);
} else {
// Create new monitor entry
LOG.debug("Adding new interface-monitor association for interface {} with id {}", interfaceName, monitorId);
List<Long> monitorIds2 = new ArrayList<>();
monitorIds2.add(monitorId);
InterfaceMonitorEntry newEntry2 = new InterfaceMonitorEntryBuilder().setInterfaceName(interfaceName).setMonitorIds(monitorIds2).build();
tx.put(LogicalDatastoreType.OPERATIONAL, getInterfaceMonitorMapId(interfaceName), newEntry2, CREATE_MISSING_PARENT);
}
return tx.submit();
}, callbackExecutorService);
Futures.addCallback(updateFuture, new FutureCallbackImpl(String.format("Association of monitorId %d with Interface %s", monitorId, interfaceName)), MoreExecutors.directExecutor());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411._interface.monitor.map.InterfaceMonitorEntryKey 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());
}
Aggregations