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

Commit

Permalink
Merge branch 'master' into che#15552
Browse files Browse the repository at this point in the history
  • Loading branch information
vzhukovs committed Jan 13, 2020
2 parents 7809753 + e148767 commit 6657d44
Show file tree
Hide file tree
Showing 40 changed files with 858 additions and 546 deletions.
12 changes: 6 additions & 6 deletions CONTRIBUTING.md
Expand Up @@ -103,7 +103,7 @@ At this stage, you can code on Che-theia plugins. In this devfile, containers an
Che-theia plugins are located in `/projects/che-theia/plugins/` folder.

### Step 6: Compile your plugin
You can use the che command `build ... containers-plugin` or `build ... factory-plugin` (command pallette > Run task > … or containers view)
You can use the che command `build ... containers-plugin` or `build ... workspace-plugin` (command pallette > Run task > … or containers view)
Basically, this command will perform in the right plugin folder:

```
Expand All @@ -116,12 +116,12 @@ $ yarn
### Step 7: Run che-theia + plugin
In this section, we are going to run the che-theia assembly built previously and run that with one of the plugins built previously. We will be able to test our changes with a dedicated che-theia instance.

You can use the che command `run ... DEV che-theia + factory-plugin` or `run ... DEV che-theia + containers-plugin` (command pallette > Run task > … or containers view)
You can use the che command `run ... DEV che-theia + workspace-plugin` or `run ... DEV che-theia + containers-plugin` (command pallette > Run task > … or containers view)
Basically, this command will start the DEV che-theia with the plugin:

```
[theia-ide]
$ export HOSTED_PLUGIN=/projects/che-theia/plugins/factory-plugin/
$ export HOSTED_PLUGIN=/projects/che-theia/plugins/workspace-plugin/
$ node /projects/theia/production/src-gen/backend/main.js /tmp/theiadev_projects --hostname=0.0.0.0 --port=3130
```

Expand All @@ -131,7 +131,7 @@ You can then access to your modified Che-theia from the Container view `theia-de
### Step 7bis: Run che-theia + plugin in dev mode
In this section we show how to run the che-theia assembly but in `dev mode`: keeping all the information for debugging.

