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 component template. 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 like to know more about this process.

Generate your ONOS application project

Let's now generate an ONOS project which will be fully compilable and ready to be deployed. Although, you will still have to code up your application, 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 following:

Code Block
languagetext
$ mvn archetype:generate -Dfilter=org.onosproject: -DarchetypeGroupId=org.onosproject  -DarchetypeArtifactId=onos-bundle-archetype -DarchetypeVersion=1.02.0-SNAPSHOT

Alternatively, if you have the ONOS code checked-out and available, you can use the onos-create-app tool to accomplish the same thing. 

This will ask you several specific information about the bundle you would like to generate as you can see below. Make sure to enter parameters that are appropriate for you.

...

This has now generated a new project for you. Let's move on to building it and loading it into ONOS.

Loading your generated component into ONOS

First start by entering If you want to designated the newly created project as an ONOS application, rather than just an OSGi bundle, enter the directory of your generated component and then building itedit the pom.xml file within.

Code Block
$ cd foo-app
$ vi pom.xml

Uncomment the onos.app.name and onos.app.origin properties as shown in the following snippet.

Code Block
collapsetrue
    ...    
    <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 bundle as an ONOS application by producing an .oar (ONOS Application aRchive). After saving the changes, build the project as follows:

Code Block
$ mvn clean install

Now this has When the build is complete, both the OSGi bundle and the application archive have been installed in your local maven repository and it is ready to be loaded into your ONOS instance. If . To install the application into running ONOS instance (or cluster), you can use the onos-app tool, which uses ONOS REST API within, to upload the .oar file as shown in the following example. If you need help running ONOS please refer to this page.

Code Block
languagetext
onos> bundle:install mvn:org.foo$ onos-app localhost install target/foo-app/-1.0-SNAPSHOT.oar

Now, from the ONOS console, you should be able to see the bundle application has been loadedinstalled,

Code Block
languagetext
onos> listapps -s
...
154 | Installed |  80 |   29 org.foo.app                      1.0.0.SNAPSHOT | foo-app ONOS OSGi bundle archetype

and it is ready to startbe activated.

Code Block
languagetext
onos> startapp activate org.foo-.app
onos> apps list-s
...
154 | Active |  80 |*  29 org.foo.app                      1.0.0.SNAPSHOT | foo-appONOS OSGi bundle archetype 

Happy coding 

Finally your component application is loaded and running into withing ONOS. Also, the generation process has generated an entire project which can be loaded into your favourite JAVA editor.

...