Return-Path: X-Original-To: apmail-helix-commits-archive@minotaur.apache.org Delivered-To: apmail-helix-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 80E5510B7E for ; Fri, 27 Sep 2013 01:04:24 +0000 (UTC) Received: (qmail 70391 invoked by uid 500); 27 Sep 2013 01:04:24 -0000 Delivered-To: apmail-helix-commits-archive@helix.apache.org Received: (qmail 70357 invoked by uid 500); 27 Sep 2013 01:04:24 -0000 Mailing-List: contact commits-help@helix.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@helix.incubator.apache.org Delivered-To: mailing list commits@helix.incubator.apache.org Received: (qmail 70350 invoked by uid 99); 27 Sep 2013 01:04:24 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 27 Sep 2013 01:04:24 +0000 X-ASF-Spam-Status: No, hits=-2002.3 required=5.0 tests=ALL_TRUSTED,RP_MATCHES_RCVD X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO mail.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with SMTP; Fri, 27 Sep 2013 01:04:23 +0000 Received: (qmail 67851 invoked by uid 99); 27 Sep 2013 01:04:02 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 27 Sep 2013 01:04:02 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 75F5490BB06; Fri, 27 Sep 2013 01:04:02 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: kanak@apache.org To: commits@helix.incubator.apache.org Message-Id: <52cd184106764e78b82e22f66f843c88@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: git commit: [HELIX-240] Add update examples to the existing example class Date: Fri, 27 Sep 2013 01:04:02 +0000 (UTC) X-Virus-Checked: Checked by ClamAV on apache.org 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 Authored: Thu Sep 26 18:03:09 2013 -0700 Committer: Kanak Biscuitwala 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 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) {