From 232c12c4bea7c16d192bef9100607d8bb34271c9 Mon Sep 17 00:00:00 2001 From: Angel Misevski Date: Tue, 7 Mar 2017 23:27:06 -0500 Subject: [PATCH] Add implementation of getEvents() to avoid busy wait Signed-off-by: Angel Misevski --- .../openshift/client/OpenShiftConnector.java | 35 +++++++++++++++++-- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/plugins/plugin-docker/che-plugin-openshift-client/src/main/java/org/eclipse/che/plugin/openshift/client/OpenShiftConnector.java b/plugins/plugin-docker/che-plugin-openshift-client/src/main/java/org/eclipse/che/plugin/openshift/client/OpenShiftConnector.java index 248c2d204f36..8de0f9cfb570 100644 --- a/plugins/plugin-docker/che-plugin-openshift-client/src/main/java/org/eclipse/che/plugin/openshift/client/OpenShiftConnector.java +++ b/plugins/plugin-docker/che-plugin-openshift-client/src/main/java/org/eclipse/che/plugin/openshift/client/OpenShiftConnector.java @@ -24,6 +24,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; @@ -36,8 +37,8 @@ import io.fabric8.openshift.api.model.Route; import io.fabric8.openshift.api.model.RouteList; + import org.eclipse.che.commons.annotation.Nullable; -import org.eclipse.che.inject.StringArrayConverter; import org.eclipse.che.plugin.docker.client.DockerApiVersionPathPrefixProvider; import org.eclipse.che.plugin.docker.client.DockerConnector; import org.eclipse.che.plugin.docker.client.DockerConnectorConfiguration; @@ -172,7 +173,7 @@ public class OpenShiftConnector extends DockerConnector { private final String workspacesPvcQuantity; private final String cheWorkspaceStorage; private final String cheWorkspaceProjectsStorage; - private final String cheServerExternalAddress; + private final String cheServerExternalAddress; @Inject public OpenShiftConnector(DockerConnectorConfiguration connectorConfiguration, @@ -650,7 +651,35 @@ public String commit(final CommitParams params) throws IOException { } @Override - public void getEvents(final GetEventsParams params, MessageProcessor messageProcessor) {} + public void getEvents(final GetEventsParams params, MessageProcessor messageProcessor) { + CountDownLatch waitForClose = new CountDownLatch(1); + Watcher eventWatcher = + new Watcher() { + @Override + public void eventReceived(Action action, io.fabric8.kubernetes.api.model.Event event) { + // Do nothing; + } + + @Override + public void onClose(KubernetesClientException e) { + if (e == null) { + LOG.error("Eventwatch Closed"); + } else { + LOG.error("Eventwatch Closed" + e.getMessage()); + } + waitForClose.countDown(); + } + }; + openShiftClient.events() + .inNamespace(openShiftCheProjectName) + .watch(eventWatcher); + try { + waitForClose.await(); + } catch (InterruptedException e) { + LOG.error("Thread interrupted while waiting for eventWatcher."); + Thread.currentThread().interrupt(); + } + } @Override public void getContainerLogs(final GetContainerLogsParams params, MessageProcessor containerLogsProcessor)