diff --git a/assembly/assembly-wsmaster-war/src/main/webapp/WEB-INF/classes/codenvy/che.properties b/assembly/assembly-wsmaster-war/src/main/webapp/WEB-INF/classes/codenvy/che.properties index e19283888f..e086c85478 100644 --- a/assembly/assembly-wsmaster-war/src/main/webapp/WEB-INF/classes/codenvy/che.properties +++ b/assembly/assembly-wsmaster-war/src/main/webapp/WEB-INF/classes/codenvy/che.properties @@ -255,6 +255,9 @@ che.docker.cleanup_period_min=60 # Version number of the Docker API used within the Che implementation che.docker.api=1.20 +# Whether to enable component that detects failures of a machine caused by unexpected container stop +che.docker.enable_container_stop_detector=true + che.docker.network_driver=NULL che.docker.tcp_connection_timeout_ms=600000 diff --git a/plugins/plugin-docker/che-plugin-docker-machine/src/main/java/org/eclipse/che/plugin/docker/machine/DockerInstanceStopDetector.java b/plugins/plugin-docker/che-plugin-docker-machine/src/main/java/org/eclipse/che/plugin/docker/machine/DockerInstanceStopDetector.java index 8b171fc263..2f54c26813 100644 --- a/plugins/plugin-docker/che-plugin-docker-machine/src/main/java/org/eclipse/che/plugin/docker/machine/DockerInstanceStopDetector.java +++ b/plugins/plugin-docker/che-plugin-docker-machine/src/main/java/org/eclipse/che/plugin/docker/machine/DockerInstanceStopDetector.java @@ -21,6 +21,7 @@ import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; import javax.annotation.PostConstruct; import javax.inject.Inject; +import javax.inject.Named; import javax.inject.Singleton; import org.eclipse.che.api.core.notification.EventService; import org.eclipse.che.api.machine.server.event.InstanceStateEvent; @@ -44,10 +45,11 @@ import org.slf4j.LoggerFactory; public class DockerInstanceStopDetector { private static final Logger LOG = LoggerFactory.getLogger(DockerInstanceStopDetector.class); - private final EventService eventService; - private final DockerConnector dockerConnector; - private final ExecutorService executorService; - private final Map> instances; + private final boolean isEnabled; + private EventService eventService; + private DockerConnector dockerConnector; + private ExecutorService executorService; + private Map> instances; /* Helps differentiate container main process OOM from other processes OOM Algorithm: @@ -60,13 +62,19 @@ public class DockerInstanceStopDetector { That's why cache expires in X seconds. X was set as 10 empirically. */ - private final Cache containersOomTimestamps; + private Cache containersOomTimestamps; private long lastProcessedEventDate = 0; @Inject public DockerInstanceStopDetector( - EventService eventService, DockerConnectorProvider dockerConnectorProvider) { + EventService eventService, + DockerConnectorProvider dockerConnectorProvider, + @Named("che.docker.enable_container_stop_detector") boolean isEnabled) { + this.isEnabled = isEnabled; + if (!isEnabled) { + return; + } this.eventService = eventService; this.dockerConnector = dockerConnectorProvider.get(); this.instances = new ConcurrentHashMap<>(); @@ -89,7 +97,9 @@ public class DockerInstanceStopDetector { * @param workspaceId id of a workspace that owns machine */ public void startDetection(String containerId, String machineId, String workspaceId) { - instances.put(containerId, Pair.of(machineId, workspaceId)); + if (isEnabled) { + instances.put(containerId, Pair.of(machineId, workspaceId)); + } } /** @@ -98,11 +108,16 @@ public class DockerInstanceStopDetector { * @param containerId id of a container to start detection for */ public void stopDetection(String containerId) { - instances.remove(containerId); + if (isEnabled) { + instances.remove(containerId); + } } @PostConstruct private void detectContainersEvents() { + if (!isEnabled) { + return; + } executorService.execute( () -> { //noinspection InfiniteLoopStatement