Search in sources :

Example 1 with PersistenceManager

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

the class FlowValidatorTest method setup.

@BeforeClass
public static void setup() {
    RepositoryFactory repositoryFactory = mock(RepositoryFactory.class);
    when(repositoryFactory.createFlowRepository()).thenReturn(mock(FlowRepository.class));
    when(repositoryFactory.createSwitchRepository()).thenReturn(mock(SwitchRepository.class));
    when(repositoryFactory.createIslRepository()).thenReturn(mock(IslRepository.class));
    when(repositoryFactory.createSwitchPropertiesRepository()).thenReturn(mock(SwitchPropertiesRepository.class));
    when(repositoryFactory.createFlowMirrorPathRepository()).thenReturn(mock(FlowMirrorPathRepository.class));
    PersistenceManager persistenceManager = mock(PersistenceManager.class);
    when(persistenceManager.getRepositoryFactory()).thenReturn(repositoryFactory);
    flowValidator = new FlowValidator(persistenceManager);
}
Also used : SwitchPropertiesRepository(org.openkilda.persistence.repositories.SwitchPropertiesRepository) FlowRepository(org.openkilda.persistence.repositories.FlowRepository) IslRepository(org.openkilda.persistence.repositories.IslRepository) PersistenceManager(org.openkilda.persistence.PersistenceManager) FlowMirrorPathRepository(org.openkilda.persistence.repositories.FlowMirrorPathRepository) SwitchRepository(org.openkilda.persistence.repositories.SwitchRepository) RepositoryFactory(org.openkilda.persistence.repositories.RepositoryFactory) BeforeClass(org.junit.BeforeClass)

Example 2 with PersistenceManager

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

the class PingTopology method flowFetcher.

private void flowFetcher(TopologyBuilder topology) {
    PersistenceManager persistenceManager = new PersistenceManager(configurationProvider);
    FlowResourcesConfig flowResourcesConfig = configurationProvider.getConfiguration(FlowResourcesConfig.class);
    FlowFetcher bolt = new FlowFetcher(persistenceManager, flowResourcesConfig, topologyConfig.getPeriodicPingCacheExpirationInterval());
    declareBolt(topology, bolt, FlowFetcher.BOLT_ID).globalGrouping(TickDeduplicator.BOLT_ID, TickDeduplicator.STREAM_PING_ID).shuffleGrouping(InputRouter.BOLT_ID, InputRouter.STREAM_ON_DEMAND_REQUEST_ID).shuffleGrouping(InputRouter.BOLT_ID, InputRouter.STREAM_ON_DEMAND_Y_FLOW_REQUEST_ID).allGrouping(InputRouter.BOLT_ID, InputRouter.STREAM_PERIODIC_PING_UPDATE_REQUEST_ID);
}
Also used : FlowResourcesConfig(org.openkilda.wfm.share.flow.resources.FlowResourcesConfig) FlowFetcher(org.openkilda.wfm.topology.ping.bolt.FlowFetcher) PersistenceManager(org.openkilda.persistence.PersistenceManager)

Example 3 with PersistenceManager

use of org.openkilda.persistence.PersistenceManager 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 PersistenceManager

use of org.openkilda.persistence.PersistenceManager 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 PersistenceManager

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

the class RerouteServiceTest method processManualRerouteRequestForYFlow.

@Test
public void processManualRerouteRequestForYFlow() {
    RepositoryFactory repositoryFactory = mock(RepositoryFactory.class);
    YFlowRepository yFlowRepository = mock(YFlowRepository.class);
    when(repositoryFactory.createYFlowRepository()).thenReturn(yFlowRepository);
    PersistenceManager persistenceManager = mock(PersistenceManager.class);
    when(persistenceManager.getRepositoryFactory()).thenReturn(repositoryFactory);
    when(persistenceManager.getTransactionManager()).thenReturn(transactionManager);
    when(yFlowRepository.findById(YFLOW_ID)).thenReturn(Optional.of(regularYFlow));
    RerouteService rerouteService = new RerouteService(persistenceManager);
    YFlowRerouteRequest request = new YFlowRerouteRequest(regularYFlow.getYFlowId(), Collections.emptySet(), true, "reason", false);
    rerouteService.processRerouteRequest(carrier, CORRELATION_ID, request);
    FlowThrottlingData expected = FlowThrottlingData.builder().correlationId(CORRELATION_ID).priority(regularYFlow.getPriority()).timeCreate(regularYFlow.getTimeCreate()).affectedIsl(Collections.emptySet()).force(true).reason("reason").yFlow(true).build();
    verify(carrier).emitManualRerouteCommand(eq(regularYFlow.getYFlowId()), eq(expected));
}
Also used : YFlowRepository(org.openkilda.persistence.repositories.YFlowRepository) PersistenceManager(org.openkilda.persistence.PersistenceManager) FlowThrottlingData(org.openkilda.wfm.topology.reroute.model.FlowThrottlingData) YFlowRerouteRequest(org.openkilda.messaging.command.yflow.YFlowRerouteRequest) RepositoryFactory(org.openkilda.persistence.repositories.RepositoryFactory) Test(org.junit.Test)

Aggregations

PersistenceManager (org.openkilda.persistence.PersistenceManager)22 RepositoryFactory (org.openkilda.persistence.repositories.RepositoryFactory)13 YFlowRepository (org.openkilda.persistence.repositories.YFlowRepository)11 Test (org.junit.Test)10 FlowRepository (org.openkilda.persistence.repositories.FlowRepository)9 FlowPathRepository (org.openkilda.persistence.repositories.FlowPathRepository)8 TopologyBuilder (org.apache.storm.topology.TopologyBuilder)6 FlowThrottlingData (org.openkilda.wfm.topology.reroute.model.FlowThrottlingData)6 PathSegmentRepository (org.openkilda.persistence.repositories.PathSegmentRepository)5 RerouteAffectedFlows (org.openkilda.messaging.command.reroute.RerouteAffectedFlows)3 PathNode (org.openkilda.messaging.info.event.PathNode)3 BeforeClass (org.junit.BeforeClass)2 YFlowRerouteRequest (org.openkilda.messaging.command.yflow.YFlowRerouteRequest)2 FlowPath (org.openkilda.model.FlowPath)2 PathSegment (org.openkilda.model.PathSegment)2 CoordinatorBolt (org.openkilda.wfm.share.hubandspoke.CoordinatorBolt)2 CoordinatorSpout (org.openkilda.wfm.share.hubandspoke.CoordinatorSpout)2 HubBolt (org.openkilda.wfm.share.hubandspoke.HubBolt)2 WorkerBolt (org.openkilda.wfm.share.hubandspoke.WorkerBolt)2 ZooKeeperBolt (org.openkilda.wfm.share.zk.ZooKeeperBolt)2