Return intent collection with details
Added backwards compatible flag to GET /intents/ to return full intent JSON.
Added GET /intents/application/{appId} to return application specifc intents.
Extended IntentService to include getIntentsByAppId(appId).
Removed hard-coded intent codec lookup in IntentWebResource.
Change-Id: I38e7b1dbd7669e654afe723f6ec3a4eb7a9af6fb
diff --git a/core/api/src/main/java/org/onosproject/net/intent/IntentService.java b/core/api/src/main/java/org/onosproject/net/intent/IntentService.java
index 595e7e3..745d7f4 100644
--- a/core/api/src/main/java/org/onosproject/net/intent/IntentService.java
+++ b/core/api/src/main/java/org/onosproject/net/intent/IntentService.java
@@ -17,6 +17,7 @@
import com.google.common.annotations.Beta;
+import org.onosproject.core.ApplicationId;
import org.onosproject.event.ListenerService;
import java.util.List;
@@ -72,6 +73,14 @@
Iterable<Intent> getIntents();
/**
+ * Returns an iterable of all intents with this application ID.
+ *
+ * @param id the application ID to look up
+ * @return collection of intents
+ */
+ Iterable<Intent> getIntentsByAppId(ApplicationId id);
+
+ /**
* Adds an intent data object to the pending map for processing.
* <p>
* This method is intended to only be called by core components, not
diff --git a/core/api/src/test/java/org/onosproject/net/intent/FakeIntentManager.java b/core/api/src/test/java/org/onosproject/net/intent/FakeIntentManager.java
index e3e6277..870ad0b 100644
--- a/core/api/src/test/java/org/onosproject/net/intent/FakeIntentManager.java
+++ b/core/api/src/test/java/org/onosproject/net/intent/FakeIntentManager.java
@@ -16,6 +16,7 @@
package org.onosproject.net.intent;
import com.google.common.collect.ImmutableMap;
+import org.onosproject.core.ApplicationId;
import java.util.ArrayList;
import java.util.Collections;
@@ -26,6 +27,7 @@
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
+import java.util.stream.Collectors;
/**
* Fake implementation of the intent service to assist in developing tests of
@@ -179,6 +181,15 @@
}
@Override
+ public Set<Intent> getIntentsByAppId(ApplicationId id) {
+ return Collections.unmodifiableSet(
+ intents.values().stream()
+ .filter(intent -> intent.appId().equals(id))
+ .collect(Collectors.toSet())
+ );
+ }
+
+ @Override
public void addPending(IntentData intentData) {
throw new UnsupportedOperationException();
}
diff --git a/core/api/src/test/java/org/onosproject/net/intent/IntentServiceAdapter.java b/core/api/src/test/java/org/onosproject/net/intent/IntentServiceAdapter.java
index 8503447..17f489e 100644
--- a/core/api/src/test/java/org/onosproject/net/intent/IntentServiceAdapter.java
+++ b/core/api/src/test/java/org/onosproject/net/intent/IntentServiceAdapter.java
@@ -16,6 +16,8 @@
package org.onosproject.net.intent;
+import org.onosproject.core.ApplicationId;
+
import java.util.List;
/**
@@ -43,6 +45,11 @@
}
@Override
+ public Iterable<Intent> getIntentsByAppId(ApplicationId id) {
+ return null;
+ }
+
+ @Override
public void addPending(IntentData intentData) {
}
diff --git a/core/api/src/test/java/org/onosproject/net/intent/IntentTestsMocks.java b/core/api/src/test/java/org/onosproject/net/intent/IntentTestsMocks.java
index 642830e..bdfa106 100644
--- a/core/api/src/test/java/org/onosproject/net/intent/IntentTestsMocks.java
+++ b/core/api/src/test/java/org/onosproject/net/intent/IntentTestsMocks.java
@@ -19,6 +19,7 @@
import com.google.common.collect.Sets;
import org.onlab.graph.ScalarWeight;
import org.onlab.graph.Weight;
+import org.onosproject.core.ApplicationId;
import org.onosproject.core.GroupId;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.DefaultLink;
@@ -557,6 +558,12 @@
this.number = number;
}
+ public MockIntent(Long number, ApplicationId appId) {
+ super(appId, null, Collections.emptyList(),
+ Intent.DEFAULT_INTENT_PRIORITY, null);
+ this.number = number;
+ }
+
public MockIntent(Long number, Collection<NetworkResource> resources) {
super(NetTestTools.APP_ID, null, resources, Intent.DEFAULT_INTENT_PRIORITY, null);
this.number = number;