Added support for Azure cosmosDB for alarms package#163
Added support for Azure cosmosDB for alarms package#163sandeep-paliwal wants to merge 13 commits intoapache:masterfrom
Conversation
All database interactions will now go through database.js which in turn will delegate to actual DB implementations (couchdb or cosmosdb) based on dbType There are some TODO comments and need to get better understanding on those.
| .then(() => { | ||
| db = new Database(params.DB_URL, params.DB_NAME); | ||
| db = getDatabase(params.DB_URL, params.DB_NAME, params.DB_TYPE, | ||
| params.COSMOSDB_ROOT_DB, params.COSMOSDB_MASTERKEY); |
There was a problem hiding this comment.
instead of "all possible params" being in the sig, I think it might be simpler to pass a config object, which will vary based on db type, e.g.
let cosmosConfig = {type: "cosmosdb", url: "", rootdb:"", masterkey:""};
let couchConfig = {type: "couchdb", url: "", dbname:""};
getDatabase(config);
| else if(dbType === "cosmosdb") { | ||
| console.log("using cosmosdb"); | ||
| var cosmosdb = require('./cosmosdb'); | ||
| db = new cosmosdb(dbURL, cosmosdbMasterKey); |
There was a problem hiding this comment.
instead of duplicating functions like createTrigger, I think we should duplicate document manipulation functions like createDocument so that the db operations are the only piece that is delegated to the db impls.
…ll params. Fixed issue with DB follow function.
|
@sandeep-paliwal - have you tested this with couchdb? fails for me |
|
@sandeep-paliwal Please run all tests to verify it works once you fix this issue. The getDatabase function in alarmWebAction needs to be a promise that you wait on when you call it. You are returning the database but only after you wait on the initDB. The call to getDatabase right before you try to getWorkerID is undefined because you are not waiting on it. |
jasonpet
left a comment
There was a problem hiding this comment.
Please see latest comments regarding errors.
|
@sandeep-paliwal I also see some alarms functionality that exists with couchdb that was not made available with cosmosDB as part of this PR:
|
|
Thanks for the comments @jasonpet . I will update the PR and run the tests you have mentioned. |
| }); | ||
| }; | ||
|
|
||
| this.getTrigger = function(triggerID) { |
| reject(err);}); | ||
| } | ||
| else | ||
| reject("No db type to initialize"); |
There was a problem hiding this comment.
I think type must be couchdb or cosmosdb; found $config.type would be more clear?
| console.log("Found valid collection"); | ||
| utilsDB.collectionLink = results[0]._self; | ||
| resolve(results); | ||
| } |
| client.createCollection(utilsDB.dbLink, collectionDefinition, function(err, collection) { | ||
| if(err) reject(err); | ||
|
|
||
| console.log("Created collection"); |
There was a problem hiding this comment.
add an } else { to prevent processing after reject; or else do return reject(err);
| }; | ||
| return new Promise((resolve, reject) => { | ||
| client.queryCollections(utilsDB.dbLink, querySpec).toArray((err, results) => { | ||
| if (err) reject(err); |
There was a problem hiding this comment.
add an } else { to prevent processing after reject; or else do return reject(err);
| utilsDB.collectionLink = col._self; | ||
| resolve(col); | ||
| }) | ||
| .catch((err) => reject(err)); |
| console.log("got database"); | ||
| resolve(); | ||
| }) | ||
| .catch((err) => { reject(err);}); |
| }; | ||
| return new Promise((resolve, reject) => { | ||
| client.queryDatabases(querySpec).toArray((err, results) => { | ||
| if(err) reject(err); |
There was a problem hiding this comment.
add an } else { to prevent processing after reject; or else do return reject(err);
| resolve(); | ||
| }) | ||
| .catch((err) => { | ||
| reject(err);}); |
There was a problem hiding this comment.
I will tryout without this and check.
| .then(id => { | ||
| resolve(id); | ||
| }) | ||
| .catch(err => { |
| resolve(replaced); | ||
| }); | ||
| }) | ||
| .catch((err) => { reject(err);}); |
| reject(err); | ||
| }); | ||
| }, 1000); | ||
| } |
| utilsDB.getTrigger(triggerID) | ||
| .then((doc) => { | ||
| client.deleteDocument(doc._self, function(err) { | ||
| if (err) reject(err); |
There was a problem hiding this comment.
add an } else { to prevent processing after reject; or else do return reject(err);
| resolve(); | ||
| }); | ||
| }) | ||
| .catch((err) => { reject(err);}); |
Fixed issue with DB feed Fixed formatting
Added env var support for Feed check interval
| config = { | ||
| protocol: dbProtocol, | ||
| host: dbHost, | ||
| username: databaseName, |
There was a problem hiding this comment.
This should be username: dbUsername correct?
Added support for alarms package to use cosmos DB.
All database interactions will now go through database.js which in turn will delegate to actual DB implementations (couchdb or cosmosdb) based on dbType.
There are some TODO comments and need to get better understanding on those.