in modules/backend/app/browsersHandler.js [210:304]
nodeListeners(sock) {
// Return command result from grid to browser.
sock.on('node:rest', (arg, cb) => {
const {clusterId, params, credentials} = arg || {};
if (!_.isFunction(cb))
cb = console.log;
const demo = _.get(sock, 'request._query.IgniteDemoMode') === 'true';
if ((_.isNil(clusterId) && !demo) || _.isNil(params)) {
console.log('Received invalid message: "node:rest" on socket:', JSON.stringify(sock.handshake));
return cb('Invalid format of message: "node:rest"');
}
const agent = this._agentHnd.agent(sock.request.user, demo, clusterId);
const token = sock.request.user.token;
this.executeOnNode(agent, token, demo, credentials, params)
.then((data) => cb(null, data))
.catch((err) => cb(this.errorTransformer(err)));
});
const internalVisor = (postfix) => `org.apache.ignite.internal.visor.${postfix}`;
this.registerVisorTask('querySql', internalVisor('query.VisorQueryTask'), internalVisor('query.VisorQueryArg'));
this.registerVisorTask('querySqlV2', internalVisor('query.VisorQueryTask'), internalVisor('query.VisorQueryArgV2'));
this.registerVisorTask('querySqlV3', internalVisor('query.VisorQueryTask'), internalVisor('query.VisorQueryArgV3'));
this.registerVisorTask('querySqlX2', internalVisor('query.VisorQueryTask'), internalVisor('query.VisorQueryTaskArg'));
this.registerVisorTask('queryScanX2', internalVisor('query.VisorScanQueryTask'), internalVisor('query.VisorScanQueryTaskArg'));
this.registerVisorTask('queryFetch', internalVisor('query.VisorQueryNextPageTask'), 'org.apache.ignite.lang.IgniteBiTuple', 'java.lang.String', 'java.lang.Integer');
this.registerVisorTask('queryFetchX2', internalVisor('query.VisorQueryNextPageTask'), internalVisor('query.VisorQueryNextPageTaskArg'));
this.registerVisorTask('queryFetchFirstPage', internalVisor('query.VisorQueryFetchFirstPageTask'), internalVisor('query.VisorQueryNextPageTaskArg'));
this.registerVisorTask('queryPing', internalVisor('query.VisorQueryPingTask'), internalVisor('query.VisorQueryNextPageTaskArg'));
this.registerVisorTask('queryClose', internalVisor('query.VisorQueryCleanupTask'), 'java.util.Map', 'java.util.UUID', 'java.util.Set');
this.registerVisorTask('queryCloseX2', internalVisor('query.VisorQueryCleanupTask'), internalVisor('query.VisorQueryCleanupTaskArg'));
this.registerVisorTask('toggleClusterState', internalVisor('misc.VisorChangeGridActiveStateTask'), internalVisor('misc.VisorChangeGridActiveStateTaskArg'));
this.registerVisorTask('cacheNamesCollectorTask', internalVisor('cache.VisorCacheNamesCollectorTask'), 'java.lang.Void');
this.registerVisorTask('cacheNodesTask', internalVisor('cache.VisorCacheNodesTask'), 'java.lang.String');
this.registerVisorTask('cacheNodesTaskX2', internalVisor('cache.VisorCacheNodesTask'), internalVisor('cache.VisorCacheNodesTaskArg'));
// Return command result from grid to browser.
sock.on('node:visor', (arg, cb) => {
const {clusterId, params, credentials} = arg || {};
if (!_.isFunction(cb))
cb = console.log;
const demo = _.get(sock, 'request._query.IgniteDemoMode') === 'true';
if ((_.isNil(clusterId) && !demo) || _.isNil(params)) {
console.log('Received invalid message: "node:visor" on socket:', JSON.stringify(sock.handshake));
return cb('Invalid format of message: "node:visor"');
}
const {taskId, nids, args = []} = params;
const desc = this._visorTasks.get(taskId);
if (_.isNil(desc))
return cb(this.errorTransformer(new errors.IllegalArgumentException(`Failed to find Visor task for id: ${taskId}`)));
const exeParams = {
cmd: 'exe',
name: 'org.apache.ignite.internal.visor.compute.VisorGatewayTask',
p1: nids,
p2: desc.taskCls
};
_.forEach(_.concat(desc.argCls, args), (param, idx) => { exeParams[`p${idx + 3}`] = param; });
const agent = this._agentHnd.agent(sock.request.user, demo, clusterId);
const token = sock.request.user.token;
this.executeOnNode(agent, token, demo, credentials, exeParams)
.then((data) => {
if (data.finished && !data.zipped)
return cb(null, data.result);
return cb(null, data);
})
.catch((err) => cb(this.errorTransformer(err)));
});
}