helix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ka...@apache.org
Subject git commit: [HELIX-240] Add update examples to the existing example class
Date Fri, 27 Sep 2013 01:04:02 GMT
Updated Branches:
  refs/heads/helix-logical-model c070a7651 -> df5287633


[HELIX-240] Add update examples to the existing example class


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

Branch: refs/heads/helix-logical-model
Commit: df5287633ec29cc16c62021ebffed87301d7f94b
Parents: c070a76
Author: Kanak Biscuitwala <kanak@apache.org>
Authored: Thu Sep 26 18:03:09 2013 -0700
Committer: Kanak Biscuitwala <kanak@apache.org>
Committed: Thu Sep 26 18:03:09 2013 -0700

----------------------------------------------------------------------
 .../helix/api/accessor/ParticipantAccessor.java | 26 ++++++----------
 .../apache/helix/examples/NewModelExample.java  | 32 ++++++++++++++++++++
 2 files changed, 42 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/df528763/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 c1a9250..ca7cf3c 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
@@ -38,7 +38,6 @@ import org.apache.helix.api.Participant;
 import org.apache.helix.api.RunningInstance;
 import org.apache.helix.api.config.ParticipantConfig;
 import org.apache.helix.api.config.UserConfig;
-import org.apache.helix.api.id.ClusterId;
 import org.apache.helix.api.id.MessageId;
 import org.apache.helix.api.id.ParticipantId;
 import org.apache.helix.api.id.PartitionId;
