helix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From l...@apache.org
Subject [17/33] helix git commit: Added method to TaskDriver to get all workflows from a cluster. Added methods to convert HelixProperty to WorkflowConfig and JobConfig.
Date Wed, 17 Aug 2016 04:27:13 GMT
Added method to TaskDriver to get all workflows from a cluster. Added methods to convert HelixProperty
to WorkflowConfig and JobConfig.


Project: http://git-wip-us.apache.org/repos/asf/helix/repo
Commit: http://git-wip-us.apache.org/repos/asf/helix/commit/9f802064
Tree: http://git-wip-us.apache.org/repos/asf/helix/tree/9f802064
Diff: http://git-wip-us.apache.org/repos/asf/helix/diff/9f802064

Branch: refs/heads/helix-0.6.x
Commit: 9f802064fbc782fd6820d551bb1cf39ba4c53108
Parents: ead8301
Author: Lei Xia <lxia@linkedin.com>
Authored: Fri Apr 8 10:52:23 2016 -0700
Committer: Lei Xia <lxia@linkedin.com>
Committed: Tue Jul 5 15:01:06 2016 -0700

----------------------------------------------------------------------
 .../java/org/apache/helix/task/JobConfig.java   |  8 +++++++
 .../java/org/apache/helix/task/TaskDriver.java  | 22 ++++++++++++++++++++
 .../org/apache/helix/task/WorkflowConfig.java   | 13 +++++++++++-
 3 files changed, 42 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/helix/blob/9f802064/helix-core/src/main/java/org/apache/helix/task/JobConfig.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/task/JobConfig.java b/helix-core/src/main/java/org/apache/helix/task/JobConfig.java
index 4d5aa94..ac086d3 100644
--- a/helix-core/src/main/java/org/apache/helix/task/JobConfig.java
+++ b/helix-core/src/main/java/org/apache/helix/task/JobConfig.java
@@ -34,10 +34,12 @@ import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
 import org.apache.helix.task.beans.JobBean;
 import org.apache.helix.task.beans.TaskBean;
+import org.apache.helix.HelixProperty;
 
 /**
  * Provides a typed interface to job configurations.
  */
+// TODO: extends JobConfig from ResourceConfig
 public class JobConfig {
 
   /**
@@ -268,6 +270,12 @@ public class JobConfig {
     return cfgMap;
   }
 
+  public static JobConfig fromHelixProperty(HelixProperty property)
+      throws IllegalArgumentException {
+    Map<String, String> configs = property.getRecord().getSimpleFields();
+    return Builder.fromMap(configs).build();
+  }
+
   /**
    * A builder for {@link JobConfig}. Validates the configurations.
    */

http://git-wip-us.apache.org/repos/asf/helix/blob/9f802064/helix-core/src/main/java/org/apache/helix/task/TaskDriver.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/task/TaskDriver.java b/helix-core/src/main/java/org/apache/helix/task/TaskDriver.java
index c0d7852..b3a0364 100644
--- a/helix-core/src/main/java/org/apache/helix/task/TaskDriver.java
+++ b/helix-core/src/main/java/org/apache/helix/task/TaskDriver.java
@@ -749,6 +749,28 @@ public class TaskDriver {
     return TaskUtil.getJobCfg(manager, job);
   }
 
+  /**
+   * Batch get the configurations of all workflows in this cluster.
+   *
+   * @return
+   */
+  public Map<String, WorkflowConfig> getWorkflows() {
+    Map<String, WorkflowConfig> workflowConfigMap = new HashMap<String, WorkflowConfig>();
+    Map<String, ResourceConfig> resourceConfigMap =
+        _accessor.getChildValuesMap(_accessor.keyBuilder().resourceConfigs());
+
+    for (Map.Entry<String, ResourceConfig> resource : resourceConfigMap.entrySet())
{
+      try {
+        WorkflowConfig config = WorkflowConfig.fromHelixProperty(resource.getValue());
+        workflowConfigMap.put(resource.getKey(), config);
+      } catch (IllegalArgumentException ex) {
+        // ignore if it is not a workflow config.
+      }
+    }
+
+    return workflowConfigMap;
+  }
+
   public void list(String resource) {
     WorkflowConfig wCfg = TaskUtil.getWorkflowCfg(_accessor, resource);
     if (wCfg == null) {

http://git-wip-us.apache.org/repos/asf/helix/blob/9f802064/helix-core/src/main/java/org/apache/helix/task/WorkflowConfig.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/task/WorkflowConfig.java b/helix-core/src/main/java/org/apache/helix/task/WorkflowConfig.java
index 844bdf0..cbd22cd 100644
--- a/helix-core/src/main/java/org/apache/helix/task/WorkflowConfig.java
+++ b/helix-core/src/main/java/org/apache/helix/task/WorkflowConfig.java
@@ -28,11 +28,13 @@ import java.util.TimeZone;
 import java.util.concurrent.TimeUnit;
 import org.apache.helix.HelixException;
 import org.apache.helix.task.beans.WorkflowBean;
+import org.apache.helix.HelixProperty;
 import org.apache.log4j.Logger;
 
 /**
  * Provides a typed interface to workflow level configurations. Validates the configurations.
  */
+// TODO: extends WorkflowConfig from ResourceConfig
 public class WorkflowConfig {
   private static final Logger LOG = Logger.getLogger(WorkflowConfig.class);
 
@@ -217,6 +219,16 @@ public class WorkflowConfig {
     return null;
   }
 
+  public static WorkflowConfig fromHelixProperty(HelixProperty property)
+      throws IllegalArgumentException {
+    Map<String, String> configs = property.getRecord().getSimpleFields();
+    if (!configs.containsKey(WorkflowConfigProperty.Dag.name())) {
+      throw new IllegalArgumentException(
+          String.format("%s is an invalid WorkflowConfig", property.getId()));
+    }
+    return Builder.fromMap(configs).build();
+  }
+
   public static class Builder {
     private JobDag _taskDag = JobDag.EMPTY_DAG;
     private int _parallelJobs = 1;
@@ -399,5 +411,4 @@ public class WorkflowConfig {
       }
     }
   }
-
 }


Mime
View raw message