Search in sources :

Example 1 with InterfaceMonitorEntryBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411._interface.monitor.map.InterfaceMonitorEntryBuilder 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());
}
Also used : Optional(com.google.common.base.Optional) InterfaceMonitorEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411._interface.monitor.map.InterfaceMonitorEntry) InterfaceMonitorEntryBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411._interface.monitor.map.InterfaceMonitorEntryBuilder) ArrayList(java.util.ArrayList) ReadWriteTransaction(org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction) InterfaceMonitorEntryKey(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411._interface.monitor.map.InterfaceMonitorEntryKey)

Example 2 with InterfaceMonitorEntryBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411._interface.monitor.map.InterfaceMonitorEntryBuilder 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());
}
Also used : Optional(com.google.common.base.Optional) InterfaceMonitorEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411._interface.monitor.map.InterfaceMonitorEntry) InterfaceMonitorEntryBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411._interface.monitor.map.InterfaceMonitorEntryBuilder) ReadWriteTransaction(org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction) InterfaceMonitorEntryKey(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411._interface.monitor.map.InterfaceMonitorEntryKey)

Aggregations

Optional (com.google.common.base.Optional)2 ReadWriteTransaction (org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction)2 InterfaceMonitorEntry (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411._interface.monitor.map.InterfaceMonitorEntry)2 InterfaceMonitorEntryBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411._interface.monitor.map.InterfaceMonitorEntryBuilder)2 InterfaceMonitorEntryKey (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411._interface.monitor.map.InterfaceMonitorEntryKey)2 ArrayList (java.util.ArrayList)1