diff --git a/dashboard/src/app/workspaces/workspaces.service.spec.ts b/dashboard/src/app/workspaces/workspaces.service.spec.ts
new file mode 100644
index 0000000000..aaeec79d33
--- /dev/null
+++ b/dashboard/src/app/workspaces/workspaces.service.spec.ts
@@ -0,0 +1,167 @@
+/*
+ * Copyright (c) 2015-2018 Red Hat, Inc.
+ * This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License 2.0
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ */
+'use strict';
+
+import {CheWorkspace} from '../../components/api/workspace/che-workspace.factory';
+import {WorkspacesService} from './workspaces.service';
+
+/**
+ * WorkspacesService tests.
+ *
+ * @author Oleksii Orel
+ */
+describe(`WorkspacesService >`, () => {
+
+ /**
+ * Service to test.
+ */
+ let workspacesService: WorkspacesService;
+ let cheWorkspace: CheWorkspace;
+
+ function getCHE6Workspace(recipeType?: string): che.IWorkspace {
+ return {
+ 'namespace': 'che',
+ 'status': 'RUNNING',
+ 'config': {
+ 'attributes': {},
+ 'environments': {
+ 'default': {
+ 'recipe': {
+ 'type': recipeType ? recipeType : 'dockerimage',
+ 'content': 'eclipse/ubuntu_jdk8'
+ },
+ 'machines': {
+ 'dev-machine': {
+ 'env': {},
+ 'volumes': {},
+ 'installers': [
+ 'org.eclipse.che.exec',
+ 'org.eclipse.che.terminal'
+ ],
+ 'servers': {
+ 'tomcat8-debug': {'protocol': 'http', 'port': '8000'},
+ 'codeserver': {'protocol': 'http', 'port': '9876'},
+ 'tomcat8': {'protocol': 'http', 'port': '8080'}
+ },
+ 'attributes': {'memoryLimitBytes': '2147483648'}
+ }
+ }
+ }
+ }, 'projects': [], 'commands': [], 'defaultEnv': 'default', 'name': 'wksp-98cs'
+ },
+ 'temporary': false,
+ 'links': {
+ 'self': '...Fake self link...',
+ 'ide': '...Fake ide link...'
+ },
+ 'id': 'workspacezbkov1e8qcm00dli',
+ 'attributes': {
+ 'created': 1516282666658,
+ 'stackId': '...Fake stack id...'
+ }
+ };
+ }
+
+ function getCHE7Workspace(recipeType?: string): che.IWorkspace {
+ return {
+ 'namespace': 'che',
+ 'status': 'RUNNING',
+ 'config': {
+ 'defaultEnv': 'default',
+ 'environments': {
+ 'default': {
+ 'machines': {},
+ 'recipe': {
+ 'type': recipeType ? recipeType : 'kubernetes',
+ 'content': '...Fake recipe content...',
+ 'contentType': '...Fake recipe contentType...'
+ }
+ }
+ },
+ 'attributes': {
+ 'editor': 'eclipse/che-theia/0.0.1',
+ 'plugins': 'eclipse/che-machine-exec-plugin/0.0.1'
+ },
+ 'projects': [],
+ 'name': 'wksp-7znm',
+ 'commands': []
+ },
+ 'temporary': false,
+ 'links': {
+ 'self': '...Fake self link...',
+ 'ide': '...Fake ide link...'
+ },
+ 'id': 'workspacezbkov1e8qcm00dli',
+ 'attributes': {
+ 'created': 1516282666658,
+ 'stackId': '...Fake stack id...'
+ }
+ };
+ }
+
+ /**
+ * Setup module
+ */
+ beforeEach(() => {
+ angular.mock.module('userDashboard');
+ });
+
+ beforeEach(() => {
+ angular.module('workspacesServiceMock', [])
+ .service('cheWorkspace', function () {
+ this.getSupportedRecipeTypes = (): string[] => {
+ return ['kubernetes','dockerimage','no-environment'];
+ }
+ });
+ angular.mock.module('workspacesServiceMock');
+ });
+
+ beforeEach(inject((_workspacesService_: WorkspacesService,
+ _cheWorkspace_: CheWorkspace) => {
+ cheWorkspace = _cheWorkspace_;
+ workspacesService = _workspacesService_;
+ }));
+
+ describe(`supported workspace version >`, () => {
+
+ it(`should support a CHE7 workspace >`, () => {
+ const newCHE7Workspace = getCHE7Workspace();
+ expect(workspacesService.isSupported(newCHE7Workspace)).toBeTruthy();
+ expect(workspacesService.isSupportedVersion(newCHE7Workspace)).toBeTruthy();
+ });
+
+ it(`shouldn't support a CHE6 workspace >`, () => {
+ const oldCHE6Workspace = getCHE6Workspace();
+ expect(workspacesService.isSupported(oldCHE6Workspace)).toBeFalsy();
+ expect(workspacesService.isSupportedVersion(oldCHE6Workspace)).toBeFalsy();
+ });
+
+ });
+
+ describe(`supported recipe type >`, () => {
+
+ it(`should support a default recipe type >`, () => {
+ const newCHE7Workspace = getCHE7Workspace();
+ expect(workspacesService.isSupported(newCHE7Workspace)).toBeTruthy();
+ expect(workspacesService.isSupportedRecipeType(newCHE7Workspace)).toBeTruthy();
+ });
+
+ it(`shouldn't support a fake recipe type >`, () => {
+ const recipeType = '...Fake recipeType...';
+ const newCHE7Workspace = getCHE7Workspace(recipeType);
+ expect(workspacesService.isSupported(newCHE7Workspace)).toBeFalsy();
+ expect(workspacesService.isSupportedRecipeType(newCHE7Workspace)).toBeFalsy();
+ });
+
+ });
+
+});
diff --git a/dashboard/src/app/workspaces/workspaces.service.ts b/dashboard/src/app/workspaces/workspaces.service.ts
index 2c4bb7152b..f7e4c41604 100644
--- a/dashboard/src/app/workspaces/workspaces.service.ts
+++ b/dashboard/src/app/workspaces/workspaces.service.ts
@@ -13,6 +13,8 @@
import {CheWorkspace} from '../../components/api/workspace/che-workspace.factory';
+const MINIMAL_SUPORTED_VERSION = 7;
+
/**
* This is a helper class for workspaces.
*
@@ -42,7 +44,7 @@ export class WorkspacesService {
* @param {string=} envName environment name
* @returns {boolean}
*/
- isSupported(workspace: che.IWorkspace, envName?: string): boolean {
+ isSupportedRecipeType(workspace: che.IWorkspace, envName?: string): boolean {
if (workspace.config) {
envName = envName || workspace.config.defaultEnv;
const supportedRecipeTypes = this.cheWorkspace.getSupportedRecipeTypes(),
@@ -52,4 +54,45 @@ export class WorkspacesService {
return true;
}
}
+
+ /**
+ * Returns `true` if supported.
+ * @param {che.IWorkspace} workspace
+ * @param {string=} envName environment name
+ * @returns {boolean}
+ */
+ isSupported(workspace: che.IWorkspace, envName?: string): boolean {
+ envName = envName || workspace.config.defaultEnv;
+
+ return this.isSupportedRecipeType(workspace, envName) && this.isSupportedVersion(workspace);
+ }
+
+ /**
+ * Returns `true` if supported in the current version of the product.
+ * @param {che.IWorkspace} workspace
+ * @returns {boolean}
+ */
+ isSupportedVersion(workspace: che.IWorkspace): boolean {
+ if (!workspace || !workspace.config) {
+ return false;
+ }
+ const config = workspace.config;
+ const machines = config.environments[config.defaultEnv];
+
+ let version: number;
+ if (!Object.keys(machines).length || config.attributes.editor || config.attributes.plugins) {
+ version = 7;
+ } else {
+ for (const key in machines) {
+ const installers = machines[key].installers;
+ if (installers && installers.length !== 0) {
+ version = 6;
+ break;
+ }
+ }
+ }
+
+ return version && version >= MINIMAL_SUPORTED_VERSION;
+ }
+
}
diff --git a/dashboard/src/components/api/environment/compose-environment-manager.spec.ts b/dashboard/src/components/api/environment/compose-environment-manager.spec.ts
index 277ba00077..f7ed00daeb 100644
--- a/dashboard/src/components/api/environment/compose-environment-manager.spec.ts
+++ b/dashboard/src/components/api/environment/compose-environment-manager.spec.ts
@@ -51,7 +51,6 @@ describe('ComposeEnvironmentManager', () => {
'volumes': {
'volume1': {'path': '/some/path'}
},
- 'installers': ['org.eclipse.che.ws-agent', 'org.eclipse.che.terminal', 'org.eclipse.che.ssh']
}
},
'recipe': {
@@ -78,15 +77,6 @@ describe('ComposeEnvironmentManager', () => {
expect(servers).toEqual(expectedServers);
});
-
- it('at least one machine should contain \'ws-agent\'', () => {
- let devMachinesList = machines.filter((machine: IEnvironmentManagerMachine) => {
- return envManager.isDev(machine);
- });
-
- expect(devMachinesList.length).toBeGreaterThan(0);
- });
-
});
describe('for recipe from content', () => {
@@ -113,8 +103,7 @@ describe('ComposeEnvironmentManager', () => {
'volumes': {
'vol1': {'path': '/some/path'},
'm22': {'path': '/home/user/.m2/repository'}
- },
- 'installers': ['org.eclipse.che.ws-agent', 'org.eclipse.che.terminal', 'org.eclipse.che.ssh']
+ }
}
},
'recipe': {
@@ -197,7 +186,6 @@ describe('ComposeEnvironmentManager', () => {
'dev-machine': {
'servers': {},
'volumes': {},
- 'installers': ['org.eclipse.che.ws-agent', 'org.eclipse.che.terminal', 'org.eclipse.che.ssh'],
'attributes': {'memoryLimitBytes': '2147483648'}
}
},
diff --git a/dashboard/src/components/api/environment/docker-file-environment-manager.spec.ts b/dashboard/src/components/api/environment/docker-file-environment-manager.spec.ts
index c66614f62b..96e761fa6a 100644
--- a/dashboard/src/components/api/environment/docker-file-environment-manager.spec.ts
+++ b/dashboard/src/components/api/environment/docker-file-environment-manager.spec.ts
@@ -31,7 +31,6 @@ describe('If recipe has content', () => {
'attributes': {'memoryLimitBytes': '2147483648'},
'servers': {},
'volumes': {},
- 'installers': ['org.eclipse.che.ws-agent', 'org.eclipse.che.terminal', 'org.eclipse.che.ssh']
}
},
'recipe': {
@@ -73,12 +72,6 @@ describe('If recipe has content', () => {
expect(source).toEqual(expectedSource);
});
- it('the machine should be a dev machine', () => {
- let isDev = envManager.isDev(machines[0]);
-
- expect(isDev).toBe(true);
- });
-
it('should update environment\'s recipe via machine\'s source', () => {
let oldMachines = envManager.getMachines(environment),
oldSource = envManager.getSource(oldMachines[0]),
@@ -109,7 +102,6 @@ describe('If recipe has location', () => {
'dev-machine': {
'servers': {},
'volumes': {},
- 'installers': ['org.eclipse.che.ws-agent', 'org.eclipse.che.terminal', 'org.eclipse.che.ssh'],
'attributes': {'memoryLimitBytes': '2147483648'}
}
},
@@ -151,12 +143,6 @@ describe('If recipe has location', () => {
expect(source).toEqual(null);
});
- it('the machine should be a dev machine', () => {
- let isDev = envManager.isDev(machines[0]);
-
- expect(isDev).toBe(true);
- });
-
});
});
diff --git a/dashboard/src/components/api/environment/docker-image-environment-manager.spec.ts b/dashboard/src/components/api/environment/docker-image-environment-manager.spec.ts
index ed6508fb89..a3b7abcc2b 100644
--- a/dashboard/src/components/api/environment/docker-image-environment-manager.spec.ts
+++ b/dashboard/src/components/api/environment/docker-image-environment-manager.spec.ts
@@ -40,7 +40,7 @@ describe('DockerImageEnvironmentManager', () => {
'volume1': {
'path': '/123'
}
- }, 'installers': ['ws-agent', 'org.eclipse.che.ws-agent'], 'attributes': {'memoryLimitBytes': '16642998272'}
+ }, 'attributes': {'memoryLimitBytes': '16642998272'}
}
}, 'recipe': {'content': 'codenvy/ubuntu_jdk8', 'type': 'dockerimage'}
};
@@ -73,12 +73,6 @@ describe('DockerImageEnvironmentManager', () => {
expect(memoryLimit.toString()).toEqual(expectedMemoryLimit.toString());
});
- it('the machine should be a dev machine', () => {
- let isDev = envManager.isDev(machines[0]);
-
- expect(isDev).toBe(true);
- });
-
it('should update environment\'s recipe via machine\'s source', () => {
let machines = envManager.getMachines(environment),
newSource = 'eclipse/node';
diff --git a/dashboard/src/components/api/environment/kubernetes-environment-manager.spec.ts b/dashboard/src/components/api/environment/kubernetes-environment-manager.spec.ts
index 89e9953586..2f74fe067b 100644
--- a/dashboard/src/components/api/environment/kubernetes-environment-manager.spec.ts
+++ b/dashboard/src/components/api/environment/kubernetes-environment-manager.spec.ts
@@ -56,7 +56,7 @@ describe('KubernetesEnvironmentManager', () => {
'volume1': {
'path': '/123'
}
- }, 'installers': ['org.eclipse.che.ws-agent'], 'attributes': {'memoryLimitBytes': '16642998272'}
+ }, 'attributes': {'memoryLimitBytes': '16642998272'}
}
}, 'recipe': {
'contentType': 'application/x-yaml',
@@ -92,12 +92,6 @@ describe('KubernetesEnvironmentManager', () => {
expect(memoryLimit.toString()).toEqual(expectedMemoryLimit.toString());
});
- it(`the machine should be a dev machine`, () => {
- let isDev = envManager.isDev(machines[0]);
-
- expect(isDev).toBe(true);
- });
-
it(`should update environment's recipe via machine's source`, () => {
const machines = envManager.getMachines(environment);
const newSource = 'eclipse/node';
@@ -142,7 +136,7 @@ describe('KubernetesEnvironmentManager', () => {
'volume1': {
'path': '/123'
}
- }, 'installers': ['org.eclipse.che.ws-agent'], 'attributes': {'memoryLimitBytes': '16642998272'}
+ }, 'attributes': {'memoryLimitBytes': '16642998272'}
}
}, 'recipe': {
'contentType': 'application/x-yaml',
@@ -178,12 +172,6 @@ describe('KubernetesEnvironmentManager', () => {
expect(memoryLimit.toString()).toEqual(expectedMemoryLimit.toString());
});
- it(`the machine should be a dev machine`, () => {
- let isDev = envManager.isDev(machines[0]);
-
- expect(isDev).toBe(true);
- });
-
it(`should update environment's recipe via machine's source`, () => {
const machines = envManager.getMachines(environment);
const newSource = 'eclipse/node';
diff --git a/dashboard/src/components/api/workspace/che-workspace.factory.ts b/dashboard/src/components/api/workspace/che-workspace.factory.ts
index c4b34dac6b..f76f7a118c 100644
--- a/dashboard/src/components/api/workspace/che-workspace.factory.ts
+++ b/dashboard/src/components/api/workspace/che-workspace.factory.ts
@@ -25,11 +25,6 @@ import {WorkspaceDataManager} from './workspace-data-manager';
const WS_AGENT_HTTP_LINK: string = 'wsagent/http';
const WS_AGENT_WS_LINK: string = 'wsagent/ws';
-interface IWorkspaceSettings {
- supportedRecipeTypes: string;
- cheWorkspacePluginRegistryUrl: string;
-}
-
interface ICHELicenseResource
extends ng.resource.IResourceClass {
create: any;
createWithNamespace: any;
@@ -42,7 +37,7 @@ interface ICHELicenseResource extends ng.resource.IResourceClass {
startWorkspaceWithNoEnvironment: any;
startTemporaryWorkspace: any;
addCommand: any;
- getSettings: () => ng.resource.IResource;
+ getSettings: () => ng.resource.IResource;
}
export enum WorkspaceStatus {
@@ -79,7 +74,7 @@ export class CheWorkspace {
private remoteWorkspaceAPI: ICHELicenseResource;
private lodash: any;
private statusDefers: Object;
- private workspaceSettings: any;
+ private workspaceSettings: che.IWorkspaceSettings;
private jsonRpcApiLocation: string;
private workspaceLoaderUrl: string;
/**
@@ -89,9 +84,9 @@ export class CheWorkspace {
/**
* Map with promises.
*/
- private workspacePromises: Map> = new Map();
+ private workspacePromises: Map> = new Map();
/**
- *
+ *
*/
private workspaceDataManager: WorkspaceDataManager;
@@ -392,7 +387,7 @@ export class CheWorkspace {
}
const defer = this.$q.defer();
const promise: ng.IHttpPromise = this.$http.get('/api/workspace/' + workspaceKey);
- this.workspacePromises.set(workspacePromisesKey, promise);
+ this.workspacePromises.set(workspacePromisesKey, defer.promise);
promise.then((response: ng.IHttpPromiseCallbackArg) => {
const workspace = response.data;
@@ -461,8 +456,7 @@ export class CheWorkspace {
'recipe': null,
'machines': {
'dev-machine': {
- 'attributes': {'memoryLimitBytes': ram},
- 'installers': ['org.eclipse.che.ws-agent', 'org.eclipse.che.exec', 'org.eclipse.che.terminal', 'org.eclipse.che.ssh']
+ 'attributes': {'memoryLimitBytes': ram}
}
}
};
@@ -494,8 +488,7 @@ export class CheWorkspace {
devMachine = {
'name': 'ws-machine',
'attributes': {'memoryLimitBytes': ram},
- 'type': 'docker',
- 'installers': ['org.eclipse.che.ws-agent', 'org.eclipse.che.exec', 'org.eclipse.che.terminal', 'org.eclipse.che.ssh']
+ 'type': 'docker'
};
defaultEnvironment.machines[devMachine.name] = devMachine;
} else {
@@ -583,8 +576,8 @@ export class CheWorkspace {
/**
* Notify user if workspace is ephemeral.
- *
- * @param workspaceId
+ *
+ * @param workspaceId
*/
notifyIfEphemeral(workspaceId: string): void {
let workspace = this.workspacesById.get(workspaceId);
@@ -762,7 +755,7 @@ export class CheWorkspace {
*/
fetchWorkspaceSettings(): ng.IPromise {
const promise = this.remoteWorkspaceAPI.getSettings().$promise;
- return promise.then((settings: IWorkspaceSettings) => {
+ return promise.then((settings: che.IWorkspaceSettings) => {
this.workspaceSettings = settings;
return this.workspaceSettings;
}, (error: any) => {
@@ -791,7 +784,7 @@ export class CheWorkspace {
*
* @returns {any} the system settings for workspaces
*/
- getWorkspaceSettings(): IWorkspaceSettings {
+ getWorkspaceSettings(): che.IWorkspaceSettings {
return this.workspaceSettings;
}
diff --git a/dashboard/src/components/typings/che.d.ts b/dashboard/src/components/typings/che.d.ts
index 76b778adda..eb918f0251 100755
--- a/dashboard/src/components/typings/che.d.ts
+++ b/dashboard/src/components/typings/che.d.ts
@@ -301,6 +301,12 @@ declare namespace che {
usedResources?: string;
}
+ export interface IWorkspaceSettings {
+ supportedRecipeTypes: string;
+ cheWorkspacePluginRegistryUrl: string;
+ [propName: string]: string | boolean;
+ }
+
export interface IWorkspaceAttributes {
created: number;
updated?: number;