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

Server settings #2185

Merged
merged 45 commits into from
May 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
f90e3cf
wip serverconnection api
blink1073 May 10, 2017
4350fd2
Finish serverconnection api
blink1073 May 10, 2017
a748b82
Update config to use serverconnection
blink1073 May 10, 2017
5fed863
Only force a payload when necessary: fixes #2182
blink1073 May 11, 2017
700427d
comments
blink1073 May 11, 2017
4705e6d
Add ability to specify xhr and ws ctors
blink1073 May 11, 2017
c1c65bb
Clean up request handling
blink1073 May 11, 2017
bc93ab2
Convert contents and clean up config
blink1073 May 11, 2017
2551a00
Update the terminal
blink1073 May 11, 2017
e512ee3
Clean up contents constructor
blink1073 May 11, 2017
4616a0c
wip update apis
blink1073 May 11, 2017
834ab92
Update terminal manager
blink1073 May 11, 2017
0dea5ae
wip update kernel
blink1073 May 11, 2017
c553ac3
wip update kernel
blink1073 May 11, 2017
fb89e6a
wip update kernel
blink1073 May 12, 2017
ede620e
wip update kernel
blink1073 May 12, 2017
5510f0d
Finish kernel updates
blink1073 May 12, 2017
21c0706
wip sessions update
blink1073 May 12, 2017
73eeb1a
finish updates to session
blink1073 May 12, 2017
3480083
finish updates to service manager
blink1073 May 12, 2017
2d5eda7
Bump notebook depedency for new sessions API
blink1073 May 12, 2017
a6dd797
wip update session api
blink1073 May 12, 2017
211e2cd
Revert changes to session model for now
blink1073 May 15, 2017
054befd
wip update tests
blink1073 May 15, 2017
6ff6231
Update kernel tests
blink1073 May 15, 2017
810a71f
Finish updating tests
blink1073 May 15, 2017
4f72645
Fix terminal socket handling
blink1073 May 15, 2017
ec068ff
Clean up session disposal
blink1073 May 15, 2017
1693281
update integration tests
blink1073 May 15, 2017
91c1014
wip update tests
blink1073 May 15, 2017
036677a
Update kernel tests
blink1073 May 15, 2017
a36ce0f
All tests passing
blink1073 May 15, 2017
6a0a265
Move timeout to server settings
blink1073 May 15, 2017
77783c8
Update filebrowser
blink1073 May 15, 2017
98a2333
Cleanup and top level tests passing
blink1073 May 15, 2017
c8441b1
Add tests for serverconnection
blink1073 May 15, 2017
51df71d
update examples
blink1073 May 15, 2017
576cca5
Remove debug comment
blink1073 May 15, 2017
d10499a
Remove explicit cache setting
blink1073 May 15, 2017
b572298
wip fix tests on travis
blink1073 May 15, 2017
53ba463
wip travis debug
blink1073 May 15, 2017
855b197
Fix config update
blink1073 May 15, 2017
fe3d1fc
Fix syntax
blink1073 May 15, 2017
9664bff
Rename success -> response
blink1073 May 16, 2017
eb1b1b1
Update node example
blink1073 May 16, 2017
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
5 changes: 3 additions & 2 deletions packages/apputils/src/clientsession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
} from '@jupyterlab/coreutils';

import {
Kernel, KernelMessage, Session, utils
Kernel, KernelMessage, ServerConnection, Session
} from '@jupyterlab/services';

