Search in sources :

Example 1 with YFlowRepository

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

the class AbstractYFlowTest method createYFlowViaTransit.

protected YFlow createYFlowViaTransit(String yFlowId) {
    // Create sub-flows
    Flow firstFlow = dummyFactory.makeMainAffinityFlow(firstSharedEndpoint, firstEndpoint, islSharedToTransit, islTransitToFirst);
    Flow secondFlow = dummyFactory.makeFlow(secondSharedEndpoint, secondEndpoint, firstFlow.getAffinityGroupId(), islSharedToTransit, islTransitToSecond);
    SwitchId yPoint = SWITCH_TRANSIT;
    FlowMeter yPointMeter = dummyFactory.makeFlowMeter(yPoint, yFlowId, null);
    FlowMeter sharedEndpointMeter = dummyFactory.makeFlowMeter(firstSharedEndpoint.getSwitchId(), yFlowId, null);
    YFlow yFlow = YFlow.builder().yFlowId(yFlowId).sharedEndpoint(new SharedEndpoint(firstSharedEndpoint.getSwitchId(), firstSharedEndpoint.getPortNumber())).sharedEndpointMeterId(sharedEndpointMeter.getMeterId()).yPoint(yPoint).meterId(yPointMeter.getMeterId()).status(FlowStatus.UP).build();
    yFlow.setSubFlows(Stream.of(firstFlow, secondFlow).map(flow -> YSubFlow.builder().sharedEndpointVlan(flow.getSrcVlan()).sharedEndpointInnerVlan(flow.getSrcInnerVlan()).endpointSwitchId(flow.getDestSwitchId()).endpointPort(flow.getDestPort()).endpointVlan(flow.getDestVlan()).endpointInnerVlan(flow.getDestInnerVlan()).flow(flow).yFlow(yFlow).build()).collect(Collectors.toSet()));
    YFlowRepository yFlowRepository = persistenceManager.getRepositoryFactory().createYFlowRepository();
    yFlowRepository.add(yFlow);
    return yFlow;
}
Also used : YFlow(org.openkilda.model.YFlow) YFlowRepository(org.openkilda.persistence.repositories.YFlowRepository) SwitchId(org.openkilda.model.SwitchId) SharedEndpoint(org.openkilda.model.YFlow.SharedEndpoint) FlowMeter(org.openkilda.model.FlowMeter) Flow(org.openkilda.model.Flow) YSubFlow(org.openkilda.model.YSubFlow) YFlow(org.openkilda.model.YFlow)

Example 2 with YFlowRepository

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

the class AbstractYFlowTest method createYFlowWithProtected.

protected YFlow createYFlowWithProtected(String yFlowId) {
    dummyFactory.getFlowDefaults().setAllocateProtectedPath(true);
    // Create sub-flows
    Flow firstFlow = dummyFactory.makeMainAffinityFlowWithProtectedPath(firstSharedEndpoint, firstEndpoint, asList(islSharedToTransit, islTransitToFirst), asList(islSharedToAltTransit, islAltTransitToFirst));
    Flow secondFlow = dummyFactory.makeFlowWithProtectedPath(secondSharedEndpoint, secondEndpoint, firstFlow.getAffinityGroupId(), asList(islSharedToTransit, islTransitToSecond), asList(islSharedToAltTransit, islAltTransitToSecond));
    YFlow yFlow = YFlow.builder().yFlowId(yFlowId).sharedEndpoint(new SharedEndpoint(firstSharedEndpoint.getSwitchId(), firstSharedEndpoint.getPortNumber())).allocateProtectedPath(true).status(FlowStatus.UP).build();
    yFlow.setSubFlows(Stream.of(firstFlow, secondFlow).map(flow -> YSubFlow.builder().sharedEndpointVlan(flow.getSrcVlan()).sharedEndpointInnerVlan(flow.getSrcInnerVlan()).endpointSwitchId(flow.getDestSwitchId()).endpointPort(flow.getDestPort()).endpointVlan(flow.getDestVlan()).endpointInnerVlan(flow.getDestInnerVlan()).flow(flow).yFlow(yFlow).build()).collect(Collectors.toSet()));
    YFlowRepository yFlowRepository = persistenceManager.getRepositoryFactory().createYFlowRepository();
    yFlowRepository.add(yFlow);
    return yFlow;
}
Also used : YFlow(org.openkilda.model.YFlow) YFlowRepository(org.openkilda.persistence.repositories.YFlowRepository) SharedEndpoint(org.openkilda.model.YFlow.SharedEndpoint) Flow(org.openkilda.model.Flow) YSubFlow(org.openkilda.model.YSubFlow) YFlow(org.openkilda.model.YFlow)

Example 3 with YFlowRepository

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

the class AbstractYFlowTest method verifyYFlowIsAbsent.

protected void verifyYFlowIsAbsent(String yFlowId) {
    YFlowRepository repository = persistenceManager.getRepositoryFactory().createYFlowRepository();
    assertFalse(repository.findById(yFlowId).isPresent());
}
Also used : YFlowRepository(org.openkilda.persistence.repositories.YFlowRepository)

Example 4 with YFlowRepository

use of org.openkilda.persistence.repositories.YFlowRepository 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)

Example 5 with YFlowRepository

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

the class YFlowCreateServiceTest method shouldFailOnErrorDuringDraftYFlowCreation.

