forked from treasure-data/digdag
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #56 from st-tech/patch/makeCommandExecutorPluggable
patch make command executor pluggable
- Loading branch information
Showing
16 changed files
with
604 additions
and
9 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
digdag-core/src/test/java/io/digdag/core/workflow/MockCommandExecutorFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package io.digdag.core.workflow; | ||
|
||
import com.google.inject.Inject; | ||
import io.digdag.spi.CommandExecutor; | ||
import io.digdag.spi.CommandExecutorFactory; | ||
|
||
public class MockCommandExecutorFactory | ||
implements CommandExecutorFactory | ||
{ | ||
@Inject | ||
public MockCommandExecutorFactory() | ||
{ } | ||
|
||
@Override | ||
public String getType() | ||
{ | ||
return "mock"; | ||
} | ||
|
||
@Override | ||
public CommandExecutor newCommandExecutor() | ||
{ | ||
return new MockCommandExecutor(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
digdag-spi/src/main/java/io/digdag/spi/CommandExecutorFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package io.digdag.spi; | ||
|
||
public interface CommandExecutorFactory | ||
{ | ||
String getType(); | ||
|
||
CommandExecutor newCommandExecutor(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
digdag-standards/src/main/java/io/digdag/standards/command/CommandExecutorProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package io.digdag.standards.command; | ||
|
||
import com.google.inject.Inject; | ||
import com.google.inject.Provider; | ||
import io.digdag.client.config.Config; | ||
import io.digdag.client.config.ConfigException; | ||
import io.digdag.core.plugin.PluginSet; | ||
import io.digdag.spi.CommandExecutor; | ||
import io.digdag.spi.CommandExecutorFactory; | ||
|
||
import java.util.Set; | ||
import java.util.stream.Stream; | ||
|
||
public class CommandExecutorProvider | ||
implements Provider<CommandExecutor> | ||
{ | ||
private final CommandExecutor commandExecutor; | ||
|
||
@Inject | ||
public CommandExecutorProvider(Set<CommandExecutorFactory> injectedFactories, PluginSet.WithInjector pluginSet, Config systemConfig) | ||
{ | ||
// Set ECS as default command executor type | ||
String executorName = systemConfig.get("agent.command_executor.type", String.class, "ecs"); | ||
Stream<CommandExecutorFactory> candidates = Stream.concat( | ||
// Search from PluginSet first | ||
pluginSet.getServiceProviders(CommandExecutorFactory.class).stream(), | ||
// Then fallback to statically-injected commandExecutor | ||
injectedFactories.stream()); | ||
|
||
CommandExecutorFactory factory = candidates | ||
.filter(candidate -> candidate.getType().equals(executorName)) | ||
.findFirst() | ||
.orElseThrow(() -> new ConfigException("Configured commandExecutor name is not found: " + executorName)); | ||
|
||
this.commandExecutor = factory.newCommandExecutor(); | ||
} | ||
|
||
@Override | ||
public CommandExecutor get() | ||
{ | ||
return commandExecutor; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
digdag-standards/src/main/java/io/digdag/standards/command/DockerCommandExecutorFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package io.digdag.standards.command; | ||
|
||
import com.google.inject.Inject; | ||
import io.digdag.spi.CommandExecutor; | ||
import io.digdag.spi.CommandExecutorFactory; | ||
import io.digdag.spi.CommandLogger; | ||
|
||
public class DockerCommandExecutorFactory | ||
implements CommandExecutorFactory | ||
{ | ||
private final CommandLogger clog; | ||
private final SimpleCommandExecutor simple; | ||
|
||
@Inject | ||
public DockerCommandExecutorFactory(CommandLogger clog) | ||
{ | ||
this.clog = clog; | ||
this.simple = new SimpleCommandExecutor(clog); | ||
} | ||
|
||
@Override | ||
public String getType() | ||
{ | ||
return "docker"; | ||
} | ||
|
||
@Override | ||
public CommandExecutor newCommandExecutor() | ||
{ | ||
return new DockerCommandExecutor(clog, simple); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
digdag-standards/src/main/java/io/digdag/standards/command/EcsCommandExecutorFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package io.digdag.standards.command; | ||
|
||
import com.google.inject.Inject; | ||
import io.digdag.client.config.Config; | ||
import io.digdag.core.archive.ProjectArchiveLoader; | ||
import io.digdag.core.storage.StorageManager; | ||
import io.digdag.spi.CommandExecutor; | ||
import io.digdag.spi.CommandExecutorFactory; | ||
import io.digdag.spi.CommandLogger; | ||
import io.digdag.standards.command.ecs.EcsClientFactory; | ||
|
||
public class EcsCommandExecutorFactory | ||
implements CommandExecutorFactory | ||
{ | ||
private final Config systemConfig; | ||
private final EcsClientFactory ecsClientFactory; | ||
private final DockerCommandExecutor docker; | ||
private final StorageManager storageManager; | ||
private final ProjectArchiveLoader projectArchiveLoader; | ||
private final CommandLogger clog; | ||
|
||
@Inject | ||
public EcsCommandExecutorFactory( | ||
final Config systemConfig, | ||
final EcsClientFactory ecsClientFactory, | ||
final StorageManager storageManager, | ||
final ProjectArchiveLoader projectArchiveLoader, | ||
final CommandLogger clog) | ||
{ | ||
this.systemConfig = systemConfig; | ||
this.ecsClientFactory = ecsClientFactory; | ||
this.docker = new DockerCommandExecutor(clog, new SimpleCommandExecutor(clog)); | ||
this.storageManager = storageManager; | ||
this.projectArchiveLoader = projectArchiveLoader; | ||
this.clog = clog; | ||
} | ||
|
||
@Override | ||
public String getType() | ||
{ | ||
return "ecs"; | ||
} | ||
|
||
@Override | ||
public CommandExecutor newCommandExecutor() | ||
{ | ||
return new EcsCommandExecutor( | ||
systemConfig, | ||
ecsClientFactory, | ||
docker, | ||
storageManager, | ||
projectArchiveLoader, | ||
clog); | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
...standards/src/main/java/io/digdag/standards/command/KubernetesCommandExecutorFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package io.digdag.standards.command; | ||
|
||
import com.google.inject.Inject; | ||
import io.digdag.client.config.Config; | ||
import io.digdag.core.archive.ProjectArchiveLoader; | ||
import io.digdag.core.storage.StorageManager; | ||
import io.digdag.spi.CommandExecutor; | ||
import io.digdag.spi.CommandExecutorFactory; | ||
import io.digdag.spi.CommandLogger; | ||
import io.digdag.standards.command.kubernetes.KubernetesClientFactory; | ||
|
||
public class KubernetesCommandExecutorFactory | ||
implements CommandExecutorFactory | ||
{ | ||
private final Config systemConfig; | ||
private final KubernetesClientFactory kubernetesClientFactory; | ||
private final DockerCommandExecutor docker; | ||
private final StorageManager storageManager; | ||
private final ProjectArchiveLoader projectArchiveLoader; | ||
private final CommandLogger clog; | ||
|
||
@Inject | ||
public KubernetesCommandExecutorFactory( | ||
final Config systemConfig, | ||
final KubernetesClientFactory kubernetesClientFactory, | ||
final StorageManager storageManager, | ||
final ProjectArchiveLoader projectArchiveLoader, | ||
final CommandLogger clog) | ||
{ | ||
this.systemConfig = systemConfig; | ||
this.kubernetesClientFactory = kubernetesClientFactory; | ||
this.docker = new DockerCommandExecutor(clog, new SimpleCommandExecutor(clog)); | ||
this.storageManager = storageManager; | ||
this.projectArchiveLoader = projectArchiveLoader; | ||
this.clog = clog; | ||
} | ||
|
||
@Override | ||
public String getType() | ||
{ | ||
return "kubernetes"; | ||
} | ||
|
||
@Override | ||
public CommandExecutor newCommandExecutor() | ||
{ | ||
return new KubernetesCommandExecutor( | ||
systemConfig, | ||
kubernetesClientFactory, | ||
docker, | ||
storageManager, | ||
projectArchiveLoader, | ||
clog); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
digdag-standards/src/main/java/io/digdag/standards/command/SimpleCommandExecutorFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package io.digdag.standards.command; | ||
|
||
import com.google.inject.Inject; | ||
import io.digdag.spi.CommandExecutor; | ||
import io.digdag.spi.CommandExecutorFactory; | ||
import io.digdag.spi.CommandLogger; | ||
|
||
public class SimpleCommandExecutorFactory | ||
implements CommandExecutorFactory | ||
{ | ||
private final CommandLogger clog; | ||
|
||
@Inject | ||
public SimpleCommandExecutorFactory(CommandLogger clog) | ||
{ | ||
this.clog = clog; | ||
} | ||
|
||
@Override | ||
public String getType() | ||
{ | ||
return "simple"; | ||
} | ||
|
||
@Override | ||
public CommandExecutor newCommandExecutor() | ||
{ | ||
return new SimpleCommandExecutor(clog); | ||
} | ||
} |
Oops, something went wrong.