@Test public void testListJobs() throws Exception { final ImmutableMap<JobId, Job> jobs = ImmutableMap.of( JobId.parse("foobar:1"), Job.newBuilder().build(), JobId.parse("foobar:2"), Job.newBuilder().build(), JobId.parse("foobar:3"), Job.newBuilder().build() ); when(model.getJobs()).thenReturn(jobs); assertThat(resource.list("", ""), is(jobs)); }
@GET @Produces(APPLICATION_JSON) @Timed @ExceptionMetered public Map<JobId, Job> list( @QueryParam("q") @DefaultValue("") final String query, @QueryParam("hostPattern") @DefaultValue("") final String hostPattern) { final Map<JobId, Job> allJobs; if (!hostPattern.isEmpty()) { allJobs = model.listHosts(hostPattern).stream() .map(model::getHostStatus) .flatMap(hostStatus -> hostStatus.getJobs().keySet().stream()) .distinct() .collect(Collectors.toMap(Function.identity(), model::getJob)); } else { allJobs = model.getJobs(); } if (query.isEmpty()) { metrics.jobsInJobList(allJobs.size()); return allJobs; } final Map<JobId, Job> filteredJobs = Maps.newHashMap(); for (final Map.Entry<JobId, Job> entry : allJobs.entrySet()) { if (entry.getKey().toString().contains(query)) { filteredJobs.put(entry.getKey(), entry.getValue()); } } metrics.jobsInJobList(filteredJobs.size()); return filteredJobs; }
JobsResource { @GET @Produces(APPLICATION_JSON) @Timed @ExceptionMetered public Map<JobId, Job> list( @QueryParam("q") @DefaultValue("") final String query, @QueryParam("hostPattern") @DefaultValue("") final String hostPattern) { final Map<JobId, Job> allJobs; if (!hostPattern.isEmpty()) { allJobs = model.listHosts(hostPattern).stream() .map(model::getHostStatus) .flatMap(hostStatus -> hostStatus.getJobs().keySet().stream()) .distinct() .collect(Collectors.toMap(Function.identity(), model::getJob)); } else { allJobs = model.getJobs(); } if (query.isEmpty()) { metrics.jobsInJobList(allJobs.size()); return allJobs; } final Map<JobId, Job> filteredJobs = Maps.newHashMap(); for (final Map.Entry<JobId, Job> entry : allJobs.entrySet()) { if (entry.getKey().toString().contains(query)) { filteredJobs.put(entry.getKey(), entry.getValue()); } } metrics.jobsInJobList(filteredJobs.size()); return filteredJobs; } }
JobsResource { @GET @Produces(APPLICATION_JSON) @Timed @ExceptionMetered public Map<JobId, Job> list( @QueryParam("q") @DefaultValue("") final String query, @QueryParam("hostPattern") @DefaultValue("") final String hostPattern) { final Map<JobId, Job> allJobs; if (!hostPattern.isEmpty()) { allJobs = model.listHosts(hostPattern).stream() .map(model::getHostStatus) .flatMap(hostStatus -> hostStatus.getJobs().keySet().stream()) .distinct() .collect(Collectors.toMap(Function.identity(), model::getJob)); } else { allJobs = model.getJobs(); } if (query.isEmpty()) { metrics.jobsInJobList(allJobs.size()); return allJobs; } final Map<JobId, Job> filteredJobs = Maps.newHashMap(); for (final Map.Entry<JobId, Job> entry : allJobs.entrySet()) { if (entry.getKey().toString().contains(query)) { filteredJobs.put(entry.getKey(), entry.getValue()); } } metrics.jobsInJobList(filteredJobs.size()); return filteredJobs; } JobsResource(final MasterModel model, final MasterMetrics metrics,
                      final Set<String> whitelistedCapabilities); @VisibleForTesting  JobsResource(final MasterModel model, final MasterMetrics metrics,
               final Set<String> whitelistedCapabilities, final Clock clock); }
