ReadOnlySchedulerImpl implements ReadOnlyScheduler.Iface { @Override public Response getJobs(@Nullable String maybeNullRole) { Optional<String> ownerRole = Optional.fromNullable(maybeNullRole); return ok(Result.getJobsResult( new GetJobsResult() .setConfigs(IJobConfiguration.toBuildersSet( getJobs(ownerRole, getTasks(maybeRoleScoped(ownerRole).active())).values())))); } @Inject  ReadOnlySchedulerImpl(
      ConfigurationManager configurationManager,
      Storage storage,
      NearestFit nearestFit,
      CronPredictor cronPredictor,
      QuotaManager quotaManager); @Override Response populateJobConfig(JobConfiguration description); @Override Response getTasksStatus(TaskQuery query); @Override Response getTasksWithoutConfigs(TaskQuery query); @Override Response getPendingReason(TaskQuery query); @Override Response getConfigSummary(JobKey job); @Override Response getRoleSummary(); @Override Response getJobSummary(@Nullable String maybeNullRole); @Override Response getJobs(@Nullable String maybeNullRole); @Override Response getQuota(String ownerRole); @Override Response getJobUpdateSummaries(JobUpdateQuery mutableQuery); @Override Response getJobUpdateDetails(JobUpdateKey mutableKey); @Override Response getJobUpdateDiff(JobUpdateRequest mutableRequest);  }
@Test public void testGetAllJobs() throws Exception { JobConfiguration cronJobOne = makeJob() .setCronSchedule("1 * * * *") .setKey(JOB_KEY.newBuilder()) .setTaskConfig(nonProductionTask()); JobKey jobKey2 = JOB_KEY.newBuilder().setRole("other_role"); JobConfiguration cronJobTwo = makeJob() .setCronSchedule("2 * * * *") .setKey(jobKey2) .setTaskConfig(nonProductionTask()); TaskConfig immediateTaskConfig = defaultTask(false) .setJob(JOB_KEY.newBuilder().setName("immediate")); IScheduledTask immediateTask = IScheduledTask.build(new ScheduledTask() .setAssignedTask(new AssignedTask().setTask(immediateTaskConfig)) .setStatus(ScheduleStatus.ASSIGNED)); JobConfiguration immediateJob = new JobConfiguration() .setKey(JOB_KEY.newBuilder().setName("immediate")) .setOwner(IDENTITY) .setInstanceCount(1) .setTaskConfig(immediateTaskConfig); Set<JobConfiguration> crons = ImmutableSet.of(cronJobOne, cronJobTwo); expect(storageUtil.jobStore.fetchJobs()).andReturn(IJobConfiguration.setFromBuilders(crons)); storageUtil.expectTaskFetch(Query.unscoped().active(), immediateTask); control.replay(); Set<JobConfiguration> allJobs = ImmutableSet.<JobConfiguration>builder().addAll(crons).add(immediateJob).build(); assertEquals( IJobConfiguration.setFromBuilders(allJobs), IJobConfiguration.setFromBuilders( thrift.getJobs(null).getResult().getGetJobsResult().getConfigs())); }
@Test public void testGetJobs() throws Exception { TaskConfig ownedCronJobTask = nonProductionTask(); JobConfiguration ownedCronJob = makeJob() .setCronSchedule(CRON_SCHEDULE) .setTaskConfig(ownedCronJobTask); IScheduledTask ownedCronJobScheduledTask = IScheduledTask.build(new ScheduledTask() .setAssignedTask(new AssignedTask().setTask(ownedCronJobTask)) .setStatus(ScheduleStatus.ASSIGNED)); Identity otherOwner = new Identity().setUser("other"); JobConfiguration unownedCronJob = makeJob() .setOwner(otherOwner) .setCronSchedule(CRON_SCHEDULE) .setKey(JOB_KEY.newBuilder().setRole("other")) .setTaskConfig(ownedCronJobTask.deepCopy().setOwner(otherOwner)); TaskConfig ownedImmediateTaskInfo = defaultTask(false) .setJob(JOB_KEY.newBuilder().setName("immediate")); Set<JobConfiguration> ownedCronJobOnly = ImmutableSet.of(ownedCronJob); Set<JobConfiguration> unownedCronJobOnly = ImmutableSet.of(unownedCronJob); Set<JobConfiguration> bothCronJobs = ImmutableSet.of(ownedCronJob, unownedCronJob); IScheduledTask ownedImmediateTask = IScheduledTask.build(new ScheduledTask() .setAssignedTask(new AssignedTask().setTask(ownedImmediateTaskInfo)) .setStatus(ScheduleStatus.ASSIGNED)); JobConfiguration ownedImmediateJob = new JobConfiguration() .setKey(JOB_KEY.newBuilder().setName("immediate")) .setOwner(IDENTITY) .setInstanceCount(1) .setTaskConfig(ownedImmediateTaskInfo); Query.Builder query = Query.roleScoped(ROLE).active(); storageUtil.expectTaskFetch(query); expect(storageUtil.jobStore.fetchJobs()) .andReturn(IJobConfiguration.setFromBuilders(ownedCronJobOnly)); storageUtil.expectTaskFetch(query); expect(storageUtil.jobStore.fetchJobs()) .andReturn(IJobConfiguration.setFromBuilders(bothCronJobs)); storageUtil.expectTaskFetch(query, ownedImmediateTask); expect(storageUtil.jobStore.fetchJobs()) .andReturn(IJobConfiguration.setFromBuilders(unownedCronJobOnly)); expect(storageUtil.jobStore.fetchJobs()).andReturn(ImmutableSet.of()); storageUtil.expectTaskFetch(query); storageUtil.expectTaskFetch(query, ownedCronJobScheduledTask); expect(storageUtil.jobStore.fetchJobs()) .andReturn(IJobConfiguration.setFromBuilders(ImmutableSet.of(ownedCronJob))); control.replay(); assertJobsEqual(ownedCronJob, Iterables.getOnlyElement(thrift.getJobs(ROLE) .getResult().getGetJobsResult().getConfigs())); assertJobsEqual(ownedCronJob, Iterables.getOnlyElement(thrift.getJobs(ROLE) .getResult().getGetJobsResult().getConfigs())); Set<JobConfiguration> queryResult3 = thrift.getJobs(ROLE).getResult().getGetJobsResult().getConfigs(); assertJobsEqual(ownedImmediateJob, Iterables.getOnlyElement(queryResult3)); assertEquals( ITaskConfig.build(ownedImmediateTaskInfo), ITaskConfig.build(Iterables.getOnlyElement(queryResult3).getTaskConfig())); assertTrue(thrift.getJobs(ROLE) .getResult().getGetJobsResult().getConfigs().isEmpty()); assertJobsEqual(ownedCronJob, Iterables.getOnlyElement(thrift.getJobs(ROLE) .getResult().getGetJobsResult().getConfigs())); }