Skip to content
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

Open
wants to merge 13 commits into
base: master
Choose a base branch
from

Conversation

sandeep-paliwal
Copy link

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.

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.
@csantanapr csantanapr added the wip label Sep 22, 2018
@@ -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);

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);

else if(dbType === "cosmosdb") {
console.log("using cosmosdb");
var cosmosdb = require('./cosmosdb');
db = new cosmosdb(dbURL, cosmosdbMasterKey);

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.
@jasonpet
Copy link
Contributor

@sandeep-paliwal - have you tested this with couchdb? fails for me

"namespace": "whisk.system",
    "name": "alarmWebAction",
    "version": "0.0.2",
    "subject": "whisk.system",
    "activationId": "5d9dfa5f98cb4f629dfa5f98cb2f6232",
    "start": 1539971896476,
    "end": 1539971896495,
    "duration": 19,
    "response": {
        "status": "application error",
        "statusCode": 0,
        "success": false,
        "result": {
            "error": {
                "message": "Cannot read property 'getWorkerID' of undefined",
                "stack": "TypeError: Cannot read property 'getWorkerID' of undefined\n    at common.verifyTriggerAuth.then (/nodejsAction/dUGHWGoL/alarmWebAction.js:135:26)\n    at process._tickCallback (internal/process/next_tick.js:109:7)"

@jasonpet
Copy link
Contributor

@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.

Copy link
Contributor

@jasonpet jasonpet left a 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.

@jasonpet
Copy link
Contributor

@sandeep-paliwal I also see some alarms functionality that exists with couchdb that was not made available with cosmosDB as part of this PR:

  • The internal monitoring/health code that creates and deletes trigger db entries found in provider/lib/health.js
  • The trigger feed cleanup that occurs for the fire once alarm when the deleteAfterFire param is not set to false (see the handleFiredTriggers function in provider/lib/utils.js)

@sandeep-paliwal
Copy link
Author

Thanks for the comments @jasonpet . I will update the PR and run the tests you have mentioned.

});
};

this.getTrigger = function(triggerID) {
Copy link

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.

}
else
reject("No db type to initialize");

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?

Copy link
Author

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);
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indentation/formatting?

client.createCollection(utilsDB.dbLink, collectionDefinition, function(err, collection) {
if(err) reject(err);

console.log("Created collection");

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);

};
return new Promise((resolve, reject) => {
client.queryCollections(utilsDB.dbLink, querySpec).toArray((err, results) => {
if (err) reject(err);

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);

utilsDB.collectionLink = col._self;
resolve(col);
})
.catch((err) => reject(err));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this needed?

console.log("got database");
resolve();
})
.catch((err) => { reject(err);});

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this needed?

};
return new Promise((resolve, reject) => {
client.queryDatabases(querySpec).toArray((err, results) => {
if(err) reject(err);

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);

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

resolve();
})
.catch((err) => {
reject(err);});

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this needed?

Copy link
Author

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.

.then(id => {
resolve(id);
})
.catch(err => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this needed

resolve(replaced);
});
})
.catch((err) => { reject(err);});

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);
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

formatting?

utilsDB.getTrigger(triggerID)
.then((doc) => {
client.deleteDocument(doc._self, function(err) {
if (err) reject(err);

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);

resolve();
});
})
.catch((err) => { reject(err);});

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this needed?

provider/app.js Outdated
config = {
protocol: dbProtocol,
host: dbHost,
username: databaseName,
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants