Search in sources :

Example 1 with SubFlowSharedEndpointEncapsulation

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

the class OnSubFlowAllocatedAction method performWithResponse.

@Override
protected Optional<Message> performWithResponse(State from, State to, Event event, YFlowUpdateContext context, YFlowUpdateFsm stateMachine) {
    String subFlowId = context.getSubFlowId();
    if (!stateMachine.isUpdatingSubFlow(subFlowId)) {
        throw new IllegalStateException("Received an event for non-pending sub-flow " + subFlowId);
    }
    String yFlowId = stateMachine.getYFlowId();
    stateMachine.saveActionToHistory("Updating a sub-flow", format("Allocated resources for sub-flow %s of y-flow %s", subFlowId, yFlowId));
    stateMachine.addAllocatedSubFlow(subFlowId);
    SubFlowDto subFlowDto = stateMachine.getTargetFlow().getSubFlows().stream().filter(f -> f.getFlowId().equals(subFlowId)).findAny().orElseThrow(() -> new FlowProcessingException(ErrorType.INTERNAL_ERROR, format("Can't find definition of updated sub-flow %s", subFlowId)));
    SubFlowSharedEndpointEncapsulation sharedEndpoint = subFlowDto.getSharedEndpoint();
    FlowEndpoint endpoint = subFlowDto.getEndpoint();
    log.debug("Start updating sub-flow references from {} to y-flow {}", subFlowId, stateMachine.getYFlowId());
    YFlow result = transactionManager.doInTransaction(() -> {
        YFlow yFlow = yFlowRepository.findById(yFlowId).orElseThrow(() -> new FlowProcessingException(ErrorType.INTERNAL_ERROR, format("Y-flow %s not found", yFlowId)));
        Flow flow = flowRepository.findById(subFlowId).orElseThrow(() -> new FlowProcessingException(ErrorType.INTERNAL_ERROR, format("Flow %s not found", subFlowId)));
        YSubFlow subFlow = YSubFlow.builder().yFlow(yFlow).flow(flow).sharedEndpointVlan(sharedEndpoint.getVlanId()).sharedEndpointInnerVlan(sharedEndpoint.getInnerVlanId()).endpointSwitchId(endpoint.getSwitchId()).endpointPort(endpoint.getPortNumber()).endpointVlan(endpoint.getOuterVlanId()).endpointInnerVlan(endpoint.getInnerVlanId()).build();
        yFlow.updateSubFlow(subFlow);
        return yFlow;
    });
    if (stateMachine.getAllocatedSubFlows().size() == stateMachine.getSubFlows().size()) {
        return Optional.of(buildResponseMessage(result, stateMachine.getCommandContext()));
    } else {
        return Optional.empty();
    }
}
Also used : YFlow(org.openkilda.model.YFlow) FlowEndpoint(org.openkilda.model.FlowEndpoint) FlowProcessingException(org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException) SubFlowSharedEndpointEncapsulation(org.openkilda.messaging.command.yflow.SubFlowSharedEndpointEncapsulation) SubFlowDto(org.openkilda.messaging.command.yflow.SubFlowDto) YSubFlow(org.openkilda.model.YSubFlow) Flow(org.openkilda.model.Flow) YFlow(org.openkilda.model.YFlow) YSubFlow(org.openkilda.model.YSubFlow)

Example 2 with SubFlowSharedEndpointEncapsulation

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

the class OnRevertSubFlowAllocatedAction method perform.