@Test
public void shouldFailOnErrorDuringDraftYFlowCreation() throws RecoverableException, UnroutableFlowException, DuplicateKeyException {
    // given
    YFlowRequest request = buildYFlowRequest("test_failed_yflow", "test_flow_1", "test_flow_2").build();
    YFlowRepository repository = setupYFlowRepositorySpy();
    doThrow(new RuntimeException(injectedErrorMessage)).when(repository).add(ArgumentMatchers.argThat(argument -> argument.getYFlowId().equals(request.getYFlowId())));
    preparePathComputation("test_flow_1", buildFirstSubFlowPathPair());
    preparePathComputation("test_flow_2", buildSecondSubFlowPathPair());
    prepareYPointComputation(SWITCH_SHARED, SWITCH_FIRST_EP, SWITCH_SECOND_EP, SWITCH_TRANSIT);
    // when
    processRequest(request);
    // then
    verifyNorthboundErrorResponse(yFlowCreateHubCarrier, ErrorType.INTERNAL_ERROR);
    verifyNoSpeakerInteraction(yFlowCreateHubCarrier);
    verifyYFlowIsAbsent(request.getYFlowId());
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ArgumentMatchers(org.mockito.ArgumentMatchers) FlowPath(org.openkilda.model.FlowPath) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Mock(org.mockito.Mock) YFlowResponse(org.openkilda.messaging.command.yflow.YFlowResponse) RunWith(org.junit.runner.RunWith) FlowStatus(org.openkilda.model.FlowStatus) ResourceAllocationException(org.openkilda.wfm.share.flow.resources.ResourceAllocationException) RecoverableException(org.openkilda.pce.exception.RecoverableException) Mockito.doThrow(org.mockito.Mockito.doThrow) SpeakerRequest(org.openkilda.floodlight.api.request.SpeakerRequest) ArgumentMatcher(org.mockito.ArgumentMatcher) UnroutableFlowException(org.openkilda.pce.exception.UnroutableFlowException) InstallSpeakerCommandsRequest(org.openkilda.floodlight.api.request.rulemanager.InstallSpeakerCommandsRequest) Mockito.doAnswer(org.mockito.Mockito.doAnswer) SpeakerResponse(org.openkilda.floodlight.api.response.SpeakerResponse) UnknownKeyException(org.openkilda.wfm.topology.flowhs.exception.UnknownKeyException) FlowDeleteService(org.openkilda.wfm.topology.flowhs.service.FlowDeleteService) FlowSegmentRequest(org.openkilda.floodlight.api.request.FlowSegmentRequest) YFlowRequest(org.openkilda.messaging.command.yflow.YFlowRequest) Before(org.junit.Before) FlowGenericCarrier(org.openkilda.wfm.topology.flowhs.service.FlowGenericCarrier) DuplicateKeyException(org.openkilda.wfm.topology.flowhs.exception.DuplicateKeyException) ErrorType(org.openkilda.messaging.error.ErrorType) Mockito.times(org.mockito.Mockito.times) CommandContext(org.openkilda.wfm.CommandContext) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) FlowCreateService(org.openkilda.wfm.topology.flowhs.service.FlowCreateService) Mockito.verify(org.mockito.Mockito.verify) YFlowRepository(org.openkilda.persistence.repositories.YFlowRepository) SwitchId(org.openkilda.model.SwitchId) Ignore(org.junit.Ignore) BaseSpeakerCommandsRequest(org.openkilda.floodlight.api.request.rulemanager.BaseSpeakerCommandsRequest) GetPathsResult(org.openkilda.pce.GetPathsResult) AbstractYFlowTest(org.openkilda.wfm.topology.flowhs.service.AbstractYFlowTest) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) YFlowRepository(org.openkilda.persistence.repositories.YFlowRepository) YFlowRequest(org.openkilda.messaging.command.yflow.YFlowRequest) Test(org.junit.Test) AbstractYFlowTest(org.openkilda.wfm.topology.flowhs.service.AbstractYFlowTest)

Aggregations

YFlowRepository (org.openkilda.persistence.repositories.YFlowRepository)8 Test (org.junit.Test)4 YFlow (org.openkilda.model.YFlow)3 SharedEndpoint (org.openkilda.model.YFlow.SharedEndpoint)3 PersistenceManager (org.openkilda.persistence.PersistenceManager)3 RepositoryFactory (org.openkilda.persistence.repositories.RepositoryFactory)3 FlowThrottlingData (org.openkilda.wfm.topology.reroute.model.FlowThrottlingData)3 Flow (org.openkilda.model.Flow)2 SwitchId (org.openkilda.model.SwitchId)2 YSubFlow (org.openkilda.model.YSubFlow)2 FlowPathRepository (org.openkilda.persistence.repositories.FlowPathRepository)2 Before (org.junit.Before)1 Ignore (org.junit.Ignore)1 RunWith (org.junit.runner.RunWith)1 ArgumentMatcher (org.mockito.ArgumentMatcher)1 ArgumentMatchers (org.mockito.ArgumentMatchers)1 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)1 ArgumentMatchers.eq (org.mockito.ArgumentMatchers.eq)1 Mock (org.mockito.Mock)1 Mockito.doAnswer (org.mockito.Mockito.doAnswer)1