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/src/main/resources/OSGI-INF/blueprint/shell-config.xml b/apps/yang/src/main/resources/OSGI-INF/blueprint/shell-config.xml
index 05cb393f..d5e1711 100644
--- a/apps/yang/src/main/resources/OSGI-INF/blueprint/shell-config.xml
+++ b/apps/yang/src/main/resources/OSGI-INF/blueprint/shell-config.xml
@@ -16,7 +16,10 @@
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
<command-bundle xmlns="http://karaf.apache.org/xmlns/shell/v1.1.0">
<command>
- <action class="org.onosproject.yang.YangModelsListCommand"/>
+ <action class="org.onosproject.yang.impl.YangModelsListCommand"/>
+ </command>
+ <command>
+ <action class="org.onosproject.yang.impl.YangCompileCommand"/>
</command>
</command-bundle>
</blueprint>
diff --git a/apps/yang/src/main/resources/YangModelRegistrator.java b/apps/yang/src/main/resources/YangModelRegistrator.java
new file mode 100644
index 0000000..fb6b0e3
--- /dev/null
+++ b/apps/yang/src/main/resources/YangModelRegistrator.java
@@ -0,0 +1,10 @@
+// Auto-generated code
+package PACKAGE;
+
+import org.onosproject.yang.AbstractYangModelRegistrator;
+
+public class YangModelRegistrator extends AbstractYangModelRegistrator {
+ public YangModelRegistrator() {
+ super(YangModelRegistrator.class);
+ }
+}
\ No newline at end of file
diff --git a/apps/yang/src/main/resources/YangModelRegistrator.xml b/apps/yang/src/main/resources/YangModelRegistrator.xml
new file mode 100644
index 0000000..647ae45
--- /dev/null
+++ b/apps/yang/src/main/resources/YangModelRegistrator.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" immediate="true" name="PACKAGE.YangModelRegistrator" activate="activate" deactivate="deactivate">
+ <implementation class="PACKAGE.YangModelRegistrator"/>
+ <property name="service.pid" value="PACKAGE.YangModelRegistrator"/>
+ <reference name="modelRegistry" interface="org.onosproject.yang.runtime.YangModelRegistry" cardinality="1..1" policy="static" bind="bindModelRegistry" unbind="unbindModelRegistry"/>
+ <reference name="sourceResolver" interface="org.onosproject.yang.YangClassLoaderRegistry" cardinality="1..1" policy="static" bind="bindSourceResolver" unbind="unbindSourceResolver"/>
+</scr:component>
\ No newline at end of file
diff --git a/apps/yang/src/main/resources/app.xml b/apps/yang/src/main/resources/app.xml
new file mode 100644
index 0000000..1188a02
--- /dev/null
+++ b/apps/yang/src/main/resources/app.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<app name="MODEL_ID" origin="ONOS Community" version="1.0"
+ title="YANG Model: MODEL_ID" category="Model" url="http://onosproject.org"
+ featuresRepo="mvn:org.onosproject/MODEL_ID/1.0/xml/features"
+ features="MODEL_ID" apps="org.onosproject.yang">
+ <description>YANG Model: MODEL_ID</description>
+ <artifact>mvn:org.onosproject/MODEL_ID/1.0</artifact>
+</app>
\ No newline at end of file
diff --git a/apps/yang/src/main/resources/features.xml b/apps/yang/src/main/resources/features.xml
new file mode 100644
index 0000000..7d56a53
--- /dev/null
+++ b/apps/yang/src/main/resources/features.xml
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<features xmlns="http://karaf.apache.org/xmlns/features/v1.2.0"
+ name="MODEL_ID-1.0">
+ <feature name="MODEL_ID" version="1.0"
+ description="YANG Model: MODEL_ID">
+ <feature>onos-api</feature>
+ <bundle>wrap:mvn:org.onosproject/MODEL_ID/1.0$Bundle-SymbolicName=MODEL_ID&Bundle-Version=1.0&Service-Component=OSGI-INF/MODEL_ID.YangModelRegistrator.xml</bundle>
+ </feature>
+</features>
\ No newline at end of file
diff --git a/apps/yang/src/main/resources/onos-yang-jar b/apps/yang/src/main/resources/onos-yang-jar
new file mode 100644
index 0000000..4429e07
--- /dev/null
+++ b/apps/yang/src/main/resources/onos-yang-jar
@@ -0,0 +1,24 @@
+#!/bin/bash
+# -----------------------------------------------------------------------------
+# Assembles ONOS application jar from the compiled YANG model artifacts.
+# -----------------------------------------------------------------------------
+
+classes=${1:-classes}
+jar=${2:-model.jar}
+modelId=${3-org.onosproject.model.unknown}
+
+# Generate the app.xml descriptor file and stage it at the top of the jar
+sed "s/MODEL_ID/$modelId/g" $(dirname $0)/app.xml > $classes/app.xml
+
+# Generate features.xml file and stage it at the top of the jar
+sed "s/MODEL_ID/$modelId/g" $(dirname $0)/features.xml > $classes/features.xml
+mkdir -p $classes/m2/org/onosproject/$modelId/1.0/
+cp $classes/features.xml $classes/m2/org/onosproject/$modelId/1.0/$modelId-1.0-features.xml
+
+# Generate model self-registrator SCR descriptor
+mkdir -p $classes/OSGI-INF
+sed "s/PACKAGE/$modelId/g" $(dirname $0)/YangModelRegistrator.xml \
+ > $classes/OSGI-INF/$modelId.YangModelRegistrator.xml
+
+cd $classes
+jar cf $jar *
\ No newline at end of file
diff --git a/apps/yang/src/main/resources/onos-yang-javac b/apps/yang/src/main/resources/onos-yang-javac
new file mode 100755
index 0000000..1fa344c
--- /dev/null
+++ b/apps/yang/src/main/resources/onos-yang-javac
@@ -0,0 +1,35 @@
+#!/bin/bash
+# -----------------------------------------------------------------------------
+# Compiles Java code generated by the YANG compiler.
+# -----------------------------------------------------------------------------
+
+sources=${1:-src}
+classes=${2:-classes}
+modelId=${3:-org.onosproject.model.unknown}
+
+# Stage the YANG sources and the YANG schema meta-data
+mkdir -p $classes/yang/resources
+cp $sources/schema/* $classes/yang/resources
+
+root=${root:-system}
+op="$root/org/onosproject"
+
+function findLib() {
+ find $1/$2 -name "$2-*.jar"
+}
+
+classPath="$(findLib $op onos-yang-model)"
+classPath="$classPath:$(findLib $op onos-yang-runtime)"
+classPath="$classPath:$(findLib $op onos-yang-compiler-api)"
+classPath="$classPath:$(findLib $op onos-apps-yang)"
+
+package=${modelId//./\/}
+mkdir -p $sources/src/$package
+sed "s/PACKAGE/$modelId/g" $(dirname $0)/YangModelRegistrator.java \
+ > $sources/src/$package/YangModelRegistrator.java
+
+# Compile the generated java code
+find $sources/src -name '*.java' > $sources/javaFiles
+javac -source 1.8 -target 1.8 \
+ -sourcepath "$sources/src" -classpath "$classPath" -d "$classes" \
+ @$sources/javaFiles