Re-organize intent related packages
- Delete classes under intent package except for ApplicaitonIntent,
PacketConnectivityIntent, and OpticalConnectivityIntent
- Move PacketConnectivityIntent and OpticalConnectivityIntent under
net.onrc.onos.api.newintent package
- Adapt BatchOperation related changes for Intent and IntentId class
This is for ONOS-1887.
Change-Id: I4d25a0f8cbba806e9dd6e00333b6c7157c854658
diff --git a/src/main/java/net/onrc/onos/api/intent/IIntentRuntimeService.java b/src/main/java/net/onrc/onos/api/intent/IIntentRuntimeService.java
deleted file mode 100644
index a3b1705..0000000
--- a/src/main/java/net/onrc/onos/api/intent/IIntentRuntimeService.java
+++ /dev/null
@@ -1,161 +0,0 @@
-package net.onrc.onos.api.intent;
-
-import java.util.Collection;
-import java.util.EventListener;
-
-import net.onrc.onos.api.flowmanager.ConflictDetectionPolicy;
-import net.onrc.onos.api.flowmanager.Flow;
-import net.onrc.onos.api.flowmanager.FlowId;
-
-/**
- * An interface class for the Intent-Runtime Service. The role of the
- * Intent-Runtime Service is to manage a set of IFlow objects based on the
- * specified Intent objects.
- * <p>
- * It compiles accepted Intents to IFlow objects by allocating resources and
- * calculating paths based on the constrains described in the Intents, and
- * executes installation/uninstallation of the IFlow objects using FlowManager
- * Service.
- */
-public interface IIntentRuntimeService {
- /**
- * Installs the specified intent synchronously.
- *
- * <p>
- * This method blocks until the installation succeeds or fails.
- * </p>
- *
- * @param intent the intent to be installed.
- * @return true if the intent is successfully installed. Otherwise, false.
- */
- public boolean install(Intent intent);
-
- /**
- * Removes the specified intent synchronously.
- *
- * <p>
- * This method blocks until the removal succeeds or fails.
- * </p>
- *
- * @param id the ID of the intent to be uninstalled.
- * @return true if the intent is successfully uninstalled. Otherwise, false.
- */
- public boolean remove(IntentId id);
-
- /**
- * Gets specific intent.
- *
- * @param id ID of the intent should be retrieved
- * @return Intent if it exists, null otherwise.
- */
- Intent getIntent(IntentId id);
-
- /**
- * Gets all intents.
- *
- * @return collection of intents.
- */
- Collection<Intent> getIntents();
-
- /**
- * Executes batch operation of intents.
- *
- * @param ops BatchOperations to be executed.
- * @return true if succeeded, false otherwise.
- */
- boolean executeBatch(IntentBatchOperation ops);
-
- /**
- * Adds an IntentResolver associated with a given intent type.
- *
- * @param type the class instance of the intent type.
- * @param resolver the resolver of the given intent type.
- * @param <T> the type of the intent.
- */
- public <T extends Intent> void addResolver(Class<T> type, IntentResolver<T> resolver);
-
- /**
- * Removes the IntentResolver associated with the intent type.
- *
- * @param type the class instance of the intent type.
- * @param <T> the type of the intent.
- */
- public <T extends Intent> void removeResolver(Class<T> type);
-
- /**
- * Adds an IntentInstaller associated with a given intent type.
- *
- * <p>
- * If there is an Intent instance of the specified Intent type in the runtime,
- * the specified IntentInstaller doesn't replace the existing installer.
- * Otherwise, the existing installer is replaced with the specified installer.
- * </p>
- *
- * @param type the class instance of the intent type.
- * @param installer the installer of the given intent type.
- * @param <T> the type of the intent.
- * @return false when there is an Intent instance of the specified intent type
- * in the runtime. Otherwise, true.
- */
- public <T extends Intent> boolean addInstaller(Class<T> type, IntentInstaller<T> installer);
-
- /**
- * Removes the IntentInstaller associated with a given intent type.
- *
- * <p>
- * If there is an Intent instance of the specified Intent type in the runtime,
- * the specified IntentInstaller is not removed. Otherwise, the existing
- * IntentInstaller is removed from the runtime.
- * </p>
- *
- * @param type the class instance of the intent type.
- * @param <T> the type of the intent.
- * @return false when there is an Intent instance of the specified intent type
- * in the runtime. Otherwise, true.
- */
- public <T extends Intent> boolean removeInstaller(Class<T> type);
-
- /**
- * Gets IFlow objects managed by the specified intent.
- *
- * @param intentId ID of the target Intent.
- * @return Collection of IFlow objects if exists, null otherwise.
- */
- Collection<Flow> getFlows(String intentId);
-
- /**
- * Gets Intent object which manages the specified IFlow object.
- *
- * @param flowId ID of the target IFlow object.
- * @return Intent which manages the specified IFlow object, null otherwise.
- */
- Intent getIntentByFlow(FlowId flowId);
-
- /**
- * Sets a conflict detection policy.
- *
- * @param policy ConflictDetectionPolicy object to be set.
- */
- void setConflictDetectionPolicy(ConflictDetectionPolicy policy);
-
- /**
- * Gets the conflict detection policy.
- *
- * @return ConflictDetectionPolicy object being applied currently.
- */
- ConflictDetectionPolicy getConflictDetectionPolicy();
-
- /**
- * Adds event listener to this service.
- *
- * @param listener EventListener to be added.
- */
- void addEventListener(EventListener listener);
-
- /**
- * Removes event listener from this service.
- *
- * @param listener EventListener to be removed.
- */
- void removeEventListener(EventListener listener);
-}
diff --git a/src/main/java/net/onrc/onos/api/intent/Intent.java b/src/main/java/net/onrc/onos/api/intent/Intent.java
deleted file mode 100644
index 586605c..0000000
--- a/src/main/java/net/onrc/onos/api/intent/Intent.java
+++ /dev/null
@@ -1,74 +0,0 @@
-package net.onrc.onos.api.intent;
-
-import com.google.common.base.Objects;
-import net.onrc.onos.api.batchoperation.BatchOperationTarget;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-
-/**
- * The base class of an intent type.
- *
- * <p>
- * This class is sub-classed to provide other intent types like shortest path
- * connectivity and bandwidth constrained shortest path connectivity.
- * </p>
- *
- * <p>
- * The reasoning behind "intent" is that the applications can provide some
- * abstract representation of how traffic should flow be handled by the
- * networking, allowing the network OS to compile, reserve and optimize the
- * data-plane to satisfy those constraints.
- * </p>
- *
- * <p>
- * It is assumed that any kinds of intents are immutable.
- * Developers that will define a new intent type should ensure its immutability.
- * </p>
- */
-public abstract class Intent implements BatchOperationTarget {
- private final IntentId id;
-
- /**
- * Constructs an intent, which is activated permanently until it is removed explicitly.
- *
- * @param id ID for this intent object.
- */
- protected Intent(IntentId id) {
- this.id = checkNotNull(id);
- }
-
- /**
- * Returns ID for this Intent object.
- *
- * @return ID for this Intent object.
- */
- public IntentId getId() {
- return id;
- }
-
- @Override
- public int hashCode() {
- return id.hashCode();
- }
-
- @Override
- public boolean equals(Object obj) {
- if (obj == this) {
- return true;
- }
-
- if (!(obj instanceof Intent)) {
- return false;
- }
-
- Intent that = (Intent) obj;
- return Objects.equal(this.id, that.id);
- }
-
- @Override
- public String toString() {
- return Objects.toStringHelper(this)
- .add("id", id)
- .toString();
- }
-}
diff --git a/src/main/java/net/onrc/onos/api/intent/IntentId.java b/src/main/java/net/onrc/onos/api/intent/IntentId.java
deleted file mode 100644
index 5de5a12..0000000
--- a/src/main/java/net/onrc/onos/api/intent/IntentId.java
+++ /dev/null
@@ -1,51 +0,0 @@
-package net.onrc.onos.api.intent;
-
-import net.onrc.onos.api.batchoperation.BatchOperationTarget;
-
-/**
- * The class representing intent's ID.
- *
- * <p>
- * This class is immutable.
- * </p>
- */
-public final class IntentId implements BatchOperationTarget {
- private final long id;
-
- /**
- * Constructs the ID corresponding to a given long value.
- *
- * <p>
- * In the future, this constructor will not be exposed to avoid misuses.
- * </p>
- *
- * @param id the underlay value of this ID.
- */
- public IntentId(long id) {
- this.id = id;
- }
-
- @Override
- public int hashCode() {
- return (int) (id ^ (id >>> 32));
- }
-
- @Override
- public boolean equals(Object obj) {
- if (obj == this) {
- return true;
- }
-
- if (!(obj instanceof IntentId)) {
- return false;
- }
-
- IntentId that = (IntentId) obj;
- return this.id == that.id;
- }
-
- @Override
- public String toString() {
- return "0x" + Long.toHexString(id);
- }
-}
diff --git a/src/main/java/net/onrc/onos/api/intent/IntentInstaller.java b/src/main/java/net/onrc/onos/api/intent/IntentInstaller.java
deleted file mode 100644
index 3b8085a..0000000
--- a/src/main/java/net/onrc/onos/api/intent/IntentInstaller.java
+++ /dev/null
@@ -1,24 +0,0 @@
-package net.onrc.onos.api.intent;
-
-/**
- * An interface to handle installation and removal of a specific type of intent.
- *
- * @param <T> the type of intent this installer handles.
- */
-public interface IntentInstaller<T extends Intent> {
- /**
- * Installs the given intent.
- *
- * @param intent the intent to be installed.
- * @return true if the installation succeeds. Otherwise, false.
- */
- public boolean install(T intent);
-
- /**
- * Removes the given intent.
- *
- * @param intent the intent to be removed.
- * @return true if the removal succeeds. Otherwise, false.
- */
- public boolean remove(T intent);
-}
diff --git a/src/main/java/net/onrc/onos/api/intent/IntentResolutionException.java b/src/main/java/net/onrc/onos/api/intent/IntentResolutionException.java
deleted file mode 100644
index 5b90f27..0000000
--- a/src/main/java/net/onrc/onos/api/intent/IntentResolutionException.java
+++ /dev/null
@@ -1,7 +0,0 @@
-package net.onrc.onos.api.intent;
-
-/**
- * The base class of an exception thrown during intent resolution.
- */
-public class IntentResolutionException extends Exception {
-}
diff --git a/src/main/java/net/onrc/onos/api/intent/IntentResolver.java b/src/main/java/net/onrc/onos/api/intent/IntentResolver.java
deleted file mode 100644
index a27cc57..0000000
--- a/src/main/java/net/onrc/onos/api/intent/IntentResolver.java
+++ /dev/null
@@ -1,26 +0,0 @@
-package net.onrc.onos.api.intent;
-
-import java.util.List;
-
-/**
- * An interface to translate an intent to lower level intents.
- *
- * <p>
- * IntentResolvers are registered to {@link IIntentRuntimeService} to handle translations of intents
- * (we call it intent resolution).
- * </p>
- *
- * @param <T> the type of intent this resolver translates
- */
-public interface IntentResolver<T extends Intent> {
- /**
- * Returns lower level intents, into which the given intent is translated.
- *
- * This method is invoked by the Intent Framework when the framework find an unresolved intent.
- *
- * @param intent the intent to be translated.
- * @return lower level intents, into which the given intent is translated.
- * @throws IntentResolutionException if this method can't resolve the intent.
- */
- public List<Intent> resolve(T intent) throws IntentResolutionException;
-}
diff --git a/src/main/java/net/onrc/onos/api/newintent/Intent.java b/src/main/java/net/onrc/onos/api/newintent/Intent.java
index 009725c..671ad30 100644
--- a/src/main/java/net/onrc/onos/api/newintent/Intent.java
+++ b/src/main/java/net/onrc/onos/api/newintent/Intent.java
@@ -1,11 +1,13 @@
package net.onrc.onos.api.newintent;
+import net.onrc.onos.api.batchoperation.BatchOperationTarget;
+
/**
* Abstraction of an application level intent.
*
* Make sure that an Intent should be immutable when a new type is defined.
*/
-public interface Intent {
+public interface Intent extends BatchOperationTarget {
/**
* Returns the intent identifier.
*
diff --git a/src/main/java/net/onrc/onos/api/intent/IntentBatchOperation.java b/src/main/java/net/onrc/onos/api/newintent/IntentBatchOperation.java
similarity index 96%
rename from src/main/java/net/onrc/onos/api/intent/IntentBatchOperation.java
rename to src/main/java/net/onrc/onos/api/newintent/IntentBatchOperation.java
index b5ca1aa..0e34deb 100644
--- a/src/main/java/net/onrc/onos/api/intent/IntentBatchOperation.java
+++ b/src/main/java/net/onrc/onos/api/newintent/IntentBatchOperation.java
@@ -1,4 +1,4 @@
-package net.onrc.onos.api.intent;
+package net.onrc.onos.api.newintent;
import net.onrc.onos.api.batchoperation.BatchOperation;
import net.onrc.onos.api.batchoperation.BatchOperationEntry;
diff --git a/src/main/java/net/onrc/onos/api/newintent/IntentId.java b/src/main/java/net/onrc/onos/api/newintent/IntentId.java
index 6d10b35..b7cdb01 100644
--- a/src/main/java/net/onrc/onos/api/newintent/IntentId.java
+++ b/src/main/java/net/onrc/onos/api/newintent/IntentId.java
@@ -1,11 +1,13 @@
package net.onrc.onos.api.newintent;
+import net.onrc.onos.api.batchoperation.BatchOperationTarget;
+
/**
* Intent identifier suitable as an external key.
*
* This class is immutable.
*/
-public final class IntentId {
+public final class IntentId implements BatchOperationTarget {
private static final int DEC = 10;
private static final int HEX = 16;
diff --git a/src/main/java/net/onrc/onos/api/intent/IntentIdGenerator.java b/src/main/java/net/onrc/onos/api/newintent/IntentIdGenerator.java
similarity index 93%
rename from src/main/java/net/onrc/onos/api/intent/IntentIdGenerator.java
rename to src/main/java/net/onrc/onos/api/newintent/IntentIdGenerator.java
index 7bfd906..ec75c7b 100644
--- a/src/main/java/net/onrc/onos/api/intent/IntentIdGenerator.java
+++ b/src/main/java/net/onrc/onos/api/newintent/IntentIdGenerator.java
@@ -1,4 +1,4 @@
-package net.onrc.onos.api.intent;
+package net.onrc.onos.api.newintent;
/**
* This interface is for generator of IntentId.
diff --git a/src/main/java/net/onrc/onos/api/newintent/IntentState.java b/src/main/java/net/onrc/onos/api/newintent/IntentState.java
index f272320..65310ee 100644
--- a/src/main/java/net/onrc/onos/api/newintent/IntentState.java
+++ b/src/main/java/net/onrc/onos/api/newintent/IntentState.java
@@ -36,7 +36,7 @@
/**
* The intent is being withdrawn.
*
- * When {@link net.onrc.onos.api.newintent.IntentService#withdraw(Intent)} is called,
+ * When {@link IntentService#withdraw(Intent)} is called,
* the intent takes this state first.
*/
WITHDRAWING,
diff --git a/src/main/java/net/onrc/onos/api/intent/OpticalConnectivityIntent.java b/src/main/java/net/onrc/onos/api/newintent/OpticalConnectivityIntent.java
similarity index 87%
rename from src/main/java/net/onrc/onos/api/intent/OpticalConnectivityIntent.java
rename to src/main/java/net/onrc/onos/api/newintent/OpticalConnectivityIntent.java
index 256fa44..174d8c0 100644
--- a/src/main/java/net/onrc/onos/api/intent/OpticalConnectivityIntent.java
+++ b/src/main/java/net/onrc/onos/api/newintent/OpticalConnectivityIntent.java
@@ -1,7 +1,8 @@
-package net.onrc.onos.api.intent;
+package net.onrc.onos.api.newintent;
import net.onrc.onos.core.util.SwitchPort;
+// TODO: consider if this intent should be sub-class of ConnectivityIntent
/**
* An optical layer Intent for a connectivity from a transponder port to another
* transponder port.
@@ -10,7 +11,7 @@
* ports and assign lambda automatically. The lambda can be specified using
* OpticalPathFlow class.
*/
-public class OpticalConnectivityIntent extends Intent {
+public class OpticalConnectivityIntent extends AbstractIntent {
protected SwitchPort srcSwitchPort;
protected SwitchPort dstSwitchPort;
diff --git a/src/main/java/net/onrc/onos/api/intent/PacketConnectivityIntent.java b/src/main/java/net/onrc/onos/api/newintent/PacketConnectivityIntent.java
similarity index 96%
rename from src/main/java/net/onrc/onos/api/intent/PacketConnectivityIntent.java
rename to src/main/java/net/onrc/onos/api/newintent/PacketConnectivityIntent.java
index 77a2a13..e03166c 100644
--- a/src/main/java/net/onrc/onos/api/intent/PacketConnectivityIntent.java
+++ b/src/main/java/net/onrc/onos/api/newintent/PacketConnectivityIntent.java
@@ -1,4 +1,4 @@
-package net.onrc.onos.api.intent;
+package net.onrc.onos.api.newintent;
import net.onrc.onos.core.matchaction.match.PacketMatch;
import net.onrc.onos.core.util.SwitchPort;
@@ -8,6 +8,7 @@
import java.util.HashSet;
import java.util.Set;
+// TODO: consider if this intent should be sub-class of Connectivity intent
/**
* A packet layer Intent for a connectivity from a set of ports to a set of
* ports.
@@ -16,7 +17,7 @@
* NOTE: Should this class support modifier methods? Should this object a
* read-only object?
*/
-public class PacketConnectivityIntent extends Intent {
+public class PacketConnectivityIntent extends AbstractIntent {
protected Set<SwitchPort> srcSwitchPorts;
protected PacketMatch match;
protected Set<SwitchPort> dstSwitchPorts;