Search in sources :

Example 1 with YangLiveCompilerService

use of org.onosproject.yang.YangLiveCompilerService 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 YangLiveCompilerService

use of org.onosproject.yang.YangLiveCompilerService 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)

Aggregations

ApplicationAdminService (org.onosproject.app.ApplicationAdminService)2 YangLiveCompilerService (org.onosproject.yang.YangLiveCompilerService)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 URL (java.net.URL)1 Consumes (javax.ws.rs.Consumes)1 POST (javax.ws.rs.POST)1 ApplicationId (org.onosproject.core.ApplicationId)1