Skip to content

Commit cc64841

Browse files
committed
feat(Google-Batch): Configurable mounting point via config option google.batch.mountRoot
This commit adds the ability to configure the root of the mounting point for gcsfuse such that you could specify where the data is mounted. It is controlled by the config item google.batch.mountRoot with a default of /mnt/disks Signed-off-by: adamrtalbot <[email protected]>
1 parent c9bd193 commit cc64841

File tree

5 files changed

+28
-16
lines changed

5 files changed

+28
-16
lines changed

docs/reference/config.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -878,6 +878,11 @@ The following settings are available for Google Cloud Batch:
878878
: Max number of execution attempts of a job interrupted by a Compute Engine Spot reclaim event (default: `0`).
879879
: See also: `google.batch.autoRetryExitCodes`
880880

881+
`google.batch.mountRoot`
882+
: :::{versionadded} 25.05.0-edge
883+
:::
884+
: The root directory for GCS mounting in the container (default: `/mnt/disks`).
885+
881886
`google.batch.network`
882887
: The URL of an existing network resource to which the VM will be attached.
883888

plugins/nf-google/src/main/nextflow/cloud/google/batch/GoogleBatchExecutor.groovy

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,10 @@ class GoogleBatchExecutor extends Executor implements ExtensionPoint, TaskArrayE
168168
String getArrayWorkDir(TaskHandler handler) {
169169
return isFusionEnabled() || isWorkDirDefaultFS()
170170
? TaskArrayExecutor.super.getArrayWorkDir(handler)
171-
: containerMountPath(handler.task.workDir as CloudStoragePath)
171+
: containerMountPath(
172+
handler.task.workDir as CloudStoragePath,
173+
config.getMountRoot()
174+
)
172175
}
173176

174177
@Override

plugins/nf-google/src/main/nextflow/cloud/google/batch/GoogleBatchScriptLauncher.groovy

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ import nextflow.util.TestOnly
4343
@CompileStatic
4444
class GoogleBatchScriptLauncher extends BashWrapperBuilder implements GoogleBatchLauncherSpec {
4545

46-
private static final String MOUNT_ROOT = '/mnt/disks'
47-
4846
private BatchConfig config
4947
private CloudStoragePath remoteWorkDir
5048
private Path remoteBinDir
@@ -55,8 +53,11 @@ class GoogleBatchScriptLauncher extends BashWrapperBuilder implements GoogleBatc
5553
@TestOnly
5654
protected GoogleBatchScriptLauncher() {}
5755

58-
GoogleBatchScriptLauncher(TaskBean bean, Path remoteBinDir) {
56+
GoogleBatchScriptLauncher(TaskBean bean, Path remoteBinDir, BatchConfig config) {
5957
super(bean)
58+
// Initialize config first before using any methods that depend on it
59+
this.config = config
60+
6061
// keep track the google storage work dir
6162
this.remoteWorkDir = (CloudStoragePath) bean.workDir
6263
this.remoteBinDir = toContainerMount(remoteBinDir)
@@ -116,7 +117,7 @@ class GoogleBatchScriptLauncher extends BashWrapperBuilder implements GoogleBatc
116117
if( path instanceof CloudStoragePath ) {
117118
buckets.add(path.bucket())
118119
pathTrie.add( (parent ? "/${path.bucket()}${path.parent}" : "/${path.bucket()}${path}").toString() )
119-
final containerMount = containerMountPath(path)
120+
final containerMount = containerMountPath(path, config.getMountRoot())
120121
log.trace "Path ${FilesEx.toUriString(path)} to container mount: $containerMount"
121122
return Paths.get(containerMount)
122123
}
@@ -135,15 +136,17 @@ class GoogleBatchScriptLauncher extends BashWrapperBuilder implements GoogleBatc
135136
@Override
136137
List<String> getContainerMounts() {
137138
final result = new ArrayList(10)
139+
final mountRoot = config.getMountRoot()
138140
for( String it : pathTrie.longest() ) {
139-
result.add( "${MOUNT_ROOT}${it}:${MOUNT_ROOT}${it}:rw".toString() )
141+
result.add( "${mountRoot}${it}:${mountRoot}${it}:rw".toString() )
140142
}
141143
return result
142144
}
143145

144146
@Override
145147
List<Volume> getVolumes() {
146148
final result = new ArrayList(10)
149+
final mountRoot = config.getMountRoot()
147150
for( String it : buckets ) {
148151
final mountOptions = new LinkedList<String>()
149152
if( config && config.gcsfuseOptions )
@@ -157,7 +160,7 @@ class GoogleBatchScriptLauncher extends BashWrapperBuilder implements GoogleBatc
157160
GCS.newBuilder()
158161
.setRemotePath(it)
159162
)
160-
.setMountPath( "${MOUNT_ROOT}/${it}".toString() )
163+
.setMountPath( "${mountRoot}/${it}".toString() )
161164
.addAllMountOptions( mountOptions )
162165
.build()
163166
)
@@ -184,11 +187,6 @@ class GoogleBatchScriptLauncher extends BashWrapperBuilder implements GoogleBatc
184187
return remoteWorkDir.resolve(TaskRun.CMD_INFILE)
185188
}
186189

187-
GoogleBatchScriptLauncher withConfig(BatchConfig config) {
188-
this.config = config
189-
return this
190-
}
191-
192190
GoogleBatchScriptLauncher withIsArray(boolean value) {
193191
this.isArray = value
194192
return this
@@ -207,7 +205,7 @@ class GoogleBatchScriptLauncher extends BashWrapperBuilder implements GoogleBatc
207205
"trap \"{ cp ${TaskRun.CMD_LOG} ${workDir}/${TaskRun.CMD_LOG}; }\" ERR; /bin/bash ${workDir}/${TaskRun.CMD_RUN} 2>&1 | tee ${TaskRun.CMD_LOG}"
208206
}
209207

210-
static String containerMountPath(CloudStoragePath path) {
211-
return "$MOUNT_ROOT/${path.bucket()}${path}"
208+
static String containerMountPath(CloudStoragePath path, String mountRoot) {
209+
return "${mountRoot}/${path.bucket()}${path}"
212210
}
213211
}

plugins/nf-google/src/main/nextflow/cloud/google/batch/GoogleBatchTaskHandler.groovy

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import groovy.transform.CompileStatic
3737
import groovy.transform.PackageScope
3838
import groovy.util.logging.Slf4j
3939
import nextflow.cloud.google.batch.client.BatchClient
40+
import nextflow.cloud.google.batch.client.BatchConfig
4041
import nextflow.cloud.types.CloudMachineInfo
4142
import nextflow.cloud.types.PriceModel
4243
import nextflow.exception.ProcessException
@@ -148,8 +149,8 @@ class GoogleBatchTaskHandler extends TaskHandler implements FusionAwareTask {
148149
}
149150
else {
150151
final taskBean = task.toTaskBean()
151-
return new GoogleBatchScriptLauncher(taskBean, executor.remoteBinDir)
152-
.withConfig(executor.config)
152+
final config = executor.config ?: new BatchConfig()
153+
return new GoogleBatchScriptLauncher(taskBean, executor.remoteBinDir, config)
153154
.withIsArray(task.isArray())
154155
}
155156
}

plugins/nf-google/src/main/nextflow/cloud/google/batch/client/BatchConfig.groovy

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ class BatchConfig {
3737

3838
static final private List<String> DEFAULT_GCSFUSE_OPTS = List.<String>of('-o rw', '-implicit-dirs')
3939

40+
static final private String DEFAULT_MOUNT_ROOT = '/mnt/disks'
41+
4042
private GoogleOpts googleOpts
4143
private GoogleCredentials credentials
4244
private List<String> allowedLocations
@@ -55,6 +57,7 @@ class BatchConfig {
5557
private BatchRetryConfig retryConfig
5658
private List<Integer> autoRetryExitCodes
5759
private List<String> gcsfuseOptions
60+
private String mountRoot
5861

5962
GoogleOpts getGoogleOpts() { return googleOpts }
6063
GoogleCredentials getCredentials() { return credentials }
@@ -74,6 +77,7 @@ class BatchConfig {
7477
BatchRetryConfig getRetryConfig() { retryConfig }
7578
List<Integer> getAutoRetryExitCodes() { autoRetryExitCodes }
7679
List<String> getGcsfuseOptions() { gcsfuseOptions }
80+
String getMountRoot() { mountRoot }
7781

7882
static BatchConfig create(Session session) {
7983
final result = new BatchConfig()
@@ -95,6 +99,7 @@ class BatchConfig {
9599
result.retryConfig = new BatchRetryConfig( session.config.navigate('google.batch.retryPolicy') as Map ?: Map.of() )
96100
result.autoRetryExitCodes = session.config.navigate('google.batch.autoRetryExitCodes', DEFAULT_RETRY_LIST) as List<Integer>
97101
result.gcsfuseOptions = session.config.navigate('google.batch.gcsfuseOptions', DEFAULT_GCSFUSE_OPTS) as List<String>
102+
result.mountRoot = session.config.navigate('google.batch.mountRoot', DEFAULT_MOUNT_ROOT) as String
98103
return result
99104
}
100105

0 commit comments

Comments
 (0)