Skip to content
Permalink
Browse files

Merge pull request #2685 from telstra/fix/default-flow-create

Fix default flow creation in v2 +fixed resetting of FSM in case of retry
  • Loading branch information...
nikitacherevko committed Aug 12, 2019
2 parents 23bed46 + f982bd8 commit 198c7eae1d84deea5af7fb9d497448ac0854c7c8
@@ -30,5 +30,5 @@
public class FlowEndpointV2 {
private SwitchId switchId;
private Integer portNumber;
private Integer vlanId;
private int vlanId;
}
@@ -77,15 +77,15 @@
private final String flowId;
private final FlowCreateHubCarrier carrier;

private Map<UUID, SpeakerCommandObserver> pendingCommands = new HashMap<>();
private Set<UUID> failedCommands = new HashSet<>();

private List<FlowResources> flowResources = new ArrayList<>();
private PathId forwardPathId;
private PathId reversePathId;
private PathId protectedForwardPathId;
private PathId protectedReversePathId;

private Map<UUID, SpeakerCommandObserver> pendingCommands = new HashMap<>();
private Set<UUID> failedCommands = new HashSet<>();

private Map<UUID, InstallIngressRule> ingressCommands = new HashMap<>();
private Map<UUID, InstallTransitRule> nonIngressCommands = new HashMap<>();
private Map<UUID, RemoveRule> removeCommands = new HashMap<>();
@@ -113,6 +113,7 @@ public boolean isPendingCommand(UUID commandId) {
public boolean retryIfAllowed() {
if (!timedOut && remainRetries-- > 0) {
log.info("About to retry flow create. Retries left: {}", remainRetries);
resetState();
fire(Event.RETRY);
return true;
} else {
@@ -166,6 +167,19 @@ public void sendResponse(Message message) {
carrier.sendNorthboundResponse(message);
}

private void resetState() {
ingressCommands.clear();
nonIngressCommands.clear();
removeCommands.clear();
failedCommands.clear();
flowResources.clear();

forwardPathId = null;
reversePathId = null;
protectedForwardPathId = null;
protectedReversePathId = null;
}

public static FlowCreateFsm.Factory factory(PersistenceManager persistenceManager, FlowCreateHubCarrier carrier,
Config config, FlowResourcesManager resourcesManager,
PathComputer pathComputer) {
@@ -43,9 +43,12 @@ protected void perform(State from, State to, Event event, FlowCreateContext cont

if (stateMachine.getPendingCommands().isEmpty()) {
if (stateMachine.getFailedCommands().isEmpty()) {
log.debug("Received responses for all pending commands");
log.debug("Successfully executed all pending commands");
stateMachine.fire(Event.NEXT);
} else {
log.debug("Received responses of all pending commands. Total failed commands: {}",
stateMachine.getFailedCommands().size());
stateMachine.getFailedCommands().clear();
stateMachine.fireError();
}
}
@@ -77,7 +77,6 @@ protected void perform(State from, State to, Event event, FlowCreateContext cont
flowRepository.createOrUpdate(flow);
}
});
flowResources.clear();

saveHistory(stateMachine, stateMachine.getCarrier(), stateMachine.getFlowId(),
"Resources released successfully");
@@ -56,22 +56,24 @@ protected void perform(State from, State to, Event event, FlowCreateContext cont

FlowRuleResponse response = (FlowRuleResponse) context.getSpeakerFlowResponse();
RulesValidator validator = new IngressRulesValidator(expected, response, switchFeatures);
String action;
if (!validator.validate()) {
stateMachine.getFailedCommands().add(commandId);
action = format("Rule is valid: switch %s, cookie %s", expected.getSwitchId(), expected.getCookie());
} else {
saveHistory(stateMachine, expected);
stateMachine.getPendingCommands().remove(commandId);
if (stateMachine.getPendingCommands().isEmpty()) {
log.debug("Ingress rules have been validated for flow {}", stateMachine.getFlowId());
stateMachine.fire(Event.NEXT);
}
action = format("Rule is invalid: switch %s, cookie %s", expected.getSwitchId(), expected.getCookie());
}

stateMachine.getPendingCommands().remove(commandId);
if (stateMachine.getPendingCommands().isEmpty()) {
log.debug("Ingress rules have been validated for flow {}", stateMachine.getFlowId());
saveHistory(stateMachine, expected, action);
stateMachine.fire(Event.NEXT);
}
}

private void saveHistory(FlowCreateFsm stateMachine, InstallIngressRule expected) {
String action = format("Rule is valid: switch %s, cookie %s",
expected.getSwitchId().toString(), expected.getCookie());
String description = format("Ingress rule has been validated successfully: switch %s, cookie %s",
private void saveHistory(FlowCreateFsm stateMachine, InstallIngressRule expected, String action) {
String description = format("Ingress rule validation is completed: switch %s, cookie %s",
expected.getSwitchId().toString(), expected.getCookie());
saveHistory(stateMachine, stateMachine.getCarrier(), stateMachine.getFlowId(), action, description);
}
@@ -44,22 +44,24 @@ protected void perform(State from, State to, Event event, FlowCreateContext cont

InstallTransitRule expected = stateMachine.getNonIngressCommands().get(commandId);
FlowRuleResponse actual = (FlowRuleResponse) context.getSpeakerFlowResponse();
String action;
if (!new NonIngressRulesValidator(expected, actual).validate()) {
stateMachine.getFailedCommands().add(commandId);
action = format("Rule is valid: switch %s, cookie %s", expected.getSwitchId(), expected.getCookie());
} else {
saveHistory(stateMachine, expected);
stateMachine.getPendingCommands().remove(commandId);
if (stateMachine.getPendingCommands().isEmpty()) {
log.debug("Non ingress rules have been validated for flow {}", stateMachine.getFlowId());
stateMachine.fire(Event.NEXT);
}
action = format("Rule is invalid: switch %s, cookie %s", expected.getSwitchId(), expected.getCookie());
}

stateMachine.getPendingCommands().remove(commandId);
if (stateMachine.getPendingCommands().isEmpty()) {
log.debug("Non ingress rules have been validated for flow {}", stateMachine.getFlowId());
saveHistory(stateMachine, expected, action);
stateMachine.fire(Event.NEXT);
}
}

private void saveHistory(FlowCreateFsm stateMachine, InstallTransitRule expected) {
String action = format("Rule is valid: switch %s, cookie %s",
expected.getSwitchId().toString(), expected.getCookie());
String description = format("Non ingress rule has been validated successfully: switch %s, cookie %s",
private void saveHistory(FlowCreateFsm stateMachine, InstallTransitRule expected, String action) {
String description = format("Non ingress rule validation is completed: switch %s, cookie %s",
expected.getSwitchId().toString(), expected.getCookie());
saveHistory(stateMachine, stateMachine.getCarrier(), stateMachine.getFlowId(), action, description);
}

0 comments on commit 198c7ea

Please sign in to comment.
You can’t perform that action at this time.