Skip to content
This repository has been archived by the owner on Apr 4, 2023. It is now read-only.

Commit

Permalink
feat(che-server): Move access to che-server through a set of interfac…
Browse files Browse the repository at this point in the history
…es with an implementation for che-server

eclipse-che/che#17901
It should allow then to implement other ways of grabbing workspace details, etc.
Change-Id: I6c6a6b9d02c3e22dd114dfa53f10456fef3dd0a7
Signed-off-by: Florent Benoit <fbenoit@redhat.com>
  • Loading branch information
benoitf committed Oct 8, 2020
1 parent 27034b2 commit ffdacc2
Show file tree
Hide file tree
Showing 72 changed files with 1,057 additions and 831 deletions.
1 change: 1 addition & 0 deletions che-theia-init-sources.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ sources:
- extensions/eclipse-che-theia-file-sync-tracker
- extensions/eclipse-che-theia-cli-endpoint
- extensions/eclipse-che-theia-workspace
- extensions/eclipse-che-theia-remote-api
plugins:
- plugins/containers-plugin
- plugins/workspace-plugin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
"@theia/core": "next",
"@theia/plugin-dev": "next",
"@theia/plugin-ext": "next",
"@eclipse-che/workspace-client": "latest",
"@eclipse-che/api": "latest"
"@eclipse-che/theia-remote-api": "^0.0.1"
},
"scripts": {
"prepare": "yarn clean && yarn build",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,18 @@
* SPDX-License-Identifier: EPL-2.0
**********************************************************************/

import { injectable } from 'inversify';
import { injectable, inject } from 'inversify';
import URI from '@theia/core/lib/common/uri';
import { HostedPluginUriPostProcessor } from '@theia/plugin-dev';
import WorkspaceClient, { IRemoteAPI } from '@eclipse-che/workspace-client';
import { che } from '@eclipse-che/api';
import { Endpoint, WorkspaceService } from '@eclipse-che/theia-remote-api/lib/common/workspace-service';

@injectable()
export class CheWorkspaceHostedPluginUriPostProcessor implements HostedPluginUriPostProcessor {

protected restApiClient: IRemoteAPI;
@inject(WorkspaceService)
protected workspaceService: WorkspaceService;

constructor() {
this.restApiClient = WorkspaceClient.getRestApi({
baseUrl: process.env.CHE_API,
machineToken: process.env.CHE_MACHINE_TOKEN
});
}

async processUri(uri: URI): Promise<URI> {
Expand All @@ -36,11 +32,11 @@ export class CheWorkspaceHostedPluginUriPostProcessor implements HostedPluginUri
}

/**
* Searches for server which exposes hosted Theia instance.
* The server label is the attribute "type": "ide-dev".
* Searches for endpoint which exposes hosted Theia instance.
* The endpoint label is the attribute "type": "ide-dev".
*/
protected async getHostedPluginTheiaInstanceServer(): Promise<che.workspace.Server | undefined> {
const workspace = await this.getCurrentWorkspace();
protected async getHostedPluginTheiaInstanceServer(): Promise<Endpoint | undefined> {
const workspace = await this.workspaceService.currentWorkspace();
if (!workspace.runtime) {
throw new Error('Workspace is not running.');
}
Expand All @@ -64,14 +60,6 @@ export class CheWorkspaceHostedPluginUriPostProcessor implements HostedPluginUri
return undefined;
}

protected getCurrentWorkspace(): Promise<che.workspace.Workspace> {
const workspaceId = process.env.CHE_WORKSPACE_ID;
if (!workspaceId) {
throw new Error('Environment variable CHE_WORKSPACE_ID is not set.');
}
return this.restApiClient.getById<che.workspace.Workspace>(workspaceId);
}

async processOptions(options: object): Promise<object> {
return options;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

import { injectable, inject } from 'inversify';
import { ActivityTrackerService } from '../common/activity-tracker-protocol';
import { CheApiService } from '@eclipse-che/theia-plugin-ext/lib/common/che-protocol';
import { TelemetryService } from '@eclipse-che/theia-remote-api/lib/common/telemetry-service';
import { WorkspaceService } from '@eclipse-che/theia-remote-api/lib/common/workspace-service';

/**
* Server side part of Theia activity tracker.
Expand All @@ -41,8 +42,11 @@ export class ActivityTrackerServiceImpl implements ActivityTrackerService {
// Flag which is used to check if new requests were received during timer awaiting.
private isNewRequest: boolean;

@inject(CheApiService)
protected cheApiService: CheApiService;
@inject(WorkspaceService)
protected workspaceService: WorkspaceService;

@inject(TelemetryService)
protected telemetryService: TelemetryService;

constructor() {
this.isTimerRunning = false;
Expand Down Expand Up @@ -78,9 +82,9 @@ export class ActivityTrackerServiceImpl implements ActivityTrackerService {
}

private sendRequest(attemptsLeft: number = ActivityTrackerServiceImpl.RETRY_COUNT): void {
this.cheApiService.submitTelemetryActivity();
this.telemetryService.submitTelemetryActivity();
try {
this.cheApiService.updateWorkspaceActivity();
this.workspaceService.updateWorkspaceActivity();
} catch (error) {
if (attemptsLeft > 0) {
setTimeout(() => this.sendRequest(), ActivityTrackerServiceImpl.RETRY_REQUEST_PERIOD_MS, --attemptsLeft);
Expand Down
2 changes: 1 addition & 1 deletion extensions/eclipse-che-theia-dashboard/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"dependencies": {
"@eclipse-che/api": "latest",
"@theia/core": "next",
"@eclipse-che/theia-plugin-ext": "^0.0.1"
"@eclipse-che/theia-remote-api": "^0.0.1"
},
"scripts": {
"prepare": "yarn clean && yarn build",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@

import { injectable, inject } from 'inversify';
import { FrontendApplicationContribution, FrontendApplication } from '@theia/core/lib/browser';
import { EnvVariablesServer, EnvVariable } from '@theia/core/lib/common/env-variables';
import { FrontendApplicationStateService } from '@theia/core/lib/browser/frontend-application-state';
import { CheApiService } from '@eclipse-che/theia-plugin-ext/lib/common/che-protocol';
import { WorkspaceService } from '@eclipse-che/theia-remote-api/lib/common/workspace-service';
import '../../src/browser/style/che-theia-dashboard-module.css';

const THEIA_ICON_ID = 'theia:icon';
Expand All @@ -25,11 +24,10 @@ export class TheiaDashboardClient implements FrontendApplicationContribution {

private isExpanded: boolean = false;

@inject(CheApiService)
private cheApi: CheApiService;
@inject(WorkspaceService)
private workspaceService: WorkspaceService;

constructor(
@inject(EnvVariablesServer) private readonly envVariablesServer: EnvVariablesServer,
@inject(FrontendApplicationStateService) protected readonly frontendApplicationStateService: FrontendApplicationStateService,
) {
this.frontendApplicationStateService.reachedState('ready').then(() => this.onReady());
Expand Down Expand Up @@ -80,17 +78,7 @@ export class TheiaDashboardClient implements FrontendApplicationContribution {
}

async getIdeUrl(): Promise<string | undefined> {
const envVariables: EnvVariable[] = await this.envVariablesServer.getVariables();
if (!envVariables) {
return undefined;
}
const workspaceIdEnvVar = envVariables.find(envVariable =>
envVariable.name === 'CHE_WORKSPACE_ID');
if (!workspaceIdEnvVar || !workspaceIdEnvVar.value) {
return undefined;
}

const workspace = await this.cheApi.currentWorkspace();
const workspace = await this.workspaceService.currentWorkspace();

if (workspace && workspace.links && workspace.links.ide) {
return workspace.links.ide;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
],
"dependencies": {
"@theia/core": "next",
"@eclipse-che/theia-plugin-ext": "^0.0.1"
"@eclipse-che/theia-remote-api": "^0.0.1"
},
"scripts": {
"prepare": "yarn clean && yarn build",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { injectable, inject } from 'inversify';
import { FrontendApplicationContribution } from '@theia/core/lib/browser';
import { MessageService } from '@theia/core/lib/common';
import { StatusBar, StatusBarAlignment, StatusBarEntry } from '@theia/core/lib/browser/status-bar/status-bar';
import { CheApiService } from '@eclipse-che/theia-plugin-ext/lib/common/che-protocol';
import { WorkspaceService } from '@eclipse-che/theia-remote-api/lib/common/workspace-service';
import URI from '@theia/core/lib/common/uri';
import ReconnectingWebSocket from 'reconnecting-websocket';
import { DisposableCollection, Disposable } from '@theia/core';
Expand All @@ -30,8 +30,8 @@ export class SyncProcessTracker implements FrontendApplicationContribution {
private statusBar: StatusBar;
@inject(MessageService)
protected readonly messageService: MessageService;
@inject(CheApiService)
protected cheApiService: CheApiService;
@inject(WorkspaceService)
protected workspaceService: WorkspaceService;
private readonly ID = 'file-synchronization-indicator-id';
protected readonly statusBarDisposable = new DisposableCollection();

Expand All @@ -44,7 +44,7 @@ export class SyncProcessTracker implements FrontendApplicationContribution {
}

async getSyncServiceURL(): Promise<string> {
const server = await this.cheApiService.findUniqueServerByAttribute('type', 'rsync');
const server = await this.workspaceService.findUniqueEndpointByAttribute('type', 'rsync');
if (server) {
return new URI(server.url).resolve('track').toString();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@
import { injectable, inject, postConstruct } from 'inversify';
import { FrontendApplicationContribution, CommonCommands } from '@theia/core/lib/browser';
import { StatusBar, StatusBarAlignment } from '@theia/core/lib/browser/status-bar/status-bar';
import { CheApiService } from '@eclipse-che/theia-plugin-ext/lib/common/che-protocol';
import { CheGitService, GIT_USER_EMAIL, GIT_USER_NAME } from '../common/git-protocol';
import { CheGitClientImpl } from './git-config-changes-tracker';
import { UserService } from '@eclipse-che/theia-remote-api/lib/common/user-service';

@injectable()
export class CheTheiaStatusBarFrontendContribution implements FrontendApplicationContribution {

@inject(StatusBar)
private statusBar: StatusBar;

@inject(CheApiService)
protected cheApiService: CheApiService;
@inject(UserService)
protected userService: UserService;

@inject(CheGitService)
protected gitService: CheGitService;
Expand All @@ -49,7 +49,7 @@ export class CheTheiaStatusBarFrontendContribution implements FrontendApplicatio
}

checkGitCommiterSettings(): void {
this.cheApiService.getUserPreferences('theia-user-preferences').then(async chePreferences => {
this.userService.getUserPreferences('theia-user-preferences').then(async chePreferences => {
const theiaPreferences = JSON.parse(chePreferences['theia-user-preferences'] ? chePreferences['theia-user-preferences'] : '{}');
const email = theiaPreferences[GIT_USER_EMAIL];
const name = theiaPreferences[GIT_USER_NAME];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ import * as ws from 'ws';
import { inject, injectable, Container } from 'inversify';
import URI from '@theia/core/lib/common/uri';
import { MessagingContribution } from '@theia/core/lib/node/messaging/messaging-contribution';
import { CheApiService } from '@eclipse-che/theia-plugin-ext/lib/common/che-protocol';
import { WorkspaceService } from '@eclipse-che/theia-remote-api/lib/common/workspace-service';

@injectable()
export class CheMessagingContribution extends MessagingContribution {

private connectionContainers: Set<Container> = new Set();
private connectionContainersMap: Map<ws, Container> = new Map();

@inject(CheApiService)
protected cheApiService: CheApiService;
@inject(WorkspaceService)
protected workspaceService: WorkspaceService;

/**
* Keep reference to containers used by connections
Expand Down Expand Up @@ -55,7 +55,7 @@ export class CheMessagingContribution extends MessagingContribution {
async isRequestAllowed(request: http.IncomingMessage): Promise<boolean> {
const theiaEndpoints = [];
try {
const containers = await this.cheApiService.getCurrentWorkspacesContainers();
const containers = await this.workspaceService.getCurrentWorkspacesContainers();
for (const containerName of Object.keys(containers)) {
const servers = containers[containerName].servers;
if (servers) {
Expand Down
2 changes: 1 addition & 1 deletion extensions/eclipse-che-theia-plugin-ext/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
],
"dependencies": {
"@eclipse-che/plugin": "0.0.1",
"@eclipse-che/workspace-client": "latest",
"@theia/core": "next",
"@theia/task": "next",
"@theia/mini-browser": "next",
Expand All @@ -24,6 +23,7 @@
"vscode-uri": "2.1.1",
"js-yaml": "3.13.1",
"drivelist": "9.0.2",
"@eclipse-che/theia-remote-api": "^0.0.1",
"@eclipse-che/workspace-telemetry-client": "latest"
},
"devDependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { RPCProtocol } from '@theia/plugin-ext/lib/common/rpc-protocol';
import { injectable, interfaces } from 'inversify';
import { PLUGIN_RPC_CONTEXT } from '../common/che-protocol';
import { CheWorkspaceMainImpl } from './che-workspace-main';
import { CheFactoryMainImpl } from './che-factory-main';
import { CheTelemetryMainImpl } from './che-telemetry-main';
import { CheVariablesMainImpl } from './che-variables-main';
import { CheTaskMainImpl } from './che-task-main';
Expand All @@ -32,7 +31,6 @@ export class CheApiProvider implements MainPluginApiProvider {

initialize(rpc: RPCProtocol, container: interfaces.Container): void {
rpc.set(PLUGIN_RPC_CONTEXT.CHE_WORKSPACE_MAIN, new CheWorkspaceMainImpl(container));
rpc.set(PLUGIN_RPC_CONTEXT.CHE_FACTORY_MAIN, new CheFactoryMainImpl(container));
rpc.set(PLUGIN_RPC_CONTEXT.CHE_DEVFILE_MAIN, new CheDevfileMainImpl(container));
rpc.set(PLUGIN_RPC_CONTEXT.CHE_TELEMETRY_MAIN, new CheTelemetryMainImpl(container, rpc));
rpc.set(PLUGIN_RPC_CONTEXT.CHE_VARIABLES_MAIN, new CheVariablesMainImpl(container, rpc));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,51 +9,29 @@
**********************************************************************/

import { interfaces } from 'inversify';
import { CheDevfileMain, CheApiService } from '../common/che-protocol';
import { CheDevfileMain } from '../common/che-protocol';
import { AbstractDialog } from '@theia/core/lib/browser';
import { WindowService } from '@theia/core/lib/browser/window/window-service';
import { MessageService } from '@theia/core';
import { FactoryService } from '@eclipse-che/theia-remote-api/lib/common/factory-service';

export class CheDevfileMainImpl implements CheDevfileMain {

private readonly cheApiService: CheApiService;
private readonly factoryService: FactoryService;

private readonly windowService: WindowService;

private readonly messageService: MessageService;

private readonly openFactoryLinkDialog: OpenFactoryLinkDialog;

constructor(container: interfaces.Container) {
this.cheApiService = container.get(CheApiService);
this.factoryService = container.get(FactoryService);
this.windowService = container.get(WindowService);
this.messageService = container.get(MessageService);

this.openFactoryLinkDialog = new OpenFactoryLinkDialog(this.windowService);
}

async $createWorkspace(devfilePath: string): Promise<void> {
return new Promise<void>(async (resolve, reject) => {
let baseURI = this.cheApiService.getCheApiURI();

if (!baseURI) {
const error = 'Che API URI is not set!';
this.messageService.error(error);
reject(error);
return;
}

if (baseURI.endsWith('/api')) {
baseURI = baseURI.substring(0, baseURI.length - 4);
}

const fileDownloadURI = window.location.origin + '/files/?uri=' + devfilePath;
const factoryURI = `${baseURI}/f?url=${fileDownloadURI}`;

this.openFactoryWindow(factoryURI);

resolve();
});
const fileDownloadURI = window.location.origin + '/files/?uri=' + devfilePath;
const factoryURI = await this.factoryService.getFactoryLink(fileDownloadURI);
await this.openFactoryWindow(factoryURI);
}

/**
Expand Down

This file was deleted.

Loading

0 comments on commit ffdacc2

Please sign in to comment.