diff --git a/src/main/java/picard/cmdline/CommandLineProgram.java b/src/main/java/picard/cmdline/CommandLineProgram.java index d37242a610..9b8f880c80 100644 --- a/src/main/java/picard/cmdline/CommandLineProgram.java +++ b/src/main/java/picard/cmdline/CommandLineProgram.java @@ -134,6 +134,9 @@ public abstract class CommandLineProgram { @Argument(doc="Google Genomics API client_secrets.json file path.", common = true) public String GA4GH_CLIENT_SECRETS="client_secrets.json"; + @Argument(doc="Google project for access to 'requester pays' buckets and objects.", common = true, optional = true) + public String REQUESTER_PAYS_PROJECT = null; + @ArgumentCollection(doc="Special Arguments that have meaning to the argument parsing system. " + "It is unlikely these will ever need to be accessed by the command line program") public Object specialArgumentsCollection = useLegacyParser() ? @@ -238,6 +241,16 @@ public int instanceMain(final String[] argv) { if (System.getProperty("ga4gh.client_secrets") == null) { System.setProperty("ga4gh.client_secrets", GA4GH_CLIENT_SECRETS); } + + if (PathProvider.GCS.isAvailable){ + if (System.getProperty("google_project_requester_pays") == null && + REQUESTER_PAYS_PROJECT != null) { + System.setProperty("google_project_requester_pays", REQUESTER_PAYS_PROJECT); + } + Log.getInstance(this.getClass()).info( + String.format("Will use google project %s for gcs requests.", System.getProperty("google_project_requester_pays"))); + } + SamReaderFactory.setDefaultValidationStringency(VALIDATION_STRINGENCY); // Set the compression level everywhere we can think of diff --git a/src/main/java/picard/nio/GoogleStorageUtils.java b/src/main/java/picard/nio/GoogleStorageUtils.java index 1e5f7c2d39..353fbcbebf 100644 --- a/src/main/java/picard/nio/GoogleStorageUtils.java +++ b/src/main/java/picard/nio/GoogleStorageUtils.java @@ -24,7 +24,6 @@ package picard.nio; - import com.google.cloud.storage.StorageOptions; import com.google.cloud.storage.contrib.nio.CloudStorageConfiguration; import com.google.cloud.storage.contrib.nio.CloudStorageFileSystemProvider; @@ -50,19 +49,20 @@ class GoogleStorageUtils { public static void initialize() { - // requester pays support is currently not configured - CloudStorageFileSystemProvider.setDefaultCloudStorageConfiguration(GoogleStorageUtils.getCloudStorageConfiguration(20, null)); + final String google_project = System.getProperty("google_project_requester_pays"); + + CloudStorageFileSystemProvider.setDefaultCloudStorageConfiguration(GoogleStorageUtils.getCloudStorageConfiguration(20, google_project)); CloudStorageFileSystemProvider.setStorageOptions(GoogleStorageUtils.setGenerousTimeouts(StorageOptions.newBuilder()).build()); } /** The config we want to use. **/ - private static CloudStorageConfiguration getCloudStorageConfiguration(int maxReopens, String requesterProject) { - CloudStorageConfiguration.Builder builder = CloudStorageConfiguration.builder() + private static CloudStorageConfiguration getCloudStorageConfiguration(final int maxReopens, final String requesterProject) { + final CloudStorageConfiguration.Builder builder = CloudStorageConfiguration.builder() // if the channel errors out, re-open up to this many times .maxChannelReopens(maxReopens); if (!Strings.isNullOrEmpty(requesterProject)) { // enable requester pays and indicate who pays - builder = builder.autoDetectRequesterPays(true).userProject(requesterProject); + builder.autoDetectRequesterPays(true).userProject(requesterProject); } // this causes the gcs filesystem to treat files that end in a / as a directory