Skip to content

Commit

Permalink
Add a new workflow path in rerouting FSMs to skip rerouting when it i…
Browse files Browse the repository at this point in the history
…s not needed because the flow is already in the UP state.
  • Loading branch information
dmitrii-beliakov committed Dec 21, 2023
1 parent ef5e1ad commit de4eed8
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,9 @@ public Factory(@NonNull HaFlowRerouteHubCarrier carrier, @NonNull Config config,
builder.transition().from(State.PROTECTED_RESOURCES_ALLOCATED).to(State.MARKED_FLOW_DOWN_OR_DEGRADED)
.on(Event.NO_PATH_FOUND)
.perform(new OnNoPathFoundAction(persistenceManager, dashboardLogger, false));
builder.transition().from(State.MARKED_FLOW_DOWN_OR_DEGRADED).to(State.RESOURCE_ALLOCATION_COMPLETED)
.on(Event.NEXT)
builder.transitions().from(State.MARKED_FLOW_DOWN_OR_DEGRADED)
.toAmong(State.RESOURCE_ALLOCATION_COMPLETED, State.RESOURCE_ALLOCATION_COMPLETED)
.onEach(Event.NEXT, Event.REROUTE_IS_NOT_REQUIRED)
.perform(new PostResourceAllocationAction(persistenceManager));
builder.transitions().from(State.PROTECTED_RESOURCES_ALLOCATED)
.toAmong(State.REVERTING_ALLOCATED_RESOURCES, State.REVERTING_ALLOCATED_RESOURCES)
Expand All @@ -209,8 +210,10 @@ public Factory(@NonNull HaFlowRerouteHubCarrier carrier, @NonNull Config config,
.on(Event.NEXT)
.perform(new BuildNewRulesAction(persistenceManager, ruleManager));
builder.transition().from(State.RESOURCE_ALLOCATION_COMPLETED).to(State.NOTIFY_FLOW_MONITOR_WITH_ERROR)
.on(Event.REROUTE_IS_SKIPPED)
.on(Event.REROUTE_IS_SKIPPED_ERROR)
.perform(new RevertFlowStatusAction(persistenceManager));
builder.transition().from(State.RESOURCE_ALLOCATION_COMPLETED).to(State.NOTIFY_FLOW_MONITOR)
.on(Event.REROUTE_IS_NOT_REQUIRED);
builder.transitions().from(State.RESOURCE_ALLOCATION_COMPLETED)
.toAmong(State.REVERTING_ALLOCATED_RESOURCES, State.REVERTING_ALLOCATED_RESOURCES)
.onEach(Event.TIMEOUT, Event.ERROR);
Expand Down Expand Up @@ -486,7 +489,8 @@ public enum Event {
NEXT,

NO_PATH_FOUND,
REROUTE_IS_SKIPPED,
REROUTE_IS_SKIPPED_ERROR,
REROUTE_IS_NOT_REQUIRED,

RESPONSE_RECEIVED,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.openkilda.wfm.topology.flowhs.service.history.HaFlowHistory;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;

import java.util.Optional;

Expand All @@ -54,7 +55,7 @@ public void perform(
HaFlowHistory haFlowHistory = HaFlowHistory.of(stateMachine.getCommandContext().getCorrelationId())
.withHaFlowId(stateMachine.getHaFlowId());

if (stateMachine.getNewHaFlowStatus() == FlowStatus.UP) {
if (stateMachine.getNewHaFlowStatus() == FlowStatus.UP && StringUtils.isEmpty(stateMachine.getErrorReason())) {
dashboardLogger.onSuccessfulHaFlowReroute(stateMachine.getHaFlowId());
haFlowHistory.withAction("HA-flow has been rerouted successfully");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
import org.openkilda.wfm.topology.flowhs.fsm.haflow.reroute.HaFlowRerouteFsm.Event;
import org.openkilda.wfm.topology.flowhs.fsm.haflow.reroute.HaFlowRerouteFsm.State;
import org.openkilda.wfm.topology.flowhs.model.CrossingPaths;
import org.openkilda.wfm.topology.flowhs.service.history.FlowHistoryService;
import org.openkilda.wfm.topology.flowhs.service.history.HaFlowHistory;

import lombok.extern.slf4j.Slf4j;

Expand All @@ -60,7 +62,17 @@ protected Optional<Message> performWithResponse(State from, State to, Event even
HaFlowPath currentForwardPath = stateMachine.getOriginalHaFlow().getForwardPath();

if (stateMachine.getNewPrimaryPathIds() == null && stateMachine.getNewProtectedPathIds() == null) {
stateMachine.fireError(Event.REROUTE_IS_SKIPPED, "Reroute is unsuccessful. Couldn't find new path(s)");
if (stateMachine.getOriginalFlowStatus() == FlowStatus.UP) {
FlowHistoryService.using(stateMachine.getCarrier()).save(HaFlowHistory
.of(stateMachine.getCommandContext().getCorrelationId())
.withAction(
"Rerouting is skipped because the HA-flow is already in UP status and no new paths found"));
stateMachine.setNewHaFlowStatus(stateMachine.getOriginalFlowStatus());
stateMachine.setErrorReason("No errors. Rerouting is skipped");
stateMachine.fire(Event.REROUTE_IS_NOT_REQUIRED);
} else {
stateMachine.fireError(Event.REROUTE_IS_SKIPPED_ERROR, "Couldn't find new paths");
}
} else {
if (stateMachine.isEffectivelyDown()) {
log.warn("HA-flow {} is mentioned as effectively DOWN, so it will be forced to DOWN state if reroute "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ public void fireNoPathFound(String errorReason) {
fireError(Event.NO_PATH_FOUND, errorReason);
}

public void fireRerouteIsSkipped(String errorReason) {
fireError(Event.REROUTE_IS_SKIPPED, errorReason);
public void fireErrorRerouteIsSkipped(String errorReason) {
fireError(Event.REROUTE_IS_SKIPPED_ERROR, errorReason);
}

public void setRerouteError(RerouteError rerouteError) {
Expand Down Expand Up @@ -214,8 +214,9 @@ public Factory(@NonNull FlowRerouteHubCarrier carrier, @NonNull Config config,
builder.transition().from(State.PROTECTED_RESOURCES_ALLOCATED).to(State.MARKED_FLOW_DOWN_OR_DEGRADED)
.on(Event.NO_PATH_FOUND)
.perform(new OnNoPathFoundAction(persistenceManager, dashboardLogger, false));
builder.transition().from(State.MARKED_FLOW_DOWN_OR_DEGRADED).to(State.RESOURCE_ALLOCATION_COMPLETED)
.on(Event.NEXT)
builder.transitions().from(State.MARKED_FLOW_DOWN_OR_DEGRADED)
.toAmong(State.RESOURCE_ALLOCATION_COMPLETED, State.RESOURCE_ALLOCATION_COMPLETED)
.onEach(Event.NEXT, Event.REROUTE_IS_NOT_REQUIRED)
.perform(new PostResourceAllocationAction(persistenceManager));
builder.transitions().from(State.PROTECTED_RESOURCES_ALLOCATED)
.toAmong(State.REVERTING_ALLOCATED_RESOURCES, State.REVERTING_ALLOCATED_RESOURCES)
Expand All @@ -224,8 +225,10 @@ public Factory(@NonNull FlowRerouteHubCarrier carrier, @NonNull Config config,
builder.transition().from(State.RESOURCE_ALLOCATION_COMPLETED).to(State.INSTALLING_NON_INGRESS_RULES)
.on(Event.NEXT)
.perform(new InstallNonIngressRulesAction(persistenceManager, resourcesManager));
builder.transition().from(State.RESOURCE_ALLOCATION_COMPLETED).to(State.NOTIFY_FLOW_MONITOR)
.on(Event.REROUTE_IS_NOT_REQUIRED);
builder.transition().from(State.RESOURCE_ALLOCATION_COMPLETED).to(State.NOTIFY_FLOW_MONITOR_WITH_ERROR)
.on(Event.REROUTE_IS_SKIPPED)
.on(Event.REROUTE_IS_SKIPPED_ERROR)
.perform(new RevertFlowStatusAction(persistenceManager));
builder.transitions().from(State.RESOURCE_ALLOCATION_COMPLETED)
.toAmong(State.REVERTING_ALLOCATED_RESOURCES, State.REVERTING_ALLOCATED_RESOURCES)
Expand Down Expand Up @@ -546,7 +549,8 @@ public enum Event {
NEXT,

NO_PATH_FOUND,
REROUTE_IS_SKIPPED,
REROUTE_IS_SKIPPED_ERROR,
REROUTE_IS_NOT_REQUIRED,

RESPONSE_RECEIVED,
ERROR_RECEIVED,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

package org.openkilda.wfm.topology.flowhs.fsm.reroute.actions;

import static org.openkilda.wfm.topology.flowhs.fsm.reroute.FlowRerouteFsm.Event.REROUTE_IS_NOT_REQUIRED;

import org.openkilda.messaging.Message;
import org.openkilda.messaging.error.ErrorType;
import org.openkilda.messaging.info.InfoMessage;
Expand Down Expand Up @@ -68,7 +70,16 @@ protected Optional<Message> performWithResponse(State from, State to, Event even
&& stateMachine.getNewProtectedForwardPath() == null
&& stateMachine.getNewProtectedReversePath() == null) {
stateMachine.setOperationResultMessage(rerouteResponse);
stateMachine.fireRerouteIsSkipped("Reroute is unsuccessful. Couldn't find new path(s)");

if (stateMachine.getOriginalFlowStatus() == FlowStatus.UP) {
stateMachine.saveActionToHistory(
"Rerouting is skipped because the flow is already in UP status and no new paths found");
stateMachine.setErrorReason("No errors. Rerouting is skipped.");
stateMachine.setNewFlowStatus(stateMachine.getOriginalFlowStatus());
stateMachine.fire(REROUTE_IS_NOT_REQUIRED);
} else {
stateMachine.fireErrorRerouteIsSkipped("Reroute is unsuccessful. Couldn't find new path(s)");
}
} else {
if (stateMachine.isEffectivelyDown()) {
log.warn("Flow {} is mentioned as effectively DOWN, so it will be forced to DOWN state if reroute fail",
Expand Down

0 comments on commit de4eed8

Please sign in to comment.