
water.api.CloudV3 Maven / Gradle / Ivy
package water.api;
import water.*;
import java.util.concurrent.ConcurrentHashMap;
public class CloudV3 extends RequestSchema {
/**
* Data structure to store last tick counts from a given node.
*/
private static class LastTicksEntry {
final public long _system_idle_ticks;
final public long _system_total_ticks;
final public long _process_total_ticks;
LastTicksEntry(HeartBeat hb) {
_system_idle_ticks = hb._system_idle_ticks;
_system_total_ticks = hb._system_total_ticks;
_process_total_ticks = hb._process_total_ticks;
}
}
/**
* Store last tick counts for each node.
*
* This is local to a node and doesn't need to be Iced, so make it transient.
* Access this each time the Cloud status page is called on this node.
*
* The window of tick aggregation is between calls to this page (which might come from the browser or from REST
* API clients).
*
* Note there is no attempt to distinguish between REST API sessions. Every call updates the last tick count info.
*/
private static transient ConcurrentHashMap ticksHashMap = new ConcurrentHashMap<>();
public CloudV3() {}
// This Schema has no inputs
@API(help="skip_ticks", direction=API.Direction.INPUT)
public boolean skip_ticks = false;
// Output fields
@API(help="version", direction=API.Direction.OUTPUT)
public String version;
@API(help="branch_name", direction=API.Direction.OUTPUT)
public String branch_name;
@API(help="build_number", direction=API.Direction.OUTPUT)
public String build_number;
@API(help="Node index number cloud status is collected from (zero-based)", direction=API.Direction.OUTPUT)
public int node_idx;
@API(help="cloud_name", direction=API.Direction.OUTPUT)
public String cloud_name;
@API(help="cloud_size", direction=API.Direction.OUTPUT)
public int cloud_size;
@API(help="cloud_uptime_millis", direction=API.Direction.OUTPUT)
public long cloud_uptime_millis;
@API(help="cloud_healthy", direction=API.Direction.OUTPUT)
public boolean cloud_healthy;
@API(help="Nodes reporting unhealthy", direction=API.Direction.OUTPUT)
public int bad_nodes;
@API(help="Cloud voting is stable", direction=API.Direction.OUTPUT)
public boolean consensus;
@API(help="Cloud is accepting new members or not", direction=API.Direction.OUTPUT)
public boolean locked;
@API(help="Cloud is in client mode.", direction=API.Direction.OUTPUT)
public boolean is_client;
@API(help="nodes", direction=API.Direction.OUTPUT)
public NodeV3[] nodes;
// Output fields one-per-JVM
public static class NodeV3 extends Schema {
public NodeV3() {}
@API(help="IP", direction=API.Direction.OUTPUT)
public String h2o;
@API(help="IP address and port in the form a.b.c.d:e", direction=API.Direction.OUTPUT)
public String ip_port;
@API(help="(now-last_ping) 0) {
long system_idle_ticks_delta = hb._system_idle_ticks - lte._system_idle_ticks;
double sys_cpu_frac_double = 1 - ((double)(system_idle_ticks_delta) / (double)system_total_ticks_delta);
if (sys_cpu_frac_double < 0) sys_cpu_frac_double = 0; // Clamp at 0.
else if (sys_cpu_frac_double > 1) sys_cpu_frac_double = 1; // Clamp at 1.
sys_cpu_pct = (int)(sys_cpu_frac_double * 100);
long process_total_ticks_delta = hb._process_total_ticks - lte._process_total_ticks;
double process_cpu_frac_double = ((double)(process_total_ticks_delta) / (double)system_total_ticks_delta);
// Saturate at 0 and 1.
if (process_cpu_frac_double < 0) process_cpu_frac_double = 0; // Clamp at 0.
else if (process_cpu_frac_double > 1) process_cpu_frac_double = 1; // Clamp at 1.
my_cpu_pct = (int)(process_cpu_frac_double * 100);
}
}
LastTicksEntry newLte = new LastTicksEntry(hb);
ticksHashMap.put(h2o.toString(), newLte);
}
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy