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