Search in sources :

Example 1 with FlowRepository

use of org.openkilda.persistence.repositories.FlowRepository in project open-kilda by telstra.

the class FlowDeleteServiceTest method shouldCompleteDeleteOnErrorDuringRemovingFlow.

@Test
public void shouldCompleteDeleteOnErrorDuringRemovingFlow() throws DuplicateKeyException, UnknownKeyException {
    Flow target = makeFlow();
    FlowRepository repository = setupFlowRepositorySpy();
    doThrow(new RuntimeException(injectedErrorMessage)).when(repository).remove(eq(target.getFlowId()));
    FlowDeleteService service = makeService();
    service.handleRequest(dummyRequestKey, commandContext, target.getFlowId());
    verifyFlowStatus(target.getFlowId(), FlowStatus.IN_PROGRESS);
    verifyNorthboundSuccessResponse(carrier);
    // 4 flow rules + 4 mirror rules
    verify(carrier, times(8)).sendSpeakerRequest(any());
    produceSpeakerResponses(service);
    // FIXME(surabujin): The flow become untouchable from kilda API (because it stack in IN_PROGRESS state
    // no one CRUD operation can perform on it). This is DB/persisted storage level error, we do not have
    // a clear plan on the way how to handle it.
    verifyFlowStatus(target.getFlowId(), FlowStatus.IN_PROGRESS);
}
Also used : FlowRepository(org.openkilda.persistence.repositories.FlowRepository) Flow(org.openkilda.model.Flow) Test(org.junit.Test)

Example 2 with FlowRepository

use of org.openkilda.persistence.repositories.FlowRepository in project open-kilda by telstra.

the class SwitchSyncServiceImplTest method setUp.

@Before
public void setUp() {
    RepositoryFactory repositoryFactory = Mockito.mock(RepositoryFactory.class);
    FlowRepository flowRepository = Mockito.mock(FlowRepository.class);
    FlowPathRepository flowPathRepository = Mockito.mock(FlowPathRepository.class);
    TransitVlanRepository transitVlanRepository = Mockito.mock(TransitVlanRepository.class);
    when(repositoryFactory.createFlowPathRepository()).thenReturn(flowPathRepository);
    when(repositoryFactory.createFlowRepository()).thenReturn(flowRepository);
    when(repositoryFactory.createTransitVlanRepository()).thenReturn(transitVlanRepository);
    when(persistenceManager.getRepositoryFactory()).thenReturn(repositoryFactory);
    Properties configProps = new Properties();
    configProps.setProperty("flow.meter-id.max", "40");
    configProps.setProperty("flow.vlan.max", "50");
    PropertiesBasedConfigurationProvider configurationProvider = new PropertiesBasedConfigurationProvider(configProps);
    FlowResourcesConfig flowResourcesConfig = configurationProvider.getConfiguration(FlowResourcesConfig.class);
    service = new SwitchSyncServiceImpl(carrier, persistenceManager, flowResourcesConfig);
    service.commandBuilder = commandBuilder;
    request = SwitchValidateRequest.builder().switchId(SWITCH_ID).performSync(true).build();
    flowEntry = new FlowEntry(new FlowSegmentCookie(FlowPathDirection.FORWARD, 7).getValue(), 0, 0, 0, 0, "", 0, 0, 0, 0, null, null, null);
    InstallIngressFlow installingRule = new InstallIngressFlow(UUID.randomUUID(), FLOW_ID, flowEntry.getCookie(), SWITCH_ID, 1, 2, 50, 0, 60, FlowEncapsulationType.TRANSIT_VLAN, OutputVlanType.POP, 10L, 100L, EGRESS_SWITCH_ID, false, false, false, null);
    when(commandBuilder.buildCommandsToSyncMissingRules(eq(SWITCH_ID), any())).thenReturn(singletonList(installingRule));
    missingRules = singletonList(flowEntry.getCookie());
    excessRules = emptyList();
    misconfiguredRules = emptyList();
    excessMeters = emptyList();
}
Also used : InstallIngressFlow(org.openkilda.messaging.command.flow.InstallIngressFlow) FlowRepository(org.openkilda.persistence.repositories.FlowRepository) FlowPathRepository(org.openkilda.persistence.repositories.FlowPathRepository) FlowResourcesConfig(org.openkilda.wfm.share.flow.resources.FlowResourcesConfig) FlowSegmentCookie(org.openkilda.model.cookie.FlowSegmentCookie) TransitVlanRepository(org.openkilda.persistence.repositories.TransitVlanRepository) PropertiesBasedConfigurationProvider(org.openkilda.config.provider.PropertiesBasedConfigurationProvider) RepositoryFactory(org.openkilda.persistence.repositories.RepositoryFactory) Properties(java.util.Properties) FlowEntry(org.openkilda.messaging.info.rule.FlowEntry) Before(org.junit.Before)

Example 3 with FlowRepository

use of org.openkilda.persistence.repositories.FlowRepository in project open-kilda by telstra.

the class RerouteServiceTest method shouldSkipRerouteRequestsForFlowWithoutAffectedPathSegment.

