You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@openwhisk.apache.org by GitBox <gi...@apache.org> on 2018/03/15 14:42:20 UTC

[GitHub] csantanapr closed pull request #140: minor updates to health monitor

csantanapr closed pull request #140: minor updates to health monitor
URL: https://github.com/apache/incubator-openwhisk-package-alarms/pull/140
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/provider/lib/utils.js b/provider/lib/utils.js
index a4d5072..3714b73 100644
--- a/provider/lib/utils.js
+++ b/provider/lib/utils.js
@@ -71,7 +71,7 @@ module.exports = function(logger, triggerDB, redisClient) {
         utils.postTrigger(dataTrigger, auth, 0)
         .then(triggerId => {
             logger.info(method, 'Trigger', triggerId, 'was successfully fired');
-            utils.handleFiredTrigger(dataTrigger, dataTrigger.monitor !== undefined);
+            utils.handleFiredTrigger(dataTrigger);
         })
         .catch(err => {
             logger.error(method, err);
@@ -159,23 +159,21 @@ module.exports = function(logger, triggerDB, redisClient) {
     };
 
     this.shouldFireTrigger = function(trigger) {
-        if (!trigger.monitor && utils.activeHost === utils.host) {
-           return true;
-        }
-        else if (trigger.monitor === utils.host) {
-            return true;
-        }
-        return false;
+        return trigger.monitor || utils.activeHost === utils.host;
     };
 
     this.hasTriggersRemaining = function(trigger) {
         return !trigger.maxTriggers || trigger.maxTriggers === -1 || trigger.triggersLeft > 0;
     };
 
-    this.handleFiredTrigger = function(dataTrigger, isMonitorTrigger) {
+    this.isMonitoringTrigger = function(monitor, triggerName) {
+        return monitor && utils.monitorStatus.triggerName === triggerName;
+    };
+
+    this.handleFiredTrigger = function(dataTrigger) {
         var method = 'handleFiredTrigger';
 
-        if (isMonitorTrigger && utils.monitorStatus.triggerName === dataTrigger.name) {
+        if (utils.isMonitoringTrigger(dataTrigger.monitor, dataTrigger.name)) {
             utils.monitorStatus.triggerFired = "success";
         }
 
@@ -283,7 +281,7 @@ module.exports = function(logger, triggerDB, redisClient) {
                     var triggerIdentifier = trigger.id;
                     var doc = trigger.doc;
 
-                    if (!(triggerIdentifier in utils.triggers)) {
+                    if (!(triggerIdentifier in utils.triggers) && !doc.monitor) {
                         //check if trigger still exists in whisk db
                         var namespace = doc.namespace;
                         var name = doc.name;
@@ -354,20 +352,20 @@ module.exports = function(logger, triggerDB, redisClient) {
                 if (utils.triggers[triggerIdentifier]) {
                     if (doc.status && doc.status.active === false) {
                         utils.stopTrigger(triggerIdentifier);
-                        if (doc.monitor && doc.monitor === utils.host && utils.monitorStatus.triggerName === doc.name) {
+                        if (utils.isMonitoringTrigger(doc.monitor, doc.name)) {
                             utils.monitorStatus.triggerStopped = "success";
                         }
                     }
                 }
                 else {
                     //ignore changes to disabled triggers
-                    if (!doc.status || doc.status.active === true) {
+                    if ((!doc.status || doc.status.active === true) && (!doc.monitor || doc.monitor === utils.host)) {
                         utils.createTrigger(triggerIdentifier, doc)
                         .then(cachedTrigger => {
                             utils.triggers[triggerIdentifier] = cachedTrigger;
                             logger.info(method, triggerIdentifier, 'created successfully');
 
-                            if (doc.monitor && doc.monitor === utils.host && utils.monitorStatus.triggerName === cachedTrigger.name) {
+                            if (utils.isMonitoringTrigger(cachedTrigger.monitor, cachedTrigger.name)) {
                                 utils.monitorStatus.triggerStarted = "success";
                             }
 


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services