ReadOnlySchedulerImpl implements ReadOnlyScheduler.Iface { @Override public Response getRoleSummary() { Multimap<String, IJobKey> jobsByRole = storage.read( storeProvider -> Multimaps.index(storeProvider.getTaskStore().getJobKeys(), IJobKey::getRole)); Multimap<String, IJobKey> cronJobsByRole = Multimaps.index( Iterables.transform(Storage.Util.fetchCronJobs(storage), IJobConfiguration::getKey), IJobKey::getRole); Set<RoleSummary> summaries = FluentIterable.from( Sets.union(jobsByRole.keySet(), cronJobsByRole.keySet())) .transform(role -> new RoleSummary( role, jobsByRole.get(role).size(), cronJobsByRole.get(role).size())) .toSet(); return ok(Result.roleSummaryResult(new RoleSummaryResult(summaries))); } @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 testGetRoleSummary() throws Exception { String bazRole = "baz_role"; Identity bazRoleIdentity = new Identity().setUser(USER); JobConfiguration cronJobOne = makeJob() .setCronSchedule("1 * * * *") .setKey(JOB_KEY.newBuilder()) .setTaskConfig(nonProductionTask()); JobConfiguration cronJobTwo = makeJob() .setCronSchedule("2 * * * *") .setKey(JOB_KEY.newBuilder().setName("cronJob2")) .setTaskConfig(nonProductionTask()); JobConfiguration cronJobThree = makeJob() .setCronSchedule("3 * * * *") .setKey(JOB_KEY.newBuilder().setRole(bazRole)) .setTaskConfig(nonProductionTask()) .setOwner(bazRoleIdentity); Set<JobConfiguration> crons = ImmutableSet.of(cronJobOne, cronJobTwo, cronJobThree); TaskConfig immediateTaskConfig = defaultTask(false) .setJob(JOB_KEY.newBuilder().setName("immediate")); IScheduledTask task1 = IScheduledTask.build(new ScheduledTask() .setAssignedTask(new AssignedTask().setTask(immediateTaskConfig))); IScheduledTask task2 = IScheduledTask.build(new ScheduledTask() .setAssignedTask(new AssignedTask().setTask(immediateTaskConfig.setNumCpus(2)))); TaskConfig immediateTaskConfigTwo = defaultTask(false) .setJob(JOB_KEY.newBuilder().setRole(bazRole).setName("immediateTwo")) .setOwner(bazRoleIdentity); IScheduledTask task3 = IScheduledTask.build(new ScheduledTask() .setAssignedTask(new AssignedTask().setTask(immediateTaskConfigTwo))); TaskConfig immediateTaskConfigThree = defaultTask(false) .setJob(JOB_KEY.newBuilder().setRole(bazRole).setName("immediateThree")) .setOwner(bazRoleIdentity); IScheduledTask task4 = IScheduledTask.build(new ScheduledTask() .setAssignedTask(new AssignedTask().setTask(immediateTaskConfigThree))); expect(storageUtil.taskStore.getJobKeys()).andReturn( FluentIterable.from(ImmutableSet.of(task1, task2, task3, task4)) .transform(Tasks::getJob) .toSet()); expect(storageUtil.jobStore.fetchJobs()).andReturn(IJobConfiguration.setFromBuilders(crons)); RoleSummaryResult expectedResult = new RoleSummaryResult(); expectedResult.addToSummaries( new RoleSummary().setRole(ROLE).setCronJobCount(2).setJobCount(1)); expectedResult.addToSummaries( new RoleSummary().setRole(bazRole).setCronJobCount(1).setJobCount(2)); control.replay(); Response response = assertOkResponse(thrift.getRoleSummary()); assertEquals(expectedResult, response.getResult().getRoleSummaryResult()); }