1 # Create app for ODL Boron and some backgrounds
3 ## Common information and workshop tasks
7 - Demo ODL, GUI and Simulators
8 - [Opendaylight](http://5g-crosshaul.eu/wp-content/uploads/2016/10/UC3M_5tonic_SdnOdlDay_19Oct2016.pdf)
9 - Three slides: 6:MDSAL, 8:AppDev, 11:Karaf
11 - User's home and the tools to use
12 - Git/ Maven &co mvn command, .m2
13 - HANDS-ON: Setup Single server development environment
14 - Follow [DevEnv](READMEInstallDevelopmentEnvironment.md)
18 - OSGi and what does Karaf do
19 - [osgi](https://en.wikipedia.org/wiki/OSGi)
20 - [karaf](https://stackoverflow.com/questions/17350281/what-exactly-is-apache-karaf)
21 - How does it come and the directory structure
22 - Opendaylight karaf [odlkaraf](https://nexus.opendaylight.org/content/groups/public/org/opendaylight/integration/distribution-karaf/)
26 - Bundles and Features
30 - commands start/stop/client
33 - start and list features and bundles
39 ### Network applications
41 - commons bundle and parents
42 - See CENTENNIAL/code/features (features-parent)
43 - binding-parent => Access of MDSAL
44 - config-parent => Push config xml file
45 - Karaf / Yang and the device model
46 - DLUX, Angular JS, Chromium
48 - ODL Datamodel, Access the database and the Netconf model
49 - [Documentation Boron](http://docs.opendaylight.org/en/stable-boron/)
50 - [ArchetypeRPCHelloWorld](https://wiki.opendaylight.org/view/OpenDaylight_Controller:MD-SAL:Startup_Project_Archetype)
53 ## 1. Create app for ODL Boron
55 ### 1.1. Prerequirements
57 - Development environment for ODL Boron according to Description "InstallDevelopmentEnvironment".
58 - Clone from git the projects CENTENNIAL and WirelessTranportEmulator to get the following structure
62 ├── WirelessTransportEmulator
63 └── distribution-karaf-0.6.1-Carbon
66 ### 1.2. Create the app
68 Approach is to copy the template application in the CENTENNIAL repository apps directory and adapt it to the needs.<br/>
69 - Northbound: Provide RPC northbound
70 - Southbound: Monitors mountpoints connected to netconf devices.
72 The template app is located here:
74 CENTENNIAL/code/apps/template/
86 Use the commandline and copy template to a new directory and modify with vi
88 cd ~/odl/CENTENNIAL/code/apps
93 Remove files which are recreated later
96 rm -r target api/target impl/target
97 rm -r .settings/ api/.settings/ impl/.settings/
98 rm -r .project api/.project impl/.project
100 Change with eclipse editor (or vi) within the directory tree the four pom.xml files from<br/>
101 template_something to myapp_something
105 <artifactId>myapp</artifactId>
108 Adapt in the impl/pom.xml and the features/pom.xml the dependency to the myapps-api project.
110 Import into eclipse under the apps working set, that you see the new projects:
116 Using eclipse do rename
118 - filename or partial filenames from "template" to "myapp"
119 - .yang file in myapp-api
120 - .yang file in myapp-impl
121 - bundle name in myapp-impl/src/main/java to org.opendaylight.mwtn.myapp
123 Modify module name, namespace, prefix revision date of myapp-api yang file:
127 namespace "urn:opendaylight:params:xml:ns:yang:myapp";
130 revision "2018-01-23" {
131 description "Initial revision of myapp model";
148 Similar with myapp-impl yang file. Adapt module name, namespace, prefix, revision date, java-name-prefix.
152 namespace "urn:opendaylight:params:xml:ns:yang:myapp:impl";
155 import config { prefix config; revision-date 2013-04-05; }
156 import opendaylight-md-sal-binding { prefix md-sal-binding; revision-date 2013-10-28;}
159 "Service definition for myapp project";
161 revision "2018-01-23" {
163 "Initial myapp revision";
167 base config:module-type;
168 config:java-name-prefix MyappImpl;
171 augment "/config:modules/config:module/config:configuration" {
173 when "/config:modules/config:module/config:type = 'myapp'";
175 uses config:service-ref {
178 config:required-identity md-sal-binding:binding-broker-osgi-registry;
186 Adapt Java classes using eclipse refactor
188 - TemplateAppProvider -> MyAppProvider
189 - TemplateServiceImpl -> MyAppServiceImpl
191 HINT1: The enabled *eclipse -> project -> Build Automatically* option interferes with external Maven builds in the command line. You can see strange errors during maven build. If this is the case than disable it and try again. Basically handling is easier if option is switched on, but disable it before you use cli/maven.
193 HINT2: After cli/maven build is done use F5 to see all generated files files.
195 HINT3: If you feel that errors are all corrected, but the errors will not go away in eclipse use *eclipse -> projects -> clean* for the project.
197 Enable *eclipse -> project -> Build Automatically* or use maven build command below to build the app.<br/>
200 mvn clean install -DskipTests -Dmaven.javadoc.skip=true
202 You see the new created sources with the timestamp in the package name.<br/>
203 Open "MyAppImplModule" and fill the implementation with addapted code similar to the code in the "TemplateImplModule.java" in the function "createInstance()". The eclipse refactor has already renamed the code snippet to the right class name.
207 - Remove the old package.
208 - Correct the imports where necessary
210 If all errors are corrected, do a cli maven build. If you see this you are ready with this section.
212 [INFO] Reactor Summary:
214 [INFO] myapp-api .......................................... SUCCESS [ 10.130 s]
215 [INFO] myapp-impl ......................................... SUCCESS [ 4.644 s]
216 [INFO] ONF :: Wireless :: myapp-features .................. SUCCESS [ 8.811 s]
217 [INFO] myapp .............................................. SUCCESS [ 3.727 s]
218 [INFO] ------------------------------------------------------------------------
220 [INFO] ------------------------------------------------------------------------
225 rm -r target api/target impl/target features/target
226 - Grep for all string "template" and replace
228 - Activate enough logging
229 - (!)Remove in the karaf the xml config file: rm $ODL_KARAF_HOME/etc/opendaylight/karaf/myapp.xml. New install of the feature/bundle is required to re-create this file.
234 HINT1: At this point your .m2 repository needs to contain all jars of the applications in apps, features and ux. If not done before you need to compile everything with the following command:
236 cd ~/odl/CENTENNIAL/code
237 mvn clean install -DskipTests
239 HINT2: If karaf container is already running you get a feedback that start is not possible. Use the stop command to stop it:
241 cd ~/odl/CENTENNIAL/code
244 HIN3: In new environment you should use the the ```./odl``` command insteadt of ```./install.sh```
245 Change to the code directory and start the karaf container using the *imd* option:
247 cd ~/odl/CENTENNIAL/code
250 To **Test it** step into to the karaf cli:
254 Add the new feature in the karaf command line:
256 feature:repo-add mvn:org.opendaylight.mwtn/myapp-features/0.4.0-SNAPSHOT/xml/features
257 feature:install odl-mwt-myapp
260 You are done with this test if you see something like this, especially the last line is important!
262 herbert@vm2-herbert:~/odl/distribution-karaf-0.5.3-Boron-SR3/data/log$ grep -ia "session i" *
263 2018-01-23 20:24:18,651 | INFO | config-pusher | TemplateProvider | 331 - org.opendaylight.mwtn.template-impl - 0.4.0.SNAPSHOT | TemplateProvider Session Initiated
264 2018-01-23 20:24:18,760 | INFO | config-pusher | WebsocketmanagerProvider | 329 - org.opendaylight.mwtn.websocketmanager-impl - 0.4.0.SNAPSHOT | WebsocketmanagerProvider Session Initiated
265 2018-01-23 20:26:39,218 | INFO | config-pusher | MyAppProvider | 337 - org.opendaylight.mwtn.myapp-impl - 0.4.0.SNAPSHOT | TemplateProvider Session Initiated
267 Nect test is to access the RPC via restonf. This is done via ODLs APIDOC explorer.
268 Use this link to open the application, enter login credentials admin, admin <br/>
269 [odl apidoc](http://127.0.0.1:8181/apidoc/explorer/index.html)
272 ### 1.5. Change higher-level POM files
277 ### 1.6. Adapt install.sh script
281 ## 2.0 Test and debug app
283 ### 2.1 Setup and connect netconf simulator
286 ### 2.2 Setup ODL debug level
291 - Karaf Intro and Install