CORDA-1953 Display error when unable to open connection to Docker (#4136)

* Display error when unable to open connection to Docker

* review comments
This commit is contained in:
Stefano Franz 2018-10-30 17:14:47 +00:00 committed by GitHub
parent e064800173
commit ab1deaac99
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 55 additions and 25 deletions

View File

@ -1,5 +1,7 @@
package net.corda.bootstrapper;
import javafx.application.Platform;
import javafx.embed.swing.JFXPanel;
import javafx.scene.control.Alert;
import javafx.scene.control.Label;
import javafx.scene.control.TextArea;
@ -9,6 +11,7 @@ import javafx.stage.StageStyle;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.concurrent.CountDownLatch;
public class GuiUtils {
@ -18,31 +21,40 @@ public class GuiUtils {
alert.setTitle("Exception");
alert.setHeaderText(title);
alert.setContentText(message);
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
exception.printStackTrace(pw);
String exceptionText = sw.toString();
Label label = new Label("Details:");
TextArea textArea = new TextArea(exceptionText);
textArea.setEditable(false);
textArea.setWrapText(true);
textArea.setMaxWidth(Double.MAX_VALUE);
textArea.setMaxHeight(Double.MAX_VALUE);
GridPane.setVgrow(textArea, Priority.ALWAYS);
GridPane.setHgrow(textArea, Priority.ALWAYS);
GridPane expContent = new GridPane();
expContent.setMaxWidth(Double.MAX_VALUE);
expContent.add(label, 0, 0);
expContent.add(textArea, 0, 1);
alert.getDialogPane().setExpandableContent(expContent);
if (exception != null) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
exception.printStackTrace(pw);
String exceptionText = sw.toString();
TextArea textArea = new TextArea(exceptionText);
textArea.setEditable(false);
textArea.setWrapText(true);
textArea.setMaxWidth(Double.MAX_VALUE);
textArea.setMaxHeight(Double.MAX_VALUE);
Label label = new Label("Details:");
GridPane.setVgrow(textArea, Priority.ALWAYS);
GridPane.setHgrow(textArea, Priority.ALWAYS);
GridPane expContent = new GridPane();
expContent.setMaxWidth(Double.MAX_VALUE);
expContent.add(label, 0, 0);
expContent.add(textArea, 0, 1);
alert.getDialogPane().setExpandableContent(expContent);
}
alert.showAndWait();
}
public static void showAndQuit(String title, String message, Throwable exception) {
CountDownLatch countDownLatch = new CountDownLatch(1);
new JFXPanel();
Platform.runLater(() -> {
showException(title, message, exception);
countDownLatch.countDown();
System.exit(1);
});
try {
countDownLatch.await();
} catch (InterruptedException e) {
}
}
}

View File

@ -1,4 +1,5 @@
@file:JvmName("Main")
package net.corda.bootstrapper
import javafx.application.Application
@ -7,15 +8,19 @@ import net.corda.bootstrapper.backends.Backend.BackendType.AZURE
import net.corda.bootstrapper.cli.AzureParser
import net.corda.bootstrapper.cli.CliParser
import net.corda.bootstrapper.cli.CommandLineInterface
import net.corda.bootstrapper.docker.DockerUtils
import net.corda.bootstrapper.gui.Gui
import net.corda.bootstrapper.serialization.SerializationEngine
import picocli.CommandLine
import javax.ws.rs.ProcessingException
import kotlin.system.exitProcess
val baseArgs = CliParser()
fun main(args: Array<String>) {
SerializationEngine.init()
CommandLine(baseArgs).parse(*args)
testDockerConnectivity()
if (baseArgs.gui) {
Application.launch(Gui::class.java)
@ -32,3 +37,16 @@ fun main(args: Array<String>) {
}
CommandLineInterface().run(argParser)
}
private fun testDockerConnectivity() {
try {
DockerUtils.createLocalDockerClient().listImagesCmd().exec()
} catch (se: ProcessingException) {
if (baseArgs.gui) {
GuiUtils.showAndQuit("Could not connect to Docker", "Please ensure that docker is running locally", null)
} else {
System.err.println("Could not connect to Docker, please ensure that docker is running locally")
exitProcess(1)
}
}
}

View File

@ -1,7 +1,7 @@
package net.corda.bootstrapper.gui
import javafx.stage.Stage
import tornadofx.*
import tornadofx.App
class Gui : App(BootstrapperView::class) {
override fun start(stage: Stage) {