SDN Controller Programming Guide
182
alertService.post(Severity.WARNING, alertTopic,
source, data);
}
}
}
...
}
When the optional AlertService is set an alert topic is registered using the AlertService. Such
registration process will return the alert topic to use when the alert is posted. Alert topics are
persistent, thus if the topic was already registered, registering it again will have no effect.
Since AlertService is optional in SwitchManager, the alert will be posted just if the service is
available, thus a check for null is needed before posting the alert.
NOTE
As mentioned before, a better design would make use of the decorator patter [XXX] to decorate
business logic with optional dependencies so no check for null is needed and logics with different
concerns are separated.
Optional services are bound/unbound in a multi-thread environment. An optional service may become
unavailable at any time and thus synchronization methods (Avoided here for simple illustration
purposes) need to be put in place.
To try the new alert feature use the Rsdoc to add and modify an OpenFlow switch so an alert is
generated.
1. Build and install the application as described in Building Application on page 115 and Installing
Application on page 116.
2. Open the HP VAN SDN Controller’s Rsdoc and authenticate as illustrated in Trying the REST API
with RSdoc on page 164.
3. Add (POST) a device using the following JSON document:
{"switch":{"mac_address":"00:00:00:00:00:01","ip_address":"192.168.1.1","friendly_name":"
OpenFlow switch 1"}} (as illustrated in Figure 58)