Skip to content

Commit

Permalink
Revert "[FIXED JENKINS-24071] Execute command remotely on slaves, not…
Browse files Browse the repository at this point in the history
… on master (+formating)"

This reverts commit 9f6f42d.
Actually didn't fix the issue (see JENKINS-24071) and potentially makes it even worse.
  • Loading branch information
vjuranek committed Sep 11, 2014
1 parent 44da190 commit 471393e
Showing 1 changed file with 18 additions and 48 deletions.
Expand Up @@ -7,7 +7,6 @@
import hudson.model.BuildListener;
import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.remoting.Callable;
import hudson.tasks.BuildStepDescriptor;
import hudson.tasks.Builder;
import hudson.util.FormValidation;
Expand All @@ -23,6 +22,7 @@
import org.jenkinsci.plugins.dockerbuildstep.cmd.DockerCommand;
import org.jenkinsci.plugins.dockerbuildstep.cmd.DockerCommand.DockerCommandDescriptor;
import org.jenkinsci.plugins.dockerbuildstep.log.ConsoleLogger;
import org.jenkinsci.plugins.dockerbuildstep.util.PortBindingParser;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.StaplerRequest;
Expand Down Expand Up @@ -52,7 +52,7 @@ public DockerCommand getDockerCmd() {

@Override
public boolean perform(@SuppressWarnings("rawtypes") AbstractBuild build, Launcher launcher, BuildListener listener)
throws AbortException, IOException, InterruptedException {
throws AbortException {

ConsoleLogger clog = new ConsoleLogger(listener);

Expand All @@ -63,8 +63,7 @@ public boolean perform(@SuppressWarnings("rawtypes") AbstractBuild build, Launch
}

try {
DockerCmdCallable callable = new DockerCmdCallable(dockerCmd, build, clog);
launcher.getChannel().call(callable);
dockerCmd.execute(build, clog);
} catch (DockerException e) {
clog.logError("command '" + dockerCmd.getDescriptor().getDisplayName() + "' failed: " + e.getMessage());
LOGGER.severe("Failed to execute Docker command " + dockerCmd.getDescriptor().getDisplayName() + ": "
Expand All @@ -79,32 +78,6 @@ public DescriptorImpl getDescriptor() {
return (DescriptorImpl) super.getDescriptor();
}

private static final class DockerCmdCallable implements Callable<Void, DockerException> {

private static final long serialVersionUID = 1L;
private final DockerCommand cmd;
private final AbstractBuild<?, ?> build;
private final ConsoleLogger console;

public DockerCmdCallable(DockerCommand cmd, AbstractBuild<?, ?> build, ConsoleLogger console) {
this.cmd = cmd;
this.build = build;
this.console = console;
}

// @Override
public Void call() throws DockerException {
try {
cmd.execute(build, console);
} catch (AbortException e) {
LOGGER.log(Level.INFO,
String.format("Docker command %s was aborted", cmd.getDescriptor().getDisplayName()),
e.getCause());
}
return null;
}
}

@Extension
public static final class DescriptorImpl extends BuildStepDescriptor<Builder> {

Expand All @@ -121,29 +94,27 @@ public DescriptorImpl() {
}

try {
DockerClientConfigBuilder dcb = new DockerClientConfigBuilder().withUri(dockerUrl).withVersion(
versionOrNull(dockerVersion));
DockerClientConfigBuilder dcb = new DockerClientConfigBuilder().withUri(dockerUrl).withVersion(versionOrNull(dockerVersion));
dockerClient = new DockerClient(dcb.build());
} catch (DockerException e) {
LOGGER.warning("Cannot create Docker client: " + e.getCause());
}
}

/**
* Ensures that version is either <code>null</code> or defined, i.e. holding a non-empty string value.
*/
private static String versionOrNull(String version) {
return version == null || version.isEmpty() ? null : version;
}
/**
* Ensures that version is either <code>null</code> or defined, i.e. holding
* a non-empty string value.
*/
private static String versionOrNull(String version) {
return version == null || version.isEmpty() ? null : version;
}

public FormValidation doTestConnection(@QueryParameter String dockerUrl, @QueryParameter String dockerVersion)
throws IOException, ServletException {
public FormValidation doTestConnection(@QueryParameter String dockerUrl, @QueryParameter String dockerVersion) throws IOException, ServletException {
LOGGER.fine(String.format("Trying to get client for %s and version %s", dockerUrl, dockerVersion));
try {
DockerClientConfigBuilder dcb = new DockerClientConfigBuilder().withUri(dockerUrl).withVersion(
versionOrNull(dockerVersion));
DockerClientConfigBuilder dcb = new DockerClientConfigBuilder().withUri(dockerUrl).withVersion(versionOrNull(dockerVersion));
dockerClient = new DockerClient(dcb.build());
if (dockerClient.execute(dockerClient.pingCmd()) != 200) {
if(dockerClient.execute(dockerClient.pingCmd()) != 200) {
return FormValidation.error("Cannot ping REST endpoint of " + dockerUrl);
}
} catch (Exception e) {
Expand All @@ -168,14 +139,13 @@ public boolean configure(StaplerRequest req, JSONObject formData) throws FormExc
dockerVersion = formData.getString("dockerVersion");
if (dockerUrl == null || dockerUrl.isEmpty()) {
LOGGER.severe("Docker URL is empty, Docker build test plugin cannot work without Docker URL being set up properly");
// JENKINS-23733 doen't block user to save the config if admin decides so
//JENKINS-23733 doen't block user to save the config if admin decides so
return true;
}

save();
try {
DockerClientConfigBuilder dcb = new DockerClientConfigBuilder().withUri(dockerUrl).withVersion(
dockerVersion);
DockerClientConfigBuilder dcb = new DockerClientConfigBuilder().withUri(dockerUrl).withVersion(dockerVersion);
dockerClient = new DockerClient(dcb.build());
} catch (DockerException e) {
LOGGER.warning("Cannot create Docker client: " + e.getCause());
Expand All @@ -186,7 +156,7 @@ public boolean configure(StaplerRequest req, JSONObject formData) throws FormExc
public String getDockerUrl() {
return dockerUrl;
}

public String getDockerVersion() {
return dockerVersion;
}
Expand All @@ -198,7 +168,7 @@ public DockerClient getDockerClient() {
public DescriptorExtensionList<DockerCommand, DockerCommandDescriptor> getCmdDescriptors() {
return DockerCommand.all();
}

}

private static Logger LOGGER = Logger.getLogger(DockerBuilder.class.getName());
Expand Down

0 comments on commit 471393e

Please sign in to comment.