Skip to content

Commit

Permalink
Renaming endExclusive to startExclusive (#609)
Browse files Browse the repository at this point in the history
* Changing from endExclusive to startExclusive

This change is a pure refactor

* Formatting

---------

Co-authored-by: Sundaram Ananthanarayanan <[email protected]>
  • Loading branch information
sundargates and sundargates authored Dec 14, 2023
1 parent 7d65cc9 commit 1504bd0
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public class JobRouteUtils {
public static final String QUERY_PARAM_ACTIVE_ONLY = "activeOnly";
public static final String QUERY_PARAM_LABELS_QUERY = "labels";
public static final String QUERY_PARAM_LABELS_OPERAND = "labels.op";
public static final String QUERY_PARAM_END_JOB_ID = "endJobId";
public static final String QUERY_PARAM_END_JOB_ID = "startJobIdExclusive";

public static WorkerEvent createWorkerStatusRequest(final PostJobStatusRequest req) {
final Status status = req.getStatus();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,14 +231,14 @@ public List<CompletedJob> getCompletedJobs(int limit) throws IOException {
}

@Override
public List<CompletedJob> getCompletedJobs(int limit, JobId endExclusive) throws IOException {
public List<CompletedJob> getCompletedJobs(int limit, JobId startExclusive) throws IOException {
List<CompletedJob> completedJobsList =
jobStore.loadCompletedJobsForCluster(name, limit, endExclusive);
jobStore.loadCompletedJobsForCluster(name, limit, startExclusive);
addCompletedJobsToCache(completedJobsList);
return terminalSortedJobSet
.stream()
.filter(job ->
JobId.fromId(job.getJobId()).get().getJobNum() < endExclusive.getJobNum())
JobId.fromId(job.getJobId()).get().getJobNum() < startExclusive.getJobNum())
.limit(limit)
.collect(Collectors.toList());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1076,7 +1076,9 @@ private List<JobIdInfo> getFilteredTerminalJobIdList(ListJobCriteria request, Se
if(!prefilteredJobIdSet.isEmpty()) {
completedJobsList = prefilteredJobIdSet.stream().map((jId) -> jobManager.getCompletedJob(jId)).filter((cjOp) -> cjOp.isPresent()).map((cjop) -> cjop.get()).collect(Collectors.toList());
} else {
completedJobsList = jobManager.getCompletedJobsList(request.getLimit().orElse(DEFAULT_LIMIT), request.getEndJobIdExclusive().orElse(null));
completedJobsList = jobManager.getCompletedJobsList(
request.getLimit().orElse(DEFAULT_LIMIT),
request.getStartJobIdExclusive().orElse(null));
}

List<CompletedJob> subsetCompletedJobs = completedJobsList.subList(0, Math.min(completedJobsList.size(), request.getLimit().orElse(DEFAULT_LIMIT)));
Expand Down Expand Up @@ -1168,7 +1170,7 @@ private Observable<MantisJobMetadataView> getFilteredTerminalJobList(ListJobCrit
jobInfoList = jobIdSet.stream().map((jId) -> jobManager.getCompletedJob(jId))
.filter((compJobOp) -> compJobOp.isPresent()).map((compJobOp) -> compJobOp.get()).collect(Collectors.toList());
} else {
jobInfoList = jobManager.getCompletedJobsList(request.getLimit().orElse(DEFAULT_LIMIT), request.getEndJobIdExclusive().orElse(null));
jobInfoList = jobManager.getCompletedJobsList(request.getLimit().orElse(DEFAULT_LIMIT), request.getStartJobIdExclusive().orElse(null));
}

List<CompletedJob> shortenedList = jobInfoList.subList(0, Math.min(jobInfoList.size(), request.getLimit().orElse(DEFAULT_LIMIT)));
Expand Down Expand Up @@ -2905,10 +2907,10 @@ List<JobInfo> getActiveJobsList() {
* List of jobs in completed state
* @return list of completed jobs
*/
List<CompletedJob> getCompletedJobsList(int limit, @Nullable JobId to) {
List<CompletedJob> getCompletedJobsList(int limit, @Nullable JobId from) {
try {
if (to != null) {
return completedJobStore.getCompletedJobs(limit, to);
if (from != null) {
return completedJobStore.getCompletedJobs(limit, from);
} else {
return completedJobStore.getCompletedJobs(limit);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -883,7 +883,7 @@ public static final class ListJobCriteria {
private final List<Label> matchingLabels;
private final Optional<String> labelsOperand;

private final Optional<JobId> endJobIdExclusive;
private final Optional<JobId> startJobIdExclusive;

public ListJobCriteria(
final Optional<Integer> limit,
Expand All @@ -896,7 +896,7 @@ public ListJobCriteria(
final Optional<String> matchingRegex,
final Optional<String> matchingLabels,
final Optional<String> labelsOperand,
final Optional<JobId> endJobIdExclusive) {
final Optional<JobId> startJobIdExclusive) {
this.limit = limit;
this.jobState = jobState;
this.stageNumberList = stageNumber;
Expand All @@ -908,7 +908,7 @@ public ListJobCriteria(
this.matchingLabels = matchingLabels.map(query -> LabelUtils.generatePairs(query))
.orElse(Collections.emptyList());
this.labelsOperand = labelsOperand;
this.endJobIdExclusive = endJobIdExclusive;
this.startJobIdExclusive = startJobIdExclusive;
}

public ListJobCriteria() {
Expand Down Expand Up @@ -966,8 +966,8 @@ public Optional<String> getLabelsOperand() {
return labelsOperand;
}

public Optional<JobId> getEndJobIdExclusive() {
return endJobIdExclusive;
public Optional<JobId> getStartJobIdExclusive() {
return startJobIdExclusive;
}

@Override
Expand Down Expand Up @@ -1188,7 +1188,7 @@ public ListJobIdsRequest(
final Optional<String> matchingRegex,
final Optional<String> matchingLabels,
final Optional<String> labelsOperand,
final Optional<JobId> endJobIdExclusive) {
final Optional<JobId> startJobIdExclusive) {
super();
filters = new ListJobCriteria(
limit,
Expand All @@ -1201,7 +1201,7 @@ public ListJobIdsRequest(
matchingRegex,
matchingLabels,
labelsOperand,
endJobIdExclusive);
startJobIdExclusive);


}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,23 @@ void storeAndUpdateWorkers(final IMantisWorkerMetadata existingWorker, final IMa

Observable<IMantisJobMetadata> loadAllArchivedJobs();

// /**
// * Initialize and return all existing NamedJobs from persistence.
// * @return List of {@link NamedJob} objects.
// * @throws IOException Upon error connecting to or reading from persistence.
// */
/**
* Initialize and return all existing NamedJobs from persistence.
*
* @return List of {@link NamedJob} objects.
* @throws IOException Upon error connecting to or reading from persistence.
*/
List<IJobClusterMetadata> loadAllJobClusters() throws IOException;

List<CompletedJob> loadLatestCompletedJobsForCluster(String name, int limit, @Nullable JobId endJobId) throws IOException;
/**
* load all completed jobs for a given cluster sorted by descending order of job id
* @param name name of cluster
* @param limit max number of jobs to return
* @param startJobIdExclusive if not null, start from this job id
* @return list of completed jobs
* @throws IOException upon errors with storage invocation
*/
List<CompletedJob> loadLatestCompletedJobsForCluster(String name, int limit, @Nullable JobId startJobIdExclusive) throws IOException;

void archiveWorker(IMantisWorkerMetadata mwmd) throws IOException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -565,11 +565,11 @@ public void deleteCompletedJobsForCluster(String name) throws IOException {
}

@Override
public List<CompletedJob> loadLatestCompletedJobsForCluster(String name, int limit, @Nullable JobId endExclusive)
public List<CompletedJob> loadLatestCompletedJobsForCluster(String name, int limit, @Nullable JobId startJobIdExclusive)
throws IOException {
final Map<Long, String> items;
if (endExclusive != null) {
items = kvStore.getAllOrdered(NAMED_COMPLETEDJOBS_NS, name, limit, endExclusive.getJobNum());
if (startJobIdExclusive != null) {
items = kvStore.getAllOrdered(NAMED_COMPLETEDJOBS_NS, name, limit, startJobIdExclusive.getJobNum());
} else {
items = kvStore.getAllOrdered(NAMED_COMPLETEDJOBS_NS, name, limit);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ public List<IMantisJobMetadata> loadAllActiveJobs() throws IOException {
return mantisJobMetadataList;
}

public List<CompletedJob> loadCompletedJobsForCluster(String clusterName, int limit, @Nullable JobId endJobIdExclusive) throws IOException {
return storageProvider.loadLatestCompletedJobsForCluster(clusterName, limit, endJobIdExclusive);
public List<CompletedJob> loadCompletedJobsForCluster(String clusterName, int limit, @Nullable JobId startJobIdExclusive) throws IOException {
return storageProvider.loadLatestCompletedJobsForCluster(clusterName, limit, startJobIdExclusive);
}

public void deleteCompletedJobsForCluster(String clusterName) throws IOException {
Expand Down

0 comments on commit 1504bd0

Please sign in to comment.