Integrating YANG live compilation into YANG runtime.

- Bumped ONOS dependency on ONOS YANG tools 2.2.0-b4.
- Added CLI to compile YANG models.
- Added GUI capability to compile YANG models via drag-n-drop or file upload.
- Fixed defect in propagating self-contained JAR apps through the cluster.

Change-Id: Icbd2a588bf1ffe0282e12d3d10a117e0957c3084
diff --git a/apps/yang/web/BUCK b/apps/yang/web/BUCK
index e6a782f..9563765 100644
--- a/apps/yang/web/BUCK
+++ b/apps/yang/web/BUCK
@@ -6,6 +6,7 @@
   '//lib:onos-yang-model',
   '//lib:onos-yang-compiler-api',
   '//lib:onos-yang-runtime',
+  '//apps/yang:onos-apps-yang'
 ]
 
 TEST_DEPS = [
diff --git a/apps/yang/web/src/main/java/org/onosproject/yang/web/YangWebResource.java b/apps/yang/web/src/main/java/org/onosproject/yang/web/YangWebResource.java
index 72d9cbe..9e56f4a 100644
--- a/apps/yang/web/src/main/java/org/onosproject/yang/web/YangWebResource.java
+++ b/apps/yang/web/src/main/java/org/onosproject/yang/web/YangWebResource.java
@@ -20,7 +20,10 @@
 import org.glassfish.jersey.media.multipart.FormDataBodyPart;
 import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
 import org.glassfish.jersey.media.multipart.FormDataMultiPart;
+import org.glassfish.jersey.media.multipart.FormDataParam;
+import org.onosproject.app.ApplicationAdminService;
 import org.onosproject.rest.AbstractWebResource;
+import org.onosproject.yang.YangLiveCompilerService;
 import org.onosproject.yang.compiler.api.YangCompilationParam;
 import org.onosproject.yang.compiler.api.YangCompilerService;
 import org.onosproject.yang.compiler.datamodel.YangNode;
@@ -32,8 +35,10 @@
 import org.onosproject.yang.runtime.YangModelRegistry;
 
 import javax.ws.rs.Consumes;
+import javax.ws.rs.DefaultValue;
 import javax.ws.rs.POST;
 import javax.ws.rs.Path;
+import javax.ws.rs.QueryParam;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
 import java.io.File;
@@ -74,11 +79,31 @@
     /**
      * 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);
+        appService.install(compiler.compileYangFiles(modelId, stream));
+        appService.activate(appService.getId(modelId));
+        return Response.ok().build();
+    }
+
+    /**
+     * Compiles and registers the given yang files.
+     *
      * @param formData YANG files or ser files
      * @return 200 OK
      * @throws IOException when fails to generate a file
      */
     @POST
+    @Path("deprecated")
     @Consumes(MediaType.MULTIPART_FORM_DATA)
     public Response upload(FormDataMultiPart formData) throws IOException {
         Map<String, List<File>> input = parseInputData(formData);
@@ -161,7 +186,7 @@
     }
 
     private void addToParam(DefaultYangCompilationParam.Builder builder,
-                                            File file) {
+                            File file) {
         if (file.getName().endsWith(YANG_FILE_EXTENSION)) {
             builder.addYangFile(Paths.get(file.getAbsolutePath()));
         } else if (file.getName().endsWith(SER_FILE_EXTENSION)) {
@@ -198,8 +223,7 @@
 
         // first get all directories,
         // then make those directory on the destination Path
-        for (Enumeration<? extends ZipEntry> enums = zip.entries();
-             enums.hasMoreElements();) {
+        for (Enumeration<? extends ZipEntry> enums = zip.entries(); enums.hasMoreElements();) {
             ZipEntry entry = enums.nextElement();
 
             String fileName = YANG_RESOURCES + entry.getName();
@@ -211,8 +235,7 @@
         }
 
         //now create all files
-        for (Enumeration<? extends ZipEntry> enums = zip.entries();
-             enums.hasMoreElements();) {
+        for (Enumeration<? extends ZipEntry> enums = zip.entries(); enums.hasMoreElements();) {
             ZipEntry entry = enums.nextElement();
             String fileName = YANG_RESOURCES + entry.getName();
             File f = new File(fileName);