Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXavier Coulon2015-06-01 12:39:38 +0000
committerRoland Grunberg2015-09-03 14:52:48 +0000
commit05adcd885f2a59d20ed5b5f0175c5cf4c1fe1ad9 (patch)
treec01c7a195bdb2379b9862e43785d6e64c20a0fb4 /containers/org.eclipse.linuxtools.docker.core/src/org/eclipse
parent79fab9b365f02809299565c35b1f6b098e7bb265 (diff)
downloadorg.eclipse.linuxtools-05adcd885f2a59d20ed5b5f0175c5cf4c1fe1ad9.tar.gz
org.eclipse.linuxtools-05adcd885f2a59d20ed5b5f0175c5cf4c1fe1ad9.tar.xz
org.eclipse.linuxtools-05adcd885f2a59d20ed5b5f0175c5cf4c1fe1ad9.zip
Bug 468966 - New Connection Wizard fails when no settings are detected
Refactored the wizard page to use Databinding and to validate connection settings input: - the unix socket exists and is readable/writable - the TCP connection scheme is "tcp", "http" or "https" - the TCP connection host and port are valid - the path to certificates exists and is readable (those values are validated according to the connection mode) - automatically insert a "unix://" prefix (scheme) in the "Unix Socket" field when the user selects a file from the FileDialog Change-Id: I193461394f906119f00125ba982aedd942ebd1b8 Signed-off-by: Xavier Coulon <xcoulon@redhat.com> Reviewed-on: https://git.eclipse.org/r/49107 Tested-by: Hudson CI Reviewed-by: Roland Grunberg <rgrunber@redhat.com> Tested-by: Roland Grunberg <rgrunber@redhat.com>
Diffstat (limited to 'containers/org.eclipse.linuxtools.docker.core/src/org/eclipse')
-rw-r--r--containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerConnection.java68
1 files changed, 45 insertions, 23 deletions
diff --git a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerConnection.java b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerConnection.java
index 6881537ce7..4454a2a3ba 100644
--- a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerConnection.java
+++ b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerConnection.java
@@ -19,6 +19,7 @@ import static org.eclipse.linuxtools.docker.core.EnumDockerConnectionSettings.UN
import static org.eclipse.linuxtools.docker.core.EnumDockerConnectionSettings.UNIX_SOCKET_PATH;
import java.io.BufferedReader;
+import java.io.Closeable;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
@@ -40,9 +41,6 @@ import java.util.Map.Entry;
import java.util.Properties;
import java.util.Set;
-import jnr.unixsocket.UnixSocketAddress;
-import jnr.unixsocket.UnixSocketChannel;
-
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.ListenerList;
@@ -102,39 +100,55 @@ import com.spotify.docker.client.messages.Info;
import com.spotify.docker.client.messages.PortBinding;
import com.spotify.docker.client.messages.Version;
+import jnr.unixsocket.UnixSocketAddress;
+import jnr.unixsocket.UnixSocketChannel;
+
/**
* A connection to a Docker daemon. The connection may rely on Unix Socket or TCP connection (using the REST API).
* All low-level communication is delegated to a wrapped {@link DockerClient}.
*
*
*/
-public class DockerConnection implements IDockerConnection {
+public class DockerConnection implements IDockerConnection, Closeable {
public static class Defaults {
public static final String DEFAULT_UNIX_SOCKET_PATH = "unix:///var/run/docker.sock"; //$NON-NLS-1$
- private String name = Messages.Default_Name;
+ private boolean settingsResolved;
+ private String name = null;
private final Map<EnumDockerConnectionSettings, Object> settings = new HashMap<>();
- public Defaults() throws DockerException {
- // first, looking for a Unix socket at /var/run/docker.sock
- if (defaultsWithUnixSocket() || defaultsWithSystemEnv()
- || defaultWithShellEnv()) {
- // attempt to connect and retrieve the 'name' from the system
- // info
- final DockerConnection connection = new Builder()
- .unixSocket(getUnixSocketPath()).tcpHost(getTcpHost())
- .tcpCertPath(getTcpCertPath()).build();
- connection.open(false);
- final IDockerConnectionInfo info = connection.getInfo();
- if (info != null) {
- this.name = info.getName();
+ public Defaults() {
+ try {
+ // first, looking for a Unix socket at /var/run/docker.sock
+ if (defaultsWithUnixSocket() || defaultsWithSystemEnv()
+ || defaultWithShellEnv()) {
+ this.settingsResolved = true;
+ // attempt to connect and retrieve the 'name' from the system
+ // info
+ try(final DockerConnection connection = new Builder()
+ .unixSocket(getUnixSocketPath()).tcpHost(getTcpHost())
+ .tcpCertPath(getTcpCertPath()).build()) {
+ connection.open(false);
+ final IDockerConnectionInfo info = connection.getInfo();
+ if (info != null) {
+ this.name = info.getName();
+ }
+ } catch (DockerException e) {
+ // force custom settings in that case
+ this.settingsResolved = false;
+ }
+ } else {
+ this.settingsResolved = false;
+ Activator.log(
+ new Status(IStatus.WARNING, Activator.PLUGIN_ID,
+ Messages.Missing_Default_Settings));
}
- return;
- }
- Activator.log(new Status(IStatus.WARNING, Activator.PLUGIN_ID,
- Messages.Missing_Default_Settings));
+ } catch (DockerException e) {
+ Activator.log(new Status(IStatus.ERROR, Activator.PLUGIN_ID,
+ Messages.Missing_Default_Settings, e));
+ }
}
/**
@@ -349,6 +363,10 @@ public class DockerConnection implements IDockerConnection {
return res.length() > 0 ? res.substring(1) : "";
}
+ public boolean isSettingsResolved() {
+ return settingsResolved;
+ }
+
public String getName() {
return name;
}
@@ -575,7 +593,11 @@ public class DockerConnection implements IDockerConnection {
@Override
public void ping() throws DockerException {
try {
- client.ping();
+ if (client != null) {
+ client.ping();
+ } else {
+ throw new DockerException(Messages.Docker_Daemon_Ping_Failure);
+ }
} catch (com.spotify.docker.client.DockerException
| InterruptedException e) {
throw new DockerException(Messages.Docker_Daemon_Ping_Failure, e);

Back to the top