Remove IntentStore access in IntentUpdate subclasses
Change-Id: I923c62f1d34dc2c911323f11990de5c9788bf655
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/InstallRequest.java b/core/net/src/main/java/org/onosproject/net/intent/impl/InstallRequest.java
index c22cd35..52e8bc1 100644
--- a/core/net/src/main/java/org/onosproject/net/intent/impl/InstallRequest.java
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/InstallRequest.java
@@ -27,16 +27,16 @@
// 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)));
}
}
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/IntentManager.java b/core/net/src/main/java/org/onosproject/net/intent/impl/IntentManager.java
index 2ebc518..fb772fd 100644
--- a/core/net/src/main/java/org/onosproject/net/intent/impl/IntentManager.java
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/IntentManager.java
@@ -489,19 +489,16 @@
}
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);
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/WithdrawRequest.java b/core/net/src/main/java/org/onosproject/net/intent/impl/WithdrawRequest.java
index 5af60dc..7444d35 100644
--- a/core/net/src/main/java/org/onosproject/net/intent/impl/WithdrawRequest.java
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/WithdrawRequest.java
@@ -20,7 +20,6 @@
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 @@
// 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