Skip to content

Commit

Permalink
Merge pull request #76 from rpmoore/master
Browse files Browse the repository at this point in the history
Added a call that will find all the pending jobs where a set of files…
  • Loading branch information
rpmoore committed Jun 9, 2015
2 parents 1e0111b + 4cdbfa1 commit 41ff61d
Show file tree
Hide file tree
Showing 8 changed files with 534 additions and 2 deletions.
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

allprojects {
group = 'com.spectralogic.ds3'
version = '1.1.0-RC6'
version = '1.1.0-RC7'
}

subprojects {
Expand All @@ -31,6 +31,7 @@ subprojects {

dependencies {
compile 'org.slf4j:slf4j-api:1.7.12'
compile 'org.slf4j:jcl-over-slf4j:1.7.12'
testCompile 'org.mockito:mockito-all:1.9.5'
testCompile 'junit:junit:4.11'
testCompile 'org.slf4j:slf4j-simple:1.7.12'
Expand Down
4 changes: 4 additions & 0 deletions ds3-sdk/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ artifacts {
archives shadowJar
}

jar {
from sourceSets.main.allJava
}

dependencies {
compile 'org.apache.httpcomponents:httpclient:4.3.2'
compile 'commons-codec:commons-codec:1.10'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,11 @@ public String getPath() {
public HttpVerb getVerb() {
return HttpVerb.GET;
}

@Override
public boolean equals(final Object obj) {
if (!obj.getClass().equals(GetJobRequest.class)) return false;
final GetJobRequest other = (GetJobRequest) obj;
return other.getJobId().equals(this.getJobId());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,22 @@

import java.util.UUID;

/**
* Creates a NotificationRequest to receive notifications when either a specific job is completed
* or when any job completes.
*/
public class CreateJobCompletedNotificationRequest extends AbstractCreateNotificationRequest {
/**
* Create a NotificationRequest that will receive all JobCompleted Notifications
*/
public CreateJobCompletedNotificationRequest(final String endpoint) {
super(endpoint);
}

/**
* Create a NotificationRequest that will receive the JobCompleted Notification only for
* the job specified by {@param jobId}
*/
public CreateJobCompletedNotificationRequest(final String endpoint, final UUID jobId) {
super(endpoint);
this.getQueryParams().put("job_id", jobId.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@

package com.spectralogic.ds3client.commands.notifications;

/**
* Creates a NotificationRequest to receive notifications for when any Job is Created.
*/
public class CreateJobCreatedNotificationRequest extends AbstractCreateNotificationRequest {
public CreateJobCreatedNotificationRequest(final String endpoint) {
super(endpoint);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,22 @@

import java.util.UUID;

/**
* Creates a NotificationRequest to receive notifications for when an object is finished being written to cache
*/
public class CreateObjectCachedNotificationRequest extends AbstractCreateNotificationRequest {

/**
* Creates a NotificationRequest to receive all object cached notifications
*/
public CreateObjectCachedNotificationRequest(final String endpoint) {
super(endpoint);
}

public CreateObjectCachedNotificationRequest(final String endpoint, final UUID jobId) {
/**
* Creates a NotificationRequest to receive object cached notifications for the job specified by {@param jobId}
*/
public CreateObjectCachedNotificationRequest(final String endpoint, final UUID jobId) {
super(endpoint);
this.getQueryParams().put("job_id", jobId.toString());
}
Expand Down
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;
}

}
Loading

0 comments on commit 41ff61d

Please sign in to comment.