Search in sources :

Example 1 with MonitorUnpauseInput

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;
}
Also used : Optional(com.google.common.base.Optional) MonitoringInfo(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.configs.MonitoringInfo) Nonnull(javax.annotation.Nonnull) MonitorProfile(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.profiles.MonitorProfile) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) EtherTypes(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.EtherTypes) ReadOnlyTransaction(org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) FutureCallback(com.google.common.util.concurrent.FutureCallback)

Example 2 with MonitorUnpauseInput

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());
}
Also used : MonitoringInfo(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.configs.MonitoringInfo) MonitoringStateBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitoring.states.MonitoringStateBuilder) MonitorProfile(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.profiles.MonitorProfile) MonitoringInfoBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.configs.MonitoringInfoBuilder) MonitorUnpauseInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorUnpauseInputBuilder) MonitoringState(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitoring.states.MonitoringState) MonitoridKeyEntryBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitorid.key.map.MonitoridKeyEntryBuilder) MonitorUnpauseInput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorUnpauseInput) MonitoridKeyEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitorid.key.map.MonitoridKeyEntry) Test(org.junit.Test)

Aggregations

MonitoringInfo (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.configs.MonitoringInfo)2 MonitorProfile (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.profiles.MonitorProfile)2 Optional (com.google.common.base.Optional)1 FutureCallback (com.google.common.util.concurrent.FutureCallback)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 Nonnull (javax.annotation.Nonnull)1 Test (org.junit.Test)1 ReadOnlyTransaction (org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction)1 EtherTypes (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.EtherTypes)1 MonitorUnpauseInput (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorUnpauseInput)1 MonitorUnpauseInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorUnpauseInputBuilder)1 MonitoringInfoBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.configs.MonitoringInfoBuilder)1 MonitoridKeyEntry (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitorid.key.map.MonitoridKeyEntry)1 MonitoridKeyEntryBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitorid.key.map.MonitoridKeyEntryBuilder)1 MonitoringState (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitoring.states.MonitoringState)1 MonitoringStateBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitoring.states.MonitoringStateBuilder)1 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)1