Running Asadmin Commands on Bootstrapped Instances using the API

It is possible to execute administration commands programmatically using the
Payara Micro API,
using the PayaraMicroRuntime.run method.

There are two overloaded forms that can be used:

run(String command, String…​ args )

This method executes the specified asadmin command on all instances in the
runtime’s cluster. It returns a Map<InstanceDescriptor, Future<ClusterCommandResult>>,
which can be used to inspect the results of the execution on each instance the
command was executed.

This method executes the specified asadmin command on all instances contained
in the Collection supplied. As with the previous method, it returns a
Map<InstanceDescriptor, Future<ClusterCommandResult>>, which can be used to
inspect the results of the command execution.



For both methods, it’s recommended to use the getClusteredPayaras() method
exposed by the PayaraMicroRuntime class to retrieve a list of all the instances
in the cluster and determine which command executions should be filtered.

Here’s an example of how to use the first form of the method that executes
the deploy subcommand to deploy an application and parses the results to
check out if the application was successfully deployed on all instances of the
cluster: