CHE-3797 fix project import in case when workspace is running

Signed-off-by: Oleksii Orel <oorel@codenvy.com>
6.19.x
Oleksii Orel 2017-01-25 16:06:13 +02:00
parent 25e8a4d1a2
commit 12bf0a11de
2 changed files with 24 additions and 15 deletions

View File

@ -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);

View File

@ -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;
@ -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
@ -177,7 +177,7 @@ export class CheWorkspace {
});
}
getWorkspacesByNamespace(namespace) {
getWorkspacesByNamespace(namespace: string): Array<che.IWorkspace> {
return this.workspacesByNamespace.get(namespace);
}
@ -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
@ -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) => {
@ -237,6 +237,8 @@ export class CheWorkspace {
promises.push(promise);
});
return this.$q.all(promises);
}, (error: any) => {
return this.$q.reject(error);
});
return callbackPromises;