فهرست منبع

HDFS-444. Allow to change probability levels dynamically in the fault injection framework. Contributed by Konstantin Boudnik

git-svn-id: https://svn.apache.org/repos/asf/hadoop/hdfs/trunk@788513 13f79535-47bb-0310-9956-ffa450edef68
Tsz-wo Sze 16 سال پیش
والد
کامیت
1c1655b80e
3فایلهای تغییر یافته به همراه28 افزوده شده و 9 حذف شده
  1. 3 0
      CHANGES.txt
  2. 0 1
      src/test/aop/org/apache/hadoop/fi/FiConfig.java
  3. 25 8
      src/test/aop/org/apache/hadoop/fi/ProbabilityModel.java

+ 3 - 0
CHANGES.txt

@@ -15,6 +15,9 @@ Trunk (unreleased changes)
     HDFS-396. NameNode image and edits directories are specified as URIs.
     (Luca Telloli via rangadi)
 
+    HDFS-444. Allow to change probability levels dynamically in the fault
+    injection framework.  (Konstantin Boudnik via szetszwo)
+
   BUG FIXES
     HDFS-76. Better error message to users when commands fail because of 
     lack of quota. Allow quota to be set even if the limit is lower than

+ 0 - 1
src/test/aop/org/apache/hadoop/fi/FiConfig.java

@@ -38,7 +38,6 @@ public class FiConfig {
   protected static void init () {
     if (conf == null) {
       conf = new Configuration(false);
-      System.out.println(System.getProperties());
       String configName = System.getProperty(CONFIG_PARAMETER, DEFAULT_CONFIG);
       conf.addResource(configName);
     }

+ 25 - 8
src/test/aop/org/apache/hadoop/fi/ProbabilityModel.java

@@ -46,7 +46,8 @@ public class ProbabilityModel {
 
   static final String FPROB_NAME = "fi.";
   private static final String ALL_PROBABILITIES = FPROB_NAME + "*";
-  private static final float DEFAULT_PROB = 0.00f; // Default probability rate is 0%
+  private static final float DEFAULT_PROB = 0.00f; //Default probability is 0%
+  private static final float MAX_PROB = 1.00f; // Max probability is 100%
 
   private static Configuration conf = FiConfig.getConfig();
 
@@ -60,7 +61,14 @@ public class ProbabilityModel {
     LOG.info(ALL_PROBABILITIES + "=" + conf.get(ALL_PROBABILITIES));
   }
 
-  // Simplistic method to check if we have reached the point of injection
+  /**
+   * Simplistic method to check if we have reached the point of injection
+   * @param klassName is the name of the probability level to check. 
+   *  If a configuration has been set for "fi.myClass" then you can check if the
+   *  inject criteria has been reached by calling this method with "myClass"
+   *  string as its parameter
+   * @return true if the probability threshold has been reached; false otherwise
+   */
   public static boolean injectCriteria(String klassName) {
     boolean trigger = false;
     // TODO fix this: make it more sophisticated!!!
@@ -70,17 +78,26 @@ public class ProbabilityModel {
     return trigger;
   }
 
-  // This primitive checks for arbitrary set of desired probability and
-  // uses default setting if it wasn't
-  // The probability expected to be set as an float between 0 and 100
+  /**
+   * This primitive checks for arbitrary set of desired probability. If the 
+   * level hasn't been set method will return default setting.
+   * The probability expected to be set as an float between 0.0 and 1.0
+   * @param klass is the name of the resource
+   * @return float representation of configured probability level of 
+   *  the requested resource or default value if hasn't been set
+   */
   protected static float getProbability(final String klass) {
     String newProbName = FPROB_NAME + klass;
 
-    conf.setIfUnset(newProbName, System.getProperty(newProbName, conf.get(ALL_PROBABILITIES)));
-    float ret = conf.getFloat(newProbName, conf.getFloat(ALL_PROBABILITIES, DEFAULT_PROB));
+    String newValue = System.getProperty(newProbName, conf.get(ALL_PROBABILITIES));
+    if (newValue != null && !newValue.equals(conf.get(newProbName)))
+      conf.set(newProbName, newValue);
+
+    float ret = conf.getFloat(newProbName,
+        conf.getFloat(ALL_PROBABILITIES, DEFAULT_PROB));
     LOG.debug("Request for " + newProbName + " returns=" + ret);
     // Make sure that probability level is valid.
-    if (ret < 0.00 || ret > 1.00) 
+    if (ret < DEFAULT_PROB || ret > MAX_PROB) 
       ret = conf.getFloat(ALL_PROBABILITIES, DEFAULT_PROB);
     
     return ret;