@Test public void testFilterJob() throws Exception { when(options.getString("job")).thenReturn("foo"); final JobId jobId1 = JobId.parse("foo:bar"); final JobId jobId2 = JobId.parse("foo:bat"); final Job job1 = jobWithId(jobId1); final Job job2 = jobWithId(jobId2); final Map<JobId, Job> jobs = ImmutableMap.of( jobId1, job1, jobId2, job2 ); when(client.jobs("foo", "")).thenReturn(immediateFuture(jobs)); final TaskStatus taskStatus1 = TaskStatus.newBuilder() .setGoal(Goal.START) .setJob(job1) .setState(TaskStatus.State.RUNNING) .build(); final TaskStatus taskStatus2 = TaskStatus.newBuilder() .setGoal(Goal.START) .setJob(job2) .setState(TaskStatus.State.RUNNING) .build(); final Map<JobId, JobStatus> statusMap = ImmutableMap.of( jobId1, JobStatus.newBuilder() .setDeployments(ImmutableMap.of("host1", Deployment.of(jobId1, Goal.START))) .setJob(job1) .setTaskStatuses(ImmutableMap.of("host1", taskStatus1)) .build(), jobId2, JobStatus.newBuilder() .setDeployments(ImmutableMap.of("host2", Deployment.of(jobId2, Goal.START))) .setJob(job2) .setTaskStatuses(ImmutableMap.of("host2", taskStatus2)) .build() ); when(client.jobStatuses(jobs.keySet())).thenReturn(immediateFuture(statusMap)); final int ret = command.run(options, client, out, false, null); assertEquals(0, ret); assertThat(baos.toString().split("\n"), Matchers.arrayContaining( "JOB ID HOST GOAL STATE CONTAINER ID PORTS ", "foo:bar:6123457 host1. START RUNNING ", "foo:bat:c8aa21a host2. START RUNNING " )); }
@Override int run(final Namespace options, final HeliosClient client, final PrintStream out, final boolean json, final BufferedReader stdin) throws ExecutionException, InterruptedException { final String jobIdString = options.getString(jobArg.getDest()); final String hostPattern = options.getString(hostArg.getDest()); final boolean full = options.getBoolean(fullArg.getDest()); if (Strings.isNullOrEmpty(jobIdString) && Strings.isNullOrEmpty(hostPattern)) { if (!json) { out.printf("WARNING: listing status of all hosts in the cluster is a slow operation. " + "Consider adding the --job and/or --host flag(s)!"); } } final Set<JobId> jobIds = client.jobs(jobIdString, hostPattern).get().keySet(); if (!Strings.isNullOrEmpty(jobIdString) && jobIds.isEmpty()) { if (json) { out.println("{ }"); } else { out.printf("job id matcher \"%s\" matched no jobs%n", jobIdString); } return 1; } final Map<JobId, JobStatus> statuses = new TreeMap<>(client.jobStatuses(jobIds).get()); if (json) { showJsonStatuses(out, hostPattern, jobIds, statuses); return 0; } final JobStatusTable table = jobStatusTable(out, full); final boolean noHostMatchedEver = showStatusesForHosts(hostPattern, jobIds, statuses, new HostStatusDisplayer() { @Override public void matchedStatus(JobStatus jobStatus, Iterable<String> matchingHosts, Map<String, TaskStatus> taskStatuses) { displayTask(full, table, jobStatus.getJob().getId(), jobStatus, taskStatuses, matchingHosts); } }); if (noHostMatchedEver) { String domainsSwitchString = ""; final List<String> domains = options.get("domains"); if (domains.size() > 0) { domainsSwitchString = "-d " + Joiner.on(",").join(domains); } out.printf("There are no jobs deployed to hosts with the host pattern '%s'%n" + "Run 'helios %s hosts %s' to check your host exists and is up.%n", hostPattern, domainsSwitchString, hostPattern); return 1; } table.print(); return 0; }
JobStatusCommand extends ControlCommand { @Override int run(final Namespace options, final HeliosClient client, final PrintStream out, final boolean json, final BufferedReader stdin) throws ExecutionException, InterruptedException { final String jobIdString = options.getString(jobArg.getDest()); final String hostPattern = options.getString(hostArg.getDest()); final boolean full = options.getBoolean(fullArg.getDest()); if (Strings.isNullOrEmpty(jobIdString) && Strings.isNullOrEmpty(hostPattern)) { if (!json) { out.printf("WARNING: listing status of all hosts in the cluster is a slow operation. " + "Consider adding the --job and/or --host flag(s)!"); } } final Set<JobId> jobIds = client.jobs(jobIdString, hostPattern).get().keySet(); if (!Strings.isNullOrEmpty(jobIdString) && jobIds.isEmpty()) { if (json) { out.println("{ }"); } else { out.printf("job id matcher \"%s\" matched no jobs%n", jobIdString); } return 1; } final Map<JobId, JobStatus> statuses = new TreeMap<>(client.jobStatuses(jobIds).get()); if (json) { showJsonStatuses(out, hostPattern, jobIds, statuses); return 0; } final JobStatusTable table = jobStatusTable(out, full); final boolean noHostMatchedEver = showStatusesForHosts(hostPattern, jobIds, statuses, new HostStatusDisplayer() { @Override public void matchedStatus(JobStatus jobStatus, Iterable<String> matchingHosts, Map<String, TaskStatus> taskStatuses) { displayTask(full, table, jobStatus.getJob().getId(), jobStatus, taskStatuses, matchingHosts); } }); if (noHostMatchedEver) { String domainsSwitchString = ""; final List<String> domains = options.get("domains"); if (domains.size() > 0) { domainsSwitchString = "-d " + Joiner.on(",").join(domains); } out.printf("There are no jobs deployed to hosts with the host pattern '%s'%n" + "Run 'helios %s hosts %s' to check your host exists and is up.%n", hostPattern, domainsSwitchString, hostPattern); return 1; } table.print(); return 0; } }
JobStatusCommand extends ControlCommand { @Override int run(final Namespace options, final HeliosClient client, final PrintStream out, final boolean json, final BufferedReader stdin) throws ExecutionException, InterruptedException { final String jobIdString = options.getString(jobArg.getDest()); final String hostPattern = options.getString(hostArg.getDest()); final boolean full = options.getBoolean(fullArg.getDest()); if (Strings.isNullOrEmpty(jobIdString) && Strings.isNullOrEmpty(hostPattern)) { if (!json) { out.printf("WARNING: listing status of all hosts in the cluster is a slow operation. " + "Consider adding the --job and/or --host flag(s)!"); } } final Set<JobId> jobIds = client.jobs(jobIdString, hostPattern).get().keySet(); if (!Strings.isNullOrEmpty(jobIdString) && jobIds.isEmpty()) { if (json) { out.println("{ }"); } else { out.printf("job id matcher \"%s\" matched no jobs%n", jobIdString); } return 1; } final Map<JobId, JobStatus> statuses = new TreeMap<>(client.jobStatuses(jobIds).get()); if (json) { showJsonStatuses(out, hostPattern, jobIds, statuses); return 0; } final JobStatusTable table = jobStatusTable(out, full); final boolean noHostMatchedEver = showStatusesForHosts(hostPattern, jobIds, statuses, new HostStatusDisplayer() { @Override public void matchedStatus(JobStatus jobStatus, Iterable<String> matchingHosts, Map<String, TaskStatus> taskStatuses) { displayTask(full, table, jobStatus.getJob().getId(), jobStatus, taskStatuses, matchingHosts); } }); if (noHostMatchedEver) { String domainsSwitchString = ""; final List<String> domains = options.get("domains"); if (domains.size() > 0) { domainsSwitchString = "-d " + Joiner.on(",").join(domains); } out.printf("There are no jobs deployed to hosts with the host pattern '%s'%n" + "Run 'helios %s hosts %s' to check your host exists and is up.%n", hostPattern, domainsSwitchString, hostPattern); return 1; } table.print(); return 0; } JobStatusCommand(final Subparser parser); }
JobStatusCommand extends ControlCommand { @Override int run(final Namespace options, final HeliosClient client, final PrintStream out, final boolean json, final BufferedReader stdin) throws ExecutionException, InterruptedException { final String jobIdString = options.getString(jobArg.getDest()); final String hostPattern = options.getString(hostArg.getDest()); final boolean full = options.getBoolean(fullArg.getDest()); if (Strings.isNullOrEmpty(jobIdString) && Strings.isNullOrEmpty(hostPattern)) { if (!json) { out.printf("WARNING: listing status of all hosts in the cluster is a slow operation. " + "Consider adding the --job and/or --host flag(s)!"); } } final Set<JobId> jobIds = client.jobs(jobIdString, hostPattern).get().keySet(); if (!Strings.isNullOrEmpty(jobIdString) && jobIds.isEmpty()) { if (json) { out.println("{ }"); } else { out.printf("job id matcher \"%s\" matched no jobs%n", jobIdString); } return 1; } final Map<JobId, JobStatus> statuses = new TreeMap<>(client.jobStatuses(jobIds).get()); if (json) { showJsonStatuses(out, hostPattern, jobIds, statuses); return 0; } final JobStatusTable table = jobStatusTable(out, full); final boolean noHostMatchedEver = showStatusesForHosts(hostPattern, jobIds, statuses, new HostStatusDisplayer() { @Override public void matchedStatus(JobStatus jobStatus, Iterable<String> matchingHosts, Map<String, TaskStatus> taskStatuses) { displayTask(full, table, jobStatus.getJob().getId(), jobStatus, taskStatuses, matchingHosts); } }); if (noHostMatchedEver) { String domainsSwitchString = ""; final List<String> domains = options.get("domains"); if (domains.size() > 0) { domainsSwitchString = "-d " + Joiner.on(",").join(domains); } out.printf("There are no jobs deployed to hosts with the host pattern '%s'%n" + "Run 'helios %s hosts %s' to check your host exists and is up.%n", hostPattern, domainsSwitchString, hostPattern); return 1; } table.print(); return 0; } JobStatusCommand(final Subparser parser);  }
JobStatusCommand extends ControlCommand { @Override int run(final Namespace options, final HeliosClient client, final PrintStream out, final boolean json, final BufferedReader stdin) throws ExecutionException, InterruptedException { final String jobIdString = options.getString(jobArg.getDest()); final String hostPattern = options.getString(hostArg.getDest()); final boolean full = options.getBoolean(fullArg.getDest()); if (Strings.isNullOrEmpty(jobIdString) && Strings.isNullOrEmpty(hostPattern)) { if (!json) { out.printf("WARNING: listing status of all hosts in the cluster is a slow operation. " + "Consider adding the --job and/or --host flag(s)!"); } } final Set<JobId> jobIds = client.jobs(jobIdString, hostPattern).get().keySet(); if (!Strings.isNullOrEmpty(jobIdString) && jobIds.isEmpty()) { if (json) { out.println("{ }"); } else { out.printf("job id matcher \"%s\" matched no jobs%n", jobIdString); } return 1; } final Map<JobId, JobStatus> statuses = new TreeMap<>(client.jobStatuses(jobIds).get()); if (json) { showJsonStatuses(out, hostPattern, jobIds, statuses); return 0; } final JobStatusTable table = jobStatusTable(out, full); final boolean noHostMatchedEver = showStatusesForHosts(hostPattern, jobIds, statuses, new HostStatusDisplayer() { @Override public void matchedStatus(JobStatus jobStatus, Iterable<String> matchingHosts, Map<String, TaskStatus> taskStatuses) { displayTask(full, table, jobStatus.getJob().getId(), jobStatus, taskStatuses, matchingHosts); } }); if (noHostMatchedEver) { String domainsSwitchString = ""; final List<String> domains = options.get("domains"); if (domains.size() > 0) { domainsSwitchString = "-d " + Joiner.on(",").join(domains); } out.printf("There are no jobs deployed to hosts with the host pattern '%s'%n" + "Run 'helios %s hosts %s' to check your host exists and is up.%n", hostPattern, domainsSwitchString, hostPattern); return 1; } table.print(); return 0; } JobStatusCommand(final Subparser parser);   }