Search in sources :

Example 1 with ApplicationAdminService

use of org.onosproject.app.ApplicationAdminService in project onos by opennetworkinglab.

the class YangCompileCommand method doExecute.

@Override
protected void doExecute() {
    try {
        InputStream yangJar = new URL(url).openStream();
        YangLiveCompilerService compiler = get(YangLiveCompilerService.class);
        if (compileOnly) {
            ByteStreams.copy(compiler.compileYangFiles(modelId, yangJar), System.out);
        } else {
            ApplicationAdminService appService = get(ApplicationAdminService.class);
            if (forceReinstall) {
                ApplicationId appId = appService.getId(modelId);
                if (appId != null && appService.getApplication(appId) != null) {
                    appService.uninstall(appId);
                }
            }
            appService.install(compiler.compileYangFiles(modelId, yangJar));
            appService.activate(appService.getId(modelId));
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : YangLiveCompilerService(org.onosproject.yang.YangLiveCompilerService) InputStream(java.io.InputStream) IOException(java.io.IOException) ApplicationId(org.onosproject.core.ApplicationId) URL(java.net.URL) ApplicationAdminService(org.onosproject.app.ApplicationAdminService)

Example 2 with ApplicationAdminService

use of org.onosproject.app.ApplicationAdminService in project onos by opennetworkinglab.

the class YangWebResource method upload.

/**
 * Compiles and registers the given yang files.
 *
 * @param modelId model identifier
 * @param stream  YANG, ZIP or JAR file
 * @return 200 OK
 * @throws IOException when fails to generate a file
 */
@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response upload(@QueryParam("modelId") @DefaultValue("org.onosproject.model.unknown") String modelId, @FormDataParam("file") InputStream stream) throws IOException {
    YangLiveCompilerService compiler = get(YangLiveCompilerService.class);
    ApplicationAdminService appService = get(ApplicationAdminService.class);
    modelId = getValidModelId(modelId);
    appService.install(compiler.compileYangFiles(modelId, stream));
    appService.activate(appService.getId(modelId));
    return Response.ok().build();
}
Also used : YangLiveCompilerService(org.onosproject.yang.YangLiveCompilerService) ApplicationAdminService(org.onosproject.app.ApplicationAdminService) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes)

Example 3 with ApplicationAdminService

use of org.onosproject.app.ApplicationAdminService in project onos by opennetworkinglab.

the class ApplicationCommand method manageApp.

// Manages the specified application.
private boolean manageApp(ApplicationAdminService service, String name) {
    ApplicationId appId = service.getId(name);
    if (appId == null) {
        List<Application> matches = service.getApplications().stream().filter(app -> app.id().name().matches(".*\\." + name + "$")).collect(Collectors.toList());
        if (matches.size() == 1) {
            // Found match
            appId = matches.iterator().next().id();
        } else if (!matches.isEmpty()) {
            print("Did you mean one of: %s", matches.stream().map(Application::id).map(ApplicationId::name).collect(Collectors.toList()));
            return false;
        }
    }
    if (appId == null) {
        print("No such application: %s", name);
        return false;
    }
    String action;
    if (command.equals(UNINSTALL)) {
        service.uninstall(appId);
        action = "Uninstalled";
    } else if (command.equals(ACTIVATE)) {
        service.activate(appId);
        action = "Activated";
    } else if (command.equals(DEACTIVATE)) {
        service.deactivate(appId);
        action = "Deactivated";
    } else {
        print("Unsupported command: %s", command);
        return false;
    }
    print("%s %s", action, appId.name());
    return true;
}
Also used : URL(java.net.URL) Argument(org.apache.karaf.shell.api.action.Argument) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) Command(org.apache.karaf.shell.api.action.Command) AbstractShellCommand(org.onosproject.cli.AbstractShellCommand) List(java.util.List) ApplicationAdminService(org.onosproject.app.ApplicationAdminService) ByteStreams(com.google.common.io.ByteStreams) Service(org.apache.karaf.shell.api.action.lifecycle.Service) ApplicationId(org.onosproject.core.ApplicationId) Completion(org.apache.karaf.shell.api.action.Completion) Application(org.onosproject.core.Application) ApplicationId(org.onosproject.core.ApplicationId) Application(org.onosproject.core.Application)

Example 4 with ApplicationAdminService

use of org.onosproject.app.ApplicationAdminService in project onos by opennetworkinglab.

the class ApplicationsWebResource method installApp.

/**
 * 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 = readTreeFromStream(mapper(), 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();
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) IOException(java.io.IOException) Application(org.onosproject.core.Application) URL(java.net.URL) ApplicationAdminService(org.onosproject.app.ApplicationAdminService) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 5 with ApplicationAdminService

use of org.onosproject.app.ApplicationAdminService in project onos by opennetworkinglab.

the class ApplicationsWebResource method deactivateApp.

/**
 * De-activate application.
 * De-activates the specified application.
 *
 * @param name application name
 * @return 204 NO CONTENT
 */
@DELETE
@Produces(MediaType.APPLICATION_JSON)
@Path("{name}/active")
public Response deactivateApp(@PathParam("name") String name) {
    ApplicationAdminService service = get(ApplicationAdminService.class);
    ApplicationId appId = service.getId(name);
    if (appId != null) {
        service.deactivate(appId);
    }
    return Response.noContent().build();
}
Also used : ApplicationId(org.onosproject.core.ApplicationId) ApplicationAdminService(org.onosproject.app.ApplicationAdminService) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Produces(javax.ws.rs.Produces)

Aggregations

ApplicationAdminService (org.onosproject.app.ApplicationAdminService)14 ApplicationId (org.onosproject.core.ApplicationId)11 Path (javax.ws.rs.Path)8 GET (javax.ws.rs.GET)6 Produces (javax.ws.rs.Produces)6 Application (org.onosproject.core.Application)6 IOException (java.io.IOException)3 InputStream (java.io.InputStream)3 URL (java.net.URL)3 POST (javax.ws.rs.POST)3 Consumes (javax.ws.rs.Consumes)2 DELETE (javax.ws.rs.DELETE)2 YangLiveCompilerService (org.onosproject.yang.YangLiveCompilerService)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 ByteStreams (com.google.common.io.ByteStreams)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Argument (org.apache.karaf.shell.api.action.Argument)1 Command (org.apache.karaf.shell.api.action.Command)1 Completion (org.apache.karaf.shell.api.action.Completion)1