Skip to content
This repository has been archived by the owner on Jul 19, 2019. It is now read-only.

Set correct che api external enviroment variable. Use official released workspace client. #2

Merged
merged 6 commits into from
Jun 18, 2018
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions browser-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@
"name": "browser-app",
"version": "0.0.1",
"dependencies": {
"@theia/core": "0.3.8",
"@theia/filesystem": "0.3.8",
"@theia/workspace": "0.3.8",
"@theia/preferences": "0.3.8",
"@theia/navigator": "0.3.8",
"@theia/process": "0.3.8",
"@theia/terminal": "0.3.8",
"@theia/editor": "0.3.8",
"@theia/languages": "0.3.8",
"@theia/markers": "0.3.8",
"@theia/monaco": "0.3.8",
"@theia/typescript": "0.3.8",
"@theia/messages": "0.3.8",
"@theia/core": "0.3.10",
"@theia/filesystem": "0.3.10",
"@theia/workspace": "0.3.10",
"@theia/preferences": "0.3.10",
"@theia/navigator": "0.3.10",
"@theia/process": "0.3.10",
"@theia/terminal": "0.3.10",
"@theia/editor": "0.3.10",
"@theia/languages": "0.3.10",
"@theia/markers": "0.3.10",
"@theia/monaco": "0.3.10",
"@theia/typescript": "0.3.10",
"@theia/messages": "0.3.10",
"theia-machines-extension": "0.0.1"
},
"devDependencies": {
"@theia/cli": "0.3.8"
"@theia/cli": "0.3.10"
},
"scripts": {
"prepare": "theia build",
Expand Down
28 changes: 14 additions & 14 deletions electron-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@
"name": "electron-app",
"version": "0.0.1",
"dependencies": {
"@theia/core": "0.3.8",
"@theia/filesystem": "0.3.8",
"@theia/workspace": "0.3.8",
"@theia/preferences": "0.3.8",
"@theia/navigator": "0.3.8",
"@theia/process": "0.3.8",
"@theia/terminal": "0.3.8",
"@theia/editor": "0.3.8",
"@theia/languages": "0.3.8",
"@theia/markers": "0.3.8",
"@theia/monaco": "0.3.8",
"@theia/typescript": "0.3.8",
"@theia/messages": "0.3.8",
"@theia/core": "0.3.10",
"@theia/filesystem": "0.3.10",
"@theia/workspace": "0.3.10",
"@theia/preferences": "0.3.10",
"@theia/navigator": "0.3.10",
"@theia/process": "0.3.10",
"@theia/terminal": "0.3.10",
"@theia/editor": "0.3.10",
"@theia/languages": "0.3.10",
"@theia/markers": "0.3.10",
"@theia/monaco": "0.3.10",
"@theia/typescript": "0.3.10",
"@theia/messages": "0.3.10",
"theia-machines-extension": "0.0.1"
},
"devDependencies": {
"@theia/cli": "0.3.8"
"@theia/cli": "0.3.10"
},
"scripts": {
"prepare": "theia build",
Expand Down
4 changes: 2 additions & 2 deletions theia-machines-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
"src"
],
"dependencies": {
"@theia/core": "0.3.8",
"workspace-client": "https://github.com/akurinnoy/workspace-client"
"@theia/core": "0.3.10",
"@eclipse-che/workspace-client": "0.0.1-1525953185"
},
"devDependencies": {
"rimraf": "2.6.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,30 @@

import {inject, injectable} from 'inversify';
import {IBaseEnvVariablesServer} from '../common/base-env-variables-protocol';
import {getRestApi, getBackend, IRemoteAPI, IBackend} from 'workspace-client';
import WorkspaceClient, {IRemoteAPI, IBackend} from '@eclipse-che/workspace-client';

@injectable()
export class CheWorkspaceClientService {

private cheApi: string;
private cheApiPromise: Promise<string>;
private _backend: IBackend;

constructor(@inject(IBaseEnvVariablesServer) protected readonly baseEnvVariablesServer: IBaseEnvVariablesServer) {
this.baseEnvVariablesServer.getEnvValueByKey('CHE_API').then((cheApi: string) => {
this.cheApi = cheApi;
});
this._backend = getBackend();
this.cheApiPromise = this.baseEnvVariablesServer.getEnvValueByKey('CHE_API_EXTERNAL');
this._backend = WorkspaceClient.getRestBackend();
}

get restClient(): IRemoteAPI {
return getRestApi({
baseUrl: this.cheApi
});
get restClient(): Promise<IRemoteAPI> {
return new Promise<IRemoteAPI>((resolve, reject) => {
this.cheApiPromise.then(cheApi => {
const remoteApi = WorkspaceClient.getRestApi({
baseUrl: cheApi
});
resolve(remoteApi);
}).catch(err => {
reject("Unable to get CHE api endPoint.");
});
})
}

get backend(): IBackend {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@
*/

import {injectable, inject} from 'inversify';
import {IWorkspace, IRequestError} from 'workspace-client';
import {IWorkspace} from '@eclipse-che/workspace-client';
import {CheWorkspaceClientService} from './che-workspace-client-service';
import {IBaseEnvVariablesServer} from '../common/base-env-variables-protocol';

export interface IWorkspaceMachine {
machineName?: string;
servers?: {
[serverRef: string]: {
url?: string;
port?: string;
}
};
status: string;
servers?: {
[serverRef: string]: {
url?: string;
port?: string;
}
};
status: string;
}

@injectable()
Expand All @@ -41,34 +41,35 @@ export class CheWorkspaceMachinesService {


async updateMachines(): Promise<Array<IWorkspaceMachine>> {
if (!this.workspaceId) {
return Promise.reject('Failed to get workspaceId');
}
this.runtimeMachines.length = 0;
const restClient = await this.cheWorkspaceClient.restClient;

return new Promise<Array<IWorkspaceMachine>>((resolve, reject) => {
this.cheWorkspaceClient.restClient.getById<IWorkspace>(this.workspaceId)
.catch((reason: IRequestError) => {
reject(`Failed to get workspace by ID:${this.workspaceId}, Status code: ${reason.status}`);
})
.then((workspace: IWorkspace) => {
if (workspace && workspace.runtime) {
Object.keys(workspace.runtime.machines).forEach((machineName: string) => {
const machine: IWorkspaceMachine = workspace.runtime.machines[machineName];
machine.machineName = machineName;
this.runtimeMachines.push(machine);
});
} else {
// in the case without workspace runtime
const workspaceMachines = workspace.config.environments[workspace.config.defaultEnv].machines;
Object.keys(workspaceMachines).forEach((machineName: string) => {
const machine: IWorkspaceMachine = workspaceMachines[machineName];
machine.machineName = machineName;
this.runtimeMachines.push(machine);
});
if (!this.workspaceId) {
return reject('Failed to get workspaceId');
}
this.runtimeMachines.length = 0;

restClient.getById<IWorkspace>(this.workspaceId)
.then((workspace: IWorkspace) => {
if (workspace && workspace.runtime) {
for (const machineName in workspace.runtime.machines) {
const machine: IWorkspaceMachine = workspace.runtime.machines[machineName];
machine.machineName = machineName;
this.runtimeMachines.push(machine);
}
resolve(this.runtimeMachines);
});
} else {
// in the case without workspace runtime
const workspaceMachines = workspace.config.environments[workspace.config.defaultEnv].machines;
Object.keys(workspaceMachines).forEach((machineName: string) => {
const machine: IWorkspaceMachine = workspaceMachines[machineName];
machine.machineName = machineName;
this.runtimeMachines.push(machine);
});
}
resolve(this.runtimeMachines);
}).catch(error => {
reject(`Failed to get workspace by ID:${this.workspaceId}, error`);
})
});
}

Expand Down
30 changes: 15 additions & 15 deletions theia-machines-extension/src/browser/machines-view-contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ export class MachinesViewContribution extends AbstractViewContribution<MachinesV

machines.forEach(machine => {
const machineEntry = {
name: machine.machineName,
id: this.getRandId(machine.machineName),
name,
id: this.getRandId(machine.machineName || ""),
parentId: undefined,
kind: machine.status ? SymbolKind.Machine : SymbolKind.Empty
};
Expand All @@ -99,7 +99,7 @@ export class MachinesViewContribution extends AbstractViewContribution<MachinesV
if (status) {
entries.push({
name: status,
id: this.getRandId(machine.machineName, 'status'),
id: this.getRandId(machine.machineName || "", 'status'),
parentId: machineEntry.id
});
}
Expand Down Expand Up @@ -132,15 +132,15 @@ export class MachinesViewContribution extends AbstractViewContribution<MachinesV
});
}
/*
// TODO: Add terminal's call if it terminal node.
const terminalEntryName = 'terminal';
entries.push({
name: terminalEntryName,
id: this.getRandId(terminalEntryName),
parentId: machineEntry.id,
kind: SymbolKind.Terminal
});
*/
// TODO: Add terminal's call if it terminal node.
const terminalEntryName = 'terminal';
entries.push({
name: terminalEntryName,
id: this.getRandId(terminalEntryName),
parentId: machineEntry.id,
kind: SymbolKind.Terminal
});
*/
});

this.machineViewService.publish(this.createTree(undefined, entries));
Expand All @@ -159,7 +159,7 @@ export class MachinesViewContribution extends AbstractViewContribution<MachinesV
}

protected convertToNode(symbol: SymbolInformation, parent: NodeAndSymbol | undefined): NodeAndSymbol {
const iconClass = this.getClass(symbol.kind);
const iconClass = this.getClass(symbol.kind) || "";
const node: MachinesSymbolInformationNode = {
children: [],
id: symbol.id,
Expand All @@ -175,7 +175,7 @@ export class MachinesViewContribution extends AbstractViewContribution<MachinesV
}

private getRandId(nodeName: string, key?: string): string {
let uniqueId: string;
let uniqueId: string = "";
let name = key ? `${nodeName}_${key}` : nodeName;
for (let counter = 0; counter < 100; counter++) {
uniqueId = `${name}_id_${('0000' + (Math.random() * Math.pow(36, 4) << 0).toString(36)).slice(-4)}`;
Expand All @@ -187,7 +187,7 @@ export class MachinesViewContribution extends AbstractViewContribution<MachinesV
return uniqueId;
}

private getClass(symbolKind: SymbolKind): string | undefined {
private getClass(symbolKind: SymbolKind | undefined): string | undefined {
switch (symbolKind) {
case SymbolKind.Empty:
return EMPTY_CLASS;
Expand Down
2 changes: 1 addition & 1 deletion theia-machines-extension/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"compilerOptions": {
"strict": false,
"strict": true,
"experimentalDecorators": true,
"noUnusedLocals": true,
"emitDecoratorMetadata": true,
Expand Down