Search in sources :

Example 1 with YFlowRequest

use of org.openkilda.messaging.command.yflow.YFlowRequest in project open-kilda by telstra.

the class CreateDraftYFlowAction method performWithResponse.

@Override
protected Optional<Message> performWithResponse(State from, State to, Event event, YFlowCreateContext context, YFlowCreateFsm stateMachine) {
    YFlowRequest targetFlow = stateMachine.getTargetFlow();
    stateMachine.setDiverseFlowId(targetFlow.getDiverseFlowId());
    String yFlowId = targetFlow.getYFlowId();
    if (yFlowRepository.exists(yFlowId)) {
        throw new FlowProcessingException(ErrorType.ALREADY_EXISTS, format("Y-flow %s already exists", yFlowId));
    }
    YFlow result = transactionManager.doInTransaction(() -> {
        YFlow yFlow = YFlowRequestMapper.INSTANCE.toYFlow(targetFlow);
        yFlow.setStatus(FlowStatus.IN_PROGRESS);
        yFlowRepository.add(yFlow);
        return yFlow;
    });
    stateMachine.saveActionToHistory(format("Draft y-flow was created with status %s", result.getStatus()));
    return Optional.empty();
}
Also used : YFlow(org.openkilda.model.YFlow) FlowProcessingException(org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException) YFlowRequest(org.openkilda.messaging.command.yflow.YFlowRequest)

Example 2 with YFlowRequest

use of org.openkilda.messaging.command.yflow.YFlowRequest in project open-kilda by telstra.

the class ValidateYFlowAction method performWithResponse.

@Override
protected Optional<Message> performWithResponse(State from, State to, Event event, YFlowCreateContext context, YFlowCreateFsm stateMachine) {
    YFlowRequest targetFlow = context.getTargetFlow();
    String yFlowId = targetFlow.getYFlowId();
    boolean isOperationAllowed = featureTogglesRepository.getOrDefault().getModifyYFlowEnabled();
    if (!isOperationAllowed) {
        throw new FlowProcessingException(ErrorType.NOT_PERMITTED, "Y-flow create feature is disabled");
    }
    if (flowRepository.exists(yFlowId)) {
        throw new FlowProcessingException(ErrorType.ALREADY_EXISTS, format("Flow %s already exists", yFlowId));
    }
    if (yFlowRepository.exists(yFlowId)) {
        throw new FlowProcessingException(ErrorType.ALREADY_EXISTS, format("Y-flow %s already exists", yFlowId));
    }
    try {
        yFlowValidator.validate(targetFlow);
    } catch (InvalidFlowException e) {
        throw new FlowProcessingException(e.getType(), e.getMessage(), e);
    } catch (UnavailableFlowEndpointException e) {
        throw new FlowProcessingException(ErrorType.DATA_INVALID, e.getMessage(), e);
    }
    stateMachine.setTargetFlow(targetFlow);
    List<FlowEndpoint> subFlowEndpoints = targetFlow.getSubFlows().stream().map(SubFlowDto::getEndpoint).collect(Collectors.toList());
    dashboardLogger.onYFlowCreate(yFlowId, targetFlow.getSharedEndpoint(), subFlowEndpoints, targetFlow.getMaximumBandwidth());
    stateMachine.saveNewEventToHistory("Y-flow was validated successfully", FlowEventData.Event.CREATE);
    return Optional.empty();
}
Also used : UnavailableFlowEndpointException(org.openkilda.wfm.topology.flowhs.validation.UnavailableFlowEndpointException) FlowEndpoint(org.openkilda.model.FlowEndpoint) FlowProcessingException(org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException) InvalidFlowException(org.openkilda.wfm.topology.flowhs.validation.InvalidFlowException) YFlowRequest(org.openkilda.messaging.command.yflow.YFlowRequest)

Example 3 with YFlowRequest

use of org.openkilda.messaging.command.yflow.YFlowRequest in project open-kilda by telstra.

the class RevertYFlowAction method perform.

@Override
protected void perform(State from, State to, Event event, YFlowUpdateContext context, YFlowUpdateFsm stateMachine) {
    YFlowRequest originalFlow = stateMachine.getOriginalFlow();
    YFlowResources resources = stateMachine.getOldResources();
    FlowStatus flowStatus = transactionManager.doInTransaction(() -> {
        YFlow yFlow = getYFlow(originalFlow.getYFlowId());
        revertFlow(yFlow, YFlowRequestMapper.INSTANCE.toYFlow(originalFlow), resources);
        return yFlow.getStatus();
    });
    stateMachine.saveActionToHistory(format("The y-flow was reverted. The status %s", flowStatus));
}
Also used : YFlow(org.openkilda.model.YFlow) YFlowResources(org.openkilda.wfm.topology.flowhs.model.yflow.YFlowResources) YFlowRequest(org.openkilda.messaging.command.yflow.YFlowRequest) FlowStatus(org.openkilda.model.FlowStatus)

Example 4 with YFlowRequest

use of org.openkilda.messaging.command.yflow.YFlowRequest in project open-kilda by telstra.

the class YFlowUpdateServiceTest method createYFlowWithProtectedPath.

