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();
}
}
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;
});
}
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();
}
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);
}
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);
}
Aggregations