Aria Automation offers different runtime environments, Node.js, PowerShell and Python. Each of them has its own handler routine, more or less. This is a wrapper that contains the commands to be executed within a defined frame. This frame specifically defines the input and output interface. This blog post describes how these handler routines can be emulated locally. This gives the opportunity to test a development as if it were being executed in the context of Aria Automation.

Emulation Templates for the Runtime Environments

The handler routines are structured equivalently. The original handler code from Aria Automation is included between the Begin and End comments. Then there is a function called template that calls the handler routine. The variables Context and Inputs are defined below. The variable context contains dummy values and inputs can be set as desired. Then the template function is executed, which calls the handler. Finally the return values are output.

Node.js

Node.js works exactly as described above, except that the return is done via a callback routine, which is also part of the Aria Automation frame.

/**
 * Aria Automation handler emulation for Node.js
 *
 * @author Stefan Schnell <mail@stefan-schnell.de>
 * @license MIT
 * @version 0.1.0
 */

// Begin ---------------------------------------------------------------

exports.handler = (context, inputs, callback) => {
  console.log('Inputs were ' + JSON.stringify(inputs));
  console.log(inputs.name);



  callback(undefined, {status: "done", result: "Result"});
}

// End -----------------------------------------------------------------

function template(context, inputs, callback) {
  return exports.handler(context, inputs, callback);
}

var context = {
  executionId: '07c137b0-1a96-43f8-9ac1-e1e3c1d3415d',
  returnType: 'Properties',
  vcoUrl: 'http://localhost:8280/vco',
  getToken: function() {}
}

var inputs = {
  name: "Stefan Schnell",
  city: "Oberirsen"
}

callback = (parameter1, outputs) => {
  // Output is from type JSON object.
  //console.log(JSON.stringify(outputs));
  console.log(outputs.status);
  console.log(outputs.result);
}

template(context, inputs, callback);

console.log('\nPress any key to continue...');
process.stdin.setRawMode(true);
process.stdin.resume();
process.stdin.on('data', process.exit.bind(process, 0));

Python

# Aria Automation handler emulation for Python
#
# @author Stefan Schnell <mail@stefan-schnell.de>
# @license MIT
# @version 0.1.0

# Begin ----------------------------------------------------------------

import json

def handler(context, inputs):
  jsonOut = json.dumps(inputs, separators=(',', ':'))
  print("Inputs were {0}".format(jsonOut))



  outputs = {
    "status": "done",
    "result": "Result"
  }

  return outputs

# End ------------------------------------------------------------------

def template(context, inputs):
  return handler(context, inputs)

context = {
  "executionId": "07c137b0-1a96-43f8-9ac1-e1e3c1d3415d",
  "returnType": "Properties",
  "vcoUrl": "http://localhost:8280/vco",
  "getToken": lambda : None
}

inputs = {
  "name": "Stefan Schnell",
  "city": "Oberirsen"
}

outputs = template(context, inputs)

# Output is from type Dictionary and stores the data in key:value pairs.
print(outputs["status"])
print(outputs["result"])

print("\nPress any key to continue...")
input()

PowerShell

<#
 # Aria Automation handler emulation for PowerShell
 #
 # @author Stefan Schnell &lt;mail@stefan-schnell.de&gt;
 # @license MIT
 # @version 0.1.0
 #>

# Begin ----------------------------------------------------------------

function Handler($context, $inputs) {

  $inputsString = $inputs | ConvertTo-Json -Compress;
  Write-Host "Inputs were $($inputsString)";



  $output = @{
    status = "done"
    result = "Result"
  };
  return $output;

}

# End ------------------------------------------------------------------

function template {
  param(
    [Parameter(Mandatory)][Object] $context,
    [Object] $inputs
  )
  Handler -context $context -inputs $inputs;
}

$context = @{
  executionId = "07c137b0-1a96-43f8-9ac1-e1e3c1d3415d"
  returnType = "Properties"
  vcoUrl = "http://localhost:8280/vco"
};

$inputs = @{
  name = "Stefan Schnell"
  city = "Oberirsen"
};

$outputs = template -context $context -inputs $inputs;

# Output is from type System.Collections.Hashtable
# Write-Host $outputs;
Write-Host $outputs.status;
Write-Host $outputs.result;

[Void][Console]::WriteLine("Press any key to continue...");
[Void][Console]::ReadKey("NoEcho,IncludeKeyDown");

Conclusion

The routines presented here can especially support us when testing code that is integrated into Aria Automation via import as zip type. That can simplify development.



This site is part of blog.stschnell.de