MachineManager - GateNLP/cloud-client GitHub Wiki

The class uk.ac.gate.cloud.machine.MachineManager is the main entry point if you want to configure, control or monitor existing cloud machines that you have previously reserved.

Creating a client

To create a client instance you need your API key ID and password - if you do not have an API key you can generate one from your account page on the GATE Cloud website. You will need to enable the "manage cloud machines" permission for the API key.

MachineManager mgr = new MachineManager("<key id>", "<password>");

Accessing your machines

You can list all your reserved cloud machines using the listMachines method

List<MachineSummary> allMyMachines = mgr.listMachines();

You can filter the list based on the machine state, for example to check that all the machines that should be currently running are actually running. Note that the objects returned from listMachines are just a brief summary of the machine's state, you must call the details() method to fetch the full details (which requires another HTTP call).

If you know the specific machine you are interested in you can access it directly using getMachine

Machine machine = mgr.getMachine(15);

The Machine class

Once you have obtained a Machine instance from the MachineManager you can use its methods to interact with the machine. The Machine class has public fields holding various information about the machine including its ID, type, time of the last startup or shutdown, and for running machines the URL and password required to access the services that are running on the machine. The Machine object is a snapshot of the machine's state at the point when it was retrieved, you can call the refresh() method to update the object state from the server.

Machine offers public methods to change the machine's name as it appears in your dashboard:

machine.rename("New name for the machine");

and to start the machine if it is stopped or stop it if it is running:

myStoppedMachine.start();
myRunningMachine.stop();

The process of starting and stopping cloud machines takes some time; when you start() an "inactive" machine it will initially move to the "pending" state and then a few minutes later transition to "active", and similarly when you stop() an "active" machine it will initially move to the "stopping" state and then become "inactive" shortly thereafter. You will need to regularly call refresh() to monitor for when these state changes happen.

⚠️ **GitHub.com Fallback** ⚠️