Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Connect to DHE worker #134

Merged
merged 89 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
89 commits
Select commit Hold shift + click to select a range
9c8c0ee
Copied @deephaven-enterprise/jsapi-types from DHE codebase (#79)
bmingles Sep 13, 2024
a660f03
First pass at DHE connections (#79)
bmingles Oct 2, 2024
3c0c3f5
Moved ent jsapi-types directory (#79)
bmingles Sep 13, 2024
92be5e0
Added dependency (#79)
bmingles Sep 13, 2024
4757e9c
DH license (#79)
bmingles Sep 13, 2024
7987951
WIP: DHE connection (#79)
bmingles Oct 2, 2024
b153bae
Rebase
bmingles Sep 20, 2024
366e71b
Rebase fixes (#79)
bmingles Oct 2, 2024
696d3aa
Moving dhe code out of package (#79)
bmingles Sep 20, 2024
c350da2
Moved AUTH_HANDLER_TYPE_DHE (#79)
bmingles Sep 20, 2024
a3bd28e
Comments (#79)
bmingles Sep 20, 2024
a25db49
Installed @deephaven-enterprise/jsapi-types alpha from npm (#79)
bmingles Sep 23, 2024
627335f
Copied QueryScheduler module from DHE (#79)
bmingles Sep 24, 2024
00a1251
Installed latest alpha of @deephaven-enterprise/jsapi-types (#79)
bmingles Sep 25, 2024
607efd3
Installed latest @deephaven-enterprise/jsapi-types (#79)
bmingles Sep 26, 2024
494e8bb
Installed @deephaven-enterprise/query-utils (#79)
bmingles Sep 30, 2024
58f403f
Using @deephaven-enterprise/query-utils (#79)
bmingles Sep 27, 2024
635a01d
Fixed package lock after add / remove sub packages (#79)
bmingles Sep 27, 2024
4b1a698
Fixed some module issues (#79)
bmingles Sep 27, 2024
97fa689
Fixed rebase (#79)
bmingles Oct 1, 2024
e7161e1
Upgraded to latest dhe alphas (#79)
bmingles Oct 1, 2024
40a1e3c
Upgraded to latest alpha (#79)
bmingles Oct 1, 2024
e8c1911
Successful DHE connection (#79)
bmingles Oct 2, 2024
88d956a
Refactored worker management (#79)
bmingles Oct 3, 2024
0c1d1f4
Refactored worker auth (#79)
bmingles Oct 3, 2024
9b35942
Improved type safety for worker urls (#79)
bmingles Oct 3, 2024
dfa02eb
Dispose workers (#79)
bmingles Oct 4, 2024
5fdf3bc
Using arrays instead of iterables (#79)
bmingles Oct 4, 2024
ff07414
Removed commented out code (#79)
bmingles Oct 4, 2024
5becadf
Added performance log for running commands (#79)
bmingles Oct 4, 2024
d99a4ff
Split out cache classes (#79)
bmingles Oct 4, 2024
3a709c3
Moved some base cache classes (#79)
bmingles Oct 4, 2024
f63d1a9
Moved method (#79)
bmingles Oct 4, 2024
238a52c
Fixed duplicate instantiation bug (#79)
bmingles Oct 4, 2024
2c8033d
CoreCredentialsFactory type (#79)
bmingles Oct 4, 2024
4471239
Cleanup + comments (#79)
bmingles Oct 7, 2024
be56eb8
User login workflow for DHE (#79)
bmingles Oct 7, 2024
2f1893e
Comment (#79)
bmingles Oct 7, 2024
2eff07b
import cleanup (#79)
bmingles Oct 7, 2024
6237e9b
type alias (#79)
bmingles Oct 7, 2024
eb08831
Comment and removed import (#79)
bmingles Oct 7, 2024
8a33bc2
Lazy type (#79)
bmingles Oct 7, 2024
5779a8e
Updated credentials cache to be lazy typed (#79)
bmingles Oct 7, 2024
b739a74
Documentation and cleanup of panel messaging (#79)
bmingles Oct 7, 2024
54a1f3a
Split out util for embed widget url (#79)
bmingles Oct 7, 2024
0a819c7
Removed unused import (#79)
bmingles Oct 7, 2024
96f9374
Added `has` method (#79)
bmingles Oct 8, 2024
746949d
Renamed UrlKeyCache (#79)
bmingles Oct 8, 2024
437a568
Renamed URLPromiseMapCache (#79)
bmingles Oct 8, 2024
9f875e9
Fixed URL casing (#79)
bmingles Oct 8, 2024
ec47fee
tagId functionality + cleaning up server management (#79)
bmingles Oct 8, 2024
adbce7a
Storing connection count on ServerState (#79)
bmingles Oct 8, 2024
4c1a0e6
Cleanup (#79)
bmingles Oct 8, 2024
f46d482
Fixed bugs with server state (#79)
bmingles Oct 8, 2024
5d025de
Fixed bug (#79)
bmingles Oct 8, 2024
2c226aa
Simplified (#79)
bmingles Oct 8, 2024
7217e09
label (#79)
bmingles Oct 8, 2024
4d7dbb2
Comments (#79)
bmingles Oct 8, 2024
8c91221
Comments (#79)
bmingles Oct 8, 2024
0f32d0d
Create worker console type based on editor (#79)
bmingles Oct 8, 2024
bebfe33
Fixed connection count bug (#79)
bmingles Oct 8, 2024
2241f36
Always include DHE server in picker (#79)
bmingles Oct 8, 2024
a6cf1f0
comments (#79)
bmingles Oct 8, 2024
9f3ac0e
Comments (#79)
bmingles Oct 8, 2024
6cf8fa0
Console type for worker creation (#79)
bmingles Oct 8, 2024
74182f3
getConsoleType util (#79)
bmingles Oct 8, 2024
b30acf9
comment (#79)
bmingles Oct 8, 2024
7c90f88
comment (#79)
bmingles Oct 8, 2024
d80bec0
comments (#79)
bmingles Oct 8, 2024
223f731
Removed unused workercount (#79)
bmingles Oct 8, 2024
61a5e33
Check for creds (#79)
bmingles Oct 8, 2024
483b5a8
tweak creds handling (#79)
bmingles Oct 8, 2024
2060bb1
Error output (#79)
bmingles Oct 8, 2024
6667033
Fixed a subtle but + added comments (#79)
bmingles Oct 8, 2024
f0ecc55
Deleted unused class (#79)
bmingles Oct 8, 2024
9570111
Removed comment (#79)
bmingles Oct 9, 2024
7be2778
Renamed service (#79)
bmingles Oct 9, 2024
b3b5c06
Removed credentials payloadsfrom logs (#79)
bmingles Oct 9, 2024
fbfc962
Fixed unit tests (#79)
bmingles Oct 9, 2024
ccbee21
Renamed test (#79)
bmingles Oct 9, 2024
3b5888f
Fixed unit test build (#79)
bmingles Oct 9, 2024
37d2d58
Updated snapshot (#79)
bmingles Oct 9, 2024
28f4059
Don't let connection count go below 0 (#79)
bmingles Oct 9, 2024
850953e
Fixed a bug with the polyfill where CustomEvent wasn't inheriting fro…
bmingles Oct 17, 2024
657d404
Upgraded to beta dhe packages (#79)
bmingles Oct 17, 2024
88df4bc
Match event detail (#79)
bmingles Oct 17, 2024
bbdabf8
Improve handling of worker creation errors (#79)
bmingles Oct 17, 2024
47cd6c8
Switched to temporary pq (#79)
bmingles Oct 17, 2024
7fcfc7e
Implemented more temp query logic (#79)
bmingles Oct 17, 2024
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
4,281 changes: 1,848 additions & 2,433 deletions package-lock.json

Large diffs are not rendered by default.

19 changes: 16 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@
"title": "Deephaven: Refresh Server Connection Tree",
"icon": "$(refresh)"
},
{
"command": "vscode-deephaven.requestDheUserCredentials",
"title": "Deephaven: Request DHE User Credentials"
},
{
"command": "vscode-deephaven.startServer",
"title": "Deephaven: Start Server",
Expand Down Expand Up @@ -624,6 +628,10 @@
{
"command": "vscode-deephaven.refreshVariablePanels",
"when": "false"
},
{
"command": "vscode-deephaven.requestDheUserCredentials",
"when": "false"
}
],
"editor/context": [
Expand Down Expand Up @@ -665,7 +673,7 @@
"view/item/context": [
{
"command": "vscode-deephaven.connectToServer",
"when": "view == vscode-deephaven.serverTree && (viewItem == isManagedServerDisconnected || viewItem == isServerRunningDisconnected)",
"when": "view == vscode-deephaven.serverTree && (viewItem == isManagedServerDisconnected || viewItem == isServerRunningDisconnected || viewItem == isDHEServerRunning)",
"group": "inline"
},
{
Expand All @@ -685,7 +693,7 @@
},
{
"command": "vscode-deephaven.openInBrowser",
"when": "view == vscode-deephaven.serverTree && (viewItem == isManagedServerConnected || viewItem == isServerRunningConnected || viewItem == isServerRunningDisconnected || viewItem == isManagedServerDisconnected)",
"when": "view == vscode-deephaven.serverTree && (viewItem == isManagedServerConnected || viewItem == isServerRunningConnected || viewItem == isServerRunningDisconnected || viewItem == isManagedServerDisconnected || viewItem == isDHEServerRunning)",
"group": "inline"
},
{
Expand Down Expand Up @@ -730,6 +738,7 @@
}
},
"devDependencies": {
"@deephaven-enterprise/jsapi-types": "^1.20240723.95-beta",
"@deephaven/jsapi-types": "^1.0.0-dev0.35.3",
"@types/node": "22.5.4",
"@types/vscode": "^1.91.0",
Expand Down Expand Up @@ -757,7 +766,11 @@
"wdio-vscode-service": "^6.1.0"
},
"dependencies": {
"@deephaven-enterprise/query-utils": "^1.20240723.95-beta",
"@deephaven/require-jsapi": "file:./packages/require-jsapi",
"ws": "^8.18.0"
"nanoid": "^5.0.7"
},
"overrides": {
"event-target-shim": "^6.0.2"
}
}
6 changes: 6 additions & 0 deletions packages/require-jsapi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,11 @@
"sideEffects": false,
"scripts": {
"build": "tsc --build"
},
"dependencies": {
"ws": "^8.18.0"
},
"devDependencies": {
"@deephaven-enterprise/jsapi-types": "^1.20240723.95-beta"
}
}
54 changes: 53 additions & 1 deletion packages/require-jsapi/src/dhe.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { hasStatusCode } from './serverUtils';
import * as fs from 'node:fs';
import * as path from 'node:path';
import type { EnterpriseDhType as DheType } from '@deephaven-enterprise/jsapi-types';
import { polyfillDh } from './polyfill';
import { downloadFromURL, hasStatusCode } from './serverUtils';

/**
* Check if a given server is running by checking if the `irisapi/irisapi.nocache.js`
Expand All @@ -15,3 +19,51 @@ export async function isDheServerRunning(serverUrl: URL): Promise<boolean> {
return false;
}
}

/**
* Polyfill browser apis, download jsapi to a local directory, and return the
* default export.
* @param serverUrl URL of the server to download the jsapi from
* @param storageDir Directory to save the downloaded jsapi
* @returns Default export of downloaded jsapi
*/
export async function initDheApi(
serverUrl: URL,
storageDir: string
): Promise<DheType> {
polyfillDh();
return getDhe(serverUrl, true, storageDir);
}

declare global {
export const iris: DheType;
}

/**
* Returns a CJS module that exports the Deephaven JS API. If the download flag
* is true, the API is downloaded from the server and saved to a local storage
* directory. If it is false, it will be returned from the local storage directory.
* @param serverUrl URL of the server to download the jsapi from
* @param download Whether to download the jsapi from the server
* @param storageDir Directory to save the downloaded jsapi and load it from
* @returns Default export of downloaded jsapi
*/
async function getDhe(
serverUrl: URL,
download: boolean,
storageDir: string
): Promise<DheType> {
const dheFilePath = path.join(storageDir, 'irisapi.nocache.js');

if (download) {
const dhe = await downloadFromURL(
path.join(serverUrl.toString(), 'irisapi/irisapi.nocache.js')
);

fs.writeFileSync(dheFilePath, dhe);
}

require(dheFilePath);

return iris;
}
24 changes: 12 additions & 12 deletions packages/require-jsapi/src/polyfill.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import ws from 'ws';

class Event {
type: string;
detail: unknown;

constructor(type: string, dict: { detail: unknown }) {
this.type = type;
if (dict) {
this.detail = dict.detail;
}
}
}

export class CustomEvent extends Event {
constructor(...args: ConstructorParameters<typeof Event>) {
super(...args);
}
}

export function polyfillDh(): void {
class Event {
type: string;
detail: unknown;

constructor(type: string, dict: { detail: unknown }) {
this.type = type;
if (dict) {
this.detail = dict.detail;
}
}
}

// Copilot will look for `window.document.currentScript` if it finds `window`.
// Since we are polyfilling `window` below, we also need to set `document` to
// avoid a "Cannot read properties of undefined (reading 'currentScript')"
Expand Down
1 change: 1 addition & 0 deletions src/common/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const OPEN_VARIABLE_PANELS_CMD = `${EXTENSION_ID}.openVariablePanels`;
export const REFRESH_SERVER_TREE_CMD = `${EXTENSION_ID}.refreshServerTree`;
export const REFRESH_SERVER_CONNECTION_TREE_CMD = `${EXTENSION_ID}.refreshServerConnectionTree`;
export const REFRESH_VARIABLE_PANELS_CMD = `${EXTENSION_ID}.refreshVariablePanels`;
export const REQUEST_DHE_USER_CREDENTIALS_CMD = `${EXTENSION_ID}.requestDheUserCredentials`;
export const RUN_CODE_COMMAND = `${EXTENSION_ID}.runCode`;
export const RUN_SELECTION_COMMAND = `${EXTENSION_ID}.runSelection`;
export const SELECT_CONNECTION_COMMAND = `${EXTENSION_ID}.selectConnection`;
Expand Down
20 changes: 20 additions & 0 deletions src/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ export const CONFIG_KEY = {
export const DEFAULT_CONSOLE_TYPE = 'python' as const;
// export const DHFS_SCHEME = 'dhfs';

// 600 seconds is based on default `auto_delete_timeout` in
// `ControllerClient.make_temporary_config`
export const DEFAULT_TEMPORARY_QUERY_AUTO_TIMEOUT_MS = 600000 as const;
export const DEFAULT_TEMPORARY_QUERY_TIMEOUT_MS = 60000 as const;

export const INTERACTIVE_CONSOLE_QUERY_TYPE = 'InteractiveConsole';
export const INTERACTIVE_CONSOLE_TEMPORARY_QUEUE_NAME =
'InteractiveConsoleTemporaryQueue';

export const PYTHON_ENV_WAIT = 1500 as const;

export const PIP_SERVER_STATUS_CHECK_INTERVAL = 3000;
Expand Down Expand Up @@ -88,6 +97,7 @@ export const PIP_SERVER_STATUS_DIRECTORY = 'pip-server-status';

export const SERVER_TREE_ITEM_CONTEXT = {
canStartServer: 'canStartServer',
isDHEServerRunning: 'isDHEServerRunning',
isManagedServerConnected: 'isManagedServerConnected',
isManagedServerConnecting: 'isManagedServerConnecting',
isManagedServerDisconnected: 'isManagedServerDisconnected',
Expand All @@ -97,3 +107,13 @@ export const SERVER_TREE_ITEM_CONTEXT = {
} as const;

export type ServerTreeItemContextValue = keyof typeof SERVER_TREE_ITEM_CONTEXT;

export const DEEPHAVEN_POST_MSG = {
loginOptionsRequest: 'io.deephaven.message.LoginOptions.request',
sessionDetailsRequest: 'io.deephaven.message.SessionDetails.request',
} as const;

export const VSCODE_POST_MSG = {
loginOptionsResponse: 'vscode-ext.loginOptions',
sessionDetailsResponse: 'vscode-ext.sessionDetails',
} as const;
29 changes: 23 additions & 6 deletions src/controllers/ConnectionController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
createConnectionQuickPickOptions,
createConnectStatusBarItem,
getConnectionsForConsoleType,
getConsoleType,
getEditorForUri,
isSupportedLanguageId,
Logger,
Expand Down Expand Up @@ -82,9 +83,9 @@ export class ConnectionController implements Disposable {

this._serverManager.onDidServerStatusChange(
server => {
// Auto connect to servers managed by extension when they start
// Auto connect to pip servers managed by extension when they start
if (server.isManaged && server.isRunning) {
this._serverManager.connectToServer(server.url);
this._serverManager.connectToServer(server.url, 'python');
}
},
undefined,
Expand Down Expand Up @@ -131,7 +132,8 @@ export class ConnectionController implements Disposable {

if ('url' in connectionOrServer) {
const cn = await this._serverManager.connectToServer(
connectionOrServer.url
connectionOrServer.url,
getConsoleType(editor.document.languageId)
);

if (cn == null) {
Expand Down Expand Up @@ -228,7 +230,12 @@ export class ConnectionController implements Disposable {
};

/**
* Prompt user to select a connection and apply the selection.
* Prompt user to select a connection and apply the selection. The options
* presented to the user consist of:
* 1. Active connections that support the console type of the active editor.
* 2. A list of running servers composed of:
* - DHC servers that don't yet have a connection
* - All running DHE servers
*/
onPromptUserToSelectConnection = async (): Promise<boolean> => {
assertDefined(vscode.window.activeTextEditor, 'activeTextEditor');
Expand All @@ -252,9 +259,19 @@ export class ConnectionController implements Disposable {
await updateStatusPromise;
}

const runningServersWithoutConnections = this._serverManager.getServers({
// Only include DHC servers that don't have any connections yet since their
// single connection will be included in the `connectionsForConsoleType` list.
const runningDHCServersWithoutConnections = this._serverManager.getServers({
isRunning: true,
hasConnections: false,
type: 'DHC',
});

// Since DHE servers allow creating multiple workers, always include the
// server in the list regardless of how many worker connections already exist.
const runningDHEServers = this._serverManager.getServers({
isRunning: true,
type: 'DHE',
});

const connectionsForConsoleType: ConnectionState[] =
Expand All @@ -272,7 +289,7 @@ export class ConnectionController implements Disposable {
try {
selectedCnResult = await createConnectionQuickPick(
createConnectionQuickPickOptions(
runningServersWithoutConnections,
[...runningDHCServersWithoutConnections, ...runningDHEServers],
connectionsForConsoleType,
editor.document.languageId,
editorActiveConnectionUrl
Expand Down
31 changes: 31 additions & 0 deletions src/controllers/ControllerBase.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import * as vscode from 'vscode';
import type { Disposable } from '../types';

/**
* Base controller class.
*/
export abstract class ControllerBase implements Disposable {
protected readonly disposables: Disposable[] = [];

/**
* Register a command and add it's subscription to the disposables list.
*/
registerCommand = (
...args: Parameters<typeof vscode.commands.registerCommand>
): void => {
const cmd = vscode.commands.registerCommand(...args);
this.disposables.push(cmd);
};

/**
* Dispose all registered disposables.
*/
async dispose(): Promise<void> {
const disposing = this.disposables.map(subscription =>
subscription.dispose()
);
this.disposables.length = 0;

await Promise.all(disposing);
}
}
Loading