Search in sources :

Example 11 with MonitorProfile

use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.profiles.MonitorProfile in project genius by opendaylight.

the class AlivenessMonitor method monitorProfileCreate.

@Override
public Future<RpcResult<MonitorProfileCreateOutput>> monitorProfileCreate(final MonitorProfileCreateInput input) {
    LOG.debug("Monitor Profile Create operation - {}", input.getProfile());
    final SettableFuture<RpcResult<MonitorProfileCreateOutput>> returnFuture = SettableFuture.create();
    Profile profile = input.getProfile();
    final Long failureThreshold = profile.getFailureThreshold();
    final Long monitorInterval = profile.getMonitorInterval();
    final Long monitorWindow = profile.getMonitorWindow();
    final EtherTypes ethType = profile.getProtocolType();
    String idKey = getUniqueProfileKey(failureThreshold, monitorInterval, monitorWindow, ethType);
    final Long profileId = (long) getUniqueId(idKey);
    final ReadWriteTransaction tx = dataBroker.newReadWriteTransaction();
    ListenableFuture<Optional<MonitorProfile>> readFuture = tx.read(LogicalDatastoreType.OPERATIONAL, getMonitorProfileId(profileId));
    ListenableFuture<RpcResult<MonitorProfileCreateOutput>> resultFuture = Futures.transformAsync(readFuture, optProfile -> {
        if (optProfile.isPresent()) {
            tx.cancel();
            MonitorProfileCreateOutput output = new MonitorProfileCreateOutputBuilder().setProfileId(profileId).build();
            String msg = String.format("Monitor profile %s already present for the given input", input);
            LOG.warn(msg);
            returnFuture.set(RpcResultBuilder.success(output).withWarning(ErrorType.PROTOCOL, "profile-exists", msg).build());
        } else {
            final MonitorProfile monitorProfile = new MonitorProfileBuilder().setId(profileId).setFailureThreshold(failureThreshold).setMonitorInterval(monitorInterval).setMonitorWindow(monitorWindow).setProtocolType(ethType).build();
            tx.put(LogicalDatastoreType.OPERATIONAL, getMonitorProfileId(profileId), monitorProfile, CREATE_MISSING_PARENT);
            Futures.addCallback(tx.submit(), new FutureCallback<Void>() {

                @Override
                public void onFailure(Throwable error) {
                    String msg = String.format("Error when storing monitorprofile %s in datastore", monitorProfile);
                    LOG.error("Error when storing monitorprofile {} in datastore", monitorProfile, error);
                    returnFuture.set(RpcResultBuilder.<MonitorProfileCreateOutput>failed().withError(ErrorType.APPLICATION, msg, error).build());
                }

                @Override
                public void onSuccess(Void noarg) {
                    MonitorProfileCreateOutput output = new MonitorProfileCreateOutputBuilder().setProfileId(profileId).build();
                    returnFuture.set(RpcResultBuilder.success(output).build());
                }
            }, callbackExecutorService);
        }
        return returnFuture;
    }, callbackExecutorService);
    Futures.addCallback(resultFuture, new FutureCallback<RpcResult<MonitorProfileCreateOutput>>() {

        @Override
        public void onFailure(Throwable error) {
            // This would happen when any error happens during reading for
            // monitoring profile
            String msg = String.format("Error in creating monitorprofile - %s", input);
            returnFuture.set(RpcResultBuilder.<MonitorProfileCreateOutput>failed().withError(ErrorType.APPLICATION, msg, error).build());
            LOG.error("Error in creating monitorprofile - {} ", input, error);
        }

        @Override
        public void onSuccess(RpcResult<MonitorProfileCreateOutput> result) {
            LOG.debug("Successfully created monitor Profile {} ", input);
        }
    }, callbackExecutorService);
    return returnFuture;
}
Also used : Optional(com.google.common.base.Optional) MonitorProfile(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.profiles.MonitorProfile) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) MonitorProfileBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.profiles.MonitorProfileBuilder) EtherTypes(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.EtherTypes) Profile(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.profile.create.input.Profile) MonitorProfile(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.profiles.MonitorProfile) MonitorProfileCreateOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorProfileCreateOutputBuilder) MonitorProfileCreateOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorProfileCreateOutput) ReadWriteTransaction(org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction)

Example 12 with MonitorProfile

use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.profiles.MonitorProfile 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 13 with MonitorProfile

use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.profiles.MonitorProfile 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 14 with MonitorProfile

use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.profiles.MonitorProfile 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 15 with MonitorProfile

use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.profiles.MonitorProfile 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

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