@Override
protected void perform(State from, State to, Event event, YFlowUpdateContext context, YFlowUpdateFsm stateMachine) {
    String subFlowId = context.getSubFlowId();
    if (!stateMachine.isUpdatingSubFlow(subFlowId)) {
        throw new IllegalStateException("Received an event for non-pending sub-flow " + subFlowId);
    }
    String yFlowId = stateMachine.getYFlowId();
    stateMachine.saveActionToHistory("Reverting a sub-flow", format("Allocated resources for sub-flow %s of y-flow %s", subFlowId, yFlowId));
    stateMachine.addAllocatedSubFlow(subFlowId);
    SubFlowDto subFlowDto = stateMachine.getOriginalFlow().getSubFlows().stream().filter(f -> f.getFlowId().equals(subFlowId)).findAny().orElseThrow(() -> new FlowProcessingException(ErrorType.INTERNAL_ERROR, format("Can't find definition of updated sub-flow %s", subFlowId)));
    SubFlowSharedEndpointEncapsulation sharedEndpoint = subFlowDto.getSharedEndpoint();
    FlowEndpoint endpoint = subFlowDto.getEndpoint();
    log.debug("Start updating sub-flow references from {} to y-flow {}", subFlowId, stateMachine.getYFlowId());
    transactionManager.doInTransaction(() -> {
        YFlow yFlow = yFlowRepository.findById(yFlowId).orElseThrow(() -> new FlowProcessingException(ErrorType.INTERNAL_ERROR, format("Y-flow %s not found", yFlowId)));
        Flow flow = flowRepository.findById(subFlowId).orElseThrow(() -> new FlowProcessingException(ErrorType.INTERNAL_ERROR, format("Flow %s not found", subFlowId)));
        YSubFlow subFlow = YSubFlow.builder().yFlow(yFlow).flow(flow).sharedEndpointVlan(sharedEndpoint.getVlanId()).sharedEndpointInnerVlan(sharedEndpoint.getInnerVlanId()).endpointSwitchId(endpoint.getSwitchId()).endpointPort(endpoint.getPortNumber()).endpointVlan(endpoint.getOuterVlanId()).endpointInnerVlan(endpoint.getInnerVlanId()).build();
        yFlow.updateSubFlow(subFlow);
        return yFlow;
    });
}
Also used : YFlow(org.openkilda.model.YFlow) FlowEndpoint(org.openkilda.model.FlowEndpoint) FlowProcessingException(org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException) SubFlowSharedEndpointEncapsulation(org.openkilda.messaging.command.yflow.SubFlowSharedEndpointEncapsulation) SubFlowDto(org.openkilda.messaging.command.yflow.SubFlowDto) YSubFlow(org.openkilda.model.YSubFlow) YSubFlow(org.openkilda.model.YSubFlow) Flow(org.openkilda.model.Flow) YFlow(org.openkilda.model.YFlow)

Example 3 with SubFlowSharedEndpointEncapsulation

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

the class YFlowMapper method toSubFlowDto.

/**
 * Map {@link YSubFlow} to {@link SubFlowDto}.
 */
public SubFlowDto toSubFlowDto(YSubFlow subFlow) {
    SubFlowSharedEndpointEncapsulation sharedEndpoint = SubFlowSharedEndpointEncapsulation.builder().vlanId(subFlow.getSharedEndpointVlan()).innerVlanId(subFlow.getSharedEndpointInnerVlan()).build();
    FlowEndpoint endpoint = FlowEndpoint.builder().switchId(subFlow.getEndpointSwitchId()).portNumber(subFlow.getEndpointPort()).outerVlanId(subFlow.getEndpointVlan()).innerVlanId(subFlow.getEndpointInnerVlan()).build();
    Optional<Flow> flow = Optional.ofNullable(subFlow.getFlow());
    return SubFlowDto.builder().flowId(subFlow.getSubFlowId()).endpoint(endpoint).sharedEndpoint(sharedEndpoint).status(flow.map(Flow::getStatus).orElse(null)).description(flow.map(Flow::getDescription).orElse(null)).timeCreate(flow.map(Flow::getTimeCreate).orElse(null)).timeUpdate(flow.map(Flow::getTimeModify).orElse(null)).build();
}
Also used : FlowEndpoint(org.openkilda.model.FlowEndpoint) SubFlowSharedEndpointEncapsulation(org.openkilda.messaging.command.yflow.SubFlowSharedEndpointEncapsulation) YSubFlow(org.openkilda.model.YSubFlow) Flow(org.openkilda.model.Flow) YFlow(org.openkilda.model.YFlow)

