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();
}
}
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();
}
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;
}
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();
}
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();
}
Aggregations