RIFT-14856: launchpad UI - Logging - default category severity 49/549/1
authorKIRAN KASHALKAR <kiran.kashalkar@riftio.com>
Wed, 19 Oct 2016 20:14:50 +0000 (16:14 -0400)
committerKIRAN KASHALKAR <kiran.kashalkar@riftio.com>
Wed, 19 Oct 2016 20:15:08 +0000 (16:15 -0400)
Signed-off-by: KIRAN KASHALKAR <kiran.kashalkar@riftio.com>
skyquake/plugins/logging/api/logging.js
skyquake/plugins/logging/routes.js
skyquake/plugins/logging/src/categorySeverityGrid.jsx
skyquake/plugins/logging/src/loggingGeneral.jsx
skyquake/plugins/logging/src/loggingSource.js
skyquake/plugins/logging/src/loggingStore.js

index 00cd1d6..a3bc182 100644 (file)
@@ -322,6 +322,34 @@ Config.deleteDefaultSeverity = function(req) {
 
 }
 
+// NOTE: In rel_4.3 we are going to affect syslog sink category by default
+
+Config.setDefaultSyslogSeverity = function(req) {
+  // TODO: verify there is one key at root of data: 'default-severity'
+  // OR just filter on the request body
+  return handlePutRequest(req, APIVersion + '/api/config/logging/sink/syslog');
+}
+
+Config.deleteDefaultSyslogSeverity = function(req) {
+  // TODO: verify there is one key at root of data: 'default-severity'
+  // OR just filter on the request body
+  var Categories = req.body;
+  return new Promise(function(resolve, reject) {
+    var promises = Categories.map(function(categoryName) {
+      return handleDeleteRequest(req, APIVersion + '/api/config/logging/sink/syslog/filter/category/' + categoryName);
+    });
+    return Promise.all(promises).then(
+      function(data) {
+        resolve(data[0]);
+      },
+      function(data) {
+        reject(data);
+      }
+    )
+  })
+
+}
+
 /*
   get body of forms
 
index af410c2..6c6df78 100644 (file)
@@ -64,6 +64,16 @@ var loggingRoutes = [
         endpoint: '/api/config/default-severity',
         apiHandler: loggingAPI['config'].deleteDefaultSeverity
     },
+    {
+        method: 'PUT',
+        endpoint: '/api/config/default-syslog-severity',
+        apiHandler: loggingAPI['config'].setDefaultSyslogSeverity
+    },
+    {
+        method: 'DELETE',
+        endpoint: '/api/config/default-syslog-severity',
+        apiHandler: loggingAPI['config'].deleteDefaultSyslogSeverity
+    },
     {
         method: 'PUT',
         endpoint: '/api/config/allow-duplicate-events',
index 86a42c1..12cb99c 100644 (file)
@@ -27,17 +27,29 @@ export default class CategorySeverityGrid extends React.Component {
   generateRows(defaultSeverities, severityOptions) {
     let self = this;
     return defaultSeverities.map(function(catsev) {
+      // let dropList = (<DropList options={severityOptions}
+      //   selectedOption={catsev.severity}
+      //   onChange={self.onChangeSeverity(catsev.category)} />);
       let dropList = (<DropList options={severityOptions}
         selectedOption={catsev.severity}
-        onChange={self.onChangeSeverity(catsev.category)} />);
-      return [catsev.category, dropList];
+        onChange={self.onChangeSyslogSeverity(catsev.name)} />);
+      return [catsev.name, dropList];
     });
   }
 
-  onChangeSeverity (category) {
+  // onChangeSeverity (category) {
+  //   return function(e) {
+  //     LoggingStore.updateCategoryDefaultSeverity({
+  //       category: category,
+  //       severity: e
+  //     });
+  //   }
+  // }
+
+  onChangeSyslogSeverity (name) {
     return function(e) {
-      LoggingStore.updateCategoryDefaultSeverity({
-        category: category,
+      LoggingStore.updateCategoryDefaultSyslogSeverity({
+        name: name,
         severity: e
       });
     }
@@ -60,7 +72,7 @@ export default class CategorySeverityGrid extends React.Component {
 
 CategorySeverityGrid.defaultProps = {
   cellLabels: [
-    'Category', 'Severity'
+    'Name', 'Severity'
   ],
   columnClasses: [
     'category', 'severity'
index dd04a57..7b50c76 100644 (file)
@@ -42,7 +42,7 @@ class DefaultCategorySeverityPanel extends React.Component {
     return (
       <DashboardCard className="defaultCategorySeverityPanel"
         showHeader={true}
-        title="Default Category Severity">
+        title="Syslog Category Severity">
         <CategorySeverityGrid defaultSeverities={defaultSeverities}
           severityOptions={severities}/>
       </DashboardCard>
@@ -223,45 +223,60 @@ export default class LoggingGeneral extends React.Component {
         isLoading: true
       });
       LoggingStore.updateLoggingConfig(
-         this.collectNulledCategories(
+         /* this.collectNulledCategories(
             this.state.initialLoggingConfig,
             this.state.loggingConfig),
-         this.removeCategoryNulls(
-            this.state.loggingConfig
-          )
-     );
+            this.removeCategoryNulls(
+            this.state.loggingConfig */
+        this.state.nulledCategories,
+        this.cleanupConfig(
+          this.state.loggingConfig
+        )
+      )
     } else {
       console.log("LoggingGeneral.handleSave failed validation");
     }
     this.context.router.push({pathname: ''});
   }
