Sho SHIMIZU
Committed by Brian O'Connor

Remove IntentStore access in IntentUpdate subclasses

Change-Id: I923c62f1d34dc2c911323f11990de5c9788bf655
......@@ -27,16 +27,16 @@ class InstallRequest implements IntentUpdate {
// TODO: define an interface and use it, instead of IntentManager
private final IntentManager intentManager;
private final IntentData pending;
private final Optional<IntentData> current;
InstallRequest(IntentManager intentManager, IntentData intentData) {
InstallRequest(IntentManager intentManager, IntentData intentData, Optional<IntentData> current) {
this.intentManager = checkNotNull(intentManager);
this.pending = checkNotNull(intentData);
this.current = checkNotNull(current);
}
@Override
public Optional<IntentUpdate> execute() {
//FIXME... store hack
IntentData current = intentManager.store.getIntentData(pending.key());
return Optional.of(new Compiling(intentManager, pending, current));
return Optional.of(new Compiling(intentManager, pending, current.orElse(null)));
}
}
......
......@@ -489,19 +489,16 @@ public class IntentManager
}
private IntentUpdate createIntentUpdate(IntentData intentData) {
IntentData current = store.getIntentData(intentData.key());
switch (intentData.state()) {
case INSTALL_REQ:
return new InstallRequest(this, intentData);
return new InstallRequest(this, intentData, Optional.ofNullable(current));
case WITHDRAW_REQ:
return new WithdrawRequest(this, intentData);
// fallthrough
case COMPILING:
case INSTALLING:
case INSTALLED:
case RECOMPILING:
case WITHDRAWING:
case WITHDRAWN:
case FAILED:
if (current == null) {
return new Withdrawn(current, WITHDRAWN);
} else {
return new WithdrawRequest(this, intentData, current);
}
default:
// illegal state
return new CompilingFailed(intentData);
......
......@@ -20,7 +20,6 @@ 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.
......@@ -30,19 +29,16 @@ class WithdrawRequest implements IntentUpdate {
// TODO: define an interface and use it, instead of IntentManager
private final IntentManager intentManager;
private final IntentData pending;
private final IntentData current;
WithdrawRequest(IntentManager intentManager, IntentData intentData) {
WithdrawRequest(IntentManager intentManager, IntentData intentData, IntentData current) {
this.intentManager = checkNotNull(intentManager);
this.pending = checkNotNull(intentData);
this.current = checkNotNull(current);
}
@Override
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
......