Skip to content

Commit

Permalink
CHE-1787: Remove workspace id from websocket connection path to master (
Browse files Browse the repository at this point in the history
  • Loading branch information
Igor Vinokur authored Oct 31, 2016
1 parent 92bca5d commit 69e58c7
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 35 deletions.
4 changes: 2 additions & 2 deletions src/app/ide/ide.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class IdeSvc {

this.updateRecentWorkspace(workspace.id);

let bus = this.cheAPI.getWebsocket().getBus(workspace.id);
let bus = this.cheAPI.getWebsocket().getBus();

let startWorkspaceDefer = this.$q.defer();
this.startWorkspace(bus, workspace).then(() => {
Expand Down Expand Up @@ -279,7 +279,7 @@ class IdeSvc {
websocketStream.close();
}

let workspaceBus = this.cheAPI.getWebsocket().getBus(workspaceId);
let workspaceBus = this.cheAPI.getWebsocket().getBus();

if (workspaceBus != null) {
this.listeningChannels.forEach((channel) => {
Expand Down
10 changes: 5 additions & 5 deletions src/app/projects/create-project/create-project.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ export class CreateProjectController {
//check current workspace
if (findWorkspace) {
// init WS bus
this.messageBus = this.cheAPI.getWebsocket().getBus(findWorkspace.id);
this.messageBus = this.cheAPI.getWebsocket().getBus();
} else {
this.resetCreateProgress();
}
Expand Down Expand Up @@ -914,7 +914,7 @@ export class CreateProjectController {
});
} else {
this.subscribeStatusChannel(workspace);
let bus = this.cheAPI.getWebsocket().getBus(workspace.id);
let bus = this.cheAPI.getWebsocket().getBus();
this.startWorkspace(bus, workspace);
}
}
Expand Down Expand Up @@ -945,7 +945,7 @@ export class CreateProjectController {
let promiseWorkspace = this.cheAPI.getWorkspace().fetchWorkspaceDetails(workspace.id);
promiseWorkspace.then(() => {
let websocketUrl = this.cheAPI.getWorkspace().getWebsocketUrl(workspace.id),
bus = this.cheAPI.getWebsocket().getBus(workspace.id);
bus = this.cheAPI.getWebsocket().getBus();
// try to connect
this.websocketReconnect = 10;
this.connectToExtensionServer(websocketUrl, workspace.id, this.importProjectData.project.name, this.importProjectData, bus);
Expand Down Expand Up @@ -974,15 +974,15 @@ export class CreateProjectController {

// init message bus if not there
if (this.workspaces.length === 0) {
this.messageBus = this.cheAPI.getWebsocket().getBus(workspace.id);
this.messageBus = this.cheAPI.getWebsocket().getBus();
}

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

this.$timeout(() => {
let bus = this.cheAPI.getWebsocket().getBus(workspace.id);
let bus = this.cheAPI.getWebsocket().getBus();
this.startWorkspace(bus, workspace);
}, 1000);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ export class ExportWorkspaceDialogController {

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

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

Expand Down
34 changes: 13 additions & 21 deletions src/components/api/che-websocket.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class CheWebsocket {

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

var wsProtocol;
Expand All @@ -42,10 +42,11 @@ export class CheWebsocket {
wsProtocol = 'wss';
}

wsUrl = wsProtocol + '://' + $location.host() + ':' + $location.port() + '/api/ws/';
wsUrl = wsProtocol + '://' + $location.host() + ':' + $location.port() + '/api/ws';
}
this.wsBaseUrl = wsUrl;
this.sockets = new Map();
this.bus = null;
this.remoteBus = null;
}


Expand All @@ -54,34 +55,25 @@ export class CheWebsocket {
}


getBus(workspaceId) {
var currentBus = this.sockets.get(workspaceId);
if (!currentBus) {
getBus() {
if (!this.bus) {
// needs to initialize
var url = this.wsBaseUrl + workspaceId;
var dataStream = this.$websocket(url);
var bus = new MessageBus(dataStream, this.$interval);
this.sockets.set(workspaceId, bus);
currentBus = bus;
this.bus = new MessageBus(this.$websocket(this.wsBaseUrl), this.$interval);
}
return currentBus;
return this.bus;
}


/**
* Gets a bus for a remote worksace, by providing the remote URL to this websocket
* @param websocketURL the remote host base WS url
* @param workspaceId the workspaceID used as suffix for the URL
*/
getRemoteBus(websocketURL, workspaceId) {
var currentBus = this.sockets.get(workspaceId);
if (!currentBus) {
var dataStream = this.$websocket(websocketURL + workspaceId);
var bus = new MessageBus(dataStream, this.$interval);
this.sockets.set(workspaceId, bus);
currentBus = bus;
getRemoteBus(websocketURL) {
if (!this.remoteBus) {
// needs to initialize
this.remoteBus = new MessageBus(this.$websocket(websocketURL), this.$interval);
}
return currentBus;
return this.remoteBus;
}

}
Expand Down
10 changes: 5 additions & 5 deletions src/components/api/che-workspace.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ export class CheWorkspace {
// listeners if workspaces are changed/updated
this.listeners = [];

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

// remote call
Expand Down Expand Up @@ -474,9 +474,9 @@ export class CheWorkspace {
* @param workspaceId
*/
startUpdateWorkspaceStatus(workspaceId) {
if (!this.websocketBusByWorkspaceId.has(workspaceId)) {
let bus = this.cheWebsocket.getBus(workspaceId);
this.websocketBusByWorkspaceId.set(workspaceId, bus);
if (!this.subscribedWorkspacesIds.includes(workspaceId)) {
let bus = this.cheWebsocket.getBus();
this.subscribedWorkspacesIds.push(workspaceId);

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

Expand Down
2 changes: 1 addition & 1 deletion src/components/api/remote/che-remote-workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export class CheRemoteWorkspace {
let deferred = this.$q.defer();
let deferredPromise = deferred.promise;

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

0 comments on commit 69e58c7

Please sign in to comment.