Skip to content

Commit

Permalink
add progress ui
Browse files Browse the repository at this point in the history
  • Loading branch information
akosyakov committed Dec 29, 2021
1 parent 519fd26 commit 8b6b98f
Show file tree
Hide file tree
Showing 15 changed files with 149 additions and 523 deletions.
2 changes: 1 addition & 1 deletion components/gitpod-protocol/java/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ dependencies {
implementation group: 'org.eclipse.lsp4j', name: 'org.eclipse.lsp4j.jsonrpc', version: '0.12.0'
implementation group: 'org.eclipse.lsp4j', name: 'org.eclipse.lsp4j.websocket', version: '0.12.0'
compileOnly group: 'javax.websocket', name: 'javax.websocket-api', version: '1.1'
implementation group: 'org.glassfish.tyrus.bundles', name: 'tyrus-standalone-client', version: '1.18'
implementation("org.eclipse.jetty.websocket:javax-websocket-client-impl:9.4.44.v20210927")
}

application {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,64 +4,40 @@

package io.gitpod.gitpodprotocol.api;

import org.eclipse.lsp4j.jsonrpc.Launcher;
import org.eclipse.lsp4j.websocket.WebSocketEndpoint;
import org.eclipse.lsp4j.websocket.WebSocketLauncherBuilder;

import javax.websocket.*;
import java.io.IOException;
import java.net.URI;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Map;

import javax.websocket.ClientEndpointConfig;
import javax.websocket.ContainerProvider;
import javax.websocket.DeploymentException;
import javax.websocket.Session;
import javax.websocket.WebSocketContainer;

import org.eclipse.lsp4j.jsonrpc.Launcher;
import org.eclipse.lsp4j.websocket.WebSocketEndpoint;

// TODO(ak) rename
public class ConnectionHelper {

private Session session;

public GitpodClient connect(final String uri, final String origin, final String token)
public Session connect(final String apiUrl, final String origin, final String token, String userAgent, String clientVersion, GitpodClient client)
throws DeploymentException, IOException {
final GitpodClientImpl gitpodClient = new GitpodClientImpl();
return connect(uri, origin, token, gitpodClient);
}

public GitpodClient connect(final String uri, final String origin, final String token, GitpodClient gitpodClient)
throws DeploymentException, IOException {

final WebSocketEndpoint<GitpodServer> webSocketEndpoint = new WebSocketEndpoint<GitpodServer>() {
return ContainerProvider.getWebSocketContainer().connectToServer(new WebSocketEndpoint<GitpodServer>() {
@Override
protected void configure(final Launcher.Builder<GitpodServer> builder) {
builder.setLocalService(gitpodClient).setRemoteInterface(GitpodServer.class);
builder.setLocalService(client).setRemoteInterface(GitpodServer.class);
}

@Override
protected void connect(final Collection<Object> localServices, final GitpodServer remoteProxy) {
localServices.forEach(s -> ((GitpodClient) s).connect(remoteProxy));
client.connect(remoteProxy);
}
};

final ClientEndpointConfig.Configurator configurator = new ClientEndpointConfig.Configurator() {
}, ClientEndpointConfig.Builder.create().configurator(new ClientEndpointConfig.Configurator() {
@Override
public void beforeRequest(final Map<String, List<String>> headers) {
headers.put("Origin", Arrays.asList(origin));
headers.put("Authorization", Arrays.asList("Bearer " + token));
headers.put("User-Agent", Arrays.asList(userAgent));
headers.put("X-Client-Version", Arrays.asList(clientVersion));
}
};
final ClientEndpointConfig clientEndpointConfig = ClientEndpointConfig.Builder.create()
.configurator(configurator).build();
final WebSocketContainer webSocketContainer = ContainerProvider.getWebSocketContainer();
this.session = webSocketContainer.connectToServer(webSocketEndpoint, clientEndpointConfig, URI.create(uri));
return gitpodClient;
}

public void close() throws IOException {
if (this.session != null && this.session.isOpen()) {
this.session.close();
}
}).build(), URI.create(apiUrl));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,23 @@

import io.gitpod.gitpodprotocol.api.entities.WorkspaceInstance;

public interface GitpodClient {
void connect(GitpodServer server);
public class GitpodClient {

GitpodServer server();
private GitpodServer server;

public void connect(GitpodServer server) {
this.server = server;
}

public GitpodServer getServer() {
if (this.server == null) {
throw new IllegalStateException("not connected");
}
return this.server;
}

@JsonNotification
void onInstanceUpdate(WorkspaceInstance instance);
public void onInstanceUpdate(WorkspaceInstance instance) {

}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,30 @@
import io.gitpod.gitpodprotocol.api.entities.SendHeartBeatOptions;
import io.gitpod.gitpodprotocol.api.entities.User;

import javax.websocket.Session;

public class TestClient {
public static void main(String[] args) throws Exception {
String uri = "wss://gitpod.io/api/v1";
String token = "CHANGE-ME";
String origin = "https://CHANGE-ME.gitpod.io/";

Session session = null;
ConnectionHelper conn = new ConnectionHelper();
try {
GitpodClient gitpodClient = conn.connect(uri, origin, token);
GitpodServer gitpodServer = gitpodClient.server();
GitpodClient client = new GitpodClient();
session = conn.connect(uri, origin, token, "Test", "Test", client);
GitpodServer gitpodServer = client.getServer();
User user = gitpodServer.getLoggedInUser().join();
System.out.println("logged in user:" + user);

Void result = gitpodServer
.sendHeartBeat(new SendHeartBeatOptions("CHANGE-ME", false)).join();
System.out.println("send heart beat:" + result);
} finally {
conn.close();
if (session != null) {
session.close();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.intellij.openapi.Disposable
import com.intellij.openapi.components.Service
import com.intellij.openapi.diagnostic.logger
import io.gitpod.gitpodprotocol.api.ConnectionHelper
import io.gitpod.gitpodprotocol.api.GitpodClient
import io.gitpod.gitpodprotocol.api.entities.SendHeartBeatOptions
import io.gitpod.ide.jetbrains.backend.services.ControllerStatusService.ControllerStatus
import io.gitpod.ide.jetbrains.backend.utils.Retrier.retry
Expand Down Expand Up @@ -92,8 +93,8 @@ class HeartbeatService : Disposable {
@Suppress("TooGenericExceptionCaught") // Unsure what exceptions might be thrown
try {
heartbeatClient.get()!!(wasClosed).await()
logger.info("Heartbeat sent with wasClosed=$wasClosed")
} catch (e: Exception) {
// TODO(ak) implement proper reconnecting web socket
// If connection fails for some reason,
// remove the reference to the existing server.
heartbeatClient.set(null)
Expand All @@ -111,14 +112,19 @@ class HeartbeatService : Disposable {
logger.info("Creating HeartbeatClient")
val supervisorInfo = SupervisorInfoService.fetch()

val server = ConnectionHelper().connect(
val client = GitpodClient()
ConnectionHelper().connect(
"wss://${supervisorInfo.host.split("//").last()}/api/v1",
supervisorInfo.workspaceUrl,
supervisorInfo.authToken
).server()
supervisorInfo.authToken,
"jetbrains-backend-plugin",
// TODO(ak) read from properties
"1.0-SNAPSHOT",
client
)

return { wasClosed: Boolean ->
server.sendHeartBeat(SendHeartBeatOptions(supervisorInfo.instanceId, wasClosed))
client.server.sendHeartBeat(SendHeartBeatOptions(supervisorInfo.instanceId, wasClosed))
}
}

Expand Down
1 change: 1 addition & 0 deletions components/ide/jetbrains/gateway-plugin/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.gradle
.idea
build
bin
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<option name="taskNames">
<list>
<option value="runIde" />
<option value="--args='jetbrains-gateway://connect#gitpod=%7B%22gitpodHost%22%3A%22ak-jb-gateway-plugin.staging.gitpod-dev.com%22%2C%22workspaceId%22%3A%22blue-antelope-j2hcw46v%22%7D'" />
<option value="--args='jetbrains-gateway://connect#gitpod=%7B%22gitpodHost%22%3A%22ak-jb-gateway-plugin.staging.gitpod-dev.com%22%2C%22workspaceId%22%3A%22black-boar-q0wk5q33%22%7D'" />
</list>
</option>
<option name="vmOptions" value="" />
Expand Down

This file was deleted.

This file was deleted.

Loading

0 comments on commit 8b6b98f

Please sign in to comment.