hadoop-common-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [hadoop] nandakumar131 commented on a change in pull request #558: HDDS-1217. Refactor ChillMode rules and chillmode manager.
Date Mon, 18 Mar 2019 09:14:03 GMT
nandakumar131 commented on a change in pull request #558: HDDS-1217. Refactor ChillMode rules
and chillmode manager.
URL: https://github.com/apache/hadoop/pull/558#discussion_r266346477
 
 

 ##########
 File path: hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/chillmode/ChillModeExitRule.java
 ##########
 @@ -17,16 +17,87 @@
  */
 package org.apache.hadoop.hdds.scm.chillmode;
 
+import org.apache.hadoop.hdds.server.events.EventHandler;
+import org.apache.hadoop.hdds.server.events.EventPublisher;
+
+
 /**
- * Interface for defining chill mode exit rules.
+ * Abstract class for ChillModeExitRules. When a new rule is added, the new
+ * rule should extend this abstract class.
+ *
+ * Each rule Should do:
+ * 1. Should add a handler for the event it is looking for during the
+ * initialization of the rule.
+ * 2. Add the rule in ScmChillModeManager to list of the rules.
+ *
  *
  * @param <T>
  */
-public interface ChillModeExitRule<T> {
+public abstract class ChillModeExitRule<T> implements EventHandler<T> {
+
+  private final SCMChillModeManager chillModeManager;
+  private final String ruleName;
+
+  public ChillModeExitRule(SCMChillModeManager chillModeManager,
+      String ruleName) {
+    this.chillModeManager = chillModeManager;
+    this.ruleName = ruleName;
+  }
+
+  /**
+   * Return's the name of this ChillModeExit Rule.
+   * @return ruleName
+   */
+  public String getRuleName() {
+    return ruleName;
+  }
+
+
+  /**
+   * Validate's this rule. If this rule condition is met, returns true, else
+   * returns false.
+   * @return boolean
+   */
+  public abstract boolean validate();
+
+  /**
+   * Actual processing logic for this rule.
+   * @param report
+   */
+  public abstract void process(T report);
+
+  /**
+   * Cleanup action's need to be done, once this rule is satisfied.
+   */
+  public abstract void cleanup();
+
+  @Override
+  public final void onMessage(T report, EventPublisher publisher) {
+
+    // TODO: when we have remove handlers, we can remove getInChillmode check
+
+    if (chillModeManager.getInChillMode()) {
+      if (validate()) {
+        cleanup();
+        chillModeManager.validateChillModeExitRules(ruleName, publisher);
+        return;
+      }
+
+      process(report);
 
-  boolean validate();
+      if (validate()) {
+        cleanup();
+        chillModeManager.validateChillModeExitRules(ruleName, publisher);
+      }
+    }
+  }
 
-  void process(T report);
+  /**
+   * Return SCMChillModeManager.
+   * @return SCMChillModeManager
+   */
+  public SCMChillModeManager getChillModeManager() {
+    return chillModeManager;
+  }
 
 Review comment:
   We can replace this with 
   ```protected boolean scmInChillMode() {
   	return chillModeManager.getInChillMode();
   }```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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

---------------------------------------------------------------------
To unsubscribe, e-mail: common-issues-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-issues-help@hadoop.apache.org


Mime
View raw message