-  removeCategoryNulls(config) {
+  // removeCategoryNulls(config) {
+  //   let cleanConfig = _.cloneDeep(config);
+  //   let cleanSeverities = [];
+  //   config.defaultSeverities.map(function(d) {
+  //     if (d.severity) {
+  //       cleanSeverities.push(d);
+  //     }
+  //   });
+  //   cleanConfig.defaultSeverities = cleanSeverities;
+  //   return cleanConfig;
+  // }
+  cleanupConfig(config) {
     let cleanConfig = _.cloneDeep(config);
     let cleanSeverities = [];
-    config.defaultSeverities.map(function(d) {
-      if (d.severity) {
-        cleanSeverities.push(d);
+    cleanConfig.defaultSeverities && cleanConfig.defaultSeverities.map((defSev) => {
+      if (defSev.severity) {
+        cleanSeverities.push(defSev);
       }
     });
     cleanConfig.defaultSeverities = cleanSeverities;
+
     return cleanConfig;
   }
-  collectNulledCategories(oldCat, newCat) {
-    let nulledCategories = [];
-    let newSeverities = newCat.defaultSeverities;
-    let oldSeverities = oldCat.defaultSeverities;
-    newSeverities.map(function(c, i) {
-      if(!c.severity) {
-        if(oldSeverities[i].severity) {
-          //verify that categories are the same
-          if(oldSeverities[i].category == c.category) {
-            nulledCategories.push({category: c.category})
-          }
-        }
-      }
-    });
-    return nulledCategories;
-  }
+  // collectNulledCategories(oldCat, newCat) {
+  //   let nulledCategories = [];
+  //   let newSeverities = newCat.defaultSeverities;
+  //   let oldSeverities = oldCat.defaultSeverities;
+  //   newSeverities.map(function(c, i) {
+  //     if(!c.severity) {
+  //       if(oldSeverities[i].severity) {
+  //         //verify that categories are the same
+  //         if(oldSeverities[i].category == c.category) {
+  //           nulledCategories.push({category: c.category})
+  //         }
+  //       }
+  //     }
+  //   });
+  //   return nulledCategories;
+  // }
   validateData() {
 
     function isEventIdValid(eventID) {
@@ -341,6 +356,25 @@ export default class LoggingGeneral extends React.Component {
 
     let syslogViewerURL = this.state.loggingConfig.syslogviewer;
     let defaultSeverities = this.state.loggingConfig.defaultSeverities;
+    // NOTE: There are modifications to original code here
+    // for RIFT-14856 so that default severities map to syslog sink
+    
+    // Find first syslog sink with (WTF - no type on sinks!) name syslog.
+    let syslogSink = this.state.loggingConfig.sinks && _.find(this.state.loggingConfig.sinks, {
+      name: 'syslog'
+    });
+    let defaultSyslogSeverities = [];
+
+    this.state.loggingConfig && this.state.loggingConfig.defaultSeverities && this.state.loggingConfig.defaultSeverities.map((defaultSeverity) => {
+      // Mapping between default categories and names inside a sink
+      let syslogFilterCategory = (syslogSink.filter && syslogSink.filter.category && _.find(syslogSink.filter.category, {
+        name: defaultSeverity.category
+      })) || {
+        name: defaultSeverity.category,
+        severity: null
+      };
+      defaultSyslogSeverities.push(syslogFilterCategory);
+    });
     let severities = this.state.loggingConfig.severities;
     let allowDuplicateEvents = this.state.loggingConfig.allowDuplicateEvents;
     let denyEventIDs = this.state.loggingConfig.denyEventIDs;
@@ -361,7 +395,10 @@ export default class LoggingGeneral extends React.Component {
           {errorMessage}
           <ScreenLoader show={this.state.isLoading}/>
           <div className="panelContainer">
-            <DefaultCategorySeverityPanel defaultSeverities={defaultSeverities}
+            {/*<DefaultCategorySeverityPanel defaultSeverities={defaultSeverities}
+              severities={severities}
+              />*/}
+            <DefaultCategorySeverityPanel defaultSeverities={defaultSyslogSeverities}
               severities={severities}
               />
             <LoggingEventsPanel allowDuplicateEvents={allowDuplicateEvents}
index e073809..47e6e48 100644 (file)
@@ -81,14 +81,15 @@ export default {
                 }
           });
           promises.push(change);
+          /* Backend bug disallows deleting: RIFT-14910
+          
           if(nulledCategories.length > 0) {
             remove = $.ajax({
-              url: apiUrl('api/config/default-severity'),
+              // url: apiUrl('api/config/default-severity'),
+              url: apiUrl('api/config/default-syslog-severity'),
               type: 'DELETE',
               beforeSend: Utils.addAuthorizationStub,
-              data: {
-                'default-severity' : nulledCategories
-              },
+              data: nulledCategories,
               success: function(data) {
                 resolve(data);
               },
@@ -100,6 +101,7 @@ export default {
             });
             promises.push(remove);
           }
+          */
 
 
           Promise.all(promises).then(function(data){
index 860ff9f..d8f0d70 100644 (file)
@@ -26,10 +26,12 @@ class LoggingStore {
     this.loggingConfig = {};
     // initialLoggingConfig is the saved state
     this.initialLoggingConfig = {};
+    this.nulledCategories = [];
     this.bindActions(LoggingActions);
     this.registerAsync(LoggingSource);
     this.exportPublicMethods({
       updateCategoryDefaultSeverity: this.updateCategoryDefaultSeverity,
+      updateCategoryDefaultSyslogSeverity: this.updateCategoryDefaultSyslogSeverity,
       updateAllowDuplicateEvents: this.updateAllowDuplicateEvents,
       addDenyEvent: this.addDenyEvent,
       updateDenyEvent: this.updateDenyEvent,
@@ -97,6 +99,60 @@ class LoggingStore {
     }
   }
 
+  updateCategoryDefaultSyslogSeverity = (catsev) => {
+    console.log("LoggingStore.updateCategoryDefaultSyslogSeverity:", catsev);
+    // find the category (name) in the syslog sink
+
+    let self = this;
+    let loggingConfig = _.cloneDeep(this.loggingConfig);
+    let syslogSinkIndex = -1;
+    let nulledCategories = this.nulledCategories;
+
+    loggingConfig.sinks && loggingConfig.sinks.map((sink, sinkIndex) => {
+      if (sink.name == 'syslog') {
+        if (sink.filter) {
+          if (sink.filter.category) {
+            let catIndex = _.findIndex(sink.filter.category, {
+              name: catsev.name
+            });
+            if (catIndex != -1) {
+              // found it
+              if (catsev.severity == "") {
+                // blank was selected
+                nulledCategories.push(catsev.name);
+                this.setState({
+                  nulledCategories: nulledCategories
+                });
+                // TODO/NOTE: Can't delete from model as sending a top-level payload with
+                // missing elements is not allowed!
+                // When backend supports it, in loggingSource change the order of operations
+                // Delete first followed by save/put.
+                // _.remove(loggingConfig.sinks[sinkIndex].filter.category, {
+                //   name: catsev.name
+                // });
+              } else {
+                sink.filter.category[catIndex] = catsev;
+              }
+            } else {
+              sink.filter.category.push(catsev);
+            }
+          } else {
+            sink.filter.category = [];
+            sink.filter.category.push(catsev);
+          }
+        } else {
+          sink.filter = {};
+          sink.filter.category = [];
+          sink.filter.category.push(catsev);
+        }
+      }
+    });
+
+    this.setState({
+      loggingConfig: loggingConfig
+    });
+  }
+
   updateAllowDuplicateEvents = (allowFlag) => {
     console.log("LoggingStore.updateAllowDuplicateEvents called. allowFlag=", allowFlag);
     const loggingConfig = this.loggingConfig;