use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.meta.rev160406._interface.monitor.id.map.InterfaceMonitorId in project genius by opendaylight.
the class AlivenessMonitorUtils method createOrUpdateInterfaceMonitorIdMap.
private static void createOrUpdateInterfaceMonitorIdMap(ReadWriteTransaction tx, String infName, long monitorId) throws ReadFailedException {
InterfaceMonitorId interfaceMonitorIdInstance;
List<Long> existingMonitorIds;
InterfaceMonitorIdBuilder interfaceMonitorIdBuilder = new InterfaceMonitorIdBuilder();
InstanceIdentifier<InterfaceMonitorId> id = InstanceIdentifier.builder(InterfaceMonitorIdMap.class).child(InterfaceMonitorId.class, new InterfaceMonitorIdKey(infName)).build();
Optional<InterfaceMonitorId> interfaceMonitorIdMap = tx.read(LogicalDatastoreType.OPERATIONAL, id).checkedGet();
if (interfaceMonitorIdMap.isPresent()) {
interfaceMonitorIdInstance = interfaceMonitorIdMap.get();
existingMonitorIds = interfaceMonitorIdInstance.getMonitorId();
if (existingMonitorIds == null) {
existingMonitorIds = new ArrayList<>();
}
if (!existingMonitorIds.contains(monitorId)) {
existingMonitorIds.add(monitorId);
interfaceMonitorIdInstance = interfaceMonitorIdBuilder.setKey(new InterfaceMonitorIdKey(infName)).setMonitorId(existingMonitorIds).build();
tx.merge(LogicalDatastoreType.OPERATIONAL, id, interfaceMonitorIdInstance, WriteTransaction.CREATE_MISSING_PARENTS);
}
} else {
existingMonitorIds = new ArrayList<>();
existingMonitorIds.add(monitorId);
interfaceMonitorIdInstance = interfaceMonitorIdBuilder.setMonitorId(existingMonitorIds).setKey(new InterfaceMonitorIdKey(infName)).setInterfaceName(infName).build();
tx.merge(LogicalDatastoreType.OPERATIONAL, id, interfaceMonitorIdInstance, WriteTransaction.CREATE_MISSING_PARENTS);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.meta.rev160406._interface.monitor.id.map.InterfaceMonitorId in project genius by opendaylight.
the class AlivenessMonitorUtils method removeMonitorIdFromInterfaceMonitorIdMap.
private void removeMonitorIdFromInterfaceMonitorIdMap(ReadWriteTransaction tx, String infName, long monitorId) throws ReadFailedException {
InstanceIdentifier<InterfaceMonitorId> id = InstanceIdentifier.builder(InterfaceMonitorIdMap.class).child(InterfaceMonitorId.class, new InterfaceMonitorIdKey(infName)).build();
Optional<InterfaceMonitorId> interfaceMonitorIdMap = tx.read(LogicalDatastoreType.OPERATIONAL, id).checkedGet();
if (interfaceMonitorIdMap.isPresent()) {
InterfaceMonitorId interfaceMonitorIdInstance = interfaceMonitorIdMap.get();
List<Long> existingMonitorIds = interfaceMonitorIdInstance.getMonitorId();
if (existingMonitorIds != null && existingMonitorIds.contains(monitorId)) {
existingMonitorIds.remove(monitorId);
InterfaceMonitorIdBuilder interfaceMonitorIdBuilder = new InterfaceMonitorIdBuilder();
interfaceMonitorIdInstance = interfaceMonitorIdBuilder.setKey(new InterfaceMonitorIdKey(infName)).setMonitorId(existingMonitorIds).build();
tx.merge(LogicalDatastoreType.OPERATIONAL, id, interfaceMonitorIdInstance, WriteTransaction.CREATE_MISSING_PARENTS);
}
}
}
Aggregations