Merge branch 'master' of ssh://gsa2.broadinstitute.org/humgen/gsa-scr1/gsa-engineering/git/unstable
This commit is contained in:
commit
a963b37424
|
|
@ -52,6 +52,7 @@ import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import java.util.zip.GZIPOutputStream;
|
import java.util.zip.GZIPOutputStream;
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -84,6 +85,10 @@ public class GATKRunReport {
|
||||||
*/
|
*/
|
||||||
private static File REPORT_SENTINEL = new File(REPORT_DIR.getAbsolutePath() + "/ENABLE");
|
private static File REPORT_SENTINEL = new File(REPORT_DIR.getAbsolutePath() + "/ENABLE");
|
||||||
|
|
||||||
|
// number of milliseconds before the S3 put operation is timed-out:
|
||||||
|
private static final long S3PutTimeOut = 30 * 1000;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* our log
|
* our log
|
||||||
*/
|
*/
|
||||||
|
|
@ -263,23 +268,24 @@ public class GATKRunReport {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void postReportToAWSS3() {
|
private class S3PutRunnable implements Runnable {
|
||||||
// modifying example code from http://jets3t.s3.amazonaws.com/toolkit/code-samples.html
|
|
||||||
this.hostName = Utils.resolveHostname(); // we want to fill in the host name
|
public AtomicBoolean isSuccess;
|
||||||
final String key = getKey();
|
private final String key;
|
||||||
logger.debug("Generating GATK report to AWS S3 with key " + key);
|
private final byte[] report;
|
||||||
|
|
||||||
|
public S3Object s3Object;
|
||||||
|
public String errorMsg;
|
||||||
|
public Throwable errorThrow;
|
||||||
|
|
||||||
|
public S3PutRunnable(String key, byte[] report){
|
||||||
|
isSuccess = new AtomicBoolean();
|
||||||
|
this.key = key;
|
||||||
|
this.report = report;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void run() {
|
||||||
try {
|
try {
|
||||||
// create an byte output stream so we can capture the output as a byte[]
|
|
||||||
final ByteArrayOutputStream byteStream = new ByteArrayOutputStream(8096);
|
|
||||||
final OutputStream outputStream = new GZIPOutputStream(byteStream);
|
|
||||||
postReportToStream(outputStream);
|
|
||||||
outputStream.close();
|
|
||||||
final byte[] report = byteStream.toByteArray();
|
|
||||||
|
|
||||||
// stop us from printing the annoying, and meaningless, mime types warning
|
|
||||||
Logger mimeTypeLogger = Logger.getLogger(org.jets3t.service.utils.Mimetypes.class);
|
|
||||||
mimeTypeLogger.setLevel(Level.FATAL);
|
|
||||||
|
|
||||||
// Your Amazon Web Services (AWS) login credentials are required to manage S3 accounts. These credentials
|
// Your Amazon Web Services (AWS) login credentials are required to manage S3 accounts. These credentials
|
||||||
// are stored in an AWSCredentials object:
|
// are stored in an AWSCredentials object:
|
||||||
|
|
||||||
|
|
@ -297,15 +303,66 @@ public class GATKRunReport {
|
||||||
S3Object fileObject = new S3Object(key, report);
|
S3Object fileObject = new S3Object(key, report);
|
||||||
//logger.info("Created S3Object" + fileObject);
|
//logger.info("Created S3Object" + fileObject);
|
||||||
//logger.info("Uploading " + localFile + " to AWS bucket");
|
//logger.info("Uploading " + localFile + " to AWS bucket");
|
||||||
S3Object s3Object = s3Service.putObject(REPORT_BUCKET_NAME, fileObject);
|
s3Object = s3Service.putObject(REPORT_BUCKET_NAME, fileObject);
|
||||||
logger.debug("Uploaded to AWS: " + s3Object);
|
isSuccess.set(true);
|
||||||
logger.info("Uploaded run statistics report to AWS S3");
|
|
||||||
} catch ( S3ServiceException e ) {
|
} catch ( S3ServiceException e ) {
|
||||||
exceptDuringRunReport("S3 exception occurred", e);
|
setException("S3 exception occurred", e);
|
||||||
} catch ( NoSuchAlgorithmException e ) {
|
} catch ( NoSuchAlgorithmException e ) {
|
||||||
exceptDuringRunReport("Couldn't calculate MD5", e);
|
setException("Couldn't calculate MD5", e);
|
||||||
|
} catch ( IOException e ) {
|
||||||
|
setException("Couldn't read report file", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setException(String msg, Throwable e){
|
||||||
|
errorMsg=msg;
|
||||||
|
errorThrow=e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void postReportToAWSS3() {
|
||||||
|
// modifying example code from http://jets3t.s3.amazonaws.com/toolkit/code-samples.html
|
||||||
|
this.hostName = Utils.resolveHostname(); // we want to fill in the host name
|
||||||
|
final String key = getKey();
|
||||||
|
logger.debug("Generating GATK report to AWS S3 with key " + key);
|
||||||
|
try {
|
||||||
|
// create an byte output stream so we can capture the output as a byte[]
|
||||||
|
final ByteArrayOutputStream byteStream = new ByteArrayOutputStream(8096);
|
||||||
|
final OutputStream outputStream = new GZIPOutputStream(byteStream);
|
||||||
|
postReportToStream(outputStream);
|
||||||
|
outputStream.close();
|
||||||
|
final byte[] report = byteStream.toByteArray();
|
||||||
|
|
||||||
|
// stop us from printing the annoying, and meaningless, mime types warning
|
||||||
|
Logger mimeTypeLogger = Logger.getLogger(org.jets3t.service.utils.Mimetypes.class);
|
||||||
|
mimeTypeLogger.setLevel(Level.FATAL);
|
||||||
|
|
||||||
|
// Set the S3 upload on its own thread with timeout:
|
||||||
|
S3PutRunnable s3run = new S3PutRunnable(key,report);
|
||||||
|
Thread s3thread = new Thread(s3run);
|
||||||
|
s3thread.setDaemon(true);
|
||||||
|
s3thread.setName("S3Put-Thread");
|
||||||
|
s3thread.start();
|
||||||
|
|
||||||
|
s3thread.join(S3PutTimeOut);
|
||||||
|
|
||||||
|
if(s3thread.isAlive()){
|
||||||
|
s3thread.interrupt();
|
||||||
|
exceptDuringRunReport("Run statistics report upload to AWS S3 timed-out");
|
||||||
|
} else if(s3run.isSuccess.get()) {
|
||||||
|
logger.info("Uploaded run statistics report to AWS S3");
|
||||||
|
logger.debug("Uploaded to AWS: " + s3run.s3Object);
|
||||||
|
} else {
|
||||||
|
if((s3run.errorMsg != null) && (s3run.errorThrow != null)){
|
||||||
|
exceptDuringRunReport(s3run.errorMsg,s3run.errorThrow);
|
||||||
|
} else {
|
||||||
|
exceptDuringRunReport("Run statistics report upload to AWS S3 failed");
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch ( IOException e ) {
|
} catch ( IOException e ) {
|
||||||
exceptDuringRunReport("Couldn't read report file", e);
|
exceptDuringRunReport("Couldn't read report file", e);
|
||||||
|
} catch ( InterruptedException e) {
|
||||||
|
exceptDuringRunReport("Run statistics report upload interrupted", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue