You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@helix.apache.org by ka...@apache.org on 2013/11/07 02:19:36 UTC

[28/53] [abbrv] git commit: [HELIX-238] Added user config get/set/update to accessors

[HELIX-238] Added user config get/set/update to accessors


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

Branch: refs/heads/master
Commit: 71c62c4d568d218b45b69b4777d5204d147864ec
Parents: 31725b6
Author: Kanak Biscuitwala <ka...@apache.org>
Authored: Fri Sep 27 15:41:59 2013 -0700
Committer: Kanak Biscuitwala <ka...@apache.org>
Committed: Wed Nov 6 13:17:35 2013 -0800

----------------------------------------------------------------------
 .../helix/api/accessor/ClusterAccessor.java     | 31 ++++++++++
 .../helix/api/accessor/ParticipantAccessor.java | 38 ++++++++++++
 .../helix/api/accessor/ResourceAccessor.java    | 62 ++++++++++++++++++++
 .../rebalancer/context/RebalancerConfig.java    |  9 +++
 4 files changed, 140 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/71c62c4d/helix-core/src/main/java/org/apache/helix/api/accessor/ClusterAccessor.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/api/accessor/ClusterAccessor.java b/helix-core/src/main/java/org/apache/helix/api/accessor/ClusterAccessor.java
