Docker config full support.
diff --git a/taverna-docker-activity/src/main/java/org/apache/taverna/activities/docker/DockerContainerConfiguration.java b/taverna-docker-activity/src/main/java/org/apache/taverna/activities/docker/DockerContainerConfiguration.java
index bc1768b..2ca0648 100644
--- a/taverna-docker-activity/src/main/java/org/apache/taverna/activities/docker/DockerContainerConfiguration.java
+++ b/taverna-docker-activity/src/main/java/org/apache/taverna/activities/docker/DockerContainerConfiguration.java
@@ -20,6 +20,7 @@
import com.github.dockerjava.api.model.ExposedPort;
import com.github.dockerjava.api.model.Ports;
+import com.github.dockerjava.api.model.Volume;
import java.util.Map;
@@ -75,8 +76,6 @@
public static final String CMD = "cmd";
- public static final String CMD_DELIMITER = ",";
-
public static final String ENTRY_POINT = "entrypoint";
/**
@@ -117,20 +116,60 @@
public void setDockerRemoteConfig(DockerRemoteConfig dockerRemoteConfig);
+ public DockerRemoteConfig getDockerRemoteConfig();
+
public Map<String, String> getInternalPropertyMap();
public String getName();
public String getImage();
- public String[] getCmd();
-
- public DockerRemoteConfig getDockerRemoteConfig();
-
public ExposedPort[] getExposedPorts();
public Ports.Binding[] getBindings();
- //TODO add all remaining getters
+ public String getHostName();
+
+ public String getDomainName();
+
+ public String getUser();
+
+ public String getWorkingDir();
+
+ public String getMacAddress();
+
+ public String getStopSignal();
+
+ public String getIpv4Address();
+
+ public String getIpv6Address();
+
+ public boolean getAttachStdin();
+
+ public boolean getAttachStdout();
+
+ public boolean getAttachStderr();
+
+ public boolean getTty();
+
+ public boolean getStdinOpen();
+
+ public boolean getStdinOnce();
+
+ public boolean getNetworkDisabled();
+
+ public String[] getPortSpecs();
+
+ public String[] getEnv();
+
+ public String[] getEntryPoint();
+
+ public String[] getCmd();
+
+ public Volume[] getVolumes();
+
+ public String[] getAliases();
+
+ public Map<String, String> getLabels();
}
diff --git a/taverna-docker-activity/src/main/java/org/apache/taverna/activities/docker/DockerContainerConfigurationImpl.java b/taverna-docker-activity/src/main/java/org/apache/taverna/activities/docker/DockerContainerConfigurationImpl.java
index 4e19713..ce5af23 100644
--- a/taverna-docker-activity/src/main/java/org/apache/taverna/activities/docker/DockerContainerConfigurationImpl.java
+++ b/taverna-docker-activity/src/main/java/org/apache/taverna/activities/docker/DockerContainerConfigurationImpl.java
@@ -27,6 +27,18 @@
private DockerRemoteConfig dockerRemoteConfig;
+ private static final String ARR_DELIMITER = ",";
+
+ private static final String MAP_DELIMITER = ":";
+
+ private ExposedPort[] exposedPorts = null;
+
+ private Ports.Binding[] bindings = null;
+
+ private Volume[] volumes = null;
+
+ private Map<String, String> labels = null;
+
public DockerContainerConfigurationImpl(ConfigurationManager configurationManager){
super(configurationManager);
@@ -45,130 +57,162 @@
}
public String getName() {
- return this.getInternalPropertyMap().get(NAME);
- }
-
- public String getHostName() {
- return HOST_NAME;
- }
-
- public String getDomainName() {
- return DOMAIN_NAME;
- }
-
- public String getUser() {
- return USER;
+ return this.getInternalPropertyMap().get(NAME) != null? this.getInternalPropertyMap().get(NAME) : null;
}
public String getImage() {
- return this.getInternalPropertyMap().get(IMAGE);
- }
-
- public String getWorkingDir() {
- return WORKING_DIR;
- }
-
- public String getMacAddress() {
- return MAC_ADDRESS;
- }
-
- public String getStopSignal() {
- return STOP_SIGNAL;
- }
-
- public String getIpv4Address() {
- return IPV4_ADDRESS;
- }
-
- public String getIpv6Address() {
- return IPV6_ADDRESS;
- }
-
- public String getAttachStdin() {
- return ATTACH_STDIN;
- }
-
- public String getAttachStdout() {
- return ATTACH_STDOUT;
- }
-
- public String getAttachStderr() {
- return ATTACH_STDERR;
- }
-
- public String getTty() {
- return TTY;
- }
-
- public String getStdinOpen() {
- return STDIN_OPEN;
- }
-
- public String getStdinOnce() {
- return STDIN_ONCE;
- }
-
- public String getNetworkDisabled() {
- return NETWORK_DISABLED;
- }
-
- public String getPortSpecs() {
- return PORT_SPECS;
- }
-
- public String getEnv() {
- return ENV;
- }
-
- public String[] getCmd() {
- return this.getInternalPropertyMap().get(CMD).split(CMD_DELIMITER);
- }
-
- public String getEntryPoint() {
- return ENTRY_POINT;
- }
-
- public String getVolumes() {
- return VOLUMES;
- }
-
- public Ports.Binding[] getBindings() {
- String bindingsStr = this.getInternalPropertyMap().get(BINDINGS);
- List<Ports.Binding> bindingList = new ArrayList<Ports.Binding>();
- if(bindingsStr != null) {
- for(String bind : bindingsStr.split(",")){
- bindingList.add(Ports.Binding.bindPort(Integer.valueOf(bind)));
- }
- }
- return bindingList.toArray(new Ports.Binding[0]);
- }
-
- public String getAliases() {
- return ALIASES;
+ return this.getInternalPropertyMap().get(IMAGE) != null?this.getInternalPropertyMap().get(IMAGE):null;
}
public ExposedPort[] getExposedPorts() {
- String exposedPortStr = this.getInternalPropertyMap().get(EXPOSED_PORTS);
- List<ExposedPort> exposedPortList = new ArrayList<ExposedPort>();
- if(exposedPortStr != null){
- for(String portStr: exposedPortStr.split(",")){
- exposedPortList.add(ExposedPort.tcp(Integer.valueOf(portStr)));
+ if(exposedPorts == null) {
+ String exposedPortStr = this.getInternalPropertyMap().get(EXPOSED_PORTS);
+ if(exposedPortStr == null){
+ return null;
+ }
+ List<ExposedPort> exposedPortList = new ArrayList<ExposedPort>();
+ if (exposedPortStr != null) {
+ for (String portStr : exposedPortStr.split(ARR_DELIMITER)) {
+ exposedPortList.add(ExposedPort.tcp(Integer.valueOf(portStr)));
+ }
+ }
+ exposedPorts = exposedPortList.toArray(new ExposedPort[0]);
+ }
+
+ return exposedPorts;
+ }
+
+ public Ports.Binding[] getBindings() {
+ if(bindings == null) {
+ String bindingsStr = this.getInternalPropertyMap().get(BINDINGS);
+ if(bindingsStr == null){
+ return null;
+ }
+ List<Ports.Binding> bindingList = new ArrayList<Ports.Binding>();
+ if (bindingsStr != null) {
+ for (String bind : bindingsStr.split(ARR_DELIMITER)) {
+ bindingList.add(Ports.Binding.bindPort(Integer.valueOf(bind)));
+ }
+ }
+ bindings = bindingList.toArray(new Ports.Binding[0]);
+ }
+ return bindings;
+ }
+
+ public String getHostName() {
+ return this.getInternalPropertyMap().get(HOST_NAME);
+ }
+
+ public String getDomainName() {
+ return this.getInternalPropertyMap().get(DOMAIN_NAME);
+ }
+
+ public String getUser() {
+ return this.getInternalPropertyMap().get(USER);
+ }
+
+ public String getWorkingDir() {
+ return this.getInternalPropertyMap().get(WORKING_DIR);
+ }
+
+ public String getMacAddress() {
+ return this.getInternalPropertyMap().get(MAC_ADDRESS);
+ }
+
+ public String getStopSignal() {
+ return this.getInternalPropertyMap().get(STOP_SIGNAL);
+ }
+
+ public String getIpv4Address() {
+ return this.getInternalPropertyMap().get(IPV4_ADDRESS);
+ }
+
+ public String getIpv6Address() {
+ return this.getInternalPropertyMap().get(IPV6_ADDRESS);
+ }
+
+ public boolean getAttachStdin() {
+ return Boolean.parseBoolean(this.getInternalPropertyMap().get(ATTACH_STDIN));
+ }
+
+ public boolean getAttachStdout() {
+ return Boolean.parseBoolean(this.getInternalPropertyMap().get(ATTACH_STDOUT));
+ }
+
+ public boolean getAttachStderr() {
+ return Boolean.parseBoolean(this.getInternalPropertyMap().get(ATTACH_STDERR));
+ }
+
+ public boolean getTty() {
+ return Boolean.parseBoolean(this.getInternalPropertyMap().get(TTY));
+ }
+
+ public boolean getStdinOpen() {
+ return Boolean.parseBoolean(this.getInternalPropertyMap().get(STDIN_OPEN));
+ }
+
+ public boolean getStdinOnce() {
+ return Boolean.parseBoolean(this.getInternalPropertyMap().get(STDIN_ONCE));
+ }
+
+ public boolean getNetworkDisabled() {
+ return Boolean.parseBoolean(this.getInternalPropertyMap().get(NETWORK_DISABLED));
+ }
+
+ public String[] getPortSpecs() {
+ return this.getInternalPropertyMap().get(PORT_SPECS) != null ?
+ this.getInternalPropertyMap().get(PORT_SPECS).split(ARR_DELIMITER): null;
+ }
+
+ public String[] getEnv() {
+ return this.getInternalPropertyMap().get(ENV) != null ?
+ this.getInternalPropertyMap().get(ENV).split(ARR_DELIMITER):null;
+ }
+
+ public String[] getEntryPoint() {
+ return this.getInternalPropertyMap().get(ENTRY_POINT) != null ?
+ this.getInternalPropertyMap().get(ENTRY_POINT).split(ARR_DELIMITER):null;
+ }
+
+ public String[] getCmd() {
+ return this.getInternalPropertyMap().get(CMD) != null ?
+ this.getInternalPropertyMap().get(CMD).split(ARR_DELIMITER): null;
+ }
+
+ public Volume[] getVolumes() {
+ if(volumes == null) {
+ if(this.getInternalPropertyMap().get(VOLUMES) == null){
+ return null;
+ }
+ String[] arr = this.getInternalPropertyMap().get(VOLUMES).split(ARR_DELIMITER);
+ volumes = new Volume[arr.length];
+ for (int i = 0; i < arr.length; i++) {
+ volumes[i] = new Volume(arr[i]);
}
}
- return exposedPortList.toArray(new ExposedPort[0]);
+ return volumes;
}
- public String getLabels() {
- return LABELS;
+ public String[] getAliases() {
+ return this.getInternalPropertyMap().get(ALIASES) != null ?
+ this.getInternalPropertyMap().get(ALIASES).split(ARR_DELIMITER): null;
}
- public String getHostConfig() {
- return HOST_CONFIG;
+ public Map<String, String> getLabels() {
+ if (labels == null) {
+ labels = new HashMap<>();
+ if(this.getInternalPropertyMap().get(LABELS) == null){
+ return null;
+ }
+ String[] entries = this.getInternalPropertyMap().get(LABELS).split(MAP_DELIMITER);
+ for (String entry : entries) {
+ String[] kv = entry.split(ARR_DELIMITER);
+ labels.put(kv[0], kv[1]);
+ }
+ }
+ return labels;
}
- public String getNetworkingConfig() {
- return NETWORKING_CONFIG;
- }
@Override
public Map<String, String> getDefaultPropertyMap() {
diff --git a/taverna-docker-activity/src/main/java/org/apache/taverna/activities/docker/RemoteClient.java b/taverna-docker-activity/src/main/java/org/apache/taverna/activities/docker/RemoteClient.java
index 43712c2..dc66cbd 100644
--- a/taverna-docker-activity/src/main/java/org/apache/taverna/activities/docker/RemoteClient.java
+++ b/taverna-docker-activity/src/main/java/org/apache/taverna/activities/docker/RemoteClient.java
@@ -125,14 +125,89 @@
private CreateContainerCmd buildCreateContainerCmd(){
CreateContainerCmd createCmd = dockerClient.createContainerCmd(containerConfig.getImage());
- createCmd.withCmd(containerConfig.getCmd());
- createCmd.withName(containerConfig.getName());
- Ports portBindings = new Ports();
- for(int i=0; i< containerConfig.getBindings().length; i++){
- portBindings.bind(containerConfig.getExposedPorts()[i], containerConfig.getBindings()[i]);
+
+ if(containerConfig.getCmd() != null) {
+ createCmd.withCmd(containerConfig.getCmd());
}
- createCmd.withExposedPorts(containerConfig.getExposedPorts());
- createCmd.withPortBindings(portBindings);
+
+ if(containerConfig.getName() != null) {
+ createCmd.withName(containerConfig.getName());
+ }
+
+ if(containerConfig.getBindings() != null && containerConfig.getExposedPorts() != null) {
+ Ports portBindings = new Ports();
+ for (int i = 0; i < containerConfig.getBindings().length; i++) {
+ portBindings.bind(containerConfig.getExposedPorts()[i], containerConfig.getBindings()[i]);
+ }
+ createCmd.withExposedPorts(containerConfig.getExposedPorts());
+ createCmd.withPortBindings(portBindings);
+ }
+
+ if(containerConfig.getHostName() != null) {
+ createCmd.withHostName(containerConfig.getHostName());
+ }
+
+ if(containerConfig.getDomainName() != null) {
+ createCmd.withDomainName(containerConfig.getDomainName());
+ }
+
+ if(containerConfig.getUser() != null) {
+ createCmd.withUser(containerConfig.getUser());
+ }
+
+ if(containerConfig.getWorkingDir() != null) {
+ createCmd.withWorkingDir(containerConfig.getWorkingDir());
+ }
+
+ if(containerConfig.getMacAddress() != null) {
+ createCmd.withMacAddress(containerConfig.getMacAddress());
+ }
+
+ if(containerConfig.getStopSignal() != null) {
+ createCmd.withStopSignal(containerConfig.getStopSignal());
+ }
+
+ if(containerConfig.getIpv4Address() != null) {
+ createCmd.withIpv4Address(containerConfig.getIpv4Address());
+ }
+
+ if(containerConfig.getIpv6Address() != null) {
+ createCmd.withIpv6Address(containerConfig.getIpv6Address());
+ }
+
+ createCmd.withAttachStdin(containerConfig.getAttachStdin());
+ createCmd.withAttachStdout(containerConfig.getAttachStdout());
+ createCmd.withAttachStderr(containerConfig.getAttachStderr());
+ createCmd.withTty(containerConfig.getTty());
+ createCmd.withStdInOnce(containerConfig.getStdinOnce());
+ createCmd.withStdinOpen(containerConfig.getStdinOpen());
+ createCmd.withNetworkDisabled(containerConfig.getNetworkDisabled());
+
+
+ if(containerConfig.getPortSpecs() != null) {
+ createCmd.withPortSpecs(containerConfig.getPortSpecs());
+ }
+
+ if(containerConfig.getEnv() != null) {
+ createCmd.withEnv(containerConfig.getEnv());
+ }
+
+ if(containerConfig.getEntryPoint() != null) {
+ createCmd.withEntrypoint(containerConfig.getEntryPoint());
+ }
+
+ if(containerConfig.getVolumes() != null) {
+ createCmd.withVolumes(containerConfig.getVolumes());
+ }
+
+ if(containerConfig.getAliases() != null) {
+ createCmd.withAliases(containerConfig.getAliases());
+ }
+
+ if(containerConfig.getLabels() != null) {
+ createCmd.withLabels(containerConfig.getLabels());
+ }
+
return createCmd;
}