private YFlowRequest createYFlowWithProtectedPath() throws UnroutableFlowException, RecoverableException, DuplicateKeyException {
    YFlowRequest request = buildYFlowRequest("test_successful_yflow", "test_flow_1", "test_flow_2").allocateProtectedPath(true).build();
    preparePathComputationForCreate("test_flow_1", buildFirstSubFlowPathPair(), buildFirstSubFlowProtectedPathPair());
    preparePathComputationForCreate("test_flow_2", buildSecondSubFlowPathPair(), buildSecondSubFlowProtectedPathPair());
    prepareYPointComputation(SWITCH_SHARED, SWITCH_FIRST_EP, SWITCH_SECOND_EP, SWITCH_TRANSIT, SWITCH_TRANSIT);
    prepareYPointComputation(SWITCH_SHARED, SWITCH_FIRST_EP, SWITCH_SECOND_EP, SWITCH_ALT_TRANSIT, SWITCH_ALT_TRANSIT);
    processCreateRequestAndSpeakerCommands(request);
    verifyNorthboundSuccessResponse(yFlowCreateHubCarrier, YFlowResponse.class);
    verifyYFlowStatus(request.getYFlowId(), FlowStatus.UP);
    return request;
}
Also used : YFlowRequest(org.openkilda.messaging.command.yflow.YFlowRequest)

Example 5 with YFlowRequest

use of org.openkilda.messaging.command.yflow.YFlowRequest in project open-kilda by telstra.

the class YFlowUpdateServiceTest method shouldFailOnTimeoutDuringMeterInstallation.

@Test
public void shouldFailOnTimeoutDuringMeterInstallation() throws UnroutableFlowException, RecoverableException, DuplicateKeyException, UnknownKeyException {
    // given
    YFlowRequest request = createYFlow();
    request.setMaximumBandwidth(2000L);
    request.getSubFlows().get(0).setEndpoint(newFirstEndpoint);
    request.getSubFlows().get(1).setEndpoint(newSecondEndpoint);
    preparePathComputationForUpdate("test_flow_1", buildNewFirstSubFlowPathPair(), buildFirstSubFlowPathPair());
    preparePathComputationForUpdate("test_flow_2", buildNewSecondSubFlowPathPair(), buildSecondSubFlowPathPair());
    prepareYPointComputation(SWITCH_SHARED, SWITCH_NEW_FIRST_EP, SWITCH_NEW_SECOND_EP, SWITCH_TRANSIT);
    YFlowUpdateService service = makeYFlowUpdateService(0);
    // when
    service.handleRequest(request.getYFlowId(), new CommandContext(), request);
    verifyYFlowStatus(request.getYFlowId(), FlowStatus.IN_PROGRESS);
    // and
    handleSpeakerCommandsAndTimeoutInstall(service, request.getYFlowId());
    // then
    verifyYFlowStatus(request.getYFlowId(), FlowStatus.UP);
    YFlow flow = getYFlow(request.getYFlowId());
    assertEquals(1000L, flow.getMaximumBandwidth());
    Set<SwitchId> expectedEndpointSwitchIds = Stream.of(SWITCH_FIRST_EP, SWITCH_SECOND_EP).collect(Collectors.toSet());
    Set<SwitchId> actualEndpointSwitchIds = flow.getSubFlows().stream().map(YSubFlow::getEndpointSwitchId).collect(Collectors.toSet());
    assertEquals(expectedEndpointSwitchIds, actualEndpointSwitchIds);
}
Also used : YFlow(org.openkilda.model.YFlow) CommandContext(org.openkilda.wfm.CommandContext) SwitchId(org.openkilda.model.SwitchId) YFlowRequest(org.openkilda.messaging.command.yflow.YFlowRequest) Test(org.junit.Test) AbstractYFlowTest(org.openkilda.wfm.topology.flowhs.service.AbstractYFlowTest)

Aggregations

YFlowRequest (org.openkilda.messaging.command.yflow.YFlowRequest)50 Test (org.junit.Test)35 AbstractYFlowTest (org.openkilda.wfm.topology.flowhs.service.AbstractYFlowTest)27 YFlow (org.openkilda.model.YFlow)12 YFlowRerouteRequest (org.openkilda.messaging.command.yflow.YFlowRerouteRequest)11 CommandContext (org.openkilda.wfm.CommandContext)10 SwitchId (org.openkilda.model.SwitchId)9 SubFlowSharedEndpointEncapsulation (org.openkilda.messaging.command.yflow.SubFlowSharedEndpointEncapsulation)8 UnroutableFlowException (org.openkilda.pce.exception.UnroutableFlowException)7 RerouteError (org.openkilda.messaging.info.reroute.error.RerouteError)5 FlowProcessingException (org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException)5 ResourceAllocationException (org.openkilda.wfm.share.flow.resources.ResourceAllocationException)4 Ignore (org.junit.Ignore)3 CommandMessage (org.openkilda.messaging.command.CommandMessage)3 YFlowResponse (org.openkilda.messaging.command.yflow.YFlowResponse)3 FlowEndpoint (org.openkilda.model.FlowEndpoint)3 FlowStatus (org.openkilda.model.FlowStatus)3 IslEndpoint (org.openkilda.model.IslEndpoint)3 DuplicateKeyException (org.openkilda.wfm.topology.flowhs.exception.DuplicateKeyException)3 YFlowPartialUpdateRequest (org.openkilda.messaging.command.yflow.YFlowPartialUpdateRequest)2