private JobId jobIdFromTaskPath(final String path) { final String prefix = Paths.configHostJobs(agent) + "/"; return JobId.fromString(path.replaceFirst(prefix, "")); }
/** * Returns the {@link TaskStatus}es for all tasks assigned to the current agent. */ @Override public Map<JobId, TaskStatus> getTaskStatuses() { final Map<JobId, TaskStatus> statuses = Maps.newHashMap(); for (final Map.Entry<String, byte[]> entry : this.taskStatuses.entrySet()) { try { final JobId id = JobId.fromString(entry.getKey()); final TaskStatus status = Json.read(entry.getValue(), TaskStatus.class); statuses.put(id, status); } catch (IOException e) { throw new RuntimeException(e); } } return statuses; }
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(); }
@Override void processItem(final String jobId) { final JobId id = JobId.fromString(jobId); final Job job = masterModel.getJob(id); if (job == null) { try { client.deleteRecursive(Paths.historyJob(id)); log.info("Reaped job history for job {}", jobId); } catch (NoNodeException ignored) { // Something deleted the history right before we got to it. Ignore and keep going. } catch (KeeperException e) { log.warn("error reaping job history for job {}", jobId, e); } } } }
protected JobId createJob(final Job job) throws Exception { final String createOutput = createJobRawOutput(job); final String jobId = CharMatcher.whitespace().trimFrom(createOutput); return JobId.fromString(jobId); }
final JobId jobId = JobId.fromString(id); final String path = Paths.configJob(jobId); try {
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; }
@Test public void test() throws Exception { startDefaultMaster(); final HeliosClient client = defaultClient(); final CreateJobResponse createIdMismatch = client.createJob( new Job(JobId.fromString("bad:job:deadbeef"), BUSYBOX, EMPTY_HOSTNAME, EMPTY_CREATED, IDLE_COMMAND, EMPTY_ENV, EMPTY_RESOURCES, EMPTY_PORTS, EMPTY_REGISTRATION, EMPTY_GRACE_PERIOD, EMPTY_VOLUMES, EMPTY_EXPIRES, EMPTY_REGISTRATION_DOMAIN, EMPTY_CREATING_USER, EMPTY_TOKEN, EMPTY_HEALTH_CHECK, EMPTY_SECURITY_OPT, DEFAULT_NETWORK_MODE, EMPTY_METADATA, EMPTY_CAPS, EMPTY_CAPS, EMPTY_LABELS, EMPTY_SECONDS_TO_WAIT, EMPTY_RAMDISKS, EMPTY_ROLLOUT_OPTIONS, EMPTY_RUNTIME) ).get(); // TODO (dano): Maybe this should be ID_MISMATCH but then JobValidator must become able to // TODO (dano): communicate that assertEquals(CreateJobResponse.Status.INVALID_JOB_DEFINITION, createIdMismatch.getStatus()); } }
final JobId job = JobId.fromString(jobString); final String hostJobPath = Paths.configHostJob(host, job);
private JobId jobIdFromTaskPath(final String path) { final String prefix = Paths.configHostJobs(agent) + "/"; return JobId.fromString(path.replaceFirst(prefix, "")); }
/** * Returns the {@link TaskStatus}es for all tasks assigned to the current agent. */ @Override public Map<JobId, TaskStatus> getTaskStatuses() { final Map<JobId, TaskStatus> statuses = Maps.newHashMap(); for (Map.Entry<String, byte[]> entry : this.taskStatuses.entrySet()) { try { final JobId id = JobId.fromString(entry.getKey()); final TaskStatus status = Json.read(entry.getValue(), TaskStatus.class); statuses.put(id, status); } catch (IOException e) { throw Throwables.propagate(e); } } return statuses; }
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 (String jobIdString : jobIdStrings) { jobIds.add(JobId.fromString(jobIdString)); } return jobIds.build(); }
final JobId jobId = JobId.fromString(id); final String path = Paths.configJob(jobId); try {
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) { return null; } 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; }