use of org.openkilda.model.YFlow in project open-kilda by telstra.
the class RemoveSubFlowsAction method perform.
@Override
public void perform(State from, State to, Event event, YFlowDeleteContext context, YFlowDeleteFsm stateMachine) {
String yFlowId = stateMachine.getYFlowId();
YFlow yFlow = getYFlow(yFlowId);
log.debug("Start removing 1 of {} sub-flows of y-flow {}", yFlow.getSubFlows().size(), yFlowId);
stateMachine.clearDeletingSubFlows();
// TODO: refactor to concurrent deleting once https://github.com/telstra/open-kilda/issues/3411 is fixed.
yFlow.getSubFlows().stream().findFirst().ifPresent(subFlow -> {
String subFlowId = subFlow.getSubFlowId();
stateMachine.addSubFlow(subFlowId);
stateMachine.addDeletingSubFlow(subFlowId);
stateMachine.notifyEventListeners(listener -> listener.onSubFlowProcessingStart(yFlowId, subFlowId));
CommandContext flowContext = stateMachine.getCommandContext().fork(subFlowId);
flowDeleteService.startFlowDeletion(flowContext, subFlowId);
});
}
use of org.openkilda.model.YFlow in project open-kilda by telstra.
the class YFlowReadService method convertToYFlowDto.
private YFlowDto convertToYFlowDto(YFlow yFlow) {
Flow mainAffinityFlow = yFlow.getSubFlows().stream().map(YSubFlow::getFlow).filter(flow -> flow.getFlowId().equals(flow.getAffinityGroupId())).findFirst().orElseThrow(() -> new FlowProcessingException(ErrorType.INTERNAL_ERROR, "Main affinity flow not found"));
Collection<Flow> diverseWithFlow = getDiverseWithFlow(mainAffinityFlow);
Set<String> diverseFlows = diverseWithFlow.stream().filter(flow -> flow.getYFlowId() == null).map(Flow::getFlowId).collect(Collectors.toSet());
Set<String> diverseYFlows = diverseWithFlow.stream().map(Flow::getYFlowId).filter(Objects::nonNull).collect(Collectors.toSet());
return YFlowMapper.INSTANCE.toYFlowDto(yFlow, diverseFlows, diverseYFlows);
}
use of org.openkilda.model.YFlow 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.model.YFlow in project open-kilda by telstra.
the class ValidateSubFlowsAction method perform.
@Override
protected void perform(State from, State to, Event event, YFlowValidationContext context, YFlowValidationFsm stateMachine) {
String yFlowId = stateMachine.getYFlowId();
YFlow yFlow = yFlowRepository.findById(yFlowId).orElseThrow(() -> new FlowProcessingException(ErrorType.NOT_FOUND, format("Y-flow %s not found", yFlowId)));
if (yFlow.getStatus() == FlowStatus.DOWN) {
throw new FlowProcessingException(ErrorType.UNPROCESSABLE_REQUEST, format("Could not validate y-flow: y-flow %s in in DOWN state", yFlowId));
}
log.debug("Start validating {} sub-flows of y-flow {}", yFlow.getSubFlows().size(), yFlowId);
stateMachine.clearValidatingSubFlows();
yFlow.getSubFlows().forEach(subFlow -> {
String subFlowId = subFlow.getSubFlowId();
stateMachine.addSubFlow(subFlowId);
stateMachine.addValidatingSubFlow(subFlowId);
stateMachine.notifyEventListeners(listener -> listener.onSubFlowProcessingStart(yFlowId, subFlowId));
CommandContext flowContext = stateMachine.getCommandContext().fork(subFlowId);
flowValidationHubService.startFlowValidation(flowContext, subFlowId);
});
}
use of org.openkilda.model.YFlow in project open-kilda by telstra.
the class PreValidateYFlowAction method performWithResponse.
@Override
public Optional<Message> performWithResponse(State from, State to, Event event, YFlowValidationContext context, YFlowValidationFsm stateMachine) {
String yFlowId = stateMachine.getYFlowId();
YFlow yFlow = yFlowRepository.findById(yFlowId).orElseThrow(() -> new FlowProcessingException(ErrorType.NOT_FOUND, format("Y-flow %s not found", yFlowId)));
if (yFlow.getStatus() == FlowStatus.IN_PROGRESS || yFlow.getStatus() == FlowStatus.DOWN) {
throw new FlowProcessingException(ErrorType.REQUEST_INVALID, format("Y-flow %s is in progress or down now", yFlowId));
}
return Optional.empty();
}
Aggregations