Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeff Johnston2016-08-27 01:56:39 +0000
committerJeff Johnston2016-08-31 00:41:38 +0000
commit321666f3fbd3cc044b213eb91743b2e23b41542c (patch)
tree0b548243dd7c3c9bc3ef3a609986ca4efa8bf9f2
parentf88e7ed7dc57124bf3131ee6c37147c159b51b2a (diff)
downloadorg.eclipse.linuxtools-321666f3fbd3cc044b213eb91743b2e23b41542c.tar.gz
org.eclipse.linuxtools-321666f3fbd3cc044b213eb91743b2e23b41542c.tar.xz
org.eclipse.linuxtools-321666f3fbd3cc044b213eb91743b2e23b41542c.zip
Bug 499607 - Add restart option to container context menu
- add new restartContainer method that accepts an output stream for logging purposes to DockerConnection - add new RestartContainersCommandHandler class to do a restart - add new restart wait time preference to Docker preference page - add restart to context menus for Docker Explorer view, Docker Containers view, and Docker Hierarchy view - add new tests to Docker Explorer and Docker Containers SWTBot tests Change-Id: I0409666f9cf7b126b97115c68eec938f41b33210 Reviewed-on: https://git.eclipse.org/r/79891 Tested-by: Hudson CI Reviewed-by: Jeff Johnston <jjohnstn@redhat.com>
-rw-r--r--containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerConnection.java40
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/MockContainerFactory.java23
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/MockStatusProvider.java29
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerContainersViewSWTBotTest.java28
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerExplorerViewSWTBotTest.java7
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/plugin.properties3
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/plugin.xml77
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/RestartContainersCommandHandler.java78
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/preferences/DockerPreferencePage.java31
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/preferences/PreferenceConstants.java1
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/preferences/PreferenceInitializer.java2
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/preferences/PreferenceMessages.properties2
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/DVMessages.properties4
13 files changed, 306 insertions, 19 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 e33d0ac596..796a849799 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
@@ -1706,18 +1706,44 @@ public class DockerConnection
@Override
public void restartContainer(String id, int secondsToWait)
throws DockerException, InterruptedException {
- DockerClient copyClient = getClientCopy();
+ restartContainer(id, secondsToWait, null);
+ }
+
+ public void restartContainer(final String id, int secondsToWait,
+ final OutputStream stream)
+ throws DockerException, InterruptedException {
try {
- // restart container with host config
- copyClient.restartContainer(id, secondsToWait);
+ // restart container
+ client.restartContainer(id, secondsToWait);
+ // Log the started container if a stream is provided
+ final IDockerContainerInfo containerInfo = getContainerInfo(id);
+ if (stream != null && containerInfo != null
+ && containerInfo.config() != null
+ && !containerInfo.config().tty()) {
+ // display logs for container
+ synchronized (loggingThreads) {
+ LogThread t = loggingThreads.get(id);
+ if (t == null || !t.isAlive()) {
+ t = new LogThread(id, getClientCopy(), true);
+ loggingThreads.put(id, t);
+ t.setOutputStream(stream);
+ t.start();
+ }
+ }
+ }
+ // list of containers needs to be refreshed once the container
+ // started, to reflect it new state.
+ listContainers();
+ } catch (ContainerNotFoundException e) {
+ throw new DockerContainerNotFoundException(e);
+ } catch (com.spotify.docker.client.DockerRequestException e) {
+ throw new DockerException(e.message());
} catch (com.spotify.docker.client.DockerException e) {
- throw new DockerException(e);
- } finally {
- if (copyClient != null)
- copyClient.close();
+ throw new DockerException(e.getMessage(), e.getCause());
}
}
+
@Override
public void commitContainer(final String id, final String repo, final String tag,
final String comment, final String author) throws DockerException {
diff --git a/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/MockContainerFactory.java b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/MockContainerFactory.java
index 24fee81816..07883d2813 100644
--- a/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/MockContainerFactory.java
+++ b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/MockContainerFactory.java
@@ -29,7 +29,7 @@ import com.spotify.docker.client.messages.Container;
* A factory for mock {@link Container}s.
*/
public class MockContainerFactory {
-
+
public static Builder id(final String id) {
return new Builder().id(id);
}
@@ -39,11 +39,13 @@ public class MockContainerFactory {
}
public static class Builder {
-
+
private static char[] hexa = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
-
+
+ private static int statusIndex;
+
private final Container container;
-
+
private Builder() {
this.container = Mockito.mock(Container.class);
}
@@ -52,7 +54,7 @@ public class MockContainerFactory {
Mockito.when(this.container.id()).thenReturn(id);
return this;
}
-
+
private Builder randomId() {
// generate a random id for the container
final String id = IntStream.range(0, 12)
@@ -61,7 +63,7 @@ public class MockContainerFactory {
Mockito.when(this.container.id()).thenReturn(id);
return this;
}
-
+
public Builder name(final String name, final String... otherNames) {
final List<String> repoTags = new ArrayList<>();
repoTags.add(name);
@@ -76,12 +78,17 @@ public class MockContainerFactory {
Mockito.when(this.container.image()).thenReturn(imageId);
return this;
}
-
+
public Builder status(final String status) {
Mockito.when(this.container.status()).thenReturn(status);
return this;
}
-
+
+ public Builder statusProvider(final MockStatusProvider statusProvider) {
+ Mockito.when(this.container.status()).thenReturn(statusProvider.getStatus());
+ return this;
+ }
+
public Container build() {
return container;
}
diff --git a/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/MockStatusProvider.java b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/MockStatusProvider.java
new file mode 100644
index 0000000000..39786bdf73
--- /dev/null
+++ b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/MockStatusProvider.java
@@ -0,0 +1,29 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Red Hat.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat - Initial Contribution
+ *******************************************************************************/
+package org.eclipse.linuxtools.internal.docker.ui.testutils;
+
+public class MockStatusProvider {
+
+ private String status;
+
+ public MockStatusProvider(String status) {
+ this.status = status;
+ }
+
+ String getStatus() {
+ return status;
+ }
+
+ void setStatus(String status) {
+ this.status = status;
+ }
+
+}
diff --git a/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerContainersViewSWTBotTest.java b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerContainersViewSWTBotTest.java
index 081096d37c..72262998cc 100644
--- a/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerContainersViewSWTBotTest.java
+++ b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerContainersViewSWTBotTest.java
@@ -25,11 +25,14 @@ import org.eclipse.linuxtools.internal.docker.ui.testutils.swt.ClearConnectionMa
import org.eclipse.linuxtools.internal.docker.ui.testutils.swt.CloseWelcomePageRule;
import org.eclipse.linuxtools.internal.docker.ui.testutils.swt.DockerConnectionManagerUtils;
import org.eclipse.linuxtools.internal.docker.ui.testutils.swt.DockerImageHierarchyViewAssertion;
+import org.eclipse.linuxtools.internal.docker.ui.testutils.swt.MenuAssertion;
import org.eclipse.linuxtools.internal.docker.ui.testutils.swt.SWTUtils;
import org.eclipse.linuxtools.internal.docker.ui.testutils.swt.TestLoggerRule;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotMenu;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotTable;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTableItem;
import org.eclipse.ui.PlatformUI;
import org.junit.Assert;
@@ -90,6 +93,12 @@ public class DockerContainersViewSWTBotTest {
return tableItem.click().select();
}
+ private void selectContainersInTable(final String... items) {
+ final SWTBotTable table = dockerContainersViewBot.bot().table();
+ assertThat(table).isNotNull();
+ table.select(items);
+ }
+
@Test
public void defaultContainersTest() {
// default connection with 1 image should be displayed
@@ -156,4 +165,23 @@ public class DockerContainersViewSWTBotTest {
.isNotNull();
}
+ @Test
+ public void shouldProvideEnabledRestartOnMultipleContainers() {
+ // given
+ final DockerClient client = MockDockerClientFactory
+ .container(MockContainerFactory.name("gentle_foo").status("Running").build())
+ .container(MockContainerFactory.name("bold_eagle").status("Stopped").build())
+ .container(MockContainerFactory.name("angry_bar").status("Running").build()).build();
+ final DockerConnection dockerConnection = MockDockerConnectionFactory.from("Test", client)
+ .withDefaultTCPConnectionSettings();
+ DockerConnectionManagerUtils.configureConnectionManager(dockerConnection);
+ // make sure the hierarchy view is closed.
+ SWTUtils.closeView(this.bot, DockerImageHierarchyView.VIEW_ID);
+ // open the context menu on one of the containers
+ selectContainersInTable("gentle_foo", "bold_eagle", "angry_bar");
+ final SWTBotMenu menuCommand = dockerContainersViewBot.bot().table().contextMenu("Restart");
+ // then
+ MenuAssertion.assertThat(menuCommand).isVisible().isEnabled();
+ }
+
}
diff --git a/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerExplorerViewSWTBotTest.java b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerExplorerViewSWTBotTest.java
index 540766d838..c3ebf626e4 100644
--- a/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerExplorerViewSWTBotTest.java
+++ b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerExplorerViewSWTBotTest.java
@@ -330,17 +330,18 @@ public class DockerExplorerViewSWTBotTest {
}
@Test
- public void shouldProvideEnabledStopCommandOnMultipleContainersAtOnce() {
+ public void shouldProvideEnabledRestartCommandOnMultipleContainersAtOnce() {
// given
final DockerClient client = MockDockerClientFactory
.container(MockContainerFactory.name("gentle_foo").status("Running").build())
+ .container(MockContainerFactory.name("bold_eagle").status("Stopped").build())
.container(MockContainerFactory.name("angry_bar").status("Running").build()).build();
final DockerConnection dockerConnection = MockDockerConnectionFactory.from("Test", client)
.withDefaultTCPConnectionSettings();
DockerConnectionManagerUtils.configureConnectionManager(dockerConnection);
// open the context menu on one of the containers
- selectContainersInTreeView("Test", "gentle_foo", "angry_bar");
- final SWTBotMenu menuCommand = dockerExplorerViewBot.bot().tree().contextMenu("Stop");
+ selectContainersInTreeView("Test", "gentle_foo", "bold_eagle", "angry_bar");
+ final SWTBotMenu menuCommand = dockerExplorerViewBot.bot().tree().contextMenu("Restart");
// then
MenuAssertion.assertThat(menuCommand).isVisible().isEnabled();
}
diff --git a/containers/org.eclipse.linuxtools.docker.ui/plugin.properties b/containers/org.eclipse.linuxtools.docker.ui/plugin.properties
index 7ba98c9f27..21a9461cda 100644
--- a/containers/org.eclipse.linuxtools.docker.ui/plugin.properties
+++ b/containers/org.eclipse.linuxtools.docker.ui/plugin.properties
@@ -48,6 +48,9 @@ command.refreshcontainers.description=Refresh the list of containers
command.startcontainers.name=&Start
command.startcontainers.description=Start the selected containers
+command.restartcontainers.name=Res&tart
+command.restartcontainers.description=Restart selected containers
+
command.pausecontainers.name=&Pause
command.pausecontainers.description=Pause the selected containers
diff --git a/containers/org.eclipse.linuxtools.docker.ui/plugin.xml b/containers/org.eclipse.linuxtools.docker.ui/plugin.xml
index a9dfe60839..ab92d943cd 100644
--- a/containers/org.eclipse.linuxtools.docker.ui/plugin.xml
+++ b/containers/org.eclipse.linuxtools.docker.ui/plugin.xml
@@ -250,6 +250,11 @@
name="%command.killcontainers.name">
</command>
<command
+ description="%command.restartcontainers.description"
+ id="org.eclipse.linuxtools.docker.ui.commands.restartContainers"
+ name="%command.restartcontainers.name">
+ </command>
+ <command
description="%command.removecontainers.description"
id="org.eclipse.linuxtools.docker.ui.commands.removeContainers"
name="%command.removecontainers.name">
@@ -553,6 +558,24 @@
</enabledWhen>
</handler>
<handler
+ commandId="org.eclipse.linuxtools.docker.ui.commands.restartContainers"
+ class="org.eclipse.linuxtools.internal.docker.ui.commands.RestartContainersCommandHandler">
+ <enabledWhen>
+ <with variable="selection">
+ <iterate
+ ifEmpty="false"
+ operator="or">
+ <or>
+ <instanceof
+ value="org.eclipse.linuxtools.docker.core.IDockerContainer" />
+ <adapt
+ type="org.eclipse.linuxtools.docker.core.IDockerContainer" />
+ </or>
+ </iterate>
+ </with>
+ </enabledWhen>
+ </handler>
+ <handler
commandId="org.eclipse.linuxtools.docker.ui.commands.removeContainers"
class="org.eclipse.linuxtools.internal.docker.ui.commands.RemoveContainersCommandHandler">
<enabledWhen>
@@ -1096,6 +1119,28 @@
</visibleWhen>
</command>
</menuContribution>
+ <!-- explorer view context menu: restart containers -->
+ <menuContribution
+ locationURI="popup:org.eclipse.linuxtools.docker.ui.dockerExplorerView#PopupMenu?after=org.eclipse.linuxtools.docker.ui.commands.stopContainers">
+ <command
+ commandId="org.eclipse.linuxtools.docker.ui.commands.restartContainers"
+ icon="icons/restart.gif"
+ id="org.eclipse.linuxtools.docker.ui.commands.restartContainers"
+ style="push">
+ <visibleWhen
+ checkEnabled="false">
+ <with
+ variable="selection">
+ <iterate
+ ifEmpty="false"
+ operator="and">
+ <instanceof
+ value="org.eclipse.linuxtools.docker.core.IDockerContainer" />
+ </iterate>
+ </with>
+ </visibleWhen>
+ </command>
+ </menuContribution>
<!-- explorer view context menu: kill containers -->
<menuContribution
locationURI="popup:org.eclipse.linuxtools.docker.ui.dockerExplorerView#PopupMenu?after=org.eclipse.linuxtools.docker.ui.commands.stopContainers">
@@ -1524,6 +1569,15 @@
style="push">
</command>
</menuContribution>
+ <!-- containers view context menu: restart container -->
+ <menuContribution
+ locationURI="popup:org.eclipse.linuxtools.docker.ui.dockerContainersView">
+ <command
+ commandId="org.eclipse.linuxtools.docker.ui.commands.restartContainers"
+ id="org.eclipse.linuxtools.docker.ui.commands.restartContainers"
+ style="push">
+ </command>
+ </menuContribution>
<!-- containers view context menu: display container log -->
<menuContribution
locationURI="popup:org.eclipse.linuxtools.docker.ui.dockerContainersView">
@@ -1964,9 +2018,30 @@
</visibleWhen>
</command>
</menuContribution>
- <!-- hierarchy view context menu: kill containers -->
+ <!-- hierarchy view context menu: restart containers -->
<menuContribution
locationURI="popup:org.eclipse.linuxtools.docker.ui.dockerImageHierarchyView#PopupMenu?after=org.eclipse.linuxtools.docker.ui.commands.stopContainers">
+ <command
+ commandId="org.eclipse.linuxtools.docker.ui.commands.restartContainers"
+ icon="icons/restart.gif"
+ id="org.eclipse.linuxtools.docker.ui.commands.restartContainers"
+ style="push">
+ <visibleWhen
+ checkEnabled="false">
+ <with
+ variable="selection">
+ <iterate
+ ifEmpty="false"
+ operator="and">
+ <adapt type="org.eclipse.linuxtools.docker.core.IDockerContainer" />
+ </iterate>
+ </with>
+ </visibleWhen>
+ </command>
+ </menuContribution>
+ <!-- hierarchy view context menu: kill containers -->
+ <menuContribution
+ locationURI="popup:org.eclipse.linuxtools.docker.ui.dockerImageHierarchyView#PopupMenu?after=org.eclipse.linuxtools.docker.ui.commands.restartContainers">
<command
commandId="org.eclipse.linuxtools.docker.ui.commands.killContainers"
icon="icons/kill.gif"
diff --git a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/RestartContainersCommandHandler.java b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/RestartContainersCommandHandler.java
new file mode 100644
index 0000000000..bcc0da3409
--- /dev/null
+++ b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/RestartContainersCommandHandler.java
@@ -0,0 +1,78 @@
+/*******************************************************************************
+ * Copyright (c) 2014, 2015 Red Hat.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat - Initial Contribution
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.internal.docker.ui.commands;
+
+import static org.eclipse.linuxtools.internal.docker.ui.commands.CommandUtils.getRunConsole;
+
+import java.util.List;
+
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.linuxtools.docker.core.DockerException;
+import org.eclipse.linuxtools.docker.core.IDockerConnection;
+import org.eclipse.linuxtools.docker.core.IDockerContainer;
+import org.eclipse.linuxtools.internal.docker.core.DockerConnection;
+import org.eclipse.linuxtools.internal.docker.ui.consoles.RunConsole;
+import org.eclipse.linuxtools.internal.docker.ui.preferences.PreferenceConstants;
+import org.eclipse.linuxtools.internal.docker.ui.views.DVMessages;
+
+/**
+ * Command handler to stop all the selected {@link IDockerContainer}
+ *
+ * @author xcoulon
+ *
+ */
+public class RestartContainersCommandHandler extends BaseContainersCommandHandler {
+
+ private static final long DEFAULT_WAIT_TIME = 5;
+
+ private static final String CONTAINERS_RESTART_MSG = "ContainersRestart.msg"; //$NON-NLS-1$
+ private static final String CONTAINER_RESTART_MSG = "ContainerRestart.msg"; //$NON-NLS-1$
+ private static final String CONTAINER_RESTART_ERROR_MSG = "ContainerRestartError.msg"; //$NON-NLS-1$
+
+ @Override
+ void executeInJob(final IDockerContainer container, final IDockerConnection connection) {
+ try {
+ final RunConsole console = getRunConsole(connection, container);
+ long waitTime = Platform.getPreferencesService().getLong(
+ "org.eclipse.linuxtools.docker.ui", //$NON-NLS-1$
+ PreferenceConstants.RESTART_WAIT_TIME, DEFAULT_WAIT_TIME,
+ null);
+ if (console != null) {
+ // if we are auto-logging, show the console
+ console.showConsole();
+ // Start the container
+ ((DockerConnection) connection).restartContainer(container.id(),
+ (int) waitTime,
+ console.getOutputStream());
+ } else {
+ ((DockerConnection) connection).restartContainer(container.id(),
+ (int) waitTime,
+ null);
+ }
+ connection.getContainers(true);
+ } catch (DockerException | InterruptedException e) {
+ final String errorMessage = DVMessages.getFormattedString(CONTAINER_RESTART_ERROR_MSG, container.id());
+ openError(errorMessage, e);
+ }
+ }
+
+ @Override
+ String getJobName(final List<IDockerContainer> selectedContainers) {
+ return DVMessages.getString(CONTAINERS_RESTART_MSG);
+ }
+
+ @Override
+ String getTaskName(final IDockerContainer container) {
+ return DVMessages.getFormattedString(CONTAINER_RESTART_MSG,
+ container.name());
+ }
+}
diff --git a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/preferences/DockerPreferencePage.java b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/preferences/DockerPreferencePage.java
index 9ea511eb54..012915cb2c 100644
--- a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/preferences/DockerPreferencePage.java
+++ b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/preferences/DockerPreferencePage.java
@@ -28,10 +28,13 @@ public class DockerPreferencePage extends PreferencePage implements
IWorkbenchPreferencePage {
private static final String REFRESH_TIME_MSG = "RefreshTime.label"; //$NON-NLS-1$
+ private static final String RESTART_WAIT_TIME_MSG = "RestartWaitTime.label"; //$NON-NLS-1$
private static final String INVALID_REFRESH_TIME_MSG = "RefreshTime.invalid.label"; //$NON-NLS-1$
+ private static final String INVALID_RESTART_WAIT_TIME_MSG = "RestartWaitTime.invalid.label"; //$NON-NLS-1$
private IntegerFieldEditor refreshTimeField;
+ private IntegerFieldEditor restartWaitTimeField;
public DockerPreferencePage() {
super();
@@ -49,6 +52,9 @@ public class DockerPreferencePage extends PreferencePage implements
if (this.refreshTimeField != null) {
this.refreshTimeField.store();
}
+ if (this.restartWaitTimeField != null) {
+ this.restartWaitTimeField.store();
+ }
}
@Override
@@ -108,6 +114,31 @@ public class DockerPreferencePage extends PreferencePage implements
setValid(refreshTimeField.isValid());
}
});
+ restartWaitTimeField = new IntegerFieldEditor(
+ PreferenceConstants.RESTART_WAIT_TIME,
+ PreferenceMessages.getString(RESTART_WAIT_TIME_MSG), container);
+ restartWaitTimeField.setPreferenceStore(getPreferenceStore());
+ restartWaitTimeField
+ .setValidateStrategy(StringFieldEditor.VALIDATE_ON_KEY_STROKE);
+ restartWaitTimeField.setValidRange(0, Integer.MAX_VALUE);
+ restartWaitTimeField.setPage(this);
+ restartWaitTimeField.setErrorMessage(
+ PreferenceMessages.getString(INVALID_RESTART_WAIT_TIME_MSG));
+ restartWaitTimeField.showErrorMessage();
+ restartWaitTimeField.load();
+ // If the preference changes, alert the Refresh Manager
+ restartWaitTimeField.setPropertyChangeListener(event -> {
+ if (event.getSource().equals(restartWaitTimeField)) {
+ if (restartWaitTimeField.isValid()) {
+ DockerContainerRefreshManager.getInstance()
+ .setRefreshTime(restartWaitTimeField.getIntValue());
+ setErrorMessage(null);
+ } else {
+ setErrorMessage(restartWaitTimeField.getErrorMessage());
+ }
+ setValid(restartWaitTimeField.isValid());
+ }
+ });
}
} \ No newline at end of file
diff --git a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/preferences/PreferenceConstants.java b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/preferences/PreferenceConstants.java
index 898f93da9c..6914ecbdde 100644
--- a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/preferences/PreferenceConstants.java
+++ b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/preferences/PreferenceConstants.java
@@ -18,6 +18,7 @@ public class PreferenceConstants {
// Time in seconds to wait before automatically refreshing the Containers
// view (min 5)
public static final String REFRESH_TIME = "containerRefreshTime"; //$NON-NLS-1$
+ public static final String RESTART_WAIT_TIME = "containerRestartWaitTime"; //$NON-NLS-1$
public static final String AUTOLOG_ON_START = "autoLogOnStart"; //$NON-NLS-1$
public static final String LOG_TIMESTAMP = "logTimestamp"; //$NON-NLS-1$
diff --git a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/preferences/PreferenceInitializer.java b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/preferences/PreferenceInitializer.java
index 2552b04375..3fde7e4df5 100644
--- a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/preferences/PreferenceInitializer.java
+++ b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/preferences/PreferenceInitializer.java
@@ -15,6 +15,7 @@ import static org.eclipse.linuxtools.internal.docker.ui.preferences.PreferenceCo
import static org.eclipse.linuxtools.internal.docker.ui.preferences.PreferenceConstants.DOCKER_MACHINE_INSTALLATION_DIRECTORY;
import static org.eclipse.linuxtools.internal.docker.ui.preferences.PreferenceConstants.LOG_TIMESTAMP;
import static org.eclipse.linuxtools.internal.docker.ui.preferences.PreferenceConstants.REFRESH_TIME;
+import static org.eclipse.linuxtools.internal.docker.ui.preferences.PreferenceConstants.RESTART_WAIT_TIME;
import static org.eclipse.linuxtools.internal.docker.ui.preferences.PreferenceConstants.VM_DRIVER_INSTALLATION_DIRECTORY;
import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
@@ -32,6 +33,7 @@ public class PreferenceInitializer extends AbstractPreferenceInitializer {
public void initializeDefaultPreferences() {
final IPreferenceStore store = Activator.getDefault().getPreferenceStore();
store.setDefault(REFRESH_TIME, 15);
+ store.setDefault(RESTART_WAIT_TIME, 10);
store.setDefault(AUTOLOG_ON_START, true);
store.setDefault(LOG_TIMESTAMP, true);
// set docker-machine preferences based on the user's platform
diff --git a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/preferences/PreferenceMessages.properties b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/preferences/PreferenceMessages.properties
index 44b2ad446a..71085a0b4d 100644
--- a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/preferences/PreferenceMessages.properties
+++ b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/preferences/PreferenceMessages.properties
@@ -10,6 +10,8 @@
###############################################################################
RefreshTime.label=Container Refresh Rate (seconds)
RefreshTime.invalid.label=Container refresh rate is invalid
+RestartWaitTime.label=Time to wait before killing a restarted Container (seconds)
+RestartWaitTime.invalid.label=Container restart wait time is invalid
DefaultHost.label=Default Docker Host
AutoLogOnStart.label=Automatically log when Container starts
LogTimeStamp.label=Request time stamp for logs
diff --git a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/DVMessages.properties b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/DVMessages.properties
index 17359a394a..b71d6674b8 100644
--- a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/DVMessages.properties
+++ b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/DVMessages.properties
@@ -105,6 +105,10 @@ ContainersStart.msg=Starting Containers...
ContainerStart.msg=Starting {0}
ContainerStartError.msg=Error occurred while starting {0}
+ContainersRestart.msg=Restarting Containers...
+ContainerRestart.msg=Restarting {0}
+ContainerRestartError.msg=Error occurred while restarting {0}
+
ContainersPause.msg=Pausing Containers...
ContainerPause.msg=Pausing <{0}>
ContainersUnpause.msg=Unpausing Containers...

Back to the top