VCF Automation Blog

from Stefan Schnell

The building of an equivalent JavaScript execution environment, like in Aria Automation, can be very helpful, to support and simplify this kind of software development. Surely this is not an easy way and involved with some efforts. This requires many small steps, that fit together step by step, like the pieces of a puzzle. This blog post shows a first approach that tries to do this.

Program Example Using JavaScript Emulation


Based on the following list of blog posts an example is shown in which combines these approaches. The combination of these approaches allows to program source codes that can be executed unchanged with different operating systems, different JDKs and different system environments, also in Aria Automation. Using Java programs with different operating systems and JDKs is not magic, this is a fundamental approach of Java. Our stack is operating system > JDK > Rhino JavaScript engine > Aria Automation Dunes framework > JavaScript program. The challenge here is to simulate the Dunes framework, the bridge between the program and the JavaScript engine. First emulations of classes are available and will be used as an example to demonstrate this kind of scenario, here with the detection of system information.

The Program

This program collects information about the operating system, the Java runtime, the Rhino engine, if its executing in Aria Automation and the Linux distribution. Without the load commands it is possible to run this program unmodified in the JavaScript runtime environment of Aria Automation.

load("System.class.js");
load("Command.class.js");

/**
 * @author Stefan Schnell <mail@stefan-schnell.de>
 * @license MIT
 * @version 0.1.0
 *
 * Set in the VMware Control Center the system property
 * com.vmware.js.allow-local-process to true and
 * com.vmware.scripting.javascript.allow-native-object to true.
 */

// Operating system
var osName = String(java.lang.System.getProperty("os.name"));
var osVersion = String(java.lang.System.getProperty("os.version"));
var osArchitecture = String(java.lang.System.getProperty("os.arch"));

System.log("OS Name: " + osName);
System.log("OS Version: " + osVersion);
System.log("OS Architecture: " + osArchitecture);
System.log("\n");

// Java
var javaVendor = String(java.lang.System.getProperty("java.vendor"));
var javaVersion = String(java.lang.System.getProperty("java.version"));

System.log("Java Vendor: " + javaVendor);
System.log("Java Version: " + javaVersion);
System.log("\n");

// Rhino
var contextFactory = new org.mozilla.javascript.ContextFactory();
var context = contextFactory.getGlobal().enterContext();
var rhinoVersion = String(context.getImplementationVersion());
context.exit();

System.log(rhinoVersion);
System.log("\n");

// Aria Automation
var OrchestrationUiServiceHost = java.lang.System.getenv(
  "ORCHESTRATION_UI_SERVICE_HOST"
);

var IS_RUNNING_IN_ARIA_AUTOMATION = false;
if (OrchestrationUiServiceHost !== null) {
  IS_RUNNING_IN_ARIA_AUTOMATION = true;
}

if (IS_RUNNING_IN_ARIA_AUTOMATION) {
  var ariaVersion =
    java.lang.System.getProperty("com.vmware.o11n.version.platform");
  System.log("Program is running in Aria Automation " + ariaVersion);
} else {
  System.log("Program is not running in Aria Automation");
}
System.log("\n");

// Linux distribution
if (osName.indexOf("Linux") !== -1) {

  var command = new Command("cat /etc/os-release");
  command.execute(true);
  var osIdentificationData = command.output;

  System.log(osIdentificationData);

}

Windows

program uses javascript emulation on windows
Program Uses JavaScript Emulation in Windows

RHEL

program uses javascript emulation on red hat enterprise linux
Program Uses JavaScript Emulation in Red Hat Enterprise Linux

Aria Automation

program uses javascript on vcf automation
Program Uses JavaScript in Aria Automation

Conclusion

This is only a simple approach, but it shows us potential. This does not mean that all classes of Aria Automation have to be fully provided to use this approach. They can also be partially faked with a mock-up. But this approach can be used fast and very well when 3rd party JavaScript libraries are to be used in Aria Automation, e.g. to test calls and procedures - a lucrative use case.