Skip to content

Commit bfcc846

Browse files
author
Igor Vinokur
authored
CHE-1787: Remove workspace id from websocket connection path to master (eclipse-che#2907)
1 parent d74b24f commit bfcc846

10 files changed

Lines changed: 33 additions & 43 deletions

File tree

assembly/assembly-wsmaster-war/src/main/webapp/WEB-INF/web.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
</context-param>
2424
<context-param>
2525
<param-name>org.eclipse.che.websocket.endpoint</param-name>
26-
<param-value>/ws/{ws-id}</param-value>
26+
<param-value>/ws</param-value>
2727
</context-param>
2828
<context-param>
2929
<param-name>org.eclipse.che.eventbus.endpoint</param-name>

dashboard/src/app/ide/ide.service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class IdeSvc {
7373

7474
this.updateRecentWorkspace(workspace.id);
7575

76-
let bus = this.cheAPI.getWebsocket().getBus(workspace.id);
76+
let bus = this.cheAPI.getWebsocket().getBus();
7777

7878
let startWorkspaceDefer = this.$q.defer();
7979
this.startWorkspace(bus, workspace).then(() => {
@@ -279,7 +279,7 @@ class IdeSvc {
279279
websocketStream.close();
280280
}
281281

282-
let workspaceBus = this.cheAPI.getWebsocket().getBus(workspaceId);
282+
let workspaceBus = this.cheAPI.getWebsocket().getBus();
283283

284284
if (workspaceBus != null) {
285285
this.listeningChannels.forEach((channel) => {

dashboard/src/app/projects/create-project/create-project.controller.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ export class CreateProjectController {
221221
//check current workspace
222222
if (findWorkspace) {
223223
// init WS bus
224-
this.messageBus = this.cheAPI.getWebsocket().getBus(findWorkspace.id);
224+
this.messageBus = this.cheAPI.getWebsocket().getBus();
225225
} else {
226226
this.resetCreateProgress();
227227
}
@@ -914,7 +914,7 @@ export class CreateProjectController {
914914
});
915915
} else {
916916
this.subscribeStatusChannel(workspace);
917-
let bus = this.cheAPI.getWebsocket().getBus(workspace.id);
917+
let bus = this.cheAPI.getWebsocket().getBus();
918918
this.startWorkspace(bus, workspace);
919919
}
920920
}
@@ -945,7 +945,7 @@ export class CreateProjectController {
945945
let promiseWorkspace = this.cheAPI.getWorkspace().fetchWorkspaceDetails(workspace.id);
946946
promiseWorkspace.then(() => {
947947
let websocketUrl = this.cheAPI.getWorkspace().getWebsocketUrl(workspace.id),
948-
bus = this.cheAPI.getWebsocket().getBus(workspace.id);
948+
bus = this.cheAPI.getWebsocket().getBus();
949949
// try to connect
950950
this.websocketReconnect = 10;
951951
this.connectToExtensionServer(websocketUrl, workspace.id, this.importProjectData.project.name, this.importProjectData, bus);
@@ -974,15 +974,15 @@ export class CreateProjectController {
974974

975975
// init message bus if not there
976976
if (this.workspaces.length === 0) {
977-
this.messageBus = this.cheAPI.getWebsocket().getBus(workspace.id);
977+
this.messageBus = this.cheAPI.getWebsocket().getBus();
978978
}
979979

980980
this.cheAPI.getWorkspace().fetchWorkspaceDetails(workspace.id).then(() => {
981981
this.subscribeStatusChannel(workspace);
982982
});
983983

984984
this.$timeout(() => {
985-
let bus = this.cheAPI.getWebsocket().getBus(workspace.id);
985+
let bus = this.cheAPI.getWebsocket().getBus();
986986
this.startWorkspace(bus, workspace);
987987
}, 1000);
988988

dashboard/src/app/workspaces/workspace-details/export-workspace/dialog/export-workspace-dialog.controller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ export class ExportWorkspaceDialogController {
173173

174174
// compute WS url
175175
let remoteURL = authData.url;
176-
let remoteWsURL = remoteURL.replace('http', 'ws') + '/api/ws/';
176+
let remoteWsURL = remoteURL.replace('http', 'ws') + '/api/ws';
177177

178178
let startWorkspacePromise = remoteWorkspaceAPI.startWorkspace(remoteWsURL, remoteWorkspace.id, remoteWorkspace.config.defaultEnv);
179179

dashboard/src/components/api/che-websocket.factory.ts

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export class CheWebsocket {
3232

3333
if (inDevMode) {
3434
// it handle then http and https
35-
wsUrl = proxySettings.replace('http', 'ws') + '/api/ws/';
35+
wsUrl = proxySettings.replace('http', 'ws') + '/api/ws';
3636
} else {
3737

3838
var wsProtocol;
@@ -42,10 +42,11 @@ export class CheWebsocket {
4242
wsProtocol = 'wss';
4343
}
4444

45-
wsUrl = wsProtocol + '://' + $location.host() + ':' + $location.port() + '/api/ws/';
45+
wsUrl = wsProtocol + '://' + $location.host() + ':' + $location.port() + '/api/ws';
4646
}
4747
this.wsBaseUrl = wsUrl;
48-
this.sockets = new Map();
48+
this.bus = null;
49+
this.remoteBus = null;
4950
}
5051

5152

@@ -54,34 +55,25 @@ export class CheWebsocket {
5455
}
5556

5657

57-
getBus(workspaceId) {
58-
var currentBus = this.sockets.get(workspaceId);
59-
if (!currentBus) {
58+
getBus() {
59+
if (!this.bus) {
6060
// needs to initialize
61-
var url = this.wsBaseUrl + workspaceId;
62-
var dataStream = this.$websocket(url);
63-
var bus = new MessageBus(dataStream, this.$interval);
64-
this.sockets.set(workspaceId, bus);
65-
currentBus = bus;
61+
this.bus = new MessageBus(this.$websocket(this.wsBaseUrl), this.$interval);
6662
}
67-
return currentBus;
63+
return this.bus;
6864
}
6965

7066

7167
/**
7268
* Gets a bus for a remote worksace, by providing the remote URL to this websocket
7369
* @param websocketURL the remote host base WS url
74-
* @param workspaceId the workspaceID used as suffix for the URL
7570
*/
76-
getRemoteBus(websocketURL, workspaceId) {
77-
var currentBus = this.sockets.get(workspaceId);
78-
if (!currentBus) {
79-
var dataStream = this.$websocket(websocketURL + workspaceId);
80-
var bus = new MessageBus(dataStream, this.$interval);
81-
this.sockets.set(workspaceId, bus);
82-
currentBus = bus;
71+
getRemoteBus(websocketURL) {
72+
if (!this.remoteBus) {
73+
// needs to initialize
74+
this.remoteBus = new MessageBus(this.$websocket(websocketURL), this.$interval);
8375
}
84-
return currentBus;
76+
return this.remoteBus;
8577
}
8678

8779
}

dashboard/src/components/api/che-workspace.factory.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ export class CheWorkspace {
4747
// listeners if workspaces are changed/updated
4848
this.listeners = [];
4949

50-
// list of websocket bus per workspace
51-
this.websocketBusByWorkspaceId = new Map();
50+
// list of subscribed to websocket workspace Ids
51+
this.subscribedWorkspacesIds = [];
5252
this.statusDefers = {};
5353

5454
// remote call
@@ -474,9 +474,9 @@ export class CheWorkspace {
474474
* @param workspaceId
475475
*/
476476
startUpdateWorkspaceStatus(workspaceId) {
477-
if (!this.websocketBusByWorkspaceId.has(workspaceId)) {
478-
let bus = this.cheWebsocket.getBus(workspaceId);
479-
this.websocketBusByWorkspaceId.set(workspaceId, bus);
477+
if (!this.subscribedWorkspacesIds.includes(workspaceId)) {
478+
let bus = this.cheWebsocket.getBus();
479+
this.subscribedWorkspacesIds.push(workspaceId);
480480

481481
bus.subscribe('workspace:' + workspaceId, (message) => {
482482

dashboard/src/components/api/remote/che-remote-workspace.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export class CheRemoteWorkspace {
7070
let deferred = this.$q.defer();
7171
let deferredPromise = deferred.promise;
7272

73-
let bus = this.cheWebsocket.getRemoteBus(remoteWsURL, workspaceId);
73+
let bus = this.cheWebsocket.getRemoteBus(remoteWsURL);
7474
// subscribe to workspace events
7575
bus.subscribe('workspace:' + workspaceId, (message) => {
7676
if (message.eventType === 'RUNNING' && message.workspaceId === workspaceId) {

ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/workspace/WorkspaceComponent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ public void handleWorkspaceEvents(final WorkspaceDto workspace, final Callback<C
173173
if (messageBus != null) {
174174
messageBus.cancelReconnection();
175175
}
176-
messageBus = messageBusProvider.createMessageBus(workspace.getId());
176+
messageBus = messageBusProvider.createMessageBus();
177177

178178
messageBus.addOnOpenHandler(new ConnectionOpenedHandler() {
179179
@Override

ide/commons-gwt/src/main/java/org/eclipse/che/ide/websocket/MessageBusImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
*/
2222
public class MessageBusImpl extends AbstractMessageBus {
2323

24-
public MessageBusImpl(String workspaceId) {
25-
super((getProtocol().equals("https:") ? "wss://" : "ws://") + getHost() + getRestContext() + "/ws/" + workspaceId);
24+
public MessageBusImpl() {
25+
super((getProtocol().equals("https:") ? "wss://" : "ws://") + getHost() + getRestContext() + "/ws");
2626
}
2727

2828
private static native String getRestContext() /*-{

ide/commons-gwt/src/main/java/org/eclipse/che/ide/websocket/MessageBusProvider.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,10 @@ public MessageBus getMachineMessageBus() {
3737
* Creates new instance of {@link MessageBusImpl} and connects to web socket via special url. The method returns new
3838
* instance each time it is called. Message bus is created only one time when we start workspace.
3939
*
40-
* @param workspaceId
41-
* workspace id which need for path to connect to web socket
4240
* @return instance of {@link MessageBusImpl}
4341
*/
44-
public MessageBus createMessageBus(String workspaceId) {
45-
this.messageBus = new MessageBusImpl(workspaceId);
42+
public MessageBus createMessageBus() {
43+
this.messageBus = new MessageBusImpl();
4644

4745
return messageBus;
4846
}

0 commit comments

Comments
 (0)