Date: Fri, 29 Mar 2024 02:00:21 +0000 (UTC) Message-ID: <1450601318.961.1711677621133@ip-10-30-146-46.us-west-2.compute.internal> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_960_759484887.1711677621130" ------=_Part_960_759484887.1711677621130 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html
In this tutorial we will show you how to generate an ONOS bundle templat= e. This makes it easy for you to add either an ONOS service or application.= We will be using maven archetypes to generate our template, therefore this= link could be handy if you would l= ike to know more about this process.
Let's now generate an ONOS project which will be fully compilable and re= ady to be deployed. Although, you will still have to code up your applicati= on, we haven't yet figured out how to generate code that does exactly what = you would like it to do :wink:. So let's start by running the followin= g:
mvn arc= hetype:generate -DarchetypeGroupId=3Dorg.onosproject -DarchetypeArtifactId= =3Donos-bundle-archetype
Alternatively, if you have the ONOS code checked out and available, you =
can use the onos-create-app
tool to accomplish the same thing:=
onos-cr= eate-app
You will now be asked for several pieces of specific information about t= he bundle you would like to generate as you can see below. Make sure to ent= er parameters that are appropriate for you.
Define = value for property 'groupId': : org.foo =20 Define value for property 'artifactId': : foo-app Define value for property 'version': 1.0-SNAPSHOT: :=20 Define value for property 'package': org.foo: : org.foo.app Confirm properties configuration: groupId: org.foo artifactId: foo-app version: 1.0-SNAPSHOT package: org.foo.app Y: :
After this you should see the following output:
[INFO] = ---------------------------------------------------------------------------= - [INFO] Using following parameters for creating project from Archetype: onos= -bundle-archetype:1.2.0-SNAPSHOT [INFO] --------------------------------------------------------------------= -------- [INFO] Parameter: groupId, Value: org.foo [INFO] Parameter: artifactId, Value: foo-app [INFO] Parameter: version, Value: 1.0-SNAPSHOT [INFO] Parameter: package, Value: org.foo.app [INFO] Parameter: packageInPathFormat, Value: org/foo/app [INFO] Parameter: package, Value: org.foo.app [INFO] Parameter: version, Value: 1.0-SNAPSHOT [INFO] Parameter: groupId, Value: org.foo [INFO] Parameter: artifactId, Value: foo-app [INFO] project created from Archetype in dir: /private/tmp/onos-app/foo-app [INFO] --------------------------------------------------------------------= ---- [INFO] BUILD SUCCESS [INFO] --------------------------------------------------------------------= ---- [INFO] Total time: 01:54 min [INFO] Finished at: 2014-12-03T18:00:55-08:00 [INFO] Final Memory: 14M/245M [INFO] --------------------------------------------------------------------= ----
This has now generated a new project for you. Let's move on to building = it and loading it into ONOS.
If you want to designate the newly created project as an ONOS applicatio=
n, rather than just an OSGi bundle, enter the directory of your generated c=
omponent and edit the pom.xml
file within.
$ cd fo= o-app $ vi pom.xml
Uncomment the onos.app.name
and onos.app.origin
properties as shown in the following snippet.
... <properties> <onos.version>1.2.0-SNAPSHOT</onos.version> <onos.app.name>org.foo.app</onos.app.name> <onos.app.origin>Foo, Inc.</onos.app.origin> </properties> ...
This will instruct the onos-maven-plugin
to package the bun=
dle as an ONOS application by producing an .oar
(ONOS Applicat=
ion aRchive). After saving the changes, build the project as follows:
$ mvn c= lean install
When the build is complete, both the OSGi bundle and the application arc=
hive have been installed in your local maven repository. To install the app=
lication into running ONOS instance (or cluster), you can use the ono=
s-app
tool, which uses ONOS REST API within, to upload the .oa=
r
file as shown in the following example. If you need help runn=
ing ONOS please refer to this page.
$ onos-= app localhost install target/foo-app-1.0-SNAPSHOT.oar
Now, from the ONOS console, you should be able to see the application ha= s been installed,
onos>= ; apps -s ... 29 org.foo.app 1.0.SNAPSHOT ONOS OSGi bundle archet= ype
and it is ready to be activated.
onos>= ; app activate org.foo.app onos> apps -s ... * 29 org.foo.app 1.0.SNAPSHOT ONOS OSGi bundle archet= ype
You can now use the generated code for this test app as a framework for = adding your own custom code. If you edit the file src/main/java/org/foo/app/AppComponent.java= em>, you can see how the application is created, and add your own code to t= he application.
ONOS applications can hook into the ONOS CLI and GUI. When generating yo= ur application, you can use overlays to generate the classes needed to give= your application access to these services.
To allow your application to add commands to the ONOS CLI, overlay the C= LI interface like this:
onos-cr= eate-app cli org.foo.app foo-app 1.0.0
Now, as before, we need to build and install our application. Sinc= e we installed it once already, we will use the reinstall command to deploy= it:
mvn cle= an install onos-app localhost reinstall target/foo-app-1.0-SNAPSHOT.oar
Using the ONOS command line, restart the application:
onos>= ; app activate org.foo.app
Using the ONOS command line, we now have access to the 'sample' command,= which was defined by our overlay:
onos>= ; sample Hello World
You can use the CLI overlay to add your own commands to the CLI for your= app. Edit the file = src/main/java/org/foo/app/AppCommand.java to see how the sample comman= d is implemented and the file src/main/resources/OSGI-INF/blueprint/shell-config.xml to s= ee how new commands are integrated into the existing CLI.
To allow your application to add to the ONOS web UI, overlay the UI inte= rface like this:
onos-cr= eate-app ui org.foo.app foo-app 1.0.0
Now, as before, we need to build and install our application. Sinc= e we installed it once already, we will use the reinstall command to deploy= it:
mvn cle= an install onos-app localhost reinstall target/foo-app-1.0-SNAPSHOT.oar
Using the ONOS command line, restart the application:
onos>= ; app activate org.foo.app
The web UI overlay is now active. To view the new application page= that was just created, point your browser to the ONOS GUI at http://localhost:8181/onos/ui/. In the upper left corner of the = home page, click the navigation button to activate the drop down navigation= menu. At the bottom of the list, you will see an entry for "Sample".  = ;If you select it, you will be sent to a page called "Sample App View" whic= h is a page that was installed by your test application.
You can now use the generated web UI to add your own UI elements. The Ja= va back end that was generated for your web UI can be seen in src/main/java/org/foo/app/AppUiComponen= t.java and the HTML used to display the new page can be found in = src/main/resources/app/v= iew/sample/sample.html.
Finally your application is loaded and running withing ONOS. Also, the g= eneration process has generated an entire project which can be loaded into = your favourite JAVA editor.
Return To : Tutorials and Walkthroughs