Example 4 with SubFlowSharedEndpointEncapsulation

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

the class YFlowValidatorTest method failIfOneSwitchFlowRequestedAsTheLast.

@Test(expected = InvalidFlowException.class)
public void failIfOneSwitchFlowRequestedAsTheLast() throws InvalidFlowException, UnavailableFlowEndpointException {
    YFlowRequest request = YFlowRequest.builder().yFlowId("test").sharedEndpoint(FlowEndpoint.builder().switchId(SWITCH_ID_1).portNumber(PORT_1).build()).subFlows(Arrays.asList(SubFlowDto.builder().flowId("test_1").sharedEndpoint(new SubFlowSharedEndpointEncapsulation(1, 0)).endpoint(FlowEndpoint.builder().switchId(SWITCH_ID_2).portNumber(PORT_2).build()).build(), SubFlowDto.builder().flowId("test_2").sharedEndpoint(new SubFlowSharedEndpointEncapsulation(2, 0)).endpoint(FlowEndpoint.builder().switchId(SWITCH_ID_1).portNumber(PORT_3).build()).build())).build();
    yFlowValidator.validate(request);
}
Also used : SubFlowSharedEndpointEncapsulation(org.openkilda.messaging.command.yflow.SubFlowSharedEndpointEncapsulation) YFlowRequest(org.openkilda.messaging.command.yflow.YFlowRequest) Test(org.junit.Test)

Example 5 with SubFlowSharedEndpointEncapsulation

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

the class YFlowValidatorTest method failIfSubFlowHasNoSharedEndpointProvided.

@Test(expected = InvalidFlowException.class)
public void failIfSubFlowHasNoSharedEndpointProvided() throws InvalidFlowException, UnavailableFlowEndpointException {
    YFlowRequest request = YFlowRequest.builder().yFlowId("test").sharedEndpoint(FlowEndpoint.builder().switchId(SWITCH_ID_1).portNumber(PORT_1).build()).subFlows(Arrays.asList(SubFlowDto.builder().flowId("test_1").endpoint(FlowEndpoint.builder().switchId(SWITCH_ID_2).portNumber(PORT_2).build()).build(), SubFlowDto.builder().flowId("test_2").sharedEndpoint(new SubFlowSharedEndpointEncapsulation(2, 0)).endpoint(FlowEndpoint.builder().switchId(SWITCH_ID_3).portNumber(PORT_3).build()).build())).build();
    yFlowValidator.validate(request);
}
Also used : SubFlowSharedEndpointEncapsulation(org.openkilda.messaging.command.yflow.SubFlowSharedEndpointEncapsulation) YFlowRequest(org.openkilda.messaging.command.yflow.YFlowRequest) Test(org.junit.Test)

Aggregations

SubFlowSharedEndpointEncapsulation (org.openkilda.messaging.command.yflow.SubFlowSharedEndpointEncapsulation)12 YFlowRequest (org.openkilda.messaging.command.yflow.YFlowRequest)8 Test (org.junit.Test)7 FlowEndpoint (org.openkilda.model.FlowEndpoint)5 YFlow (org.openkilda.model.YFlow)5 SubFlowDto (org.openkilda.messaging.command.yflow.SubFlowDto)4 Flow (org.openkilda.model.Flow)4 YSubFlow (org.openkilda.model.YSubFlow)4 FlowProcessingException (org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException)4 ArrayList (java.util.ArrayList)1 SubFlowPartialUpdateDto (org.openkilda.messaging.command.yflow.SubFlowPartialUpdateDto)1 SwitchId (org.openkilda.model.SwitchId)1 CommandContext (org.openkilda.wfm.CommandContext)1