@Override public void setData(String path, byte[] bytes) throws KeeperException { reporter.time(tag, "setData", () -> { client.setData(path, bytes); return null; }); }
private void write(final String node, final byte[] data) throws KeeperException { final ZooKeeperClient client = client("write"); final String nodePath = ZKPaths.makePath(path, node); if (client.stat(nodePath) != null) { log.debug("setting node: {}", nodePath); client.setData(nodePath, data); } else { log.debug("creating node: {}", nodePath); client.createAndSetData(nodePath, data); } }
client.createAndSetData(path, write.data); } else { client.setData(path, write.data);
} else if (!Arrays.equals(remoteData, localData)) { log.debug("sync: updating node {}", nodePath); client.setData(nodePath, localData); remote.put(node, localData);
@Override public boolean update(final byte[] bytes) { final String parent = ZKPaths.getPathAndNode(path).getPath(); try { if (zooKeeperClient.stat(parent) == null) { return false; } if (zooKeeperClient.stat(path) == null) { zooKeeperClient.createAndSetData(path, bytes); } else { zooKeeperClient.setData(path, bytes); } return true; } catch (KeeperException.NodeExistsException ignore) { // Conflict due to curator retry or losing a race. We're done here. return true; } catch (KeeperException.ConnectionLossException e) { log.warn("ZooKeeper connection lost while updating node: {}", path); return false; } catch (KeeperException e) { log.error("failed to update node: {}", path, e); return false; } } }
/** * Used to update the existing deployment of a job. */ @Override public void updateDeployment(final String host, final Deployment deployment, final String token) throws HostNotFoundException, JobNotDeployedException, TokenVerificationException { log.info("updating deployment {}: {}", deployment, host); final ZooKeeperClient client = provider.get("updateDeployment"); final JobId jobId = deployment.getJobId(); final Job job = getJob(client, jobId); final Deployment existingDeployment = getDeployment(host, jobId); if (job == null) { throw new JobNotDeployedException(host, jobId); } verifyToken(token, job); assertHostExists(client, host); assertTaskExists(client, host, deployment.getJobId()); final String path = Paths.configHostJob(host, jobId); final Task task = new Task(job, deployment.getGoal(), existingDeployment.getDeployerUser(), existingDeployment.getDeployerMaster(), existingDeployment.getDeploymentGroupName()); try { client.setData(path, task.toJsonBytes()); } catch (Exception e) { throw new HeliosRuntimeException("updating deployment " + deployment + " on host " + host + " failed", e); } }
@Override public void setData(String path, byte[] bytes) throws KeeperException { try { client.setData(path, bytes); } catch (KeeperException e) { reporter.checkException(e, tag, "setData"); throw e; } }
private void write(final String node, final byte[] data) throws KeeperException { final ZooKeeperClient client = client("write"); final String nodePath = ZKPaths.makePath(path, node); if (client.stat(nodePath) != null) { log.debug("setting node: {}", nodePath); client.setData(nodePath, data); } else { log.debug("creating node: {}", nodePath); client.createAndSetData(nodePath, data); } }
client.createAndSetData(path, write.data); } else { client.setData(path, write.data);
} else if (!Arrays.equals(remoteData, localData)) { log.debug("sync: updating node {}", nodePath); client.setData(nodePath, localData); remote.put(node, localData);
@Override public void updateDeploymentGroupHosts(String name, List<String> hosts) throws DeploymentGroupDoesNotExistException { log.debug("updating deployment-group hosts: name={}", name); final ZooKeeperClient client = provider.get("updateDeploymentGroupHosts"); try { client.setData(Paths.statusDeploymentGroupHosts(name), Json.asBytes(hosts)); } catch (NoNodeException e) { throw new DeploymentGroupDoesNotExistException(name, e); } catch (KeeperException | IOException e) { throw new HeliosRuntimeException("updating deployment group hosts failed", e); } }
@Override public boolean update(final byte[] bytes) { final String parent = ZKPaths.getPathAndNode(path).getPath(); try { if (zooKeeperClient.stat(parent) == null) { return false; } if (zooKeeperClient.stat(path) == null) { zooKeeperClient.createAndSetData(path, bytes); } else { zooKeeperClient.setData(path, bytes); } return true; } catch (KeeperException.NodeExistsException ignore) { // Conflict due to curator retry or losing a race. We're done here. return true; } catch (KeeperException.ConnectionLossException e) { log.warn("ZooKeeper connection lost while updating node: {}", path); return false; } catch (KeeperException e) { log.error("failed to update node: {}", path, e); return false; } } }
/** * Used to update the existing deployment of a job. */ @Override public void updateDeployment(final String host, final Deployment deployment, final String token) throws HostNotFoundException, JobNotDeployedException, TokenVerificationException { log.info("updating deployment {}: {}", deployment, host); final ZooKeeperClient client = provider.get("updateDeployment"); final JobId jobId = deployment.getJobId(); final Job job = getJob(client, jobId); final Deployment existingDeployment = getDeployment(host, jobId); if (job == null) { throw new JobNotDeployedException(host, jobId); } verifyToken(token, job); assertHostExists(client, host); assertTaskExists(client, host, deployment.getJobId()); final String path = Paths.configHostJob(host, jobId); final Task task = new Task(job, deployment.getGoal(), existingDeployment.getDeployerUser(), existingDeployment.getDeployerMaster(), existingDeployment.getDeploymentGroupName()); try { client.setData(path, task.toJsonBytes()); } catch (Exception e) { throw new HeliosRuntimeException("updating deployment " + deployment + " on host " + host + " failed", e); } }