Sho SHIMIZU
Committed by Brian O'Connor

Remove IntentStore access in IntentUpdate subclasses

Change-Id: I923c62f1d34dc2c911323f11990de5c9788bf655
...@@ -27,16 +27,16 @@ class InstallRequest implements IntentUpdate { ...@@ -27,16 +27,16 @@ class InstallRequest implements IntentUpdate {
27 // TODO: define an interface and use it, instead of IntentManager 27 // TODO: define an interface and use it, instead of IntentManager
28 private final IntentManager intentManager; 28 private final IntentManager intentManager;
29 private final IntentData pending; 29 private final IntentData pending;
30 + private final Optional<IntentData> current;
30 31
31 - InstallRequest(IntentManager intentManager, IntentData intentData) { 32 + InstallRequest(IntentManager intentManager, IntentData intentData, Optional<IntentData> current) {
32 this.intentManager = checkNotNull(intentManager); 33 this.intentManager = checkNotNull(intentManager);
33 this.pending = checkNotNull(intentData); 34 this.pending = checkNotNull(intentData);
35 + this.current = checkNotNull(current);
34 } 36 }
35 37
36 @Override 38 @Override
37 public Optional<IntentUpdate> execute() { 39 public Optional<IntentUpdate> execute() {
38 - //FIXME... store hack 40 + return Optional.of(new Compiling(intentManager, pending, current.orElse(null)));
39 - IntentData current = intentManager.store.getIntentData(pending.key());
40 - return Optional.of(new Compiling(intentManager, pending, current));
41 } 41 }
42 } 42 }
......
...@@ -489,19 +489,16 @@ public class IntentManager ...@@ -489,19 +489,16 @@ public class IntentManager
489 } 489 }
490 490
491 private IntentUpdate createIntentUpdate(IntentData intentData) { 491 private IntentUpdate createIntentUpdate(IntentData intentData) {
492 + IntentData current = store.getIntentData(intentData.key());
492 switch (intentData.state()) { 493 switch (intentData.state()) {
493 case INSTALL_REQ: 494 case INSTALL_REQ:
494 - return new InstallRequest(this, intentData); 495 + return new InstallRequest(this, intentData, Optional.ofNullable(current));
495 case WITHDRAW_REQ: 496 case WITHDRAW_REQ:
496 - return new WithdrawRequest(this, intentData); 497 + if (current == null) {
497 - // fallthrough 498 + return new Withdrawn(current, WITHDRAWN);
498 - case COMPILING: 499 + } else {
499 - case INSTALLING: 500 + return new WithdrawRequest(this, intentData, current);
500 - case INSTALLED: 501 + }
501 - case RECOMPILING:
502 - case WITHDRAWING:
503 - case WITHDRAWN:
504 - case FAILED:
505 default: 502 default:
506 // illegal state 503 // illegal state
507 return new CompilingFailed(intentData); 504 return new CompilingFailed(intentData);
......
...@@ -20,7 +20,6 @@ import org.onosproject.net.intent.IntentData; ...@@ -20,7 +20,6 @@ import org.onosproject.net.intent.IntentData;
20 import java.util.Optional; 20 import java.util.Optional;
21 21
22 import static com.google.common.base.Preconditions.checkNotNull; 22 import static com.google.common.base.Preconditions.checkNotNull;
23 -import static org.onosproject.net.intent.IntentState.WITHDRAWN;
24 23
25 /** 24 /**
26 * Represents a phase of requesting a withdraw of an intent. 25 * Represents a phase of requesting a withdraw of an intent.
...@@ -30,19 +29,16 @@ class WithdrawRequest implements IntentUpdate { ...@@ -30,19 +29,16 @@ class WithdrawRequest implements IntentUpdate {
30 // TODO: define an interface and use it, instead of IntentManager 29 // TODO: define an interface and use it, instead of IntentManager
31 private final IntentManager intentManager; 30 private final IntentManager intentManager;
32 private final IntentData pending; 31 private final IntentData pending;
32 + private final IntentData current;
33 33
34 - WithdrawRequest(IntentManager intentManager, IntentData intentData) { 34 + WithdrawRequest(IntentManager intentManager, IntentData intentData, IntentData current) {
35 this.intentManager = checkNotNull(intentManager); 35 this.intentManager = checkNotNull(intentManager);
36 this.pending = checkNotNull(intentData); 36 this.pending = checkNotNull(intentData);
37 + this.current = checkNotNull(current);
37 } 38 }
38 39
39 @Override 40 @Override
40 public Optional<IntentUpdate> execute() { 41 public Optional<IntentUpdate> execute() {
41 - //FIXME need store interface
42 - IntentData current = intentManager.store.getIntentData(pending.key());
43 - if (current == null) {
44 - return Optional.of(new Withdrawn(pending, WITHDRAWN));
45 - }
46 //TODO perhaps we want to validate that the pending and current are the 42 //TODO perhaps we want to validate that the pending and current are the
47 // same version i.e. they are the same 43 // same version i.e. they are the same
48 // Note: this call is not just the symmetric version of submit 44 // Note: this call is not just the symmetric version of submit
......