use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev200120.MonitorId in project genius by opendaylight.
the class AlivenessMonitor method updateMonitorStatusTo.
private void updateMonitorStatusTo(final Long monitorId, final MonitorStatus newStatus, final Predicate<MonitorStatus> isValidStatus) {
final String monitorKey = monitorIdKeyCache.getUnchecked(monitorId);
if (monitorKey == null) {
LOG.warn("No monitor Key associated with id {} to change the monitor status to {}", monitorId, newStatus);
return;
}
final ReadWriteTransaction tx = dataBroker.newReadWriteTransaction();
ListenableFuture<Optional<MonitoringState>> readResult = tx.read(LogicalDatastoreType.OPERATIONAL, getMonitorStateId(monitorKey));
ListenableFuture<Void> writeResult = Futures.transformAsync(readResult, optState -> {
if (optState.isPresent()) {
MonitoringState state = optState.get();
if (isValidStatus.apply(state.getStatus())) {
MonitoringState updatedState = new MonitoringStateBuilder().setMonitorKey(monitorKey).setStatus(newStatus).build();
tx.merge(LogicalDatastoreType.OPERATIONAL, getMonitorStateId(monitorKey), updatedState);
} else {
LOG.warn("Invalid Monitoring status {}, cannot be updated to {} for monitorId {}", state.getStatus(), newStatus, monitorId);
}
} else {
LOG.warn("No associated monitoring state data available to update the status to {} for {}", newStatus, monitorId);
}
return tx.submit();
}, MoreExecutors.directExecutor());
Futures.addCallback(writeResult, new FutureCallbackImpl(String.format("Monitor status update for %d to %s", monitorId, newStatus.toString())), MoreExecutors.directExecutor());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev200120.MonitorId in project genius by opendaylight.
the class AlivenessMonitor method monitorStop.
@Override
public Future<RpcResult<Void>> monitorStop(MonitorStopInput input) {
LOG.debug("Monitor Stop operation for monitor id - {}", input.getMonitorId());
SettableFuture<RpcResult<Void>> result = SettableFuture.create();
final Long monitorId = input.getMonitorId();
Optional<MonitoringInfo> optInfo = SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker, LogicalDatastoreType.OPERATIONAL, getMonitoringInfoId(monitorId));
if (optInfo.isPresent()) {
// Stop the monitoring task
stopMonitoringTask(monitorId);
String monitorKey = monitorIdKeyCache.getUnchecked(monitorId);
// Cleanup the Data store
Futures.addCallback(txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> {
if (monitorKey != null) {
tx.delete(LogicalDatastoreType.OPERATIONAL, getMonitorStateId(monitorKey));
monitorIdKeyCache.invalidate(monitorId);
}
tx.delete(LogicalDatastoreType.OPERATIONAL, getMonitoringInfoId(monitorId));
}), new FutureCallbackImpl(String.format("Delete monitor state with Id %d", monitorId)), MoreExecutors.directExecutor());
MonitoringInfo info = optInfo.get();
String interfaceName = getInterfaceName(info.getSource().getEndpointType());
if (interfaceName != null) {
removeMonitorIdFromInterfaceAssociation(monitorId, interfaceName);
}
releaseIdForMonitoringInfo(info);
if (monitorKey != null) {
lockMap.remove(monitorKey);
}
result.set(RpcResultBuilder.<Void>success().build());
} else {
String errorMsg = String.format("Do not have monitoring information associated with key %d", monitorId);
LOG.error("Delete monitoring operation Failed - {}", errorMsg);
result.set(RpcResultBuilder.<Void>failed().withError(ErrorType.APPLICATION, errorMsg).build());
}
return result;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev200120.MonitorId in project genius by opendaylight.
the class AlivenessMonitor method resumeMonitoring.
private void resumeMonitoring(final long monitorId) {
final ReadOnlyTransaction tx = dataBroker.newReadOnlyTransaction();
ListenableFuture<Optional<MonitoringInfo>> readInfoResult = tx.read(LogicalDatastoreType.OPERATIONAL, getMonitoringInfoId(monitorId));
Futures.addCallback(readInfoResult, new FutureCallback<Optional<MonitoringInfo>>() {
@Override
public void onFailure(Throwable error) {
String msg = String.format("Unable to read monitoring info associated with monitor id %d", monitorId);
LOG.error("Monitor resume Failed. {}", msg, error);
tx.close();
}
@Override
public void onSuccess(@Nonnull Optional<MonitoringInfo> optInfo) {
if (optInfo.isPresent()) {
final MonitoringInfo info = optInfo.get();
ListenableFuture<Optional<MonitorProfile>> readProfile = tx.read(LogicalDatastoreType.OPERATIONAL, getMonitorProfileId(info.getProfileId()));
Futures.addCallback(readProfile, new FutureCallback<Optional<MonitorProfile>>() {
@Override
public void onFailure(Throwable error) {
String msg = String.format("Unable to read Monitoring profile associated with id %d", info.getProfileId());
LOG.warn("Monitor resume Failed. {}", msg, error);
tx.close();
}
@Override
public void onSuccess(@Nonnull Optional<MonitorProfile> optProfile) {
tx.close();
if (optProfile.isPresent()) {
updateMonitorStatusTo(monitorId, MonitorStatus.Started, currentStatus -> currentStatus != MonitorStatus.Started);
MonitorProfile profile = optProfile.get();
LOG.debug("Monitor Resume - Scheduling monitoring task for Id: {}", monitorId);
scheduleMonitoringTask(info, profile.getMonitorInterval());
} else {
String msg = String.format("Monitoring profile associated with id %d is not present", info.getProfileId());
LOG.warn("Monitor resume Failed. {}", msg);
}
}
}, MoreExecutors.directExecutor());
} else {
tx.close();
String msg = String.format("Monitoring info associated with id %d is not present", monitorId);
LOG.warn("Monitor resume Failed. {}", msg);
}
}
}, MoreExecutors.directExecutor());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev200120.MonitorId in project genius by opendaylight.
the class AlivenessMonitor method monitorUnpause.
@Override
public Future<RpcResult<Void>> monitorUnpause(MonitorUnpauseInput input) {
LOG.debug("Monitor Unpause operation invoked for monitor id: {}", input.getMonitorId());
final SettableFuture<RpcResult<Void>> result = SettableFuture.create();
final Long monitorId = input.getMonitorId();
final ReadOnlyTransaction tx = dataBroker.newReadOnlyTransaction();
ListenableFuture<Optional<MonitoringInfo>> readInfoResult = tx.read(LogicalDatastoreType.OPERATIONAL, getMonitoringInfoId(monitorId));
Futures.addCallback(readInfoResult, new FutureCallback<Optional<MonitoringInfo>>() {
@Override
public void onFailure(Throwable error) {
tx.close();
String msg = String.format("Unable to read monitoring info associated with monitor id %d", monitorId);
LOG.error("Monitor unpause Failed. {}", msg, error);
result.set(RpcResultBuilder.<Void>failed().withError(ErrorType.APPLICATION, msg, error).build());
}
@Override
public void onSuccess(@Nonnull Optional<MonitoringInfo> optInfo) {
if (optInfo.isPresent()) {
final MonitoringInfo info = optInfo.get();
ListenableFuture<Optional<MonitorProfile>> readProfile = tx.read(LogicalDatastoreType.OPERATIONAL, getMonitorProfileId(info.getProfileId()));
Futures.addCallback(readProfile, new FutureCallback<Optional<MonitorProfile>>() {
@Override
public void onFailure(Throwable error) {
tx.close();
String msg = String.format("Unable to read Monitoring profile associated with id %d", info.getProfileId());
LOG.warn("Monitor unpause Failed. {}", msg, error);
result.set(RpcResultBuilder.<Void>failed().withError(ErrorType.APPLICATION, msg, error).build());
}
@Override
public void onSuccess(@Nonnull Optional<MonitorProfile> optProfile) {
tx.close();
if (optProfile.isPresent()) {
updateMonitorStatusTo(monitorId, MonitorStatus.Started, currentStatus -> (currentStatus == MonitorStatus.Paused || currentStatus == MonitorStatus.Stopped));
MonitorProfile profile = optProfile.get();
LOG.debug("Monitor Resume - Scheduling monitoring task with Id: {}", monitorId);
EtherTypes protocolType = profile.getProtocolType();
if (protocolType == EtherTypes.Bfd) {
LOG.debug("disabling bfd for hwvtep tunnel montior id {}", monitorId);
((HwVtepTunnelsStateHandler) alivenessProtocolHandlerRegistry.get(protocolType)).resetMonitoringTask(true);
} else {
scheduleMonitoringTask(info, profile.getMonitorInterval());
}
result.set(RpcResultBuilder.<Void>success().build());
} else {
String msg = String.format("Monitoring profile associated with id %d is not present", info.getProfileId());
LOG.warn("Monitor unpause Failed. {}", msg);
result.set(RpcResultBuilder.<Void>failed().withError(ErrorType.APPLICATION, msg).build());
}
}
}, callbackExecutorService);
} else {
tx.close();
String msg = String.format("Monitoring info associated with id %d is not present", monitorId);
LOG.warn("Monitor unpause Failed. {}", msg);
result.set(RpcResultBuilder.<Void>failed().withError(ErrorType.APPLICATION, msg).build());
}
}
}, callbackExecutorService);
return result;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev200120.MonitorId 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