JobsResource { @GET @Produces(APPLICATION_JSON) @Timed @ExceptionMetered public Map<JobId, Job> list( @QueryParam("q") @DefaultValue("") final String query, @QueryParam("hostPattern") @DefaultValue("") final String hostPattern) { final Map<JobId, Job> allJobs; if (!hostPattern.isEmpty()) { allJobs = model.listHosts(hostPattern).stream() .map(model::getHostStatus) .flatMap(hostStatus -> hostStatus.getJobs().keySet().stream()) .distinct() .collect(Collectors.toMap(Function.identity(), model::getJob)); } else { allJobs = model.getJobs(); } if (query.isEmpty()) { metrics.jobsInJobList(allJobs.size()); return allJobs; } final Map<JobId, Job> filteredJobs = Maps.newHashMap(); for (final Map.Entry<JobId, Job> entry : allJobs.entrySet()) { if (entry.getKey().toString().contains(query)) { filteredJobs.put(entry.getKey(), entry.getValue()); } } metrics.jobsInJobList(filteredJobs.size()); return filteredJobs; } JobsResource(final MasterModel model, final MasterMetrics metrics,
                      final Set<String> whitelistedCapabilities); @VisibleForTesting  JobsResource(final MasterModel model, final MasterMetrics metrics,
               final Set<String> whitelistedCapabilities, final Clock clock); @GET @Produces(APPLICATION_JSON) @Timed @ExceptionMetered Map<JobId, Job> list(
      @QueryParam("q") @DefaultValue("") final String query,
      @QueryParam("hostPattern") @DefaultValue("") final String hostPattern); @Path("{id}") @GET @Produces(APPLICATION_JSON) @Timed @ExceptionMetered Optional<Job> get(@InjectParam @PathParam("id") @Valid final JobId id); @POST @Produces(APPLICATION_JSON) @Timed @ExceptionMetered CreateJobResponse post(@Valid final Job job,
                                @RequestUser final String username); @Path("{id}") @DELETE @Produces(APPLICATION_JSON) @Timed @ExceptionMetered JobDeleteResponse delete(@PathParam("id") @Valid final JobId id,
                                  @QueryParam("token") @DefaultValue("") final String token); @Path("{id}/status") @GET @Produces(APPLICATION_JSON) @Timed @ExceptionMetered Optional<JobStatus> statusGet(@PathParam("id") @Valid final JobId id); @Path("/statuses") @POST @Produces(APPLICATION_JSON) @Timed @ExceptionMetered Map<JobId, JobStatus> jobStatuses(@Valid final Set<JobId> ids); }
JobsResource { @GET @Produces(APPLICATION_JSON) @Timed @ExceptionMetered public Map<JobId, Job> list( @QueryParam("q") @DefaultValue("") final String query, @QueryParam("hostPattern") @DefaultValue("") final String hostPattern) { final Map<JobId, Job> allJobs; if (!hostPattern.isEmpty()) { allJobs = model.listHosts(hostPattern).stream() .map(model::getHostStatus) .flatMap(hostStatus -> hostStatus.getJobs().keySet().stream()) .distinct() .collect(Collectors.toMap(Function.identity(), model::getJob)); } else { allJobs = model.getJobs(); } if (query.isEmpty()) { metrics.jobsInJobList(allJobs.size()); return allJobs; } final Map<JobId, Job> filteredJobs = Maps.newHashMap(); for (final Map.Entry<JobId, Job> entry : allJobs.entrySet()) { if (entry.getKey().toString().contains(query)) { filteredJobs.put(entry.getKey(), entry.getValue()); } } metrics.jobsInJobList(filteredJobs.size()); return filteredJobs; } JobsResource(final MasterModel model, final MasterMetrics metrics,
                      final Set<String> whitelistedCapabilities); @VisibleForTesting  JobsResource(final MasterModel model, final MasterMetrics metrics,
               final Set<String> whitelistedCapabilities, final Clock clock); @GET @Produces(APPLICATION_JSON) @Timed @ExceptionMetered Map<JobId, Job> list(
      @QueryParam("q") @DefaultValue("") final String query,
      @QueryParam("hostPattern") @DefaultValue("") final String hostPattern); @Path("{id}") @GET @Produces(APPLICATION_JSON) @Timed @ExceptionMetered Optional<Job> get(@InjectParam @PathParam("id") @Valid final JobId id); @POST @Produces(APPLICATION_JSON) @Timed @ExceptionMetered CreateJobResponse post(@Valid final Job job,
                                @RequestUser final String username); @Path("{id}") @DELETE @Produces(APPLICATION_JSON) @Timed @ExceptionMetered JobDeleteResponse delete(@PathParam("id") @Valid final JobId id,
                                  @QueryParam("token") @DefaultValue("") final String token); @Path("{id}/status") @GET @Produces(APPLICATION_JSON) @Timed @ExceptionMetered Optional<JobStatus> statusGet(@PathParam("id") @Valid final JobId id); @Path("/statuses") @POST @Produces(APPLICATION_JSON) @Timed @ExceptionMetered Map<JobId, JobStatus> jobStatuses(@Valid final Set<JobId> ids);  }