index 8e07d97..5a5400e 100644
--- a/helix-core/src/main/java/org/apache/helix/api/accessor/ClusterAccessor.java
+++ b/helix-core/src/main/java/org/apache/helix/api/accessor/ClusterAccessor.java
@@ -307,6 +307,37 @@ public class ClusterAccessor {
   }
 
   /**
+   * Read the user config of the cluster
+   * @return UserConfig, or null
+   */
+  public UserConfig readUserConfig() {
+    ClusterConfiguration clusterConfig = _accessor.getProperty(_keyBuilder.clusterConfig());
+    return clusterConfig != null ? UserConfig.from(clusterConfig) : null;
+  }
+
+  /**
+   * Set the user config of the cluster, overwriting existing user configs
+   * @param userConfig the new user config
+   * @return true if the user config was set, false otherwise
+   */
+  public boolean setUserConfig(UserConfig userConfig) {
+    ClusterConfig.Delta delta = new ClusterConfig.Delta(_clusterId).setUserConfig(userConfig);
+    return updateCluster(delta) != null;
+  }
+
+  /**
+   * Add user configuration to the existing cluster user configuration. Overwrites properties with
+   * the same key
+   * @param userConfig the user config key-value pairs to add
+   * @return true if the user config was updated, false otherwise
+   */
+  public boolean updateUserConfig(UserConfig userConfig) {
+    ClusterConfiguration clusterConfig = new ClusterConfiguration(_clusterId);
+    clusterConfig.addNamespacedConfig(userConfig);
+    return _accessor.updateProperty(_keyBuilder.clusterConfig(), clusterConfig);
+  }
+
+  /**
    * pause controller of cluster
    */
   public void pauseCluster() {

http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/71c62c4d/helix-core/src/main/java/org/apache/helix/api/accessor/ParticipantAccessor.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/api/accessor/ParticipantAccessor.java b/helix-core/src/main/java/org/apache/helix/api/accessor/ParticipantAccessor.java
index ca7cf3c..7e74fc7 100644
--- a/helix-core/src/main/java/org/apache/helix/api/accessor/ParticipantAccessor.java
+++ b/helix-core/src/main/java/org/apache/helix/api/accessor/ParticipantAccessor.java
@@ -258,6 +258,44 @@ public class ParticipantAccessor {
   }
 
   /**
+   * Read the user config of the participant
+   * @param participantId the participant to to look up
+   * @return UserConfig, or null
+   */
+  public UserConfig readUserConfig(ParticipantId participantId) {
+    InstanceConfig instanceConfig =
+        _accessor.getProperty(_keyBuilder.instanceConfig(participantId.stringify()));
+    return instanceConfig != null ? UserConfig.from(instanceConfig) : null;
+  }
+
+  /**
+   * Set the user config of the participant, overwriting existing user configs
+   * @param participantId the participant to update
+   * @param userConfig the new user config
+   * @return true if the user config was set, false otherwise
+   */
+  public boolean setUserConfig(ParticipantId participantId, UserConfig userConfig) {
+    ParticipantConfig.Delta delta =
+        new ParticipantConfig.Delta(participantId).setUserConfig(userConfig);
+    return updateParticipant(participantId, delta) != null;
+  }
+
+  /**
+   * Add user configuration to the existing participant user configuration. Overwrites properties
+   * with
+   * the same key
+   * @param participant the participant to update
+   * @param userConfig the user config key-value pairs to add
+   * @return true if the user config was updated, false otherwise
+   */
+  public boolean updateUserConfig(ParticipantId participantId, UserConfig userConfig) {
+    InstanceConfig instanceConfig = new InstanceConfig(participantId);
+    instanceConfig.addNamespacedConfig(userConfig);
+    return _accessor.updateProperty(_keyBuilder.instanceConfig(participantId.stringify()),
+        instanceConfig);
+  }
+
+  /**
    * Update a participant configuration
    * @param participantId the participant to update
    * @param participantDelta changes to the participant

http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/71c62c4d/helix-core/src/main/java/org/apache/helix/api/accessor/ResourceAccessor.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/api/accessor/ResourceAccessor.java b/helix-core/src/main/java/org/apache/helix/api/accessor/ResourceAccessor.java
index cd55684..de38453 100644
--- a/helix-core/src/main/java/org/apache/helix/api/accessor/ResourceAccessor.java
+++ b/helix-core/src/main/java/org/apache/helix/api/accessor/ResourceAccessor.java
@@ -128,6 +128,68 @@ public class ResourceAccessor {
   }
 
   /**
+   * Set the context of the rebalancer. This includes all properties required for rebalancing this
+   * resource
+   * @param resourceId the resource to update
+   * @param context the new rebalancer context
+   * @return true if the context was set, false otherwise
+   */
+  public boolean setRebalancerContext(ResourceId resourceId, RebalancerContext context) {
+    RebalancerConfig config = new RebalancerConfig(context);
+    ResourceConfiguration resourceConfig = new ResourceConfiguration(resourceId);
+    resourceConfig.addNamespacedConfig(config.toNamespacedConfig());
+    return _accessor.updateProperty(_keyBuilder.resourceConfig(resourceId.stringify()),
+        resourceConfig);
+  }
+
+  /**
+   * Read the user config of the resource
+   * @param resourceId the resource to to look up
+   * @return UserConfig, or null
+   */
+  public UserConfig readUserConfig(ResourceId resourceId) {
+    ResourceConfiguration resourceConfig =
+        _accessor.getProperty(_keyBuilder.resourceConfig(resourceId.stringify()));
+    return resourceConfig != null ? UserConfig.from(resourceConfig) : null;
+  }
+
+  /**
+   * Read the rebalancer config of the resource
+   * @param resourceId the resource to to look up
+   * @return RebalancerConfig, or null
+   */
+  public RebalancerConfig readRebalancerConfig(ResourceId resourceId) {
+    ResourceConfiguration resourceConfig =
+        _accessor.getProperty(_keyBuilder.resourceConfig(resourceId.stringify()));
+    return resourceConfig != null ? RebalancerConfig.from(resourceConfig) : null;
+  }
+
+  /**
+   * Set the user config of the resource, overwriting existing user configs
+   * @param resourceId the resource to update
+   * @param userConfig the new user config
+   * @return true if the user config was set, false otherwise
+   */
+  public boolean setUserConfig(ResourceId resourceId, UserConfig userConfig) {
+    ResourceConfig.Delta delta = new ResourceConfig.Delta(resourceId).setUserConfig(userConfig);
+    return updateResource(resourceId, delta) != null;
+  }
+
+  /**
+   * Add user configuration to the existing resource user configuration. Overwrites properties with
+   * the same key
+   * @param resourceId the resource to update
+   * @param userConfig the user config key-value pairs to add
+   * @return true if the user config was updated, false otherwise
+   */
+  public boolean updateUserConfig(ResourceId resourceId, UserConfig userConfig) {
+    ResourceConfiguration resourceConfig = new ResourceConfiguration(resourceId);
+    resourceConfig.addNamespacedConfig(userConfig);
+    return _accessor.updateProperty(_keyBuilder.resourceConfig(resourceId.stringify()),
+        resourceConfig);
+  }
+
+  /**
    * Persist an existing resource's logical configuration
    * @param resourceConfig logical resource configuration
    * @return true if resource is set, false otherwise

http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/71c62c4d/helix-core/src/main/java/org/apache/helix/controller/rebalancer/context/RebalancerConfig.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/controller/rebalancer/context/RebalancerConfig.java b/helix-core/src/main/java/org/apache/helix/controller/rebalancer/context/RebalancerConfig.java
index 31d37a8..e3ba6f0 100644
--- a/helix-core/src/main/java/org/apache/helix/controller/rebalancer/context/RebalancerConfig.java
+++ b/helix-core/src/main/java/org/apache/helix/controller/rebalancer/context/RebalancerConfig.java
@@ -148,4 +148,13 @@ public final class RebalancerConfig {
   public NamespacedConfig toNamespacedConfig() {
     return _config;
   }
+
+  /**
+   * Get a RebalancerConfig from a physical resource config
+   * @param resourceConfiguration physical resource config
+   * @return RebalancerConfig
+   */
+  public static RebalancerConfig from(ResourceConfiguration resourceConfiguration) {
+    return new RebalancerConfig(resourceConfiguration);
+  }
 }