1 | "use strict";
|
2 |
|
3 |
|
4 | Object.defineProperty(exports, "__esModule", { value: true });
|
5 | exports.getKernelModel = exports.shutdownKernel = exports.interruptKernel = exports.restartKernel = exports.startNew = exports.listRunning = exports.KERNEL_SERVICE_URL = void 0;
|
6 | const serverconnection_1 = require("../serverconnection");
|
7 | const coreutils_1 = require("@jupyterlab/coreutils");
|
8 | const validate_1 = require("./validate");
|
9 |
|
10 |
|
11 |
|
12 | exports.KERNEL_SERVICE_URL = 'api/kernels';
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 | async function listRunning(settings = serverconnection_1.ServerConnection.makeSettings()) {
|
26 | const url = coreutils_1.URLExt.join(settings.baseUrl, exports.KERNEL_SERVICE_URL);
|
27 | const response = await serverconnection_1.ServerConnection.makeRequest(url, {}, settings);
|
28 | if (response.status !== 200) {
|
29 | const err = await serverconnection_1.ServerConnection.ResponseError.create(response);
|
30 | throw err;
|
31 | }
|
32 | const data = await response.json();
|
33 | (0, validate_1.validateModels)(data);
|
34 | return data;
|
35 | }
|
36 | exports.listRunning = listRunning;
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 | async function startNew(options = {}, settings = serverconnection_1.ServerConnection.makeSettings()) {
|
50 | const url = coreutils_1.URLExt.join(settings.baseUrl, exports.KERNEL_SERVICE_URL);
|
51 | const init = {
|
52 | method: 'POST',
|
53 | body: JSON.stringify(options)
|
54 | };
|
55 | const response = await serverconnection_1.ServerConnection.makeRequest(url, init, settings);
|
56 | if (response.status !== 201) {
|
57 | const err = await serverconnection_1.ServerConnection.ResponseError.create(response);
|
58 | throw err;
|
59 | }
|
60 | const data = await response.json();
|
61 | (0, validate_1.validateModel)(data);
|
62 | return data;
|
63 | }
|
64 | exports.startNew = startNew;
|
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 | async function restartKernel(id, settings = serverconnection_1.ServerConnection.makeSettings()) {
|
74 | const url = coreutils_1.URLExt.join(settings.baseUrl, exports.KERNEL_SERVICE_URL, encodeURIComponent(id), 'restart');
|
75 | const init = { method: 'POST' };
|
76 | const response = await serverconnection_1.ServerConnection.makeRequest(url, init, settings);
|
77 | if (response.status !== 200) {
|
78 | const err = await serverconnection_1.ServerConnection.ResponseError.create(response);
|
79 | throw err;
|
80 | }
|
81 | const data = await response.json();
|
82 | (0, validate_1.validateModel)(data);
|
83 | }
|
84 | exports.restartKernel = restartKernel;
|
85 |
|
86 |
|
87 |
|
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 | async function interruptKernel(id, settings = serverconnection_1.ServerConnection.makeSettings()) {
|
94 | const url = coreutils_1.URLExt.join(settings.baseUrl, exports.KERNEL_SERVICE_URL, encodeURIComponent(id), 'interrupt');
|
95 | const init = { method: 'POST' };
|
96 | const response = await serverconnection_1.ServerConnection.makeRequest(url, init, settings);
|
97 | if (response.status !== 204) {
|
98 | const err = await serverconnection_1.ServerConnection.ResponseError.create(response);
|
99 | throw err;
|
100 | }
|
101 | }
|
102 | exports.interruptKernel = interruptKernel;
|
103 |
|
104 |
|
105 |
|
106 |
|
107 |
|
108 |
|
109 |
|
110 |
|
111 |
|
112 |
|
113 |
|
114 |
|
115 |
|
116 |
|
117 |
|
118 | async function shutdownKernel(id, settings = serverconnection_1.ServerConnection.makeSettings()) {
|
119 | const url = coreutils_1.URLExt.join(settings.baseUrl, exports.KERNEL_SERVICE_URL, encodeURIComponent(id));
|
120 | const init = { method: 'DELETE' };
|
121 | const response = await serverconnection_1.ServerConnection.makeRequest(url, init, settings);
|
122 | if (response.status === 404) {
|
123 | const msg = `The kernel "${id}" does not exist on the server`;
|
124 | console.warn(msg);
|
125 | }
|
126 | else if (response.status !== 204) {
|
127 | const err = await serverconnection_1.ServerConnection.ResponseError.create(response);
|
128 | throw err;
|
129 | }
|
130 | }
|
131 | exports.shutdownKernel = shutdownKernel;
|
132 |
|
133 |
|
134 |
|
135 |
|
136 |
|
137 |
|
138 |
|
139 |
|
140 | async function getKernelModel(id, settings = serverconnection_1.ServerConnection.makeSettings()) {
|
141 | const url = coreutils_1.URLExt.join(settings.baseUrl, exports.KERNEL_SERVICE_URL, encodeURIComponent(id));
|
142 | const response = await serverconnection_1.ServerConnection.makeRequest(url, {}, settings);
|
143 | if (response.status === 404) {
|
144 | return undefined;
|
145 | }
|
146 | else if (response.status !== 200) {
|
147 | const err = await serverconnection_1.ServerConnection.ResponseError.create(response);
|
148 | throw err;
|
149 | }
|
150 | const data = await response.json();
|
151 | (0, validate_1.validateModel)(data);
|
152 | return data;
|
153 | }
|
154 | exports.getKernelModel = getKernelModel;
|
155 |
|
\ | No newline at end of file |