Automatic Initialization at Startup

Key Concepts

  • How to run queries on startup automatically?
  • Bulk Initialization patterns.



Background

Device Management

Bulk initialization of Things is closely tied to the device management aspect of IoT Platform. The devices layer is the most important component of an IoT solution. A mature IoT platform comes with comprehensive device management features that let customers:

  • On-board existing and new devices with rich metadata. 
  • Identical devices that share the same metadata are grouped together. This feature makes it possible to search devices based on their capabilities.
  • The platform also provides per-device authentication and authorization to enforce enhanced security. 
  • It makes it easy to define which devices can connect, send, and receive messages. 
  • Devices can be easily blacklisted and whitelisted through declarative policies.

A-Stack platform provide mechanisms to easily address above device management requirements.

Bulk Initialization Design Pattern

At the time of writing this tutorial Atomiton A-Stack does not provide specific language constructs to perform bulk initialization of Things or Data. But the existing Atomic domain languages capabilities can be exploited to achieve bulk initialization requirements. The bulk initialization design pattern can be broken down into two steps:


Bulk Initialization Steps: 

Step #NameDescriptionOutputImplementation Flow
1Gather Metadata

Input to gathering of metadata step can be:

  • Manual entires
  • Code that generates metadata
  • Reading metadata from external device management source

The output of gathering metadata step could be:

  • Generated CSV, JSON Files
  • Generated Create / Save TQL Query statement
  • @TQL Macro, AppModel, AppFacet
  • Gather and Initialize can be combined into same flow.
  • Decoupled implementation from A-Stack
    (Example: NodeJS generating series of JSON files)
2Initialize

Initialize step includes:

  • Load the data into A-Stack.
  • Metadata gathered from step-1 serves as input.
  • This steps has to be repeatable.

The output of initialize steps are:

  • Data and Things loaded into A-Stack.
  • May or may not note trigger actions.
  • @TQL Query
  • Can be integrated into Gather Metadata step.
3.Run Queries Automatically

There are often requirements to run queries automatically at startup. For scenarios as listed below it becomes imperative to run queries automatically:

  • Auto create schedules. Note that schedule jobs are not persisted in permanent storage.
  • Auto create topic subscriptions.
  • Device initialization - Automatically start sensors / actuators.
  • Previously created schedules, subscriptions, and connected sensors and actuators.
  • Create a simple MessageFacet in a different package file.
  • Example: Example Startup Facet
  • Add this mqp as the last entry to sff.auto.deploy tag as part of sff.local.config.xml