use of org.openkilda.wfm.share.model.SpeakerRequestBuildContext in project open-kilda by telstra.
the class RemoveOldRulesAction method perform.
@TimedExecution("fsm.remove_old_rules")
@Override
protected void perform(State from, State to, Event event, FlowRerouteContext context, FlowRerouteFsm stateMachine) {
FlowEncapsulationType encapsulationType = stateMachine.getOriginalEncapsulationType();
FlowCommandBuilder commandBuilder = commandBuilderFactory.getBuilder(encapsulationType);
Collection<FlowSegmentRequestFactory> factories = new ArrayList<>();
Flow originalFlow = getOriginalFlowWithPaths(stateMachine, stateMachine.getOriginalFlow());
SpeakerRequestBuildContext speakerContext = SpeakerRequestBuildContext.getEmpty();
MirrorContext mirrorContext = MirrorContext.builder().removeFlowOperation(true).build();
if (stateMachine.getOldPrimaryForwardPath() != null) {
FlowPath oldForward = getFlowPath(stateMachine.getOldPrimaryForwardPath());
speakerContext.setForward(buildPathContextForRemovalIngressOnly(oldForward.getSrcSwitchId()));
if (stateMachine.getOldPrimaryReversePath() != null) {
FlowPath oldReverse = getFlowPath(stateMachine.getOldPrimaryReversePath());
speakerContext.setReverse(buildPathContextForRemovalIngressOnly(oldReverse.getSrcSwitchId()));
factories.addAll(commandBuilder.buildAll(stateMachine.getCommandContext(), originalFlow, oldForward, oldReverse, speakerContext, mirrorContext));
} else {
factories.addAll(commandBuilder.buildAll(stateMachine.getCommandContext(), originalFlow, oldForward, speakerContext, mirrorContext));
}
} else if (stateMachine.getOldPrimaryReversePath() != null) {
FlowPath oldReverse = getFlowPath(stateMachine.getOldPrimaryReversePath());
speakerContext.setForward(buildPathContextForRemovalIngressOnly(oldReverse.getSrcSwitchId()));
factories.addAll(commandBuilder.buildAll(stateMachine.getCommandContext(), originalFlow, oldReverse, speakerContext, mirrorContext));
}
if (stateMachine.getOldProtectedForwardPath() != null) {
FlowPath oldForward = getFlowPath(stateMachine.getOldProtectedForwardPath());
if (stateMachine.getOldProtectedReversePath() != null) {
FlowPath oldReverse = getFlowPath(stateMachine.getOldProtectedReversePath());
factories.addAll(commandBuilder.buildAllExceptIngress(stateMachine.getCommandContext(), originalFlow, oldForward, oldReverse, mirrorContext));
} else {
factories.addAll(commandBuilder.buildAllExceptIngress(stateMachine.getCommandContext(), originalFlow, oldForward, mirrorContext));
}
} else if (stateMachine.getOldProtectedReversePath() != null) {
FlowPath oldReverse = getFlowPath(stateMachine.getOldProtectedReversePath());
factories.addAll(commandBuilder.buildAllExceptIngress(stateMachine.getCommandContext(), originalFlow, oldReverse, mirrorContext));
}
stateMachine.clearPendingAndRetriedAndFailedCommands();
if (factories.isEmpty()) {
stateMachine.saveActionToHistory("No need to remove old rules");
stateMachine.fire(Event.RULES_REMOVED);
} else {
Map<UUID, FlowSegmentRequestFactory> requestsStorage = stateMachine.getRemoveCommands();
for (FlowSegmentRequestFactory factory : factories) {
FlowSegmentRequest request = factory.makeRemoveRequest(commandIdGenerator.generate());
// TODO ensure no conflicts
requestsStorage.put(request.getCommandId(), factory);
stateMachine.getCarrier().sendSpeakerRequest(request);
}
requestsStorage.forEach((key, value) -> stateMachine.addPendingCommand(key, value.getSwitchId()));
stateMachine.saveActionToHistory("Remove commands for old rules have been sent");
}
}
use of org.openkilda.wfm.share.model.SpeakerRequestBuildContext in project open-kilda by telstra.
the class InstallIngressRulesAction method perform.
@Override
protected void perform(State from, State to, Event event, FlowUpdateContext context, FlowUpdateFsm stateMachine) {
String flowId = stateMachine.getFlowId();
RequestedFlow requestedFlow = stateMachine.getTargetFlow();
Flow flow = getFlow(flowId);
FlowCommandBuilder commandBuilder = commandBuilderFactory.getBuilder(requestedFlow.getFlowEncapsulationType());
FlowPath newPrimaryForward = getFlowPath(flow, stateMachine.getNewPrimaryForwardPath());
FlowPath newPrimaryReverse = getFlowPath(flow, stateMachine.getNewPrimaryReversePath());
SpeakerRequestBuildContext speakerContext = buildBaseSpeakerContextForInstall(newPrimaryForward.getSrcSwitchId(), newPrimaryReverse.getSrcSwitchId());
Collection<FlowSegmentRequestFactory> commands = new ArrayList<>();
switch(stateMachine.getEndpointUpdate()) {
case SOURCE:
speakerContext.getForward().setUpdateMeter(false);
commands.addAll(getCommandsForSourceUpdate(commandBuilder, stateMachine, flow, newPrimaryForward, newPrimaryReverse, speakerContext));
break;
case DESTINATION:
speakerContext.getReverse().setUpdateMeter(false);
commands.addAll(getCommandsForDestinationUpdate(commandBuilder, stateMachine, flow, newPrimaryForward, newPrimaryReverse, speakerContext));
break;
case BOTH:
speakerContext.getForward().setUpdateMeter(false);
speakerContext.getReverse().setUpdateMeter(false);
if (stateMachine.getFlowLoopOperation() == FlowLoopOperation.NONE) {
commands.addAll(commandBuilder.buildIngressOnly(stateMachine.getCommandContext(), flow, newPrimaryForward, newPrimaryReverse, speakerContext));
} else {
commands.addAll(commandBuilder.buildIngressOnly(stateMachine.getCommandContext(), flow, newPrimaryForward, newPrimaryReverse, speakerContext).stream().filter(f -> f instanceof IngressFlowLoopSegmentRequestFactory).collect(Collectors.toList()));
}
break;
default:
commands.addAll(commandBuilder.buildIngressOnly(stateMachine.getCommandContext(), flow, newPrimaryForward, newPrimaryReverse, speakerContext));
break;
}
// Installation of ingress rules for protected paths is skipped. These paths are activated on swap.
stateMachine.clearPendingAndRetriedAndFailedCommands();
if (commands.isEmpty()) {
stateMachine.saveActionToHistory("No need to install ingress rules");
stateMachine.fire(Event.INGRESS_IS_SKIPPED);
} else {
SpeakerInstallSegmentEmitter.INSTANCE.emitBatch(stateMachine.getCarrier(), commands, stateMachine.getIngressCommands());
stateMachine.getIngressCommands().forEach((key, value) -> stateMachine.addPendingCommand(key, value.getSwitchId()));
stateMachine.saveActionToHistory("Commands for installing ingress rules have been sent");
}
}
use of org.openkilda.wfm.share.model.SpeakerRequestBuildContext in project open-kilda by telstra.
the class InstallIngressRulesAction method perform.
@Override
protected void perform(State from, State to, Event event, FlowPathSwapContext context, FlowPathSwapFsm stateMachine) {
String flowId = stateMachine.getFlowId();
Flow flow = getFlow(flowId);
FlowCommandBuilder commandBuilder = commandBuilderFactory.getBuilder(flow.getEncapsulationType());
FlowPath newPrimaryForward = flow.getForwardPath();
FlowPath newPrimaryReverse = flow.getReversePath();
SpeakerRequestBuildContext speakerContext = buildBaseSpeakerContextForInstall(flow.getSrcSwitchId(), flow.getDestSwitchId());
Collection<FlowSegmentRequestFactory> commands = new ArrayList<>(commandBuilder.buildIngressOnly(stateMachine.getCommandContext(), flow, newPrimaryForward, newPrimaryReverse, speakerContext));
commands.addAll(commandBuilder.buildEgressOnly(stateMachine.getCommandContext(), flow, newPrimaryForward, newPrimaryReverse).stream().filter(f -> f instanceof TransitFlowLoopSegmentRequestFactory || f instanceof EgressMirrorFlowSegmentRequestFactory).collect(Collectors.toList()));
// Installation of ingress rules for protected paths is skipped. These paths are activated on swap.
stateMachine.clearPendingAndRetriedAndFailedCommands();
SpeakerInstallSegmentEmitter.INSTANCE.emitBatch(stateMachine.getCarrier(), commands, stateMachine.getIngressCommands());
stateMachine.getIngressCommands().forEach((key, value) -> stateMachine.addPendingCommand(key, value.getSwitchId()));
stateMachine.saveActionToHistory("Commands for installing ingress rules have been sent");
}
Aggregations