use of org.openkilda.wfm.topology.flowhs.utils.SpeakerRequestEmitter in project open-kilda by telstra.
the class EmitUpdateRulesRequestsAction method perform.
@Override
protected void perform(State from, State to, Event event, FlowMirrorPointCreateContext context, FlowMirrorPointCreateFsm stateMachine) {
stateMachine.getCommands().clear();
stateMachine.getPendingCommands().clear();
String flowId = stateMachine.getFlowId();
Flow flow = getFlow(flowId);
Collection<FlowSegmentRequestFactory> commands = buildCommands(stateMachine, flow);
// emitting
PathId flowPathId = stateMachine.getFlowPathId();
SwitchId mirrorSwitchId = stateMachine.getMirrorSwitchId();
FlowMirrorPoints mirrorPoints = flowMirrorPointsRepository.findByPathIdAndSwitchId(flowPathId, mirrorSwitchId).orElse(null);
SpeakerRequestEmitter requestEmitter;
if (mirrorPoints != null && mirrorPoints.getMirrorPaths().isEmpty()) {
requestEmitter = SpeakerRemoveSegmentEmitter.INSTANCE;
} else {
requestEmitter = SpeakerInstallSegmentEmitter.INSTANCE;
}
requestEmitter.emitBatch(stateMachine.getCarrier(), commands, stateMachine.getCommands());
stateMachine.getCommands().forEach((key, value) -> stateMachine.getPendingCommands().put(key, value.getSwitchId()));
if (commands.isEmpty()) {
stateMachine.saveActionToHistory("No need to update rules");
} else {
stateMachine.saveActionToHistory("Commands for updating rules have been sent");
stateMachine.setRulesInstalled(true);
}
}
use of org.openkilda.wfm.topology.flowhs.utils.SpeakerRequestEmitter in project open-kilda by telstra.
the class EmitCommandRequestsAction method perform.
@Override
protected void perform(State from, State to, Event event, FlowMirrorPointDeleteContext context, FlowMirrorPointDeleteFsm stateMachine) {
String flowId = stateMachine.getFlowId();
Flow flow = getFlow(flowId);
PathId flowPathId = stateMachine.getFlowPathId();
SwitchId mirrorSwitchId = stateMachine.getMirrorSwitchId();
FlowMirrorPoints mirrorPoints = flowMirrorPointsRepository.findByPathIdAndSwitchId(flowPathId, mirrorSwitchId).orElseThrow(() -> new FlowProcessingException(ErrorType.NOT_FOUND, format("Flow mirror points for flow path %s and mirror switch id %s not found", flowPathId, mirrorSwitchId)));
FlowCommandBuilder commandBuilder = commandBuilderFactory.getBuilder(flow.getEncapsulationType());
Collection<FlowSegmentRequestFactory> commands = buildCommands(commandBuilder, stateMachine, flow, mirrorPoints);
// emitting
SpeakerRequestEmitter requestEmitter;
if (mirrorPoints.getMirrorPaths().isEmpty()) {
requestEmitter = SpeakerRemoveSegmentEmitter.INSTANCE;
} else {
requestEmitter = SpeakerInstallSegmentEmitter.INSTANCE;
}
requestEmitter.emitBatch(stateMachine.getCarrier(), commands, stateMachine.getCommands());
stateMachine.getCommands().forEach((key, value) -> stateMachine.getPendingCommands().put(key, value.getSwitchId()));
if (commands.isEmpty()) {
stateMachine.saveActionToHistory("No need to remove group");
} else {
stateMachine.saveActionToHistory("Commands for removing group have been sent");
}
}
Aggregations