ONOS-6245:Intent_mini_summary
Change-Id: I35fe2b5b3f2a24680bbef93ee31e4655b972ff45
diff --git a/web/api/src/main/java/org/onosproject/rest/resources/IntentsWebResource.java b/web/api/src/main/java/org/onosproject/rest/resources/IntentsWebResource.java
index 409dcc3..675581d 100644
--- a/web/api/src/main/java/org/onosproject/rest/resources/IntentsWebResource.java
+++ b/web/api/src/main/java/org/onosproject/rest/resources/IntentsWebResource.java
@@ -31,6 +31,7 @@
import org.onosproject.net.intent.IntentService;
import org.onosproject.net.intent.Key;
import org.onosproject.net.intent.util.IntentFilter;
+import org.onosproject.net.intent.util.IntentMiniSummary;
import org.onosproject.rest.AbstractWebResource;
import org.slf4j.Logger;
@@ -49,6 +50,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
+import java.util.Map;
import java.util.Objects;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
@@ -97,6 +99,29 @@
return ok(root).build();
}
+
+ /**
+ * Gets Summary of all intents.
+ * Returns Summary of the intents in the system.
+ *
+ * @return 200 OK with Summary of all the intents in the system
+ * @onos.rsModel Minisummary
+ */
+ @GET
+ @Produces(MediaType.APPLICATION_JSON)
+ @Path("minisummary")
+ public Response getIntentSummary() {
+ final Iterable<Intent> intents = get(IntentService.class).getIntents();
+ ObjectNode root = mapper().createObjectNode();
+ IntentMiniSummary intentminisummary = new IntentMiniSummary();
+ Map<String, IntentMiniSummary> map = intentminisummary.summarize(intents, get(IntentService.class));
+ map.values().stream().forEach(intentsummary -> {
+ root.put(intentsummary.getIntentType(), codec(IntentMiniSummary.class).encode(intentsummary, this));
+ });
+ return ok(root).build();
+ }
+
+
/**
* Gets intent intallables by application ID and key.
* @param appId application identifier
diff --git a/web/api/src/main/resources/definitions/Minisummary.json b/web/api/src/main/resources/definitions/Minisummary.json
new file mode 100644
index 0000000..9bf1c33
--- /dev/null
+++ b/web/api/src/main/resources/definitions/Minisummary.json
@@ -0,0 +1,70 @@
+{
+ "type": "object",
+ "title":"All",
+ "required": [
+ "All"
+ ],
+ "properties": {
+ "All": {
+ "required": [
+ "total",
+ "installed",
+ "failed",
+ "installReq",
+ "installing",
+ "compiling",
+ "recompiling",
+ "withdrawReq",
+ "withdrawing",
+ "withdrawn",
+ "unknownState"
+ ],
+ "properties": {
+ "total": {
+ "type": "integer",
+ "example": 1
+ },
+ "installed": {
+ "type": "integer",
+ "example": 0
+ },
+ "failed": {
+ "type": "integer",
+ "example": 0
+ },
+ "installReq": {
+ "type": "integer",
+ "example": 0
+ },
+ "installing": {
+ "type": "integer",
+ "example": 0
+ },
+ "compiling": {
+ "type": "integer",
+ "example": 0
+ },
+ "recompiling": {
+ "type": "integer",
+ "example": 0
+ },
+ "withdrawReq": {
+ "type": "integer",
+ "example": 0
+ },
+ "withdrawing": {
+ "type": "integer",
+ "example": 0
+ },
+ "withdrawn": {
+ "type": "integer",
+ "example": 0
+ },
+ "unknownState": {
+ "type": "integer",
+ "example": 0
+ }
+ }
+ }
+ }
+}
diff --git a/web/api/src/test/java/org/onosproject/rest/resources/IntentsResourceTest.java b/web/api/src/test/java/org/onosproject/rest/resources/IntentsResourceTest.java
index c9c5c1f..ea1fc47 100644
--- a/web/api/src/test/java/org/onosproject/rest/resources/IntentsResourceTest.java
+++ b/web/api/src/test/java/org/onosproject/rest/resources/IntentsResourceTest.java
@@ -65,6 +65,7 @@
import org.onosproject.net.intent.MockIdGenerator;
import org.onosproject.net.provider.ProviderId;
+
import javax.ws.rs.NotFoundException;
import javax.ws.rs.client.Entity;
import javax.ws.rs.client.WebTarget;
@@ -476,7 +477,7 @@
/**
* Factory to allocate an IntentRelatedFlows matcher.
*
- * @param pathEntries list of path conatining flow entries of a particular intent
+ * @param pathEntries list of path conatining flow entries of a particular intent
* @param expectedAppId expected app id we are looking for
* @return matcher
*/
@@ -735,7 +736,7 @@
.andReturn(IntentState.INSTALLED)
.anyTimes();
// Register the services needed for the test
- final CodecManager codecService = new CodecManager();
+ final CodecManager codecService = new CodecManager();
codecService.activate();
ServiceDirectory testDirectory =
new TestServiceDirectory()
@@ -1116,4 +1117,30 @@
assertThat(response.getStatus(), is(HttpURLConnection.HTTP_NO_CONTENT));
}
+ @Test
+ public void testIntentsMiniSummary() {
+ final Intent intent1 = new MockIntent(1L, Collections.emptyList());
+ final HashSet<NetworkResource> resources = new HashSet<>();
+ resources.add(new MockResource(1));
+ resources.add(new MockResource(2));
+ resources.add(new MockResource(3));
+ final Intent intent2 = new MockIntent(2L, resources);
+ intents.add(intent1);
+ intents.add(intent2);
+ final WebTarget wt = target();
+ replay(mockIntentService);
+ final String response = wt.path("intents/minisummary").request().get(String.class);
+ assertThat(response, containsString("{\"All\":{"));
+ final JsonObject result = Json.parse(response).asObject();
+ assertThat(result, notNullValue());
+ assertThat(result.names(), hasSize(2));
+ assertThat(result.names().get(0), containsString("All"));
+ JsonObject jsonIntents = (JsonObject) result.get("All");
+ assertThat(jsonIntents, notNullValue());
+ assertThat(jsonIntents.get("total").toString(), containsString("2"));
+ jsonIntents = (JsonObject) result.get("Mock");
+ assertThat(jsonIntents, notNullValue());
+ assertThat(jsonIntents.get("installed").toString(), containsString("2"));
+ }
}
+