Skip to content

API Docs - v1.0.6

Env

getEnvironmentProperty (Function)

This function returns Java environment property corresponding to the key provided

Syntax

<STRING> env:getEnvironmentProperty(<STRING> key, <STRING> default.value)

QUERY PARAMETERS

Name Description Default Value Possible Data Types Optional Dynamic
key This specifies Key of the property to be read. STRING No No
default.value This specifies the default Value to be returned if the property value is not available. null STRING Yes No

Examples EXAMPLE 1

define stream keyStream (key string);
from keyStream env:getEnvironmentProperty(key) as FunctionOutput 
insert into outputStream;

This query returns Java environment property corresponding to the key from keyStream as FunctionOutput to the outputStream

getOriginIPFromXForwarded (Function)

This function returns the public origin IP from the given X-Forwarded header

Syntax

<STRING> env:getOriginIPFromXForwarded(<STRING> xforwardedheader)

QUERY PARAMETERS

Name Description Default Value Possible Data Types Optional Dynamic
xforwardedheader X-Forwarded-For header of the request STRING No No

Examples EXAMPLE 1

define stream InputStream (xForwardedHeader string);
from InputStream select env:getOriginIPFromXForwarded(xForwardedHeader) as originIP 
insert into OutputStream;

This query returns the public origin IP from the given X-Forwarded header

getSystemProperty (Function)

This function returns the system property pointed by the system property key

Syntax

<STRING> env:getSystemProperty(<STRING> key, <STRING> default.value)

QUERY PARAMETERS

Name Description Default Value Possible Data Types Optional Dynamic
key This specifies Key of the property to be read. STRING No No
default.value This specifies the default Value to be returned if the property value is not available. null STRING Yes No

Examples EXAMPLE 1

define stream keyStream (key string);
from keyStream env:getSystemProperty(key) as FunctionOutput 
insert into outputStream;

This query returns system property corresponding to the key from keyStream as FunctionOutput to the outputStream

getUserAgentProperty (Function)

This function returns the value corresponding to a given property name in a given user agent

Syntax

<STRING> env:getUserAgentProperty(<STRING> user.agent, <STRING> property.name)

QUERY PARAMETERS

Name Description Default Value Possible Data Types Optional Dynamic
user.agent This specifies the user agent from which property will be extracted. STRING No No
property.name This specifies property name which should be extracted. Supported property names are 'browser', 'os' and 'device'. STRING No No

System Parameters

Name Description Default Value Possible Parameters
regexFilePath Location of the yaml file which contains the regex to process the user agent. Default regexes included in the ua_parser library N/A

Examples EXAMPLE 1

define stream UserAgentStream (userAgent string);
from UserAgentStream 
select env:getUserAgentProperty(userAgent, "browser") as functionOutput 
insert into OutputStream;

This query returns browser name of the userAgent from UserAgentStream as functionOutput to the OutputStream

getYAMLProperty (Function)

This function returns the YAML property requested or the default values specified if such avariable is not available in the deployment.yaml

Syntax

<INT|LONG|DOUBLE|FLOAT|STRING|BOOL> env:getYAMLProperty(<STRING> key, <STRING> data.type, <INT|LONG|DOUBLE|FLOAT|STRING|BOOL> default.value)

QUERY PARAMETERS

Name Description Default Value Possible Data Types Optional Dynamic
key This specifies Key of the property to be read. STRING No No
data.type A string constant parameter expressing the data type of the propertyusing one of the following string values: int, long, float, double, string, bool. string STRING No No
default.value This specifies the default Value to be returned if the property value is not available. null INT
LONG
DOUBLE
FLOAT
STRING
BOOL
Yes No

Examples EXAMPLE 1

define stream keyStream (key string);
from keyStream  env:getYAMLProperty(key) as FunctionOutput 
insert into outputStream;

This query returns corresponding YAML property for the corresponding key from keyStream as FunctionOutput to the outputStream

resourceIdentifier (Stream Processor)

The resource identify stream processor registering the resource name with reference in static map. And serve static resources count for specific resource name.

Syntax

env:resourceIdentifier(<STRING> resource.group.id)

QUERY PARAMETERS

Name Description Default Value Possible Data Types Optional Dynamic
resource.group.id The resource group name. STRING No No

Examples EXAMPLE 1

@info(name='product_color_code_rule') 
from SweetProductDefectsDetector#env:resourceIdentifier("rule-group-1")
select productId, if(colorCode == '#FF0000', true, false) as isValid
insert into DefectDetectionResult;

@info(name='product_dimensions_rule') 
from SweetProductDefectsDetector#env:resourceIdentifier("rule-group-1")
select productId, if(height == 5 && width ==10, true, false) as isValid
insert into DefectDetectionResult;
@info(name='defect_analyzer') 
from DefectDetectionResult#window.env:resourceBatch("rule-group-1", productId, 60000)
select productId, and(not isValid) as isDefected
insert into SweetProductDefectAlert;

