VMware Aria Automation Blog

from Stefan Schnell

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
 */

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

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



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

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

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);
}

exports.handler(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

The approach shown here can also be used directly in VMware Aria Automation without modifications. Aria Automation only executes the handler function and ignores the call of the main function. On the one hand this generates dead code, because it is never executed in the context of Aria Automation, but on the other hand we have code that we can also use immediately outside of Aria Automation.

"""
Aria Automation handler emulation for Python
"""

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

import json

def handler(context, inputs):
    """ Standard Aria Automation handler function """

    json_out = json.dumps(inputs, separators=(',', ':'))
    print(f"Inputs were {json_out}")



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

    return outputs

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

def main():
    """ Main function """

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

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

    outputs = handler(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()

if __name__ == "__main__":
    main()


PowerShell

<#
 # Aria Automation handler emulation for PowerShell
 #>

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

function Handler($context, $inputs) {

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



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

}

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

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

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

$outputs = Handler -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.