Search in sources :

Example 11 with PersistenceManager

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

the class RerouteServiceTest method handleRerouteInactiveAffectedFlows.

@Test
public void handleRerouteInactiveAffectedFlows() {
    FlowPathRepository pathRepository = mock(FlowPathRepository.class);
    when(pathRepository.findInactiveBySegmentSwitch(regularFlow.getSrcSwitchId())).thenReturn(asList(regularFlow.getForwardPath(), regularFlow.getReversePath()));
    RepositoryFactory repositoryFactory = mock(RepositoryFactory.class);
    when(repositoryFactory.createFlowPathRepository()).thenReturn(pathRepository);
    PersistenceManager persistenceManager = mock(PersistenceManager.class);
    when(persistenceManager.getRepositoryFactory()).thenReturn(repositoryFactory);
    when(persistenceManager.getTransactionManager()).thenReturn(transactionManager);
    RerouteService rerouteService = new RerouteService(persistenceManager);
    regularFlow.setStatus(FlowStatus.DOWN);
    rerouteService.rerouteInactiveAffectedFlows(carrier, CORRELATION_ID, regularFlow.getSrcSwitchId());
    FlowThrottlingData expected = FlowThrottlingData.builder().correlationId(CORRELATION_ID).priority(regularFlow.getPriority()).timeCreate(regularFlow.getTimeCreate()).affectedIsl(Collections.emptySet()).force(false).effectivelyDown(true).reason(format("Switch '%s' online", regularFlow.getSrcSwitchId())).build();
    verify(carrier).emitRerouteCommand(eq(regularFlow.getFlowId()), eq(expected));
    regularFlow.setStatus(FlowStatus.UP);
}
Also used : FlowPathRepository(org.openkilda.persistence.repositories.FlowPathRepository) PersistenceManager(org.openkilda.persistence.PersistenceManager) FlowThrottlingData(org.openkilda.wfm.topology.reroute.model.FlowThrottlingData) RepositoryFactory(org.openkilda.persistence.repositories.RepositoryFactory) Test(org.junit.Test)

Example 12 with PersistenceManager

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

the class RerouteServiceTest method handleRerouteAffectedYFlows.

@Test
public void handleRerouteAffectedYFlows() {
    FlowPathRepository pathRepository = mock(FlowPathRepository.class);
    when(pathRepository.findInactiveBySegmentSwitch(subFlow.getSrcSwitchId())).thenReturn(asList(subFlow.getForwardPath(), subFlow.getReversePath()));
    RepositoryFactory repositoryFactory = mock(RepositoryFactory.class);
    when(repositoryFactory.createFlowPathRepository()).thenReturn(pathRepository);
    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);
    RerouteService rerouteService = new RerouteService(persistenceManager);
    subFlow.setStatus(FlowStatus.DOWN);
    rerouteService.rerouteInactiveAffectedFlows(carrier, CORRELATION_ID, subFlow.getSrcSwitchId());
    FlowThrottlingData expected = FlowThrottlingData.builder().correlationId(CORRELATION_ID).priority(regularYFlow.getPriority()).timeCreate(regularYFlow.getTimeCreate()).affectedIsl(Collections.emptySet()).force(false).effectivelyDown(true).reason(format("Switch '%s' online", subFlow.getSrcSwitchId())).yFlow(true).build();
    verify(carrier).emitRerouteCommand(eq(regularYFlow.getYFlowId()), eq(expected));
    regularFlow.setStatus(FlowStatus.UP);
}
Also used : FlowPathRepository(org.openkilda.persistence.repositories.FlowPathRepository) YFlowRepository(org.openkilda.persistence.repositories.YFlowRepository) PersistenceManager(org.openkilda.persistence.PersistenceManager) FlowThrottlingData(org.openkilda.wfm.topology.reroute.model.FlowThrottlingData) RepositoryFactory(org.openkilda.persistence.repositories.RepositoryFactory) Test(org.junit.Test)

Example 13 with PersistenceManager

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

the class RerouteServiceTest method handlePathNoFoundExceptionForSubYFlow.

@Test
public void handlePathNoFoundExceptionForSubYFlow() {
    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(subFlow.getForwardPath(), subFlow.getReversePath()));
    FlowRepository flowRepository = mock(FlowRepository.class);
    YFlowRepository yFlowRepository = mock(YFlowRepository.class);
    RepositoryFactory repositoryFactory = mock(RepositoryFactory.class);
    when(repositoryFactory.createPathSegmentRepository()).thenReturn(mock(PathSegmentRepository.class));
    when(repositoryFactory.createFlowPathRepository()).thenReturn(pathRepository);
    when(repositoryFactory.createFlowRepository()).thenReturn(flowRepository);
    when(repositoryFactory.createYFlowRepository()).thenReturn(yFlowRepository);
    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(subFlow), eq(FlowStatus.DOWN), any());
    FlowThrottlingData expected = FlowThrottlingData.builder().correlationId(CORRELATION_ID).priority(regularYFlow.getPriority()).timeCreate(regularYFlow.getTimeCreate()).affectedIsl(Collections.singleton(new IslEndpoint(islSide.getSwitchId(), islSide.getPortNo()))).force(false).effectivelyDown(true).reason(request.getReason()).yFlow(true).build();
    verify(carrier).emitRerouteCommand(eq(regularYFlow.getYFlowId()), 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) YFlowRepository(org.openkilda.persistence.repositories.YFlowRepository) 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 14 with PersistenceManager

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

