[ONOS-4409] Support applicationId registration and query via REST
With this commit, we can register and query on/off platform
applications through REST API.
Change-Id: I82e1e0e55bbc017d6c0cce7d9a6af7a578d7196e
diff --git a/web/api/src/main/java/org/onosproject/rest/resources/ApplicationsWebResource.java b/web/api/src/main/java/org/onosproject/rest/resources/ApplicationsWebResource.java
index 41e238b..ee6a6b5 100644
--- a/web/api/src/main/java/org/onosproject/rest/resources/ApplicationsWebResource.java
+++ b/web/api/src/main/java/org/onosproject/rest/resources/ApplicationsWebResource.java
@@ -18,6 +18,7 @@
import org.onosproject.app.ApplicationAdminService;
import org.onosproject.core.Application;
import org.onosproject.core.ApplicationId;
+import org.onosproject.core.CoreService;
import org.onosproject.rest.AbstractWebResource;
import javax.ws.rs.Consumes;
@@ -44,8 +45,8 @@
* Get all installed applications.
* Returns array of all installed applications.
*
- * @onos.rsModel Applications
* @return 200 OK
+ * @onos.rsModel Applications
*/
@GET
public Response getApps() {
@@ -57,9 +58,10 @@
/**
* Get application details.
* Returns details of the specified application.
- * @onos.rsModel Application
+ *
* @param name application name
* @return 200 OK; 404; 401
+ * @onos.rsModel Application
*/
@GET
@Path("{name}")
@@ -143,9 +145,76 @@
return response(service, appId);
}
+ /**
+ * Registers an on or off platform application.
+ *
+ * @param name application name
+ * @return 200 OK; 404; 401
+ * @onos.rsModel ApplicationId
+ */
+ @POST
+ @Produces(MediaType.APPLICATION_JSON)
+ @Path("{name}/register")
+ public Response registerAppId(@PathParam("name") String name) {
+ CoreService service = get(CoreService.class);
+ ApplicationId appId = service.registerApplication(name);
+ return response(appId);
+ }
+
+ /**
+ * Gets application Id entry by short id.
+ *
+ * @param shortId numerical id of application
+ * @return 200 OK; 404; 401
+ * @onos.rsModel ApplicationId
+ */
+ @GET
+ @Produces(MediaType.APPLICATION_JSON)
+ @Path("ids/short")
+ public Response getAppIdByShortId(@QueryParam("id") int shortId) {
+ CoreService service = get(CoreService.class);
+ ApplicationId appId = service.getAppId((short) shortId);
+ return response(appId);
+ }
+
+ /**
+ * Gets application Id entry by name.
+ *
+ * @param name name of application
+ * @return 200 OK; 404; 401
+ * @onos.rsModel ApplicationId
+ */
+ @GET
+ @Produces(MediaType.APPLICATION_JSON)
+ @Path("ids/name")
+ public Response getAppIdByName(@QueryParam("name") String name) {
+ CoreService service = get(CoreService.class);
+ ApplicationId appId = service.getAppId(name);
+ return response(appId);
+ }
+
+ /**
+ * Gets a collection of application ids.
+ * Returns array of all registered application ids.
+ *
+ * @return 200 OK; 404; 401
+ * @onos.rsModel ApplicationIds
+ */
+ @GET
+ @Produces(MediaType.APPLICATION_JSON)
+ @Path("ids")
+ public Response getAppIds() {
+ CoreService service = get(CoreService.class);
+ Set<ApplicationId> appIds = service.getAppIds();
+ return ok(encodeArray(ApplicationId.class, "applicationIds", appIds)).build();
+ }
+
private Response response(ApplicationAdminService service, ApplicationId appId) {
Application app = service.getApplication(appId);
return ok(codec(Application.class).encode(app, this)).build();
}
+ private Response response(ApplicationId appId) {
+ return ok(codec(ApplicationId.class).encode(appId, this)).build();
+ }
}