You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@helix.apache.org by hu...@apache.org on 2020/08/04 17:24:02 UTC

[helix] branch dynamically-loaded-task updated: Add DynamicTaskConfig to store task configs in ZK (#1208)

This is an automated email from the ASF dual-hosted git repository.

hulee pushed a commit to branch dynamically-loaded-task
in repository https://gitbox.apache.org/repos/asf/helix.git


The following commit(s) were added to refs/heads/dynamically-loaded-task by this push:
     new 4524028  Add DynamicTaskConfig to store task configs in ZK (#1208)
4524028 is described below

commit 4524028d50e211fbaa18eb36c805d1a2c578643d
Author: rabashizade <67...@users.noreply.github.com>
AuthorDate: Tue Aug 4 13:23:53 2020 -0400

    Add DynamicTaskConfig to store task configs in ZK (#1208)
    
    Adds DynamicTaskConfig class, which is a wrapper for ZNRecord, to store
    and access the configs for dynamically loaded tasks in ZK.
    
    Also adds the appropriate constants to TaskConstants.
---
 .../org/apache/helix/task/DynamicTaskConfig.java   | 115 +++++++++++++++++++++
 .../java/org/apache/helix/task/TaskConstants.java  |  20 ++++
 2 files changed, 135 insertions(+)

diff --git a/helix-core/src/main/java/org/apache/helix/task/DynamicTaskConfig.java b/helix-core/src/main/java/org/apache/helix/task/DynamicTaskConfig.java
new file mode 100644
index 0000000..cec7359
--- /dev/null
+++ b/helix-core/src/main/java/org/apache/helix/task/DynamicTaskConfig.java
@@ -0,0 +1,115 @@
+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.util.List;
+
+import org.apache.helix.zookeeper.datamodel.ZNRecord;
+
+/**
+ * A wrapper class for ZNRecord, used to store configs for tasks that are to be dynamically loaded
+ */
+public class DynamicTaskConfig {
+  private final ZNRecord _taskConfigZNRecord;
+
+  /**
+   * Initialize task config with an existing ZNRecord
+   * @param taskConfigZNRecord
+   */
+  public DynamicTaskConfig(ZNRecord taskConfigZNRecord) {
+    _taskConfigZNRecord = taskConfigZNRecord;
+  }
+
+  /**
+   * Initialize task config with parameters
+   * @param id
+   * @param jarFilePath path of the JAR file containing the task
+   * @param taskVersion task version
+   * @param taskClassesFqns list of the {@link Task} classes fully qualified names
+   * @param taskFactoryFqn {@link TaskFactory} class fully qualified name
+   */
+  public DynamicTaskConfig(String id, String jarFilePath, String taskVersion, List<String> taskClassesFqns,
+      String taskFactoryFqn) {
+    _taskConfigZNRecord = new ZNRecord(id);
+    _taskConfigZNRecord.setSimpleField(TaskConstants.TASK_JAR_FILE_KEY, jarFilePath);
+    _taskConfigZNRecord.setSimpleField(TaskConstants.TASK_VERSION_KEY, taskVersion);
+    _taskConfigZNRecord.setListField(TaskConstants.TASK_CLASSES_KEY, taskClassesFqns);
+    _taskConfigZNRecord.setSimpleField(TaskConstants.TASK_FACTORY_KEY, taskFactoryFqn);
+  }
+
+  /**
+   * Get the task config ZNRecord
+   * @return
+   */
+  public ZNRecord getTaskConfigZNRecord() {
+    return _taskConfigZNRecord;
+  }
+
+  /**
+   * Get the address of the JAR file containing the task
+   * @return
+   */
+  public String getJarFilePath() {
+    return _taskConfigZNRecord.getSimpleField(TaskConstants.TASK_JAR_FILE_KEY);
+  }
+
+  /**
+   * Get the task version
+   * @return
+   */
+  public String getTaskVersion() {
+    return _taskConfigZNRecord.getSimpleField(TaskConstants.TASK_VERSION_KEY);
+  }
+
+  /**
+   * Get the list of the {@link Task} classes fully qualified names
+   * @return
+   */
+  public List<String> getTaskClassesFqns() {
+    return _taskConfigZNRecord.getListField(TaskConstants.TASK_CLASSES_KEY);
+  }
+
+  /**
+   * Get the {@link TaskFactory} class fully qualified name
+   * @return
+   */
+  public String getTaskFactoryFqn() {
+    return _taskConfigZNRecord.getSimpleField(TaskConstants.TASK_FACTORY_KEY);
+  }
+
+  @Override
+  public String toString() {
+    return "TaskConfig=" + _taskConfigZNRecord.toString();
+  }
+
+  @Override
+  public boolean equals(Object obj) {
+    if (obj == null) {
+      return false;
+    }
+    if (obj instanceof DynamicTaskConfig) {
+      DynamicTaskConfig that = (DynamicTaskConfig) obj;
+      if (that._taskConfigZNRecord != null) {
+        return that._taskConfigZNRecord.equals(this._taskConfigZNRecord);
+      }
+    }
+    return false;
+  }
+}
diff --git a/helix-core/src/main/java/org/apache/helix/task/TaskConstants.java b/helix-core/src/main/java/org/apache/helix/task/TaskConstants.java
index 4ee7941..b5fbf33 100644
--- a/helix-core/src/main/java/org/apache/helix/task/TaskConstants.java
+++ b/helix-core/src/main/java/org/apache/helix/task/TaskConstants.java
@@ -49,4 +49,24 @@ public class TaskConstants {
   public static final String PREV_RA_NODE = "PreviousResourceAssignment";
 
   public static final boolean DEFAULT_TASK_ENABLE_COMPRESSION = false;
+  /**
+   * Name of the JAR file for the task dynamically loaded in {@link TaskStateModel}
+   */
+  public static final String TASK_JAR_FILE_KEY = "JAR_FILE";
+  /**
+   * Version of the task dynamically loaded in {@link TaskStateModel}
+   */
+  public static final String TASK_VERSION_KEY = "VERSION";
+  /**
+   * Name of the {@link Task} class(es) for the task dynamically loaded in {@link TaskStateModel}
+   */
+  public static final String TASK_CLASSES_KEY = "TASK_CLASSES";
+  /**
+   * Name of the {@link TaskFactory} class for the task dynamically loaded in {@link TaskStateModel}
+   */
+  public static final String TASK_FACTORY_KEY = "TASK_FACTORY";
+  /**
+   * The path for dynamic task configs
+   */
+  public static final String DYNAMICALLY_LOADED_TASK_PATH = "/TASK_DEFINITION";
 }