import {
Expand Down Expand Up @@ -79,6 +79,7 @@ interface IClientSession extends IDisposable {
* The current path associated with the client sesssion.
*/
readonly path: string;

/**
* The current name associated with the client sesssion.
*/
Expand Down Expand Up @@ -627,7 +628,7 @@ class ClientSession implements IClientSession {
/**
* Handle an error in session startup.
*/
private _handleSessionError(err: utils.IAjaxError): Promise<void> {
private _handleSessionError(err: ServerConnection.IError): Promise<void> {
let response = String(err.xhr.response);
try {
response = JSON.parse(err.xhr.response)['traceback'];
Expand Down
3 changes: 0 additions & 3 deletions packages/filebrowser/src/listing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -396,9 +396,6 @@ class DirListing extends Widget {
}
}
return Promise.all(promises).catch(error => {
if (error.throwError) {
error.message = error.throwError;
}
utils.showErrorMessage('Duplicate file', error);
});
}
Expand Down
2 changes: 1 addition & 1 deletion packages/filebrowser/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function showErrorMessage(title: string, error: any): Promise<void> {
console.error(error);
let options = {
title: title,
body: error.throwError || error.message || `File ${title}`,
body: error.message || `File ${title}`,
buttons: [Dialog.okButton()],
okText: 'DISMISS'
};
Expand Down
4 changes: 2 additions & 2 deletions packages/notebook-extension/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ function addCommands(app: JupyterLab, services: IServiceManager, tracker: Notebo

let notebookPath = URLExt.encodeParts(current.context.path);
let url = URLExt.join(
services.baseUrl,
services.serverSettings.baseUrl,
'nbconvert',
(args['format']) as string,
notebookPath
Expand Down Expand Up @@ -1074,7 +1074,7 @@ function createMenu(app: JupyterLab): Menu {
EXPORT_TO_FORMATS.forEach(exportToFormat => {
exportTo.addItem({ command: CommandIDs.exportToFormat, args: exportToFormat });
});

menu.addItem({ command: CommandIDs.undo });
menu.addItem({ command: CommandIDs.redo });
menu.addItem({ type: 'separator' });
Expand Down
60 changes: 19 additions & 41 deletions packages/services/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,19 @@ Follow the package install instructions first.
npm install --save xmlhttprequest ws
```

Override the global `XMLHttpRequest` and `WebSocket` (in ES6 syntax):
Use `XMLHttpRequest` and `WebSocket` in the server settings (in ES6 syntax):

```typescript
import { Kernel, ServerConnection } from '@jupyterlab/services';
import { XMLHttpRequest } from "xmlhttprequest";
import { default as WebSocket } from 'ws';

global.XMLHttpRequest = XMLHttpRequest;
global.WebSocket = WebSocket;

let serverSettings = ServerConnection.makeSettings({
xml: XMLHttpRequest,
webSocket: WebSocket
});
Kernel.startNew({ serverSettings }).then(...);
```

See `examples/node` for an example of using an ES5 node script.
Expand All @@ -148,29 +153,21 @@ import {
KernelMessage, Kernel
} from '@jupyterlab/services';

// The base url of the notebook server.
const BASE_URL = 'http://localhost:8000';


// Get a list of available kernels and connect to one.
Kernel.listRunning({ baseUrl: BASE_URL }).then(kernelModels => {
let options: Kernel.IOptions = {
baseUrl: BASE_URL,
name: kernelModels[0].name
};
Kernel.connectTo(kernelModels[0].id, options).then((kernel) => {
/ Get a list of available kernels and connect to one.
Kernel.listRunning().then(kernelModels => {
Kernel.connectTo(kernelModels[0].id).then((kernel) => {
console.log(kernel.name);
});
});


// Get info about the available kernels and start a new one.
Kernel.getSpecs({ baseUrl: BASE_URL }).then(kernelSpecs => {
Kernel.getSpecs().then(kernelSpecs => {
console.log('Default spec:', kernelSpecs.default);
console.log('Available specs', Object.keys(kernelSpecs.kernelspecs));
// use the default name
let options: Kernel.IOptions = {
baseUrl: BASE_URL,
name: kernelSpecs.default
};
Kernel.startNew(options).then(kernel => {
Expand Down Expand Up @@ -211,6 +208,7 @@ Kernel.getSpecs({ baseUrl: BASE_URL }).then(kernelSpecs => {
});
});
});

```

**Session**
Expand All @@ -221,25 +219,15 @@ import {
} from '@jupyterlab/services';


// The base url of the Jupyter server.
const BASE_URL = 'http://localhost:8000';


// Get a list of available sessions and connect to one.
Session.listRunning({ baseUrl: BASE_URL }).then(sessionModels => {
let options = {
baseUrl: BASE_URL,
kernelName: sessionModels[0].kernel.name,
path: sessionModels[0].notebook.path
};
Session.connectTo(sessionModels[0].id, options).then((session) => {
Session.listRunning().then(sessionModels => {
Session.connectTo(sessionModels[0].id).then((session) => {
console.log(session.kernel.name);
});
});

// Start a new session.
let options = {
baseUrl: BASE_URL,
kernelName: 'python',
path: '/tmp/foo.ipynb'
};
Expand Down Expand Up @@ -273,16 +261,12 @@ Session.startNew(options).then(session => {
**Comm**

```typescript
// The base url of the Jupyter server.
const BASE_URL = 'http://localhost:8000';


// Create a comm from the server side.
//
// Get info about the available kernels and connect to one.
Kernel.getSpecs({ baseUrl: BASE_URL }).then(kernelSpecs => {
Kernel.getSpecs().then(kernelSpecs => {
return Kernel.startNew({
baseUrl: BASE_URL,
name: kernelSpecs.default,
});
}).then(kernel => {
Expand All @@ -293,9 +277,8 @@ Kernel.getSpecs({ baseUrl: BASE_URL }).then(kernelSpecs => {
});

// Create a comm from the client side.
Kernel.getSpecs({ baseUrl: BASE_URL }).then(kernelSpecs => {
Kernel.getSpecs().then(kernelSpecs => {
return Kernel.startNew({
baseUrl: BASE_URL,
name: kernelSpecs.default,
});
}).then(kernel => {
Expand Down Expand Up @@ -328,11 +311,7 @@ import {
ContentsManager
} from '@jupyterlab/services';

// The base url of the Jupyter server.
let baseUrl = 'http://localhost:8000';


let contents = new ContentsManager({ baseUrl });
let contents = new ContentsManager();

// Create a new python file.
contents.newUntitled({ path: '/foo', type: 'file', ext: 'py' }).then(
Expand Down Expand Up @@ -387,9 +366,8 @@ import {
} from '@jupyterlab/services';

// The base url of the Jupyter server.
let baseUrl = 'http://localhost:8000';

ConfigSection.create({ name: 'notebook', baseUrl }).then(section => {
ConfigSection.create({ name: 'notebook' }).then(section => {
let config = new ConfigWithDefaults({
section,
defaults: { default_cell_type: 'code' },
Expand Down
13 changes: 8 additions & 5 deletions packages/services/examples/node/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,18 @@ var ws = require('ws');
var xhr = require('xmlhttprequest');


// Override the global request and socket functions.
global.XMLHttpRequest = xhr.XMLHttpRequest;
global.WebSocket = ws;

// Set the request and socket functions.
var serverSettings = services.ServerConnection.makeSettings({
xhrFactory: function () { return new xhr.XMLHttpRequest() },
wsFactory: function (url, protocol) { return new ws(url, protocol); }
});

// Start a new session.

var options = {
kernelName: 'python',
path: 'foo.ipynb'
path: 'foo.ipynb',
serverSettings: serverSettings
}


Expand Down
6 changes: 3 additions & 3 deletions packages/services/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@
"build": "npm run build:src",
"test:coverage": "istanbul cover --dir test/coverage _mocha -- --retries 3 test/build/**/*.spec.js test/build/*.spec.js --jupyter-config-data=./test/config.json",
"test:integration": "cd test && python integration_test.py",
"test:devtool": "devtool node_modules/.bin/_mocha -qc test/build/**/*.spec.js test/build*.spec.js --jupyter-config-data=./test/config.json",
"test:debug": "mocha test/build/**/*.spec.js test/build*.spec.js --jupyter-config-data=./test/config.json --debug-brk",
"test": "mocha --retries 3 test/build/**/*.spec.js test/build*.spec.js --jupyter-config-data=./test/config.json"
"test:devtool": "devtool node_modules/.bin/_mocha -qc ttest/build/**/*.spec.js test/build/*.spec.js --jupyter-config-data=./test/config.json --timeout=50000",
"test:debug": "mocha test/build/**/*.spec.js test/build/*.spec.js --jupyter-config-data=./test/config.json --debug-brk",
"test": "mocha --retries 3 test/build/**/*.spec.js test/build/*.spec.js --jupyter-config-data=./test/config.json"
},
"repository": {
"type": "git",
Expand Down
85 changes: 31 additions & 54 deletions packages/services/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,16 @@
// Distributed under the terms of the Modified BSD License.

import {
PageConfig, URLExt
URLExt
} from '@jupyterlab/coreutils';

import {
JSONObject, JSONValue, JSONExt
JSONObject, JSONValue
} from '@phosphor/coreutils';

import {
IAjaxSettings
} from '../utils';

import * as utils
from '../utils';
ServerConnection
} from '..';


/**
Expand Down Expand Up @@ -44,9 +41,9 @@ interface IConfigSection {
update(newdata: JSONObject): Promise<JSONObject>;

/**
* Optional default settings for ajax requests, if applicable.
* The server settings for the section.
*/
ajaxSettings?: IAjaxSettings;
readonly serverSettings: ServerConnection.ISettings;
}


Expand Down Expand Up @@ -79,19 +76,9 @@ namespace ConfigSection {
name: string;

/**
* The server base url.
*/
baseUrl?: string;

/**
* The authentication token for the API.
*/
token?: string;

/**
* The default ajax settings.
* The optional server settings.
*/
ajaxSettings?: IAjaxSettings;
serverSettings?: ServerConnection.ISettings;
}
}

Expand All @@ -104,24 +91,17 @@ class DefaultConfigSection implements IConfigSection {
* Construct a new config section.
*/
constructor(options: ConfigSection.IOptions) {
let baseUrl = options.baseUrl || PageConfig.getBaseUrl();
this.ajaxSettings = utils.ajaxSettingsWithToken(options.ajaxSettings, options.token);
this._url = URLExt.join(baseUrl, SERVICE_CONFIG_URL,
let settings = this.serverSettings = (
options.serverSettings || ServerConnection.makeSettings()
);
this._url = URLExt.join(settings.baseUrl, SERVICE_CONFIG_URL,
encodeURIComponent(options.name));
}

/**
* Get a copy of the default ajax settings for the section.
* The server settings for the section.
*/
get ajaxSettings(): IAjaxSettings {
return JSONExt.deepCopy(this._ajaxSettings);
}
/**
* Set the default ajax settings for the section.
*/
set ajaxSettings(value: IAjaxSettings) {
this._ajaxSettings = JSONExt.deepCopy(value);
}
readonly serverSettings: ServerConnection.ISettings;

/**
* Get the data for this section.
Expand All @@ -139,15 +119,15 @@ class DefaultConfigSection implements IConfigSection {
* The promise is fulfilled on a valid response and rejected otherwise.
*/
load(): Promise<void> {
let ajaxSettings = this.ajaxSettings;
ajaxSettings.method = 'GET';
ajaxSettings.dataType = 'json';
ajaxSettings.cache = false;
return utils.ajaxRequest(this._url, ajaxSettings).then(success => {
if (success.xhr.status !== 200) {
throw utils.makeAjaxError(success);
let request = {
url: this._url,
method: 'GET'
};
return ServerConnection.makeRequest(request, this.serverSettings).then(response => {
if (response.xhr.status !== 200) {
throw ServerConnection.makeError(response);
}
this._data = success.data;
this._data = response.data as JSONObject;
});
}

Expand All @@ -165,25 +145,22 @@ class DefaultConfigSection implements IConfigSection {
*/
update(newdata: JSONObject): Promise<JSONObject> {
this._data = {...this._data, ...newdata};
let ajaxSettings = this.ajaxSettings;
ajaxSettings.method = 'PATCH';
ajaxSettings.data = JSON.stringify(newdata);
ajaxSettings.dataType = 'json';
ajaxSettings.contentType = 'application/json';

return utils.ajaxRequest(this._url, ajaxSettings).then(success => {
if (success.xhr.status !== 200) {
throw utils.makeAjaxError(success);
let request = {
url: this._url,
method: 'PATCH',
data: JSON.stringify(newdata)
};
return ServerConnection.makeRequest(request, this.serverSettings).then(response => {
if (response.xhr.status !== 200) {
throw ServerConnection.makeError(response);
}

this._data = success.data;
this._data = response.data as JSONObject;
return this._data;
});
}

private _url = 'unknown';
private _data: JSONObject = null;
private _ajaxSettings: IAjaxSettings = null;
}


Expand Down
Loading