Skip to content

Commit c55874c

Browse files
committed
Move snowflake specific configuration into SnowflakeConfig
1 parent 9e87c3d commit c55874c

File tree

3 files changed

+79
-4
lines changed

3 files changed

+79
-4
lines changed

src/main/groovy/nextflow/snowflake/SnowflakeExecutor.groovy

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import nextflow.processor.TaskHandler
77
import nextflow.processor.TaskMonitor
88
import nextflow.processor.TaskPollingMonitor
99
import nextflow.processor.TaskRun
10+
import nextflow.snowflake.config.SnowflakeConfig
1011
import nextflow.util.ServiceName
1112
import nextflow.util.Duration
1213
import org.pf4j.ExtensionPoint
@@ -23,7 +24,7 @@ import java.sql.ResultSet
2324
@ServiceName('snowflake')
2425
@CompileStatic
2526
class SnowflakeExecutor extends Executor implements ExtensionPoint {
26-
Map snowflakeConfig
27+
SnowflakeConfig snowflakeConfig
2728

2829
/**
2930
* A path where executable scripts from bin directory are copied
@@ -47,7 +48,7 @@ class SnowflakeExecutor extends Executor implements ExtensionPoint {
4748
Statement stmt = conn.createStatement();
4849
final Map<String, String> registryMappings = new HashMap<>()
4950

50-
String mappings = snowflakeConfig.get("registryMappings", "")
51+
String mappings = snowflakeConfig.registryMappings ?: ""
5152

5253
// Skip processing if mappings is empty
5354
if (mappings == null || mappings.trim().isEmpty()) {
@@ -119,7 +120,8 @@ class SnowflakeExecutor extends Executor implements ExtensionPoint {
119120
@Override
120121
protected void register() {
121122
super.register()
122-
snowflakeConfig = session.config.navigate("snowflake") as Map
123+
final Map configMap = session.config.navigate("snowflake") as Map
124+
snowflakeConfig = new SnowflakeConfig(configMap ?: [:])
123125

124126
// Validate that workDir uses snowflake:// scheme
125127
validateWorkDir()

src/main/groovy/nextflow/snowflake/SnowflakeTaskHandler.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ class SnowflakeTaskHandler extends TaskHandler {
174174

175175
final String spec = buildJobServiceSpec()
176176
final String computePoolEnv = System.getenv("computePool")
177-
final String defaultComputePool = computePoolEnv!=null ? computePoolEnv : executor.snowflakeConfig.get("computePool")
177+
final String defaultComputePool = computePoolEnv!=null ? computePoolEnv : executor.snowflakeConfig.computePool
178178
final String jobComment = String.format("nextflow task name: %s", task.getName())
179179

180180
String executeSql = String.format("""
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package nextflow.snowflake.config
2+
3+
import groovy.transform.CompileStatic
4+
import groovy.transform.ToString
5+
import nextflow.config.spec.ConfigOption
6+
import nextflow.config.spec.ConfigScope
7+
import nextflow.config.spec.ScopeName
8+
import nextflow.script.dsl.Description
9+
10+
/**
11+
* Configuration scope for Snowflake executor plugin.
12+
*
13+
* This class defines all configuration options available under the 'snowflake' scope
14+
* in Nextflow configuration files.
15+
*
16+
* @author Hongxin Yu <hongxin.yu@snowflake.com>
17+
*/
18+
@ScopeName('snowflake')
19+
@Description('''
20+
The `snowflake` scope allows you to configure the Snowflake executor plugin.
21+
22+
Example configuration:
23+
```
24+
snowflake {
25+
computePool = 'MY_COMPUTE_POOL'
26+
registryMappings = 'docker.io:my_registry,ghcr.io:github_registry'
27+
}
28+
```
29+
''')
30+
@CompileStatic
31+
@ToString(includeNames = true, includePackage = false)
32+
class SnowflakeConfig implements ConfigScope {
33+
34+
@ConfigOption
35+
@Description('''
36+
The name of the Snowflake compute pool to use for executing jobs.
37+
This can also be configured via the `computePool` environment variable.
38+
39+
Example: `computePool = 'MY_COMPUTE_POOL'`
40+
''')
41+
String computePool
42+
43+
@ConfigOption
44+
@Description('''
45+
Docker registry mappings for container images. This allows mapping external
46+
Docker registries to Snowflake image repositories.
47+
48+
Format: Comma-separated list of mappings in the form `original:replacement`
49+
50+
Example: `registryMappings = 'docker.io:my_registry,ghcr.io:github_registry'`
51+
''')
52+
String registryMappings
53+
54+
/**
55+
* No-argument constructor required for configuration validation support.
56+
*/
57+
SnowflakeConfig() {
58+
}
59+
60+
/**
61+
* Constructor accepting a Map for initialization from Nextflow configuration.
62+
*
63+
* @param opts Configuration options map
64+
*/
65+
SnowflakeConfig(Map opts) {
66+
if (opts == null) {
67+
return
68+
}
69+
70+
this.computePool = opts.computePool as String
71+
this.registryMappings = opts.registryMappings as String
72+
}
73+
}

0 commit comments

Comments
 (0)