Skip to content

Commit

Permalink
support custom Bpipe home in agent configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
ssadedin committed Aug 23, 2024
1 parent 53e8e4b commit 0ff1ca2
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
18 changes: 13 additions & 5 deletions src/main/groovy/bpipe/agent/Agent.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ abstract class Agent extends TimerTask {
* for that command type. These are either objects extending BpipeCommand or Closures
* that are executed directly.
*/
public static Map COMMANDS = [
"retry" : { dir, args, writer -> bpipe(dir, ['retry'], writer)},
public Map COMMANDS = [
"retry" : { dir, args, writer -> bpipe(bpipeHome, dir, ['retry'], writer)},
"stop" : Stop,
"log" : LogCommand,
"run" : RunPipelineCommand,
Expand Down Expand Up @@ -96,6 +96,8 @@ abstract class Agent extends TimerTask {

Semaphore concurrency = null

String bpipeHome = bpipe.Runner.BPIPE_HOME

int executed = 0

int errors = 0
Expand Down Expand Up @@ -155,7 +157,13 @@ abstract class Agent extends TimerTask {
try {
++this.executed
BpipeCommand command = createCommandFromAttributes(commandAttributes)
command.dir = commandAttributes.directory ?: ((PipelineInfo)pipelines[((Map)(commandAttributes.run)).id]).path
command.bpipeHome = this.bpipeHome

command.dir = commandAttributes.directory
if(!command.dir) {
command.dir = ((PipelineInfo)pipelines[((Map)(commandAttributes.run))?.id])?.path
}

validateCommand(command)
AgentCommandRunner runner = new AgentCommandRunner(createConnection(), (Long)commandAttributes.id, command, outputMode, onRun)
runner.concurrency = this.concurrency
Expand Down Expand Up @@ -241,7 +249,7 @@ abstract class Agent extends TimerTask {
return command
}

static void bpipe(String dir, List bpipeArgs, Writer out) {
static void bpipe(String home, String dir, List bpipeArgs, Writer out) {
if(dir == null)
throw new IllegalArgumentException("Directory parameter not set. Directory for command to run in must be specified")

Expand All @@ -250,7 +258,7 @@ abstract class Agent extends TimerTask {
throw new IllegalArgumentException("Directory supplied $dir is not in an existing path. The directory parent must already exist.")

log.info "Args are: " + bpipeArgs
List<String> cmd = [ bpipe.Runner.BPIPE_HOME + "/bin/bpipe" ]
List<String> cmd = [ home + "/bin/bpipe" ]
cmd.addAll(bpipeArgs)
log.info "Running command : " + cmd;
ExecutedProcess result = Utils.executeCommand(cmd, out:out, err: out) {
Expand Down
5 changes: 5 additions & 0 deletions src/main/groovy/bpipe/agent/AgentRunner.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ class AgentRunner {
agent.concurrency = new Semaphore(concurrency.toInteger())
}
agent.singleShot = agentConfig.getOrDefault('singleshot', opts.s)

if(agentConfig.containsKey('bpipeHome')) {
agent.bpipeHome = agentConfig.bpipeHome
log.info("Using custom Bpipe home $agent.bpipeHome for agent $agent.name")
}

if(opts.t) {
log.info "Scheduling timeout in $opts.t ms"
Expand Down
5 changes: 4 additions & 1 deletion src/main/groovy/bpipe/cmd/BpipeCommand.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import bpipe.agent.PipelineInfo
import groovy.transform.CompileStatic;
import groovy.util.logging.Log;;

@CompileStatic
@Log
abstract class BpipeCommand {

Expand All @@ -21,6 +22,8 @@ abstract class BpipeCommand {

String dir

String bpipeHome = bpipe.Runner.BPIPE_HOME

BpipeCommand(String commandLine, List<String> args) {
this.commandLine = commandLine
this.args = args
Expand Down Expand Up @@ -55,7 +58,7 @@ abstract class BpipeCommand {
if(!COMMAND_TMP.exists())
COMMAND_TMP.mkdirs()

String command = bpipe.Runner.BPIPE_HOME + "/bin/$exe $commandLine"
String command = this.bpipeHome + "/bin/$exe $commandLine"
if(args) {
command = "$command " + args.collect { "'" + it + "'" }.join(" ")
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/groovy/bpipe/cmd/RunPipelineCommand.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class RunPipelineCommand extends BpipeCommand {

this.runDirectory = dirFile

List<String> cmd = [ bpipe.Runner.BPIPE_HOME + "/bin/bpipe", "run" ]
List<String> cmd = [ bpipeHome + "/bin/bpipe", "run" ]
cmd.addAll(args)
result = Utils.executeCommand(cmd, out:out, err: out) {
directory(dirFile)
Expand Down

0 comments on commit 0ff1ca2

Please sign in to comment.