@Test
public void shouldSkipRerouteRequestsForFlowWithoutAffectedPathSegment() {
    PathNode islSide = new PathNode(SWITCH_A.getSwitchId(), 1, 0);
    FlowPathRepository pathRepository = mock(FlowPathRepository.class);
    when(pathRepository.findBySegmentEndpoint(eq(islSide.getSwitchId()), eq(islSide.getPortNo()))).thenReturn(asList(regularFlow.getForwardPath(), regularFlow.getReversePath()));
    FlowRepository flowRepository = mock(FlowRepository.class);
    PathSegmentRepository pathSegmentRepository = mock(PathSegmentRepository.class);
    doThrow(new EntityNotFoundException("Not found")).when(pathSegmentRepository).updateFailedStatus(any(), any(), anyBoolean());
    RepositoryFactory repositoryFactory = mock(RepositoryFactory.class);
    when(repositoryFactory.createPathSegmentRepository()).thenReturn(pathSegmentRepository);
    when(repositoryFactory.createFlowPathRepository()).thenReturn(pathRepository);
    when(repositoryFactory.createFlowRepository()).thenReturn(flowRepository);
    PersistenceManager persistenceManager = mock(PersistenceManager.class);
    when(persistenceManager.getRepositoryFactory()).thenReturn(repositoryFactory);
    when(persistenceManager.getTransactionManager()).thenReturn(transactionManager);
    RerouteService rerouteService = new RerouteService(persistenceManager);
    RerouteAffectedFlows request = new RerouteAffectedFlows(islSide, "dummy-reason - unittest");
    rerouteService.rerouteAffectedFlows(carrier, CORRELATION_ID, request);
    verifyZeroInteractions(carrier);
}
Also used : FlowPathRepository(org.openkilda.persistence.repositories.FlowPathRepository) FlowRepository(org.openkilda.persistence.repositories.FlowRepository) YFlowRepository(org.openkilda.persistence.repositories.YFlowRepository) PathSegmentRepository(org.openkilda.persistence.repositories.PathSegmentRepository) PersistenceManager(org.openkilda.persistence.PersistenceManager) EntityNotFoundException(org.openkilda.persistence.exceptions.EntityNotFoundException) RepositoryFactory(org.openkilda.persistence.repositories.RepositoryFactory) RerouteAffectedFlows(org.openkilda.messaging.command.reroute.RerouteAffectedFlows) PathNode(org.openkilda.messaging.info.event.PathNode) Test(org.junit.Test)

Example 4 with FlowRepository

use of org.openkilda.persistence.repositories.FlowRepository in project open-kilda by telstra.

the class RerouteServiceTest method handlePathNoFoundException.

@Test
public void handlePathNoFoundException() {
    PathNode islSide = new PathNode(SWITCH_A.getSwitchId(), 1, 0);
    FlowPathRepository pathRepository = mock(FlowPathRepository.class);
    when(pathRepository.findBySegmentEndpoint(eq(islSide.getSwitchId()), eq(islSide.getPortNo()))).thenReturn(asList(regularFlow.getForwardPath(), regularFlow.getReversePath()));
    FlowRepository flowRepository = mock(FlowRepository.class);
    RepositoryFactory repositoryFactory = mock(RepositoryFactory.class);
    when(repositoryFactory.createPathSegmentRepository()).thenReturn(mock(PathSegmentRepository.class));
    when(repositoryFactory.createFlowPathRepository()).thenReturn(pathRepository);
    when(repositoryFactory.createFlowRepository()).thenReturn(flowRepository);
    PersistenceManager persistenceManager = mock(PersistenceManager.class);
    when(persistenceManager.getRepositoryFactory()).thenReturn(repositoryFactory);
    when(persistenceManager.getTransactionManager()).thenReturn(transactionManager);
    RerouteService rerouteService = new RerouteService(persistenceManager);
    RerouteAffectedFlows request = new RerouteAffectedFlows(islSide, "dummy-reason - unittest");
    rerouteService.rerouteAffectedFlows(carrier, CORRELATION_ID, request);
    verify(flowRepository).updateStatusSafe(eq(regularFlow), eq(FlowStatus.DOWN), any());
    FlowThrottlingData expected = FlowThrottlingData.builder().correlationId(CORRELATION_ID).priority(regularFlow.getPriority()).timeCreate(regularFlow.getTimeCreate()).affectedIsl(Collections.singleton(new IslEndpoint(islSide.getSwitchId(), islSide.getPortNo()))).force(false).effectivelyDown(true).reason(request.getReason()).build();
    verify(carrier).emitRerouteCommand(eq(regularFlow.getFlowId()), eq(expected));
}
Also used : FlowPathRepository(org.openkilda.persistence.repositories.FlowPathRepository) FlowRepository(org.openkilda.persistence.repositories.FlowRepository) YFlowRepository(org.openkilda.persistence.repositories.YFlowRepository) IslEndpoint(org.openkilda.model.IslEndpoint) PathSegmentRepository(org.openkilda.persistence.repositories.PathSegmentRepository) PersistenceManager(org.openkilda.persistence.PersistenceManager) FlowThrottlingData(org.openkilda.wfm.topology.reroute.model.FlowThrottlingData) RepositoryFactory(org.openkilda.persistence.repositories.RepositoryFactory) RerouteAffectedFlows(org.openkilda.messaging.command.reroute.RerouteAffectedFlows) PathNode(org.openkilda.messaging.info.event.PathNode) Test(org.junit.Test)

