-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added support for Azure cosmosDB for alarms package #163
base: master
Are you sure you want to change the base?
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.
action/alarmWebAction.js
Outdated
@@ -131,7 +131,8 @@ function main(params) { | |||
return new Promise(function (resolve, reject) { | |||
common.verifyTriggerAuth(triggerData, false) | |||
.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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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);
action/lib/Database.js
Outdated
else if(dbType === "cosmosdb") { | ||
console.log("using cosmosdb"); | ||
var cosmosdb = require('./cosmosdb'); | ||
db = new cosmosdb(dbURL, cosmosdbMasterKey); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
provider/lib/cosmosdb.js
Outdated
}); | ||
}; | ||
|
||
this.getTrigger = function(triggerID) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to support retry for DB calls.
action/lib/Database.js
Outdated
} | ||
else | ||
reject("No db type to initialize"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think type must be couchdb or cosmosdb; found $config.type
would be more clear?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will make this change
console.log("Found valid collection"); | ||
utilsDB.collectionLink = results[0]._self; | ||
resolve(results); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indentation/formatting?
action/lib/cosmosdb.js
Outdated
client.createCollection(utilsDB.dbLink, collectionDefinition, function(err, collection) { | ||
if(err) reject(err); | ||
|
||
console.log("Created collection"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add an } else {
to prevent processing after reject
; or else do return reject(err);
action/lib/cosmosdb.js
Outdated
}; | ||
return new Promise((resolve, reject) => { | ||
client.queryCollections(utilsDB.dbLink, querySpec).toArray((err, results) => { | ||
if (err) reject(err); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add an } else {
to prevent processing after reject
; or else do return reject(err);
action/lib/cosmosdb.js
Outdated
utilsDB.collectionLink = col._self; | ||
resolve(col); | ||
}) | ||
.catch((err) => reject(err)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this needed?
action/lib/cosmosdb.js
Outdated
console.log("got database"); | ||
resolve(); | ||
}) | ||
.catch((err) => { reject(err);}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this needed?
action/lib/cosmosdb.js
Outdated
}; | ||
return new Promise((resolve, reject) => { | ||
client.queryDatabases(querySpec).toArray((err, results) => { | ||
if(err) reject(err); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add an } else { to prevent processing after reject; or else do return reject(err);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
action/lib/Database.js
Outdated
resolve(); | ||
}) | ||
.catch((err) => { | ||
reject(err);}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will tryout without this and check.
action/lib/cosmosdb.js
Outdated
.then(id => { | ||
resolve(id); | ||
}) | ||
.catch(err => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this needed
action/lib/cosmosdb.js
Outdated
resolve(replaced); | ||
}); | ||
}) | ||
.catch((err) => { reject(err);}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this needed?
reject(err); | ||
}); | ||
}, 1000); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
formatting?
action/lib/cosmosdb.js
Outdated
utilsDB.getTrigger(triggerID) | ||
.then((doc) => { | ||
client.deleteDocument(doc._self, function(err) { | ||
if (err) reject(err); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add an } else { to prevent processing after reject; or else do return reject(err);
action/lib/cosmosdb.js
Outdated
resolve(); | ||
}); | ||
}) | ||
.catch((err) => { reject(err);}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this needed?
Fixed issue with DB feed Fixed formatting
Added env var support for Feed check interval
provider/app.js
Outdated
config = { | ||
protocol: dbProtocol, | ||
host: dbHost, | ||
username: databaseName, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.