Browse Source

AMBARI-1159. Check the log/run dir locations to make sure its an abs path. (yusaku)

git-svn-id: https://svn.apache.org/repos/asf/incubator/ambari/trunk@1431855 13f79535-47bb-0310-9956-ffa450edef68
Yusaku Sako 12 years ago
parent
commit
655a9dd884

+ 1 - 1
ambari-web/app/data/config_properties.js

@@ -1294,7 +1294,7 @@ module.exports =
       "displayName": "MapReduce Capacity Scheduler",
       "description": "The scheduler to use for scheduling of MapReduce jobs",
       "defaultValue": "org.apache.hadoop.mapred.CapacityTaskScheduler",
-      "displayType": "directory",
+      //"displayType": "directory",
       "isVisible": true,
       "serviceName": "MAPREDUCE"
     },

+ 14 - 2
ambari-web/app/models/service_config.js

@@ -337,10 +337,12 @@ App.ServiceConfigProperty = Ember.Object.extend({
 
     var isError = false;
 
-    if (this.get('isRequired')) {
-      if (typeof value === 'string' && value.trim().length === 0) {
+    if (typeof value === 'string' && value.trim().length === 0) {
+      if (this.get('isRequired')) {
         this.set('errorMessage', 'This is required');
         isError = true;
+      } else {
+        return;
       }
     }
 
@@ -361,6 +363,16 @@ App.ServiceConfigProperty = Ember.Object.extend({
         case 'checkbox':
           break;
         case 'directories':
+          if (!validator.isValidDir(value)) {
+            this.set('errorMessage', 'Must be a slash at the start');
+            isError = true;
+          }
+          break;
+        case 'directory':
+          if (!validator.isValidDir(value)) {
+            this.set('errorMessage', 'Must be a slash at the start');
+            isError = true;
+          }
           break;
         case 'custom':
           break;

+ 15 - 0
ambari-web/app/utils/validator.js

@@ -35,6 +35,21 @@ module.exports = {
     var floatRegex = /^-?(?:\d+|\d{1,3}(?:,\d{3})+)?(?:\.\d+)?$/;
     return floatRegex.test(value);
   },
+  /**
+   * validate directory with slash at the start
+   * @param value
+   * @return {Boolean}
+   */
+  isValidDir: function(value){
+    var floatRegex = /^\/[0-9a-z]*/;
+    var dirs = value.replace(/,/g,' ').trim().split(new RegExp("\\s+", "g"));
+    for(var i = 0; i < dirs.length; i++){
+      if(!floatRegex.test(dirs[i])){
+        return false;
+      }
+    }
+    return true;
+  },
 
   /**
    * validate ip address with port