SDN Controller Programming Guide

176
function load(view) {
v.setToolbar(def.tbButton(view.mkId('btn'), view.lion('key-button'),
'', function () {
$.get('/sdn/ui/hm/app/rs/switches', function(data) {
v.setContent($('<span/>').addClass("hm-message-
style").append(data));
});
}));
}
...
As seen in the code the view connects to the relative path “/sdn/ui/hm/app/rs/switches so the
connection is opened to the same controller that generated the web page. The prefix
“/sdn/ui/hm must match the web.context.path property defined in Module Configuration on
page 168 under the “hm-ui/pom.xml to generate .warlisting. The infix app/rsis given by the
Jersey Servlet mapping configuration in GUI-Specific REST API on page 173 under the “UI Module
Web Application (web.xml) Defining Jersey Servlet” listing, and the suffix switchesis the relative
path of the resource given by the @Path annotation in the GUI-Specific REST API on page 173
under the “SwitchViewResource.java” listing.
In this case, the response media type (in SwitchViewResource) is defined as TEXT_PLAN. This
means that the data parameter of the $.get() function callback is filled in with a plan string. The
media type can also be defined as APPLICATION_JSON and return a JSON formatted string. In
which case, the JavaScript [40] data parameter would be an object.
No need to worry about authentication because the SKI framework automatically includes the
authentication token generated when after login (Figure 40) into the HTTP request headers.
Now try the application’s user interface again. Build and install the application as described in
Building Application on page 115 and Installing Application on page 116. After installing the
application refresh the SDN Controller GUI as illustrated at the top part of Figure 56; the
application’s GUI entry will appear as illustrated at the bottom part of Figure 56. Now the
message returned by SwitchViewResource can be seen after clicking the “Refresh Databutton.
Using SDN Controller Services
In the following information some of the services provided by the HP VAN SDN Controller will be
consumed to illustrate the philosophy followed by the controller: OSGi declareative services as
depicted in section Consuming Services with OSGi Declarative Services on page 134.
Services published by the controller are meant to be consumed by the application’s business logic.
Some services are available to the RESTful web services, however, as depicted in Domain Service -
REST API Integration on page 148, web services should not implement any logic but controller
logic. Thus, it is considered a good practice to always delegate to the business logic.
At this point RESTful web services and busness logic are fully integrated. A simple in-memory data
structure will be used to store OpenFlow switches data. The following listings illustrate the complete
implementation of SwitchManager and SwitchResource that will be used to consume HP VAN SDN
Controller services. These implementations allow the REST API to be functional for small transient
data (Filtering and sorting still pending).