Adding intent operations batch abstraction.
diff --git a/core/api/src/main/java/org/onlab/onos/net/intent/BatchOperation.java b/core/api/src/main/java/org/onlab/onos/net/intent/BatchOperation.java
index 72a9847..7b57769 100644
--- a/core/api/src/main/java/org/onlab/onos/net/intent/BatchOperation.java
+++ b/core/api/src/main/java/org/onlab/onos/net/intent/BatchOperation.java
@@ -14,6 +14,7 @@
* @param <T> the enum of operators <br>
* This enum must be defined in each sub-classes.
*/
+@Deprecated
public abstract class BatchOperation<T extends BatchOperationEntry<?, ?>> {
private final List<T> ops;
diff --git a/core/api/src/main/java/org/onlab/onos/net/intent/BatchOperationEntry.java b/core/api/src/main/java/org/onlab/onos/net/intent/BatchOperationEntry.java
index 4e57d33..1f0de83 100644
--- a/core/api/src/main/java/org/onlab/onos/net/intent/BatchOperationEntry.java
+++ b/core/api/src/main/java/org/onlab/onos/net/intent/BatchOperationEntry.java
@@ -11,6 +11,7 @@
* This is the interface to classes which are maintained by BatchOperation as
* its entries.
*/
+@Deprecated
public class BatchOperationEntry<T extends Enum<?>, U extends BatchOperationTarget> {
private final T operator;
private final U target;
diff --git a/core/api/src/main/java/org/onlab/onos/net/intent/BatchOperationTarget.java b/core/api/src/main/java/org/onlab/onos/net/intent/BatchOperationTarget.java
index c678f31..d2d04e7 100644
--- a/core/api/src/main/java/org/onlab/onos/net/intent/BatchOperationTarget.java
+++ b/core/api/src/main/java/org/onlab/onos/net/intent/BatchOperationTarget.java
@@ -4,6 +4,7 @@
/**
* An interface of the class which is assigned to BatchOperation.
*/
+@Deprecated
public interface BatchOperationTarget {
}
diff --git a/core/api/src/main/java/org/onlab/onos/net/intent/IntentBatchOperation.java b/core/api/src/main/java/org/onlab/onos/net/intent/IntentBatchOperation.java
index b450d71..75e240f 100644
--- a/core/api/src/main/java/org/onlab/onos/net/intent/IntentBatchOperation.java
+++ b/core/api/src/main/java/org/onlab/onos/net/intent/IntentBatchOperation.java
@@ -3,6 +3,7 @@
/**
* A list of intent operations.
*/
+@Deprecated
public class IntentBatchOperation extends
BatchOperation<BatchOperationEntry<IntentBatchOperation.Operator, ?>> {
/**
diff --git a/core/api/src/main/java/org/onlab/onos/net/intent/IntentOperation.java b/core/api/src/main/java/org/onlab/onos/net/intent/IntentOperation.java
new file mode 100644
index 0000000..4135ed8
--- /dev/null
+++ b/core/api/src/main/java/org/onlab/onos/net/intent/IntentOperation.java
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.onlab.onos.net.intent;
+
+/**
+ * Abstraction of an intent-related operation, e.g. add, remove, replace.
+ */
+public class IntentOperation {
+
+ private final Type type;
+ private final IntentId intentId;
+ private final Intent intent;
+
+ /**
+ * Operation type.
+ */
+ enum Type {
+ /**
+ * Indicates that an intent should be added.
+ */
+ SUBMIT,
+
+ /**
+ * Indicates that an intent should be removed.
+ */
+ WITHDRAW,
+
+ /**
+ * Indicates that an intent should be replaced with another.
+ */
+ REPLACE
+ }
+
+ /**
+ * Creates an intent operation.
+ *
+ * @param type operation type
+ * @param intentId identifier of the intent subject to the operation
+ * @param intent intent subject
+ */
+ IntentOperation(Type type, IntentId intentId, Intent intent) {
+ this.type = type;
+ this.intentId = intentId;
+ this.intent = intent;
+ }
+
+ /**
+ * Returns the type of the operation.
+ *
+ * @return operation type
+ */
+ public Type type() {
+ return type;
+ }
+
+ /**
+ * Returns the identifier of the intent to which this operation applies.
+ *
+ * @return intent identifier
+ */
+ public IntentId intentId() {
+ return intentId;
+ }
+
+ /**
+ * Returns the intent to which this operation applied. For remove,
+ * this can be null.
+ *
+ * @return intent that is the subject of the operation; null for remove
+ */
+ public Intent intent() {
+ return intent;
+ }
+
+}
diff --git a/core/api/src/main/java/org/onlab/onos/net/intent/IntentOperations.java b/core/api/src/main/java/org/onlab/onos/net/intent/IntentOperations.java
index 470d98b..ee7389a 100644
--- a/core/api/src/main/java/org/onlab/onos/net/intent/IntentOperations.java
+++ b/core/api/src/main/java/org/onlab/onos/net/intent/IntentOperations.java
@@ -1,10 +1,100 @@
package org.onlab.onos.net.intent;
+import com.google.common.collect.ImmutableList;
+
+import java.util.List;
+
+import static org.onlab.onos.net.intent.IntentOperation.Type.REPLACE;
+import static org.onlab.onos.net.intent.IntentOperation.Type.SUBMIT;
+import static org.onlab.onos.net.intent.IntentOperation.Type.WITHDRAW;
+
/**
- * Abstraction of a batch of intent submit/withdraw operations.
+ * Batch of intent submit/withdraw/replace operations.
*/
-public interface IntentOperations {
+public final class IntentOperations {
- // TODO: elaborate once the revised BatchOperation scheme is in place
+ private final List<IntentOperation> operations;
+ /**
+ * Creates a batch of intent operations using the supplied list.
+ *
+ * @param operations list of intent operations
+ */
+ private IntentOperations(List<IntentOperation> operations) {
+ this.operations = operations;
+ }
+
+ /**
+ * List of operations that need to be executed as a unit.
+ *
+ * @return list of intent operations
+ */
+ public List<IntentOperation> operations() {
+ return operations;
+ }
+
+ /**
+ * Returns a builder for intent operation batches.
+ *
+ * @return intent operations builder
+ */
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ /**
+ * Builder for batches of intent operations.
+ */
+ public static final class Builder {
+
+ ImmutableList.Builder<IntentOperation> builder = ImmutableList.builder();
+
+ // Public construction is forbidden.
+ private Builder() {
+ }
+
+ /**
+ * Adds an intent submit operation.
+ *
+ * @param intent intent to be submitted
+ * @return self
+ */
+ public Builder addSubmitOperation(Intent intent) {
+ builder.add(new IntentOperation(SUBMIT, intent.id(), intent));
+ return this;
+ }
+
+ /**
+ * Adds an intent submit operation.
+ *
+ * @param oldIntentId intent to be replaced
+ * @param newIntent replacement intent
+ * @return self
+ */
+ public Builder addReplaceOperation(IntentId oldIntentId, Intent newIntent) {
+ builder.add(new IntentOperation(REPLACE, oldIntentId, newIntent));
+ return this;
+ }
+
+ /**
+ * Adds an intent submit operation.
+ *
+ * @param intentId identifier of the intent to be withdrawn
+ * @return self
+ */
+ public Builder addWithdrawOperation(IntentId intentId) {
+ builder.add(new IntentOperation(WITHDRAW, intentId, null));
+ return this;
+ }
+
+ /**
+ * Builds a batch of intent operations.
+ *
+ * @return immutable batch of intent operations
+ */
+ public IntentOperations build() {
+ return new IntentOperations(builder.build());
+ }
+
+ }
}
diff --git a/core/api/src/main/java/org/onlab/onos/net/intent/IntentService.java b/core/api/src/main/java/org/onlab/onos/net/intent/IntentService.java
index 700066d..8c098a3 100644
--- a/core/api/src/main/java/org/onlab/onos/net/intent/IntentService.java
+++ b/core/api/src/main/java/org/onlab/onos/net/intent/IntentService.java
@@ -2,6 +2,7 @@
import java.util.List;
+import java.util.concurrent.Future;
/**
* Service for application submitting or withdrawing their intents.
@@ -27,6 +28,8 @@
*/
void withdraw(Intent intent);
+ // void replace(IntentId oldIntentId, Intent newIntent);
+
/**
* Submits a batch of submit & withdraw operations. Such a batch is
* assumed to be processed together.
@@ -36,7 +39,7 @@
*
* @param operations batch of intent operations
*/
- void execute(IntentOperations operations);
+ Future<IntentOperations> execute(IntentOperations operations);
/**
* Returns an iterable of intents currently in the system.
diff --git a/core/api/src/test/java/org/onlab/onos/net/intent/FakeIntentManager.java b/core/api/src/test/java/org/onlab/onos/net/intent/FakeIntentManager.java
index 5020459..4204f1e 100644
--- a/core/api/src/test/java/org/onlab/onos/net/intent/FakeIntentManager.java
+++ b/core/api/src/test/java/org/onlab/onos/net/intent/FakeIntentManager.java
@@ -9,6 +9,7 @@
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
/**
* Fake implementation of the intent service to assist in developing tests of
@@ -171,8 +172,9 @@
}
@Override
- public void execute(IntentOperations operations) {
+ public Future<IntentOperations> execute(IntentOperations operations) {
// TODO: implement later
+ return null;
}
@Override
diff --git a/core/net/src/main/java/org/onlab/onos/net/intent/impl/IntentManager.java b/core/net/src/main/java/org/onlab/onos/net/intent/impl/IntentManager.java
index bfdc57e..1a6ca38 100644
--- a/core/net/src/main/java/org/onlab/onos/net/intent/impl/IntentManager.java
+++ b/core/net/src/main/java/org/onlab/onos/net/intent/impl/IntentManager.java
@@ -126,7 +126,7 @@
// FIXME: implement this method
@Override
- public void execute(IntentOperations operations) {
+ public Future<IntentOperations> execute(IntentOperations operations) {
throw new UnsupportedOperationException("execute() is not implemented yet");
}