浏览代码

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 年之前
父节点
当前提交
655a9dd884
共有 3 个文件被更改,包括 30 次插入3 次删除
  1. 1 1
      ambari-web/app/data/config_properties.js
  2. 14 2
      ambari-web/app/models/service_config.js
  3. 15 0
      ambari-web/app/utils/validator.js

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

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

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

@@ -337,10 +337,12 @@ App.ServiceConfigProperty = Ember.Object.extend({
 
 
     var isError = false;
     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');
         this.set('errorMessage', 'This is required');
         isError = true;
         isError = true;
+      } else {
+        return;
       }
       }
     }
     }
 
 
@@ -361,6 +363,16 @@ App.ServiceConfigProperty = Ember.Object.extend({
         case 'checkbox':
         case 'checkbox':
           break;
           break;
         case 'directories':
         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;
           break;
         case 'custom':
         case 'custom':
           break;
           break;

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

@@ -35,6 +35,21 @@ module.exports = {
     var floatRegex = /^-?(?:\d+|\d{1,3}(?:,\d{3})+)?(?:\.\d+)?$/;
     var floatRegex = /^-?(?:\d+|\d{1,3}(?:,\d{3})+)?(?:\.\d+)?$/;
     return floatRegex.test(value);
     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
    * validate ip address with port