You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@netbeans.apache.org by ma...@apache.org on 2019/12/07 08:57:51 UTC
[netbeans] branch master updated: Add log message,
so we can find out why docker connection failed.
This is an automated email from the ASF dual-hosted git repository.
matthiasblaesing pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/netbeans.git
The following commit(s) were added to refs/heads/master by this push:
new d5a1a03 Add log message, so we can find out why docker connection failed.
d5a1a03 is described below
commit d5a1a036f6771916a326ec84025d0ad64a51b4a7
Author: Matthias Bläsing <mb...@doppel-helix.eu>
AuthorDate: Thu Oct 24 17:07:46 2019 +0200
Add log message, so we can find out why docker connection failed.
---
.../netbeans/modules/docker/api/DockerAction.java | 34 ++++++++++++----------
.../docker/ui/wizard/DockerConnectionPanel.java | 31 +++++++++++++++++---
2 files changed, 46 insertions(+), 19 deletions(-)
diff --git a/ide/docker.api/src/org/netbeans/modules/docker/api/DockerAction.java b/ide/docker.api/src/org/netbeans/modules/docker/api/DockerAction.java
index f7f340d..1891b79 100644
--- a/ide/docker.api/src/org/netbeans/modules/docker/api/DockerAction.java
+++ b/ide/docker.api/src/org/netbeans/modules/docker/api/DockerAction.java
@@ -1004,26 +1004,30 @@ public class DockerAction {
}
}
- public boolean ping() {
+ public boolean pingWithExceptions() throws Exception {
assert !SwingUtilities.isEventDispatchThread() : "Remote access invoked from EDT";
+ Endpoint s = createEndpoint();
try {
- Endpoint s = createEndpoint();
- try {
- OutputStream os = s.getOutputStream();
- // FIXME should we use default headers ?
- os.write(("GET /_ping HTTP/1.1\r\n"
- + "Host: " + getHostHeader().second() + "\r\n\r\n").getBytes("ISO-8859-1"));
- os.flush();
+ OutputStream os = s.getOutputStream();
+ // FIXME should we use default headers ?
+ os.write(("GET /_ping HTTP/1.1\r\n"
+ + "Host: " + getHostHeader().second() + "\r\n\r\n").getBytes("ISO-8859-1"));
+ os.flush();
- InputStream is = s.getInputStream();
- HttpUtils.Response response = HttpUtils.readResponse(is);
- return response.getCode() == HttpURLConnection.HTTP_OK;
- } finally {
- closeEndpoint(s);
- }
+ InputStream is = s.getInputStream();
+ HttpUtils.Response response = HttpUtils.readResponse(is);
+ return response.getCode() == HttpURLConnection.HTTP_OK;
+ } finally {
+ closeEndpoint(s);
+ }
+ }
+
+ public boolean ping() {
+ try {
+ return pingWithExceptions();
} catch (MalformedURLException ex) {
LOGGER.log(Level.INFO, null, ex);
- } catch (IOException ex) {
+ } catch (Exception ex) {
LOGGER.log(Level.FINE, null, ex);
}
return false;
diff --git a/ide/docker.ui/src/org/netbeans/modules/docker/ui/wizard/DockerConnectionPanel.java b/ide/docker.ui/src/org/netbeans/modules/docker/ui/wizard/DockerConnectionPanel.java
index 16ba728..2ab3295 100644
--- a/ide/docker.ui/src/org/netbeans/modules/docker/ui/wizard/DockerConnectionPanel.java
+++ b/ide/docker.ui/src/org/netbeans/modules/docker/ui/wizard/DockerConnectionPanel.java
@@ -24,6 +24,8 @@ import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;
+import java.util.logging.Level;
+import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.swing.SwingUtilities;
@@ -43,13 +45,18 @@ import org.openide.util.Utilities;
@NbBundle.Messages({
"MSG_ConnectionPassed=Connection successful.",
"MSG_CannotConnect=Cannot establish connection.",
+ "# {0} - detailed error message",
+ "MSG_CannotConnectWithDetails=Cannot establish connection, details: {0}",
"MSG_InaccessibleSocket=Socket is not accessible."
})
public class DockerConnectionPanel implements WizardDescriptor.ExtendedAsynchronousValidatingPanel<WizardDescriptor>, ChangeListener {
+ private static final Logger LOGGER = Logger.getLogger(DockerConnectionPanel.class.getName());
+
private static final Pattern REMOTE_HOST_PATTERN = Pattern.compile("^(tcp://)[^/:](:\\d+)($|/.*)"); // NOI18N
private static final String CONNECTION_TEST = "connection_test";
+ private static final String CONNECTION_EXCEPTION_MSG = "connection_exception_msg";
private final ChangeSupport changeSupport = new ChangeSupport(this);
@@ -102,6 +109,8 @@ public class DockerConnectionPanel implements WizardDescriptor.ExtendedAsynchron
// process the connection test validation
Boolean connectioTest = (Boolean) wizard.getProperty(CONNECTION_TEST);
wizard.putProperty(CONNECTION_TEST, null);
+ String connectionExceptionMessage = (String) wizard.getProperty(CONNECTION_EXCEPTION_MSG);
+ wizard.putProperty(CONNECTION_EXCEPTION_MSG, null);
Configuration panel = component.getConfiguration();
String displayName = panel.getDisplayName();
@@ -185,7 +194,10 @@ public class DockerConnectionPanel implements WizardDescriptor.ExtendedAsynchron
if (connectioTest != null) {
if (connectioTest) {
wizard.putProperty(WizardDescriptor.PROP_INFO_MESSAGE, Bundle.MSG_ConnectionPassed());
+ } else if (connectionExceptionMessage != null) {
+ wizard.putProperty(WizardDescriptor.PROP_ERROR_MESSAGE, connectionExceptionMessage);
} else {
+ //fallback to generic message
wizard.putProperty(WizardDescriptor.PROP_ERROR_MESSAGE, Bundle.MSG_CannotConnect());
}
return connectioTest;
@@ -246,14 +258,24 @@ public class DockerConnectionPanel implements WizardDescriptor.ExtendedAsynchron
}
DockerAction action = new DockerAction(instance);
- if (!action.ping()) {
+ boolean pingResult = false;
+
+ try {
+ pingResult = action.pingWithExceptions();
+ } catch (Exception ex) {
+ LOGGER.log(Level.INFO, "docker connection ping failed", ex); // NOI18N
+ throw new WizardValidationException(component,
+ Bundle.MSG_CannotConnectWithDetails(ex.getMessage()),
+ Bundle.MSG_CannotConnectWithDetails(ex.getLocalizedMessage()));
+ }
+
+ if (!pingResult) {
String error = Bundle.MSG_CannotConnect();
throw new WizardValidationException(component, error, error);
}
// runtime exception may happen
} catch (Exception ex) {
- String error = Bundle.MSG_CannotConnect();
- throw new WizardValidationException(component, error, error);
+ throw new WizardValidationException(component, ex.getMessage(), ex.getLocalizedMessage());
}
}
@@ -346,7 +368,8 @@ public class DockerConnectionPanel implements WizardDescriptor.ExtendedAsynchron
public void run() {
finishValidation();
Exception ex = ref.get();
- if (ex != null) {
+ if (ex != null) {
+ wizard.putProperty(CONNECTION_EXCEPTION_MSG, ex.getLocalizedMessage());
wizard.putProperty(CONNECTION_TEST, false);
} else {
wizard.putProperty(CONNECTION_TEST, true);
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@netbeans.apache.org
For additional commands, e-mail: commits-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists