Fix intent manager unit tests
Change-Id: I4bdde294a6cd181d3acf9218824645714c227bae
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 0939c76..c018918 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
@@ -51,6 +51,7 @@
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
import java.util.EnumSet;
import java.util.Iterator;
import java.util.List;
@@ -304,9 +305,11 @@
@Override
public void onError(FlowRuleOperations ops) {
- //FIXME store.write(pending.setState(BROKEN));
log.warn("Failed installation: {} {} on {}", pending.key(),
pending.intent(), ops);
+ //FIXME store.write(pending.setState(BROKEN));
+ pending.setState(FAILED);
+ store.write(pending);
}
});
}
@@ -317,7 +320,7 @@
* @param current intent data stored in the store
* @return flow rule operations
*/
- FlowRuleOperations uninstallCoordinate(IntentData current) {
+ FlowRuleOperations uninstallCoordinate(IntentData current, IntentData pending) {
List<Intent> installables = current.installables();
List<List<FlowRuleBatchOperation>> plans = new ArrayList<>();
for (Intent installable : installables) {
@@ -327,16 +330,17 @@
return merge(plans).build(new FlowRuleOperationsContext() {
@Override
public void onSuccess(FlowRuleOperations ops) {
- log.info("Completed withdrawing: {}", current.key());
- current.setState(WITHDRAWN);
- store.write(current);
+ log.info("Completed withdrawing: {}", pending.key());
+ pending.setState(WITHDRAWN);
+ pending.setInstallables(Collections.emptyList());
+ store.write(pending);
}
@Override
public void onError(FlowRuleOperations ops) {
- log.warn("Failed withdraw: {}", current.key());
- current.setState(FAILED);
- store.write(current);
+ log.warn("Failed withdraw: {}", pending.key());
+ pending.setState(FAILED);
+ store.write(pending);
}
});
}
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/WithdrawCoordinating.java b/core/net/src/main/java/org/onosproject/net/intent/impl/WithdrawCoordinating.java
index 9dd1019..5860d80 100644
--- a/core/net/src/main/java/org/onosproject/net/intent/impl/WithdrawCoordinating.java
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/WithdrawCoordinating.java
@@ -17,6 +17,7 @@
import org.onosproject.net.flow.FlowRuleOperations;
import org.onosproject.net.intent.IntentData;
+import org.onosproject.net.intent.IntentState;
import java.util.Optional;
@@ -36,12 +37,16 @@
WithdrawCoordinating(IntentManager intentManager, IntentData pending, IntentData current) {
this.intentManager = checkNotNull(intentManager);
this.pending = checkNotNull(pending);
- this.current = checkNotNull(current);
+ this.current = current;
}
@Override
public Optional<IntentUpdate> execute() {
- FlowRuleOperations flowRules = intentManager.uninstallCoordinate(current);
+ 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));
}
}
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 f58a7a8..2eb541a 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
@@ -37,7 +37,7 @@
@Override
public Optional<IntentUpdate> execute() {
- //FIXME... store hack
+ //FIXME need store interface
IntentData current = intentManager.store.getIntentData(pending.key());
//TODO perhaps we want to validate that the pending and current are the
// same version i.e. they are the same
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/Withdrawn.java b/core/net/src/main/java/org/onosproject/net/intent/impl/Withdrawn.java
index b4864bc..c7e531a 100644
--- a/core/net/src/main/java/org/onosproject/net/intent/impl/Withdrawn.java
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/Withdrawn.java
@@ -16,6 +16,7 @@
package org.onosproject.net.intent.impl;
import org.onosproject.net.intent.IntentData;
+import org.onosproject.net.intent.IntentState;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.onosproject.net.intent.IntentState.WITHDRAWING;
@@ -25,8 +26,12 @@
private final IntentData intentData;
Withdrawn(IntentData intentData) {
+ this(intentData, WITHDRAWING);
+ }
+
+ Withdrawn(IntentData intentData, IntentState newState) {
this.intentData = checkNotNull(intentData);
- this.intentData.setState(WITHDRAWING);
+ this.intentData.setState(newState);
}
@Override