use of org.openkilda.wfm.topology.flowhs.model.RequestedFlowMirrorPoint in project open-kilda by telstra.
the class EmitUpdateRulesRequestsAction method buildCommands.
private Collection<FlowSegmentRequestFactory> buildCommands(FlowMirrorPointCreateFsm stateMachine, Flow flow) {
final FlowCommandBuilder commandBuilder = commandBuilderFactory.getBuilder(flow.getEncapsulationType());
PathId flowPathId = stateMachine.getFlowPathId();
FlowPath path = flow.getPath(flowPathId).orElseThrow(() -> new FlowProcessingException(ErrorType.NOT_FOUND, format("Flow path %s not found", flowPathId)));
PathId oppositePathId = flow.getOppositePathId(flowPathId).orElseThrow(() -> new FlowProcessingException(ErrorType.NOT_FOUND, format("Opposite flow path id for path %s not found", flowPathId)));
FlowPath oppositePath = flow.getPath(oppositePathId).orElse(null);
RequestedFlowMirrorPoint mirrorPoint = stateMachine.getRequestedFlowMirrorPoint();
CommandContext context = stateMachine.getCommandContext();
SpeakerRequestBuildContext speakerContext = buildBaseSpeakerContextForInstall(path.getSrcSwitchId(), path.getDestSwitchId());
if (mirrorPoint.getMirrorPointSwitchId().equals(path.getSrcSwitchId())) {
return new ArrayList<>(commandBuilder.buildIngressOnlyOneDirection(context, flow, path, oppositePath, speakerContext.getForward(), MirrorContext.builder().buildMirrorFactoryOnly(true).addNewGroup(stateMachine.isAddNewGroup()).build()));
} else if (mirrorPoint.getMirrorPointSwitchId().equals(path.getDestSwitchId())) {
return new ArrayList<>(commandBuilder.buildEgressOnlyOneDirection(context, flow, path, oppositePath, MirrorContext.builder().buildMirrorFactoryOnly(true).addNewGroup(stateMachine.isAddNewGroup()).build()));
}
return Collections.emptyList();
}
use of org.openkilda.wfm.topology.flowhs.model.RequestedFlowMirrorPoint in project open-kilda by telstra.
the class OnFinishedAction method perform.
@Override
public void perform(State from, State to, Event event, FlowMirrorPointCreateContext context, FlowMirrorPointCreateFsm stateMachine) {
if (stateMachine.getFlowStatus() != null) {
flowRepository.updateStatus(stateMachine.getFlowId(), stateMachine.getFlowStatus());
}
RequestedFlowMirrorPoint mirrorPoint = stateMachine.getRequestedFlowMirrorPoint();
dashboardLogger.onSuccessfulFlowMirrorPointCreate(stateMachine.getFlowId(), mirrorPoint.getMirrorPointSwitchId(), mirrorPoint.getMirrorPointDirection().toString(), mirrorPoint.getSinkEndpoint().getSwitchId(), mirrorPoint.getSinkEndpoint().getPortNumber(), mirrorPoint.getSinkEndpoint().getOuterVlanId());
stateMachine.saveActionToHistory("Flow mirror point was created successfully");
}
use of org.openkilda.wfm.topology.flowhs.model.RequestedFlowMirrorPoint in project open-kilda by telstra.
the class ValidateRequestAction method performWithResponse.
@Override
protected Optional<Message> performWithResponse(State from, State to, Event event, FlowMirrorPointCreateContext context, FlowMirrorPointCreateFsm stateMachine) {
String flowId = stateMachine.getFlowId();
RequestedFlowMirrorPoint mirrorPoint = context.getMirrorPoint();
PathId mirrorPathId = new PathId(mirrorPoint.getMirrorPointId());
stateMachine.setMirrorPathId(mirrorPathId);
stateMachine.setMirrorSwitchId(mirrorPoint.getMirrorPointSwitchId());
dashboardLogger.onFlowMirrorPointCreate(flowId, mirrorPoint.getMirrorPointSwitchId(), mirrorPoint.getMirrorPointDirection().toString(), mirrorPoint.getSinkEndpoint().getSwitchId(), mirrorPoint.getSinkEndpoint().getPortNumber(), mirrorPoint.getSinkEndpoint().getOuterVlanId());
stateMachine.setRequestedFlowMirrorPoint(mirrorPoint);
Flow flow = 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);
return foundFlow;
});
if (!mirrorPoint.getMirrorPointSwitchId().equals(mirrorPoint.getSinkEndpoint().getSwitchId())) {
throw new FlowProcessingException(ErrorType.REQUEST_INVALID, format("Invalid sink endpoint switch id: %s. In the current implementation, " + "the sink switch id cannot differ from the mirror point switch id.", mirrorPoint.getSinkEndpoint().getSwitchId()));
}
if (!mirrorPoint.getMirrorPointSwitchId().equals(flow.getSrcSwitchId()) && !mirrorPoint.getMirrorPointSwitchId().equals(flow.getDestSwitchId())) {
throw new FlowProcessingException(ErrorType.REQUEST_INVALID, format("Invalid mirror point switch id: %s", mirrorPoint.getMirrorPointSwitchId()));
}
if (flowMirrorPathRepository.exists(mirrorPathId)) {
throw new FlowProcessingException(ErrorType.ALREADY_EXISTS, format("Flow mirror point %s already exists", mirrorPathId));
}
Optional<PhysicalPort> physicalPort = physicalPortRepository.findBySwitchIdAndPortNumber(mirrorPoint.getSinkEndpoint().getSwitchId(), mirrorPoint.getSinkEndpoint().getPortNumber());
if (physicalPort.isPresent()) {
throw new FlowProcessingException(ErrorType.REQUEST_INVALID, format("Invalid sink port %d on switch %s. This port is part of LAG %d. Please delete LAG port " + "or choose another sink port.", mirrorPoint.getSinkEndpoint().getPortNumber(), mirrorPoint.getSinkEndpoint().getSwitchId(), physicalPort.get().getLagLogicalPort().getLogicalPortNumber()));
}
try {
flowValidator.flowMirrorPointValidate(mirrorPoint);
} catch (InvalidFlowException e) {
throw new FlowProcessingException(e.getType(), e.getMessage(), e);
} catch (UnavailableFlowEndpointException e) {
throw new FlowProcessingException(ErrorType.DATA_INVALID, e.getMessage(), e);
}
stateMachine.saveNewEventToHistory("Flow was validated successfully", FlowEventData.Event.FLOW_MIRROR_POINT_CREATE);
return Optional.empty();
}
use of org.openkilda.wfm.topology.flowhs.model.RequestedFlowMirrorPoint in project open-kilda by telstra.
the class PostFlowMirrorPathDeallocationAction method perform.
@Override
protected void perform(State from, State to, Event event, FlowMirrorPointCreateContext context, FlowMirrorPointCreateFsm stateMachine) {
RequestedFlowMirrorPoint mirrorPoint = stateMachine.getRequestedFlowMirrorPoint();
PathId flowPathId = transactionManager.doInTransaction(() -> {
Flow flow = getFlow(mirrorPoint.getFlowId());
FlowPath flowPath = getFlowPath(mirrorPoint, flow);
FlowMirrorPoints flowMirrorPoints = flowMirrorPointsRepository.findByPathIdAndSwitchId(flowPath.getPathId(), mirrorPoint.getMirrorPointSwitchId()).orElse(null);
if (flowMirrorPoints != null && flowMirrorPoints.getMirrorPaths().isEmpty()) {
flowMirrorPointsRepository.remove(flowMirrorPoints);
resourcesManager.deallocateMirrorGroup(flowPath.getPathId(), mirrorPoint.getMirrorPointSwitchId());
return flowPath.getPathId();
}
return null;
});
if (flowPathId != null) {
stateMachine.saveActionToHistory("Flow mirror group was deallocated", format("The flow mirror group for flow path %s and switch id %s was deallocated", flowPathId, mirrorPoint.getMirrorPointSwitchId()));
}
}
use of org.openkilda.wfm.topology.flowhs.model.RequestedFlowMirrorPoint in project open-kilda by telstra.
the class OnFinishedWithErrorAction method perform.
@Override
public void perform(State from, State to, Event event, FlowMirrorPointCreateContext context, FlowMirrorPointCreateFsm stateMachine) {
if (stateMachine.getFlowStatus() != null) {
flowRepository.updateStatus(stateMachine.getFlowId(), stateMachine.getFlowStatus());
}
RequestedFlowMirrorPoint mirrorPoint = stateMachine.getRequestedFlowMirrorPoint();
dashboardLogger.onFailedFlowMirrorPointCreate(stateMachine.getFlowId(), mirrorPoint.getMirrorPointSwitchId(), mirrorPoint.getMirrorPointDirection().toString(), mirrorPoint.getSinkEndpoint().getSwitchId(), mirrorPoint.getSinkEndpoint().getPortNumber(), mirrorPoint.getSinkEndpoint().getOuterVlanId(), stateMachine.getErrorReason());
stateMachine.saveActionToHistory("Failed to create the flow mirror point", stateMachine.getErrorReason());
}
Aggregations