use of org.openkilda.wfm.CommandContext in project open-kilda by telstra.
the class EmitCommandRequestsAction method buildCommands.
private Collection<FlowSegmentRequestFactory> buildCommands(FlowCommandBuilder commandBuilder, FlowMirrorPointDeleteFsm stateMachine, Flow flow, FlowMirrorPoints mirrorPoints) {
FlowPath path = mirrorPoints.getFlowPath();
FlowPath oppositePath = path.isForward() ? flow.getReversePath() : flow.getForwardPath();
CommandContext context = stateMachine.getCommandContext();
SpeakerRequestBuildContext speakerContext = buildBaseSpeakerContextForInstall(path.getSrcSwitchId(), path.getDestSwitchId());
if (mirrorPoints.getMirrorSwitchId().equals(path.getSrcSwitchId())) {
return new ArrayList<>(commandBuilder.buildIngressOnlyOneDirection(context, flow, path, oppositePath, speakerContext.getForward(), MirrorContext.builder().buildMirrorFactoryOnly(true).build()));
} else if (mirrorPoints.getMirrorSwitchId().equals(path.getDestSwitchId())) {
return new ArrayList<>(commandBuilder.buildEgressOnlyOneDirection(context, flow, path, oppositePath, MirrorContext.builder().buildMirrorFactoryOnly(true).build()));
}
return Collections.emptyList();
}
use of org.openkilda.wfm.CommandContext in project open-kilda by telstra.
the class ValidateRequestAction method performWithResponse.
@Override
protected Optional<Message> performWithResponse(State from, State to, Event event, FlowMirrorPointDeleteContext context, FlowMirrorPointDeleteFsm stateMachine) {
String flowId = stateMachine.getFlowId();
PathId mirrorPathId = new PathId(context.getFlowMirrorPointId());
stateMachine.setMirrorPathId(mirrorPathId);
dashboardLogger.onFlowMirrorPointDelete(flowId, context.getFlowMirrorPointId());
FlowMirrorPointResponse response = transactionManager.doInTransaction(() -> {
Flow foundFlow = getFlow(flowId);
if (foundFlow.getStatus() == FlowStatus.IN_PROGRESS) {
throw new FlowProcessingException(ErrorType.REQUEST_INVALID, format("Flow %s is in progress now", flowId));
}
stateMachine.setFlowStatus(foundFlow.getStatus());
flowRepository.updateStatus(flowId, FlowStatus.IN_PROGRESS);
FlowMirrorPath flowMirrorPath = flowMirrorPathRepository.findById(mirrorPathId).orElseThrow(() -> new FlowProcessingException(ErrorType.NOT_FOUND, format("Flow mirror point %s not found", mirrorPathId)));
if (flowMirrorPath.getStatus() == FlowPathStatus.IN_PROGRESS) {
throw new FlowProcessingException(ErrorType.REQUEST_INVALID, format("Flow mirror point %s is in progress now", mirrorPathId));
}
stateMachine.setOriginalFlowMirrorPathStatus(flowMirrorPath.getStatus());
flowMirrorPathRepository.updateStatus(mirrorPathId, FlowPathStatus.IN_PROGRESS);
String direction = flowMirrorPath.getFlowMirrorPoints().getFlowPath().isForward() ? "forward" : "reverse";
return FlowMirrorPointResponse.builder().flowId(foundFlow.getFlowId()).mirrorPointId(flowMirrorPath.getPathId().getId()).mirrorPointDirection(direction).mirrorPointSwitchId(flowMirrorPath.getMirrorSwitchId()).sinkEndpoint(FlowEndpoint.builder().switchId(flowMirrorPath.getEgressSwitchId()).portNumber(flowMirrorPath.getEgressPort()).innerVlanId(flowMirrorPath.getEgressInnerVlan()).outerVlanId(flowMirrorPath.getEgressOuterVlan()).build()).build();
});
stateMachine.saveNewEventToHistory("Flow was validated successfully", FlowEventData.Event.FLOW_MIRROR_POINT_DELETE);
CommandContext commandContext = stateMachine.getCommandContext();
return Optional.of(new InfoMessage(response, commandContext.getCreateTime(), commandContext.getCorrelationId()));
}
use of org.openkilda.wfm.CommandContext in project open-kilda by telstra.
the class CreateSubFlowsAction method perform.
@Override
public void perform(State from, State to, Event event, YFlowCreateContext context, YFlowCreateFsm stateMachine) {
String yFlowId = stateMachine.getYFlowId();
Collection<RequestedFlow> requestedFlows = YFlowRequestMapper.INSTANCE.toRequestedFlows(stateMachine.getTargetFlow());
stateMachine.setRequestedFlows(requestedFlows);
log.debug("Start creating {} sub-flows for y-flow {}", requestedFlows.size(), yFlowId);
stateMachine.clearCreatingSubFlows();
requestedFlows.stream().findFirst().ifPresent(requestedFlow -> {
String subFlowId = requestedFlow.getFlowId();
stateMachine.setMainAffinityFlowId(subFlowId);
stateMachine.addSubFlow(subFlowId);
stateMachine.addCreatingSubFlow(subFlowId);
stateMachine.notifyEventListeners(listener -> listener.onSubFlowProcessingStart(yFlowId, subFlowId));
CommandContext flowContext = stateMachine.getCommandContext().fork(subFlowId);
requestedFlow.setDiverseFlowId(stateMachine.getDiverseFlowId());
flowCreateService.startFlowCreation(flowContext, requestedFlow, yFlowId);
});
}
use of org.openkilda.wfm.CommandContext in project open-kilda by telstra.
the class OnFinishedWithErrorAction method performWithResponse.
@Override
protected Optional<Message> performWithResponse(State from, State to, Event event, FlowSwapEndpointsContext context, FlowSwapEndpointsFsm stateMachine) {
ErrorData data;
if (Event.TIMEOUT.equals(event)) {
data = new ErrorData(ErrorType.OPERATION_TIMED_OUT, getGenericErrorMessage(), "Flow swap endpoints failed by timeout");
} else if (Event.NEXT.equals(event)) {
List<String> flows = stateMachine.getFlowResponses().stream().map(FlowResponse::getPayload).map(FlowDto::getFlowId).collect(Collectors.toList());
data = new ErrorData(ErrorType.UPDATE_FAILURE, getGenericErrorMessage(), format("Reverted flows: %s", flows));
} else {
data = (ErrorData) context.getResponse();
}
if (!Event.VALIDATION_ERROR.equals(event)) {
saveActionToHistory(stateMachine, stateMachine.getFirstFlowId(), stateMachine.getSecondFlowId(), data.getErrorDescription());
saveActionToHistory(stateMachine, stateMachine.getSecondFlowId(), stateMachine.getFirstFlowId(), data.getErrorDescription());
}
updateFlowsStatuses(stateMachine);
CommandContext commandContext = stateMachine.getCommandContext();
return Optional.of(new ErrorMessage(data, commandContext.getCreateTime(), commandContext.getCorrelationId()));
}
use of org.openkilda.wfm.CommandContext in project open-kilda by telstra.
the class OnSubFlowAllocatedAction method buildRerouteResponseMessage.
private Message buildRerouteResponseMessage(YFlowRerouteFsm stateMachine) {
String yFlowId = stateMachine.getYFlowId();
List<Long> oldFlowPathCookies = stateMachine.getOldYFlowPathCookies();
List<FlowPath> flowPaths = transactionManager.doInTransaction(() -> {
YFlow yflow = yFlowRepository.findById(yFlowId).orElseThrow(() -> new FlowProcessingException(ErrorType.NOT_FOUND, format("Y-flow %s not found", yFlowId)));
SwitchId sharedSwitchId = yflow.getSharedEndpoint().getSwitchId();
List<FlowPath> paths = new ArrayList<>();
for (YSubFlow subFlow : yflow.getSubFlows()) {
Flow flow = subFlow.getFlow();
FlowPath flowPath = flow.getPaths().stream().filter(path -> sharedSwitchId.equals(path.getSrcSwitchId()) && !path.isProtected() && !oldFlowPathCookies.contains(path.getCookie().getValue())).findFirst().orElse(sharedSwitchId.equals(flow.getForwardPath().getSrcSwitchId()) ? flow.getForwardPath() : flow.getReversePath());
paths.add(flowPath);
}
return paths;
});
List<PathSegment> sharedPathSegments = IntersectionComputer.calculatePathIntersectionFromSource(flowPaths);
PathInfoData sharedPath = FlowPathMapper.INSTANCE.map(sharedPathSegments);
List<SubFlowPathDto> subFlowPathDtos = flowPaths.stream().map(flowPath -> new SubFlowPathDto(flowPath.getFlowId(), FlowPathMapper.INSTANCE.map(flowPath))).sorted(Comparator.comparing(SubFlowPathDto::getFlowId)).collect(Collectors.toList());
PathInfoData oldSharedPath = stateMachine.getOldSharedPath();
List<SubFlowPathDto> oldSubFlowPathDtos = stateMachine.getOldSubFlowPathDtos();
YFlowRerouteResponse response = new YFlowRerouteResponse(sharedPath, subFlowPathDtos, !(sharedPath.equals(oldSharedPath) && subFlowPathDtos.equals(oldSubFlowPathDtos)));
CommandContext commandContext = stateMachine.getCommandContext();
return new InfoMessage(response, commandContext.getCreateTime(), commandContext.getCorrelationId());
}
Aggregations