use of org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException 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.wfm.topology.flowhs.exception.FlowProcessingException 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.wfm.topology.flowhs.exception.FlowProcessingException 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();
}
use of org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException in project open-kilda by telstra.
the class ValidateYFlowAction method performWithResponse.
@Override
protected Optional<Message> performWithResponse(State from, State to, Event event, YFlowUpdateContext context, YFlowUpdateFsm stateMachine) {
YFlowRequest targetFlow = context.getTargetFlow();
boolean isOperationAllowed = featureTogglesRepository.getOrDefault().getModifyYFlowEnabled();
if (!isOperationAllowed) {
throw new FlowProcessingException(ErrorType.NOT_PERMITTED, "Y-flow create feature is disabled");
}
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);
}
String yFlowId = targetFlow.getYFlowId();
YFlow yFlow = transactionManager.doInTransaction(() -> {
YFlow result = yFlowRepository.findById(yFlowId).orElseThrow(() -> new FlowProcessingException(ErrorType.NOT_FOUND, format("Y-flow %s not found", yFlowId)));
if (result.getStatus() == FlowStatus.IN_PROGRESS) {
throw new FlowProcessingException(ErrorType.REQUEST_INVALID, format("Y-flow %s is in progress now", yFlowId));
}
// Keep it, just in case we have to revert it.
stateMachine.setOriginalYFlowStatus(result.getStatus());
result.setStatus(FlowStatus.IN_PROGRESS);
return result;
});
Set<String> requestedSubFlowIds = targetFlow.getSubFlows().stream().map(SubFlowDto::getFlowId).collect(Collectors.toSet());
Set<String> originalSubFlowIds = yFlow.getSubFlows().stream().map(YSubFlow::getSubFlowId).collect(Collectors.toSet());
if (!requestedSubFlowIds.equals(originalSubFlowIds)) {
throw new FlowProcessingException(ErrorType.PARAMETERS_INVALID, format("Unable to map provided sub-flows set onto existing y-flow %s", yFlowId));
}
YSubFlow subFlow = yFlow.getSubFlows().stream().findAny().orElseThrow(() -> new FlowProcessingException(ErrorType.DATA_INVALID, format("No sub-flows of the y-flow %s were found", yFlowId)));
stateMachine.setMainAffinityFlowId(subFlow.getFlow().getAffinityGroupId());
List<FlowEndpoint> subFlowEndpoints = targetFlow.getSubFlows().stream().map(SubFlowDto::getEndpoint).collect(Collectors.toList());
dashboardLogger.onYFlowUpdate(yFlowId, targetFlow.getSharedEndpoint(), subFlowEndpoints, targetFlow.getMaximumBandwidth());
stateMachine.setTargetFlow(targetFlow);
stateMachine.saveNewEventToHistory("Y-flow was validated successfully", FlowEventData.Event.UPDATE);
return Optional.empty();
}
use of org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException in project open-kilda by telstra.
the class DumpYFlowResourcesAction 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)));
log.debug("Start validating y-flow {} resources", yFlowId);
List<SwitchId> switchIds = Stream.of(yFlow.getSharedEndpoint().getSwitchId(), yFlow.getYPoint(), yFlow.getProtectedPathYPoint()).filter(Objects::nonNull).collect(Collectors.toList());
int switchCount = switchIds.size();
stateMachine.setAwaitingRules(switchCount);
stateMachine.setAwaitingMeters(switchCount);
log.debug("Send commands to get rules & meters on {} switches", switchCount);
YFlowValidationHubCarrier carrier = stateMachine.getCarrier();
switchIds.forEach(switchId -> {
carrier.sendSpeakerRequest(yFlowId, new DumpRulesForFlowHsRequest(switchId));
carrier.sendSpeakerRequest(yFlowId, new DumpMetersForFlowHsRequest(switchId));
});
}
Aggregations