00001
00002
00003
00004
00005
00006
00007
00008
00009 var Emitter = require("events").EventEmitter;
00010 var fs = require("fs");
00011 var stream = require("stream");
00012 var child_process = require("child_process");
00013 var Utils = require("./Utils");
00014 var Connector = require("./DBConnector");
00015 var path_module = require("path");
00016 var db = new Emitter();
00017
00018
00019
00020 var DefaultColumns = [
00021 {
00022 name: "name",
00023 type: "string",
00024 editable: false,
00025 display: true
00026 },
00027 {
00028 name: "value",
00029 type: "string",
00030 editable: true,
00031 display: true
00032 },
00033 {
00034 name: "annotation",
00035 title: "User Comment",
00036 type: "string",
00037 editable: true,
00038 display: true
00039 },
00040 {
00041 name: "comment",
00042 type: "comment",
00043 editable: false,
00044 display: false
00045 },
00046 {
00047 name: "type",
00048 type: "string",
00049 editable: false,
00050 display: false
00051 },
00052 {
00053 name: "values",
00054 type: "array",
00055 editable: false,
00056 display: false
00057 }, {
00058 name: "children",
00059 type: "array",
00060 editable: false,
00061 display: false
00062 }
00063 ];
00064
00065 var MakeDbConfig = function (configFile) {
00066 var defaultConfig = {
00067 dbprovider: "filesystem"
00068 , configNameFilter: "*"
00069 , baseDir: process.env.ARTDAQ_DATABASE_URI ? process.env["ARTDAQ_DATABASE_URI"] : ""
00070 , mongoConfig: {
00071 dbUser: "anonymous"
00072 , dbHost: "localhost"
00073 , dbPort: 27017
00074 }
00075 , instanceName: configFile.instanceName ? configFile.instanceName : "test_db"
00076 };
00077
00078 if (defaultConfig.baseDir.indexOf("filesystemdb://") === 0) {
00079 console.log("Parsing filesystemdb URI: " + defaultConfig.baseDir);
00080 defaultConfig.baseDir = defaultConfig.baseDir.replace("filesystemdb://", "").replace(/\/$/, "");
00081 var tempArr = defaultConfig.baseDir.split('/');
00082 defaultConfig.instanceName = tempArr.splice(-1);
00083 defaultConfig.baseDir = tempArr.slice(0,-1).join('/');
00084 } else if (defaultConfig.baseDir.indexOf("mongodb://") === 0) {
00085 console.log("Parsing mongodb URI: " + defaultConfig.baseDir);
00086 var matches = defaultConfig.baseDir.match(/mongodb:\/\/(?:([^@:]*)(?::([^@]*))?@)?([^:]*):([0-9]+)\/([^/]*)\/?/);
00087 defaultConfig.baseDir = "";
00088 defaultConfig.dbprovider = "mongo";
00089 console.log(JSON.stringify(matches, null, 4));
00090 defaultConfig.mongoConfig.dbUser = matches[1] ? matches[1] : "";
00091 var pass = matches[2];
00092 if (pass !== null && pass !== undefined) {
00093 fs.writeFileSync(".dbpasswd", pass);
00094 }
00095 defaultConfig.mongoConfig.dbHost = matches[3];
00096 defaultConfig.mongoConfig.dbPort = matches[4];
00097 defaultConfig.instanceName = matches[5];
00098 }
00099
00100 if (defaultConfig.baseDir === "") {
00101 defaultConfig.baseDir = process.env["ARTDAQ_DATABASE_DIR"];
00102 }
00103
00104 console.log("DBConfig: " + JSON.stringify(defaultConfig, null, 4));
00105 return defaultConfig;
00106 };
00107
00108 function GetFileBase(configName, collection, entity) {
00109 return path_module.join(configName, collection, entity + ".gui.json");
00110 }
00111
00112 function GetTempFilePath(configName, collection, entity, dirs) {
00113 var filebase = GetFileBase(configName, collection, entity);
00114
00115 if (!fs.existsSync(path_module.join(dirs.tmp, configName))) fs.mkdirSync(path_module.join(dirs.tmp, configName));
00116 if (!fs.existsSync(path_module.join(dirs.tmp, configName, collection))) fs.mkdirSync(path_module.join(dirs.tmp, configName, collection));
00117 return path_module.join(dirs.tmp, filebase);
00118 }
00119
00120 function GetFilePath(configName, collection, entity, dirs, dbOnly) {
00121 var filebase = GetFileBase(configName, collection, entity);
00122 console.log("GetFilePath: filebase is " + filebase + ", dirs: " + JSON.stringify(dirs, null, 4));
00123 if (!dbOnly && fs.existsSync(path_module.join(dirs.tmp, filebase))) {
00124 return path_module.join(dirs.tmp, filebase);
00125 }
00126
00127 if (!fs.existsSync(path_module.join(dirs.db, configName))) fs.mkdirSync(path_module.join(dirs.db, configName));
00128 if (!fs.existsSync(path_module.join(dirs.db, configName, collection))) fs.mkdirSync(path_module.join(dirs.db, configName, collection));
00129 return path_module.join(dirs.db, filebase);
00130 }
00131
00137 function LoadFile(fileInfo, dirs, dbConfig) {
00138 console.log("LoadFile: fileInfo: " + JSON.stringify(fileInfo, null, 4) + ", dirs: " + JSON.stringify(dirs, null, 4) + ", dbConfig: " + JSON.stringify(dbConfig, null, 4));
00139 var output = {
00140 data: {}
00141 , filePath: ""
00142 , entity: ""
00143 , collection: ""
00144 , configName: ""
00145 };
00146
00147 output.entity = fileInfo.query.filter["entities.name"];
00148 output.collection = fileInfo.query.collection;
00149 output.configName = fileInfo.query.filter["configurations.name"];
00150
00151 console.log("File info: " + JSON.stringify(fileInfo, null, 4));
00152 output.filePath = GetFilePath(output.configName, output.collection, output.entity, dirs, true);
00153
00154 if (!fs.existsSync(output.filePath)) {
00155 console.log("Loading file from database");
00156 output.data = Connector.RunLoadQuery(dbConfig, fileInfo.query);
00157 console.log("Writing file " + output.filePath);
00158 fs.writeFileSync(output.filePath, JSON.stringify(output.data, null, 4));
00159 } else {
00160 output.data = JSON.parse("" + fs.readFileSync(output.filePath));
00161 }
00162 console.log("File Data: " + JSON.stringify(output, null, 4));
00163 console.log("Done Loading file");
00164 return output;
00165 }
00166
00178 function FetchFile(fileInfo, dataFormat, dbdirectory, dbConfig) {
00179 console.log("FetchFile: fileInfo: " + JSON.stringify(fileInfo, null, 4) + ", dataFormat: " + dataFormat + ", dbDirectory: " + dbdirectory);
00180 var fileName = path_module.join(fileInfo.collection + "_" + fileInfo.name + "_" + fileInfo.version);
00181 if (dataFormat === "fhicl") {
00182 fileName += ".fcl";
00183 } else if (dataFormat === "gui") {
00184 fileName += ".gui.json";
00185 } else {
00186 fileName += ".json";
00187 }
00188 var filePath = path_module.join(dbdirectory, fileName);
00189 var query = {
00190 filter: {
00191 "entities.name": fileInfo.name,
00192 version: fileInfo.version
00193 },
00194 collection: fileInfo.collection,
00195 configurable_entity: fileInfo.name,
00196 dbprovider: dbConfig.dbprovider,
00197 operation: "load",
00198 dataformat: dataFormat
00199 };
00200 var fhiclData = Connector.RunLoadQuery(dbConfig, query, true);
00201 fs.writeFileSync(filePath, JSON.stringify(fhiclData, null, 4));
00202
00203 var stat = fs.statSync(filePath);
00204 return { fileName: fileName, filePath: filePath, size: stat.size }
00205 };
00206
00207 function MakeColumns(rowIn, index, columns, columnGroups, group) {
00208
00209 var rowOut = {
00210 children: []
00211 };
00212
00213 for (var p in rowIn) {
00214 if (rowIn.hasOwnProperty(p)) {
00215 var value = rowIn[p];
00216 if (value !== Object(value) && Utils.ContainsName(columns, p, "name") < 0) {
00217 columns.push({ name: p, type: "string", editable: true, display: true, columnGroup: group });
00218 rowOut[p] = value;
00219 } else if (value === Object(value)) {
00220 var res;
00221 if (Utils.ContainsName(columnGroups, p, "name") < 0) {
00222 columnGroups.push({ name: "" + p, text: "" + p, parentGroup: group });
00223 }
00224 if (value.constructor === Array) {
00225 for (var i in value) {
00226 if (value.hasOwnProperty(i)) {
00227 res = MakeColumns(value[i], index + "." + i, columns, columnGroups, p);
00228 columns = res.columns;
00229 columnGroups = res.columnGroups;
00230 res.row.name = rowIn.name + "/" + p + "___" + i;
00231 res.row.index = index + "." + i;
00232 rowOut.children.push(res.row);
00233 }
00234 }
00235 } else {
00236 res = MakeColumns(value, index, columns, columnGroups, p);
00237 columns = res.columns;
00238 columnGroups = res.columnGroups;
00239 for (var pp in res.row) {
00240 if (res.row.hasOwnProperty(pp)) {
00241 rowOut[pp] = res.row[pp];
00242 }
00243 }
00244
00245 }
00246 } else {
00247 rowOut[p] = value;
00248 }
00249 }
00250 }
00251 if (rowOut.children.length === 0) delete rowOut.children;
00252 else if (Utils.ContainsName(columns, "children", "name") < 0) { columns.push({ name: "children", type: "array", editable: false, display: false }); }
00253
00254 return { row: rowOut, columns: columns, columnGroups: columnGroups };
00255 }
00256
00263 function ParseSequence(sequence, name) {
00264 console.log("ParseSequence: sequence: " + JSON.stringify(sequence, null, 4) + ", name: " + name);
00265 var children = [];
00266 var hasTable = false;
00267 var rows = [];
00268 var columns = [];
00269 var columnGroups = [];
00270 columns.push({ name: "index", type: "number", editable: false, display: true, columnGroup: name });
00271 columns.push({ name: "name", type: "string", editable: false, display: true, columnGroup: name });
00272
00273 for (var i = 0; i < sequence.length; ++i) {
00274 if (sequence[i] === Object(sequence[i])) {
00275
00276 if (sequence[i].constructor === Array) {
00277
00278 var arr = ParseSequence(sequence[i], name + "___" + i);
00279 if (arr.children !== undefined && arr.children.length > 0) {
00280 children.push({ name: name + "___" + i, children: arr.children });
00281 rows.push({ index: i, name: name + "___" + i, children: arr.children });
00282 if (Utils.ContainsName(columns, "children", "name") < 0) {
00283 columns.push({ name: "children", type: "array", editable: false, display: false });
00284 }
00285 }
00286 if (arr.rows !== undefined && arr.rows.length > 0) {
00287 if (arr.hasTable) {
00288 hasTable = true;
00289 }
00290 for (var r in arr.rows) {
00291 if (arr.rows.hasOwnProperty(r)) {
00292 rows.push(arr.rows[r]);
00293 }
00294 }
00295 for (var c in arr.columns) {
00296 if (arr.columns.hasOwnProperty(c) && Utils.ContainsName(columns, arr.columns[c].name, "name") < 0) {
00297 columns.push(arr.columns[c]);
00298 }
00299 }
00300 }
00301 } else {
00302
00303 hasTable = true;
00304 console.log("Parsing as table: " + JSON.stringify(sequence[i], null, 4));
00305 if (!sequence[i].hasOwnProperty("name") || sequence[i].name.length === 0) {
00306 sequence[i].name = name + "___" + i;
00307 }
00308 if (Utils.ContainsName(columnGroups, name, "name") < 0) {
00309 columnGroups.push({ name: "" + name, text: "" + name });
00310 }
00311 var res = MakeColumns(sequence[i], i, columns, columnGroups, name);
00312 res.row.index = i;
00313 rows.push(res.row);
00314 columns = res.columns;
00315 columnGroups = res.columnGroups;
00316 }
00317 } else {
00318 var vname = name + "___" + i;
00319 var value = sequence[i];
00320 children.push({ name: vname, value: value });
00321 rows.push({ index: i, name: vname, value: value });
00322 if (Utils.ContainsName(columns, "value", "name") < 0) {
00323 columns.push({ name: "value", type: "string", editable: true, display: true, columnGroup: name });
00324 }
00325 }
00326 }
00327 var comment = sequence.comment ? sequence.comment : " ";
00328
00329 if (hasTable) {
00330 var table = {
00331 name: name
00332 , comment: comment
00333 , type: "table"
00334 , isSequence: true
00335 , table: {
00336 rows: rows
00337 , columns: columns
00338 , columnGroups: columnGroups
00339 }
00340 };
00341 console.log("\nParseSequence returning table: " + JSON.stringify(table, null, 4));
00342 return table;
00343 } else {
00344 var output = { name: name, comment: comment, children: children };
00345 console.log("\nParseSequence returning: " + JSON.stringify(output, null, 4));
00346 return output;
00347 }
00348 };
00349
00356 function ParseFhiclTable(table, sub) {
00357 console.log("ParseFhiclTable: table: " + JSON.stringify(table, null, 4) + ", sub: " + sub);
00358 var children = [];
00359 var subtables = [];
00360 var hasSubtables = false;
00361 var comment = table.comment ? table.comment : " ";
00362
00363
00364 for (var e in table.children) {
00365 if (table.children.hasOwnProperty(e)) {
00366 var element = table.children[e];
00367 if (element.type === "table" && element.isSequence) {
00368 element.type = "sequence";
00369 }
00370
00371 switch (element.type) {
00372 case "table":
00373
00374 hasSubtables = true;
00375 children.push(ParseFhiclTable(element, 1));
00376 break;
00377 case "sequence":
00378 children.push(ParseSequence(element.children, element.name));
00379 break;
00380 case "number":
00381 case "string":
00382 case "bool":
00383 children.push(element);
00384 break;
00385 default:
00386 console.log("Unknown type " + element.type + " encountered!");
00387 break;
00388 }
00389 }
00390 }
00391
00392 var obj = { name: table.name, hasSubtables: hasSubtables, children: children, subtables: subtables, type: "table", comment: comment, columns: DefaultColumns };
00393 if (sub === 0 || sub === undefined) {
00394
00395 }
00396 return obj;
00397 };
00398
00399 function FindConfigs(configNameFilter, dbConfig) {
00400 console.log("\nFindConfigs: Request for Named Configurations received");
00401 var configsOutput = { Success: false, data: [], configs: {} };
00402 try {
00403 var configs = Connector.RunGetConfigsQuery(dbConfig).search;
00404 for (var conf in configs) {
00405 if (configs.hasOwnProperty(conf)) {
00406 var config = configs[conf];
00407 if (config.name.search(configNameFilter) >= 0) {
00408 configsOutput.data.push("<option value=" + JSON.stringify(config.query) + ">" + config.name + "</option>");
00409 configsOutput.configs[config.name] = config.query;
00410 }
00411 }
00412 }
00413 if (configsOutput.data.length === 0) {
00414 configsOutput.data.push("<option value=\"\">No Configurations Found</option>");
00415 configsOutput.configs[configNameFilter] = {};
00416 }
00417 configsOutput.Success = true;
00418 } catch (e) {
00419 console.log("Exception caught: " + e.name + ": " + e.message);
00420 }
00421 console.log("NamedConfigs complete");
00422 return configsOutput;
00423 }
00424
00425 function FindInstances(dbConfig) {
00426 console.log("FindInstances: Request for Database Instances received");
00427 var instancesOutput = { Success: false, data: [] };
00428 instancesOutput.data.push("<option value=\"NONE\">Create New Database Instance</option>");
00429 try {
00430 var dbs = Connector.RunListDatabasesQuery(dbConfig, {}).search;
00431 for (var db in dbs) {
00432 if (dbs.hasOwnProperty(db)) {
00433 instancesOutput.data.push("<option value=" + dbs[db].name + ">" + dbs[db].name + "</option>");
00434 }
00435 }
00436 instancesOutput.Success = true;
00437 } catch (e) {
00438 console.log("Exception caught: " + e.name + ": " + e.message);
00439 }
00440 console.log("FindInstances complete");
00441 return instancesOutput;
00442 }
00443
00451 function LoadConfigFiles(configName, dirs, query, dbConfig) {
00452 console.log("LoadConfigFiles: configName: " + configName + ", dirs: " + JSON.stringify(dirs, null, 4) + ", query: " + JSON.stringify(query, null, 4));
00453 var retval = {
00454 collections: {},
00455 Success: false
00456 };
00457 var error = false;
00458 var configFiles = [];
00459 var e;
00460 try {
00461 configFiles = Connector.RunBuildFilterQuery(dbConfig, configName, query).search;
00462 } catch (e) {
00463 error = true;
00464 console.log("Exception occurred: " + e.name + ": " + e.message);
00465 }
00466 if (!error) {
00467 try {
00468 for (var file in configFiles) {
00469 if (configFiles.hasOwnProperty(file)) {
00470 console.log("File info: " + JSON.stringify(configFiles[file], null, 4));
00471 var entity = LoadFile(configFiles[file], dirs, dbConfig).entity;
00472 var collection = configFiles[file].query.collection;
00473 if (!retval.collections.hasOwnProperty(collection)) {
00474 retval.collections[collection] = {
00475 name: collection
00476 , files: []
00477 };
00478 }
00479 console.log("Adding " + entity + " to output list");
00480 retval.collections[collection].files.push(entity);
00481 }
00482 }
00483 retval.Success = true;
00484 } catch (e) {
00485 console.log("Exception occurred: " + e.name + ": " + e.message);
00486 }
00487 }
00488 return retval;
00489 };
00490
00491 function SearchFile(fileData, searchKey) {
00492 console.log("\nSearching for " + searchKey + " in object " + JSON.stringify(fileData, null, 4));
00493 var retval = { name: fileData.name, children: [], columns: fileData.columns };
00494 for (var ii in fileData.children) {
00495 if (fileData.children.hasOwnProperty(ii)) {
00496 var child = fileData.children[ii];
00497 console.log("Key name: " + child.name);
00498 if (child.name.indexOf(searchKey) !== -1) {
00499 console.log("Adding child to output");
00500 retval.children.push(child);
00501 } else if (child.children && child.children.length > 0) {
00502 console.log("Searching child's children");
00503 var table = SearchFile(child, searchKey);
00504 if (table.children.length > 0) {
00505 retval.children.push(table);
00506 }
00507 }
00508 }
00509 }
00510 console.log("\nSearchFile returning " + JSON.stringify(retval, null, 4));
00511 return retval;
00512 }
00513
00514 function SearchConfigFiles(searchKey, configName, dirs, dbConfig) {
00515 console.log("\nSearchConfigFiles: keySearch: " + searchKey + ", configName: " + configName + ", dirs: " + JSON.stringify(dirs, null, 4));
00516 var retval = {
00517 collectionsTemp: {},
00518 collections: [],
00519 columns: DefaultColumns,
00520 Success: false
00521 };
00522 var error = false;
00523 var configFiles = [];
00524 var query = FindConfigs(configName, dbConfig).configs[configName];
00525 var e;
00526 try {
00527 configFiles = Connector.RunBuildFilterQuery(dbConfig, configName, query).search;
00528 } catch (e) {
00529 error = true;
00530 console.log("Exception occurred: " + e.name + ": " + e.message);
00531 }
00532 if (!error) {
00533 try {
00534 for (var file in configFiles) {
00535 if (configFiles.hasOwnProperty(file)) {
00536 console.log("File info: " + JSON.stringify(configFiles[file], null, 4));
00537 var entity = LoadFile(configFiles[file], dirs, dbConfig).entity;
00538 var collection = configFiles[file].query.collection;
00539 if (!retval.collectionsTemp.hasOwnProperty(collection)) {
00540 retval.collectionsTemp[collection] = {
00541 name: collection
00542 , children: []
00543 };
00544 }
00545 var fileData = GetData(configName, collection, entity, dirs);
00546 fileData.name = entity;
00547 var fileMatches = SearchFile(fileData, searchKey);
00548 if (fileMatches.children.length > 0) {
00549 console.log("Adding " + entity + " to output list");
00550 retval.collectionsTemp[collection].children.push(fileMatches);
00551 }
00552 }
00553 }
00554 retval.Success = true;
00555 } catch (e) {
00556 console.log("Exception occurred: " + e.name + ": " + e.message);
00557 }
00558 }
00559
00560 for (var ii in retval.collectionsTemp) {
00561 if (retval.collectionsTemp.hasOwnProperty(ii)) {
00562 retval.collections.push(retval.collectionsTemp[ii]);
00563 }
00564 }
00565 delete retval.collectionsTemp;
00566 console.log("\nSearchConfigFiles returning: " + JSON.stringify(retval, null, 4));
00567 return retval;
00568 }
00569
00582 function GetData(configName, collectionName, entity, dirs) {
00583 console.log("GetData: configName: " + configName + ", collectionName: " + collectionName + ", entity: " + entity + ", dirs: " + JSON.stringify(dirs, null, 4));
00584 var fileName = GetFilePath(configName, collectionName, entity, dirs, false);
00585 if (!fs.existsSync(fileName)) { throw { name: "FileNotFoundException", message: "The requested file was not found" }; }
00586 var jsonFile = JSON.parse("" + fs.readFileSync(fileName));
00587 var jsonBase = ParseFhiclTable({ children: jsonFile.document.converted.guidata, name: entity }, 0);
00588
00589 return jsonBase;
00590 };
00591
00592 function ReplaceByPath(obj, pathArr, data) {
00593 console.log("Utils.ReplaceByPath: obj: " + JSON.stringify(obj, null, 4) + ", pathArr: " + JSON.stringify(pathArr, null, 4) + ", data: " + JSON.stringify(data, null, 4));
00594 if (pathArr.length === 0 && (!obj.name || obj.name === data.name)) {
00595 if (data.column && data.value) {
00596 obj[data.column] = data.value;
00597 } else if (data.type) {
00598 for (var i in data) {
00599 if (data.hasOwnProperty(i)) {
00600 obj[i] = data[i];
00601 }
00602 }
00603 }
00604 return obj;
00605 }
00606
00607 var thisName = pathArr.shift();
00608 var index = -1;
00609 if (obj.type === "table") {
00610 index = Utils.ContainsName(obj.children, thisName, "name");
00611 } else if (obj.type === "sequence") {
00612 index = thisName.slice(thisName.indexOf("___") + 3);
00613 }
00614
00615 obj.children[index] = ReplaceByPath(obj.children[index], pathArr, data);
00616 return obj;
00617 }
00618
00628 function UpdateTable(configName, tablePath, data, dirs) {
00629 console.log("UpdateTable: tablePath:" + tablePath + ", configName: " + configName + ", data: " + JSON.stringify(data, null, 4) + ", dirs: " + JSON.stringify(dirs, null, 4));
00630 var tableArray = tablePath.split('/');
00631 var collection = tableArray.shift();
00632 var entity = tableArray.shift();
00633 var fileName = GetFilePath(configName, collection, entity, dirs, false);
00634 if (!fs.existsSync(fileName)) { throw { name: "FileNotFoundException", message: "The requested file: \"" + fileName + "\" was not found" }; }
00635 console.log("Reading from file " + fileName);
00636 var jsonFile = JSON.parse("" + fs.readFileSync(fileName));
00637 var oldFile = jsonFile.document.converted.guidata;
00638
00639 var curName = tableArray.shift();
00640 var dataIdx = Utils.ContainsName(oldFile, curName, "name");
00641 if (dataIdx < 0) {
00642 console.log("Cannot find data in file!");
00643 return;
00644 }
00645 var oldData = oldFile[dataIdx];
00646 console.log("oldData: " + JSON.stringify(oldData, null, 4));
00647 ReplaceByPath(oldData, tableArray, data);
00648
00649 jsonFile.document.converted.guidata[dataIdx] = oldData;
00650 console.log("After replacement, table data is " + JSON.stringify(oldData, null, 4));
00651
00652 var filePath = GetTempFilePath(configName, collection, entity, dirs);
00653 console.log("Writing to file " + filePath);
00654 fs.writeFileSync(filePath, JSON.stringify(jsonFile, null, 4));
00655 };
00656
00664 function DiscardWorkingDir(dirs) {
00665 console.log("Deleting existing trash dir (if any)");
00666 Utils.ExecSync("rm -rf " + dirs.trash);
00667 console.log("DiscardWorkingDir: Moving db temp to TRASH: mv " + dirs.db + " " + dirs.trash);
00668 Utils.ExecSync("mv " + dirs.db + " " + dirs.trash);
00669 console.log("DiscardWorkingDir: Moving temp files to TRASH: mv " + dirs.tmp + "/* " + dirs.trash);
00670 Utils.ExecSync("mv " + dirs.tmp + "/* " + dirs.trash);
00671 console.log("DiscardWorkingDir: Deleting temp directory: rmdir " + dirs.tmp);
00672 Utils.ExecSync("rmdir " + dirs.tmp);
00673 };
00674
00687 function SaveConfigurationChanges(oldConfig, newConfig, files, dirs, dbConfig) {
00688 console.log("Saving Configuration Changes, oldConfig: " + oldConfig + ", newConfig: " + newConfig + ", files: " + JSON.stringify(files, null, 4) + ", dirs: " + JSON.stringify(dirs, null, 4));
00689 var fileInfo = Connector.RunBuildFilterQuery(dbConfig, oldConfig).search;
00690
00691 var f;
00692 for (f in files) {
00693 if (files.hasOwnProperty(f)) {
00694 console.log("Current file information: " + JSON.stringify(files[f], null, 4));
00695 var collectionName = files[f].collection;
00696 var entities = files[f].entities;
00697 var entity = files[f].entity ? files[f].entity : "notprovided";
00698 var version = files[f].version;
00699 var thisFileInfo = {};
00700 for (var fi in fileInfo) {
00701 if (fileInfo.hasOwnProperty(fi)) {
00702 if (collectionName === fileInfo[fi].query.collection && Utils.ContainsString(entities, fileInfo[fi].query.filter["entities.name"]) != -1) {
00703 console.log("Matched file information to Document: " + JSON.stringify(fileInfo[fi], null, 4));
00704 thisFileInfo = fileInfo[fi];
00705 entity = fileInfo[fi].query.filter["entities.name"];
00706 fileInfo.splice(fi, 1);
00707 }
00708 }
00709 }
00710
00711 console.log("Getting metadata from original and changed files");
00712 var modified = GetFilePath(oldConfig, collectionName, entity, dirs, false);
00713 var newMetadata = ReadFileMetadata(dirs, thisFileInfo, dbConfig);
00714
00715
00716
00717 newMetadata.version = version;
00718 console.log("newMetadata: " + JSON.stringify(newMetadata, null, 4));
00719
00720 console.log("Checking metadata version strings");
00721 while (VersionExists(entity, collectionName, newMetadata.version, dbConfig)) {
00722 console.log("Inferring new version string...");
00723 version = Utils.Uniquify(newMetadata.version);
00724 console.log("Changing version from " + newMetadata.version + " to " + version);
00725 newMetadata.version = version;
00726 console.log("OK");
00727 }
00728 console.log("Prepending changelog");
00729 newMetadata.changelog = files[f].changelog + newMetadata.changelog;
00730
00731 console.log("Writing new metadata to file");
00732 if (WriteFileMetadata(newMetadata, modified)) {
00733
00734 console.log("Running store query");
00735 var data = "" + fs.readFileSync(modified);
00736 console.log("Writing " + data + " to database");
00737 Connector.RunStoreQuery(dbConfig, data, collectionName, newMetadata.version, entity, "gui", newConfig);
00738 } else {
00739 console.log("ERROR: Could not find file " + modified);
00740 console.log("Please check if it exists.");
00741 }
00742 }
00743 }
00744
00745 console.log("Running addconfig for unmodified files: " + JSON.stringify(fileInfo, null, 4));
00746 for (f in fileInfo) {
00747 if (fileInfo.hasOwnProperty(f)) {
00748 var unmodifiedVersion = GetVersion(fileInfo[f], dirs, dbConfig);
00749 Connector.RunAddConfigQuery(dbConfig, newConfig, unmodifiedVersion, fileInfo[f].query.collection, { name: fileInfo[f].query.filter["entities.name"] });
00750 }
00751 }
00752
00753 DiscardWorkingDir(dirs);
00754 };
00755
00764 function CreateNewConfiguration(configName, configData, dbConfig) {
00765 console.log("CreateNewConfigration: configName: " + configName + ", configData: " + JSON.stringify(configData, null, 4));
00766 var query = {
00767 operations: []
00768 };
00769
00770 for (var d in configData.entities) {
00771 if (configData.entities.hasOwnProperty(d)) {
00772 var entityData = configData.entities[d];
00773 console.log("Entity: " + JSON.stringify(entityData, null, 4));
00774 query.operations.push({
00775 filter: { version: entityData.version, "entities.name": entityData.name },
00776 configuration: configName,
00777 collection: entityData.collection,
00778 dbprovider: dbConfig.dbprovider,
00779 operation: "addconfig",
00780 dataformat: "gui"
00781 });
00782 }
00783 }
00784
00785 Connector.RunNewConfigQuery(dbConfig, query);
00786 };
00787
00794 function ReadConfigurationMetadata(configName, dirs, dbConfig) {
00795 console.log("ReadConfigurationMetadata: configname: " + configName + ", dirs: " + JSON.stringify(dirs, null, 4));
00796
00797 var data = Connector.RunBuildFilterQuery(dbConfig, configName ).search;
00798
00799 var metadata = {
00800 entities: []
00801 };
00802 for (var i in data) {
00803 if (data.hasOwnProperty(i)) {
00804 console.log("Loading metadata: File " + i + " of " + data.length);
00805 var version = GetVersion(data[i], dirs, dbConfig);
00806 metadata.entities.push({ name: data[i].query.filter["entities.name"], file: data[i].name + "_" + data[i].query.collection, version: version, collection: data[i].query.collection });
00807 }
00808 }
00809
00810 console.log("Returning entity list: " + JSON.stringify(metadata.entities, null, 4));
00811 return metadata;
00812 };
00813
00822 function GetVersion(query, dirs, dbConfig) {
00823 console.log("\"GetVersion\": {\"query\":" + JSON.stringify(query, null, 4) + ", \"dirs\":" + JSON.stringify(dirs, null, 4) + "},");
00824 var ver = LoadFile(query, dirs, dbConfig).data.version;
00825 console.log("GetVersion Returning " + ver);
00826 return ver;
00827 };
00828
00838 function ReadFileMetadata(dirs, query, dbConfig) {
00839 console.log("ReadFileMetadata: query=" + JSON.stringify(query, null, 4) + ", dirs=" + JSON.stringify(dirs, null, 4) + ", dbConfig: " + JSON.stringify(dbConfig, null, 4));
00840
00841 var jsonFile = LoadFile(query, dirs, dbConfig).data;
00842 if (jsonFile.changelog === undefined) {
00843 jsonFile.changelog = "";
00844 }
00845 var metadata = {
00846 entities: jsonFile.entities,
00847 bookkeeping: jsonFile.bookkeeping,
00848 aliases: jsonFile.aliases,
00849 configurations: jsonFile.configurations,
00850 version: jsonFile.version,
00851 changelog: jsonFile.changelog,
00852 collection: query.query.collection
00853 };
00854
00855 console.log("ReadFileMetadata returning: " + JSON.stringify(metadata, null, 4));
00856 return metadata;
00857 };
00858
00865 function WriteFileMetadata(newMetadata, fileName) {
00866 console.log("WriteFileMetadata: newMetadata=" + JSON.stringify(newMetadata, null, 4) + ", fileName=" + fileName);
00867
00868 console.log("Reading file: " + fileName);
00869 if (!fs.existsSync(fileName)) return false;
00870 var jsonFile = JSON.parse("" + fs.readFileSync(fileName));
00871
00872
00873 console.log("Setting fields: " + JSON.stringify(newMetadata, null, 4));
00874 jsonFile.configurable_entity = newMetadata.configurable_entity;
00875 jsonFile.bookkeeping = newMetadata.bookkeeping;
00876 jsonFile.aliases = newMetadata.aliases;
00877 jsonFile.configurations = newMetadata.configurations;
00878 jsonFile.version = newMetadata.version;
00879 jsonFile.document.converted.changelog = newMetadata.changelog;
00880
00881 console.log("Writing data to file");
00882
00883 fs.writeFileSync(fileName, JSON.stringify(jsonFile, null, 4));
00884
00885 return true;
00886 };
00887
00893 function GetDirectories(userId, dbConfig) {
00894 console.log("GetDirectories: userid=" + userId);
00895 if (dbConfig.baseDir === "" || !dbConfig.baseDir) {
00896 dbConfig.baseDir = process.env["HOME"] + "/databases";
00897 console.log("WARNING: ARTDAQ_DATABASE_DATADIR not set. Using $HOME/databases instead!!!");
00898 }
00899
00900 if (!fs.existsSync(dbConfig.baseDir)) {
00901 console.log("ERROR: Base Directory " +dbConfig.baseDir + " doesn't exist!!!");
00902 throw { name: "BaseDirectoryMissingException", message: "ERROR: Base Directory doesn't exist!!!" };
00903 }
00904 if (!fs.existsSync(path_module.join(dbConfig.baseDir, "db"))) {
00905 fs.mkdirSync(path_module.join(dbConfig.baseDir, "db"));
00906 }
00907 if (!fs.existsSync(path_module.join(dbConfig.baseDir, "tmp"))) {
00908 fs.mkdirSync(path_module.join(dbConfig.baseDir, "tmp"));
00909 }
00910 if (!fs.existsSync(path_module.join(dbConfig.baseDir, "TRASH"))) {
00911 fs.mkdirSync(path_module.join(dbConfig.baseDir, "TRASH"));
00912 }
00913
00914
00915 var db = path_module.join(dbConfig.baseDir, "db", userId);
00916 var tmp = path_module.join(dbConfig.baseDir, "tmp", userId);
00917 var trash = path_module.join(dbConfig.baseDir, "TRASH", userId);
00918
00919
00920 if (!fs.existsSync(db)) {
00921 fs.mkdirSync(db);
00922 }
00923 if (!fs.existsSync(tmp)) {
00924 fs.mkdirSync(tmp);
00925 }
00926 if (!fs.existsSync(trash)) {
00927 fs.mkdirSync(trash);
00928 }
00929
00930 return { db: db, tmp: tmp, trash: trash };
00931 };
00932
00941 function VersionExists(entity, collection, version, dbConfig) {
00942 console.log("\"VersionExists\": { version:\"" + version + "\", entity:" + JSON.stringify(entity, null, 4) + ", collection: \"" + collection + "\"}");
00943 var query = {
00944 filter: {
00945 "entities.name": entity
00946 },
00947 collection: collection,
00948 dbprovider: dbConfig.dbprovider,
00949 operation: "findversions",
00950 dataformat: "gui"
00951 };
00952 var vers = Connector.RunGetVersionsQuery(dbConfig, query).search;
00953 console.log("Search returned: " + JSON.stringify(vers, null, 4));
00954 return Utils.ContainsName(vers, version, "name") >= 0;
00955 };
00956
00961 function Lock() {
00962 console.log("Lock");
00963 if (fs.existsSync("/tmp/node_db_lockfile")) {
00964 if (Date.now() - fs.fstatSync("/tmp/node_db_lockfile").ctime.getTime() > 1000) {
00965 console.log("Stale Lockfile detected, deleting...");
00966 return Unlock();
00967 } else {
00968 console.log("Lockfile detected and is not stale, aborting...");
00969 }
00970 return false;
00971 }
00972
00973 fs.writeFileSync("/tmp/node_db_lockfile", "locked");
00974 return true;
00975 }
00976
00981 function Unlock() {
00982 console.log("Unlock");
00983 fs.unlinkSync("/tmp/node_db_lockfile");
00984 return true;
00985 }
00986
00987
00988 db.RO_GetData = function (post, dbConfig) {
00989 console.log("RO_GetData: " + JSON.stringify(post, null, 4));
00990 var ret = { Success: false, data: {} };
00991 try {
00992 ret.data = GetData(post.configName, post.collection, post.entity, GetDirectories(post.user, dbConfig));
00993 ret.Success = true;
00994 } catch (e) {
00995 console.log("Exception occurred: " + e.name + ": " + e.message);
00996 }
00997
00998 console.log("GetData complete");
00999 return ret;
01000 };
01001
01002 db.RW_MakeNewConfig = function (post, dbConfig) {
01003 if (Lock()) {
01004 console.log("RW_MakeNewConfig: Request to make new configuration received: " + JSON.stringify(post, null, 4));
01005 var res = { Success: false };
01006 var error = false;
01007 var e;
01008 try {
01009 var configs = Connector.RunGetConfigsQuery(dbConfig).search;
01010 if (!Utils.ValidatePath(post.name)) {
01011 console.log("Invalid name detected!");
01012 error = true;
01013 }
01014 while (Utils.ContainsName(configs, post.name, "name") >= 0) {
01015 console.log("Inferring new configuration name");
01016 post.name = Utils.Uniquify(post.name);
01017 }
01018 } catch (e) {
01019 error = true;
01020 console.log("Exception occurred: " + e.name + ": " + e.message);
01021 }
01022 if (!error) {
01023 console.log("Creating Configuration");
01024 try {
01025 CreateNewConfiguration(post.name, JSON.parse(post.config), dbConfig);
01026 res.Success = true;
01027 } catch (e) {
01028 console.log("Exception occurred: " + e.name + ": " + e.message);
01029 }
01030 }
01031 Unlock();
01032 console.log("MakeNewConfig completed");
01033 return res;
01034 }
01035 return null;
01036 };
01037
01038 db.RW_saveConfig = function (post, dbConfig) {
01039 if (Lock()) {
01040 console.log("RW_saveConfig: Request to save configuration recieved. Configuration data: " + JSON.stringify(post, null, 4));
01041 var res = { Success: false };
01042 var error = false;
01043 var e;
01044 try {
01045 console.log("Checking for unique Configuration name");
01046 var configs = Connector.RunGetConfigsQuery(dbConfig).search;
01047 if (!Utils.ValidatePath(post.newConfigName) || Utils.ContainsName(configs, post.oldConfigName, "name") < 0) {
01048 console.log("Invalid name detected!");
01049 error = true;
01050 }
01051 while (Utils.ContainsName(configs, post.newConfigName, "name") >= 0) {
01052 console.log("Inferring new configuration name");
01053 post.newConfigName = Utils.Uniquify(post.newConfigName);
01054 }
01055 } catch (e) {
01056 error = true;
01057 console.log("Exception occurred: " + e.name + ": " + e.message);
01058 }
01059 if (!error) {
01060 try {
01061 console.log("Updating Configuration Files");
01062 SaveConfigurationChanges(post.oldConfigName, post.newConfigName, post.files, GetDirectories(post.user, dbConfig), dbConfig);
01063 res.Success = true;
01064 } catch (e) {
01065 console.log("Exception occurred: " + e.name + ": " + e.message);
01066 }
01067 }
01068 Unlock();
01069 console.log("SaveConfig completed");
01070 return res;
01071 }
01072 return null;
01073 };
01074
01075 db.RO_LoadNamedConfig = function (post, dbConfig) {
01076 console.log("RO_LoadNamedConfig: Request for configuration with name \"" + post.configName + "\" and search query \"" + post.query + "\" received.");
01077 if (post.query.length === 0 || post.configName === "No Configurations Found") {
01078 return { collections: [] };
01079 }
01080 return LoadConfigFiles(post.configName, GetDirectories(post.user, dbConfig), JSON.parse(post.query), dbConfig);
01081 };
01082
01083 db.RW_discardConfig = function (post, dbConfig) {
01084 console.log("RW_discardConfig: Discarding configuration with parameters: " + JSON.stringify(post, null, 4));
01085 DiscardWorkingDir(GetDirectories(post.user, dbConfig));
01086 return { Success: true };
01087 };
01088
01089 db.RO_AddOrUpdate = function (post, dbConfig) {
01090 console.log("RO_AddOrUpdate: Request to update table row recieved: " + JSON.stringify(post, null, 4));
01091 UpdateTable(post.configName, post.table, post.row, GetDirectories(post.user, dbConfig));
01092 return { Success: true };
01093 }
01094
01095 db.RO_Update = function (post, dbConfig) {
01096 console.log("RO_Update: Request to update table received: " + JSON.stringify(post, null, 4));
01097 UpdateTable(post.configName, post.table, { id: post.id, name: post.name, column: post.column, value: post.value }, GetDirectories(post.user, dbConfig));
01098 console.log("Update Complete");
01099 return { Success: true };
01100 };
01101
01102 db.RO_LoadConfigMetadata = function (post, dbConfig) {
01103 console.log("RO_LoadConfigMetadata: Request to load configuration metadata received: " + JSON.stringify(post, null, 4) + ", dbConfig: " + JSON.stringify(dbConfig, null, 4));
01104 var ret = { Success: false, data: {} };
01105 try {
01106 ret.data = ReadConfigurationMetadata(post.configName, GetDirectories(post.user, dbConfig), dbConfig);
01107 ret.Success = true;
01108 } catch (e) {
01109 console.log("Exception caught: " + e.name + ": " + e.message);
01110 }
01111 console.log("LoadConfigMetadata complete");
01112 return ret;
01113 };
01114
01115 db.RO_LoadFileMetadata = function (post, dbConfig) {
01116 console.log("RO_LoadFileMetadata: Request to load file metadata received: " + JSON.stringify(post, null, 4));
01117 var ret = { Success: false, data: {} };
01118 var dirs = GetDirectories(post.user, dbConfig);
01119 var error = false;
01120 var query = {};
01121 var e;
01122 try {
01123 var search = Connector.RunBuildFilterQuery(dbConfig, post.configName).search;
01124 for (var s in search) {
01125 if (search.hasOwnProperty(s)) {
01126 if (search[s].query.collection === post.collection && search[s].query.filter["entities.name"] === post.entity) {
01127 query = search[s];
01128 }
01129 }
01130 }
01131 } catch (e) {
01132 error = true;
01133 console.log("Exception caught: " + e.name + ": " + e.message);
01134 }
01135 if (!error) {
01136 try {
01137 ret.data = ReadFileMetadata(dirs, query, dbConfig);
01138 ret.Success = true;
01139 } catch (e) {
01140 console.log("Exception caught: " + e.name + ": " + e.message);
01141 }
01142 }
01143 console.log("LoadFileMetadata complete");
01144 return ret;
01145 };
01146
01147 db.RW_UploadConfigurationFile = function (post, dbConfig) {
01148 if (Lock()) {
01149 console.log("RW_UploadConfigurationFile: Recieved request to upload file: " + JSON.stringify(post, null, 4));
01150 var e;
01151 var error = false;
01152 var ret = { Success: false };
01153 try {
01154 while (VersionExists(post.entity, post.collection, post.version, dbConfig)) {
01155 console.log("Version already exists. Running uniquifier...");
01156 post.version = Utils.Uniquify(post.version);
01157 }
01158 } catch (e) {
01159 error = true;
01160 console.log("Exception caught: " + e.name + ": " + e.message);
01161 }
01162
01163 if (!error) {
01164 console.log("Running store fhicl query");
01165 try {
01166 Connector.RunStoreQuery(dbConfig, post.file, post.collection, post.version, post.entity, post.type);
01167 ret.Success = true;
01168 } catch (e) {
01169 console.log("Exception caught: " + e.name + ": " + e.message);
01170 }
01171 }
01172 Unlock();
01173 console.log("UploadConfigurationFile complete");
01174 return ret;
01175 }
01176 return null;
01177 };
01178
01179 db.RO_DownloadConfigurationFile = function (post, dbConfig) {
01180 console.log("RO_DownloadConfigurationFile: Request to download file(s) received: " + JSON.stringify(post, null, 4));
01181 var dirs = GetDirectories(post.user, dbConfig);
01182 var configObj = JSON.parse(post.config);
01183 try {
01184 if (configObj.entities.length === 1) {
01185 console.log("Single file mode: Fetching file...");
01186 var fileInfo = FetchFile(configObj.entities[0], post.type, dirs.db, dbConfig);
01187
01188 var fclhdrs = {
01189 'Content-Type': 'text/plain',
01190 'Content-Length': fileInfo.size,
01191 'Content-Disposition': 'attachment filename=' + fileInfo.fileName
01192 }
01193 console.log("Headers: " + JSON.stringify(fclhdrs, null, 4) + ", fileInfo: " + JSON.stringify(fileInfo, null, 4));
01194
01195 var fclStream = fs.createReadStream(fileInfo.filePath);
01196 db.emit("stream", fclStream, fclhdrs, 200);
01197 } else if (configObj.entities.length > 1) {
01198 var args = ['cz'];
01199 for (var e in configObj.entities) {
01200 if (configObj.entities.hasOwnProperty(e)) {
01201 args.push(FetchFile(configObj.entities[e], post.type, dirs.db, dbConfig).fileName);
01202 }
01203 }
01204 var fileName = post.tarFileName + ".tar.gz";
01205 var tarhdrs = {
01206 'Content-Type': "application/x-gzip",
01207 'Content-Disposition': 'attachment filename=' + fileName
01208 }
01209
01210 console.log("Spawning: tar " + args.join(" "));
01211 var tar = child_process.spawn("tar", args, { cwd: dirs.db, stdio: [0, 'pipe', 0] });
01212 db.emit("stream", tar.stdout, tarhdrs, 200);
01213
01214 }
01215 } catch (err) {
01216 console.log("Exception caught: " + err.name + ": " + err.message);
01217
01218 var s = new stream.Readable();
01219 s._read = function noop() { };
01220 s.push("ERROR");
01221 s.push(null);
01222
01223 var errhdrs = {
01224 'Content-Type': 'text/plain'
01225 }
01226 db.emit("stream", s, errhdrs, 500);
01227 }
01228
01229 };
01230
01231 db.RO_NamedConfigs = function (post, dbConfig) {
01232 console.log("RO_NamedConfigs: Request for Named Configurations received");
01233 var filter = "" + post.configFilter;
01234 return FindConfigs(filter, dbConfig);
01235 };
01236
01237 db.RW_updateDbConfig = function (post, dbConfig) {
01238 console.log("RW_updateDbConfig: Request to update module configuration received: " + JSON.stringify(post, null, 4));
01239 var output = { Success: false };
01240 if (fs.existsSync(post.baseDir) && (post.dbprovider === "filesystem" || post.dbprovider === "mongo")) {
01241 if (dbConfig.baseDir !== post.baseDir) {
01242 dbConfig.baseDir = post.baseDir;
01243 db.emit("message", { name: "db", target: "baseDir", data: post.baseDir });
01244 }
01245 if (dbConfig.dbprovider !== post.dbprovider) {
01246 dbConfig.dbprovider = post.dbprovider;
01247 db.emit("message", { name: "db", target: "dbprovider", data: post.dbprovider });
01248 }
01249 if (dbConfig.instanceName !== post.instanceName) {
01250 dbConfig.instanceName = post.instanceName;
01251 db.emit("message", { name: "db", target: "instanceName", data: post.instanceName });
01252 }
01253 console.log("DB Config is now: " + JSON.stringify(dbConfig, null, 4));
01254 output.Success = true;
01255 }
01256 return output;
01257 }
01258
01259 db.RO_SearchLoadedConfig = function (post, dbConfig) {
01260 console.log("RO_SearchLoadedConfig: Searching for keys containing name \"" + post.searchKey + "\" from configuration name \"" + post.configName + "\" received.");
01261 if (post.configName === "No Configurations Found") {
01262 return { Success: false, collections: [] };
01263 }
01264 return SearchConfigFiles(post.searchKey, post.configName, GetDirectories(post.user, dbConfig), dbConfig);
01265 }
01266
01267 db.RW_makeNewDBInstance = function (post, dbConfig) {
01268 console.log("RW_makeNewDBInstance: Creating new database instance \"" + post.name + "\".");
01269 dbConfig.instanceName = post.name;
01270 return { Success: true };
01271 }
01272
01273 db.RW_AddEntityToFile = function (post, dbConfig) {
01274 console.log("RW_AddEntityToFile: request to add entity name \"" + post.name + "\" to configuration file " + post.configName + "/" + post.collection + "/" + post.entity);
01275 return { Success: true };
01276 }
01277
01278
01279 db.GET_EntitiesAndVersions = function (dbConfig) {
01280 console.log("GET_EntitiesAndVersions: Request for current Entities and Versions received");
01281 var output = {
01282 Success: false,
01283 collections: []
01284 };
01285 try {
01286 var entities = Connector.RunGetEntitiesQuery(dbConfig).search;
01287 console.log("Returned entities: " + JSON.stringify(entities, null, 4));
01288 for (var ent in entities) {
01289 if (entities.hasOwnProperty(ent)) {
01290 var entity = entities[ent];
01291 var versions = Connector.RunGetVersionsQuery(dbConfig, entity.query);
01292 if (Utils.ContainsName(output.collections, entity.query.collection, "name") < 0) {
01293 output.collections.push({ name: entity.query.collection, entities: [] });
01294 }
01295
01296 var index = Utils.ContainsName(output.collections, entity.query.collection, "name");
01297
01298 var entityObj = {
01299 collection: entity.query.collection,
01300 name: entity.name,
01301 versions: versions
01302 };
01303 output.collections[index].entities.push(entityObj);
01304 }
01305 }
01306 output.Success = true;
01307 } catch (e) {
01308 console.log("Exception caught: " + e.name + ": " + e.message);
01309 }
01310 console.log("EntitiesAndVersions complete");
01311 return output;
01312 };
01313
01314 db.GET_getDbConfig = function (dbConfig) {
01315 console.log("GET_getDbConfig Request for Database Module Configuration received");
01316
01317 var instances = FindInstances(dbConfig);
01318 var output = {
01319 Success: true,
01320 baseDir: dbConfig.baseDir,
01321 dbprovider: dbConfig.dbprovider,
01322 instanceName: dbConfig.instanceName,
01323 data: instances.data
01324 };
01325 return output;
01326 }
01327
01328
01329 db.MasterInitFunction = function (workerData, config) {
01330 var dbConfig = MakeDbConfig(config);
01331 workerData["db"] = dbConfig;
01332 GetDirectories("", dbConfig);
01333 };
01334
01335 module.exports = function (moduleHolder) {
01336 moduleHolder["db"] = db;
01337 };