Enhanced toString for intents for consistency.
Removed ID block allocator stuff.
diff --git a/cli/src/main/java/org/onlab/onos/cli/net/IntentsListCommand.java b/cli/src/main/java/org/onlab/onos/cli/net/IntentsListCommand.java
index a0c9845..e200cd0 100644
--- a/cli/src/main/java/org/onlab/onos/cli/net/IntentsListCommand.java
+++ b/cli/src/main/java/org/onlab/onos/cli/net/IntentsListCommand.java
@@ -18,7 +18,8 @@
IntentService service = get(IntentService.class);
for (Intent intent : service.getIntents()) {
IntentState state = service.getIntentState(intent.id());
- print("%s %s %s", intent.id(), state, intent);
+ print("id=%s, state=%s, appId=%s, %s",
+ intent.id(), state, intent.appId().name(), intent);
}
}
diff --git a/core/api/src/main/java/org/onlab/onos/net/intent/ConnectivityIntent.java b/core/api/src/main/java/org/onlab/onos/net/intent/ConnectivityIntent.java
index e28d8b1..8d634a4 100644
--- a/core/api/src/main/java/org/onlab/onos/net/intent/ConnectivityIntent.java
+++ b/core/api/src/main/java/org/onlab/onos/net/intent/ConnectivityIntent.java
@@ -73,7 +73,12 @@
return treatment;
}
-
+ /**
+ * Produces a collection of network resources from the given links.
+ *
+ * @param links collection of links
+ * @return collection of link resources
+ */
protected static Collection<NetworkResource> resources(Collection<Link> links) {
return ImmutableSet.<NetworkResource>copyOf(links);
}
diff --git a/core/api/src/main/java/org/onlab/onos/net/intent/HostToHostIntent.java b/core/api/src/main/java/org/onlab/onos/net/intent/HostToHostIntent.java
index 7177d3f..83fe92a 100644
--- a/core/api/src/main/java/org/onlab/onos/net/intent/HostToHostIntent.java
+++ b/core/api/src/main/java/org/onlab/onos/net/intent/HostToHostIntent.java
@@ -66,6 +66,7 @@
public String toString() {
return MoreObjects.toStringHelper(getClass())
.add("id", id())
+ .add("appId", appId())
.add("selector", selector())
.add("treatment", treatment())
.add("one", one)
diff --git a/core/api/src/main/java/org/onlab/onos/net/intent/IdGenerator.java b/core/api/src/main/java/org/onlab/onos/net/intent/IdGenerator.java
deleted file mode 100644
index 62549e9..0000000
--- a/core/api/src/main/java/org/onlab/onos/net/intent/IdGenerator.java
+++ /dev/null
@@ -1,19 +0,0 @@
-package org.onlab.onos.net.intent;
-
-/**
- * A generalized interface for ID generation
- * <p/>
- * {@link #getNewId()} generates a globally unique ID instance on
- * each invocation.
- *
- * @param <T> the type of ID
- */
-@Deprecated
-public interface IdGenerator<T> {
- /**
- * Returns a globally unique ID instance.
- *
- * @return globally unique ID instance
- */
- T getNewId();
-}
diff --git a/core/api/src/main/java/org/onlab/onos/net/intent/LinkCollectionIntent.java b/core/api/src/main/java/org/onlab/onos/net/intent/LinkCollectionIntent.java
index 7a19613..4c193ee 100644
--- a/core/api/src/main/java/org/onlab/onos/net/intent/LinkCollectionIntent.java
+++ b/core/api/src/main/java/org/onlab/onos/net/intent/LinkCollectionIntent.java
@@ -78,8 +78,9 @@
public String toString() {
return MoreObjects.toStringHelper(getClass())
.add("id", id())
- .add("match", selector())
- .add("action", treatment())
+ .add("appId", appId())
+ .add("selector", selector())
+ .add("treatment", treatment())
.add("links", links())
.add("egress", egressPoint())
.toString();
diff --git a/core/api/src/main/java/org/onlab/onos/net/intent/MultiPointToSinglePointIntent.java b/core/api/src/main/java/org/onlab/onos/net/intent/MultiPointToSinglePointIntent.java
index a09291f..7c638aa 100644
--- a/core/api/src/main/java/org/onlab/onos/net/intent/MultiPointToSinglePointIntent.java
+++ b/core/api/src/main/java/org/onlab/onos/net/intent/MultiPointToSinglePointIntent.java
@@ -81,10 +81,11 @@
public String toString() {
return MoreObjects.toStringHelper(getClass())
.add("id", id())
- .add("match", selector())
- .add("action", treatment())
- .add("ingressPoints", ingressPoints())
- .add("egressPoint", egressPoint())
+ .add("appId", appId())
+ .add("selector", selector())
+ .add("treatment", treatment())
+ .add("ingress", ingressPoints())
+ .add("egress", egressPoint())
.toString();
}
}
diff --git a/core/api/src/main/java/org/onlab/onos/net/intent/PathIntent.java b/core/api/src/main/java/org/onlab/onos/net/intent/PathIntent.java
index 4138172..1e41120 100644
--- a/core/api/src/main/java/org/onlab/onos/net/intent/PathIntent.java
+++ b/core/api/src/main/java/org/onlab/onos/net/intent/PathIntent.java
@@ -56,8 +56,9 @@
public String toString() {
return MoreObjects.toStringHelper(getClass())
.add("id", id())
- .add("match", selector())
- .add("action", treatment())
+ .add("appId", appId())
+ .add("selector", selector())
+ .add("treatment", treatment())
.add("path", path)
.toString();
}
diff --git a/core/api/src/main/java/org/onlab/onos/net/intent/PointToPointIntent.java b/core/api/src/main/java/org/onlab/onos/net/intent/PointToPointIntent.java
index fa206bc..d170c27 100644
--- a/core/api/src/main/java/org/onlab/onos/net/intent/PointToPointIntent.java
+++ b/core/api/src/main/java/org/onlab/onos/net/intent/PointToPointIntent.java
@@ -69,10 +69,11 @@
public String toString() {
return MoreObjects.toStringHelper(getClass())
.add("id", id())
- .add("match", selector())
- .add("action", treatment())
- .add("ingressPoint", ingressPoint)
- .add("egressPoints", egressPoint)
+ .add("appId", appId())
+ .add("selector", selector())
+ .add("treatment", treatment())
+ .add("ingress", ingressPoint)
+ .add("egress", egressPoint)
.toString();
}
diff --git a/core/api/src/main/java/org/onlab/onos/net/intent/SinglePointToMultiPointIntent.java b/core/api/src/main/java/org/onlab/onos/net/intent/SinglePointToMultiPointIntent.java
index 7e40cdc..62e36e7 100644
--- a/core/api/src/main/java/org/onlab/onos/net/intent/SinglePointToMultiPointIntent.java
+++ b/core/api/src/main/java/org/onlab/onos/net/intent/SinglePointToMultiPointIntent.java
@@ -77,10 +77,11 @@
public String toString() {
return MoreObjects.toStringHelper(getClass())
.add("id", id())
- .add("match", selector())
- .add("action", treatment())
- .add("ingressPoint", ingressPoint)
- .add("egressPort", egressPoints)
+ .add("appId", appId())
+ .add("selector", selector())
+ .add("treatment", treatment())
+ .add("ingress", ingressPoint)
+ .add("egress", egressPoints)
.toString();
}
diff --git a/core/api/src/test/java/org/onlab/onos/net/intent/IntentIdGenerator.java b/core/api/src/test/java/org/onlab/onos/net/intent/IntentIdGenerator.java
deleted file mode 100644
index 0ca669b..0000000
--- a/core/api/src/test/java/org/onlab/onos/net/intent/IntentIdGenerator.java
+++ /dev/null
@@ -1,14 +0,0 @@
-package org.onlab.onos.net.intent;
-
-/**
- * This interface is for generator of IntentId. It is defined only for
- * testing purpose to keep type safety on mock creation.
- *
- * <p>
- * {@link #getNewId()} generates a globally unique {@link IntentId} instance
- * on each invocation. Application developers should not generate IntentId
- * by themselves. Instead use an implementation of this interface.
- * </p>
- */
-public interface IntentIdGenerator extends IdGenerator<IntentId> {
-}
diff --git a/core/net/src/main/java/org/onlab/onos/net/intent/impl/AbstractBlockAllocatorBasedIdGenerator.java b/core/net/src/main/java/org/onlab/onos/net/intent/impl/AbstractBlockAllocatorBasedIdGenerator.java
deleted file mode 100644
index 00b64da..0000000
--- a/core/net/src/main/java/org/onlab/onos/net/intent/impl/AbstractBlockAllocatorBasedIdGenerator.java
+++ /dev/null
@@ -1,42 +0,0 @@
-package org.onlab.onos.net.intent.impl;
-
-import org.onlab.onos.net.intent.IdGenerator;
-
-/**
- * Base class of {@link IdGenerator} implementations which use {@link IdBlockAllocator} as
- * backend.
- *
- * @param <T> the type of ID
- */
-public abstract class AbstractBlockAllocatorBasedIdGenerator<T> implements IdGenerator<T> {
- protected final IdBlockAllocator allocator;
- protected IdBlock idBlock;
-
- /**
- * Constructs an ID generator which use {@link IdBlockAllocator} as backend.
- *
- * @param allocator
- */
- protected AbstractBlockAllocatorBasedIdGenerator(IdBlockAllocator allocator) {
- this.allocator = allocator;
- this.idBlock = allocator.allocateUniqueIdBlock();
- }
-
- @Override
- public synchronized T getNewId() {
- try {
- return convertFrom(idBlock.getNextId());
- } catch (UnavailableIdException e) {
- idBlock = allocator.allocateUniqueIdBlock();
- return convertFrom(idBlock.getNextId());
- }
- }
-
- /**
- * Returns an ID instance of {@code T} type from the long value.
- *
- * @param value original long value
- * @return ID instance
- */
- protected abstract T convertFrom(long value);
-}
diff --git a/core/net/src/main/java/org/onlab/onos/net/intent/impl/DummyIdBlockAllocator.java b/core/net/src/main/java/org/onlab/onos/net/intent/impl/DummyIdBlockAllocator.java
deleted file mode 100644
index f331aa2..0000000
--- a/core/net/src/main/java/org/onlab/onos/net/intent/impl/DummyIdBlockAllocator.java
+++ /dev/null
@@ -1,31 +0,0 @@
-package org.onlab.onos.net.intent.impl;
-
-public class DummyIdBlockAllocator implements IdBlockAllocator {
- private long blockTop;
- private static final long BLOCK_SIZE = 0x1000000L;
-
- /**
- * Returns a block of IDs which are unique and unused.
- * Range of IDs is fixed size and is assigned incrementally as this method
- * called.
- *
- * @return an IdBlock containing a set of unique IDs
- */
- @Override
- public IdBlock allocateUniqueIdBlock() {
- synchronized (this) {
- long blockHead = blockTop;
- long blockTail = blockTop + BLOCK_SIZE;
-
- IdBlock block = new IdBlock(blockHead, BLOCK_SIZE);
- blockTop = blockTail;
-
- return block;
- }
- }
-
- @Override
- public IdBlock allocateUniqueIdBlock(long range) {
- throw new UnsupportedOperationException("Not supported yet");
- }
-}
diff --git a/core/net/src/main/java/org/onlab/onos/net/intent/impl/IdBlock.java b/core/net/src/main/java/org/onlab/onos/net/intent/impl/IdBlock.java
deleted file mode 100644
index ce418ea..0000000
--- a/core/net/src/main/java/org/onlab/onos/net/intent/impl/IdBlock.java
+++ /dev/null
@@ -1,111 +0,0 @@
-package org.onlab.onos.net.intent.impl;
-
-import static com.google.common.base.Preconditions.checkArgument;
-
-import java.util.Objects;
-import java.util.concurrent.atomic.AtomicLong;
-
-import com.google.common.base.MoreObjects;
-
-/**
- * A class representing an ID space.
- */
-public final class IdBlock {
- private final long start;
- private final long size;
-
- private final AtomicLong currentId;
-
- /**
- * Constructs a new ID block with the specified size and initial value.
- *
- * @param start initial value of the block
- * @param size size of the block
- * @throws IllegalArgumentException if the size is less than or equal to 0
- */
- public IdBlock(long start, long size) {
- checkArgument(size > 0, "size should be more than 0, but %s", size);
-
- this.start = start;
- this.size = size;
-
- this.currentId = new AtomicLong(start);
- }
-
- // TODO: consider if this method is needed or not
- /**
- * Returns the initial value.
- *
- * @return initial value
- */
- public long getStart() {
- return start;
- }
-
- // TODO: consider if this method is needed or not
- /**
- * Returns the last value.
- *
- * @return last value
- */
- public long getEnd() {
- return start + size - 1;
- }
-
- /**
- * Returns the block size.
- *
- * @return block size
- */
- public long getSize() {
- return size;
- }
-
- /**
- * Returns the next ID in the block.
- *
- * @return next ID
- * @throws UnavailableIdException if there is no available ID in the block.
- */
- public long getNextId() {
- final long id = currentId.getAndIncrement();
- if (id > getEnd()) {
- throw new UnavailableIdException(String.format(
- "used all IDs in allocated space (size: %d, end: %d, current: %d)",
- size, getEnd(), id
- ));
- }
-
- return id;
- }
-
- // TODO: Do we really need equals and hashCode? Should it contain currentId?
- @Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
- if (o == null || getClass() != o.getClass()) {
- return false;
- }
-
- IdBlock that = (IdBlock) o;
- return Objects.equals(this.start, that.start)
- && Objects.equals(this.size, that.size)
- && Objects.equals(this.currentId.get(), that.currentId.get());
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(start, size, currentId);
- }
-
- @Override
- public String toString() {
- return MoreObjects.toStringHelper(getClass())
- .add("start", start)
- .add("size", size)
- .add("currentId", currentId)
- .toString();
- }
-}
diff --git a/core/net/src/main/java/org/onlab/onos/net/intent/impl/IdBlockAllocator.java b/core/net/src/main/java/org/onlab/onos/net/intent/impl/IdBlockAllocator.java
deleted file mode 100644
index 1adac02..0000000
--- a/core/net/src/main/java/org/onlab/onos/net/intent/impl/IdBlockAllocator.java
+++ /dev/null
@@ -1,21 +0,0 @@
-package org.onlab.onos.net.intent.impl;
-
-/**
- * An interface that gives unique ID spaces.
- */
-public interface IdBlockAllocator {
- /**
- * Allocates a unique Id Block.
- *
- * @return Id Block.
- */
- IdBlock allocateUniqueIdBlock();
-
- /**
- * Allocates next unique id and retrieve a new range of ids if needed.
- *
- * @param range range to use for the identifier
- * @return Id Block.
- */
- IdBlock allocateUniqueIdBlock(long range);
-}