This is a short introduction to the opendaylight-startup-archetype which is the easiest way to get started writing an OpenDaylight MD-SAL application. An archetype creates a maven project from a template, giving you a working project to start from.
Follow the prompts to set the project parameters. When I ran the archetype I called my project demoproject so the snippets I use will always reference demoproject. Let me explain the structure of the generated project and the purpose of each part.
Note that the default value for the ‘version’ property is 1.0-SNAPSHOT. This causes problems when you want to install the project into an OpenDaylight release such as Lithium-SR3 because it is configured to ignore snapshots. If you set the ‘version’ property to 1.0 then the generated artifacts will work.
This is the structure of the generated project:
api # contains the YANG model for your project |-- src/main/yang/demoproject.yang `-- pom.xml impl # contains the project implementation |-- src/main/java | |-- com/cisco/impl/DemoProvider.java | `-- org/.../demoproject/impl/rev141210/DemoModule.java # Your module init class |-- src/main/yang/demoproject-impl.yang # YANG definition for your module config |-- src/main/config/default-config.xml # Your module config file `-- pom.xml features # contains the feature definition for Karaf |-- src/main/features/features.xml # defines features that can be installed in karaf `-- pom.xml artifacts # maven project that includes all artifacts required by project `-- pom.xml # references demoproject-api, demoproject-impl, demoproject-features karaf # maven project that builds an OpenDaylight karaf distribution `-- pom.xml # includes odl-demoproject-ui in the list of karaf local features
Without changing anything in the generated project, you can build the project and then run the generated Karaf distribution:
% cd demoproject
% mvn install
________ ________ .__ .__ .__ __
_____ ______ ____ ____ ______ _____ ___.__.| | |__| ____ | |___/ |_
/ | ____ _/ __ / | | __ < | || | | |/ ___| | __
/ | |_> > ___/| | | ` / __ ___ || |_| / /_/ > Y |
_______ / __/ ___ >___| /_______ (____ / ____||____/_____ /|___| /__|
/|__| / / / // /_____/ /
Hit ” for a list of available commands
and ‘[cmd] –help’ for help on a specific command.
Hit ” or type ‘system:shutdown’ or ‘logout’ to shutdown OpenDaylight.
[email protected]>feature:list | grep demoproject
odl-demoproject-api | 1.0-SNAPSHOT | x | odl-demoproject-1.0-SNAPSHOT | OpenDaylight :: demoproject :: api
odl-demoproject | 1.0-SNAPSHOT | x | odl-demoproject-1.0-SNAPSHOT | OpenDaylight :: demoproject
odl-demoproject-rest | 1.0-SNAPSHOT | x | odl-demoproject-1.0-SNAPSHOT | OpenDaylight :: demoproject :: REST
odl-demoproject-ui | 1.0-SNAPSHOT | x | odl-demoproject-1.0-SNAPSHOT | OpenDaylight :: demoproject :: UI
As you can see, there are 4 features instlalled in karaf from my project. These features are define in the features.xml file. Features are a karaf concept that make it easier to install multiple OSGi bundles and their dependencies. A features.xml file is a “Feature Repository” which can contain multiple feature definitions. Here is the features.xml file with inline comments:
You can install your application into a separate OpenDaylight runtime such as the Lithium-SR3 distribution. The maven project builds a Karaf “kar” file in features/target/demoproject-features-1.0.kar which can be copied into the karaf deploy directory:
% cp demoproject/features/target/demoproject-features-1.0.kar distribution-karaf-0.3.3-Lithium-SR3/deploy
Note that the OpenDaylight Lithium-SR3 distribution is configured to ignore snapshots so it is important that your project does not have a version like 1.0-SNAPSHOT.
<< This article was originally published on blog here. >>