Search in sources :

Example 1 with EntityNotFoundException

use of org.openkilda.persistence.exceptions.EntityNotFoundException 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 2 with EntityNotFoundException

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

the class RerouteService method updateFlowPathsStateForFlow.

private boolean updateFlowPathsStateForFlow(SwitchId switchId, int port, List<FlowPath> paths) {
    boolean rerouteRequired = false;
    for (FlowPath fp : paths) {
        boolean failedFlowPath = false;
        for (PathSegment pathSegment : fp.getSegments()) {
            if (pathSegment.getSrcPort() == port && switchId.equals(pathSegment.getSrcSwitchId()) || (pathSegment.getDestPort() == port && switchId.equals(pathSegment.getDestSwitchId()))) {
                pathSegment.setFailed(true);
                try {
                    pathSegmentRepository.updateFailedStatus(fp, pathSegment, true);
                    failedFlowPath = true;
                    rerouteRequired = true;
                } catch (EntityNotFoundException e) {
                    log.warn("Path segment not found for flow {} and path {}. Skipping path segment status update.", fp.getFlow().getFlowId(), fp.getPathId(), e);
                }
                break;
            }
        }
        if (failedFlowPath) {
            updateFlowPathStatus(fp, FlowPathStatus.INACTIVE);
        }
    }
    return rerouteRequired;
}
Also used : PathSegment(org.openkilda.model.PathSegment) EntityNotFoundException(org.openkilda.persistence.exceptions.EntityNotFoundException) FlowPath(org.openkilda.model.FlowPath)

Aggregations

EntityNotFoundException (org.openkilda.persistence.exceptions.EntityNotFoundException)2 Test (org.junit.Test)1 RerouteAffectedFlows (org.openkilda.messaging.command.reroute.RerouteAffectedFlows)1 PathNode (org.openkilda.messaging.info.event.PathNode)1 FlowPath (org.openkilda.model.FlowPath)1 PathSegment (org.openkilda.model.PathSegment)1 PersistenceManager (org.openkilda.persistence.PersistenceManager)1 FlowPathRepository (org.openkilda.persistence.repositories.FlowPathRepository)1 FlowRepository (org.openkilda.persistence.repositories.FlowRepository)1 PathSegmentRepository (org.openkilda.persistence.repositories.PathSegmentRepository)1 RepositoryFactory (org.openkilda.persistence.repositories.RepositoryFactory)1 YFlowRepository (org.openkilda.persistence.repositories.YFlowRepository)1