Search in sources :

Example 6 with FlowStats

use of org.openkilda.model.FlowStats in project open-kilda by telstra.

the class FlowOperationsBolt method processFlowReadRequest.

@TimedExecution("flow_read")
private List<FlowResponse> processFlowReadRequest(FlowReadRequest readRequest) {
    try {
        String flowId = readRequest.getFlowId();
        Flow flow = flowOperationsService.getFlow(flowId);
        FlowStats flowStats = flowOperationsService.getFlowStats(flowId);
        FlowResponse response = flowOperationsService.buildFlowResponse(flow, flowStats);
        return Collections.singletonList(response);
    } catch (FlowNotFoundException e) {
        throw new MessageException(ErrorType.NOT_FOUND, "Can not get flow: " + e.getMessage(), "Flow not found");
    } catch (Exception e) {
        log.error("Can not get flow", e);
        throw new MessageException(ErrorType.INTERNAL_ERROR, "Can not get flow", "Internal Error");
    }
}
Also used : FlowStats(org.openkilda.model.FlowStats) FlowNotFoundException(org.openkilda.wfm.error.FlowNotFoundException) MessageException(org.openkilda.messaging.error.MessageException) FlowResponse(org.openkilda.messaging.info.flow.FlowResponse) IslNotFoundException(org.openkilda.wfm.error.IslNotFoundException) SwitchNotFoundException(org.openkilda.wfm.error.SwitchNotFoundException) MessageException(org.openkilda.messaging.error.MessageException) FlowNotFoundException(org.openkilda.wfm.error.FlowNotFoundException) Flow(org.openkilda.model.Flow) TimedExecution(org.openkilda.wfm.share.metrics.TimedExecution)

Example 7 with FlowStats

use of org.openkilda.model.FlowStats in project open-kilda by telstra.

the class ActionServiceTest method shouldBecomeHealthyAndSendSyncRequest.

@Test
public void shouldBecomeHealthyAndSendSyncRequest() {
    Duration tier2Failed = Duration.ofNanos(flow.getMaxLatencyTier2() * 2);
    service.processFlowLatencyMeasurement(flow.getFlowId(), FlowDirection.FORWARD, tier2Failed);
    service.processFlowLatencyMeasurement(flow.getFlowId(), FlowDirection.REVERSE, tier2Failed);
    Duration healthy = Duration.ofNanos((long) (flow.getMaxLatency() * (1 - THRESHOLD)) - 5);
    for (int i = 0; i < 10; i++) {
        clock.adjust(Duration.ofSeconds(10));
        service.processFlowLatencyMeasurement(flow.getFlowId(), FlowDirection.FORWARD, healthy);
        service.processFlowLatencyMeasurement(flow.getFlowId(), FlowDirection.REVERSE, healthy.minus(NANOSECOND));
        service.processTick();
        if (i == 0) {
            assertTrue(service.fsms.values().stream().allMatch(fsm -> UNSTABLE.equals(fsm.getCurrentState())));
        }
    }
    assertEquals(2, service.fsms.values().size());
    assertTrue(service.fsms.values().stream().allMatch(fsm -> HEALTHY.equals(fsm.getCurrentState())));
    FlowStats actual = flowStatsRepository.findByFlowId(flow.getFlowId()).orElseThrow(() -> new IllegalStateException("Flow not found"));
    assertEquals(healthy.getNano(), actual.getForwardLatency().intValue());
    assertEquals(healthy.minus(NANOSECOND).getNano(), actual.getReverseLatency().intValue());
    verify(carrier, times(2)).sendFlowSyncRequest(flow.getFlowId());
    verifyNoMoreInteractions(carrier);
}
Also used : FlowDirection(org.openkilda.server42.messaging.FlowDirection) Arrays(java.util.Arrays) FlowStats(org.openkilda.model.FlowStats) InMemoryGraphBasedTest(org.openkilda.persistence.inmemory.InMemoryGraphBasedTest) HEALTHY(org.openkilda.wfm.topology.flowmonitoring.fsm.FlowLatencyMonitoringFsm.State.HEALTHY) Mock(org.mockito.Mock) FlowStatsRepository(org.openkilda.persistence.repositories.FlowStatsRepository) RunWith(org.junit.runner.RunWith) KildaFeatureTogglesRepository(org.openkilda.persistence.repositories.KildaFeatureTogglesRepository) PathNodePayload(org.openkilda.messaging.payload.flow.PathNodePayload) TIER_2_FAILED(org.openkilda.wfm.topology.flowmonitoring.fsm.FlowLatencyMonitoringFsm.State.TIER_2_FAILED) TIER_1_FAILED(org.openkilda.wfm.topology.flowmonitoring.fsm.FlowLatencyMonitoringFsm.State.TIER_1_FAILED) FlowLatencyMonitoringFsm(org.openkilda.wfm.topology.flowmonitoring.fsm.FlowLatencyMonitoringFsm) Flow(org.openkilda.model.Flow) KildaFeatureToggles(org.openkilda.model.KildaFeatureToggles) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) UNSTABLE(org.openkilda.wfm.topology.flowmonitoring.fsm.FlowLatencyMonitoringFsm.State.UNSTABLE) FlowDefaults(org.openkilda.persistence.dummy.FlowDefaults) Duration(java.time.Duration) FlowPathDto(org.openkilda.messaging.model.FlowPathDto) FlowRepository(org.openkilda.persistence.repositories.FlowRepository) PersistenceDummyEntityFactory(org.openkilda.persistence.dummy.PersistenceDummyEntityFactory) Before(org.junit.Before) FlowEndpoint(org.openkilda.model.FlowEndpoint) FlowOperationsCarrier(org.openkilda.wfm.topology.flowmonitoring.bolt.FlowOperationsCarrier) PathComputationStrategy(org.openkilda.model.PathComputationStrategy) ManualClock(org.openkilda.stubs.ManualClock) UpdateFlowCommand(org.openkilda.messaging.info.flow.UpdateFlowCommand) Assert.assertTrue(org.junit.Assert.assertTrue) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) Mockito.verify(org.mockito.Mockito.verify) SwitchId(org.openkilda.model.SwitchId) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) Assert.assertEquals(org.junit.Assert.assertEquals) FlowStats(org.openkilda.model.FlowStats) Duration(java.time.Duration) FlowEndpoint(org.openkilda.model.FlowEndpoint) InMemoryGraphBasedTest(org.openkilda.persistence.inmemory.InMemoryGraphBasedTest) Test(org.junit.Test)

