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



##########
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:
       I would suggestion to make this feature optional. If there is no folder 
created for "TASK_DEFINITON", let's skip the steps. Otherwise, it could bring 
potential risks.

##########
File path: helix-core/src/main/java/org/apache/helix/task/JarLoader.java
##########
@@ -0,0 +1,34 @@
+package org.apache.helix.task;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.net.URL;
+
+/**
+ * The interface that is to be implemented by a specific JAR loader.
+ */
+public interface JarLoader {

Review comment:
       Let's start with this PR. You can create an API folder under task. Move 
the interface to API module.

##########
File path: helix-core/src/main/java/org/apache/helix/task/LocalJarLoader.java
##########
@@ -0,0 +1,48 @@
+package org.apache.helix.task;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.io.File;
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class LocalJarLoader implements JarLoader {
+  private static final Logger LOG = 
LoggerFactory.getLogger(LocalJarLoader.class);
+
+  @Override
+  public URL openJar(String jar) {
+    File taskJar;
+    try {
+      taskJar = new File(jar);
+      if (taskJar.exists() && !taskJar.isDirectory()) {
+        return taskJar.toURI().toURL();
+      } else {

Review comment:
       else clause is not necessary. You can directly put 
   
   LOG.error("Failed to find JAR " + jar + " for new task.");
           throw new IllegalStateException("No JAR for task");
   
   Because if the return is not happening, it will reaches the exception part.

##########
File path: helix-core/src/main/java/org/apache/helix/task/TaskStateModel.java
##########
@@ -43,6 +46,11 @@
   private ScheduledFuture timeout_task;
   private TaskRunner _taskRunner;
   private final ScheduledExecutorService _timeoutTaskExecutor;
+  public static final String TASK_JAR_FILE_KEY = "JAR_FILE";
+  public static final String TASK_VERSION_KEY = "VERSION";
+  public static final String TASK_CLASSES_KEY = "TASK_CLASSES";
+  public static final String TASK_FACTORY_KEY = "TASKFACTORY";
+  public static final String TASK_PATH = "/TASK_DEFINITION";

Review comment:
       Let's move these two TaskConstants class.




----------------------------------------------------------------
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:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to