@Override public Node getNode(final String path) throws KeeperException { assertClusterIdFlagTrue(); final Stat stat = new Stat(); try { final byte[] bytes = client.getData().storingStatIn(stat).forPath(path); return new Node(path, bytes, stat); } catch (Exception e) { throwIfInstanceOf(e, KeeperException.class); throw new RuntimeException(e); } }
private List<String> getHosts(final ZooKeeperClient client, final String path) { try { return Json.read(client.getNode(path).getBytes(), STRING_LIST_TYPE); } catch (JsonMappingException | JsonParseException | NoNodeException e) { return emptyList(); } catch (KeeperException | IOException e) { throw new HeliosRuntimeException("failed to read deployment group hosts from " + path, e); } }
private boolean isRolloutTimedOut(final ZooKeeperClient client, final DeploymentGroup deploymentGroup) { final String groupName = deploymentGroup.getName(); final RolloutOptions defaultOptions = RolloutOptions.getDefault(); final long groupTimeoutSetting = deploymentGroup.getRolloutOptions() == null ? defaultOptions.getTimeout() : deploymentGroup.getRolloutOptions().withFallback(defaultOptions).getTimeout(); final long secondsSinceDeploy; try { final String statusPath = Paths.statusDeploymentGroupTasks(groupName); secondsSinceDeploy = MILLISECONDS.toSeconds( System.currentTimeMillis() - client.getNode(statusPath).getStat().getMtime()); } catch (KeeperException e) { // statusPath doesn't exist or some other ZK issue. probably this deployment group // was removed. log.warn("error determining deployment group modification time: name={}", groupName, e); return false; } if (secondsSinceDeploy > groupTimeoutSetting) { log.info("rolling-update on deployment-group name={} has timed out after " + "{} seconds (rolloutOptions.timeout={})", groupName, secondsSinceDeploy, groupTimeoutSetting); return true; } return false; }
@Override public DeploymentGroupStatus getDeploymentGroupStatus(final String name) throws DeploymentGroupDoesNotExistException { log.debug("getting deployment group status: {}", name); final ZooKeeperClient client = provider.get("getDeploymentGroupStatus"); final DeploymentGroup deploymentGroup = getDeploymentGroup(client, name); if (deploymentGroup == null) { return null; } try { final Node node = client.getNode(Paths.statusDeploymentGroup(name)); final byte[] bytes = node.getBytes(); if (bytes.length == 0) { return null; } return Json.read(bytes, DeploymentGroupStatus.class); } catch (NoNodeException e) { return null; } catch (KeeperException | IOException e) { throw new HeliosRuntimeException("getting deployment group status " + name + " failed", e); } }
private boolean isRolloutTimedOut(final DeploymentGroup deploymentGroup, final ZooKeeperClient client) { try { final String statusPath = Paths.statusDeploymentGroup(deploymentGroup.getName()); final long secondsSinceDeploy = MILLISECONDS.toSeconds( System.currentTimeMillis() - client.getNode(statusPath).getStat().getMtime()); return secondsSinceDeploy > deploymentGroup.getRolloutOptions().getTimeout(); } catch (KeeperException e) { // statusPath doesn't exist or some other ZK issue. probably this deployment group // was removed. log.warn("error determining deployment group modification time: {} - {}", deploymentGroup.getName(), e); return false; } }
@Override public Node getNode(final String path) throws KeeperException { assertClusterIdFlagTrue(); final Stat stat = new Stat(); try { byte[] bytes = client.getData().storingStatIn(stat).forPath(path); return new Node(path, bytes, stat); } catch (Exception e) { propagateIfInstanceOf(e, KeeperException.class); throw propagate(e); } }
@Override public DeploymentGroupStatus getDeploymentGroupStatus(final String name) throws DeploymentGroupDoesNotExistException { log.debug("getting deployment group status: {}", name); final ZooKeeperClient client = provider.get("getDeploymentGroupStatus"); final DeploymentGroup deploymentGroup = getDeploymentGroup(client, name); if (deploymentGroup == null) { return null; } try { final Node node = client.getNode(Paths.statusDeploymentGroup(name)); final byte[] bytes = node.getBytes(); if (bytes.length == 0) { return null; } final DeploymentGroupStatus status = Json.read(bytes, DeploymentGroupStatus.class); return status.toBuilder() .setVersion(node.getStat().getVersion()) .build(); } catch (NoNodeException e) { return null; } catch (KeeperException | IOException e) { throw new HeliosRuntimeException("getting deployment group status " + name + " failed", e); } }