Skip to content

Commit

Permalink
CHE-3797 fix project import in case when workspace is running
Browse files Browse the repository at this point in the history
Signed-off-by: Oleksii Orel <[email protected]>
  • Loading branch information
Oleksii Orel committed Jan 26, 2017
1 parent 25e8a4d commit 12bf0a1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -950,13 +950,20 @@ export class CreateProjectController {
*/
checkExistingWorkspaceState(workspace: any): void {
if (workspace.status === 'RUNNING') {
let websocketUrl = this.cheAPI.getWorkspace().getWebsocketUrl(workspace.id);
// get bus
let websocketStream = this.$websocket(websocketUrl);
// on success, create project
websocketStream.onOpen(() => {
let bus = this.cheAPI.getWebsocket().getExistingBus(websocketStream);
this.createProjectInWorkspace(workspace.id, this.projectName, this.importProjectData, bus);
this.cheAPI.getWorkspace().fetchWorkspaceDetails(workspace.id).finally(() => {
let websocketUrl = this.cheAPI.getWorkspace().getWebsocketUrl(workspace.id);
if (!websocketUrl) {
this.getCreationSteps()[this.getCurrentProgressStep()].hasError = true;
this.$log.error('Unable to create project in workspace. Error when trying to get websocket URL.');
return;
}
// get bus
let websocketStream = this.$websocket(websocketUrl);
// on success, create project
websocketStream.onOpen(() => {
let bus = this.cheAPI.getWebsocket().getExistingBus(websocketStream);
this.createProjectInWorkspace(workspace.id, this.projectName, this.importProjectData, bus);
});
});
} else {
this.subscribeStatusChannel(workspace);
Expand Down
18 changes: 10 additions & 8 deletions dashboard/src/components/api/che-workspace.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class CheWorkspace {
workspaces: Array<che.IWorkspace>;
subscribedWorkspacesIds: Array<string>;
workspaceAgents: Map<string, CheWorkspaceAgent>;
workspacesByNamespace: Map<string, any>;
workspacesByNamespace: Map<string, Array<che.IWorkspace>>;
workspacesById: Map<string, che.IWorkspace>;
remoteWorkspaceAPI: ICHELicenseResource<any>;
lodash: any;
Expand Down Expand Up @@ -75,7 +75,7 @@ export class CheWorkspace {
// per namespace
this.workspacesByNamespace = new Map();

//Workspace agents per workspace id:
// workspace agents per workspace id:
this.workspaceAgents = new Map();

// listeners if workspaces are changed/updated
Expand Down Expand Up @@ -177,7 +177,7 @@ export class CheWorkspace {
});
}

getWorkspacesByNamespace(namespace) {
getWorkspacesByNamespace(namespace: string): Array<che.IWorkspace> {
return this.workspacesByNamespace.get(namespace);
}

Expand All @@ -201,11 +201,6 @@ export class CheWorkspace {
let updatedPromise = promise.then((data: Array<che.IWorkspace>) => {
let remoteWorkspaces = [];
this.workspaces.length = 0;
// todo It's a fix used not to loose account ID of the workspace.
// can be removed, when API will return accountId in the list of user workspaces response:
let copyWorkspaceById = new Map();
angular.copy(this.workspacesById, copyWorkspaceById);

this.workspacesById.clear();
this.workspacesByNamespace.clear();
// add workspace if not temporary
Expand All @@ -226,6 +221,11 @@ export class CheWorkspace {
this.startUpdateWorkspaceStatus(workspace.id);
});
return this.workspaces;
}, (error: any) => {
if (error.status === 304) {
return this.workspaces;
}
return this.$q.reject(error);
});

let callbackPromises = updatedPromise.then((data: any) => {
Expand All @@ -237,6 +237,8 @@ export class CheWorkspace {
promises.push(promise);
});
return this.$q.all(promises);
}, (error: any) => {
return this.$q.reject(error);
});

return callbackPromises;
Expand Down

0 comments on commit 12bf0a1

Please sign in to comment.