use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorUnpauseInput 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.genius.alivenessmonitor.rev160411.MonitorUnpauseInput in project genius by opendaylight.
the class AlivenessMonitorTest method testMonitorUnpause.
@Test
public void testMonitorUnpause() throws InterruptedException, ExecutionException {
MonitorUnpauseInput input = new MonitorUnpauseInputBuilder().setMonitorId(2L).build();
Optional<MonitoringState> optState = Optional.of(new MonitoringStateBuilder().setStatus(MonitorStatus.Paused).build());
when(readWriteTx.read(eq(LogicalDatastoreType.OPERATIONAL), argThat(isType(MonitoringState.class)))).thenReturn(Futures.immediateCheckedFuture(optState));
Optional<MonitoringInfo> optInfo = Optional.of(new MonitoringInfoBuilder().setId(2L).setProfileId(1L).build());
when(readTx.read(eq(LogicalDatastoreType.OPERATIONAL), argThat(isType(MonitoringInfo.class)))).thenReturn(Futures.immediateCheckedFuture(optInfo));
Optional<MonitorProfile> optProfile = Optional.of(getTestMonitorProfile());
when(readTx.read(eq(LogicalDatastoreType.OPERATIONAL), argThat(isType(MonitorProfile.class)))).thenReturn(Futures.immediateCheckedFuture(optProfile));
Optional<MonitoridKeyEntry> optMap = Optional.of(new MonitoridKeyEntryBuilder().setMonitorId(2L).setMonitorKey("Test monitor Key").build());
when(readTx.read(eq(LogicalDatastoreType.OPERATIONAL), argThat(isType(MonitoridKeyEntry.class)))).thenReturn(Futures.immediateCheckedFuture(optMap));
RpcResult<Void> result = alivenessMonitor.monitorUnpause(input).get();
verify(readWriteTx).merge(eq(LogicalDatastoreType.OPERATIONAL), argThat(isType(MonitoringState.class)), stateCaptor.capture());
assertEquals(MonitorStatus.Started, stateCaptor.getValue().getStatus());
assertTrue("Monitor unpause rpc result", result.isSuccessful());
}
Aggregations