mirror of
https://github.com/opennetworkinglab/onos.git
synced 2025-10-16 01:41:26 +02:00
allow applications to be installed by URL from REST API
Change-Id: I6c28d91e1bbc6e77eefba00b8f106fe22edc475b
This commit is contained in:
parent
e80e18f388
commit
20a070bed7
@ -9,6 +9,7 @@ app=${3}
|
|||||||
|
|
||||||
export URL=http://$node:8181/onos/v1/applications
|
export URL=http://$node:8181/onos/v1/applications
|
||||||
export HDR="-HContent-Type:application/octet-stream"
|
export HDR="-HContent-Type:application/octet-stream"
|
||||||
|
export HAJ="-HContent-Type:application/json"
|
||||||
export curl="curl -sS --user $ONOS_WEB_USER:$ONOS_WEB_PASS"
|
export curl="curl -sS --user $ONOS_WEB_USER:$ONOS_WEB_PASS"
|
||||||
|
|
||||||
# Prints usage help
|
# Prints usage help
|
||||||
@ -34,6 +35,13 @@ function appName {
|
|||||||
|
|
||||||
case $cmd in
|
case $cmd in
|
||||||
list) $curl -X GET $URL;;
|
list) $curl -X GET $URL;;
|
||||||
|
installUrl!|installUrl)
|
||||||
|
activate="false"
|
||||||
|
[ $cmd = "installUrl!" ] && activate="true"
|
||||||
|
[ $# -lt 3 ] && usage
|
||||||
|
appurl=$3
|
||||||
|
$curl -X POST $HAJ -d '{"url" : "'"$appurl"'", "activate" : "'$activate'" }' $URL
|
||||||
|
;;
|
||||||
install!|install)
|
install!|install)
|
||||||
[ $cmd = "install!" ] && activate="?activate=true"
|
[ $cmd = "install!" ] && activate="?activate=true"
|
||||||
[ $# -lt 3 -o ! -f $app ] && usage
|
[ $# -lt 3 -o ! -f $app ] && usage
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.onosproject.rest.resources;
|
package org.onosproject.rest.resources;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||||
import org.onosproject.app.ApplicationAdminService;
|
import org.onosproject.app.ApplicationAdminService;
|
||||||
import org.onosproject.core.Application;
|
import org.onosproject.core.Application;
|
||||||
import org.onosproject.core.ApplicationId;
|
import org.onosproject.core.ApplicationId;
|
||||||
@ -32,7 +33,9 @@ import javax.ws.rs.Produces;
|
|||||||
import javax.ws.rs.QueryParam;
|
import javax.ws.rs.QueryParam;
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.net.URL;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import static org.onlab.util.Tools.nullIsNotFound;
|
import static org.onlab.util.Tools.nullIsNotFound;
|
||||||
@ -46,6 +49,9 @@ public class ApplicationsWebResource extends AbstractWebResource {
|
|||||||
private static final String APP_ID_NOT_FOUND = "Application ID is not found";
|
private static final String APP_ID_NOT_FOUND = "Application ID is not found";
|
||||||
private static final String APP_NOT_FOUND = "Application is not found";
|
private static final String APP_NOT_FOUND = "Application is not found";
|
||||||
|
|
||||||
|
private static final String URL = "url";
|
||||||
|
private static final String ACTIVATE = "activate";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all installed applications.
|
* Get all installed applications.
|
||||||
* Returns array of all installed applications.
|
* Returns array of all installed applications.
|
||||||
@ -76,6 +82,38 @@ public class ApplicationsWebResource extends AbstractWebResource {
|
|||||||
return response(service, appId);
|
return response(service, appId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Install a new application.
|
||||||
|
* Uploads application archive stream and optionally activates the
|
||||||
|
* application.
|
||||||
|
|
||||||
|
* @param raw json object containing location (url) of application oar
|
||||||
|
* @return 200 OK; 404; 401
|
||||||
|
*/
|
||||||
|
@POST
|
||||||
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
public Response installApp(InputStream raw) {
|
||||||
|
Application app;
|
||||||
|
try {
|
||||||
|
ObjectNode jsonTree = (ObjectNode) mapper().readTree(raw);
|
||||||
|
URL url = new URL(jsonTree.get(URL).asText());
|
||||||
|
boolean activate = false;
|
||||||
|
if (jsonTree.has(ACTIVATE)) {
|
||||||
|
activate = jsonTree.get(ACTIVATE).asBoolean();
|
||||||
|
}
|
||||||
|
|
||||||
|
ApplicationAdminService service = get(ApplicationAdminService.class);
|
||||||
|
app = service.install(url.openStream());
|
||||||
|
if (activate) {
|
||||||
|
service.activate(app.id());
|
||||||
|
}
|
||||||
|
} catch (IOException ex) {
|
||||||
|
throw new IllegalArgumentException(ex);
|
||||||
|
}
|
||||||
|
return ok(codec(Application.class).encode(app, this)).build();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Install a new application.
|
* Install a new application.
|
||||||
* Uploads application archive stream and optionally activates the
|
* Uploads application archive stream and optionally activates the
|
||||||
|
Loading…
x
Reference in New Issue
Block a user