Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

In this tutorial we will show you how to generate an ONOS template application using the onos-create-app tool. This tool relies on the Maven archetypes to generate a base ONOS application as well as several different variants that add CLI command, REST API, and a few means of extending the GUI.

Select ONOS version

Because the tool uses Maven archetypes, we need to first indicate what version of ONOS API we would like to build our application against. To do this, simply export the ONOS_POM_VERSION environment variable to the desired ONOS version as follows:

Code Block
$ export ONOS_POM_VERSION=2.0.0

If the above environment variable is not explicitly set, Maven will look for the most recent version of the archetypes available in your ~/.m2/repository (and then on Maven central) and this may not be what you intended so it's always best to set this explicitly.

Generate a new base ONOS application project

Let's now generate a skeletal ONOS application project which will be fully compilable and ready to be deployed. When creating the base project, we have to specify the Maven groupId, artifactId and version. These are necessary for locating the application in the Maven coordinate space. Additionally, we will also specify Java package name where the generated code will be located. Let's run the following command:

...

Code Block
languagetext
 Y: : y
[INFO] ----------------------------------------------------------------------------
[INFO] Using following parameters for creating project from Archetype: onos-bundle-archetype:2.10.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: /Users/tom/foobar/foo-app
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 24.439 s
[INFO] Finished at: 2019-03-11T17:35:21-07:00
[INFO] Final Memory: 14M/219M
[INFO] ------------------------------------------------------------------------

This has now generated a new project for you. Note that the onos-bundle-archetype version 2.0.0 was used for this. This is because we explicitly set the ONOS_POM_VERSION to 2.0.0.

Let's move on to building it and loading it into ONOS.

Compile, install and activate your new ONOS application

Now we are ready to build the ONOS app. We can do that by changing into the root directory of the generated project and invoking Maven as follows:

...

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, you can see how the application is created, and add your own code to the application. 

Generate various project overlays

ONOS applications can hook into the ONOS CLI, REST API and GUI. When generating your application, you can use overlays to generate the classes needed to give your application access to these services.

...