You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@helix.apache.org by GitBox <gi...@apache.org> on 2020/07/31 23:28:58 UTC

[GitHub] [helix] rabashizade commented on a change in pull request #1169: Dynamically Load Tasks in Task Framework

rabashizade commented on a change in pull request #1169:
URL: https://github.com/apache/helix/pull/1169#discussion_r463885621



##########
File path: helix-core/src/main/java/org/apache/helix/task/TaskStateModel.java
##########
@@ -283,6 +297,63 @@ public void reset() {
     }
   }
 
+  /**
+   * Loads className using classLoader
+   * @param classLoader
+   * @param className
+   * @return Class className loaded by classLoader
+   */
+  private Class loadClass(URLClassLoader classLoader, String className) {
+    try {
+      return classLoader.loadClass(className);
+    } catch (ClassNotFoundException e) {
+      LOG.error("Failed to load Task class " + className + " for new task in instance " + _manager
+          .getInstanceName() + " in cluster " + _manager.getClusterName() + ".");
+      throw new IllegalStateException("Null TaskFactory for task");
+    }
+  }
+
+  /**
+   * Loads Task and TaskFactory classes for command input from
+   * a JAR file, and registers the TaskFactory in _taskFactoryRegistry.
+   * @param command The command indicating what task to be loaded
+   */
+  private void loadNewTask(String command) {
+    // Read ZNRecord containing task definition information.
+    ZNRecord taskConfig = _manager.getHelixDataAccessor().getBaseDataAccessor()
+        .get(TASK_PATH + "/" + command, null, 0);

Review comment:
       Thank you for your comments, Junkai. So do you think something like this at the beginning of the method would do?
   
   ```suggestion
       // If the path for dynamic tasks doesn't exist, skip loading the task
       if (!_manager.getHelixDataAccessor().getBaseDataAccessor().exists(TaskConstants.TASK_PATH, 0)) {
         return;
       }
       ZNRecord taskConfig = _manager.getHelixDataAccessor().getBaseDataAccessor()
           .get(TASK_PATH + "/" + command, null, 0);
   ```




----------------------------------------------------------------
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



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@helix.apache.org
For additional commands, e-mail: reviews-help@helix.apache.org