Sho SHIMIZU
Committed by Brian O'Connor

Avoid unnecessary state transition

Change state from WithdrawRequest to Withdrawn directly when
there is nothing in the store with the key

Change-Id: Ia38d02bcff8df7aad35fbb975843c6741ff540f4
......@@ -17,7 +17,6 @@ package org.onosproject.net.intent.impl;
import org.onosproject.net.flow.FlowRuleOperations;
import org.onosproject.net.intent.IntentData;
import org.onosproject.net.intent.IntentState;
import java.util.Optional;
......@@ -37,14 +36,11 @@ class WithdrawCoordinating implements IntentUpdate {
WithdrawCoordinating(IntentManager intentManager, IntentData pending, IntentData current) {
this.intentManager = checkNotNull(intentManager);
this.pending = checkNotNull(pending);
this.current = current;
this.current = checkNotNull(current);
}
@Override
public Optional<IntentUpdate> execute() {
if (current == null) { // there's nothing in the store with this key
return Optional.of(new Withdrawn(pending, IntentState.WITHDRAWN));
}
FlowRuleOperations flowRules = intentManager.uninstallCoordinate(current, pending);
pending.setInstallables(current.installables());
return Optional.of(new Withdrawing(intentManager, pending, flowRules));
......
......@@ -20,6 +20,7 @@ import org.onosproject.net.intent.IntentData;
import java.util.Optional;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.onosproject.net.intent.IntentState.WITHDRAWN;
/**
* Represents a phase of requesting a withdraw of an intent.
......@@ -39,6 +40,9 @@ class WithdrawRequest implements IntentUpdate {
public Optional<IntentUpdate> execute() {
//FIXME need store interface
IntentData current = intentManager.store.getIntentData(pending.key());
if (current == null) {
return Optional.of(new Withdrawn(pending, WITHDRAWN));
}
//TODO perhaps we want to validate that the pending and current are the
// same version i.e. they are the same
// Note: this call is not just the symmetric version of submit
......