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;
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/IntentManager.java b/core/net/src/main/java/org/onosproject/net/intent/impl/IntentManager.java
index 2b83fa8..da13b76 100644
--- a/core/net/src/main/java/org/onosproject/net/intent/impl/IntentManager.java
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/IntentManager.java
@@ -15,8 +15,10 @@
*/
package org.onosproject.net.intent.impl;
+import com.google.common.collect.ImmutableSet;
import org.onlab.util.Tools;
import org.onosproject.cfg.ComponentConfigService;
+import org.onosproject.core.ApplicationId;
import org.onosproject.core.CoreService;
import org.onosproject.core.IdGenerator;
import org.onosproject.event.AbstractListenerManager;
@@ -87,8 +89,7 @@
import static org.onosproject.net.intent.constraint.PartialFailureConstraint.intentAllowsPartialFailure;
import static org.onosproject.net.intent.impl.phase.IntentProcessPhase.newInitialPhase;
import static org.onosproject.security.AppGuard.checkPermission;
-import static org.onosproject.security.AppPermission.Type.INTENT_READ;
-import static org.onosproject.security.AppPermission.Type.INTENT_WRITE;
+import static org.onosproject.security.AppPermission.Type.*;
import static org.slf4j.LoggerFactory.getLogger;
/**
@@ -291,6 +292,20 @@
}
@Override
+ public Iterable<Intent> getIntentsByAppId(ApplicationId id) {
+ checkPermission(INTENT_READ);
+
+ ImmutableSet.Builder<Intent> builder = ImmutableSet.builder();
+ for (Intent intent : store.getIntents()) {
+ if (intent.appId().equals(id)) {
+ builder.add(intent);
+ }
+ }
+
+ return builder.build();
+ }
+
+ @Override
public void addPending(IntentData intentData) {
checkPermission(INTENT_WRITE);
checkNotNull(intentData, INTENT_NULL);
diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/IntentManagerTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/IntentManagerTest.java
index 14fb380..db92800 100644
--- a/core/net/src/test/java/org/onosproject/net/intent/impl/IntentManagerTest.java
+++ b/core/net/src/test/java/org/onosproject/net/intent/impl/IntentManagerTest.java
@@ -32,6 +32,7 @@
import org.onosproject.common.event.impl.TestEventDispatcher;
import org.onosproject.core.ApplicationId;
import org.onosproject.core.impl.TestCoreManager;
+import org.onosproject.net.NetTestTools;
import org.onosproject.net.NetworkResource;
import org.onosproject.net.flow.FlowRuleOperations;
import org.onosproject.net.flow.FlowRuleOperationsContext;
@@ -557,8 +558,8 @@
intents = Lists.newArrayList(service.getIntents());
assertThat(intents, hasSize(0));
- final MockIntent intent1 = new MockIntent(MockIntent.nextId());
- final MockIntent intent2 = new MockIntent(MockIntent.nextId());
+ final MockIntent intent1 = new MockIntent(MockIntent.nextId(), NetTestTools.APP_ID);
+ final MockIntent intent2 = new MockIntent(MockIntent.nextId(), NetTestTools.APP_ID_2);
listener.setLatch(2, Type.INSTALL_REQ);
listener.setLatch(2, Type.INSTALLED);
@@ -575,6 +576,15 @@
assertThat(intents, hasIntentWithId(intent1.id()));
assertThat(intents, hasIntentWithId(intent2.id()));
verifyState();
+
+ List<Intent> intentsAppId = Lists.newArrayList(service.getIntentsByAppId(NetTestTools.APP_ID));
+ assertThat(intentsAppId, hasSize(1));
+ assertThat(intentsAppId, hasIntentWithId(intent1.id()));
+
+ List<Intent> intentsAppId2 = Lists.newArrayList(service.getIntentsByAppId(NetTestTools.APP_ID_2));
+ assertThat(intentsAppId2, hasSize(1));
+ assertThat(intentsAppId2, hasIntentWithId(intent2.id()));
+ verifyState();
}
/**