1 | <!DOCTYPE html>
|
2 | <html lang="en">
|
3 | <head>
|
4 | <meta charset="utf-8">
|
5 | <title>JSDoc: Source: lib/yexpert-js.js</title>
|
6 |
|
7 | <script src="scripts/prettify/prettify.js"> </script>
|
8 | <script src="scripts/prettify/lang-css.js"> </script>
|
9 | |
10 |
|
11 |
|
12 | <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
|
13 | <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
|
14 | </head>
|
15 |
|
16 | <body>
|
17 |
|
18 | <div id="main">
|
19 |
|
20 | <h1 class="page-title">Source: lib/yexpert-js.js</h1>
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 | <section>
|
28 | <article>
|
29 | <pre class="prettyprint source linenums"><code>/*
|
30 |
|
31 | !----------------------------------------------------------------------------!
|
32 | ! !
|
33 | ! Yexpert : (your) Système Expert sous Mumps GT.M et GNU/Linux !
|
34 | ! Copyright (C) 2001-2015 by Hamid LOUAKED (HL). !
|
35 | ! !
|
36 | !----------------------------------------------------------------------------!
|
37 |
|
38 | */
|
39 |
|
40 | var build = require('./build');
|
41 | var fs = require('fs');
|
42 | var os = require('os');
|
43 |
|
44 | /**
|
45 | * Module yexpert-js.
|
46 | * @module lib/yexper-js
|
47 | */
|
48 |
|
49 | /** Fonction yexpert-js. */
|
50 | module.exports = {
|
51 |
|
52 | /** Initialisation. */
|
53 | init: function() {
|
54 | var types = [
|
55 | 'qoper8-stats',
|
56 | 'qoper8-getStats',
|
57 | 'getMasterProcessDetails',
|
58 | 'getWorkerDetails',
|
59 | 'getPoolSize'
|
60 | ];
|
61 | if (this.dontLog) this.dontLog(types);
|
62 | },
|
63 |
|
64 | /** Services autorisés. */
|
65 | servicesAllowed: {
|
66 | 'ewd-react-tools': true
|
67 | },
|
68 |
|
69 | /** Manutentionnaires. */
|
70 | handlers: {
|
71 |
|
72 | exemple: function(messageObj, session, send, finished) {
|
73 |
|
74 | var node = {
|
75 | global: 'irelay',
|
76 | subscripts: ['a'],
|
77 | data: 'hello world'
|
78 | };
|
79 | this.db.set(node);
|
80 |
|
81 | var func2 = this.db.function({function: 'ZGBLDIR^%GTM', arguments: ['DMO']});
|
82 |
|
83 | var dir = this.db.global_directory();
|
84 | finished(dir);
|
85 | //finished({ok: 'example executed!'});
|
86 | },
|
87 |
|
88 | /**
|
89 | * Se déplacer sur une partition.
|
90 | * @constructor
|
91 | * @param {object} messageObj - Message.
|
92 | * @param {number} session - Session.
|
93 | * @param {string} send - Send.
|
94 | * @param {object} finished - Message de retour de la fonction.
|
95 | */
|
96 | cdNameSpace: function(messageObj, session, send, finished) {
|
97 | var fn = {};
|
98 | var path = '/home/' + process.env['instance'] + '/partitions/' + messageObj.params.namespace.toLowerCase() + '/globals/';
|
99 | if (messageObj.params.namespace != '') {
|
100 | if (fs.existsSync(path + messageObj.params.namespace.toUpperCase() + '.gld')) {
|
101 | var fn = this.db.function({function: 'ZGBLDIR^%GTM', arguments: [messageObj.params.namespace.toUpperCase()]});
|
102 | }
|
103 | }
|
104 | finished(fn);
|
105 | },
|
106 |
|
107 | /**
|
108 | * Obtenir la liste des noms des partitions installées.
|
109 | * @constructor
|
110 | * @param {object} messageObj - Message.
|
111 | * @param {number} session - Session.
|
112 | * @param {string} send - Send.
|
113 | * @param {object} finished - Liste des noms des partitions installées sous la forme ["DMO", "YXP"].
|
114 | */
|
115 | getNameSpace: function(messageObj, session, send, finished) {
|
116 | var path = '/home/' + process.env['instance'] + '/partitions/';
|
117 | fs.readdir(path, function(err, items) {
|
118 | if (err) {
|
119 | finished(err);
|
120 | }
|
121 | finished(items);
|
122 | });
|
123 | },
|
124 |
|
125 | getQui: function(messageObj, session, send, finished) {
|
126 | var node = {
|
127 | global: 'QUI',
|
128 | subscripts: []
|
129 | };
|
130 | var result = this.db.get(node);
|
131 | //console.log("-----getQui: " + JSON.stringify(result.data));
|
132 | finished({qui: result.data});
|
133 | },
|
134 |
|
135 | setQui: function(messageObj, session, send, finished) {
|
136 | if (messageObj.params.partition && messageObj.params.partition !== '') {
|
137 | var node = {
|
138 | global: 'QUI',
|
139 | subscripts: [],
|
140 | data: messageObj.params.partition
|
141 | };
|
142 | var result = this.db.set(node);
|
143 | //console.log("-----setQui: " + JSON.stringify(result.data));
|
144 | finished({ok: true});
|
145 | }
|
146 | else {
|
147 | finished({error: 'Invalid partition'});
|
148 | }
|
149 | },
|
150 |
|
151 | login: function(messageObj, session, send, finished) {
|
152 | if (messageObj.params.password === this.userDefined.config.managementPassword) {
|
153 | session.timeout = 20 * 60;
|
154 | session.authenticated = true;
|
155 | finished({ok: true});
|
156 | }
|
157 | else {
|
158 | finished({error: 'Invalid login attempt'});
|
159 | }
|
160 | return;
|
161 | },
|
162 | getServerName: function(messageObj, session, send, finished) {
|
163 | var serverName = '';
|
164 | if (this.userDefined.config && this.userDefined.config.serverName) serverName = this.userDefined.config.serverName;
|
165 | finished({serverName: serverName});
|
166 | },
|
167 | getBuildDetails: function(messageObj, session, send, finished) {
|
168 | var node = {
|
169 | global: 'INCONNE',
|
170 | subscripts: ['VERSION']
|
171 | };
|
172 | var rep = this.db.get(node);
|
173 | if (session.authenticated) {
|
174 | var buildDetails = {
|
175 | nodejsBuild: process.version,
|
176 | dbInterface: this.db.version(),
|
177 | qoper8Build: this.build,
|
178 | docStoreBuild: this.documentStore.build,
|
179 | xpressBuild: this.xpress.build,
|
180 | yexpertmVersion: rep.data,
|
181 | yexpertjsBuild: build
|
182 | };
|
183 | //console.log("-----buildDetails: " + JSON.stringify(buildDetails));
|
184 | if (this.userDefined.config && this.userDefined.config.qxBuild) buildDetails.qxBuild = this.userDefined.config.qxBuild;
|
185 | finished(buildDetails);
|
186 | }
|
187 | else {
|
188 | finished({error: 'Unauthenticated'});
|
189 | }
|
190 | },
|
191 | getMasterProcessDetails: function(messageObj, session, send, finished) {
|
192 | if (session.authenticated) {
|
193 | //var details = {};
|
194 | //if (this.userDefined.config && this.userDefined.config.masterProcessPid) details.pid = this.userDefined.config.masterProcessPid;
|
195 | //finished(details);
|
196 | finished({ok: true});
|
197 | }
|
198 | else {
|
199 | finished({error: 'Unauthenticated'});
|
200 | }
|
201 | },
|
202 | stopMasterProcess: function(messageObj, session, send, finished) {
|
203 | if (session.authenticated) {
|
204 | send({displayButton: true});
|
205 | finished({closeSocket: true});
|
206 | }
|
207 | else {
|
208 | finished({error: 'Unauthenticated'});
|
209 | }
|
210 | },
|
211 |
|
212 | getWorkerDetails: function(messageObj, session, send, finished) {
|
213 | if (session.authenticated) {
|
214 | finished({ok: true});
|
215 | }
|
216 | else {
|
217 | finished({error: 'Unauthenticated'});
|
218 | }
|
219 | },
|
220 |
|
221 | stopWorkerProcess: function(messageObj, session, send, finished) {
|
222 | finished({pid: messageObj.params.pid});
|
223 | },
|
224 |
|
225 | setPoolSize: function(messageObj, session, send, finished) {
|
226 | finished({poolSize: messageObj.params.poolSize});
|
227 | },
|
228 |
|
229 | getPoolSize: function(messageObj, session, send, finished) {
|
230 | finished({ok: true});
|
231 | },
|
232 |
|
233 | getGlobalDirectory: function(messageObj, session, send, finished) {
|
234 | var dir = this.db.global_directory();
|
235 | finished(dir);
|
236 | },
|
237 |
|
238 | getNextSubscripts: function(messageObj, session, send, finished) {
|
239 | var subscripts = messageObj.params.path.split('.');
|
240 | var global = subscripts.shift();
|
241 | var glo = new this.documentStore.DocumentNode(global, subscripts);
|
242 | var data = {};
|
243 | glo.forEachChild(function(name, node) {
|
244 | if (node.hasChildren) {
|
245 | data[name] = messageObj.params.expandText
|
246 | }
|
247 | else data[name] = node.value;
|
248 | });
|
249 | finished(data);
|
250 | },
|
251 |
|
252 | getSessions: function(messageObj, session, send, finished) {
|
253 | var activeSessions = this.sessions.active();
|
254 | var sessions = [];
|
255 | var disabled;
|
256 | activeSessions.forEach(function(ewdSession) {
|
257 | disabled = false;
|
258 | if (ewdSession.id.toString() === session.id.toString()) disabled = true;
|
259 | sessions.push({
|
260 | id: ewdSession.id,
|
261 | token: ewdSession.token,
|
262 | application: ewdSession.application,
|
263 | expiry: ewdSession.expiryTime,
|
264 | disabled: disabled
|
265 | });
|
266 | });
|
267 | finished(sessions);
|
268 | },
|
269 |
|
270 | stopSession: function(messageObj, session, send, finished) {
|
271 | var ewdSession = this.sessions.byToken(messageObj.params.token);
|
272 | if (ewdSession) ewdSession.delete();
|
273 | finished({ok: true});
|
274 | },
|
275 |
|
276 | showSession: function(messageObj, session, send, finished) {
|
277 | var token = messageObj.params.token;
|
278 | var ewdSession = this.sessions.byToken(token);
|
279 | if (ewdSession) {
|
280 | var data = {};
|
281 | var expandText = ' -->';
|
282 | ewdSession.data.forEachChild(function(name, childNode) {
|
283 | data[name] = expandText;
|
284 | if (childNode.hasValue) data[name] = childNode.value;
|
285 | if (name === 'ewd_symbolTable') data[name] = 'Mumps Symbol Table Data';
|
286 | });
|
287 | finished({
|
288 | token: token,
|
289 | id: ewdSession.id,
|
290 | data: data
|
291 | });
|
292 | }
|
293 | else {
|
294 | finished({
|
295 | token: token,
|
296 | error: 'Session no longer exists'
|
297 | });
|
298 | }
|
299 | },
|
300 |
|
301 | getSessionSubscripts: function(messageObj, session, send, finished) {
|
302 | var subs = messageObj.params.path.split('.');
|
303 | var token = messageObj.params.token;
|
304 | var ewdSession = this.sessions.byToken(token);
|
305 | if (ewdSession) {
|
306 | var documentName = ewdSession.documentName;
|
307 | var subscripts = ewdSession.data._node.subscripts.concat(subs);
|
308 | var doc = new this.documentStore.DocumentNode(documentName, subscripts);
|
309 | var data = {};
|
310 | doc.forEachChild(function(name, childNode) {
|
311 | data[name] = messageObj.params.expandText;
|
312 | if (childNode.hasValue) data[name] = childNode.value;
|
313 | });
|
314 | finished({
|
315 | data: data
|
316 | });
|
317 | }
|
318 | else {
|
319 | finished({error: 'Session no longer exists'});
|
320 | }
|
321 | }
|
322 | },
|
323 |
|
324 |
|
325 |
|
326 | workerResponseHandlers: {
|
327 | // allow interception by master process to augment / process the request after authentication in worker
|
328 |
|
329 | getMasterProcessDetails: function(message) {
|
330 | var stats = this.getStats();
|
331 | return {
|
332 | pid: process.pid,
|
333 | startTime: new Date(this.startTime).toLocaleString(),
|
334 | upTime: stats.uptime,
|
335 | memory: stats.memory
|
336 | }
|
337 | },
|
338 |
|
339 | getWorkerDetails: function(message, send) {
|
340 | // use special handler function for getting stats for master and workers
|
341 | var that = this;
|
342 | this.handleStats(function(messageObj) {
|
343 | var resultObj = {
|
344 | type: 'getWorkerDetails',
|
345 | results: messageObj.worker
|
346 | };
|
347 | send(resultObj);
|
348 | });
|
349 | return;
|
350 | },
|
351 |
|
352 | stopMasterProcess: function(message) {
|
353 |
|
354 | if (message.displayButton) return message ;
|
355 |
|
356 | // delay slightly to allow response to be sent to browser
|
357 | var that = this;
|
358 | setTimeout(function() {
|
359 | that.stop();
|
360 | }, 2000);
|
361 | //return {disconnect: true, error: 'EWD AppRunner has been shut down'};
|
362 | return {ok: true};
|
363 | },
|
364 |
|
365 | stopWorkerProcess: function(message) {
|
366 | this.stopWorker(message.pid);
|
367 | return {pid: message.pid};
|
368 | },
|
369 |
|
370 | getPoolSize: function(message) {
|
371 | return {poolSize: this.worker.poolSize};
|
372 | },
|
373 |
|
374 | setPoolSize: function(message) {
|
375 | this.setWorkerPoolSize(message.poolSize);
|
376 | return {ok: true};
|
377 | }
|
378 |
|
379 | }
|
380 |
|
381 | };
|
382 | </code></pre>
|
383 | </article>
|
384 | </section>
|
385 |
|
386 |
|
387 |
|
388 |
|
389 | </div>
|
390 |
|
391 | <nav>
|
392 | <h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-lib_yexper-js.html">lib/yexper-js</a></li></ul><h3>Classes</h3><ul><li><a href="module-lib_yexper-js.handlers.cdNameSpace.html">cdNameSpace</a></li><li><a href="module-lib_yexper-js.handlers.getNameSpace.html">getNameSpace</a></li></ul>
|
393 | </nav>
|
394 |
|
395 | <br class="clear">
|
396 |
|
397 | <footer>
|
398 | Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Sun Jan 29 2017 13:56:33 GMT+0100 (CET)
|
399 | </footer>
|
400 |
|
401 | <script> prettyPrint(); </script>
|
402 | <script src="scripts/linenumber.js"> </script>
|
403 | </body>
|
404 | </html>
|