File tree Expand file tree Collapse file tree 5 files changed +63
-2
lines changed
main/nextflow/cloud/google/batch
test/nextflow/cloud/google/batch Expand file tree Collapse file tree 5 files changed +63
-2
lines changed Original file line number Diff line number Diff line change @@ -186,6 +186,13 @@ class GoogleBatchScriptLauncher extends BashWrapperBuilder implements GoogleBatc
186
186
187
187
GoogleBatchScriptLauncher withConfig (GoogleOpts config ) {
188
188
this . config = config
189
+ // Add logs bucket to mounted volumes if configured
190
+ if ( config?. batch?. logsBucket ) {
191
+ final logsBucketName = config. batch. extractBucketName(config. batch. logsBucket)
192
+ if ( logsBucketName ) {
193
+ buckets. add(logsBucketName)
194
+ }
195
+ }
189
196
return this
190
197
}
191
198
Original file line number Diff line number Diff line change @@ -459,9 +459,10 @@ class GoogleBatchTaskHandler extends TaskHandler implements FusionAwareTask {
459
459
protected LogsPolicy createLogsPolicy () {
460
460
final logsBucket = executor. batchConfig. logsBucket
461
461
if ( logsBucket ) {
462
+ final containerPath = executor. batchConfig. convertGcsPathToMountPath(logsBucket)
462
463
return LogsPolicy . newBuilder()
463
464
.setDestination(LogsPolicy.Destination . PATH )
464
- .setLogsPath(logsBucket )
465
+ .setLogsPath(containerPath )
465
466
.build()
466
467
} else {
467
468
return LogsPolicy . newBuilder()
Original file line number Diff line number Diff line change @@ -175,4 +175,31 @@ class BatchConfig implements ConfigScope {
175
175
return bucket
176
176
}
177
177
178
+ /**
179
+ * Extract the bucket name from a GCS path
180
+ * @param gcsPath GCS path like "gs://bucket-name/path/to/logs"
181
+ * @return bucket name like "bucket-name"
182
+ */
183
+ static String extractBucketName (String gcsPath ) {
184
+ if ( ! gcsPath || ! gcsPath. startsWith(' gs://' ) )
185
+ return null
186
+
187
+ final pathWithoutProtocol = gcsPath. substring(5 ) // Remove "gs://"
188
+ final slashIndex = pathWithoutProtocol. indexOf(' /' )
189
+ return slashIndex > 0 ? pathWithoutProtocol. substring(0 , slashIndex) : pathWithoutProtocol
190
+ }
191
+
192
+ /**
193
+ * Convert a GCS path to container mount path
194
+ * @param gcsPath GCS path like "gs://bucket-name/path/to/logs"
195
+ * @return container path like "/mnt/disks/bucket-name/path/to/logs"
196
+ */
197
+ static String convertGcsPathToMountPath (String gcsPath ) {
198
+ if ( ! gcsPath || ! gcsPath. startsWith(' gs://' ) )
199
+ return gcsPath
200
+
201
+ final pathWithoutProtocol = gcsPath. substring(5 ) // Remove "gs://"
202
+ return " /mnt/disks/${ pathWithoutProtocol} "
203
+ }
204
+
178
205
}
Original file line number Diff line number Diff line change @@ -702,7 +702,14 @@ class GoogleBatchTaskHandlerTest extends Specification {
702
702
703
703
and :
704
704
req. getLogsPolicy(). getDestination(). toString() == ' PATH'
705
- req. getLogsPolicy(). getLogsPath() == LOGS_BUCKET
705
+ req. getLogsPolicy(). getLogsPath() == ' /mnt/disks/my-logs-bucket/logs'
706
+ and :
707
+ def taskGroup = req. getTaskGroups(0 )
708
+ def volumes = taskGroup. getTaskSpec(). getVolumesList()
709
+ volumes. size() >= 2 // At least work dir volume and logs bucket volume
710
+ def logsBucketVolume = volumes. find { it. getGcs(). getRemotePath() == ' my-logs-bucket' }
711
+ logsBucketVolume != null
712
+ logsBucketVolume. getMountPath() == ' /mnt/disks/my-logs-bucket'
706
713
}
707
714
708
715
def makeTask (String name , TaskStatus.State state ){
Original file line number Diff line number Diff line change @@ -101,4 +101,23 @@ class BatchConfigTest extends Specification {
101
101
e. message. contains(" Logs bucket path must start with 'gs://'" )
102
102
}
103
103
104
+ def ' should extract bucket name from GCS path' () {
105
+ expect :
106
+ BatchConfig . extractBucketName(' gs://my-bucket' ) == ' my-bucket'
107
+ BatchConfig . extractBucketName(' gs://my-bucket/logs' ) == ' my-bucket'
108
+ BatchConfig . extractBucketName(' gs://my-bucket/path/to/logs' ) == ' my-bucket'
109
+ BatchConfig . extractBucketName(' gs://' ) == ' '
110
+ BatchConfig . extractBucketName(' invalid-path' ) == null
111
+ BatchConfig . extractBucketName(null ) == null
112
+ }
113
+
114
+ def ' should convert GCS path to mount path' () {
115
+ expect :
116
+ BatchConfig . convertGcsPathToMountPath(' gs://my-bucket' ) == ' /mnt/disks/my-bucket'
117
+ BatchConfig . convertGcsPathToMountPath(' gs://my-bucket/logs' ) == ' /mnt/disks/my-bucket/logs'
118
+ BatchConfig . convertGcsPathToMountPath(' gs://my-bucket/path/to/logs' ) == ' /mnt/disks/my-bucket/path/to/logs'
119
+ BatchConfig . convertGcsPathToMountPath(' invalid-path' ) == ' invalid-path'
120
+ BatchConfig . convertGcsPathToMountPath(null ) == null
121
+ }
122
+
104
123
}
You can’t perform that action at this time.
0 commit comments