@Override public Stat stat(String path) throws KeeperException { return reporter.time(tag, "stat", () -> client.stat(path)); }
private void delete(final String node) throws KeeperException { final ZooKeeperClient client = client("delete"); final String nodePath = ZKPaths.makePath(path, node); if (client.stat(nodePath) != null) { log.debug("deleting node: {}", nodePath); client.delete(nodePath); } }
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); } }
final Write write = entry.getValue(); try { if (client.stat(path) == null) { client.createAndSetData(path, write.data); } else {
@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; } } }
private void assertJobExists(final ZooKeeperClient client, final JobId id) throws JobDoesNotExistException { try { final String path = Paths.configJob(id); if (client.stat(path) == null) { throw new JobDoesNotExistException(id); } } catch (KeeperException e) { throw new HeliosRuntimeException("checking job existence failed", e); } }
final String existingId = bytes == null ? "" : new String(bytes, UTF_8); if (!id.equals(existingId)) { final Stat hostInfoStat = client.stat(hostInfoPath); if (hostInfoStat != null) { final long mtime = hostInfoStat.getMtime();
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); } }
@Test public void testRemoveJobDeletesHistory() throws Exception { startDefaultAgent(testHost()); awaitHostStatus(testHost(), UP, LONG_WAIT_SECONDS, SECONDS); final JobId jobId = createJob(testJobName, testJobVersion, BUSYBOX, IDLE_COMMAND); deployJob(jobId, testHost()); awaitJobState( defaultClient(), testHost(), jobId, TaskStatus.State.RUNNING, LONG_WAIT_SECONDS, SECONDS); undeployJob(jobId, testHost()); awaitJobUndeployed(defaultClient(), testHost(), jobId, LONG_WAIT_SECONDS, SECONDS); final ZooKeeperClient zkClient = new ZooKeeperClientProvider( new DefaultZooKeeperClient(zk().curatorWithSuperAuth()), ZooKeeperModelReporter.noop()) .get("test-client"); // Check that there's some history events assertNotNull(zkClient.stat(Paths.historyJob(jobId))); // Remove job final JobDeleteResponse response = defaultClient().deleteJob(jobId).get(WAIT_TIMEOUT_SECONDS, SECONDS); assertEquals(JobDeleteResponse.Status.OK, response.getStatus()); // Verify that history is gone assertNull(zkClient.stat(Paths.historyJob(jobId))); } }
if (client.stat(taskPath) != null) { throw new JobAlreadyDeployedException(host, id);
@Override public Stat stat(String path) throws KeeperException { try { return client.stat(path); } catch (KeeperException e) { reporter.checkException(e, tag, "stat"); throw e; } }
private void delete(final String node) throws KeeperException { final ZooKeeperClient client = client("delete"); final String nodePath = ZKPaths.makePath(path, node); if (client.stat(nodePath) != null) { log.debug("deleting node: {}", nodePath); client.delete(nodePath); } }
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); } }
final Write write = entry.getValue(); try { if (client.stat(path) == null) { client.createAndSetData(path, write.data); } else {
@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; } } }
private void assertJobExists(final ZooKeeperClient client, final JobId id) throws JobDoesNotExistException { try { final String path = Paths.configJob(id); if (client.stat(path) == null) { throw new JobDoesNotExistException(id); } } catch (KeeperException e) { throw new HeliosRuntimeException("checking job existence failed", e); } }