Skip to content

Added support for Azure cosmosDB for alarms package#163

Open
sandeep-paliwal wants to merge 13 commits intoapache:masterfrom
sandeep-paliwal:cosmosdb_support
Open

Added support for Azure cosmosDB for alarms package#163
sandeep-paliwal wants to merge 13 commits intoapache:masterfrom
sandeep-paliwal:cosmosdb_support

Conversation

@sandeep-paliwal
Copy link
Copy Markdown

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
Comment thread action/alarmWebAction.js Outdated
.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);
Copy link
Copy Markdown

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

Comment thread action/lib/Database.js Outdated
else if(dbType === "cosmosdb") {
console.log("using cosmosdb");
var cosmosdb = require('./cosmosdb');
db = new cosmosdb(dbURL, cosmosdbMasterKey);
Copy link
Copy Markdown

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
Copy Markdown

@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
Copy Markdown

@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
Copy Markdown

@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
Copy Markdown

@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
Copy Markdown
Author

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

Comment thread provider/lib/cosmosdb.js Outdated
});
};

this.getTrigger = function(triggerID) {
Copy link
Copy Markdown

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.

Comment thread action/lib/Database.js Outdated
reject(err);});
}
else
reject("No db type to initialize");
Copy link
Copy Markdown

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
Copy Markdown
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

Comment thread action/lib/cosmosdb.js
console.log("Found valid collection");
utilsDB.collectionLink = results[0]._self;
resolve(results);
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

indentation/formatting?

Comment thread action/lib/cosmosdb.js Outdated
client.createCollection(utilsDB.dbLink, collectionDefinition, function(err, collection) {
if(err) reject(err);

console.log("Created collection");
Copy link
Copy Markdown

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

Comment thread action/lib/cosmosdb.js Outdated
};
return new Promise((resolve, reject) => {
client.queryCollections(utilsDB.dbLink, querySpec).toArray((err, results) => {
if (err) reject(err);
Copy link
Copy Markdown

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

Comment thread action/lib/cosmosdb.js Outdated
utilsDB.collectionLink = col._self;
resolve(col);
})
.catch((err) => reject(err));
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

is this needed?

Comment thread action/lib/cosmosdb.js Outdated
console.log("got database");
resolve();
})
.catch((err) => { reject(err);});
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

is this needed?

Comment thread action/lib/cosmosdb.js Outdated
};
return new Promise((resolve, reject) => {
client.queryDatabases(querySpec).toArray((err, results) => {
if(err) reject(err);
Copy link
Copy Markdown

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
Copy Markdown
Author

Choose a reason for hiding this comment

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

ok

Comment thread action/lib/Database.js Outdated
resolve();
})
.catch((err) => {
reject(err);});
Copy link
Copy Markdown

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
Copy Markdown
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.

Comment thread action/lib/cosmosdb.js Outdated
.then(id => {
resolve(id);
})
.catch(err => {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

is this needed

Comment thread action/lib/cosmosdb.js Outdated
resolve(replaced);
});
})
.catch((err) => { reject(err);});
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

is this needed?

Comment thread action/lib/cosmosdb.js
reject(err);
});
}, 1000);
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

formatting?

Comment thread action/lib/cosmosdb.js Outdated
utilsDB.getTrigger(triggerID)
.then((doc) => {
client.deleteDocument(doc._self, function(err) {
if (err) reject(err);
Copy link
Copy Markdown

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

Comment thread action/lib/cosmosdb.js Outdated
resolve();
});
})
.catch((err) => { reject(err);});
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

is this needed?

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

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