ClusterHostUtil

public class ClusterHostUtil
extends Object

java.lang.Object
   ↳ com.android.tradefed.cluster.ClusterHostUtil


Static util functions for TF Cluster to get global config instances, host information, etc.

Summary

Public constructors

ClusterHostUtil()

Public methods

static IClusterClient getClusterClient()

Get the IClusterClient instance used to interact with the TFC backend.

static IClusterOptions getClusterOptions()

Get the IClusterOptions instance used to store cluster-related settings.

static long getCurrentTimeMillis()

Returns the current system time.

static String getHostIpAddress()

Gets the IP address.

static String getHostName()

Gets the hostname.

static String getLocalDeviceSerial(String serial)

Returns a local device serial for a given unique device serial.

static String getRunTarget(DeviceDescriptor device, String runTargetFormat, deviceTags)

Returns the run target for a given device descriptor.

static String getTestHarness()
static long getTfStartTimeMillis()
static String getTfVersion()

Gets the TF version running on this host.

static String getUniqueDeviceSerial(DeviceDescriptor device)

Returns a unique device serial for a device.

static boolean isLocalhostIpPort(String input)

Checks if a given input is a localhost IP:PORT string.

Protected methods

static String toValidTfVersion(String version)

Validates a TF version and returns it if it is OK.

Public constructors

ClusterHostUtil

public ClusterHostUtil ()

Public methods

getClusterClient

public static IClusterClient getClusterClient ()

Get the IClusterClient instance used to interact with the TFC backend.

Returns
IClusterClient

getClusterOptions

public static IClusterOptions getClusterOptions ()

Get the IClusterOptions instance used to store cluster-related settings.

Returns
IClusterOptions

getCurrentTimeMillis

public static long getCurrentTimeMillis ()

Returns the current system time.

Returns
long time in millis.

getHostIpAddress

public static String getHostIpAddress ()

Gets the IP address.

Returns
String the IPV4 address String or "UNKNOWN" if we were unable to fetch it.

getHostName

public static String getHostName ()

Gets the hostname.

1. Try to get hostname from InetAddress. 2. If fail, try to get hostname from HOSTNAME env. 3. If not set, generate a unique hostname.

Returns
String the hostname or null if we were unable to fetch it.

getLocalDeviceSerial

public static String getLocalDeviceSerial (String serial)

Returns a local device serial for a given unique device serial.

TFC sends down unique device serials for non-physical devices which TF does not understand. This method converts them back to local device serials.

Parameters
serial String: a unique device serial from TFC.

Returns
String a local device serial.

getRunTarget

public static String getRunTarget (DeviceDescriptor device, 
                String runTargetFormat, 
                 deviceTags)

Returns the run target for a given device descriptor.

Parameters
device DeviceDescriptor: DeviceDescriptor to get run target for.

runTargetFormat String

deviceTags

Returns
String run target.

getTestHarness

public static String getTestHarness ()

Returns
String

getTfStartTimeMillis

public static long getTfStartTimeMillis ()

Returns
long

getTfVersion

public static String getTfVersion ()

Gets the TF version running on this host.

Returns
String this host's TF version.

getUniqueDeviceSerial

public static String getUniqueDeviceSerial (DeviceDescriptor device)

Returns a unique device serial for a device.

Non-physical devices (e.g. emulator) have pseudo serials which are not unique across hosts. This method prefixes those with a hostname to make them unique.

Parameters
device DeviceDescriptor: a device descriptor.

Returns
String a unique device serial.

isLocalhostIpPort

public static boolean isLocalhostIpPort (String input)

Checks if a given input is a localhost IP:PORT string.

Parameters
input String: a string to check

Returns
boolean true if the given input is a localhost IP:PORT string

Protected methods

toValidTfVersion

protected static String toValidTfVersion (String version)

Validates a TF version and returns it if it is OK.

Parameters
version String: The string for a TF version provided by VersionParser

Returns
String the version if valid or a default if not.