Example 8 with FlowStats

use of org.openkilda.model.FlowStats in project open-kilda by telstra.

the class ActionServiceTest method shouldStayInHealthyState.

@Test
public void shouldStayInHealthyState() {
    Duration latency = Duration.ofNanos(flow.getMaxLatency() - 10);
    service.processFlowLatencyMeasurement(flow.getFlowId(), FlowDirection.FORWARD, latency);
    service.processFlowLatencyMeasurement(flow.getFlowId(), FlowDirection.REVERSE, latency.minus(NANOSECOND));
    latency = Duration.ofNanos((long) (flow.getMaxLatency() * (1 + THRESHOLD)) - 1);
    for (int i = 0; i < 10; i++) {
        clock.adjust(Duration.ofSeconds(10));
        service.processFlowLatencyMeasurement(flow.getFlowId(), FlowDirection.FORWARD, latency);
        service.processFlowLatencyMeasurement(flow.getFlowId(), FlowDirection.REVERSE, latency.minus(NANOSECOND));
        service.processTick();
    }
    assertEquals(2, service.fsms.values().size());
    assertTrue(service.fsms.values().stream().allMatch(fsm -> HEALTHY.equals(fsm.getCurrentState())));
    FlowStats actual = flowStatsRepository.findByFlowId(flow.getFlowId()).orElseThrow(() -> new IllegalStateException("Flow not found"));
    assertEquals(latency.getNano(), actual.getForwardLatency().intValue());
    assertEquals(latency.minus(NANOSECOND).getNano(), actual.getReverseLatency().intValue());
    verifyNoMoreInteractions(carrier);
}
Also used : FlowDirection(org.openkilda.server42.messaging.FlowDirection) Arrays(java.util.Arrays) FlowStats(org.openkilda.model.FlowStats) InMemoryGraphBasedTest(org.openkilda.persistence.inmemory.InMemoryGraphBasedTest) HEALTHY(org.openkilda.wfm.topology.flowmonitoring.fsm.FlowLatencyMonitoringFsm.State.HEALTHY) Mock(org.mockito.Mock) FlowStatsRepository(org.openkilda.persistence.repositories.FlowStatsRepository) RunWith(org.junit.runner.RunWith) KildaFeatureTogglesRepository(org.openkilda.persistence.repositories.KildaFeatureTogglesRepository) PathNodePayload(org.openkilda.messaging.payload.flow.PathNodePayload) TIER_2_FAILED(org.openkilda.wfm.topology.flowmonitoring.fsm.FlowLatencyMonitoringFsm.State.TIER_2_FAILED) TIER_1_FAILED(org.openkilda.wfm.topology.flowmonitoring.fsm.FlowLatencyMonitoringFsm.State.TIER_1_FAILED) FlowLatencyMonitoringFsm(org.openkilda.wfm.topology.flowmonitoring.fsm.FlowLatencyMonitoringFsm) Flow(org.openkilda.model.Flow) KildaFeatureToggles(org.openkilda.model.KildaFeatureToggles) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) UNSTABLE(org.openkilda.wfm.topology.flowmonitoring.fsm.FlowLatencyMonitoringFsm.State.UNSTABLE) FlowDefaults(org.openkilda.persistence.dummy.FlowDefaults) Duration(java.time.Duration) FlowPathDto(org.openkilda.messaging.model.FlowPathDto) FlowRepository(org.openkilda.persistence.repositories.FlowRepository) PersistenceDummyEntityFactory(org.openkilda.persistence.dummy.PersistenceDummyEntityFactory) Before(org.junit.Before) FlowEndpoint(org.openkilda.model.FlowEndpoint) FlowOperationsCarrier(org.openkilda.wfm.topology.flowmonitoring.bolt.FlowOperationsCarrier) PathComputationStrategy(org.openkilda.model.PathComputationStrategy) ManualClock(org.openkilda.stubs.ManualClock) UpdateFlowCommand(org.openkilda.messaging.info.flow.UpdateFlowCommand) Assert.assertTrue(org.junit.Assert.assertTrue) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) Mockito.verify(org.mockito.Mockito.verify) SwitchId(org.openkilda.model.SwitchId) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) Assert.assertEquals(org.junit.Assert.assertEquals) FlowStats(org.openkilda.model.FlowStats) Duration(java.time.Duration) FlowEndpoint(org.openkilda.model.FlowEndpoint) InMemoryGraphBasedTest(org.openkilda.persistence.inmemory.InMemoryGraphBasedTest) Test(org.junit.Test)

