Skip to content

Commit

Permalink
[FIXED JENKINS-23343] Implement validation button for Docker URL in g…
Browse files Browse the repository at this point in the history
…lobal config
  • Loading branch information
vjuranek committed Jun 7, 2014
1 parent dbf6b27 commit 6205fac
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
Expand Up @@ -12,6 +12,7 @@
import hudson.util.FormValidation;

import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.servlet.ServletException;
Expand All @@ -27,6 +28,7 @@

import com.kpelykh.docker.client.DockerClient;
import com.kpelykh.docker.client.DockerException;
import com.kpelykh.docker.client.model.Info;

/**
* Build step which executes various Docker commands via Docker REST API.
Expand Down Expand Up @@ -96,9 +98,17 @@ public DescriptorImpl() {
}
}

public FormValidation doCheckName(@QueryParameter String dockerURL) throws IOException, ServletException {
// TODO do validation
return FormValidation.ok();
public FormValidation doTestConnection(@QueryParameter String dockerUrl) throws IOException, ServletException {
LOGGER.fine("Trying to get client for " + dockerUrl);
try {
dockerClient = new DockerClient(dockerUrl);
Info info = dockerClient.info(); //TODO replace with _ping once implemented in docker client
} catch (Exception e) {
LOGGER.log(Level.WARNING, e.getMessage(), e);
return FormValidation.error("Something went wrong, cannot connect to " + dockerUrl + ", cause: "
+ e.getCause());
}
return FormValidation.ok("Connected to " + dockerUrl);
}

public boolean isApplicable(@SuppressWarnings("rawtypes") Class<? extends AbstractProject> aClass) {
Expand Down
Expand Up @@ -4,6 +4,7 @@
<f:entry title="Docker URL" field="dockerUrl" description="Docker server REST API URL">
<f:textbox />
</f:entry>
<f:validateButton title="${%Test Connection}" progress="${%Testing...}" method="testConnection" with="dockerUrl" />
</f:section>

</j:jelly>

0 comments on commit 6205fac

Please sign in to comment.