* @throws WaitTimeoutException if the wait timed out
*/
@VisibleForTesting
public int waitForRoleInstanceLive(String role, long timeout)
throws WaitTimeoutException, IOException, YarnException {
Duration duration = new Duration(timeout).start();
boolean live = false;
int state = ClusterDescription.STATE_CREATED;
log.info("Waiting {} millis for a live node in role {}", timeout, role);
while (!live) {
// see if there is a node in that role yet
List<String> uuids = innerListNodeUUIDSByRole(role);
String[] containers = uuids.toArray(new String[uuids.size()]);
int roleCount = containers.length;
ClusterNode roleInstance = null;
if (roleCount != 0) {
// if there is, get the node
roleInstance = getNode(containers[0]);
if (roleInstance != null) {
state = roleInstance.state;
live = state >= ClusterDescription.STATE_LIVE;
}
}
if (!live) {
if (duration.getLimitExceeded()) {
throw new WaitTimeoutException(
String.format("Timeout after %d millis" +
" waiting for a live instance of type %s; " +
"instances found %d %s",
timeout, role, roleCount,