Example 9 with FlowStats

use of org.openkilda.model.FlowStats in project open-kilda by telstra.

the class ActionServiceTest method shouldFailTier1AndSendRerouteRequest.

@Test
public void shouldFailTier1AndSendRerouteRequest() {
    service.processFlowLatencyMeasurement(flow.getFlowId(), FlowDirection.FORWARD, NANOSECOND);
    service.processFlowLatencyMeasurement(flow.getFlowId(), FlowDirection.REVERSE, NANOSECOND);
    Duration latency = Duration.ofNanos((long) (flow.getMaxLatency() * (1 + THRESHOLD)) + 5);
    for (int i = 0; i < 10; i++) {
        clock.adjust(Duration.ofSeconds(10));
        service.processFlowLatencyMeasurement(flow.getFlowId(), FlowDirection.FORWARD, latency);
        service.processFlowLatencyMeasurement(flow.getFlowId(), FlowDirection.REVERSE, latency.minus(NANOSECOND));
        service.processTick();
        if (i == 0) {
            assertTrue(service.fsms.values().stream().allMatch(fsm -> UNSTABLE.equals(fsm.getCurrentState())));
        }
    }
    assertEquals(2, service.fsms.values().size());
    assertTrue(service.fsms.values().stream().allMatch(fsm -> TIER_1_FAILED.equals(fsm.getCurrentState())));
    FlowStats actual = flowStatsRepository.findByFlowId(flow.getFlowId()).orElseThrow(() -> new IllegalStateException("Flow not found"));
    assertEquals(latency.getNano(), actual.getForwardLatency().intValue());
    assertEquals(latency.minus(NANOSECOND).getNano(), actual.getReverseLatency().intValue());
    verify(carrier, times(2)).sendFlowRerouteRequest(flow.getFlowId());
    verifyNoMoreInteractions(carrier);
}
Also used : FlowDirection(org.openkilda.server42.messaging.FlowDirection) Arrays(java.util.Arrays) FlowStats(org.openkilda.model.FlowStats) InMemoryGraphBasedTest(org.openkilda.persistence.inmemory.InMemoryGraphBasedTest) HEALTHY(org.openkilda.wfm.topology.flowmonitoring.fsm.FlowLatencyMonitoringFsm.State.HEALTHY) Mock(org.mockito.Mock) FlowStatsRepository(org.openkilda.persistence.repositories.FlowStatsRepository) RunWith(org.junit.runner.RunWith) KildaFeatureTogglesRepository(org.openkilda.persistence.repositories.KildaFeatureTogglesRepository) PathNodePayload(org.openkilda.messaging.payload.flow.PathNodePayload) TIER_2_FAILED(org.openkilda.wfm.topology.flowmonitoring.fsm.FlowLatencyMonitoringFsm.State.TIER_2_FAILED) TIER_1_FAILED(org.openkilda.wfm.topology.flowmonitoring.fsm.FlowLatencyMonitoringFsm.State.TIER_1_FAILED) FlowLatencyMonitoringFsm(org.openkilda.wfm.topology.flowmonitoring.fsm.FlowLatencyMonitoringFsm) Flow(org.openkilda.model.Flow) KildaFeatureToggles(org.openkilda.model.KildaFeatureToggles) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) UNSTABLE(org.openkilda.wfm.topology.flowmonitoring.fsm.FlowLatencyMonitoringFsm.State.UNSTABLE) FlowDefaults(org.openkilda.persistence.dummy.FlowDefaults) Duration(java.time.Duration) FlowPathDto(org.openkilda.messaging.model.FlowPathDto) FlowRepository(org.openkilda.persistence.repositories.FlowRepository) PersistenceDummyEntityFactory(org.openkilda.persistence.dummy.PersistenceDummyEntityFactory) Before(org.junit.Before) FlowEndpoint(org.openkilda.model.FlowEndpoint) FlowOperationsCarrier(org.openkilda.wfm.topology.flowmonitoring.bolt.FlowOperationsCarrier) PathComputationStrategy(org.openkilda.model.PathComputationStrategy) ManualClock(org.openkilda.stubs.ManualClock) UpdateFlowCommand(org.openkilda.messaging.info.flow.UpdateFlowCommand) Assert.assertTrue(org.junit.Assert.assertTrue) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) Mockito.verify(org.mockito.Mockito.verify) SwitchId(org.openkilda.model.SwitchId) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) Assert.assertEquals(org.junit.Assert.assertEquals) FlowStats(org.openkilda.model.FlowStats) Duration(java.time.Duration) FlowEndpoint(org.openkilda.model.FlowEndpoint) InMemoryGraphBasedTest(org.openkilda.persistence.inmemory.InMemoryGraphBasedTest) Test(org.junit.Test)

