From 4a4e5b3edaf5b53c29548a7723a62aebf61abb63 Mon Sep 17 00:00:00 2001 From: Kanstantsin Shautsou Date: Sun, 14 Aug 2016 17:14:17 +0300 Subject: [PATCH 1/2] Add logging type option. --- .../kostyasha/it/tests/SimpleBuildTest.java | 11 +++ .../yad/commons/DockerCreateContainer.java | 18 ++++ .../yad/commons/DockerLogConfig.java | 86 +++++++++++++++++++ .../DockerCreateContainer/config.groovy | 1 + .../yad/commons/DockerLogConfig/config.groovy | 18 ++++ .../DockerLogConfig/help-loggingType.html | 2 + 6 files changed, 136 insertions(+) create mode 100644 yet-another-docker-plugin/src/main/java/com/github/kostyasha/yad/commons/DockerLogConfig.java create mode 100644 yet-another-docker-plugin/src/main/resources/com/github/kostyasha/yad/commons/DockerLogConfig/config.groovy create mode 100644 yet-another-docker-plugin/src/main/resources/com/github/kostyasha/yad/commons/DockerLogConfig/help-loggingType.html diff --git a/yet-another-docker-its/src/test/java/com/github/kostyasha/it/tests/SimpleBuildTest.java b/yet-another-docker-its/src/test/java/com/github/kostyasha/it/tests/SimpleBuildTest.java index 73b96780..ca3a6b1a 100644 --- a/yet-another-docker-its/src/test/java/com/github/kostyasha/it/tests/SimpleBuildTest.java +++ b/yet-another-docker-its/src/test/java/com/github/kostyasha/it/tests/SimpleBuildTest.java @@ -10,8 +10,11 @@ import com.github.kostyasha.yad.DockerConnector.DescriptorImpl; import com.github.kostyasha.yad.DockerContainerLifecycle; import com.github.kostyasha.yad.DockerSlaveTemplate; +import com.github.kostyasha.yad.commons.DockerCreateContainer; +import com.github.kostyasha.yad.commons.DockerLogConfig; import com.github.kostyasha.yad.commons.DockerPullImage; import com.github.kostyasha.yad.commons.DockerRemoveContainer; +import com.github.kostyasha.yad.docker_java.com.github.dockerjava.api.model.LogConfig; import com.github.kostyasha.yad.launcher.DockerComputerJNLPLauncher; import com.github.kostyasha.yad.other.ConnectorType; import com.github.kostyasha.yad.strategy.DockerOnceRetentionStrategy; @@ -49,6 +52,7 @@ import static com.github.kostyasha.it.utils.JenkinsRuleHelpers.waitUntilNoActivityUpTo; import static com.github.kostyasha.yad.DockerConnector.DEFAULT_API_VERSION; import static com.github.kostyasha.yad.commons.DockerImagePullStrategy.PULL_LATEST; +import static com.github.kostyasha.yad.docker_java.com.github.dockerjava.api.model.LogConfig.LoggingType.JSON_FILE; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.notNullValue; @@ -165,6 +169,12 @@ public Boolean call() throws Throwable { final DockerPullImage pullImage = new DockerPullImage(); pullImage.setPullStrategy(PULL_LATEST); + // create + final DockerCreateContainer createContainer = new DockerCreateContainer(); + final DockerLogConfig logConfig = new DockerLogConfig(); + logConfig.setLoggingType(JSON_FILE); + createContainer.setLogConfig(logConfig); + //remove final DockerRemoveContainer removeContainer = new DockerRemoveContainer(); removeContainer.setRemoveVolumes(true); @@ -172,6 +182,7 @@ public Boolean call() throws Throwable { //lifecycle final DockerContainerLifecycle containerLifecycle = new DockerContainerLifecycle(); + containerLifecycle.setCreateContainer(createContainer); containerLifecycle.setImage(slaveImage); containerLifecycle.setPullImage(pullImage); containerLifecycle.setRemoveContainer(removeContainer); diff --git a/yet-another-docker-plugin/src/main/java/com/github/kostyasha/yad/commons/DockerCreateContainer.java b/yet-another-docker-plugin/src/main/java/com/github/kostyasha/yad/commons/DockerCreateContainer.java index 59c01dfe..b6dbc125 100644 --- a/yet-another-docker-plugin/src/main/java/com/github/kostyasha/yad/commons/DockerCreateContainer.java +++ b/yet-another-docker-plugin/src/main/java/com/github/kostyasha/yad/commons/DockerCreateContainer.java @@ -49,6 +49,7 @@ import static com.github.kostyasha.yad.utils.BindUtils.joinToStr; import static com.github.kostyasha.yad.utils.BindUtils.splitAndFilterEmpty; import static java.util.Objects.isNull; +import static java.util.Objects.nonNull; import static org.apache.commons.lang.StringUtils.trimToNull; import static org.apache.commons.lang.builder.ToStringStyle.SHORT_PREFIX_STYLE; @@ -123,6 +124,9 @@ public class DockerCreateContainer extends AbstractDescribableImpl { + private static final Logger LOG = LoggerFactory.getLogger(DockerLogConfig.class); + + @CheckForNull + private LoggingType loggingType = null; + + @CheckForNull + private Map config = null; + + @DataBoundConstructor + public DockerLogConfig() { + } + + + @CheckForNull + public LogConfig.LoggingType getLoggingType() { + return loggingType; + } + + @DataBoundSetter + public void setLoggingType(LoggingType loggingType) { + this.loggingType = loggingType; + } + + @CheckForNull + public Map getConfig() { + return config; + } + + @DataBoundSetter + public void setConfig(Map config) { + this.config = config; + } + + @CheckForNull + public LogConfig getLogConfig() { + return new LogConfig(getLoggingType(), getConfig()); + } + + + @Override + public String toString() { + return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE); + } + + @Override + public boolean equals(Object o) { + return EqualsBuilder.reflectionEquals(this, o); + } + + @Override + public int hashCode() { + return HashCodeBuilder.reflectionHashCode(this); + } + + @Extension + public static class DescriptorImpl extends Descriptor { + + @Override + public String getDisplayName() { + return "Create Container Log Config"; + } + } +} diff --git a/yet-another-docker-plugin/src/main/resources/com/github/kostyasha/yad/commons/DockerCreateContainer/config.groovy b/yet-another-docker-plugin/src/main/resources/com/github/kostyasha/yad/commons/DockerCreateContainer/config.groovy index 49ee8404..670f721f 100644 --- a/yet-another-docker-plugin/src/main/resources/com/github/kostyasha/yad/commons/DockerCreateContainer/config.groovy +++ b/yet-another-docker-plugin/src/main/resources/com/github/kostyasha/yad/commons/DockerCreateContainer/config.groovy @@ -82,4 +82,5 @@ f.advanced(title: _("Container settings"), align: "left") { f.textbox() } + f.property(field: "logConfig") } diff --git a/yet-another-docker-plugin/src/main/resources/com/github/kostyasha/yad/commons/DockerLogConfig/config.groovy b/yet-another-docker-plugin/src/main/resources/com/github/kostyasha/yad/commons/DockerLogConfig/config.groovy new file mode 100644 index 00000000..a145bf03 --- /dev/null +++ b/yet-another-docker-plugin/src/main/resources/com/github/kostyasha/yad/commons/DockerLogConfig/config.groovy @@ -0,0 +1,18 @@ +package com.github.kostyasha.yad.commons.DockerLogConfig + +import lib.FormTagLib + +def f = namespace(FormTagLib); + + +f.entry(title: _("Logging Type"), field: "loggingType") { + f.enum() { + text(my.name()) + } +} + +// No good UI for binding. +// +//f.entry(title: _("Logging Config"), field: "configStr") { +// f.expandableTextbox() +//} diff --git a/yet-another-docker-plugin/src/main/resources/com/github/kostyasha/yad/commons/DockerLogConfig/help-loggingType.html b/yet-another-docker-plugin/src/main/resources/com/github/kostyasha/yad/commons/DockerLogConfig/help-loggingType.html new file mode 100644 index 00000000..b924a94f --- /dev/null +++ b/yet-another-docker-plugin/src/main/resources/com/github/kostyasha/yad/commons/DockerLogConfig/help-loggingType.html @@ -0,0 +1,2 @@ +See Docker Engine Logging Overview +DEFAULT is "json-file". From 7b9d621728a88ec9e6b1cccdacb3945292c49f2d Mon Sep 17 00:00:00 2001 From: Kanstantsin Shautsou Date: Sun, 14 Aug 2016 17:42:44 +0300 Subject: [PATCH 2/2] Set default log --- .../java/com/github/kostyasha/yad/commons/DockerLogConfig.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yet-another-docker-plugin/src/main/java/com/github/kostyasha/yad/commons/DockerLogConfig.java b/yet-another-docker-plugin/src/main/java/com/github/kostyasha/yad/commons/DockerLogConfig.java index 48ff0bdc..f24628ee 100644 --- a/yet-another-docker-plugin/src/main/java/com/github/kostyasha/yad/commons/DockerLogConfig.java +++ b/yet-another-docker-plugin/src/main/java/com/github/kostyasha/yad/commons/DockerLogConfig.java @@ -24,7 +24,7 @@ public class DockerLogConfig extends AbstractDescribableImpl { private static final Logger LOG = LoggerFactory.getLogger(DockerLogConfig.class); @CheckForNull - private LoggingType loggingType = null; + private LoggingType loggingType = LoggingType.DEFAULT; @CheckForNull private Map config = null;