Search in sources :

Example 26 with Monitor

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev171207.bmp.monitor.Monitor in project genius by opendaylight.

the class HwVtepTunnelsStateHandler method update.

@Override
public void update(@Nonnull Tunnels oldTunnelInfo, @Nonnull Tunnels updatedTunnelInfo) {
    List<BfdStatus> oldBfdStatus = oldTunnelInfo.getBfdStatus();
    List<BfdStatus> newBfdStatus = updatedTunnelInfo.getBfdStatus();
    LivenessState oldTunnelOpState = getTunnelOpState(oldBfdStatus);
    final LivenessState newTunnelOpState = getTunnelOpState(newBfdStatus);
    if (oldTunnelOpState == newTunnelOpState) {
        LOG.debug("Tunnel state of old tunnel {} and update tunnel {} are same", oldTunnelInfo, updatedTunnelInfo);
        return;
    }
    updatedTunnelInfo.getTunnelUuid();
    String interfaceName = "<TODO>";
    // TODO: find out the corresponding interface using tunnelIdentifier or
    // any attributes of tunnelInfo object
    final String monitorKey = getBfdMonitorKey(interfaceName);
    LOG.debug("Processing monitorKey: {} for received Tunnels update DCN", monitorKey);
    final Semaphore lock = alivenessMonitor.getLock(monitorKey);
    LOG.debug("Acquiring lock for monitor key : {} to process monitor DCN", monitorKey);
    alivenessMonitor.acquireLock(lock);
    final ReadWriteTransaction tx = dataBroker.newReadWriteTransaction();
    ListenableFuture<Optional<MonitoringState>> stateResult = tx.read(LogicalDatastoreType.OPERATIONAL, getMonitorStateId(monitorKey));
    Futures.addCallback(stateResult, new FutureCallback<Optional<MonitoringState>>() {

        @Override
        public void onSuccess(@Nonnull Optional<MonitoringState> optState) {
            if (optState.isPresent()) {
                final MonitoringState currentState = optState.get();
                if (currentState.getState() == newTunnelOpState) {
                    return;
                }
                final boolean stateChanged = true;
                final MonitoringState state = new MonitoringStateBuilder().setMonitorKey(monitorKey).setState(newTunnelOpState).build();
                tx.merge(LogicalDatastoreType.OPERATIONAL, getMonitorStateId(monitorKey), state);
                ListenableFuture<Void> writeResult = tx.submit();
                // WRITE Callback
                Futures.addCallback(writeResult, new FutureCallback<Void>() {

                    @Override
                    public void onSuccess(Void arg0) {
                        alivenessMonitor.releaseLock(lock);
                        if (stateChanged) {
                            // send notifications
                            LOG.info("Sending notification for monitor Id : {} with Current State: {}", currentState.getMonitorId(), newTunnelOpState);
                            alivenessMonitor.publishNotification(currentState.getMonitorId(), newTunnelOpState);
                        } else {
                            if (LOG.isTraceEnabled()) {
                                LOG.trace("Successful in writing monitoring state {} to ODS", state);
                            }
                        }
                    }

                    @Override
                    public void onFailure(@Nonnull Throwable error) {
                        alivenessMonitor.releaseLock(lock);
                        LOG.warn("Error in writing monitoring state : {} to Datastore", monitorKey, error);
                        if (LOG.isTraceEnabled()) {
                            LOG.trace("Error in writing monitoring state: {} to Datastore", state);
                        }
                    }
                }, MoreExecutors.directExecutor());
            } else {
                LOG.warn("Monitoring State not available for key: {} to process the Packet received", monitorKey);
                // Complete the transaction
                tx.submit();
                alivenessMonitor.releaseLock(lock);
            }
        }

        @Override
        public void onFailure(@Nonnull Throwable error) {
            LOG.error("Error when reading Monitoring State for key: {} to process the Packet received", monitorKey, error);
            // FIXME: Not sure if the transaction status is valid to cancel
            tx.cancel();
            alivenessMonitor.releaseLock(lock);
        }
    }, MoreExecutors.directExecutor());
}
Also used : Optional(com.google.common.base.Optional) Nonnull(javax.annotation.Nonnull) MonitoringStateBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitoring.states.MonitoringStateBuilder) Semaphore(java.util.concurrent.Semaphore) BfdStatus(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.tunnel.attributes.BfdStatus) MonitoringState(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitoring.states.MonitoringState) LivenessState(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.LivenessState) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) ReadWriteTransaction(org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction) FutureCallback(com.google.common.util.concurrent.FutureCallback)

Example 27 with Monitor

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev171207.bmp.monitor.Monitor in project genius by opendaylight.

the class AlivenessMonitorTest method testMonitorStop.

