Skip to content

Commit

Permalink
Start default plugins on-demand #1964
Browse files Browse the repository at this point in the history
  • Loading branch information
pditommaso committed Apr 6, 2021
1 parent 7c35d98 commit cf2a9d7
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
17 changes: 16 additions & 1 deletion modules/nf-commons/src/main/nextflow/file/FileHelper.groovy
Expand Up @@ -46,9 +46,9 @@ import groovy.util.logging.Slf4j
import nextflow.Global
import nextflow.extension.Bolts
import nextflow.extension.FilesEx
import nextflow.plugin.Plugins
import nextflow.util.CacheHelper
import nextflow.util.Escape

/**
* Provides some helper method handling files
*
Expand Down Expand Up @@ -254,13 +254,28 @@ class FileHelper {
return Paths.get(str)
}

checkForMissingPlugins(str)

final result = FileSystemPathFactory.parse(str)
if( result )
return result

asPath(toPathURI(str))
}

static private Map<String,String> PLUGINS_MAP = [s3:'nf-amazon', gs:'nf-google', az:'nf-azure']

static protected void checkForMissingPlugins(String str) {
final scheme = getUrlProtocol(str)
final pluginId = PLUGINS_MAP.get(scheme)
if( pluginId ) try {
if( Plugins.startIfMissing(pluginId) )
log.debug "Started plugin '$pluginId' required to handle file: $str"
}
catch (Exception e) {
log.warn ("Unable to start plugin '$pluginId' required by $str")
}
}

/**
* Given a {@link URI} return a {@link Path} object
Expand Down
13 changes: 13 additions & 0 deletions modules/nf-commons/src/main/nextflow/plugin/Plugins.groovy
Expand Up @@ -47,6 +47,10 @@ class Plugins {
INSTANCE.stop()
}

static boolean hasPlugin(String pluginId) {
INSTANCE.hasPlugin(pluginId)
}

static <T> List<T> getExtensions(Class<T> type) {
INSTANCE.getExtensions(type)
}
Expand All @@ -59,4 +63,13 @@ class Plugins {
static void pull(List<String> ids) {
INSTANCE.pullPlugins(ids)
}

static boolean startIfMissing(String pluginId) {
if( INSTANCE ) {
return INSTANCE.startIfMissing(pluginId)
} else {
log.debug "Plugins subsystem not available - Ignoring installIfMissing('$pluginId')"
return false
}
}
}
23 changes: 23 additions & 0 deletions modules/nf-commons/src/main/nextflow/plugin/PluginsFacade.groovy
Expand Up @@ -28,6 +28,7 @@ import nextflow.extension.FilesEx
import nextflow.util.CacheHelper
import org.pf4j.DefaultPluginManager
import org.pf4j.PluginManager
import org.pf4j.PluginState
import org.pf4j.PluginStateEvent
import org.pf4j.PluginStateListener
/**
Expand Down Expand Up @@ -200,6 +201,14 @@ class PluginsFacade implements PluginStateListener {
}
}

boolean hasPlugin(String pluginId) {
return manager.getPlugin(pluginId) != null
}

boolean isStarted(String pluginId) {
manager.getPlugin(pluginId)?.pluginState == PluginState.STARTED
}

protected List<PluginSpec> pluginsRequirement(Map config) {
def specs = parseConf(config)
if( env.get('NXF_PACK')=='all' && specs ) {
Expand Down Expand Up @@ -275,4 +284,18 @@ class PluginsFacade implements PluginStateListener {
updater.pullPlugins(ids)
}

boolean startIfMissing(String pluginId) {
if( env.NXF_PLUGINS_DEFAULT == 'false' )
return false

if( isStarted(pluginId) )
return false

synchronized (this) {
if( isStarted(pluginId) )
return false
start(pluginId)
return true
}
}
}

0 comments on commit cf2a9d7

Please sign in to comment.