Remove mutating methods in IntentData
Change-Id: I1d9ac694922f4a12b2d94a92b64be2c336c31ae3
diff --git a/core/api/src/main/java/org/onosproject/net/intent/IntentData.java b/core/api/src/main/java/org/onosproject/net/intent/IntentData.java
index c3277bc..743e349 100644
--- a/core/api/src/main/java/org/onosproject/net/intent/IntentData.java
+++ b/core/api/src/main/java/org/onosproject/net/intent/IntentData.java
@@ -68,6 +68,27 @@
}
/**
+ * Creates a new intent data object.
+ *
+ * @param intent intent this metadata references
+ * @param state intent state
+ * @param version version of the intent for this key
+ * @param origin ID of the node where the data was originally created
+ */
+ public IntentData(Intent intent, IntentState state, Timestamp version, NodeId origin) {
+ checkNotNull(intent);
+ checkNotNull(state);
+ checkNotNull(version);
+ checkNotNull(origin);
+
+ this.intent = intent;
+ this.state = state;
+ this.request = state;
+ this.version = version;
+ this.origin = origin;
+ }
+
+ /**
* Copy constructor.
*
* @param intentData intent data to copy
@@ -84,6 +105,18 @@
errorCount = intentData.errorCount;
}
+ /**
+ * Create a new instance based on the original instance with new installables.
+ *
+ * @param original original data
+ * @param installables new installable intents to set
+ */
+ public IntentData(IntentData original, List<Intent> installables) {
+ this(original);
+
+ this.installables = ImmutableList.copyOf(checkNotNull(installables));
+ }
+
// kryo constructor
protected IntentData() {
intent = null;
@@ -131,15 +164,6 @@
}
/**
- * Sets the origin, which is the node that created the intent.
- *
- * @param origin origin instance
- */
- public void setOrigin(NodeId origin) {
- this.origin = origin;
- }
-
- /**
* Returns the origin node that created this intent.
*
* @return origin node ID
@@ -158,20 +182,6 @@
}
/**
- * Sets the version for this intent data.
- * <p>
- * The store should call this method only once when the IntentData is
- * first passed into the pending map. Ideally, an IntentData is timestamped
- * on the same thread that the called used to submit the intents.
- * </p>
- *
- * @param version the version/timestamp for this intent data
- */
- public void setVersion(Timestamp version) {
- this.version = version;
- }
-
- /**
* Increments the error count for this intent.
*/
public void incrementErrorCount() {
@@ -198,15 +208,6 @@
}
/**
- * Sets the intent installables to the given list of intents.
- *
- * @param installables list of installables for this intent
- */
- public void setInstallables(List<Intent> installables) {
- this.installables = ImmutableList.copyOf(installables);
- }
-
- /**
* Returns the installables associated with this intent.
*
* @return list of installable intents
diff --git a/core/common/src/test/java/org/onosproject/store/trivial/SimpleIntentStore.java b/core/common/src/test/java/org/onosproject/store/trivial/SimpleIntentStore.java
index 4a9eaa9..c374cd1 100644
--- a/core/common/src/test/java/org/onosproject/store/trivial/SimpleIntentStore.java
+++ b/core/common/src/test/java/org/onosproject/store/trivial/SimpleIntentStore.java
@@ -156,7 +156,7 @@
@Override
public void addPending(IntentData data) {
if (data.version() == null) { // recompiled intents will already have a version
- data.setVersion(new SystemClockTimestamp());
+ data = new IntentData(data.intent(), data.state(), new SystemClockTimestamp());
}
synchronized (this) {
IntentData existingData = pending.get(data.key());
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/phase/Compiling.java b/core/net/src/main/java/org/onosproject/net/intent/impl/phase/Compiling.java
index 5078b5d..6cef3a4 100644
--- a/core/net/src/main/java/org/onosproject/net/intent/impl/phase/Compiling.java
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/phase/Compiling.java
@@ -57,14 +57,12 @@
List<Intent> compiled = processor.compile(data.intent(),
//TODO consider passing an optional here in the future
stored.isPresent() ? stored.get().installables() : null);
- data.setInstallables(compiled);
- return Optional.of(new Installing(processor, data, stored));
+ return Optional.of(new Installing(processor, new IntentData(data, compiled), stored));
} catch (IntentException e) {
log.debug("Unable to compile intent {} due to: {}", data.intent(), e);
if (stored.isPresent() && !stored.get().installables().isEmpty()) {
// removing orphaned flows and deallocating resources
- data.setInstallables(stored.get().installables());
- return Optional.of(new Withdrawing(processor, data));
+ return Optional.of(new Withdrawing(processor, new IntentData(data, stored.get().installables())));
} else {
return Optional.of(new Failed(data));
}
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/phase/WithdrawRequest.java b/core/net/src/main/java/org/onosproject/net/intent/impl/phase/WithdrawRequest.java
index 8a0709e..a2c3dc0 100644
--- a/core/net/src/main/java/org/onosproject/net/intent/impl/phase/WithdrawRequest.java
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/phase/WithdrawRequest.java
@@ -64,7 +64,6 @@
}
}
- data.setInstallables(stored.get().installables());
- return Optional.of(new Withdrawing(processor, data));
+ return Optional.of(new Withdrawing(processor, new IntentData(data, stored.get().installables())));
}
}
diff --git a/core/store/dist/src/main/java/org/onosproject/store/intent/impl/GossipIntentStore.java b/core/store/dist/src/main/java/org/onosproject/store/intent/impl/GossipIntentStore.java
index f87bd3d..b4bdf2c 100644
--- a/core/store/dist/src/main/java/org/onosproject/store/intent/impl/GossipIntentStore.java
+++ b/core/store/dist/src/main/java/org/onosproject/store/intent/impl/GossipIntentStore.java
@@ -251,10 +251,12 @@
checkNotNull(data);
if (data.version() == null) {
- data.setVersion(new WallClockTimestamp());
+ pendingMap.put(data.key(), new IntentData(data.intent(), data.state(),
+ new WallClockTimestamp(), clusterService.getLocalNode().id()));
+ } else {
+ pendingMap.put(data.key(), new IntentData(data.intent(), data.state(),
+ data.version(), clusterService.getLocalNode().id()));
}
- data.setOrigin(clusterService.getLocalNode().id());
- pendingMap.put(data.key(), new IntentData(data));
}
@Override