Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JENKINS-32741] Allow the log driver to be set for a Task #16

Merged
merged 1 commit into from
Apr 1, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import com.amazonaws.services.ecs.model.KeyValuePair;
import com.amazonaws.services.ecs.model.RegisterTaskDefinitionRequest;
import com.amazonaws.services.ecs.model.RegisterTaskDefinitionResult;
import com.amazonaws.services.ecs.model.LogConfiguration;
import hudson.Extension;
import hudson.model.AbstractDescribableImpl;
import hudson.model.Descriptor;
Expand All @@ -50,6 +51,8 @@
import java.util.Collection;
import java.util.List;
import java.util.Set;
import java.util.Map;
import java.util.HashMap;
import java.util.logging.Level;
import java.util.logging.Logger;

Expand Down Expand Up @@ -123,13 +126,35 @@ public class ECSTaskTemplate extends AbstractDescribableImpl<ECSTaskTemplate> {

private String taskDefinitionArn;

/**
* The log configuration specification for the container.
* This parameter maps to LogConfig in the Create a container section of
* the Docker Remote API and the --log-driver option to docker run.
* Valid log drivers are displayed in the LogConfiguration data type.
* This parameter requires version 1.18 of the Docker Remote API or greater
* on your container instance. To check the Docker Remote API version on
* your container instance, log into your container instance and run the
* following command: sudo docker version | grep "Server API version"
* The Amazon ECS container agent running on a container instance must
* register the logging drivers available on that instance with the
* ECS_AVAILABLE_LOGGING_DRIVERS environment variable before containers
* placed on that instance can use these log configuration options.
* For more information, see Amazon ECS Container Agent Configuration
* in the Amazon EC2 Container Service Developer Guide.
*/
@CheckForNull
private String logDriver;
private List<LogDriverOption> logDriverOptions;

@DataBoundConstructor
public ECSTaskTemplate(@Nullable String label,
@Nonnull String image,
@Nullable String remoteFSRoot,
int memory,
int cpu,
boolean privileged,
@Nullable List<LogDriverOption> logDriverOptions,
@Nullable String logDriver,
@Nullable List<EnvironmentEntry> environments,
@Nullable List<ExtraHostEntry> extraHosts,
@Nullable List<MountPointEntry> mountPoints) {
Expand All @@ -139,6 +164,8 @@ public ECSTaskTemplate(@Nullable String label,
this.memory = memory;
this.cpu = cpu;
this.privileged = privileged;
this.logDriver = logDriver;
this.logDriverOptions = logDriverOptions;
this.environments = environments;
this.extraHosts = extraHosts;
this.mountPoints = mountPoints;
Expand Down Expand Up @@ -186,6 +213,53 @@ public boolean getPrivileged() {
return privileged;
}

public String getLogDriver() {
return logDriver;
}

public static class LogDriverOption extends AbstractDescribableImpl<LogDriverOption>{
public String name, value;

@DataBoundConstructor
public LogDriverOption(String name, String value) {
this.name = name;
this.value = value;
}

@Override
public String toString() {
return "LogDriverOption{" + name + ": " + value + "}";
}

@Extension
public static class DescriptorImpl extends Descriptor<LogDriverOption> {
@Override
public String getDisplayName() {
return "logDriverOption";
}
}
}

public List<LogDriverOption> getLogDriverOptions() {
return logDriverOptions;
}

private Map<String,String> getLogDriverOptionsMap() {
if (null == logDriverOptions || logDriverOptions.isEmpty()) {
return null;
}
Map<String,String> options = new HashMap<String,String>();
for (LogDriverOption logDriverOption : logDriverOptions) {
String name = logDriverOption.name;
String value = logDriverOption.value;
if (StringUtils.isEmpty(name) || StringUtils.isEmpty(value)) {
continue;
}
options.put(name, value);
}
return options;
}

public String getTaskDefinitionArn() {
return taskDefinitionArn;
}
Expand Down Expand Up @@ -373,6 +447,13 @@ public RegisterTaskDefinitionRequest asRegisterTaskDefinitionRequest() {
.withName("JAVA_OPTS").withValue(jvmArgs))
.withEssential(true);

if (logDriver != null) {
LogConfiguration logConfig = new LogConfiguration();
logConfig.setLogDriver(logDriver);
logConfig.setOptions(getLogDriverOptionsMap());
def.withLogConfiguration(logConfig);
}

return new RegisterTaskDefinitionRequest()
.withFamily("jenkins-slave")
.withVolumes(getVolumeEntries())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,26 @@
<f:entry title="${%Privileged}" field="privileged">
<f:checkbox />
</f:entry>
<f:entry title="${%Logging Driver}" field="logDriver">
<f:textbox />
</f:entry>
<f:entry title="${%Logging Configuration}">
<f:repeatable field="logDriverOptions">
<table width="100%">
<f:entry title="${%Name}" field="name">
<f:textbox />
</f:entry>
<f:entry title="${%Value}" field="value">
<f:textbox />
</f:entry>
<f:entry>
<div align="right">
<f:repeatableDeleteButton />
</div>
</f:entry>
</table>
</f:repeatable>
</f:entry>
<f:entry title="${%Environments}">
<f:repeatable field="environments">
<table width="100%">
Expand Down