private static List<String> safeGetChildren(final ZooKeeperClient client, final String path) { try { return client.getChildren(path); } catch (KeeperException ignore) { return ImmutableList.of(); } }
@Override Iterable<String> collectItems() { final String path = Paths.historyJobs(); List<String> jobIds = Collections.emptyList(); try { jobIds = client.getChildren(path); } catch (KeeperException e) { log.warn("Failed to get children of znode {}", path, e); } return jobIds; }
@Override public List<String> getChildren(String path) throws KeeperException { return reporter.time(tag, "getChildren", () -> client.getChildren(path)); }
private List<JobId> listHostJobs(final ZooKeeperClient client, final String host) { final List<String> jobIdStrings; final String folder = Paths.statusHostJobs(host); try { jobIdStrings = client.getChildren(folder); } catch (KeeperException.NoNodeException e) { return null; } catch (KeeperException e) { throw new HeliosRuntimeException("List tasks for host failed: " + host, e); } final ImmutableList.Builder<JobId> jobIds = ImmutableList.builder(); for (final String jobIdString : jobIdStrings) { jobIds.add(JobId.fromString(jobIdString)); } return jobIds.build(); }
/** * Returns a list of the hosts/agents that have been registered. */ @Override public List<String> listHosts() { try { // TODO (dano): only return hosts whose agents completed registration (i.e. has id nodes) return provider.get("listHosts").getChildren(Paths.configHosts()); } catch (KeeperException.NoNodeException e) { return emptyList(); } catch (KeeperException e) { throw new HeliosRuntimeException("listing hosts failed", e); } }
static void initializeAclRecursive(final ZooKeeperClient client, final String path, final ACLProvider aclProvider) throws KeeperException { try { final List<ACL> expected = aclProvider.getAclForPath(path); final List<ACL> actual = client.getAcl(path); if (newHashSet(expected).equals(newHashSet(actual))) { // actual ACL matches expected } else { client.setAcl(path, expected); } for (final String child : client.getChildren(path)) { initializeAclRecursive(client, path.replaceAll("/$", "") + "/" + child, aclProvider); } } catch (Exception e) { throwIfInstanceOf(e, KeeperException.class); throw new RuntimeException(e); } } }
private List<String> listJobHosts(final ZooKeeperClient client, final JobId jobId) throws JobDoesNotExistException { final List<String> hosts; try { hosts = client.getChildren(Paths.configJobHosts(jobId)); } catch (NoNodeException e) { throw new JobDoesNotExistException(jobId); } catch (KeeperException e) { throw new HeliosRuntimeException("failed to list hosts for job: " + jobId, e); } return hosts; }
private UUID getJobCreation(final ZooKeeperClient client, final JobId id) throws KeeperException { final String parent = Paths.configHostJobCreationParent(id); final List<String> children = client.getChildren(parent); for (final String child : children) { if (Paths.isConfigJobCreation(child)) { return Paths.configJobCreationId(child); } } return null; }
private void syncChecked() throws KeeperException { final ZooKeeperClient client = client("sync"); final List<String> nodes = client.getChildren(path); final Map<String, byte[]> snapshot = entries.get();
/** * Returns a list of the host names of the currently running masters. */ @Override public List<String> getRunningMasters() { final ZooKeeperClient client = provider.get("getRunningMasters"); try { final List<String> masters = client.getChildren(Paths.statusMaster()); final ImmutableList.Builder<String> upMasters = ImmutableList.builder(); for (final String master : masters) { if (client.exists(Paths.statusMasterUp(master)) != null) { upMasters.add(master); } } return upMasters.build(); } catch (KeeperException e) { throw new HeliosRuntimeException("listing masters failed", e); } }
client.getChildren(Paths.historyJobHosts(jobId)); } catch (NoNodeException e) { return emptyList(); final List<String> events; try { events = client.getChildren(Paths.historyJobHostEvents(jobId, h)); } catch (NoNodeException e) { continue;
final List<String> names; try { names = client.getChildren(folder); } catch (NoNodeException e) { return Maps.newHashMap();
final List<String> ids; try { ids = client.getChildren(folder); } catch (NoNodeException e) { return Maps.newHashMap();
final List<String> names; try { names = client.getChildren(folder); } catch (NoNodeException e) { return Collections.emptyMap();
private Map<JobId, Deployment> getTasks(final ZooKeeperClient client, final String host) { final Map<JobId, Deployment> jobs = Maps.newHashMap(); try { final String folder = Paths.configHostJobs(host); final List<String> jobIds; try { jobIds = client.getChildren(folder); } catch (KeeperException.NoNodeException e) { log.warn("Unable to get deployment config for {}", host, e); return ImmutableMap.of(); } for (final String jobIdString : jobIds) { final JobId jobId = JobId.fromString(jobIdString); final String containerPath = Paths.configHostJob(host, jobId); try { final byte[] data = client.getData(containerPath); final Task task = parse(data, Task.class); jobs.put(jobId, Deployment.of(jobId, task.getGoal(), task.getDeployerUser(), task.getDeployerMaster(), task.getDeploymentGroupName())); } catch (KeeperException.NoNodeException ignored) { log.debug("deployment config node disappeared: {}", jobIdString); } } } catch (KeeperException | IOException e) { throw new HeliosRuntimeException("getting deployment config failed", e); } return jobs; }
final List<String> events = client.getChildren(Paths.historyJobHostEvents(jobId, hostname)); if (events.size() > MAX_NUMBER_STATUS_EVENTS_TO_RETAIN) { trimStatusEvents(events, jobId);
private List<String> safeGetChildren(final ZooKeeperClient client, final String path) { try { return client.getChildren(path); } catch (KeeperException ignore) { return ImmutableList.of(); } }
@Override public List<String> getChildren(String path) throws KeeperException { try { return client.getChildren(path); } catch (KeeperException e) { reporter.checkException(e, tag, "getChildren"); throw e; } }
private List<String> listJobHosts(final ZooKeeperClient client, final JobId jobId) throws JobDoesNotExistException { final List<String> hosts; try { hosts = client.getChildren(Paths.configJobHosts(jobId)); } catch (NoNodeException e) { throw new JobDoesNotExistException(jobId); } catch (KeeperException e) { throw new HeliosRuntimeException("failed to list hosts for job: " + jobId, e); } return hosts; }
private UUID getJobCreation(final ZooKeeperClient client, final JobId id) throws KeeperException { final String parent = Paths.configHostJobCreationParent(id); final List<String> children = client.getChildren(parent); for (final String child : children) { if (Paths.isConfigJobCreation(id, parent, child)) { return Paths.configJobCreationId(id, parent, child); } } return null; }