Example 5 with FlowRepository

use of org.openkilda.persistence.repositories.FlowRepository in project open-kilda by telstra.

the class FlowFetcher method refreshHeap.

private void refreshHeap(Tuple input, boolean emitCacheExpiry) throws PipelineException {
    log.debug("Handle periodic ping request");
    Set<FlowWithTransitEncapsulation> flowsWithTransitEncapsulation = flowRepository.findWithPeriodicPingsEnabled().stream().peek(flowRepository::detach).map(this::getFlowWithTransitEncapsulation).flatMap(o -> o.isPresent() ? Stream.of(o.get()) : Stream.empty()).collect(Collectors.toSet());
    if (emitCacheExpiry) {
        final CommandContext commandContext = pullContext(input);
        emitCacheExpire(input, commandContext, flowsWithTransitEncapsulation);
    }
    flowsSet = flowsWithTransitEncapsulation;
    lastPeriodicPingCacheRefresh = System.currentTimeMillis();
}
Also used : OutputFieldsDeclarer(org.apache.storm.topology.OutputFieldsDeclarer) YFlowPingResponse(org.openkilda.messaging.info.flow.YFlowPingResponse) FlowTransitEncapsulation(org.openkilda.model.FlowTransitEncapsulation) FlowResourcesConfig(org.openkilda.wfm.share.flow.resources.FlowResourcesConfig) Value(lombok.Value) ArrayList(java.util.ArrayList) Values(org.apache.storm.tuple.Values) Tuple(org.apache.storm.tuple.Tuple) FlowPingRequest(org.openkilda.messaging.command.flow.FlowPingRequest) Flow(org.openkilda.model.Flow) OutputCollector(org.apache.storm.task.OutputCollector) PipelineException(org.openkilda.wfm.error.PipelineException) Kinds(org.openkilda.wfm.topology.ping.model.PingContext.Kinds) YFlow(org.openkilda.model.YFlow) FlowRepository(org.openkilda.persistence.repositories.FlowRepository) PersistenceManager(org.openkilda.persistence.PersistenceManager) Utils(org.openkilda.messaging.Utils) YSubFlow(org.openkilda.model.YSubFlow) PersistenceContextRequired(org.openkilda.persistence.context.PersistenceContextRequired) PeriodicPingCommand(org.openkilda.messaging.command.flow.PeriodicPingCommand) Set(java.util.Set) CommandContext(org.openkilda.wfm.CommandContext) Fields(org.apache.storm.tuple.Fields) FlowPingResponse(org.openkilda.messaging.info.flow.FlowPingResponse) EqualsAndHashCode(lombok.EqualsAndHashCode) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) YFlowRepository(org.openkilda.persistence.repositories.YFlowRepository) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) YFlowPingRequest(org.openkilda.messaging.command.flow.YFlowPingRequest) Stream(java.util.stream.Stream) GroupId(org.openkilda.wfm.topology.ping.model.GroupId) PingContext(org.openkilda.wfm.topology.ping.model.PingContext) FlowResourcesManager(org.openkilda.wfm.share.flow.resources.FlowResourcesManager) Optional(java.util.Optional) AllArgsConstructor(lombok.AllArgsConstructor) CommandContext(org.openkilda.wfm.CommandContext)

Aggregations

FlowRepository (org.openkilda.persistence.repositories.FlowRepository)12 Test (org.junit.Test)9 RepositoryFactory (org.openkilda.persistence.repositories.RepositoryFactory)9 PersistenceManager (org.openkilda.persistence.PersistenceManager)8 FlowPathRepository (org.openkilda.persistence.repositories.FlowPathRepository)8 YFlowRepository (org.openkilda.persistence.repositories.YFlowRepository)8 PathSegmentRepository (org.openkilda.persistence.repositories.PathSegmentRepository)5 RerouteAffectedFlows (org.openkilda.messaging.command.reroute.RerouteAffectedFlows)3 PathNode (org.openkilda.messaging.info.event.PathNode)3 FlowPath (org.openkilda.model.FlowPath)3 Flow (org.openkilda.model.Flow)2 IslEndpoint (org.openkilda.model.IslEndpoint)2 PathSegment (org.openkilda.model.PathSegment)2 FlowResourcesConfig (org.openkilda.wfm.share.flow.resources.FlowResourcesConfig)2 MessageSender (org.openkilda.wfm.topology.reroute.bolts.MessageSender)2 FlowThrottlingData (org.openkilda.wfm.topology.reroute.model.FlowThrottlingData)2 String.format (java.lang.String.format)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Optional (java.util.Optional)1