提交 b7923480 编写于 作者: R rsercano

#352

上级 daec37fe
......@@ -17,6 +17,7 @@ const packageJson = require('/package.json');
const mongodbUrlParser = require('parse-mongo-url');
const checkAuthenticationOfConnection = function (connection) {
LOGGER.info('[checkAuthenticationOfConnection]', connection.authenticationType);
if (connection.authenticationType !== 'scram_sha_1') delete connection.scram_sha_1;
if (connection.authenticationType !== 'mongodb_cr') delete connection.mongodb_cr;
if (connection.authenticationType !== 'mongodb_x509') delete connection.mongodb_x509;
......@@ -31,6 +32,7 @@ const checkAuthenticationOfConnection = function (connection) {
export const parseUrl = function (connection) {
try {
LOGGER.info('[parseUrl]', connection.url);
let parsedUrl = mongodbUrlParser(connection.url);
connection.options = connection.options || {};
connection.ssl = connection.ssl || {};
......@@ -92,6 +94,7 @@ const checkConnection = function (connection) {
};
const saveConnectionToDB = function (connection) {
LOGGER.info('[saveConnectionToDB]', JSON.stringify(connection));
if (connection._id) {
Connections.remove({_id: connection._id});
}
......@@ -101,6 +104,7 @@ const saveConnectionToDB = function (connection) {
Meteor.methods({
subscribed(){
LOGGER.info('[subscriber]', 'setting as subscribed');
Settings.update({}, {
$set: {subscribed: true}
});
......@@ -128,6 +132,7 @@ Meteor.methods({
checkMongoclientVersion(){
try {
LOGGER.info('[checkMongoclientVersion]');
const response = HTTP.get('https://api.github.com/repos/mongoclient/mongoclient/releases/latest', {headers: {"User-Agent": "Mongoclient"}});
if (response && response.data && response.data.name && response.data.name !== packageJson.version) {
return "There's a new version of mongoclient: " + response.data.name + ", <a href='https://github.com/mongoclient/mongoclient/releases/latest' target='_blank'>download here</a>, if you're using docker just use pull for the <b>" + response.data.name + "</b> or <b>latest</b> tag !";
......@@ -139,14 +144,17 @@ Meteor.methods({
},
removeSchemaAnalyzeResult(sessionId){
LOGGER.info('[removeSchemaAnalyzeResult]', sessionId);
SchemaAnalyzeResult.remove({sessionId: sessionId});
},
saveActions(action) {
LOGGER.info('[saveActions]', action);
Actions.insert(action);
},
saveQueryHistory(history) {
LOGGER.info('[saveQueryHistory]', history);
const queryHistoryCount = QueryHistory.find({
connectionId: history.connectionId,
collectionName: history.collectionName
......@@ -160,6 +168,7 @@ Meteor.methods({
},
updateDump(dump) {
LOGGER.info('[updateDump]', dump._id, dump.connectionName, dump.connectionId, dump.status);
Dumps.update({_id: dump._id}, {
$set: {
connectionName: dump.connectionName,
......@@ -173,19 +182,23 @@ Meteor.methods({
},
saveDump(dump) {
LOGGER.info('[saveDump]', dump._id, dump.connectionName, dump.connectionId, dump.status);
Dumps.insert(dump);
},
updateSettings(settings) {
LOGGER.info('[updateSettings]', JSON.stringify(settings));
Settings.remove({});
Settings.insert(settings);
},
saveConnection(connection) {
LOGGER.info('[saveConnection]', JSON.stringify(connection));
saveConnectionToDB(connection)
},
checkAndSaveConnection(connection){
LOGGER.info('[checkAndSaveConnection]', JSON.stringify(connection));
checkConnection(connection);
if (!connection.databaseName) {
......@@ -200,6 +213,7 @@ Meteor.methods({
},
removeConnection(connectionId) {
LOGGER.info('[removeConnection]', connectionId);
Connections.remove(connectionId);
Dumps.remove({connectionId: connectionId});
QueryHistory.remove({connectionId: connectionId});
......
......@@ -9,7 +9,7 @@ import {databasesBySessionId} from "./methods_common";
const proceedQueryExecution = function (methodArray, runOnAdminDB, sessionId) {
LOGGER.info(JSON.stringify(methodArray), runOnAdminDB);
LOGGER.info(JSON.stringify(methodArray), runOnAdminDB, sessionId);
let result = Async.runSync(function (done) {
try {
......@@ -35,7 +35,7 @@ const proceedQueryExecution = function (methodArray, runOnAdminDB, sessionId) {
}
}
catch (ex) {
LOGGER.error(methodArray, ex);
LOGGER.error(methodArray, sessionId, ex);
done(new Meteor.Error(ex.message), null);
}
});
......@@ -45,7 +45,7 @@ const proceedQueryExecution = function (methodArray, runOnAdminDB, sessionId) {
Meteor.methods({
top(sessionId){
LOGGER.info('[top]');
LOGGER.info('[top]', sessionId);
let result = Async.runSync(function (done) {
try {
......@@ -54,7 +54,7 @@ Meteor.methods({
});
}
catch (ex) {
LOGGER.error('[top]', ex);
LOGGER.error('[top]', sessionId, ex);
done(new Meteor.Error(ex.message), null);
}
});
......@@ -63,7 +63,7 @@ Meteor.methods({
},
dbStats(sessionId) {
LOGGER.info('[stats]');
LOGGER.info('[stats]', sessionId);
let result = Async.runSync(function (done) {
try {
......@@ -72,7 +72,7 @@ Meteor.methods({
});
}
catch (ex) {
LOGGER.error('[stats]', ex);
LOGGER.error('[stats]', sessionId, ex);
done(new Meteor.Error(ex.message), null);
}
});
......
......@@ -11,7 +11,7 @@ import {databasesBySessionId} from "./methods_common";
const proceedMapReduceExecution = function (selectedCollection, map, reduce, options, sessionId) {
options = Helper.convertJSONtoBSON(options);
LOGGER.info('[mapReduce]', selectedCollection, map, reduce, options);
LOGGER.info('[mapReduce]', selectedCollection, map, reduce, options, sessionId);
let result = Async.runSync(function (done) {
try {
......@@ -32,7 +32,7 @@ const proceedMapReduceExecution = function (selectedCollection, map, reduce, opt
});
}
catch (ex) {
LOGGER.error('[mapReduce]', ex);
LOGGER.error('[mapReduce]', sessionId, ex);
done(new Meteor.Error(ex.message), null);
}
});
......@@ -41,7 +41,7 @@ const proceedMapReduceExecution = function (selectedCollection, map, reduce, opt
};
export const proceedQueryExecution = function (selectedCollection, methodArray, sessionId, removeCollectionTopology) {
LOGGER.info(JSON.stringify(methodArray), selectedCollection);
LOGGER.info(JSON.stringify(methodArray), selectedCollection, sessionId);
let result = Async.runSync(function (done) {
try {
......@@ -67,7 +67,7 @@ export const proceedQueryExecution = function (selectedCollection, methodArray,
}
}
catch (ex) {
LOGGER.error(methodArray, ex);
LOGGER.error(methodArray, sessionId, ex);
done(new Meteor.Error(ex.message), null);
}
});
......
......@@ -29,13 +29,13 @@ const connectToShell = function (connectionId, sessionId) {
const connectionUrl = Helper.getConnectionUrl(connection);
const mongoPath = getProperMongo();
LOGGER.info('[shell]', mongoPath, connectionUrl);
LOGGER.info('[shell]', mongoPath, connectionUrl, sessionId);
spawnedShellsBySessionId[sessionId] = spawn(mongoPath, [connectionUrl]);
setEventsToShell(connectionId, sessionId);
}
if (spawnedShellsBySessionId[sessionId]) {
LOGGER.info('[shell]', 'executing command "use ' + connection.databaseName + '" on shell');
LOGGER.info('[shell]', 'executing command "use ' + connection.databaseName + '" on shell', sessionId);
spawnedShellsBySessionId[sessionId].stdin.write('use ' + connection.databaseName + '\n');
}
else {
......@@ -44,7 +44,7 @@ const connectToShell = function (connectionId, sessionId) {
}
catch (ex) {
spawnedShellsBySessionId[sessionId] = null;
LOGGER.error('[shell]', ex);
LOGGER.error('[shell]', sessionId, ex);
return {err: new Meteor.Error(ex.message), result: null};
}
};
......@@ -101,7 +101,7 @@ const proceedConnectingMongodb = function (dbName, sessionId, connectionUrl, con
mongodbApi.MongoClient.connect(connectionUrl, connectionOptions, function (mainError, db) {
try {
if (mainError || !db) {
LOGGER.error(mainError, db);
LOGGER.error(mainError, sessionId, db);
done(mainError, db);
if (db) db.close();
if (tunnelsBySessionId[sessionId]) {
......@@ -116,7 +116,7 @@ const proceedConnectingMongodb = function (dbName, sessionId, connectionUrl, con
});
}
catch (ex) {
LOGGER.error('[connect]', ex);
LOGGER.error('[connect]', sessionId, ex);
done(new Meteor.Error(ex.message), null);
if (db) db.close();
if (tunnelsBySessionId[sessionId]) {
......@@ -128,10 +128,10 @@ const proceedConnectingMongodb = function (dbName, sessionId, connectionUrl, con
};
const setEventsToShell = function (connectionId, sessionId) {
LOGGER.info('[shell]', 'binding events to shell');
LOGGER.info('[shell]', 'binding events to shell', connectionId, sessionId);
spawnedShellsBySessionId[sessionId].on('error', Meteor.bindEnvironment(function (err) {
LOGGER.error('unexpected error on spawned shell: ' + err);
LOGGER.error('unexpected error on spawned shell: ' + err, sessionId);
spawnedShellsBySessionId[sessionId] = null;
if (err) {
ShellCommands.insert({
......@@ -237,7 +237,7 @@ Meteor.methods({
},
listCollectionNames(dbName, sessionId) {
LOGGER.info('[listCollectionNames]', dbName);
LOGGER.info('[listCollectionNames]', dbName, sessionId);
return Async.runSync(function (done) {
try {
......@@ -247,7 +247,7 @@ Meteor.methods({
});
}
catch (ex) {
LOGGER.error('[listCollectionNames]', ex);
LOGGER.error('[listCollectionNames]', sessionId, ex);
done(new Meteor.Error(ex.message), null);
}
});
......@@ -255,7 +255,7 @@ Meteor.methods({
},
getDatabases(sessionId) {
LOGGER.info('[getDatabases]');
LOGGER.info('[getDatabases]', sessionId);
return Async.runSync(function (done) {
try {
......@@ -269,13 +269,15 @@ Meteor.methods({
});
}
catch (ex) {
LOGGER.error('[getDatabases]', ex);
LOGGER.error('[getDatabases]', sessionId, ex);
done(new Meteor.Error(ex.message), null);
}
});
},
disconnect(sessionId) {
LOGGER.info('[disconnect]', sessionId);
if (databasesBySessionId[sessionId]) {
databasesBySessionId[sessionId].close();
}
......@@ -292,7 +294,7 @@ Meteor.methods({
const connectionUrl = Helper.getConnectionUrl(connection);
const connectionOptions = Helper.getConnectionOptions(connection);
LOGGER.info('[connect]', connectionUrl, Helper.clearConnectionOptionsForLog(connectionOptions));
LOGGER.info('[connect]', connectionUrl, Helper.clearConnectionOptionsForLog(connectionOptions), sessionId);
return Async.runSync(function (done) {
try {
......@@ -309,7 +311,7 @@ Meteor.methods({
if (connection.ssh.passPhrase) config.passphrase = connection.ssh.passPhrase;
if (connection.ssh.password) config.password = connection.ssh.password;
LOGGER.info('[connect]', '[ssh]', 'ssh is enabled, config is ' + JSON.stringify(config));
LOGGER.info('[connect]', '[ssh]', sessionId, 'ssh is enabled, config is ' + JSON.stringify(config));
tunnelsBySessionId[sessionId] = tunnelSsh(config, Meteor.bindEnvironment(function (error) {
if (error) {
done(new Meteor.Error(error.message), null);
......@@ -333,14 +335,14 @@ Meteor.methods({
}
}
catch (ex) {
LOGGER.error('[connect]', ex);
LOGGER.error('[connect]', sessionId, ex);
done(new Meteor.Error(ex.message), null);
}
});
},
dropDB(sessionId) {
LOGGER.info('[dropDatabase]');
LOGGER.info('[dropDatabase]', sessionId);
return Async.runSync(function (done) {
try {
......@@ -349,14 +351,14 @@ Meteor.methods({
});
}
catch (ex) {
LOGGER.error('[dropDatabase]', ex);
LOGGER.error('[dropDatabase]', sessionId, ex);
done(new Meteor.Error(ex.message), null);
}
});
},
dropCollection(collectionName, sessionId) {
LOGGER.info('[dropCollection]', collectionName);
LOGGER.info('[dropCollection]', sessionId, collectionName);
return Async.runSync(function (done) {
try {
......@@ -366,13 +368,14 @@ Meteor.methods({
});
}
catch (ex) {
LOGGER.error('[dropCollection]', ex);
LOGGER.error('[dropCollection]', sessionId, ex);
done(new Meteor.Error(ex.message), null);
}
});
},
dropAllCollections(sessionId) {
LOGGER.info('[dropAllCollections]', sessionId);
return Async.runSync(function (done) {
try {
databasesBySessionId[sessionId].collections(function (err, collections) {
......@@ -380,14 +383,14 @@ Meteor.methods({
});
}
catch (ex) {
LOGGER.error('[dropAllCollections]', ex);
LOGGER.error('[dropAllCollections]', sessionId, ex);
done(new Meteor.Error(ex.message), null);
}
});
},
createCollection(collectionName, options, sessionId) {
LOGGER.info('[createCollection]', collectionName, JSON.stringify(options));
LOGGER.info('[createCollection]', collectionName, sessionId, JSON.stringify(options));
return Async.runSync(function (done) {
try {
......@@ -396,19 +399,19 @@ Meteor.methods({
});
}
catch (ex) {
LOGGER.error('[createCollection]', ex);
LOGGER.error('[createCollection]', sessionId, ex);
done(new Meteor.Error(ex.message), null);
}
});
},
clearShell(sessionId){
LOGGER.info('[clearShell]');
LOGGER.info('[clearShell]', sessionId);
ShellCommands.remove({'sessionId': sessionId});
},
executeShellCommand(command, connectionId, sessionId){
LOGGER.info('[shellCommand]', command, connectionId);
LOGGER.info('[shellCommand]', sessionId, command, connectionId);
if (!spawnedShellsBySessionId[sessionId]) connectToShell(connectionId, sessionId);
if (spawnedShellsBySessionId[sessionId]) spawnedShellsBySessionId[sessionId].stdin.write(command + '\n');
},
......@@ -423,7 +426,7 @@ Meteor.methods({
let args = [connectionUrl, '--quiet', '--eval', 'var collection =\"' + collection + '\", outputFormat=\"json\"', getMongoExternalsPath() + '/variety/variety.js_'];
LOGGER.info('[analyzeSchema]', args, collection);
LOGGER.info('[analyzeSchema]', sessionId, args, collection);
try {
let spawned = spawn(mongoPath, args);
let message = "";
......@@ -456,7 +459,7 @@ Meteor.methods({
spawned.stdin.end();
}
catch (ex) {
LOGGER.error('[analyzeSchema]', ex);
LOGGER.error('[analyzeSchema]', sessionId, ex);
return {err: new Meteor.Error(ex.message), result: null};
}
......
......@@ -17,7 +17,7 @@ Meteor.methods({
mongoimport(blob, collection, sessionId){
try {
let buffer = new Buffer(blob);
LOGGER.info('[mongoimport]', collection);
LOGGER.info('[mongoimport]', sessionId, collection);
const methodArray = [
{
......@@ -26,7 +26,7 @@ Meteor.methods({
];
return proceedQueryExecution(collection, methodArray, sessionId);
} catch (ex) {
LOGGER.error('[mongoimport]', ex);
LOGGER.error('[mongoimport]', sessionId, ex);
throw new Meteor.Error(ex.message);
}
},
......
......@@ -31,14 +31,14 @@ Meteor.methods({
ids.push(obj._id);
}
LOGGER.info(JSON.stringify(selector) + " removing from " + bucketName + ".files");
LOGGER.info(JSON.stringify(selector) + " removing from " + bucketName + ".files", sessionId);
filesCollection.deleteMany({_id: {$in: ids}}, {}, function (err) {
if (err) {
done(err, null);
return;
}
LOGGER.info(JSON.stringify(selector) + " removing from " + bucketName + ".chunks");
LOGGER.info(JSON.stringify(selector) + " removing from " + bucketName + ".chunks", sessionId);
chunksCollection.deleteMany({files_id: {$in: ids}}, function (err) {
done(err, null);
})
......@@ -46,7 +46,7 @@ Meteor.methods({
});
}
catch (ex) {
LOGGER.error('[deleteFiles]', ex);
LOGGER.error('[deleteFiles]', sessionId, ex);
done(new Meteor.Error(ex.message), null);
}
});
......@@ -65,7 +65,7 @@ Meteor.methods({
});
}
catch (ex) {
LOGGER.error('[deleteFile]', ex);
LOGGER.error('[deleteFile]', sessionId, ex);
done(new Meteor.Error(ex.message), null);
}
});
......@@ -89,7 +89,7 @@ Meteor.methods({
}
catch (ex) {
LOGGER.error('[getFileInfos]', ex);
LOGGER.error('[getFileInfos]', sessionId, ex);
done(new Meteor.Error(ex.message), null);
}
});
......@@ -120,7 +120,7 @@ Meteor.methods({
});
}
catch (ex) {
LOGGER.error('[uploadFile]', ex);
LOGGER.error('[uploadFile]', sessionId, ex);
done(new Meteor.Error(ex.message), null);
}
});
......@@ -141,7 +141,7 @@ Meteor.methods({
});
}
catch (ex) {
LOGGER.error('[getFile]', ex);
LOGGER.error('[getFile]', sessionId, ex);
done(new Meteor.Error(ex.message), null);
}
});
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册