While Software AG is busy adding features to Apama, the community is busy creating and publishing things as well. We maintain an index of the various community-created projects here. We hope that these community libraries and plug-ins can be useful for others and share them for people to use. Improvements and contributions are also very welcome.
This is part two of this series of community round-up blogs. You can find the first blog post here, which looked at some EPL libraries. In this blog post we will cover some recent EPL plug-ins.
EPL Localization
Support for other languages and locales is something which Apama holds quite highly. It’s a 100% UTF-8 end-to-end system which allows people to provide text in any language or character set. However, this is only half of the story. The other problem is being able to provide text in multiple languages, which might have different rules about numbers and plurals etc, and automatically selecting the correct text at the right time. Although Apama allows people to write applications in any language, at the moment it doesn’t allow people to write applications in multiple languages and easily switch between them at runtime.
The EPL L10N Plug-in solves this problem. Taking advantage of the open-source GNU gettext project and all of its utilities for translation and multiple language support, this plug-in provides a simple way to write EPL, extract text snippets from it, create translations and select the appropriate translation at runtime, based on the locale in which Apama is running.
More information can be found in the GitHub project and the API documentation for the library, but here is a small taste of how to write a translatable string in EPL:
// A single translatable string
log _("Setup and waiting for messages");
// Formatting data into a translatable string
log printf(_("Caught exception type %1$s message: %2$s"), [<any>e.getType(), e.getMessage()]);
// A string with variants for singular and plural
log printf(_N("Received a total of one message, it is %1$s", "Received a total of %2$d messages, latest is %1$s", count), [<any>me.toString(), count]);
The user picks one language to write in the source, then the gettext tools can extract all the strings into a file which can be sent to translators, including managing which strings have changed and need updating in subsequent releases. The translations are then compiled into the standard gettext format, which can be read by the L10N library. At runtime, a different locale will select the appropriate translations.
English
> correlator --config sample
Setup and waiting for messages
Received a total of one message, it is EventOne
Received a total of 2 messages, latest is EventTwo
Received a total of 3 messages, latest is EventThree
Spanish
> LANG=es_MX.utf8 correlator --config sample
Configurar y esperar mensajes
Recibió un total de 1 mensaje, es EventOne
Recibió un total de 2 mensajes, el último es EventTwo
Recibió un total de 3 mensajes, el último es EventThree
Authentication
The standard Apama product can host an HTTP server which provides basic usename/password authentication via HTTP basic and a static password file. This new community plug-in provides a more fully-featured authentication layer for storing hashed and salted passwords using MemoryStore in a persistent but dynamically-updatable fashion. It also provides Base64 and HTTP Basic Authorization header encoding and decoding so that it can replace the static HTTP authentication seamlessly from EPL. Lastly, it provides a session-cache layer to provide authentication tokens which can be stored by web applications in cookies, with automatic session expiry and renewal.
The Authentication plug-in can be found on GitHub along with the API documentation.
A complete set of requests with the full authentication and session token protocol could look like this:
Implementation of the HTTP server chain and responses are left to the user to integrate into their own application, the Authentication plug-in provides the memory store, password hashing, header decoding and session token management functions, which should be integrated with the user’s REST implementation on the HTTP server transport.
TP-Link Kasa device management
The Internet of Things is the latest big development in the IT world. It’s something which in the industrial world Software AG is heavily involved through the Cumulocity IoT and Apama Streaming Analytics platforms. In the consumer market this is largely represented by Smart Home technology. One of the major players in this area is TP-Link® who with their Kasa Smart™ line provide smart plugs, smart light bulbs and more. TP-Link provide their own cloud-based solution for managing their devices, but combining them with the power of Software AG’s Apama platform provides even more opportunities. This library provides an EPL plug-in to allow Apama application writers to discover, manage and control Kasa devices on their network.
The TP-Link Kasa plug-in can be found on GitHub along with the API documentation. This plug-in uses Apama’s Python integration. The plug-in provides the following functions on the following device types:
White bulb | Color bulb | Plug | Power strip | |
---|---|---|---|---|
Discover | ||||
Lookup by address | ||||
Get device state | ||||
Get device information | ||||
Turn on/off | ||||
Turn on individual sockets | ||||
Set brightness | ||||
Set colour |
Once EPL can interact with the devices you can use the power of Apama to control them. Actions on multiple devices, changing lights at certain times, or in response to sensors are just some of the options – your imagination is the limit.
Future directions
The market for smart devices is large and there are a lot of vendors. Support for other brand lines, or more types of device from TP-Link are always welcome.
Summary
These are just a couple of the community activities going on outside of the official Software AG ecosystem. We hope they may prove useful. Please contact the author of the plugins via github if you have any useful comments and as always feel free to ask questions via the apama tag on Stackoverflow.
Look out for the next blog post in this series,
Matt