This repository has been archived by the owner on Apr 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CHE-11443 and implement the containers plugin
Signed-off-by: Oleksii Orel <oorel@redhat.com> code cleanup Signed-off-by: root <root@workspaceqi0ng17xncf6eimt.ws-6d45d78c5b-g44fb> code cleanup Signed-off-by: root <root@workspaceqi0ng17xncf6eimt.ws-6d45d78c5b-g44fb>
- Loading branch information
Showing
10 changed files
with
1,594 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,6 @@ | |
"publish:next": "lerna run publish:next" | ||
}, | ||
"workspaces": [ | ||
"extensions/*", | ||
"plugins/*" | ||
"extensions/*" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
lib/ | ||
node_modules/ | ||
*.theia |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# containers-plugin | ||
|
||
Containers-tree plugin for Theia. | ||
|
||
This plugin provides: | ||
|
||
- List of containers with their status, where each container provides: | ||
|
||
- List of servers (resource locator) if there is any; | ||
|
||
- Ability to open a terminal within a selected container; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
{ | ||
"name": "containers-plugin", | ||
"publisher": "theia", | ||
"keywords": [ | ||
"theia-plugin" | ||
], | ||
"version": "0.0.1", | ||
"license": "EPL-2.0", | ||
"files": [ | ||
"src" | ||
], | ||
"contributes": { | ||
"viewsContainers": { | ||
"right": [ | ||
{ | ||
"id": "containers", | ||
"title": "Containers" | ||
} | ||
] | ||
}, | ||
"views": { | ||
"containers": [ | ||
{ | ||
"id": "containers", | ||
"name": "Containers" | ||
} | ||
] | ||
} | ||
}, | ||
"devDependencies": { | ||
"@theia/plugin": "next", | ||
"@theia/plugin-packager": "latest", | ||
"@eclipse-che/plugin": "latest", | ||
"rimraf": "2.6.2", | ||
"typescript-formatter": "7.2.2", | ||
"typescript": "2.9.2" | ||
}, | ||
"dependencies": { | ||
}, | ||
"scripts": { | ||
"prepare": "yarn run clean && yarn run build", | ||
"clean": "rimraf lib", | ||
"format-code": "tsfmt -r", | ||
"watch": "tsc -watch", | ||
"compile": "tsc", | ||
"build": "yarn run format-code && yarn run compile && theia:plugin pack" | ||
}, | ||
"engines": { | ||
"theiaPlugin": "next" | ||
}, | ||
"theiaPlugin": { | ||
"backend": "lib/containers-plugin.js" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/********************************************************************* | ||
* Copyright (c) 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 | ||
**********************************************************************/ | ||
|
||
import { ContainersTree } from './containers-tree'; | ||
|
||
export function start() { | ||
new ContainersTree(); | ||
} | ||
|
||
export function stop() { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
/********************************************************************* | ||
* Copyright (c) 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 | ||
**********************************************************************/ | ||
|
||
import * as theia from '@theia/plugin'; | ||
import { MachinesService } from "./machine-service"; | ||
|
||
const machines: Map<string, string[]> = new Map<string, string[]>(); | ||
|
||
export class ContainersTree { | ||
|
||
constructor() { | ||
const treeDataProvider = new TreeDataDataProvider(); | ||
|
||
theia.window.createTreeView('containers', { treeDataProvider }); | ||
|
||
this.initTreeData().then(() => { | ||
treeDataProvider.sendDataChanged(); | ||
}); | ||
} | ||
|
||
async initTreeData(): Promise<void> { | ||
const machinesService = new MachinesService(); | ||
|
||
await machinesService.updateMachines(); | ||
|
||
machinesService.machines.forEach(machine => { | ||
const machineName = machine.machineName; | ||
const machineProp: Array<string> = []; | ||
|
||
if (machine.status) { | ||
machineProp.push(machine.status); | ||
} | ||
|
||
const commands = ['terminal']; | ||
commands.forEach((command: string) => { | ||
machineProp.push(`${command}__${machineName}`); | ||
}); | ||
|
||
const servers = machine.servers; | ||
if (servers) { | ||
Object.keys(servers).forEach((serverName: string) => { | ||
const server = servers[serverName]; | ||
if (server && server.url) { | ||
machineProp.push(` [${serverName}](${server.url})`); | ||
} else { | ||
machineProp.push(serverName); | ||
} | ||
}); | ||
} | ||
|
||
machines.set(machineName, machineProp); | ||
}); | ||
} | ||
|
||
} | ||
|
||
export class TreeDataDataProvider implements theia.TreeDataProvider<string> { | ||
|
||
private onDidChangeTreeDataEmitter: theia.EventEmitter<undefined> = new theia.EventEmitter<undefined>(); | ||
readonly onDidChangeTreeData: theia.Event<undefined> = this.onDidChangeTreeDataEmitter.event; | ||
|
||
public sendDataChanged() { | ||
this.onDidChangeTreeDataEmitter.fire(); | ||
} | ||
|
||
/** | ||
* Get representation of the `element` | ||
* | ||
* @param element The element for which [TreeItem](#TreeItem) representation is asked for. | ||
* @return [TreeItem](#TreeItem) representation of the element | ||
*/ | ||
getTreeItem(element: string): theia.TreeItem | PromiseLike<theia.TreeItem> { | ||
const treeItem: theia.TreeItem = { | ||
label: element, | ||
tooltip: element | ||
}; | ||
if (machines.has(element)) { | ||
treeItem.iconPath = 'fa-circle medium-green'; | ||
treeItem.collapsibleState = theia.TreeItemCollapsibleState.Expanded; | ||
} else { | ||
const [label, machineName] = element.split('__'); | ||
if (!machineName || !machines.has(machineName)) { | ||
return treeItem; | ||
} | ||
treeItem.label = label; | ||
treeItem.command = { id: `${label}-for-${machineName}-container:new` }; | ||
if (label === 'terminal') { | ||
treeItem.iconPath = 'fa-terminal'; | ||
} | ||
} | ||
return treeItem; | ||
} | ||
|
||
async getChildren(element?: string): Promise<string[]> { | ||
if (element && machines.has(element)) { | ||
return machines.get(element)!; | ||
} else { | ||
return await this.getRootChildren(); | ||
} | ||
} | ||
|
||
async getRootChildren(): Promise<string[]> { | ||
const arr: string[] = []; | ||
machines.forEach((value, key) => { | ||
arr.push(key); | ||
}); | ||
return arr; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/********************************************************************* | ||
* Copyright (c) 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 | ||
**********************************************************************/ | ||
|
||
import * as che from '@eclipse-che/plugin'; | ||
|
||
export interface IWorkspaceMachine { | ||
machineName: string; | ||
servers?: { | ||
[serverRef: string]: { | ||
url?: string; | ||
port?: string; | ||
} | ||
}; | ||
status?: 'STARTING' | 'RUNNING' | 'STOPPED' | 'FAILED'; | ||
} | ||
|
||
export class MachinesService { | ||
|
||
private runtimeMachines: Array<IWorkspaceMachine> = []; | ||
|
||
constructor() { | ||
} | ||
|
||
async updateMachines(): Promise<void> { | ||
const workspace = await che.workspace.getCurrentWorkspace(); | ||
if (!workspace) { | ||
return Promise.reject('Failed to get workspace configuration'); | ||
} | ||
|
||
const workspaceMachines = workspace!.runtime | ||
&& workspace!.runtime!.machines | ||
|| workspace!.config!.environments![workspace.config!.defaultEnv!].machines | ||
|| {}; | ||
|
||
this.runtimeMachines.length = 0; | ||
|
||
Object.keys(workspaceMachines).forEach((machineName: string) => { | ||
const machine = <IWorkspaceMachine>workspaceMachines[machineName]; | ||
machine.machineName = machineName; | ||
this.runtimeMachines.push(machine); | ||
}); | ||
} | ||
|
||
get machines(): Array<IWorkspaceMachine> { | ||
return this.runtimeMachines; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"compilerOptions": { | ||
"strict": true, | ||
"skipLibCheck": true, | ||
"experimentalDecorators": true, | ||
"noUnusedLocals": true, | ||
"emitDecoratorMetadata": true, | ||
"downlevelIteration": true, | ||
"module": "commonjs", | ||
"moduleResolution": "node", | ||
"target": "es5", | ||
"lib": [ | ||
"es6", | ||
"webworker" | ||
], | ||
"sourceMap": true, | ||
"rootDir": "src", | ||
"outDir": "lib" | ||
}, | ||
"include": [ | ||
"src" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"baseIndentSize": 0, | ||
"newLineCharacter": "\n", | ||
"indentSize": 4, | ||
"tabSize": 4, | ||
"indentStyle": 4, | ||
"convertTabsToSpaces": true, | ||
"insertSpaceAfterCommaDelimiter": true, | ||
"insertSpaceAfterSemicolonInForStatements": true, | ||
"insertSpaceBeforeAndAfterBinaryOperators": true, | ||
"insertSpaceAfterKeywordsInControlFlowStatements": true, | ||
"insertSpaceAfterFunctionKeywordForAnonymousFunctions": false, | ||
"insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis": false, | ||
"insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets": false, | ||
"insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces": false, | ||
"placeOpenBraceOnNewLineForFunctions": false, | ||
"placeOpenBraceOnNewLineForControlBlocks": false | ||
} | ||
|
Oops, something went wrong.