Aggregations

Flow (org.openkilda.model.Flow)9 FlowStats (org.openkilda.model.FlowStats)9 Duration (java.time.Duration)7 Arrays (java.util.Arrays)7 Assert.assertEquals (org.junit.Assert.assertEquals)7 Assert.assertTrue (org.junit.Assert.assertTrue)7 Before (org.junit.Before)7 Test (org.junit.Test)7 RunWith (org.junit.runner.RunWith)7 Mock (org.mockito.Mock)7 Mockito.times (org.mockito.Mockito.times)7 Mockito.verify (org.mockito.Mockito.verify)7 Mockito.verifyNoMoreInteractions (org.mockito.Mockito.verifyNoMoreInteractions)7 MockitoJUnitRunner (org.mockito.junit.MockitoJUnitRunner)7 UpdateFlowCommand (org.openkilda.messaging.info.flow.UpdateFlowCommand)7 FlowPathDto (org.openkilda.messaging.model.FlowPathDto)7 PathNodePayload (org.openkilda.messaging.payload.flow.PathNodePayload)7 FlowEndpoint (org.openkilda.model.FlowEndpoint)7 KildaFeatureToggles (org.openkilda.model.KildaFeatureToggles)7 PathComputationStrategy (org.openkilda.model.PathComputationStrategy)7