@@ -58,10 +57,8 @@ public class ParticipantAccessor {
 
   private final HelixDataAccessor _accessor;
   private final PropertyKey.Builder _keyBuilder;
-  private final ClusterId _clusterId;
 
-  public ParticipantAccessor(ClusterId clusterId, HelixDataAccessor accessor) {
-    _clusterId = clusterId;
+  public ParticipantAccessor(HelixDataAccessor accessor) {
     _accessor = accessor;
     _keyBuilder = accessor.keyBuilder();
   }
@@ -74,8 +71,7 @@ public class ParticipantAccessor {
   void enableParticipant(ParticipantId participantId, boolean isEnabled) {
     String participantName = participantId.stringify();
     if (_accessor.getProperty(_keyBuilder.instanceConfig(participantName)) == null) {
-      LOG.error("Config for participant: " + participantId + " does NOT exist in cluster:
"
-          + _clusterId);
+      LOG.error("Config for participant: " + participantId + " does NOT exist in cluster");
       return;
     }
 
@@ -167,17 +163,15 @@ public class ParticipantAccessor {
     // check instanceConfig exists
     PropertyKey instanceConfigKey = _keyBuilder.instanceConfig(participantName);
     if (_accessor.getProperty(instanceConfigKey) == null) {
-      LOG.error("Config for participant: " + participantId + " does NOT exist in cluster:
"
-          + _clusterId);
+      LOG.error("Config for participant: " + participantId + " does NOT exist in cluster");
       return;
     }
 
     // check resource exist. warn if not
     IdealState idealState = _accessor.getProperty(_keyBuilder.idealState(resourceName));
     if (idealState == null) {
-      LOG.warn("Disable partitions: " + partitionIdSet + " but Cluster: " + _clusterId
-          + ", resource: " + resourceId
-          + " does NOT exists. probably disable it during ERROR->DROPPED transtition");
+      LOG.warn("Disable partitions: " + partitionIdSet + ", resource: " + resourceId
+          + " does NOT exist. probably disable it during ERROR->DROPPED transtition");
 
     } else {
       // check partitions exist. warn if not
@@ -186,8 +180,8 @@ public class ParticipantAccessor {
             .getPreferenceList(partitionId) == null)
             || (idealState.getRebalanceMode() == RebalanceMode.CUSTOMIZED && idealState
                 .getParticipantStateMap(partitionId) == null)) {
-          LOG.warn("Cluster: " + _clusterId + ", resource: " + resourceId + ", partition:
"
-              + partitionId + ", partition does NOT exist in ideal state");
+          LOG.warn("Resource: " + resourceId + ", partition: " + partitionId
+              + ", partition does NOT exist in ideal state");
         }
       }
     }
@@ -205,8 +199,7 @@ public class ParticipantAccessor {
       @Override
       public ZNRecord update(ZNRecord currentData) {
         if (currentData == null) {
-          throw new HelixException("Cluster: " + _clusterId + ", instance: " + participantId
-              + ", participant config is null");
+          throw new HelixException("Instance: " + participantId + ", participant config is
null");
         }
 
         // TODO: merge with InstanceConfig.setInstanceEnabledForPartition
@@ -382,7 +375,8 @@ public class ParticipantAccessor {
   public Participant readParticipant(ParticipantId participantId) {
     // read physical model
     String participantName = participantId.stringify();
-    InstanceConfig instanceConfig = _accessor.getProperty(_keyBuilder.instance(participantName));
+    InstanceConfig instanceConfig =
+        _accessor.getProperty(_keyBuilder.instanceConfig(participantName));
 
     if (instanceConfig == null) {
       LOG.error("Participant " + participantId + " is not present on the cluster");

http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/df528763/helix-examples/src/main/java/org/apache/helix/examples/NewModelExample.java
----------------------------------------------------------------------
diff --git a/helix-examples/src/main/java/org/apache/helix/examples/NewModelExample.java b/helix-examples/src/main/java/org/apache/helix/examples/NewModelExample.java
index cb5906f..2de8dda 100644
--- a/helix-examples/src/main/java/org/apache/helix/examples/NewModelExample.java
+++ b/helix-examples/src/main/java/org/apache/helix/examples/NewModelExample.java
@@ -1,6 +1,7 @@
 package org.apache.helix.examples;
 
 import java.util.List;
+import java.util.Map;
 import java.util.concurrent.TimeUnit;
 
 import org.apache.helix.BaseDataAccessor;
@@ -10,6 +11,8 @@ import org.apache.helix.api.Partition;
 import org.apache.helix.api.Scope;
 import org.apache.helix.api.State;
 import org.apache.helix.api.accessor.ClusterAccessor;
+import org.apache.helix.api.accessor.ParticipantAccessor;
+import org.apache.helix.api.accessor.ResourceAccessor;
 import org.apache.helix.api.config.ClusterConfig;
 import org.apache.helix.api.config.ParticipantConfig;
 import org.apache.helix.api.config.ResourceConfig;
@@ -30,6 +33,7 @@ import org.apache.helix.model.Transition;
 import org.apache.log4j.Logger;
 
 import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
 
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
@@ -105,6 +109,34 @@ public class NewModelExample {
 
     // create the cluster
     createCluster(cluster, accessor);
+
+    // update the resource
+    updateResource(resource, accessor);
+
+    // update the participant
+    updateParticipant(participant, accessor);
+  }
+
+  private static void updateParticipant(ParticipantConfig participant,
+      HelixDataAccessor helixAccessor) {
+    // add a tag to the participant and change the hostname, then update it using a delta
+    ParticipantAccessor accessor = new ParticipantAccessor(helixAccessor);
+    ParticipantConfig.Delta delta =
+        new ParticipantConfig.Delta(participant.getId()).addTag("newTag").setHostName("newHost");
+    accessor.updateParticipant(participant.getId(), delta);
+  }
+
+  private static void updateResource(ResourceConfig resource, HelixDataAccessor helixAccessor)
{
+    // add some fields to the resource user config, then update it using the resource config
delta
+    ResourceAccessor accessor = new ResourceAccessor(helixAccessor);
+    UserConfig userConfig = resource.getUserConfig();
+    Map<String, String> mapField = Maps.newHashMap();
+    mapField.put("k1", "v1");
+    mapField.put("k2", "v2");
+    userConfig.setMapField("sampleMap", mapField);
+    ResourceConfig.Delta delta =
+        new ResourceConfig.Delta(resource.getId()).setUserConfig(userConfig);
+    accessor.updateResource(resource.getId(), delta);
   }
 
   private static void createCluster(ClusterConfig cluster, HelixDataAccessor helixAccessor)
{


Mime
View raw message