diff --git a/dashboard/src/app/factories/load-factory/load-factory.controller.ts b/dashboard/src/app/factories/load-factory/load-factory.controller.ts index 977a8591e0c5..ffbbc3c8cd97 100644 --- a/dashboard/src/app/factories/load-factory/load-factory.controller.ts +++ b/dashboard/src/app/factories/load-factory/load-factory.controller.ts @@ -13,6 +13,8 @@ import {CheAPI} from '../../../components/api/che-api.factory'; import {LoadFactoryService} from './load-factory.service'; import {CheNotification} from '../../../components/notification/che-notification.factory'; import {RouteHistory} from '../../../components/routing/route-history.service'; +import {CheJsonRpcApi} from '../../../components/api/json-rpc/che-json-rpc-api.factory'; +import {CheJsonRpcMasterApi} from '../../../components/api/json-rpc/che-json-rpc-master-api'; const WS_AGENT_STEP: number = 3 @@ -37,13 +39,14 @@ export class LoadFactoryController { private projectsToImport: number; private factory: che.IFactory; + private jsonRpcMasterApi: CheJsonRpcMasterApi; /** * Default constructor that is using resource * @ngInject for Dependency injection */ - constructor(cheAPI: CheAPI, $route: ng.route.IRouteService, $timeout: ng.ITimeoutService, + constructor(cheAPI: CheAPI, cheJsonRpcApi: CheJsonRpcApi, $route: ng.route.IRouteService, $timeout: ng.ITimeoutService, $mdDialog: ng.material.IDialogService, loadFactoryService: LoadFactoryService, lodash: _.LoDashStatic, cheNotification: CheNotification, $location: ng.ILocationService, routeHistory: RouteHistory, $window: ng.IWindowService) { this.cheAPI = cheAPI; @@ -59,6 +62,7 @@ export class LoadFactoryController { this.workspaces = []; this.workspace = {}; this.hideMenuAndFooter(); + this.jsonRpcMasterApi = cheJsonRpcApi.getJsonRpcMasterApi(cheAPI.getWorkspace().getJsonRpcApiLocation()); this.loadFactoryService.resetLoadProgress(); this.loadFactoryService.setLoadFactoryInProgress(true); @@ -368,7 +372,7 @@ export class LoadFactoryController { console.log('Status channel of workspaceID', workspaceId, message); }; - this.cheAPI.getWorkspace().getMasterApi().subscribeEnvironmentStatus(workspaceId, environmentStatusHandler); + this.jsonRpcMasterApi.subscribeEnvironmentStatus(workspaceId, environmentStatusHandler); let environmentOutputHandler = (message: any) => { // skip displaying machine logs after workspace agent: @@ -385,7 +389,7 @@ export class LoadFactoryController { let machines = this.getMachineNames(data.config); machines.forEach((machine: string) => { - this.cheAPI.getWorkspace().getMasterApi().subscribeEnvironmentOutput(workspaceId, machine, environmentOutputHandler); + this.jsonRpcMasterApi.subscribeEnvironmentOutput(workspaceId, machine, environmentOutputHandler); }); let workspaceStatusHandler = (message: any) => { @@ -406,7 +410,7 @@ export class LoadFactoryController { } }; - this.cheAPI.getWorkspace().getMasterApi().subscribeWorkspaceStatus(workspaceId, workspaceStatusHandler); + this.jsonRpcMasterApi.subscribeWorkspaceStatus(workspaceId, workspaceStatusHandler); let wsAgentHandler = (message: any) => { if (this.loadFactoryService.getCurrentProgressStep() < WS_AGENT_STEP) { @@ -420,7 +424,7 @@ export class LoadFactoryController { } }; - this.cheAPI.getWorkspace().getMasterApi().subscribeWsAgentOutput(workspaceId, wsAgentHandler); + this.jsonRpcMasterApi.subscribeWsAgentOutput(workspaceId, wsAgentHandler); } /** diff --git a/dashboard/src/app/projects/create-project/create-project.controller.ts b/dashboard/src/app/projects/create-project/create-project.controller.ts index dfc65ee729c3..047d39a483b0 100755 --- a/dashboard/src/app/projects/create-project/create-project.controller.ts +++ b/dashboard/src/app/projects/create-project/create-project.controller.ts @@ -15,6 +15,8 @@ import {CreateProjectSvc} from './create-project.service'; import {CheNotification} from '../../../components/notification/che-notification.factory'; import {CheEnvironmentRegistry} from '../../../components/api/environment/che-environment-registry.factory'; import {IEnvironmentManagerMachine} from '../../../components/api/environment/environment-manager-machine'; +import {CheJsonRpcApi} from '../../../components/api/json-rpc/che-json-rpc-api.factory'; +import {CheJsonRpcMasterApi} from '../../../components/api/json-rpc/che-json-rpc-master-api'; /** * This class is handling the controller for the projects @@ -36,6 +38,7 @@ export class CreateProjectController { cheAPI: CheAPI; cheStack: CheStack; cheEnvironmentRegistry: CheEnvironmentRegistry; + jsonRpcMasterApi: CheJsonRpcMasterApi; stackMachines: any; importProjectData: che.IImportProject; @@ -86,7 +89,7 @@ export class CreateProjectController { constructor($document: ng.IDocumentService, $filter: ng.IFilterService, $location: ng.ILocationService, $log: ng.ILogService, $mdDialog: ng.material.IDialogService, $rootScope: che.IRootScopeService, $routeParams: che.route.IRouteParamsService, $q: ng.IQService, $scope: ng.IScope, - $timeout: ng.ITimeoutService, $window: ng.IWindowService, + $timeout: ng.ITimeoutService, $window: ng.IWindowService, cheJsonRpcApi: CheJsonRpcApi, lodash: any, cheAPI: CheAPI, cheStack: CheStack, createProjectSvc: CreateProjectSvc, cheNotification: CheNotification, cheEnvironmentRegistry: CheEnvironmentRegistry) { this.$log = $log; @@ -109,6 +112,7 @@ export class CreateProjectController { this.resetCreateProgress(); this.importProjectData = this.getDefaultProjectJson(); + this.jsonRpcMasterApi = cheJsonRpcApi.getJsonRpcMasterApi(cheAPI.getWorkspace().getJsonRpcApiLocation()); this.enableWizardProject = true; @@ -428,7 +432,7 @@ export class CreateProjectController { } }; - this.cheAPI.getWorkspace().getMasterApi().subscribeWsAgentOutput(workspaceId, this.agentOutputHandler); + this.jsonRpcMasterApi.subscribeWsAgentOutput(workspaceId, this.agentOutputHandler); this.statusHandler = (message: any) => { message = this.getDisplayMachineLog(message); @@ -463,7 +467,7 @@ export class CreateProjectController { } this.$log.log('Status channel of workspaceID', workspaceId, message); }; - this.cheAPI.getWorkspace().getMasterApi().subscribeEnvironmentStatus(workspaceId, this.statusHandler); + this.jsonRpcMasterApi.subscribeEnvironmentStatus(workspaceId, this.statusHandler); this.environmentOutputHandler = (message: any) => { message = this.getDisplayMachineLog(message); @@ -476,7 +480,7 @@ export class CreateProjectController { let machineNames = this.getMachineNames(workspace.config); machineNames.forEach((machine: string) => { - this.cheAPI.getWorkspace().getMasterApi().subscribeEnvironmentOutput(workspaceId, machine, this.environmentOutputHandler); + this.jsonRpcMasterApi.subscribeEnvironmentOutput(workspaceId, machine, this.environmentOutputHandler); }); let startWorkspacePromise = this.cheAPI.getWorkspace().startWorkspace(workspace.id, workspace.config.defaultEnv); @@ -689,11 +693,11 @@ export class CreateProjectController { */ cleanupChannels(workspaceId: string, projectName: string): void { let workspace = this.cheAPI.getWorkspace().getWorkspaceById(workspaceId); - this.cheAPI.getWorkspace().getMasterApi().unSubscribeEnvironmentStatus(workspaceId, this.statusHandler); - this.cheAPI.getWorkspace().getMasterApi().unSubscribeWsAgentOutput(workspaceId, this.agentOutputHandler); + this.jsonRpcMasterApi.unSubscribeEnvironmentStatus(workspaceId, this.statusHandler); + this.jsonRpcMasterApi.unSubscribeWsAgentOutput(workspaceId, this.agentOutputHandler); let machineNames = this.getMachineNames(workspace.config); machineNames.forEach((machine: string) => { - this.cheAPI.getWorkspace().getMasterApi().unSubscribeEnvironmentOutput(workspaceId, machine, this.environmentOutputHandler); + this.jsonRpcMasterApi.unSubscribeEnvironmentOutput(workspaceId, machine, this.environmentOutputHandler); }); this.cheAPI.getWorkspace().getWorkspaceAgent(workspaceId).getWsAgentApi().unSubscribeProjectImport(projectName, this.projectImportHandler); } diff --git a/dashboard/src/components/api/che-api-config.ts b/dashboard/src/components/api/che-api-config.ts index 44ddcc1fd01b..84012532dc0b 100644 --- a/dashboard/src/components/api/che-api-config.ts +++ b/dashboard/src/components/api/che-api-config.ts @@ -33,6 +33,7 @@ import {CheSsh} from './che-ssh.factory'; import {CheNamespaceRegistry} from './namespace/che-namespace-registry.factory'; import {CheUser} from './che-user.factory'; import {ChePageObject} from './paging-resource/page-object.factory'; +import {CheJsonRpcApi} from './json-rpc/che-json-rpc-api.factory'; export class ApiConfig { @@ -60,5 +61,6 @@ export class ApiConfig { register.factory('cheNamespaceRegistry', CheNamespaceRegistry); register.factory('cheUser', CheUser); register.factory('chePageObject', ChePageObject); + register.factory('cheJsonRpcApi', CheJsonRpcApi); } } diff --git a/dashboard/src/components/api/che-workspace-agent.ts b/dashboard/src/components/api/che-workspace-agent.ts index 3f7abde48233..905599a56d5b 100644 --- a/dashboard/src/components/api/che-workspace-agent.ts +++ b/dashboard/src/components/api/che-workspace-agent.ts @@ -15,7 +15,7 @@ import {CheGit} from './che-git'; import {CheSvn} from './che-svn'; import {CheProjectType} from './che-project-type'; import {CheTypeResolver} from './project/che-type-resolver'; -import {CheJsonRpcWsagentApi} from './json-rpc/che-json-rpc-wsagent-api.factory'; +import {CheJsonRpcWsagentApi} from './json-rpc/che-json-rpc-wsagent-api'; import {WebsocketClient} from './json-rpc/websocket-client'; interface IWorkspaceAgentData { diff --git a/dashboard/src/components/api/che-workspace.factory.ts b/dashboard/src/components/api/che-workspace.factory.ts index 1a3810c57ec5..49db46bca088 100644 --- a/dashboard/src/components/api/che-workspace.factory.ts +++ b/dashboard/src/components/api/che-workspace.factory.ts @@ -15,9 +15,8 @@ import {ComposeEnvironmentManager} from './environment/compose-environment-manag import {DockerFileEnvironmentManager} from './environment/docker-file-environment-manager'; import {DockerImageEnvironmentManager} from './environment/docker-image-environment-manager'; import {CheEnvironmentRegistry} from './environment/che-environment-registry.factory'; -import {CheWebsocket} from './che-websocket.factory'; -import {CheJsonRpcMasterApi} from './json-rpc/che-json-rpc-master-api.factory'; -import {WebsocketClient} from './json-rpc/websocket-client'; +import {CheJsonRpcMasterApi} from './json-rpc/che-json-rpc-master-api'; +import {CheJsonRpcApi} from './json-rpc/che-json-rpc-api.factory'; interface ICHELicenseResource extends ng.resource.IResourceClass { create: any; @@ -54,15 +53,15 @@ export class CheWorkspace { private workspacesById: Map; private remoteWorkspaceAPI: ICHELicenseResource; private lodash: any; - private cheWebsocket: CheWebsocket; private statusDefers: Object; private workspaceSettings: any; + private jsonRpcApiLocation: string; /** * Default constructor that is using resource * @ngInject for Dependency injection */ - constructor($resource: ng.resource.IResourceService, $http: ng.IHttpService, $q: ng.IQService, cheWebsocket: CheWebsocket, + constructor($resource: ng.resource.IResourceService, $http: ng.IHttpService, $q: ng.IQService, cheJsonRpcApi: CheJsonRpcApi, $websocket: ng.websocket.IWebSocketProvider, $location: ng.ILocationService, proxySettings : string, userDashboardConfig: any, lodash: any, cheEnvironmentRegistry: CheEnvironmentRegistry, $log: ng.ILogService) { this.workspaceStatuses = ['RUNNING', 'STOPPED', 'PAUSED', 'STARTING', 'STOPPING', 'ERROR']; @@ -74,7 +73,6 @@ export class CheWorkspace { this.$log = $log; this.$websocket = $websocket; this.lodash = lodash; - this.cheWebsocket = cheWebsocket; // current list of workspaces this.workspaces = []; @@ -94,6 +92,8 @@ export class CheWorkspace { // list of subscribed to websocket workspace Ids this.subscribedWorkspacesIds = []; this.statusDefers = {}; + this.jsonRpcApiLocation = this.formJsonRpcApiLocation($location, proxySettings, userDashboardConfig.developmentMode); + this.cheJsonRpcMasterApi = cheJsonRpcApi.getJsonRpcMasterApi(this.jsonRpcApiLocation); // remote call this.remoteWorkspaceAPI = >this.$resource('/api/workspace', {}, { @@ -116,9 +116,6 @@ export class CheWorkspace { cheEnvironmentRegistry.addEnvironmentManager('dockerfile', new DockerFileEnvironmentManager($log)); cheEnvironmentRegistry.addEnvironmentManager('dockerimage', new DockerImageEnvironmentManager($log)); - let websocketClient = new WebsocketClient($websocket, $q); - this.cheJsonRpcMasterApi = new CheJsonRpcMasterApi(websocketClient); - this.connectWsMasterApi($location, proxySettings, userDashboardConfig.developmentMode); this.fetchWorkspaceSettings(); } @@ -151,7 +148,7 @@ export class CheWorkspace { wsAgentWebocketLink = wsAgentWebocketLink.replace('/api/ws', ''); } - let workspaceAgentData = {path: wsAgentLink.href, websocket: wsAgentWebocketLink, clientId: this.getMasterApi().getClientId()}; + let workspaceAgentData = {path: wsAgentLink.href, websocket: wsAgentWebocketLink, clientId: this.cheJsonRpcMasterApi.getClientId()}; let wsagent: CheWorkspaceAgent = new CheWorkspaceAgent(this.$resource, this.$q, this.$websocket, workspaceAgentData); this.workspaceAgents.set(workspaceId, wsagent); return wsagent; @@ -637,8 +634,8 @@ export class CheWorkspace { return this.workspaceSettings ? this.workspaceSettings['che.workspace.auto_snapshot'] === 'true' : true; } - public getMasterApi(): CheJsonRpcMasterApi { - return this.cheJsonRpcMasterApi; + getJsonRpcApiLocation(): string { + return this.jsonRpcApiLocation; } private updateWorkspacesList(workspace: che.IWorkspace): void { @@ -653,7 +650,7 @@ export class CheWorkspace { this.startUpdateWorkspaceStatus(workspace.id); } - private connectWsMasterApi($location: ng.ILocationService, proxySettings : string, devmode: boolean): void { + private formJsonRpcApiLocation($location: ng.ILocationService, proxySettings : string, devmode: boolean): string { let wsUrl; if (devmode) { @@ -664,10 +661,6 @@ export class CheWorkspace { wsProtocol = 'http' === $location.protocol() ? 'ws' : 'wss'; wsUrl = wsProtocol + '://' + $location.host() + ':' + $location.port(); } - this.cheJsonRpcMasterApi.connect(wsUrl).then(() => { - this.$log.info('Connected to workspace master: ' + wsUrl); - }, (error: any) => { - this.$log.error('Failed to connect to workspace master: ' + wsUrl, error); - }); + return wsUrl; } } diff --git a/dashboard/src/components/api/json-rpc/che-json-rpc-api-service.ts b/dashboard/src/components/api/json-rpc/che-json-rpc-api-service.ts index 240a875034bc..8ede65062f70 100644 --- a/dashboard/src/components/api/json-rpc/che-json-rpc-api-service.ts +++ b/dashboard/src/components/api/json-rpc/che-json-rpc-api-service.ts @@ -1,12 +1,12 @@ /* - * Copyright (c) 2015-2017 Codenvy, S.A. + * Copyright (c) 2015-2017 Red Hat, Inc. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Codenvy, S.A. - initial API and implementation + * Red Hat, Inc. - initial API and implementation */ 'use strict'; import {ICommunicationClient, JsonRpcClient} from './json-rpc-client'; diff --git a/dashboard/src/components/api/json-rpc/che-json-rpc-api.factory.ts b/dashboard/src/components/api/json-rpc/che-json-rpc-api.factory.ts new file mode 100644 index 000000000000..be1eb2b8e632 --- /dev/null +++ b/dashboard/src/components/api/json-rpc/che-json-rpc-api.factory.ts @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2015-2017 Red Hat, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Red Hat, Inc. - initial API and implementation + */ +'use strict'; + +import {CheJsonRpcMasterApi} from './che-json-rpc-master-api'; +import {WebsocketClient} from './websocket-client'; + +/** + * This class manages the api connection through JSON RPC. + * + * @author Ann Shumilova + */ +export class CheJsonRpcApi { + private $q: ng.IQService; + private $websocket: ng.websocket.IWebSocketProvider; + private $log: ng.ILogService; + private jsonRpcApiConnection: Map; + + /** + * Default constructor that is using resource + * @ngInject for Dependency injection + */ + constructor($q: ng.IQService, $websocket: ng.websocket.IWebSocketProvider, $log: ng.ILogService) { + this.$q = $q; + this.$websocket = $websocket; + this.$log = $log; + this.jsonRpcApiConnection = new Map(); + } + + getJsonRpcMasterApi(entrypoint: string): CheJsonRpcMasterApi { + if (this.jsonRpcApiConnection.has(entrypoint)) { + return this.jsonRpcApiConnection.get(entrypoint); + } else { + let websocketClient = new WebsocketClient(this.$websocket, this.$q); + let cheJsonRpcMasterApi: CheJsonRpcMasterApi = new CheJsonRpcMasterApi(websocketClient, entrypoint); + this.jsonRpcApiConnection.set(entrypoint, cheJsonRpcMasterApi); + return cheJsonRpcMasterApi; + } + } +} diff --git a/dashboard/src/components/api/json-rpc/che-json-rpc-master-api.factory.ts b/dashboard/src/components/api/json-rpc/che-json-rpc-master-api.ts similarity index 97% rename from dashboard/src/components/api/json-rpc/che-json-rpc-master-api.factory.ts rename to dashboard/src/components/api/json-rpc/che-json-rpc-master-api.ts index 26dae9b54aeb..939f780a55fa 100644 --- a/dashboard/src/components/api/json-rpc/che-json-rpc-master-api.factory.ts +++ b/dashboard/src/components/api/json-rpc/che-json-rpc-master-api.ts @@ -1,12 +1,12 @@ /* - * Copyright (c) 2015-2017 Codenvy, S.A. + * Copyright (c) 2015-2017 Red Hat, Inc. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Codenvy, S.A. - initial API and implementation + * Red Hat, Inc. - initial API and implementation */ 'use strict'; import {CheJsonRpcApiClient, IChannel} from './che-json-rpc-api-service'; @@ -28,7 +28,7 @@ export class CheJsonRpcMasterApi { private channels: Map; private clientId: string; - constructor (client: ICommunicationClient) { + constructor (client: ICommunicationClient, entrypoint: string) { this.cheJsonRpcApi = new CheJsonRpcApiClient(client); this.channels = new Map(); @@ -55,6 +55,8 @@ export class CheJsonRpcMasterApi { unsubscription: 'event:workspace-status:un-subscribe', notification: 'event:workspace-status:changed' }); + + this.connect(entrypoint); } /** diff --git a/dashboard/src/components/api/json-rpc/che-json-rpc-wsagent-api.factory.ts b/dashboard/src/components/api/json-rpc/che-json-rpc-wsagent-api.ts similarity index 94% rename from dashboard/src/components/api/json-rpc/che-json-rpc-wsagent-api.factory.ts rename to dashboard/src/components/api/json-rpc/che-json-rpc-wsagent-api.ts index 76e74af57095..2915425d35f5 100644 --- a/dashboard/src/components/api/json-rpc/che-json-rpc-wsagent-api.factory.ts +++ b/dashboard/src/components/api/json-rpc/che-json-rpc-wsagent-api.ts @@ -1,15 +1,14 @@ /* - * Copyright (c) 2015-2017 Codenvy, S.A. + * Copyright (c) 2015-2017 Red Hat, Inc. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Codenvy, S.A. - initial API and implementation + * Red Hat, Inc. - initial API and implementation */ 'use strict'; -import {WebsocketClient} from './websocket-client'; import {CheJsonRpcApiClient, IChannel} from './che-json-rpc-api-service'; import {ICommunicationClient} from './json-rpc-client'; diff --git a/dashboard/src/components/api/json-rpc/json-rpc-client.ts b/dashboard/src/components/api/json-rpc/json-rpc-client.ts index a8b5ef0bcf6e..034376bdbe26 100644 --- a/dashboard/src/components/api/json-rpc/json-rpc-client.ts +++ b/dashboard/src/components/api/json-rpc/json-rpc-client.ts @@ -1,12 +1,12 @@ /* - * Copyright (c) 2015-2017 Codenvy, S.A. + * Copyright (c) 2015-2017 Red Hat, Inc. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Codenvy, S.A. - initial API and implementation + * Red Hat, Inc. - initial API and implementation */ 'use strict'; diff --git a/dashboard/src/components/api/json-rpc/websocket-client.ts b/dashboard/src/components/api/json-rpc/websocket-client.ts index f743f6f2072c..b0c499ea334d 100644 --- a/dashboard/src/components/api/json-rpc/websocket-client.ts +++ b/dashboard/src/components/api/json-rpc/websocket-client.ts @@ -1,12 +1,12 @@ /* - * Copyright (c) 2015-2017 Codenvy, S.A. + * Copyright (c) 2015-2017 Red Hat, Inc. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Codenvy, S.A. - initial API and implementation + * Red Hat, Inc. - initial API and implementation */ 'use strict'; import {ICommunicationClient} from './json-rpc-client'; diff --git a/dashboard/src/components/api/remote/che-remote-workspace.ts b/dashboard/src/components/api/remote/che-remote-workspace.ts index 350188c4808b..4846f4300785 100644 --- a/dashboard/src/components/api/remote/che-remote-workspace.ts +++ b/dashboard/src/components/api/remote/che-remote-workspace.ts @@ -9,8 +9,8 @@ * Red Hat, Inc. - initial API and implementation */ 'use strict'; -import {CheJsonRpcMasterApi} from '../json-rpc/che-json-rpc-master-api.factory'; -import {WebsocketClient} from '../json-rpc/websocket-client'; +import {CheJsonRpcMasterApi} from '../json-rpc/che-json-rpc-master-api'; +import {CheJsonRpcApi} from '../json-rpc/che-json-rpc-api.factory'; interface IRemoteWorkspaceResource extends ng.resource.IResourceClass { create: any; @@ -29,16 +29,15 @@ export class CheRemoteWorkspace { private remoteWorkspaceAPI: IRemoteWorkspaceResource; private cheJsonRpcMasterApi: CheJsonRpcMasterApi; private authData: any; + private cheJsonRpcApi: CheJsonRpcApi; /** * Default constructor that is using resource */ - constructor($resource: ng.resource.IResourceService, $q: ng.IQService, $websocket: ng.websocket.IWebSocketProvider, authData: any) { + constructor($resource: ng.resource.IResourceService, $q: ng.IQService, cheJsonRpcApi: CheJsonRpcApi, authData: any) { this.$resource = $resource; this.$q = $q; - - let websocketClient = new WebsocketClient($websocket, $q); - this.cheJsonRpcMasterApi = new CheJsonRpcMasterApi(websocketClient); + this.cheJsonRpcApi = cheJsonRpcApi; this.authData = authData; // remote call @@ -83,19 +82,16 @@ export class CheRemoteWorkspace { startWorkspace(remoteWsURL: string, workspaceId: string, envName: string): ng.IPromise { let deferred = this.$q.defer(); let deferredPromise = deferred.promise; - this.cheJsonRpcMasterApi.connect(remoteWsURL).then(() => { - this.cheJsonRpcMasterApi.subscribeWorkspaceStatus(workspaceId, (message: any) => { - if (message.eventType === 'RUNNING' && message.workspaceId === workspaceId) { - let promise = this.remoteWorkspaceAPI.getDetails({workspaceId: workspaceId}, {}).$promise; - promise.then((workspace: any) => { - deferred.resolve(workspace); - }, (error: any) => { - deferred.reject(error); - }); - } - }); - }, (error: any) => { - deferred.reject(error); + this.cheJsonRpcMasterApi = this.cheJsonRpcApi.getJsonRpcMasterApi(remoteWsURL); + this.cheJsonRpcMasterApi.subscribeWorkspaceStatus(workspaceId, (message: any) => { + if (message.eventType === 'RUNNING' && message.workspaceId === workspaceId) { + let promise = this.remoteWorkspaceAPI.getDetails({workspaceId: workspaceId}, {}).$promise; + promise.then((workspace: any) => { + deferred.resolve(workspace); + }, (error: any) => { + deferred.reject(error); + }); + } }); this.remoteWorkspaceAPI.startWorkspace({workspaceId: workspaceId, envName : envName}, {}).$promise; diff --git a/dashboard/src/components/api/remote/che-remote.factory.ts b/dashboard/src/components/api/remote/che-remote.factory.ts index 93800fa9ed08..0c317539a09a 100644 --- a/dashboard/src/components/api/remote/che-remote.factory.ts +++ b/dashboard/src/components/api/remote/che-remote.factory.ts @@ -14,6 +14,7 @@ import {CheRemoteLogin} from './che-remote-login'; import {CheRemoteRecipe} from './che-remote-recipe'; import {CheRemoteWorkspace} from './che-remote-workspace'; import {CheRemoteProject} from './che-remote-project'; +import {CheJsonRpcApi} from '../json-rpc/che-json-rpc-api.factory'; /** * This class is handling the call to remote API @@ -22,16 +23,16 @@ import {CheRemoteProject} from './che-remote-project'; export class CheRemote { private $resource: ng.resource.IResourceService; private $q: ng.IQService; - private $websocket: ng.websocket.IWebSocketProvider; + private cheJsonRpcApi: CheJsonRpcApi; /** * Default constructor that is using resource * @ngInject for Dependency injection */ - constructor($resource: ng.resource.IResourceService, $q: ng.IQService, $websocket: ng.websocket.IWebSocketProvider) { + constructor($resource: ng.resource.IResourceService, $q: ng.IQService, cheJsonRpcApi: CheJsonRpcApi) { this.$resource = $resource; this.$q = $q; - this.$websocket = $websocket; + this.cheJsonRpcApi = cheJsonRpcApi; } /** @@ -53,7 +54,7 @@ export class CheRemote { * @returns {*} */ newWorkspace(remoteConfig: any): CheRemoteWorkspace { - return new CheRemoteWorkspace(this.$resource, this.$q, this.$websocket, remoteConfig); + return new CheRemoteWorkspace(this.$resource, this.$q, this.cheJsonRpcApi, remoteConfig); } /**