-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #76 from rpmoore/master
Added a call that will find all the pending jobs where a set of files…
- Loading branch information
Showing
8 changed files
with
534 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
ds3-sdk/src/main/java/com/spectralogic/ds3client/utils/JobUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.spectralogic.ds3client.utils; | ||
|
||
import com.google.common.collect.ImmutableSet; | ||
import com.spectralogic.ds3client.Ds3Client; | ||
import com.spectralogic.ds3client.commands.GetJobRequest; | ||
import com.spectralogic.ds3client.commands.GetJobResponse; | ||
import com.spectralogic.ds3client.commands.GetJobsRequest; | ||
import com.spectralogic.ds3client.commands.GetJobsResponse; | ||
import com.spectralogic.ds3client.models.bulk.*; | ||
|
||
import java.io.IOException; | ||
import java.security.SignatureException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.UUID; | ||
|
||
public class JobUtils { | ||
|
||
public static List<UUID> findJob(final Ds3Client client, final RequestType type, final String bucketName, final Set<String> fileNames) throws IOException, SignatureException { | ||
final ImmutableSet<String> files = ImmutableSet.copyOf(fileNames); | ||
final GetJobsResponse response = client.getJobs(new GetJobsRequest()); | ||
final List<UUID> jobs = new ArrayList<>(); | ||
|
||
for (final JobInfo jobInfo : response.getJobs()) { | ||
if (!jobInfo.getBucketName().equals(bucketName) || jobInfo.getStatus() != JobStatus.IN_PROGRESS || jobInfo.getRequestType() != type) continue; | ||
final GetJobResponse jobResponse = client.getJob(new GetJobRequest(jobInfo.getJobId())); | ||
final MasterObjectList mol = jobResponse.getMasterObjectList(); | ||
|
||
for (final Objects chunk : mol.getObjects()) { | ||
if (chunkAndSetIntersects(chunk, files)){ | ||
jobs.add(jobInfo.getJobId()); | ||
break; // move onto the next job | ||
} | ||
} | ||
} | ||
return jobs; | ||
} | ||
|
||
private static boolean chunkAndSetIntersects(final Objects chunk, final ImmutableSet<String> fileNames) { | ||
for (final BulkObject bulkObject : chunk.getObjects()) { | ||
if (fileNames.contains(bulkObject.getName())) return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
} |
Oops, something went wrong.