You can use the che command `run ... DEV yarn start ... che-theia + factory-plugin` or
You can use the che command `run ... DEV yarn start ... che-theia + workspace-plugin` or
`run ... DEV yarn start... che-theia + containers-plugin`
(command pallette > Run task > … or containers view).
To start che-theia in `dev-mode` with yarn (not using the production che-theia generated). It would keep things like the ability to source map.
Expand All @@ -140,9 +140,9 @@ Running dev theia would be located in the che-dev container and `theia-dev-flow`
![Che-Theia-dev-endpoint](https://raw.githubusercontent.com/eclipse/che-theia/assets/theia-dev-flow-endpoint.png)

### Just want to build the plugin and run with the existing Theia image
If you do not have any changes on Theia or Che-theia extension, you could just build the plugins with `build ... containers-plugin` or `build ... factory-plugin`
If you do not have any changes on Theia or Che-theia extension, you could just build the plugins with `build ... containers-plugin` or `build ... workspace-plugin`
and run these plugins with the existing che-theia app:
`run ... HOSTED che-theia + container-plugin` or `run ... HOSTED che-theia + factory-plugin`
`run ... HOSTED che-theia + container-plugin` or `run ... HOSTED che-theia + workspace-plugin`


## How to develop Che Theia remote plugin mechanism
Expand Down
3 changes: 2 additions & 1 deletion che-theia-init-sources.yml
Expand Up @@ -14,9 +14,10 @@ sources:
- extensions/eclipse-che-theia-git-provisioner
plugins:
- plugins/containers-plugin
- plugins/factory-plugin
- plugins/workspace-plugin
- plugins/ports-plugin
- plugins/task-plugin
- plugins/welcome-plugin
- plugins/ssh-plugin
- plugins/telemetry-plugin
checkoutTo: master
26 changes: 13 additions & 13 deletions devfiles/che-theia-all.devfile.yaml
Expand Up @@ -89,35 +89,35 @@ commands:
echo -e "\e[32mDone.\e[0m build ... containers-plugin"
workdir: /projects/che-theia/plugins/containers-plugin

- name: build ... factory-plugin
- name: build ... workspace-plugin
actions:
- type: exec
component: che-dev
command: >
killall node;
yarn &&
echo -e "\e[32mDone.\e[0m build ... factory-plugin"
workdir: /projects/che-theia/plugins/factory-plugin
echo -e "\e[32mDone.\e[0m build ... workspace-plugin"
workdir: /projects/che-theia/plugins/workspace-plugin

- name: test-watch ... factory-plugin
- name: test-watch ... workspace-plugin
actions:
- type: exec
component: che-dev
command: >
killall node;
yarn test-watch
workdir: /projects/che-theia/plugins/factory-plugin
workdir: /projects/che-theia/plugins/workspace-plugin

- name: run ... DEV che-theia + factory-plugin
- name: run ... DEV che-theia + workspace-plugin
actions:
- type: exec
component: theia-editor
command: >
kill `cat /tmp/node_theiadev.pid`;
rm /default-theia-plugins/eclipse_che_theia_factory_plugin.theia;
rm /default-theia-plugins/eclipse_che_workspace_plugin.theia;
mkdir -p /tmp/theiadev_projects &&
export CHE_PROJECTS_ROOT=/tmp/theiadev_projects &&
export HOSTED_PLUGIN=/projects/che-theia/plugins/factory-plugin/ &&
export HOSTED_PLUGIN=/projects/che-theia/plugins/workspace-plugin/ &&
node src-gen/backend/main.js /tmp/theiadev_projects --hostname=0.0.0.0 --port=3130 & echo $!> /tmp/node_theiadev.pid ; wait `cat /tmp/node_theiadev.pid`
workdir: /projects/theia/production

Expand All @@ -134,16 +134,16 @@ commands:
node src-gen/backend/main.js /tmp/theiadev_projects --hostname=0.0.0.0 --port=3130 & echo $!> /tmp/node_theiadev.pid ; wait `cat /tmp/node_theiadev.pid`
workdir: /projects/theia/production

- name: run ... HOSTED che-theia + factory-plugin
- name: run ... HOSTED che-theia + workspace-plugin
actions:
- type: exec
component: theia-editor
command: >
kill `cat /tmp/node_theiadev.pid`;
rm /default-theia-plugins/eclipse_che_theia_factory_plugin.theia;
rm /default-theia-plugins/eclipse_che_workspace_plugin.theia;
mkdir -p /tmp/theiadev_projects &&
export CHE_PROJECTS_ROOT=/tmp/theiadev_projects &&
cp /projects/che-theia/plugins/factory-plugin/eclipse_che_theia_factory_plugin.theia /default-theia-plugins/ &&
cp /projects/che-theia/plugins/workspace-plugin/eclipse_che_workspace_plugin.theia /default-theia-plugins/ &&
node src-gen/backend/main.js /tmp/theiadev_projects --hostname=0.0.0.0 --port=3130 & echo $!> /tmp/node_theiadev.pid ; wait `cat /tmp/node_theiadev.pid`
workdir: /home/theia

Expand All @@ -160,15 +160,15 @@ commands:
node src-gen/backend/main.js /tmp/theiadev_projects --hostname=0.0.0.0 --port=3130 & echo $!> /tmp/node_theiadev.pid ; wait `cat /tmp/node_theiadev.pid`
workdir: /home/theia

- name: run ... DEV yarn start ... che-theia + factory-plugin
- name: run ... DEV yarn start ... che-theia + workspace-plugin
actions:
- type: exec
component: che-dev
command: >
killall node;
mkdir -p /tmp/theiadev_projects &&
export CHE_PROJECTS_ROOT=/tmp/theiadev_projects &&
export HOSTED_PLUGIN=/projects/che-theia/plugins/factory-plugin/ &&
export HOSTED_PLUGIN=/projects/che-theia/plugins/workspace-plugin/ &&
export GIT_EXEC_PATH=/usr/libexec/git-core && export USE_LOCAL_GIT=true && export LOCAL_GIT_DIRECTORY=/usr &&
yarn start /tmp/theiadev_projects --hostname=0.0.0.0 --port=3010
workdir: /projects/theia/examples/assembly
Expand Down
3 changes: 2 additions & 1 deletion extensions/eclipse-che-theia-activity-tracker/package.json
Expand Up @@ -9,7 +9,8 @@
"src"
],
"dependencies": {
"@theia/core": "next"
"@theia/core": "next",
"@eclipse-che/theia-plugin-ext": "0.0.1"
},
"scripts": {
"prepare": "yarn clean && yarn build",
Expand Down
Expand Up @@ -14,9 +14,10 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

import { injectable } from 'inversify';
import { injectable, inject } from 'inversify';
import URI from '@theia/core/lib/common/uri';
import { ActivityTrackerService } from '../common/activity-tracker-protocol';
import { CheApiService } from '@eclipse-che/theia-plugin-ext/lib/common/che-protocol';
import * as http from 'http';

/**
Expand Down Expand Up @@ -50,6 +51,9 @@ export class ActivityTrackerServiceImpl implements ActivityTrackerService {
private pinger: { request(option: http.RequestOptions): http.ClientRequest };
private activityRequestOptions: http.RequestOptions;

@inject(CheApiService)
protected cheApiService: CheApiService;

constructor() {
const workspaceId = process.env[ActivityTrackerServiceImpl.WORKSPACE_ID_ENV_VAR_NAME];
if (!workspaceId) {
Expand Down Expand Up @@ -115,6 +119,7 @@ export class ActivityTrackerServiceImpl implements ActivityTrackerService {
}

private sendRequest(attemptsLeft: number = ActivityTrackerServiceImpl.RETRY_COUNT): void {
this.cheApiService.submitTelemetryActivity();
const request = this.pinger.request(this.activityRequestOptions);
request.on('error', (error: Error) => {
if (attemptsLeft > 0) {
Expand Down
3 changes: 2 additions & 1 deletion extensions/eclipse-che-theia-plugin-ext/package.json
Expand Up @@ -20,7 +20,8 @@
"@theia/mini-browser": "next",
"@theia/plugin-ext": "next",
"axios": "0.19.0",
"js-yaml": "3.13.1"
"js-yaml": "3.13.1",
"@eclipse-che/workspace-telemetry-client": "latest"
},
"devDependencies": {
"clean-webpack-plugin": "^0.1.19",
Expand Down
Expand Up @@ -14,6 +14,7 @@ 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';
import { CheSshMainImpl } from './che-ssh-main';
Expand All @@ -30,6 +31,7 @@ export class CheApiProvider implements MainPluginApiProvider {
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.set(PLUGIN_RPC_CONTEXT.CHE_VARIABLES_MAIN, new CheVariablesMainImpl(container, rpc));
rpc.set(PLUGIN_RPC_CONTEXT.CHE_TASK_MAIN, new CheTaskMainImpl(container, rpc));
rpc.set(PLUGIN_RPC_CONTEXT.CHE_SSH_MAIN, new CheSshMainImpl(container));
Expand Down
@@ -0,0 +1,44 @@
/*********************************************************************
* Copyright (c) 2020 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
**********************************************************************/

import { interfaces } from 'inversify';
import { CheTelemetryMain } from '../common/che-protocol';
import { CheApiService } from '../common/che-protocol';

export class CheTelemetryMainImpl implements CheTelemetryMain {

private readonly cheApiService: CheApiService;

constructor(container: interfaces.Container) {
this.cheApiService = container.get(CheApiService);
}

async $event(id: string, ownerId: string, properties: [string, string][]): Promise<void> {
// TODO : get the infos from the browser
const ip = '';

let agent = '';
let resolution = '';
const navigator = window.navigator;
if (navigator) {
agent = navigator.userAgent;
}
const screen = window.screen;
if (screen) {
const width = screen.width;
const height = screen.height;
if (height && width) {
resolution = '' + width + 'x' + height;
}
}

return this.cheApiService.submitTelemetryEvent(id, ownerId, ip, agent, resolution, properties);
}
}
15 changes: 15 additions & 0 deletions extensions/eclipse-che-theia-plugin-ext/src/common/che-protocol.ts
Expand Up @@ -69,6 +69,16 @@ export interface CheGithubMain {
$uploadPublicSshKey(publicKey: string): Promise<void>;
}

/**
* Telemetry plugin API
*/
export interface CheTelemetry {
}

export interface CheTelemetryMain {
$event(id: string, ownerId: string, properties: [string, string][]): Promise<void>;
}

/**
* Variables plugin API
*/
Expand Down Expand Up @@ -375,6 +385,9 @@ export const PLUGIN_RPC_CONTEXT = {
CHE_DEVFILE: <ProxyIdentifier<CheDevfile>>createProxyIdentifier<CheDevfile>('CheDevfile'),
CHE_DEVFILE_MAIN: <ProxyIdentifier<CheDevfileMain>>createProxyIdentifier<CheDevfileMain>('CheDevfileMain'),

CHE_TELEMETRY: <ProxyIdentifier<CheTelemetry>>createProxyIdentifier<CheTelemetry>('CheTelemetry'),
CHE_TELEMETRY_MAIN: <ProxyIdentifier<CheTelemetryMain>>createProxyIdentifier<CheTelemetryMain>('CheTelemetryMain'),

CHE_VARIABLES: <ProxyIdentifier<CheVariables>>createProxyIdentifier<CheVariables>('CheVariables'),
CHE_VARIABLES_MAIN: <ProxyIdentifier<CheVariablesMain>>createProxyIdentifier<CheVariablesMain>('CheVariablesMain'),
CHE_TASK: <ProxyIdentifier<CheTask>>createProxyIdentifier<CheTask>('CheTask'),
Expand Down Expand Up @@ -429,6 +442,8 @@ export interface CheApiService {
getSshKey(service: string, name: string): Promise<cheApi.ssh.SshPair>;
deleteSshKey(service: string, name: string): Promise<void>;
getAllSshKey(service: string): Promise<cheApi.ssh.SshPair[]>;
submitTelemetryEvent(id: string, ownerId: string, ip: string, agent: string, resolution: string, properties: [string, string][]): Promise<void>;
submitTelemetryActivity(): Promise<void>;
}

export const CHE_TASK_SERVICE_PATH = '/che-task-service';
Expand Down
Expand Up @@ -11,14 +11,18 @@ import { CheApiService, Preferences, WorkspaceSettings } from '../common/che-pro
import { che as cheApi } from '@eclipse-che/api';
import WorkspaceClient, { IRestAPIConfig, IRemoteAPI } from '@eclipse-che/workspace-client';
import { injectable } from 'inversify';

import { SS_CRT_PATH } from './che-https';

import { TelemetryClient, Event, EventProperty } from '@eclipse-che/workspace-telemetry-client';

const ENV_WORKSPACE_ID_IS_NOT_SET = 'Environment variable CHE_WORKSPACE_ID is not set';

@injectable()
export class CheApiServiceImpl implements CheApiService {

private workspaceRestAPI: IRemoteAPI | undefined;
private telemetryClient: TelemetryClient | undefined = this.getWorkspaceTelemetryClient();

async getCurrentWorkspaceId(): Promise<string> {
return this.getWorkspaceIdFromEnv();
Expand Down Expand Up @@ -240,6 +244,60 @@ export class CheApiServiceImpl implements CheApiService {
}
}

async submitTelemetryEvent(id: string, ownerId: string, ip: string, agent: string, resolution: string, properties: [string, string][]): Promise<void> {
try {
const event: Event = {
id: id,
ip: ip,
ownerId: ownerId,
agent: agent,
resolution: resolution,
properties: properties.map((prop: [string, string]) => {
const eventProp: EventProperty = {
id: prop[0],
value: prop[1]
};
return eventProp;
})
};
const client = this.getWorkspaceTelemetryClient();
if (client) {
await client.event(event);
}
} catch (e) {
console.error(e);
throw new Error(e);
}
}

async submitTelemetryActivity(): Promise<void> {
try {
const client = this.getWorkspaceTelemetryClient();
if (client) {
await client.activity();
}
} catch (e) {
console.error(e);
throw new Error(e);
}
}

private getWorkspaceTelemetryClient(): TelemetryClient | undefined {

if (!this.telemetryClient) {
const cheWorkspaceTelemetryBackendPortVar = process.env.CHE_WORKSPACE_TELEMETRY_BACKEND_PORT;

if (!cheWorkspaceTelemetryBackendPortVar) {
console.error('Unable to create Che API REST Client: "CHE_WORKSPACE_TELEMETRY_BACKEND_PORT" is not set.');
return undefined;
}

this.telemetryClient = new TelemetryClient(undefined, 'http://localhost:' + cheWorkspaceTelemetryBackendPortVar);
}

return this.telemetryClient;
}

private async getCheApiClient(): Promise<IRemoteAPI> {
const cheApiInternalVar = process.env.CHE_API_INTERNAL;
const cheMachineToken = process.env.CHE_MACHINE_TOKEN;
Expand Down

0 comments on commit 6657d44

Please sign in to comment.