the class RerouteServiceTest method testRerouteInactivePinnedFlowsOneFailedSegment.

@Test
public void testRerouteInactivePinnedFlowsOneFailedSegment() throws Throwable {
    pinnedFlow.setStatus(FlowStatus.DOWN);
    for (FlowPath flowPath : pinnedFlow.getPaths()) {
        flowPath.setStatus(FlowPathStatus.INACTIVE);
        for (PathSegment pathSegment : flowPath.getSegments()) {
            if (pathSegment.containsNode(SWITCH_ID_A, PORT)) {
                pathSegment.setFailed(true);
            }
        }
    }
    RepositoryFactory repositoryFactory = mock(RepositoryFactory.class);
    FlowRepository flowRepository = mock(FlowRepository.class);
    when(flowRepository.findInactiveFlows()).thenReturn(Collections.singletonList(pinnedFlow));
    doAnswer(invocation -> {
        FlowStatus status = invocation.getArgument(1);
        pinnedFlow.setStatus(status);
        return null;
    }).when(flowRepository).updateStatusSafe(eq(pinnedFlow), any(), any());
    when(repositoryFactory.createFlowRepository()).thenReturn(flowRepository);
    FlowPathRepository pathRepository = mock(FlowPathRepository.class);
    when(repositoryFactory.createFlowPathRepository()).thenReturn(pathRepository);
    PathSegmentRepository pathSegmentRepository = mock(PathSegmentRepository.class);
    when(repositoryFactory.createPathSegmentRepository()).thenReturn(pathSegmentRepository);
    MessageSender messageSender = mock(MessageSender.class);
    PersistenceManager persistenceManager = mock(PersistenceManager.class);
    when(persistenceManager.getRepositoryFactory()).thenReturn(repositoryFactory);
    TransactionManager transactionManager = mock(TransactionManager.class);
    doAnswer(invocation -> {
        TransactionCallback<?, ?> arg = invocation.getArgument(0);
        return arg.doInTransaction();
    }).when(transactionManager).doInTransaction(Mockito.<TransactionCallback<?, ?>>any());
    when(persistenceManager.getTransactionManager()).thenReturn(transactionManager);
    RerouteService rerouteService = new RerouteService(persistenceManager);
    rerouteService.rerouteInactiveFlows(messageSender, CORRELATION_ID, REROUTE_INACTIVE_FLOWS_COMMAND);
    assertEquals(FlowStatus.UP, pinnedFlow.getStatus());
    for (FlowPath fp : pinnedFlow.getPaths()) {
        assertEquals(FlowPathStatus.ACTIVE, fp.getStatus());
        for (PathSegment ps : fp.getSegments()) {
            if (ps.containsNode(SWITCH_ID_A, PORT)) {
                assertFalse(ps.isFailed());
            }
        }
    }
}
Also used : FlowRepository(org.openkilda.persistence.repositories.FlowRepository) YFlowRepository(org.openkilda.persistence.repositories.YFlowRepository) FlowPathRepository(org.openkilda.persistence.repositories.FlowPathRepository) PathSegmentRepository(org.openkilda.persistence.repositories.PathSegmentRepository) PersistenceManager(org.openkilda.persistence.PersistenceManager) MessageSender(org.openkilda.wfm.topology.reroute.bolts.MessageSender) TransactionManager(org.openkilda.persistence.tx.TransactionManager) PathSegment(org.openkilda.model.PathSegment) RepositoryFactory(org.openkilda.persistence.repositories.RepositoryFactory) FlowPath(org.openkilda.model.FlowPath) FlowStatus(org.openkilda.model.FlowStatus) Test(org.junit.Test)

Example 15 with PersistenceManager

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

the class RerouteServiceTest method handleUpdateSingleSwitchFlows.

@Test
public void handleUpdateSingleSwitchFlows() {
    FlowRepository flowRepository = mock(FlowRepository.class);
    when(flowRepository.findOneSwitchFlows(oneSwitchFlow.getSrcSwitch().getSwitchId())).thenReturn(Collections.singletonList(oneSwitchFlow));
    FlowPathRepository flowPathRepository = mock(FlowPathRepository.class);
    RepositoryFactory repositoryFactory = mock(RepositoryFactory.class);
    when(repositoryFactory.createFlowRepository()).thenReturn(flowRepository);
    when(repositoryFactory.createFlowPathRepository()).thenReturn(flowPathRepository);
    PersistenceManager persistenceManager = mock(PersistenceManager.class);
    when(persistenceManager.getRepositoryFactory()).thenReturn(repositoryFactory);
    when(persistenceManager.getTransactionManager()).thenReturn(transactionManager);
    RerouteService rerouteService = new RerouteService(persistenceManager);
    rerouteService.processSingleSwitchFlowStatusUpdate(new SwitchStateChanged(oneSwitchFlow.getSrcSwitchId(), SwitchStatus.INACTIVE));
    assertEquals(format("Switch %s is inactive", oneSwitchFlow.getSrcSwitchId()), FlowStatus.DOWN, oneSwitchFlow.getStatus());
}
Also used : FlowRepository(org.openkilda.persistence.repositories.FlowRepository) YFlowRepository(org.openkilda.persistence.repositories.YFlowRepository) FlowPathRepository(org.openkilda.persistence.repositories.FlowPathRepository) PersistenceManager(org.openkilda.persistence.PersistenceManager) RepositoryFactory(org.openkilda.persistence.repositories.RepositoryFactory) SwitchStateChanged(org.openkilda.messaging.info.reroute.SwitchStateChanged) 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