This application, created from the ONOS UI2 archetype can be deployed in 2 ways
There are 2 main parts to it:
${symbol_h2} Standalone Application outside of ONOS In the standalone scenario this library can continue to be built with Maven like:
The app/BUILD.rename and web/${artifactId}/BUILD.rename files can be discarded or ignored because they are only for building with Bazel.
The ONOS OAR application may be installed with
onos-app localhost install! app/target/${artifactId}-app-1.0-SNAPSHOT.oar
The JavaScript GUI library ${artifactId}-gui-lib-1.0.0.tgz may be included in a new Angular Project by adding the line:
"${artifactId}-gui-lib": "file:../${artifactId}/web/${artifactId}-gui/${artifactId}-gui-lib-1.0.0.tgz"
(ensuring the path is correct) to the dependencies section of the package.json of the new Angular application.
Then in the main folder of the new Angular app run
npm install ${artifactId}-gui-lib gui2-fw-lib d3
Finally to use the ${artifactId}-gui-lib in your new Angular application, add it to the Angular Router and make a link to it
{ path: '${artifactId}-gui', loadChildren: '${artifactId}-gui-lib#${appNameTitle}GuiLibModule' }
and
import { ${appNameTitle}GuiLibModule } from '${artifactId}-gui-lib';
in the imports section at the top of the same file.
providers: [ { provide: LogService, useClass: ConsoleLoggerService }, { provide: 'Window', useValue: window } ],
and to the imports section:
Gui2FwLibModule
and to the import section:
import { Gui2FwLibModule, ConsoleLoggerService, LogService } from 'gui2-fw-lib';
At this stage you should be able to build the new application:
ng build --prod
and then copy the files to the html folder of an Apache or Nginx web server
cp -r dist/<your-app-name>/* /var/www/html
And you should be able to open it in your browser at http://localhost
${symbol_h2} Application embedded within ONOS To embed the application inside ONOS (permanently add it to the ONOS code base) move the application folder in to the ~/onos/apps directory (ensuring its name does not clash with anything already there).
Run
cd ~/onos/apps/${artifactId} && \ mvn -pl web/${artifactId}-gui install && \ mvn -pl web/${artifactId}-gui clean
once inside the folder - this is the easiest way to fetch the dependent node modules for the Angular application.
To ensure it gets built along with ONOS rename the files BUILD.rename, app/BUILD.rename and web/${artifactId}/BUILD.rename to BUILD, and remove the pom.xml files, and some extra files left over from the build.
cd ~/onos/apps/${artifactId} && \ mv BUILD.rename BUILD && \ mv app/BUILD.rename app/BUILD && \ mv web/${artifactId}-gui/BUILD.rename web/${artifactId}-gui/BUILD && \ rm pom.xml && \ rm app/pom.xml && \ rm web/${artifactId}-gui/pom.xml && \ mv web/${artifactId}-gui/gitignore web/${artifactId}-gui/.gitignore && \ chmod +x web/${artifactId}-gui/ng-test.sh && \ rm -rf web/${artifactId}-gui/node_modules/rxjs/src
In the file
Add a reference to the app in ~/onos/tools/build/bazel/modules.bzl at the end of the ONOS_APPS section as:
"//apps/${artifactId}:onos-apps-${artifactId}-oar",
In the file ~/onos/web/gui2/BUILD in the genrule section _onos-gui2-ng-build add to the srcs section:
"//apps/${artifactId}/web/${artifactId}-gui:${artifactId}-gui-lib-build",
and in the cmd section of the same genrule add the following 3 lines (just before the comment "# End of add in modules from external packages"):
" ${appNameAllCaps}_GUI_LIB_FILES=($(locations //apps/${artifactId}/web/${artifactId}-gui:${artifactId}-gui-lib-build)) &&" + # An array of filenames - sorted by time created " tar xf $$ROOT/$${${appNameAllCaps}_GUI_LIB_FILES[0]} &&" + " mv package/ node_modules/${artifactId}-gui-lib/ &&" +
Finally to use the ${artifactId}-gui-lib in the ONOS GUI, add it to the Angular Router
{ path: '${artifactId}-gui', loadChildren: '${artifactId}-gui-lib#${appNameTitle}GuiLibModule' },
and in the imports section at the top of the same file
import { ${appNameTitle}GuiLibModule } from '${artifactId}-gui-lib';
Run Bazel build with
cd ~/onos && \ ob
or equivalent.
Start ONOS in the normal way.
Using the ONOS command line, activate the application:
app activate ${artifactId}
To turn on ONOS Server side logging, from the same ONOS CLI use:
log:set DEBUG ${package} log:set DEBUG org.onosproject.ui.impl
On the ONOS GUI the navigation menu should show the new application link. Clicking on it will navigate to the new app (there is a system of lazy-loading implemented here so that applications are not loaded until they are first used).
To rebuild and run the web side of the application do:
bazel build //web/gui2:onos-web-gui2-oar && \ onos-app localhost reinstall! bazel-bin/web/gui2/onos-web-gui2-oar.oar
To rebuild and run the server side of the application do:
bazel build //apps/${artifactId}:onos-apps-${artifactId}-oar && \ onos-app localhost reinstall! bazel-bin/apps/${artifactId}/onos-apps-${artifactId}-oar.oar
The application demonstrates some major concepts:
The use of Angular 7 concepts like Modules, Components, Service
The top level component - contains the "Fetch Data" button and the connection to the server backend through a WebSocket
Passing a number in the request
Receiving a JSON object in reply
Reuse of items from the gui2-fw-lib - with LogService, WebSocketService and IconComponent
The use of a child component (WelcomeComponent) in 3 different ways
The embedding of SVG content in to the web page
The use of TypeScript (as opposed to JavaScript or ECMAScript directly) to ensure type safety