@Override public byte[] getData(String path) throws KeeperException { return reporter.time(tag, "getData", () -> client.getData(path)); }
private <T> T tryGetEntity(final ZooKeeperClient client, String path, TypeReference<T> type, String name) { try { final byte[] data = client.getData(path); return Json.read(data, type); } catch (NoNodeException e) { return null; } catch (KeeperException | IOException e) { throw new HeliosRuntimeException("reading " + name + " info failed", e); } }
@Nullable private TaskStatus getTaskStatus(final ZooKeeperClient client, final String host, final JobId jobId) { final String containerPath = Paths.statusHostJob(host, jobId); try { final byte[] data = client.getData(containerPath); return parse(data, TaskStatus.class); } catch (NoNodeException ignored) { return null; } catch (KeeperException | IOException e) { throw new HeliosRuntimeException("Getting task " + jobId + " status " + "for host " + host + " failed", e); } }
private Job getJob(final ZooKeeperClient client, final JobId id) { final String path = Paths.configJob(id); try { final byte[] data = client.getData(path); return Json.read(data, Job.class); } catch (NoNodeException e) { // Return null to indicate that the job does not exist return null; } catch (KeeperException | IOException e) { throw new HeliosRuntimeException("getting job " + id + " failed", e); } }
private void assertHostExists(final ZooKeeperClient client, final String host) throws HostNotFoundException { try { client.getData(Paths.configHost(host)); } catch (NoNodeException e) { throw new HostNotFoundException(host, e); } catch (KeeperException e) { throw new HeliosRuntimeException(e); } }
private void assertTaskExists(final ZooKeeperClient client, final String host, final JobId jobId) throws JobNotDeployedException { try { client.getData(Paths.configHostJob(host, jobId)); } catch (NoNodeException e) { throw new JobNotDeployedException(host, jobId); } catch (KeeperException e) { throw new HeliosRuntimeException(e); } }
for (final String node : nodes) { final String nodePath = ZKPaths.makePath(path, node); final byte[] data = client.getData(nodePath); remote.put(node, data);
private DeploymentGroup getDeploymentGroup(final ZooKeeperClient client, final String name) throws DeploymentGroupDoesNotExistException { try { final byte[] data = client.getData(Paths.configDeploymentGroup(name)); return Json.read(data, DeploymentGroup.class); } catch (NoNodeException e) { throw new DeploymentGroupDoesNotExistException(name); } catch (KeeperException | IOException e) { throw new HeliosRuntimeException("getting deployment-group " + name + " failed", e); } }
final byte[] data = client.getData(Paths.historyJobHostEventsTimestamp( jobId, h, Long.valueOf(event))); final TaskStatus status = Json.read(data, TaskStatus.class);
final String path = Paths.configDeploymentGroup(name); try { final byte[] data = client.getData(path); final DeploymentGroup descriptor = parse(data, DeploymentGroup.class); descriptors.put(descriptor.getName(), descriptor);
final String path = Paths.configJob(jobId); try { final byte[] data = client.getData(path); final Job descriptor = parse(data, Job.class); descriptors.put(descriptor.getId(), descriptor);
ZooKeeperRegistrarUtil.registerHost(client, idPath, name, id); } else { final byte[] bytes = client.getData(idPath); final String existingId = bytes == null ? "" : new String(bytes, UTF_8); if (!id.equals(existingId)) {
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; }
private static void checkForPortConflicts(final ZooKeeperClient client, final String host, final int port, final JobId jobId) throws JobPortAllocationConflictException { try { final String path = Paths.configHostPort(host, port); if (client.stat(path) == null) { return; } final byte[] b = client.getData(path); final JobId existingJobId = parse(b, JobId.class); throw new JobPortAllocationConflictException(jobId, existingJobId, host, port); } catch (KeeperException | IOException ex) { throw new HeliosRuntimeException("checking port allocations failed", ex); } }
/** * Returns the current deployment state of {@code jobId} on {@code host}. */ @Override public Deployment getDeployment(final String host, final JobId jobId) { final String path = Paths.configHostJob(host, jobId); final ZooKeeperClient client = provider.get("getDeployment"); try { final byte[] data = client.getData(path); final Task task = parse(data, Task.class); return Deployment.of(jobId, task.getGoal(), task.getDeployerUser(), task.getDeployerMaster(), task.getDeploymentGroupName()); } catch (KeeperException.NoNodeException e) { return null; } catch (KeeperException | IOException e) { throw new HeliosRuntimeException("getting deployment failed", e); } }
@Override public byte[] getData(String path) throws KeeperException { try { return client.getData(path); } catch (KeeperException e) { reporter.checkException(e, tag, "getData"); throw e; } }
private <T> T tryGetEntity(final ZooKeeperClient client, String path, TypeReference<T> type, String name) { try { final byte[] data = client.getData(path); return Json.read(data, type); } catch (NoNodeException e) { return null; } catch (KeeperException | IOException e) { throw new HeliosRuntimeException("reading " + name + " info failed", e); } }
private void assertHostExists(final ZooKeeperClient client, final String host) throws HostNotFoundException { try { client.getData(Paths.configHost(host)); } catch (NoNodeException e) { throw new HostNotFoundException(host, e); } catch (KeeperException e) { throw new HeliosRuntimeException(e); } }
private Job getJob(final ZooKeeperClient client, final JobId id) { final String path = Paths.configJob(id); try { final byte[] data = client.getData(path); return Json.read(data, Job.class); } catch (NoNodeException e) { // Return null to indicate that the job does not exist return null; } catch (KeeperException | IOException e) { throw new HeliosRuntimeException("getting job " + id + " failed", e); } }
private DeploymentGroup getDeploymentGroup(final ZooKeeperClient client, final String name) throws DeploymentGroupDoesNotExistException { try { final byte[] data = client.getData(Paths.configDeploymentGroup(name)); return Json.read(data, DeploymentGroup.class); } catch (NoNodeException e) { throw new DeploymentGroupDoesNotExistException(name); } catch (KeeperException | IOException e) { throw new HeliosRuntimeException("getting deployment-group " + name + " failed", e); } }