@Test
public void testMonitorStop() throws InterruptedException, ExecutionException {
    MonitorStopInput input = new MonitorStopInputBuilder().setMonitorId(2L).build();
    Optional<MonitoringInfo> optInfo = Optional.of(new MonitoringInfoBuilder().setSource(new SourceBuilder().setEndpointType(getInterface("testInterface", "10.1.1.1")).build()).build());
    CheckedFuture<Optional<MonitoringInfo>, ReadFailedException> outFuture = Futures.immediateCheckedFuture(optInfo);
    when(readTx.read(eq(LogicalDatastoreType.OPERATIONAL), argThat(isType(MonitoringInfo.class)))).thenReturn(outFuture);
    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));
    Optional<MonitorProfile> optProfile = Optional.of(getTestMonitorProfile());
    when(readTx.read(eq(LogicalDatastoreType.OPERATIONAL), argThat(isType(MonitorProfile.class)))).thenReturn(Futures.immediateCheckedFuture(optProfile));
    Optional<InterfaceMonitorEntry> optEntry = Optional.of(getInterfaceMonitorEntry());
    when(readWriteTx.read(eq(LogicalDatastoreType.OPERATIONAL), argThat(isType(InterfaceMonitorEntry.class)))).thenReturn(Futures.immediateCheckedFuture(optEntry));
    RpcResult<Void> result = alivenessMonitor.monitorStop(input).get();
    verify(idManager).releaseId(any(ReleaseIdInput.class));
    verify(writeTx, times(2)).delete(eq(LogicalDatastoreType.OPERATIONAL), any(InstanceIdentifier.class));
    assertTrue("Monitor stop rpc result", result.isSuccessful());
}
Also used : ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) MonitorStopInput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorStopInput) MonitoringInfo(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.configs.MonitoringInfo) Optional(com.google.common.base.Optional) SourceBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.params.SourceBuilder) MonitorStopInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorStopInputBuilder) 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) MonitoridKeyEntryBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitorid.key.map.MonitoridKeyEntryBuilder) InterfaceMonitorEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411._interface.monitor.map.InterfaceMonitorEntry) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) ReleaseIdInput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.ReleaseIdInput) MonitoridKeyEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitorid.key.map.MonitoridKeyEntry) Test(org.junit.Test)

Example 28 with Monitor

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev171207.bmp.monitor.Monitor in project genius by opendaylight.

the class AlivenessMonitorTest method testMonitorProfileDelete.

@Test
public void testMonitorProfileDelete() throws InterruptedException, ExecutionException {
    MonitorProfileDeleteInput input = new MonitorProfileDeleteInputBuilder().setProfileId(1L).build();
    Optional<MonitorProfile> optProfile = Optional.of(getTestMonitorProfile());
    when(readWriteTx.read(eq(LogicalDatastoreType.OPERATIONAL), argThat(isType(MonitorProfile.class)))).thenReturn(Futures.immediateCheckedFuture(optProfile));
    RpcResult<Void> result = alivenessMonitor.monitorProfileDelete(input).get();
    verify(idManager).releaseId(any(ReleaseIdInput.class));
    verify(readWriteTx).delete(eq(LogicalDatastoreType.OPERATIONAL), Matchers.<InstanceIdentifier<MonitorProfile>>any());
    assertTrue("Monitor profile delete result", result.isSuccessful());
}
Also used : MonitorProfileDeleteInput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorProfileDeleteInput) MonitorProfile(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.profiles.MonitorProfile) ReleaseIdInput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.ReleaseIdInput) MonitorProfileDeleteInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorProfileDeleteInputBuilder) Test(org.junit.Test)

Example 29 with Monitor

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev171207.bmp.monitor.Monitor 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)

Example 30 with Monitor

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev171207.bmp.monitor.Monitor in project genius by opendaylight.

the class AlivenessMonitorTest method testMonitorPause.

@Test
public void testMonitorPause() throws InterruptedException, ExecutionException {
    MonitorPauseInput input = new MonitorPauseInputBuilder().setMonitorId(2L).build();
    Optional<MonitorProfile> optProfile = Optional.of(getTestMonitorProfile());
    when(readTx.read(eq(LogicalDatastoreType.OPERATIONAL), argThat(isType(MonitorProfile.class)))).thenReturn(Futures.immediateCheckedFuture(optProfile));
    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<MonitoringState> optState = Optional.of(new MonitoringStateBuilder().setStatus(MonitorStatus.Started).build());
    when(readWriteTx.read(eq(LogicalDatastoreType.OPERATIONAL), argThat(isType(MonitoringState.class)))).thenReturn(Futures.immediateCheckedFuture(optState));
    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));
    alivenessMonitor.monitorPause(input).get();
    verify(readWriteTx).merge(eq(LogicalDatastoreType.OPERATIONAL), argThat(isType(MonitoringState.class)), stateCaptor.capture());
    assertEquals(MonitorStatus.Paused, stateCaptor.getValue().getStatus());
}
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) MonitorPauseInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorPauseInputBuilder) MonitoringState(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitoring.states.MonitoringState) MonitorPauseInput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorPauseInput) MonitoridKeyEntryBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitorid.key.map.MonitoridKeyEntryBuilder) MonitoridKeyEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitorid.key.map.MonitoridKeyEntry) Test(org.junit.Test)

Aggregations

Optional (com.google.common.base.Optional)15 MonitorProfile (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.profiles.MonitorProfile)15 ReadWriteTransaction (org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction)10 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)9 Test (org.junit.Test)8 MonitoringInfo (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.configs.MonitoringInfo)8 MonitoringState (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitoring.states.MonitoringState)8 MonitoringStateBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitoring.states.MonitoringStateBuilder)8 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)7 FutureCallback (com.google.common.util.concurrent.FutureCallback)6 Nonnull (javax.annotation.Nonnull)6 EtherTypes (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.EtherTypes)6 MonitorProfileCreateOutput (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorProfileCreateOutput)6 ArrayList (java.util.ArrayList)5 Semaphore (java.util.concurrent.Semaphore)5 LivenessState (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.LivenessState)5 MonitorProfileDeleteInput (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorProfileDeleteInput)5 MonitoringInfoBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.configs.MonitoringInfoBuilder)5 MonitoridKeyEntry (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitorid.key.map.MonitoridKeyEntry)5 MonitoridKeyEntryBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitorid.key.map.MonitoridKeyEntryBuilder)5