These are two rule base queries, which processing the same events from the SweetProductDefectsDetector and output the process results into same stream DefectDetectionResult. Also, the queries like this can be newly introduce into Siddhi Application and the number of output events(in DefectDetectionResult) depends on the number of available queries. If we need to further aggregate results for particular correlation.id: productId from the DefectDetectionResult stream, follow-up queries should wait for events with same correlation.id from all these available queries. For that future queries should know the number of events which can expect from these 'rule' base queries for given correlation id.To address this requirement, in above example, we have defined the resource identifier with 'resource.group.id: rule-group-1' in both the 'rule' queries, so that the other extensions can be used the number of registered resource 'rule-group-1' count for their internal processing. Here the 'defect_analyzer' query has env:resourceBatch window where it uses registered resource 'rule-group-1' count to determine the event waiting condition for events from DefectDetectionResult stream.

resourceBatch (Window)

A resource batch (tumbling) window that holds a number of events with specified attribute as grouping key and based on the resource count inferred from env:resourceIdentifier extension. The window is updated each time a batch of events with same key value that equals the number of resources count.

Syntax

env:resourceBatch(<STRING> resource.group.id, <INT|LONG|FLOAT|BOOL|DOUBLE> correlation.id, <INT|LONG|TIME> time.in.milliseconds)

QUERY PARAMETERS

Name Description Default Value Possible Data Types Optional Dynamic
resource.group.id The resource group name. STRING No No
correlation.id The attribute that should be used for event correlation. INT
LONG
FLOAT
BOOL
DOUBLE
No No
time.in.milliseconds Time to wait for arrival of new event, before flushing and giving output for events belonging to a specific batch. 300000 INT
LONG
TIME
Yes No

Examples EXAMPLE 1

define stream SweetProductDefectsDetector(productId string, colorCode string, height long, width long);
define stream SweetProductDefectAlert(productId string, isDefected bool);

@info(name='product_color_code_rule') 
from SweetProductDefectsDetector#env:resourceIdentifier("rule-group-1")
select productId, if(colorCode == '#FF0000', true, false) as isValid
insert into DefectDetectionResult;

@info(name='product_dimensions_rule') 
from SweetProductDefectsDetector#env:resourceIdentifier("rule-group-1")
select productId, if(height == 5 && width ==10, true, false) as isValid
insert into DefectDetectionResult;

@info(name='defect_analyzer') 
from DefectDetectionResult#window.env:resourceBatch("rule-group-1", productId, 60000)
select productId, and(not isValid) as isDefected
insert into SweetProductDefectAlert;

This example demonstrate the usage of 'env:resourceBatch' widow extension with 'env:resourceIdentifier' stream processor and 'and' attribute aggregator extensions.
 Use Case: The SweetProductDefectsDetector gets the Sweet Production data as an input stream and each event will be sent to the 'rule' queries( 'product_color_code_rule' and 'product_dimensions_rule') . The query 'defect_analyzer' should wait for both the output results from the 'rule' queries output and based on the aggregated results(take the logical AND aggregation of the 'isValid' attribute both events from 'product_color_code_rule' and 'product_dimensions_rule'), generate events and insert into the output stream 'SweetProductDefectAlert'.
In the above example, a number of 'rule' queries can be changed and the 'defect_analyzer' query should wait for results from the all available rules.

To address this use case, we have defined the same resource.group.id: rule-group-1 in all the 'rule' queries, and its registering the resources using 'resourceIdentifier' extension. In the 'defect_analyzer' query we defined the env:resourceBatch("rule-group-1", productId, 2000) window as it will accumulating the events with correlation.id:productId, where it holds the events for same 'productId' until it matches the number of available "rule-group-1" resources or flushing the events if the timeout(time.in.milliseconds:2000) occurs.
To aggregate the results from 'rule' queries, we have used 'and(not isValid)' attribute aggregator where it logically computes AND operation of not isValid boolean attribute values and outputs the results as a boolean value.

Input 1: [SweetProductDefectsDetector]
{
   "event":{
      "productId":"Cake",
      "colorCode":"FF0000",
      "height": 5,
      "width": 10

   }
}

Output 1:[SweetProductDefectAlert]
{
   "event":{
      "productId":"Cake",
      "isDefected":"false"
   }
}

Input 2: [SweetProductDefectsDetector]
{
   "event":{
      "productId":"Cake",
      "colorCode":"FF0000",
      "height": 10,
      "width": 20

   }
}

Output 2:[SweetProductDefectAlert]
{
   "event":{
      "productId":"Cake",
      "isDefected":"true"
   }
}