helix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1428210 [27/29] - in /incubator/helix/site-content: ./ apidocs/assets/ apidocs/reference/ apidocs/reference/org/apache/helix/ apidocs/reference/org/apache/helix/manager/zk/ apidocs/reference/org/apache/helix/tools/ apidocs/reference/org/ap...
Date Thu, 03 Jan 2013 08:21:29 GMT
Modified: incubator/helix/site-content/xref/org/apache/helix/tools/ClusterSetup.html
URL: http://svn.apache.org/viewvc/incubator/helix/site-content/xref/org/apache/helix/tools/ClusterSetup.html?rev=1428210&r1=1428209&r2=1428210&view=diff
==============================================================================
--- incubator/helix/site-content/xref/org/apache/helix/tools/ClusterSetup.html (original)
+++ incubator/helix/site-content/xref/org/apache/helix/tools/ClusterSetup.html Thu Jan  3 08:21:23 2013
@@ -493,1378 +493,1102 @@
 <a class="jxr_linenumber" name="483" href="#483">483</a>       _logger.warn(<span class="jxr_string">"Resource "</span> + resourceName + <span class="jxr_string">" not balanced, skip"</span>);
 <a class="jxr_linenumber" name="484" href="#484">484</a>       <strong class="jxr_keyword">return</strong>;
 <a class="jxr_linenumber" name="485" href="#485">485</a>     }
-<a class="jxr_linenumber" name="486" href="#486">486</a>     <a href="../../../../org/apache/helix/model/IdealState.html">IdealState</a> newIdealState = balanceIdealState(clusterName, idealState);
-<a class="jxr_linenumber" name="487" href="#487">487</a>     _admin.setResourceIdealState(clusterName, resourceName, newIdealState);
-<a class="jxr_linenumber" name="488" href="#488">488</a>   }
-<a class="jxr_linenumber" name="489" href="#489">489</a> 
-<a class="jxr_linenumber" name="490" href="#490">490</a>   <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">void</strong> expandCluster(String clusterName)
-<a class="jxr_linenumber" name="491" href="#491">491</a>   {
-<a class="jxr_linenumber" name="492" href="#492">492</a>     List&lt;String&gt; resources = _admin.getResourcesInCluster(clusterName);
-<a class="jxr_linenumber" name="493" href="#493">493</a>     <strong class="jxr_keyword">for</strong> (String resourceName : resources)
-<a class="jxr_linenumber" name="494" href="#494">494</a>     {
-<a class="jxr_linenumber" name="495" href="#495">495</a>       expandResource(clusterName, resourceName);
-<a class="jxr_linenumber" name="496" href="#496">496</a>     }
-<a class="jxr_linenumber" name="497" href="#497">497</a>   }
-<a class="jxr_linenumber" name="498" href="#498">498</a> 
-<a class="jxr_linenumber" name="499" href="#499">499</a>   <strong class="jxr_keyword">public</strong> String[] parseStates(String clusterName, String stateModelName)
-<a class="jxr_linenumber" name="500" href="#500">500</a>   {
-<a class="jxr_linenumber" name="501" href="#501">501</a>     String[] result = <strong class="jxr_keyword">new</strong> String[2];
-<a class="jxr_linenumber" name="502" href="#502">502</a>     String masterStateValue = <strong class="jxr_keyword">null</strong>, slaveStateValue = <strong class="jxr_keyword">null</strong>;
-<a class="jxr_linenumber" name="503" href="#503">503</a>     <a href="../../../../org/apache/helix/model/StateModelDefinition.html">StateModelDefinition</a> stateModDef =
-<a class="jxr_linenumber" name="504" href="#504">504</a>         _admin.getStateModelDef(clusterName, stateModelName);
-<a class="jxr_linenumber" name="505" href="#505">505</a> 
-<a class="jxr_linenumber" name="506" href="#506">506</a>     <strong class="jxr_keyword">if</strong> (stateModDef == <strong class="jxr_keyword">null</strong>)
-<a class="jxr_linenumber" name="507" href="#507">507</a>     {
-<a class="jxr_linenumber" name="508" href="#508">508</a>       <strong class="jxr_keyword">throw</strong> <strong class="jxr_keyword">new</strong> <a href="../../../../org/apache/helix/HelixException.html">HelixException</a>(<span class="jxr_string">"cannot find state model: "</span> + stateModelName);
-<a class="jxr_linenumber" name="509" href="#509">509</a>     }
-<a class="jxr_linenumber" name="510" href="#510">510</a>     <em class="jxr_comment">// StateModelDefinition def = new StateModelDefinition(stateModDef);</em>
-<a class="jxr_linenumber" name="511" href="#511">511</a> 
-<a class="jxr_linenumber" name="512" href="#512">512</a>     List&lt;String&gt; statePriorityList = stateModDef.getStatesPriorityList();
-<a class="jxr_linenumber" name="513" href="#513">513</a> 
-<a class="jxr_linenumber" name="514" href="#514">514</a>     <strong class="jxr_keyword">for</strong> (String state : statePriorityList)
-<a class="jxr_linenumber" name="515" href="#515">515</a>     {
-<a class="jxr_linenumber" name="516" href="#516">516</a>       String count = stateModDef.getNumInstancesPerState(state);
-<a class="jxr_linenumber" name="517" href="#517">517</a>       <strong class="jxr_keyword">if</strong> (count.equals(<span class="jxr_string">"1"</span>))
-<a class="jxr_linenumber" name="518" href="#518">518</a>       {
-<a class="jxr_linenumber" name="519" href="#519">519</a>         <strong class="jxr_keyword">if</strong> (masterStateValue != <strong class="jxr_keyword">null</strong>)
-<a class="jxr_linenumber" name="520" href="#520">520</a>         {
-<a class="jxr_linenumber" name="521" href="#521">521</a>           <strong class="jxr_keyword">throw</strong> <strong class="jxr_keyword">new</strong> <a href="../../../../org/apache/helix/HelixException.html">HelixException</a>(<span class="jxr_string">"Invalid or unsupported state model definition"</span>);
-<a class="jxr_linenumber" name="522" href="#522">522</a>         }
-<a class="jxr_linenumber" name="523" href="#523">523</a>         masterStateValue = state;
-<a class="jxr_linenumber" name="524" href="#524">524</a>       }
-<a class="jxr_linenumber" name="525" href="#525">525</a>       <strong class="jxr_keyword">else</strong> <strong class="jxr_keyword">if</strong> (count.equalsIgnoreCase(<span class="jxr_string">"R"</span>))
-<a class="jxr_linenumber" name="526" href="#526">526</a>       {
-<a class="jxr_linenumber" name="527" href="#527">527</a>         <strong class="jxr_keyword">if</strong> (slaveStateValue != <strong class="jxr_keyword">null</strong>)
-<a class="jxr_linenumber" name="528" href="#528">528</a>         {
-<a class="jxr_linenumber" name="529" href="#529">529</a>           <strong class="jxr_keyword">throw</strong> <strong class="jxr_keyword">new</strong> <a href="../../../../org/apache/helix/HelixException.html">HelixException</a>(<span class="jxr_string">"Invalid or unsupported state model definition"</span>);
-<a class="jxr_linenumber" name="530" href="#530">530</a>         }
-<a class="jxr_linenumber" name="531" href="#531">531</a>         slaveStateValue = state;
-<a class="jxr_linenumber" name="532" href="#532">532</a>       }
-<a class="jxr_linenumber" name="533" href="#533">533</a>       <strong class="jxr_keyword">else</strong> <strong class="jxr_keyword">if</strong> (count.equalsIgnoreCase(<span class="jxr_string">"N"</span>))
-<a class="jxr_linenumber" name="534" href="#534">534</a>       {
-<a class="jxr_linenumber" name="535" href="#535">535</a>         <strong class="jxr_keyword">if</strong> (!(masterStateValue == <strong class="jxr_keyword">null</strong> &amp;&amp; slaveStateValue == <strong class="jxr_keyword">null</strong>))
-<a class="jxr_linenumber" name="536" href="#536">536</a>         {
-<a class="jxr_linenumber" name="537" href="#537">537</a>           <strong class="jxr_keyword">throw</strong> <strong class="jxr_keyword">new</strong> <a href="../../../../org/apache/helix/HelixException.html">HelixException</a>(<span class="jxr_string">"Invalid or unsupported state model definition"</span>);
-<a class="jxr_linenumber" name="538" href="#538">538</a>         }
-<a class="jxr_linenumber" name="539" href="#539">539</a>         masterStateValue = slaveStateValue = state;
-<a class="jxr_linenumber" name="540" href="#540">540</a>       }
-<a class="jxr_linenumber" name="541" href="#541">541</a>     }
-<a class="jxr_linenumber" name="542" href="#542">542</a>     <strong class="jxr_keyword">if</strong> (masterStateValue == <strong class="jxr_keyword">null</strong> &amp;&amp; slaveStateValue == <strong class="jxr_keyword">null</strong>)
-<a class="jxr_linenumber" name="543" href="#543">543</a>     {
-<a class="jxr_linenumber" name="544" href="#544">544</a>       <strong class="jxr_keyword">throw</strong> <strong class="jxr_keyword">new</strong> <a href="../../../../org/apache/helix/HelixException.html">HelixException</a>(<span class="jxr_string">"Invalid or unsupported state model definition"</span>);
-<a class="jxr_linenumber" name="545" href="#545">545</a>     }
-<a class="jxr_linenumber" name="546" href="#546">546</a> 
-<a class="jxr_linenumber" name="547" href="#547">547</a>     <strong class="jxr_keyword">if</strong> (masterStateValue == <strong class="jxr_keyword">null</strong>)
-<a class="jxr_linenumber" name="548" href="#548">548</a>     {
-<a class="jxr_linenumber" name="549" href="#549">549</a>       masterStateValue = slaveStateValue;
-<a class="jxr_linenumber" name="550" href="#550">550</a>     }
-<a class="jxr_linenumber" name="551" href="#551">551</a>     result[0] = masterStateValue;
-<a class="jxr_linenumber" name="552" href="#552">552</a>     result[1] = slaveStateValue;
-<a class="jxr_linenumber" name="553" href="#553">553</a>     <strong class="jxr_keyword">return</strong> result;
-<a class="jxr_linenumber" name="554" href="#554">554</a>   }
-<a class="jxr_linenumber" name="555" href="#555">555</a> 
-<a class="jxr_linenumber" name="556" href="#556">556</a>   <strong class="jxr_keyword">public</strong> <a href="../../../../org/apache/helix/model/IdealState.html">IdealState</a> balanceIdealState(String clusterName, <a href="../../../../org/apache/helix/model/IdealState.html">IdealState</a> idealState)
-<a class="jxr_linenumber" name="557" href="#557">557</a>   {
-<a class="jxr_linenumber" name="558" href="#558">558</a>     <em class="jxr_comment">// The new instances are added into the cluster already. So we need to find out the</em>
-<a class="jxr_linenumber" name="559" href="#559">559</a>     <em class="jxr_comment">// instances that</em>
-<a class="jxr_linenumber" name="560" href="#560">560</a>     <em class="jxr_comment">// already have partitions assigned to them.</em>
-<a class="jxr_linenumber" name="561" href="#561">561</a>     List&lt;String&gt; instanceNames = _admin.getInstancesInCluster(clusterName);
-<a class="jxr_linenumber" name="562" href="#562">562</a>     Set&lt;String&gt; activeInstances = <strong class="jxr_keyword">new</strong> HashSet&lt;String&gt;();
-<a class="jxr_linenumber" name="563" href="#563">563</a>     <strong class="jxr_keyword">for</strong> (String partition : idealState.getPartitionSet())
-<a class="jxr_linenumber" name="564" href="#564">564</a>     {
-<a class="jxr_linenumber" name="565" href="#565">565</a>       activeInstances.addAll(idealState.getRecord().getListField(partition));
-<a class="jxr_linenumber" name="566" href="#566">566</a>     }
-<a class="jxr_linenumber" name="567" href="#567">567</a>     instanceNames.removeAll(activeInstances);
-<a class="jxr_linenumber" name="568" href="#568">568</a>     Map&lt;String, Object&gt; previousIdealState = buildInternalIdealState(idealState);
-<a class="jxr_linenumber" name="569" href="#569">569</a> 
-<a class="jxr_linenumber" name="570" href="#570">570</a>     Map&lt;String, Object&gt; balancedRecord =
-<a class="jxr_linenumber" name="571" href="#571">571</a>         IdealStateCalculatorForStorageNode.calculateNextIdealState(instanceNames,
-<a class="jxr_linenumber" name="572" href="#572">572</a>                                                                    previousIdealState);
-<a class="jxr_linenumber" name="573" href="#573">573</a> 
-<a class="jxr_linenumber" name="574" href="#574">574</a>     String[] states = parseStates(clusterName, idealState.getStateModelDefRef());
+<a class="jxr_linenumber" name="486" href="#486">486</a>     balanceIdealState(clusterName, idealState);
+<a class="jxr_linenumber" name="487" href="#487">487</a>   }
+<a class="jxr_linenumber" name="488" href="#488">488</a> 
+<a class="jxr_linenumber" name="489" href="#489">489</a>   <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">void</strong> expandCluster(String clusterName)
+<a class="jxr_linenumber" name="490" href="#490">490</a>   {
+<a class="jxr_linenumber" name="491" href="#491">491</a>     List&lt;String&gt; resources = _admin.getResourcesInCluster(clusterName);
+<a class="jxr_linenumber" name="492" href="#492">492</a>     <strong class="jxr_keyword">for</strong> (String resourceName : resources)
+<a class="jxr_linenumber" name="493" href="#493">493</a>     {
+<a class="jxr_linenumber" name="494" href="#494">494</a>       expandResource(clusterName, resourceName);
+<a class="jxr_linenumber" name="495" href="#495">495</a>     }
+<a class="jxr_linenumber" name="496" href="#496">496</a>   }
+<a class="jxr_linenumber" name="497" href="#497">497</a> 
+<a class="jxr_linenumber" name="498" href="#498">498</a>   
+<a class="jxr_linenumber" name="499" href="#499">499</a> 
+<a class="jxr_linenumber" name="500" href="#500">500</a>   <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">void</strong> balanceIdealState(String clusterName, <a href="../../../../org/apache/helix/model/IdealState.html">IdealState</a> idealState)
+<a class="jxr_linenumber" name="501" href="#501">501</a>   {
+<a class="jxr_linenumber" name="502" href="#502">502</a>     <em class="jxr_comment">// The new instances are added into the cluster already. So we need to find out the</em>
+<a class="jxr_linenumber" name="503" href="#503">503</a>     <em class="jxr_comment">// instances that</em>
+<a class="jxr_linenumber" name="504" href="#504">504</a>     <em class="jxr_comment">// already have partitions assigned to them.</em>
+<a class="jxr_linenumber" name="505" href="#505">505</a>     List&lt;String&gt; instanceNames = _admin.getInstancesInCluster(clusterName);
+<a class="jxr_linenumber" name="506" href="#506">506</a>     rebalanceResource(clusterName, idealState, instanceNames);
+<a class="jxr_linenumber" name="507" href="#507">507</a> 
+<a class="jxr_linenumber" name="508" href="#508">508</a>   }
+<a class="jxr_linenumber" name="509" href="#509">509</a> 
+<a class="jxr_linenumber" name="510" href="#510">510</a>   <strong class="jxr_keyword">private</strong> <strong class="jxr_keyword">void</strong> rebalanceResource(String clusterName,
+<a class="jxr_linenumber" name="511" href="#511">511</a>       <a href="../../../../org/apache/helix/model/IdealState.html">IdealState</a> idealState, List&lt;String&gt; instanceNames)
+<a class="jxr_linenumber" name="512" href="#512">512</a>   {
+<a class="jxr_linenumber" name="513" href="#513">513</a>      _admin.rebalance(clusterName, idealState, instanceNames);
+<a class="jxr_linenumber" name="514" href="#514">514</a>   }
+<a class="jxr_linenumber" name="515" href="#515">515</a> 
+<a class="jxr_linenumber" name="516" href="#516">516</a>   <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">void</strong> rebalanceStorageCluster(String clusterName,
+<a class="jxr_linenumber" name="517" href="#517">517</a>                                       String resourceName,
+<a class="jxr_linenumber" name="518" href="#518">518</a>                                       <strong class="jxr_keyword">int</strong> replica,
+<a class="jxr_linenumber" name="519" href="#519">519</a>                                       String keyPrefix)
+<a class="jxr_linenumber" name="520" href="#520">520</a>   {
+<a class="jxr_linenumber" name="521" href="#521">521</a>     _admin.rebalance(clusterName, resourceName, replica);
+<a class="jxr_linenumber" name="522" href="#522">522</a>   }
+<a class="jxr_linenumber" name="523" href="#523">523</a> 
+<a class="jxr_linenumber" name="524" href="#524">524</a>   <em class="jxr_javadoccomment">/**</em>
+<a class="jxr_linenumber" name="525" href="#525">525</a> <em class="jxr_javadoccomment">   * setConfig</em>
+<a class="jxr_linenumber" name="526" href="#526">526</a> <em class="jxr_javadoccomment">   * </em>
+<a class="jxr_linenumber" name="527" href="#527">527</a> <em class="jxr_javadoccomment">   * @param scopeStr</em>
+<a class="jxr_linenumber" name="528" href="#528">528</a> <em class="jxr_javadoccomment">   *          : scope=value, ... where scope=CLUSTER, RESOURCE, PARTICIPANT, PARTITION</em>
+<a class="jxr_linenumber" name="529" href="#529">529</a> <em class="jxr_javadoccomment">   * @param properitesStr</em>
+<a class="jxr_linenumber" name="530" href="#530">530</a> <em class="jxr_javadoccomment">   *          : key=value, ... which represents a Map&lt;String, String&gt;</em>
+<a class="jxr_linenumber" name="531" href="#531">531</a> <em class="jxr_javadoccomment">   */</em>
+<a class="jxr_linenumber" name="532" href="#532">532</a>   <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">void</strong> setConfig(String scopesStr, String propertiesStr)
+<a class="jxr_linenumber" name="533" href="#533">533</a>   {
+<a class="jxr_linenumber" name="534" href="#534">534</a>     <a href="../../../../org/apache/helix/ConfigScope.html">ConfigScope</a> scope = <strong class="jxr_keyword">new</strong> <a href="../../../../org/apache/helix/ConfigScopeBuilder.html">ConfigScopeBuilder</a>().build(scopesStr);
+<a class="jxr_linenumber" name="535" href="#535">535</a> 
+<a class="jxr_linenumber" name="536" href="#536">536</a>     <em class="jxr_comment">// parse properties</em>
+<a class="jxr_linenumber" name="537" href="#537">537</a>     String[] properties = propertiesStr.split(<span class="jxr_string">"[&#92;&#92;s,]"</span>);
+<a class="jxr_linenumber" name="538" href="#538">538</a>     Map&lt;String, String&gt; propertiesMap = <strong class="jxr_keyword">new</strong> TreeMap&lt;String, String&gt;();
+<a class="jxr_linenumber" name="539" href="#539">539</a>     <strong class="jxr_keyword">for</strong> (String property : properties)
+<a class="jxr_linenumber" name="540" href="#540">540</a>     {
+<a class="jxr_linenumber" name="541" href="#541">541</a>       <strong class="jxr_keyword">int</strong> idx = property.indexOf('=');
+<a class="jxr_linenumber" name="542" href="#542">542</a>       <strong class="jxr_keyword">if</strong> (idx == -1)
+<a class="jxr_linenumber" name="543" href="#543">543</a>       {
+<a class="jxr_linenumber" name="544" href="#544">544</a>         logger.error(<span class="jxr_string">"Invalid property string: "</span> + property);
+<a class="jxr_linenumber" name="545" href="#545">545</a>         <strong class="jxr_keyword">continue</strong>;
+<a class="jxr_linenumber" name="546" href="#546">546</a>       }
+<a class="jxr_linenumber" name="547" href="#547">547</a> 
+<a class="jxr_linenumber" name="548" href="#548">548</a>       String key = property.substring(0, idx);
+<a class="jxr_linenumber" name="549" href="#549">549</a>       String value = property.substring(idx + 1);
+<a class="jxr_linenumber" name="550" href="#550">550</a>       propertiesMap.put(key, value);
+<a class="jxr_linenumber" name="551" href="#551">551</a>     }
+<a class="jxr_linenumber" name="552" href="#552">552</a>     logger.debug(<span class="jxr_string">"propertiesMap: "</span> + propertiesMap);
+<a class="jxr_linenumber" name="553" href="#553">553</a> 
+<a class="jxr_linenumber" name="554" href="#554">554</a>     _admin.setConfig(scope, propertiesMap);
+<a class="jxr_linenumber" name="555" href="#555">555</a>   }
+<a class="jxr_linenumber" name="556" href="#556">556</a> 
+<a class="jxr_linenumber" name="557" href="#557">557</a>   <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">void</strong> removeConfig(String scopesStr, String keysStr)
+<a class="jxr_linenumber" name="558" href="#558">558</a>   {
+<a class="jxr_linenumber" name="559" href="#559">559</a>     <a href="../../../../org/apache/helix/ConfigScope.html">ConfigScope</a> scope = <strong class="jxr_keyword">new</strong> <a href="../../../../org/apache/helix/ConfigScopeBuilder.html">ConfigScopeBuilder</a>().build(scopesStr);
+<a class="jxr_linenumber" name="560" href="#560">560</a> 
+<a class="jxr_linenumber" name="561" href="#561">561</a>     <em class="jxr_comment">// parse keys</em>
+<a class="jxr_linenumber" name="562" href="#562">562</a>     String[] keys = keysStr.split(<span class="jxr_string">"[&#92;&#92;s,]"</span>);
+<a class="jxr_linenumber" name="563" href="#563">563</a>     Set&lt;String&gt; keysSet = <strong class="jxr_keyword">new</strong> HashSet&lt;String&gt;(Arrays.asList(keys));
+<a class="jxr_linenumber" name="564" href="#564">564</a> 
+<a class="jxr_linenumber" name="565" href="#565">565</a>     _admin.removeConfig(scope, keysSet);
+<a class="jxr_linenumber" name="566" href="#566">566</a>   }
+<a class="jxr_linenumber" name="567" href="#567">567</a> 
+<a class="jxr_linenumber" name="568" href="#568">568</a>   <strong class="jxr_keyword">public</strong> String getConfig(String scopesStr, String keysStr)
+<a class="jxr_linenumber" name="569" href="#569">569</a>   {
+<a class="jxr_linenumber" name="570" href="#570">570</a>     <a href="../../../../org/apache/helix/ConfigScope.html">ConfigScope</a> scope = <strong class="jxr_keyword">new</strong> <a href="../../../../org/apache/helix/ConfigScopeBuilder.html">ConfigScopeBuilder</a>().build(scopesStr);
+<a class="jxr_linenumber" name="571" href="#571">571</a> 
+<a class="jxr_linenumber" name="572" href="#572">572</a>     <em class="jxr_comment">// parse keys</em>
+<a class="jxr_linenumber" name="573" href="#573">573</a>     String[] keys = keysStr.split(<span class="jxr_string">"[&#92;&#92;s,]"</span>);
+<a class="jxr_linenumber" name="574" href="#574">574</a>     Set&lt;String&gt; keysSet = <strong class="jxr_keyword">new</strong> HashSet&lt;String&gt;(Arrays.asList(keys));
 <a class="jxr_linenumber" name="575" href="#575">575</a> 
-<a class="jxr_linenumber" name="576" href="#576">576</a>     <a href="../../../../org/apache/helix/ZNRecord.html">ZNRecord</a> newIdealStateRecord =
-<a class="jxr_linenumber" name="577" href="#577">577</a>         IdealStateCalculatorForStorageNode.convertToZNRecord(balancedRecord,
-<a class="jxr_linenumber" name="578" href="#578">578</a>                                                              idealState.getResourceName(),
-<a class="jxr_linenumber" name="579" href="#579">579</a>                                                              states[0],
-<a class="jxr_linenumber" name="580" href="#580">580</a>                                                              states[1]);
-<a class="jxr_linenumber" name="581" href="#581">581</a>     Set&lt;String&gt; partitionSet = <strong class="jxr_keyword">new</strong> HashSet&lt;String&gt;();
-<a class="jxr_linenumber" name="582" href="#582">582</a>     partitionSet.addAll(newIdealStateRecord.getMapFields().keySet());
-<a class="jxr_linenumber" name="583" href="#583">583</a>     partitionSet.addAll(newIdealStateRecord.getListFields().keySet());
-<a class="jxr_linenumber" name="584" href="#584">584</a> 
-<a class="jxr_linenumber" name="585" href="#585">585</a>     Map&lt;String, String&gt; reversePartitionIndex =
-<a class="jxr_linenumber" name="586" href="#586">586</a>         (Map&lt;String, String&gt;) balancedRecord.get(<span class="jxr_string">"reversePartitionIndex"</span>);
-<a class="jxr_linenumber" name="587" href="#587">587</a>     <strong class="jxr_keyword">for</strong> (String partition : partitionSet)
-<a class="jxr_linenumber" name="588" href="#588">588</a>     {
-<a class="jxr_linenumber" name="589" href="#589">589</a>       <strong class="jxr_keyword">if</strong> (reversePartitionIndex.containsKey(partition))
-<a class="jxr_linenumber" name="590" href="#590">590</a>       {
-<a class="jxr_linenumber" name="591" href="#591">591</a>         String originPartitionName = reversePartitionIndex.get(partition);
-<a class="jxr_linenumber" name="592" href="#592">592</a>         <strong class="jxr_keyword">if</strong> (partition.equals(originPartitionName))
-<a class="jxr_linenumber" name="593" href="#593">593</a>         {
-<a class="jxr_linenumber" name="594" href="#594">594</a>           <strong class="jxr_keyword">continue</strong>;
-<a class="jxr_linenumber" name="595" href="#595">595</a>         }
-<a class="jxr_linenumber" name="596" href="#596">596</a>         newIdealStateRecord.getMapFields()
-<a class="jxr_linenumber" name="597" href="#597">597</a>                            .put(originPartitionName,
-<a class="jxr_linenumber" name="598" href="#598">598</a>                                 newIdealStateRecord.getMapField(partition));
-<a class="jxr_linenumber" name="599" href="#599">599</a>         newIdealStateRecord.getMapFields().remove(partition);
-<a class="jxr_linenumber" name="600" href="#600">600</a> 
-<a class="jxr_linenumber" name="601" href="#601">601</a>         newIdealStateRecord.getListFields()
-<a class="jxr_linenumber" name="602" href="#602">602</a>                            .put(originPartitionName,
-<a class="jxr_linenumber" name="603" href="#603">603</a>                                 newIdealStateRecord.getListField(partition));
-<a class="jxr_linenumber" name="604" href="#604">604</a>         newIdealStateRecord.getListFields().remove(partition);
-<a class="jxr_linenumber" name="605" href="#605">605</a>       }
-<a class="jxr_linenumber" name="606" href="#606">606</a>     }
-<a class="jxr_linenumber" name="607" href="#607">607</a> 
-<a class="jxr_linenumber" name="608" href="#608">608</a>     newIdealStateRecord.getSimpleFields()
-<a class="jxr_linenumber" name="609" href="#609">609</a>                        .putAll(idealState.getRecord().getSimpleFields());
-<a class="jxr_linenumber" name="610" href="#610">610</a>     <strong class="jxr_keyword">return</strong> <strong class="jxr_keyword">new</strong> <a href="../../../../org/apache/helix/model/IdealState.html">IdealState</a>(newIdealStateRecord);
-<a class="jxr_linenumber" name="611" href="#611">611</a> 
-<a class="jxr_linenumber" name="612" href="#612">612</a>   }
-<a class="jxr_linenumber" name="613" href="#613">613</a> 
-<a class="jxr_linenumber" name="614" href="#614">614</a>   <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">static</strong> Map&lt;String, Object&gt; buildInternalIdealState(<a href="../../../../org/apache/helix/model/IdealState.html">IdealState</a> state)
-<a class="jxr_linenumber" name="615" href="#615">615</a>   {
-<a class="jxr_linenumber" name="616" href="#616">616</a>     <em class="jxr_comment">// Try parse the partition number from name DB_n. If not, sort the partitions and</em>
-<a class="jxr_linenumber" name="617" href="#617">617</a>     <em class="jxr_comment">// assign id</em>
-<a class="jxr_linenumber" name="618" href="#618">618</a>     Map&lt;String, Integer&gt; partitionIndex = <strong class="jxr_keyword">new</strong> HashMap&lt;String, Integer&gt;();
-<a class="jxr_linenumber" name="619" href="#619">619</a>     Map&lt;String, String&gt; reversePartitionIndex = <strong class="jxr_keyword">new</strong> HashMap&lt;String, String&gt;();
-<a class="jxr_linenumber" name="620" href="#620">620</a>     <strong class="jxr_keyword">boolean</strong> indexInPartitionName = <strong class="jxr_keyword">true</strong>;
-<a class="jxr_linenumber" name="621" href="#621">621</a>     <strong class="jxr_keyword">for</strong> (String partitionId : state.getPartitionSet())
-<a class="jxr_linenumber" name="622" href="#622">622</a>     {
-<a class="jxr_linenumber" name="623" href="#623">623</a>       <strong class="jxr_keyword">int</strong> lastPos = partitionId.lastIndexOf(<span class="jxr_string">"_"</span>);
-<a class="jxr_linenumber" name="624" href="#624">624</a>       <strong class="jxr_keyword">if</strong> (lastPos &lt; 0)
-<a class="jxr_linenumber" name="625" href="#625">625</a>       {
-<a class="jxr_linenumber" name="626" href="#626">626</a>         indexInPartitionName = false;
-<a class="jxr_linenumber" name="627" href="#627">627</a>         <strong class="jxr_keyword">break</strong>;
-<a class="jxr_linenumber" name="628" href="#628">628</a>       }
-<a class="jxr_linenumber" name="629" href="#629">629</a>       <strong class="jxr_keyword">try</strong>
-<a class="jxr_linenumber" name="630" href="#630">630</a>       {
-<a class="jxr_linenumber" name="631" href="#631">631</a>         String idStr = partitionId.substring(lastPos + 1);
-<a class="jxr_linenumber" name="632" href="#632">632</a>         <strong class="jxr_keyword">int</strong> partition = Integer.parseInt(idStr);
-<a class="jxr_linenumber" name="633" href="#633">633</a>         partitionIndex.put(partitionId, partition);
-<a class="jxr_linenumber" name="634" href="#634">634</a>         reversePartitionIndex.put(state.getResourceName() + <span class="jxr_string">"_"</span> + partition, partitionId);
-<a class="jxr_linenumber" name="635" href="#635">635</a>       }
-<a class="jxr_linenumber" name="636" href="#636">636</a>       <strong class="jxr_keyword">catch</strong> (Exception e)
-<a class="jxr_linenumber" name="637" href="#637">637</a>       {
-<a class="jxr_linenumber" name="638" href="#638">638</a>         indexInPartitionName = false;
-<a class="jxr_linenumber" name="639" href="#639">639</a>         partitionIndex.clear();
-<a class="jxr_linenumber" name="640" href="#640">640</a>         reversePartitionIndex.clear();
-<a class="jxr_linenumber" name="641" href="#641">641</a>         <strong class="jxr_keyword">break</strong>;
-<a class="jxr_linenumber" name="642" href="#642">642</a>       }
-<a class="jxr_linenumber" name="643" href="#643">643</a>     }
-<a class="jxr_linenumber" name="644" href="#644">644</a> 
-<a class="jxr_linenumber" name="645" href="#645">645</a>     <strong class="jxr_keyword">if</strong> (indexInPartitionName == false)
-<a class="jxr_linenumber" name="646" href="#646">646</a>     {
-<a class="jxr_linenumber" name="647" href="#647">647</a>       List&lt;String&gt; partitions = <strong class="jxr_keyword">new</strong> ArrayList&lt;String&gt;();
-<a class="jxr_linenumber" name="648" href="#648">648</a>       partitions.addAll(state.getPartitionSet());
-<a class="jxr_linenumber" name="649" href="#649">649</a>       Collections.sort(partitions);
-<a class="jxr_linenumber" name="650" href="#650">650</a>       <strong class="jxr_keyword">for</strong> (<strong class="jxr_keyword">int</strong> i = 0; i &lt; partitions.size(); i++)
-<a class="jxr_linenumber" name="651" href="#651">651</a>       {
-<a class="jxr_linenumber" name="652" href="#652">652</a>         partitionIndex.put(partitions.get(i), i);
-<a class="jxr_linenumber" name="653" href="#653">653</a>         reversePartitionIndex.put(state.getResourceName() + <span class="jxr_string">"_"</span> + i, partitions.get(i));
-<a class="jxr_linenumber" name="654" href="#654">654</a>       }
-<a class="jxr_linenumber" name="655" href="#655">655</a>     }
-<a class="jxr_linenumber" name="656" href="#656">656</a> 
-<a class="jxr_linenumber" name="657" href="#657">657</a>     Map&lt;String, List&lt;Integer&gt;&gt; nodeMasterAssignmentMap =
-<a class="jxr_linenumber" name="658" href="#658">658</a>         <strong class="jxr_keyword">new</strong> TreeMap&lt;String, List&lt;Integer&gt;&gt;();
-<a class="jxr_linenumber" name="659" href="#659">659</a>     Map&lt;String, Map&lt;String, List&lt;Integer&gt;&gt;&gt; combinedNodeSlaveAssignmentMap =
-<a class="jxr_linenumber" name="660" href="#660">660</a>         <strong class="jxr_keyword">new</strong> TreeMap&lt;String, Map&lt;String, List&lt;Integer&gt;&gt;&gt;();
-<a class="jxr_linenumber" name="661" href="#661">661</a>     <strong class="jxr_keyword">for</strong> (String partition : state.getPartitionSet())
-<a class="jxr_linenumber" name="662" href="#662">662</a>     {
-<a class="jxr_linenumber" name="663" href="#663">663</a>       List&lt;String&gt; instances = state.getRecord().getListField(partition);
-<a class="jxr_linenumber" name="664" href="#664">664</a>       String master = instances.get(0);
-<a class="jxr_linenumber" name="665" href="#665">665</a>       <strong class="jxr_keyword">if</strong> (!nodeMasterAssignmentMap.containsKey(master))
-<a class="jxr_linenumber" name="666" href="#666">666</a>       {
-<a class="jxr_linenumber" name="667" href="#667">667</a>         nodeMasterAssignmentMap.put(master, <strong class="jxr_keyword">new</strong> ArrayList&lt;Integer&gt;());
-<a class="jxr_linenumber" name="668" href="#668">668</a>       }
-<a class="jxr_linenumber" name="669" href="#669">669</a>       <strong class="jxr_keyword">if</strong> (!combinedNodeSlaveAssignmentMap.containsKey(master))
-<a class="jxr_linenumber" name="670" href="#670">670</a>       {
-<a class="jxr_linenumber" name="671" href="#671">671</a>         combinedNodeSlaveAssignmentMap.put(master, <strong class="jxr_keyword">new</strong> TreeMap&lt;String, List&lt;Integer&gt;&gt;());
-<a class="jxr_linenumber" name="672" href="#672">672</a>       }
-<a class="jxr_linenumber" name="673" href="#673">673</a>       nodeMasterAssignmentMap.get(master).add(partitionIndex.get(partition));
-<a class="jxr_linenumber" name="674" href="#674">674</a>       <strong class="jxr_keyword">for</strong> (<strong class="jxr_keyword">int</strong> i = 1; i &lt; instances.size(); i++)
-<a class="jxr_linenumber" name="675" href="#675">675</a>       {
-<a class="jxr_linenumber" name="676" href="#676">676</a>         String instance = instances.get(i);
-<a class="jxr_linenumber" name="677" href="#677">677</a>         Map&lt;String, List&lt;Integer&gt;&gt; slaveMap = combinedNodeSlaveAssignmentMap.get(master);
-<a class="jxr_linenumber" name="678" href="#678">678</a>         <strong class="jxr_keyword">if</strong> (!slaveMap.containsKey(instance))
-<a class="jxr_linenumber" name="679" href="#679">679</a>         {
-<a class="jxr_linenumber" name="680" href="#680">680</a>           slaveMap.put(instance, <strong class="jxr_keyword">new</strong> ArrayList&lt;Integer&gt;());
-<a class="jxr_linenumber" name="681" href="#681">681</a>         }
-<a class="jxr_linenumber" name="682" href="#682">682</a>         slaveMap.get(instance).add(partitionIndex.get(partition));
-<a class="jxr_linenumber" name="683" href="#683">683</a>       }
-<a class="jxr_linenumber" name="684" href="#684">684</a>     }
-<a class="jxr_linenumber" name="685" href="#685">685</a> 
-<a class="jxr_linenumber" name="686" href="#686">686</a>     Map&lt;String, Object&gt; result = <strong class="jxr_keyword">new</strong> TreeMap&lt;String, Object&gt;();
-<a class="jxr_linenumber" name="687" href="#687">687</a>     result.put(<span class="jxr_string">"MasterAssignmentMap"</span>, nodeMasterAssignmentMap);
-<a class="jxr_linenumber" name="688" href="#688">688</a>     result.put(<span class="jxr_string">"SlaveAssignmentMap"</span>, combinedNodeSlaveAssignmentMap);
-<a class="jxr_linenumber" name="689" href="#689">689</a>     result.put(<span class="jxr_string">"replicas"</span>, Integer.parseInt(state.getReplicas()));
-<a class="jxr_linenumber" name="690" href="#690">690</a>     result.put(<span class="jxr_string">"partitions"</span>, <strong class="jxr_keyword">new</strong> Integer(state.getRecord().getListFields().size()));
-<a class="jxr_linenumber" name="691" href="#691">691</a>     result.put(<span class="jxr_string">"reversePartitionIndex"</span>, reversePartitionIndex);
-<a class="jxr_linenumber" name="692" href="#692">692</a>     <strong class="jxr_keyword">return</strong> result;
-<a class="jxr_linenumber" name="693" href="#693">693</a>   }
-<a class="jxr_linenumber" name="694" href="#694">694</a> 
-<a class="jxr_linenumber" name="695" href="#695">695</a>   <em class="jxr_comment">// TODO: remove this. has moved to ZkHelixAdmin</em>
-<a class="jxr_linenumber" name="696" href="#696">696</a>   <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">void</strong> rebalanceStorageCluster(String clusterName,
-<a class="jxr_linenumber" name="697" href="#697">697</a>                                       String resourceName,
-<a class="jxr_linenumber" name="698" href="#698">698</a>                                       <strong class="jxr_keyword">int</strong> replica,
-<a class="jxr_linenumber" name="699" href="#699">699</a>                                       String keyPrefix)
-<a class="jxr_linenumber" name="700" href="#700">700</a>   {
-<a class="jxr_linenumber" name="701" href="#701">701</a>     List&lt;String&gt; InstanceNames = _admin.getInstancesInCluster(clusterName);
-<a class="jxr_linenumber" name="702" href="#702">702</a>     <em class="jxr_comment">// ensure we get the same idealState with the same set of instances</em>
-<a class="jxr_linenumber" name="703" href="#703">703</a>     Collections.sort(InstanceNames);
-<a class="jxr_linenumber" name="704" href="#704">704</a> 
-<a class="jxr_linenumber" name="705" href="#705">705</a>     <a href="../../../../org/apache/helix/model/IdealState.html">IdealState</a> idealState = _admin.getResourceIdealState(clusterName, resourceName);
-<a class="jxr_linenumber" name="706" href="#706">706</a>     <strong class="jxr_keyword">if</strong> (idealState == <strong class="jxr_keyword">null</strong>)
-<a class="jxr_linenumber" name="707" href="#707">707</a>     {
-<a class="jxr_linenumber" name="708" href="#708">708</a>       <strong class="jxr_keyword">throw</strong> <strong class="jxr_keyword">new</strong> <a href="../../../../org/apache/helix/HelixException.html">HelixException</a>(<span class="jxr_string">"Resource: "</span> + resourceName + <span class="jxr_string">" has NOT been added yet"</span>);
-<a class="jxr_linenumber" name="709" href="#709">709</a>     }
-<a class="jxr_linenumber" name="710" href="#710">710</a> 
-<a class="jxr_linenumber" name="711" href="#711">711</a>     idealState.setReplicas(Integer.toString(replica));
-<a class="jxr_linenumber" name="712" href="#712">712</a>     <strong class="jxr_keyword">int</strong> partitions = idealState.getNumPartitions();
-<a class="jxr_linenumber" name="713" href="#713">713</a>     String stateModelName = idealState.getStateModelDefRef();
-<a class="jxr_linenumber" name="714" href="#714">714</a>     <a href="../../../../org/apache/helix/model/StateModelDefinition.html">StateModelDefinition</a> stateModDef =
-<a class="jxr_linenumber" name="715" href="#715">715</a>         _admin.getStateModelDef(clusterName, stateModelName);
-<a class="jxr_linenumber" name="716" href="#716">716</a> 
-<a class="jxr_linenumber" name="717" href="#717">717</a>     <strong class="jxr_keyword">if</strong> (stateModDef == <strong class="jxr_keyword">null</strong>)
-<a class="jxr_linenumber" name="718" href="#718">718</a>     {
-<a class="jxr_linenumber" name="719" href="#719">719</a>       <strong class="jxr_keyword">throw</strong> <strong class="jxr_keyword">new</strong> <a href="../../../../org/apache/helix/HelixException.html">HelixException</a>(<span class="jxr_string">"cannot find state model: "</span> + stateModelName);
-<a class="jxr_linenumber" name="720" href="#720">720</a>     }
-<a class="jxr_linenumber" name="721" href="#721">721</a>     <em class="jxr_comment">// StateModelDefinition def = new StateModelDefinition(stateModDef);</em>
+<a class="jxr_linenumber" name="576" href="#576">576</a>     Map&lt;String, String&gt; propertiesMap = _admin.getConfig(scope, keysSet);
+<a class="jxr_linenumber" name="577" href="#577">577</a>     StringBuffer sb = <strong class="jxr_keyword">new</strong> StringBuffer();
+<a class="jxr_linenumber" name="578" href="#578">578</a>     <strong class="jxr_keyword">for</strong> (String key : keys)
+<a class="jxr_linenumber" name="579" href="#579">579</a>     {
+<a class="jxr_linenumber" name="580" href="#580">580</a>       <strong class="jxr_keyword">if</strong> (propertiesMap.containsKey(key))
+<a class="jxr_linenumber" name="581" href="#581">581</a>       {
+<a class="jxr_linenumber" name="582" href="#582">582</a>         <strong class="jxr_keyword">if</strong> (sb.length() &gt; 0)
+<a class="jxr_linenumber" name="583" href="#583">583</a>         {
+<a class="jxr_linenumber" name="584" href="#584">584</a>           sb.append(<span class="jxr_string">","</span> + key + <span class="jxr_string">"="</span> + propertiesMap.get(key));
+<a class="jxr_linenumber" name="585" href="#585">585</a>         }
+<a class="jxr_linenumber" name="586" href="#586">586</a>         <strong class="jxr_keyword">else</strong>
+<a class="jxr_linenumber" name="587" href="#587">587</a>         {
+<a class="jxr_linenumber" name="588" href="#588">588</a>           <em class="jxr_comment">// sb.length()==0 means the first key=value</em>
+<a class="jxr_linenumber" name="589" href="#589">589</a>           sb.append(key + <span class="jxr_string">"="</span> + propertiesMap.get(key));
+<a class="jxr_linenumber" name="590" href="#590">590</a>         }
+<a class="jxr_linenumber" name="591" href="#591">591</a>       }
+<a class="jxr_linenumber" name="592" href="#592">592</a>       <strong class="jxr_keyword">else</strong>
+<a class="jxr_linenumber" name="593" href="#593">593</a>       {
+<a class="jxr_linenumber" name="594" href="#594">594</a>         logger.error(<span class="jxr_string">"Config doesn't exist for key: "</span> + key);
+<a class="jxr_linenumber" name="595" href="#595">595</a>       }
+<a class="jxr_linenumber" name="596" href="#596">596</a>     }
+<a class="jxr_linenumber" name="597" href="#597">597</a> 
+<a class="jxr_linenumber" name="598" href="#598">598</a>     System.out.println(sb.toString());
+<a class="jxr_linenumber" name="599" href="#599">599</a>     <strong class="jxr_keyword">return</strong> sb.toString();
+<a class="jxr_linenumber" name="600" href="#600">600</a>   }
+<a class="jxr_linenumber" name="601" href="#601">601</a> 
+<a class="jxr_linenumber" name="602" href="#602">602</a>   <em class="jxr_javadoccomment">/**</em>
+<a class="jxr_linenumber" name="603" href="#603">603</a> <em class="jxr_javadoccomment">   * Sets up a cluster with 6 Instances[localhost:8900 to localhost:8905], 1</em>
+<a class="jxr_linenumber" name="604" href="#604">604</a> <em class="jxr_javadoccomment">   * resource[EspressoDB] with a replication factor of 3</em>
+<a class="jxr_linenumber" name="605" href="#605">605</a> <em class="jxr_javadoccomment">   * </em>
+<a class="jxr_linenumber" name="606" href="#606">606</a> <em class="jxr_javadoccomment">   * @param clusterName</em>
+<a class="jxr_linenumber" name="607" href="#607">607</a> <em class="jxr_javadoccomment">   */</em>
+<a class="jxr_linenumber" name="608" href="#608">608</a>   <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">void</strong> setupTestCluster(String clusterName)
+<a class="jxr_linenumber" name="609" href="#609">609</a>   {
+<a class="jxr_linenumber" name="610" href="#610">610</a>     addCluster(clusterName, <strong class="jxr_keyword">true</strong>);
+<a class="jxr_linenumber" name="611" href="#611">611</a>     String storageInstanceInfoArray[] = <strong class="jxr_keyword">new</strong> String[6];
+<a class="jxr_linenumber" name="612" href="#612">612</a>     <strong class="jxr_keyword">for</strong> (<strong class="jxr_keyword">int</strong> i = 0; i &lt; storageInstanceInfoArray.length; i++)
+<a class="jxr_linenumber" name="613" href="#613">613</a>     {
+<a class="jxr_linenumber" name="614" href="#614">614</a>       storageInstanceInfoArray[i] = <span class="jxr_string">"localhost:"</span> + (8900 + i);
+<a class="jxr_linenumber" name="615" href="#615">615</a>     }
+<a class="jxr_linenumber" name="616" href="#616">616</a>     addInstancesToCluster(clusterName, storageInstanceInfoArray);
+<a class="jxr_linenumber" name="617" href="#617">617</a>     addResourceToCluster(clusterName, <span class="jxr_string">"TestDB"</span>, 10, <span class="jxr_string">"MasterSlave"</span>);
+<a class="jxr_linenumber" name="618" href="#618">618</a>     rebalanceStorageCluster(clusterName, <span class="jxr_string">"TestDB"</span>, 3);
+<a class="jxr_linenumber" name="619" href="#619">619</a>   }
+<a class="jxr_linenumber" name="620" href="#620">620</a> 
+<a class="jxr_linenumber" name="621" href="#621">621</a>   <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">static</strong> <strong class="jxr_keyword">void</strong> printUsage(Options cliOptions)
+<a class="jxr_linenumber" name="622" href="#622">622</a>   {
+<a class="jxr_linenumber" name="623" href="#623">623</a>     HelpFormatter helpFormatter = <strong class="jxr_keyword">new</strong> HelpFormatter();
+<a class="jxr_linenumber" name="624" href="#624">624</a>     helpFormatter.setWidth(1000);
+<a class="jxr_linenumber" name="625" href="#625">625</a>     helpFormatter.printHelp(<span class="jxr_string">"java "</span> + ClusterSetup.<strong class="jxr_keyword">class</strong>.getName(), cliOptions);
+<a class="jxr_linenumber" name="626" href="#626">626</a>   }
+<a class="jxr_linenumber" name="627" href="#627">627</a> 
+<a class="jxr_linenumber" name="628" href="#628">628</a>   @SuppressWarnings(<span class="jxr_string">"static-access"</span>)
+<a class="jxr_linenumber" name="629" href="#629">629</a>   <strong class="jxr_keyword">private</strong> <strong class="jxr_keyword">static</strong> Options constructCommandLineOptions()
+<a class="jxr_linenumber" name="630" href="#630">630</a>   {
+<a class="jxr_linenumber" name="631" href="#631">631</a>     Option helpOption =
+<a class="jxr_linenumber" name="632" href="#632">632</a>         OptionBuilder.withLongOpt(help)
+<a class="jxr_linenumber" name="633" href="#633">633</a>                      .withDescription(<span class="jxr_string">"Prints command-line options info"</span>)
+<a class="jxr_linenumber" name="634" href="#634">634</a>                      .create();
+<a class="jxr_linenumber" name="635" href="#635">635</a> 
+<a class="jxr_linenumber" name="636" href="#636">636</a>     Option zkServerOption =
+<a class="jxr_linenumber" name="637" href="#637">637</a>         OptionBuilder.withLongOpt(zkServerAddress)
+<a class="jxr_linenumber" name="638" href="#638">638</a>                      .withDescription(<span class="jxr_string">"Provide zookeeper address"</span>)
+<a class="jxr_linenumber" name="639" href="#639">639</a>                      .create();
+<a class="jxr_linenumber" name="640" href="#640">640</a>     zkServerOption.setArgs(1);
+<a class="jxr_linenumber" name="641" href="#641">641</a>     zkServerOption.setRequired(<strong class="jxr_keyword">true</strong>);
+<a class="jxr_linenumber" name="642" href="#642">642</a>     zkServerOption.setArgName(<span class="jxr_string">"ZookeeperServerAddress(Required)"</span>);
+<a class="jxr_linenumber" name="643" href="#643">643</a> 
+<a class="jxr_linenumber" name="644" href="#644">644</a>     Option listClustersOption =
+<a class="jxr_linenumber" name="645" href="#645">645</a>         OptionBuilder.withLongOpt(listClusters)
+<a class="jxr_linenumber" name="646" href="#646">646</a>                      .withDescription(<span class="jxr_string">"List existing clusters"</span>)
+<a class="jxr_linenumber" name="647" href="#647">647</a>                      .create();
+<a class="jxr_linenumber" name="648" href="#648">648</a>     listClustersOption.setArgs(0);
+<a class="jxr_linenumber" name="649" href="#649">649</a>     listClustersOption.setRequired(false);
+<a class="jxr_linenumber" name="650" href="#650">650</a> 
+<a class="jxr_linenumber" name="651" href="#651">651</a>     Option listResourceOption =
+<a class="jxr_linenumber" name="652" href="#652">652</a>         OptionBuilder.withLongOpt(listResources)
+<a class="jxr_linenumber" name="653" href="#653">653</a>                      .withDescription(<span class="jxr_string">"List resources hosted in a cluster"</span>)
+<a class="jxr_linenumber" name="654" href="#654">654</a>                      .create();
+<a class="jxr_linenumber" name="655" href="#655">655</a>     listResourceOption.setArgs(1);
+<a class="jxr_linenumber" name="656" href="#656">656</a>     listResourceOption.setRequired(false);
+<a class="jxr_linenumber" name="657" href="#657">657</a>     listResourceOption.setArgName(<span class="jxr_string">"clusterName"</span>);
+<a class="jxr_linenumber" name="658" href="#658">658</a> 
+<a class="jxr_linenumber" name="659" href="#659">659</a>     Option listInstancesOption =
+<a class="jxr_linenumber" name="660" href="#660">660</a>         OptionBuilder.withLongOpt(listInstances)
+<a class="jxr_linenumber" name="661" href="#661">661</a>                      .withDescription(<span class="jxr_string">"List Instances in a cluster"</span>)
+<a class="jxr_linenumber" name="662" href="#662">662</a>                      .create();
+<a class="jxr_linenumber" name="663" href="#663">663</a>     listInstancesOption.setArgs(1);
+<a class="jxr_linenumber" name="664" href="#664">664</a>     listInstancesOption.setRequired(false);
+<a class="jxr_linenumber" name="665" href="#665">665</a>     listInstancesOption.setArgName(<span class="jxr_string">"clusterName"</span>);
+<a class="jxr_linenumber" name="666" href="#666">666</a> 
+<a class="jxr_linenumber" name="667" href="#667">667</a>     Option addClusterOption =
+<a class="jxr_linenumber" name="668" href="#668">668</a>         OptionBuilder.withLongOpt(addCluster)
+<a class="jxr_linenumber" name="669" href="#669">669</a>                      .withDescription(<span class="jxr_string">"Add a new cluster"</span>)
+<a class="jxr_linenumber" name="670" href="#670">670</a>                      .create();
+<a class="jxr_linenumber" name="671" href="#671">671</a>     addClusterOption.setArgs(1);
+<a class="jxr_linenumber" name="672" href="#672">672</a>     addClusterOption.setRequired(false);
+<a class="jxr_linenumber" name="673" href="#673">673</a>     addClusterOption.setArgName(<span class="jxr_string">"clusterName"</span>);
+<a class="jxr_linenumber" name="674" href="#674">674</a> 
+<a class="jxr_linenumber" name="675" href="#675">675</a>     Option activateClusterOption =
+<a class="jxr_linenumber" name="676" href="#676">676</a>         OptionBuilder.withLongOpt(activateCluster)
+<a class="jxr_linenumber" name="677" href="#677">677</a>                      .withDescription(<span class="jxr_string">"Enable/disable a cluster in distributed controller mode"</span>)
+<a class="jxr_linenumber" name="678" href="#678">678</a>                      .create();
+<a class="jxr_linenumber" name="679" href="#679">679</a>     activateClusterOption.setArgs(3);
+<a class="jxr_linenumber" name="680" href="#680">680</a>     activateClusterOption.setRequired(false);
+<a class="jxr_linenumber" name="681" href="#681">681</a>     activateClusterOption.setArgName(<span class="jxr_string">"clusterName grandCluster true/false"</span>);
+<a class="jxr_linenumber" name="682" href="#682">682</a> 
+<a class="jxr_linenumber" name="683" href="#683">683</a>     Option deleteClusterOption =
+<a class="jxr_linenumber" name="684" href="#684">684</a>         OptionBuilder.withLongOpt(dropCluster)
+<a class="jxr_linenumber" name="685" href="#685">685</a>                      .withDescription(<span class="jxr_string">"Delete a cluster"</span>)
+<a class="jxr_linenumber" name="686" href="#686">686</a>                      .create();
+<a class="jxr_linenumber" name="687" href="#687">687</a>     deleteClusterOption.setArgs(1);
+<a class="jxr_linenumber" name="688" href="#688">688</a>     deleteClusterOption.setRequired(false);
+<a class="jxr_linenumber" name="689" href="#689">689</a>     deleteClusterOption.setArgName(<span class="jxr_string">"clusterName"</span>);
+<a class="jxr_linenumber" name="690" href="#690">690</a> 
+<a class="jxr_linenumber" name="691" href="#691">691</a>     Option addInstanceOption =
+<a class="jxr_linenumber" name="692" href="#692">692</a>         OptionBuilder.withLongOpt(addInstance)
+<a class="jxr_linenumber" name="693" href="#693">693</a>                      .withDescription(<span class="jxr_string">"Add a new Instance to a cluster"</span>)
+<a class="jxr_linenumber" name="694" href="#694">694</a>                      .create();
+<a class="jxr_linenumber" name="695" href="#695">695</a>     addInstanceOption.setArgs(2);
+<a class="jxr_linenumber" name="696" href="#696">696</a>     addInstanceOption.setRequired(false);
+<a class="jxr_linenumber" name="697" href="#697">697</a>     addInstanceOption.setArgName(<span class="jxr_string">"clusterName InstanceAddress(host:port)"</span>);
+<a class="jxr_linenumber" name="698" href="#698">698</a> 
+<a class="jxr_linenumber" name="699" href="#699">699</a>     Option addResourceOption =
+<a class="jxr_linenumber" name="700" href="#700">700</a>         OptionBuilder.withLongOpt(addResource)
+<a class="jxr_linenumber" name="701" href="#701">701</a>                      .withDescription(<span class="jxr_string">"Add a resource to a cluster"</span>)
+<a class="jxr_linenumber" name="702" href="#702">702</a>                      .create();
+<a class="jxr_linenumber" name="703" href="#703">703</a>     addResourceOption.setArgs(4);
+<a class="jxr_linenumber" name="704" href="#704">704</a>     addResourceOption.setRequired(false);
+<a class="jxr_linenumber" name="705" href="#705">705</a>     addResourceOption.setArgName(<span class="jxr_string">"clusterName resourceName partitionNum stateModelRef &lt;-mode modeValue&gt;"</span>);
+<a class="jxr_linenumber" name="706" href="#706">706</a> 
+<a class="jxr_linenumber" name="707" href="#707">707</a>     Option expandResourceOption =
+<a class="jxr_linenumber" name="708" href="#708">708</a>         OptionBuilder.withLongOpt(expandResource)
+<a class="jxr_linenumber" name="709" href="#709">709</a>                      .withDescription(<span class="jxr_string">"Expand resource to additional nodes"</span>)
+<a class="jxr_linenumber" name="710" href="#710">710</a>                      .create();
+<a class="jxr_linenumber" name="711" href="#711">711</a>     expandResourceOption.setArgs(2);
+<a class="jxr_linenumber" name="712" href="#712">712</a>     expandResourceOption.setRequired(false);
+<a class="jxr_linenumber" name="713" href="#713">713</a>     expandResourceOption.setArgName(<span class="jxr_string">"clusterName resourceName"</span>);
+<a class="jxr_linenumber" name="714" href="#714">714</a> 
+<a class="jxr_linenumber" name="715" href="#715">715</a>     Option expandClusterOption =
+<a class="jxr_linenumber" name="716" href="#716">716</a>         OptionBuilder.withLongOpt(expandCluster)
+<a class="jxr_linenumber" name="717" href="#717">717</a>                      .withDescription(<span class="jxr_string">"Expand a cluster and all the resources"</span>)
+<a class="jxr_linenumber" name="718" href="#718">718</a>                      .create();
+<a class="jxr_linenumber" name="719" href="#719">719</a>     expandClusterOption.setArgs(1);
+<a class="jxr_linenumber" name="720" href="#720">720</a>     expandClusterOption.setRequired(false);
+<a class="jxr_linenumber" name="721" href="#721">721</a>     expandClusterOption.setArgName(<span class="jxr_string">"clusterName"</span>);
 <a class="jxr_linenumber" name="722" href="#722">722</a> 
-<a class="jxr_linenumber" name="723" href="#723">723</a>     List&lt;String&gt; statePriorityList = stateModDef.getStatesPriorityList();
-<a class="jxr_linenumber" name="724" href="#724">724</a> 
-<a class="jxr_linenumber" name="725" href="#725">725</a>     String masterStateValue = <strong class="jxr_keyword">null</strong>;
-<a class="jxr_linenumber" name="726" href="#726">726</a>     String slaveStateValue = <strong class="jxr_keyword">null</strong>;
-<a class="jxr_linenumber" name="727" href="#727">727</a>     replica--;
-<a class="jxr_linenumber" name="728" href="#728">728</a> 
-<a class="jxr_linenumber" name="729" href="#729">729</a>     <strong class="jxr_keyword">for</strong> (String state : statePriorityList)
-<a class="jxr_linenumber" name="730" href="#730">730</a>     {
-<a class="jxr_linenumber" name="731" href="#731">731</a>       String count = stateModDef.getNumInstancesPerState(state);
-<a class="jxr_linenumber" name="732" href="#732">732</a>       <strong class="jxr_keyword">if</strong> (count.equals(<span class="jxr_string">"1"</span>))
-<a class="jxr_linenumber" name="733" href="#733">733</a>       {
-<a class="jxr_linenumber" name="734" href="#734">734</a>         <strong class="jxr_keyword">if</strong> (masterStateValue != <strong class="jxr_keyword">null</strong>)
-<a class="jxr_linenumber" name="735" href="#735">735</a>         {
-<a class="jxr_linenumber" name="736" href="#736">736</a>           <strong class="jxr_keyword">throw</strong> <strong class="jxr_keyword">new</strong> <a href="../../../../org/apache/helix/HelixException.html">HelixException</a>(<span class="jxr_string">"Invalid or unsupported state model definition"</span>);
-<a class="jxr_linenumber" name="737" href="#737">737</a>         }
-<a class="jxr_linenumber" name="738" href="#738">738</a>         masterStateValue = state;
-<a class="jxr_linenumber" name="739" href="#739">739</a>       }
-<a class="jxr_linenumber" name="740" href="#740">740</a>       <strong class="jxr_keyword">else</strong> <strong class="jxr_keyword">if</strong> (count.equalsIgnoreCase(<span class="jxr_string">"R"</span>))
-<a class="jxr_linenumber" name="741" href="#741">741</a>       {
-<a class="jxr_linenumber" name="742" href="#742">742</a>         <strong class="jxr_keyword">if</strong> (slaveStateValue != <strong class="jxr_keyword">null</strong>)
-<a class="jxr_linenumber" name="743" href="#743">743</a>         {
-<a class="jxr_linenumber" name="744" href="#744">744</a>           <strong class="jxr_keyword">throw</strong> <strong class="jxr_keyword">new</strong> <a href="../../../../org/apache/helix/HelixException.html">HelixException</a>(<span class="jxr_string">"Invalid or unsupported state model definition"</span>);
-<a class="jxr_linenumber" name="745" href="#745">745</a>         }
-<a class="jxr_linenumber" name="746" href="#746">746</a>         slaveStateValue = state;
-<a class="jxr_linenumber" name="747" href="#747">747</a>       }
-<a class="jxr_linenumber" name="748" href="#748">748</a>       <strong class="jxr_keyword">else</strong> <strong class="jxr_keyword">if</strong> (count.equalsIgnoreCase(<span class="jxr_string">"N"</span>))
-<a class="jxr_linenumber" name="749" href="#749">749</a>       {
-<a class="jxr_linenumber" name="750" href="#750">750</a>         <strong class="jxr_keyword">if</strong> (!(masterStateValue == <strong class="jxr_keyword">null</strong> &amp;&amp; slaveStateValue == <strong class="jxr_keyword">null</strong>))
-<a class="jxr_linenumber" name="751" href="#751">751</a>         {
-<a class="jxr_linenumber" name="752" href="#752">752</a>           <strong class="jxr_keyword">throw</strong> <strong class="jxr_keyword">new</strong> <a href="../../../../org/apache/helix/HelixException.html">HelixException</a>(<span class="jxr_string">"Invalid or unsupported state model definition"</span>);
-<a class="jxr_linenumber" name="753" href="#753">753</a>         }
-<a class="jxr_linenumber" name="754" href="#754">754</a>         replica = InstanceNames.size() - 1;
-<a class="jxr_linenumber" name="755" href="#755">755</a>         masterStateValue = slaveStateValue = state;
-<a class="jxr_linenumber" name="756" href="#756">756</a>       }
-<a class="jxr_linenumber" name="757" href="#757">757</a>     }
-<a class="jxr_linenumber" name="758" href="#758">758</a>     <strong class="jxr_keyword">if</strong> (masterStateValue == <strong class="jxr_keyword">null</strong> &amp;&amp; slaveStateValue == <strong class="jxr_keyword">null</strong>)
-<a class="jxr_linenumber" name="759" href="#759">759</a>     {
-<a class="jxr_linenumber" name="760" href="#760">760</a>       <strong class="jxr_keyword">throw</strong> <strong class="jxr_keyword">new</strong> <a href="../../../../org/apache/helix/HelixException.html">HelixException</a>(<span class="jxr_string">"Invalid or unsupported state model definition"</span>);
-<a class="jxr_linenumber" name="761" href="#761">761</a>     }
+<a class="jxr_linenumber" name="723" href="#723">723</a>     Option resourceModeOption =
+<a class="jxr_linenumber" name="724" href="#724">724</a>         OptionBuilder.withLongOpt(mode)
+<a class="jxr_linenumber" name="725" href="#725">725</a>                      .withDescription(<span class="jxr_string">"Specify resource mode, used with addResourceGroup command"</span>)
+<a class="jxr_linenumber" name="726" href="#726">726</a>                      .create();
+<a class="jxr_linenumber" name="727" href="#727">727</a>     resourceModeOption.setArgs(1);
+<a class="jxr_linenumber" name="728" href="#728">728</a>     resourceModeOption.setRequired(false);
+<a class="jxr_linenumber" name="729" href="#729">729</a>     resourceModeOption.setArgName(<span class="jxr_string">"IdealState mode"</span>);
+<a class="jxr_linenumber" name="730" href="#730">730</a> 
+<a class="jxr_linenumber" name="731" href="#731">731</a>     Option resourceBucketSizeOption =
+<a class="jxr_linenumber" name="732" href="#732">732</a>         OptionBuilder.withLongOpt(bucketSize)
+<a class="jxr_linenumber" name="733" href="#733">733</a>                      .withDescription(<span class="jxr_string">"Specify size of a bucket, used with addResourceGroup command"</span>)
+<a class="jxr_linenumber" name="734" href="#734">734</a>                      .create();
+<a class="jxr_linenumber" name="735" href="#735">735</a>     resourceBucketSizeOption.setArgs(1);
+<a class="jxr_linenumber" name="736" href="#736">736</a>     resourceBucketSizeOption.setRequired(false);
+<a class="jxr_linenumber" name="737" href="#737">737</a>     resourceBucketSizeOption.setArgName(<span class="jxr_string">"Size of a bucket for a resource"</span>);
+<a class="jxr_linenumber" name="738" href="#738">738</a> 
+<a class="jxr_linenumber" name="739" href="#739">739</a>     Option resourceKeyOption =
+<a class="jxr_linenumber" name="740" href="#740">740</a>         OptionBuilder.withLongOpt(resourceKeyPrefix)
+<a class="jxr_linenumber" name="741" href="#741">741</a>                      .withDescription(<span class="jxr_string">"Specify resource key prefix, used with rebalance command"</span>)
+<a class="jxr_linenumber" name="742" href="#742">742</a>                      .create();
+<a class="jxr_linenumber" name="743" href="#743">743</a>     resourceKeyOption.setArgs(1);
+<a class="jxr_linenumber" name="744" href="#744">744</a>     resourceKeyOption.setRequired(false);
+<a class="jxr_linenumber" name="745" href="#745">745</a>     resourceKeyOption.setArgName(<span class="jxr_string">"Resource key prefix"</span>);
+<a class="jxr_linenumber" name="746" href="#746">746</a> 
+<a class="jxr_linenumber" name="747" href="#747">747</a>     Option addStateModelDefOption =
+<a class="jxr_linenumber" name="748" href="#748">748</a>         OptionBuilder.withLongOpt(addStateModelDef)
+<a class="jxr_linenumber" name="749" href="#749">749</a>                      .withDescription(<span class="jxr_string">"Add a State model to a cluster"</span>)
+<a class="jxr_linenumber" name="750" href="#750">750</a>                      .create();
+<a class="jxr_linenumber" name="751" href="#751">751</a>     addStateModelDefOption.setArgs(2);
+<a class="jxr_linenumber" name="752" href="#752">752</a>     addStateModelDefOption.setRequired(false);
+<a class="jxr_linenumber" name="753" href="#753">753</a>     addStateModelDefOption.setArgName(<span class="jxr_string">"clusterName &lt;filename&gt;"</span>);
+<a class="jxr_linenumber" name="754" href="#754">754</a> 
+<a class="jxr_linenumber" name="755" href="#755">755</a>     Option addIdealStateOption =
+<a class="jxr_linenumber" name="756" href="#756">756</a>         OptionBuilder.withLongOpt(addIdealState)
+<a class="jxr_linenumber" name="757" href="#757">757</a>                      .withDescription(<span class="jxr_string">"Add a State model to a cluster"</span>)
+<a class="jxr_linenumber" name="758" href="#758">758</a>                      .create();
+<a class="jxr_linenumber" name="759" href="#759">759</a>     addIdealStateOption.setArgs(3);
+<a class="jxr_linenumber" name="760" href="#760">760</a>     addIdealStateOption.setRequired(false);
+<a class="jxr_linenumber" name="761" href="#761">761</a>     addIdealStateOption.setArgName(<span class="jxr_string">"clusterName resourceName &lt;filename&gt;"</span>);
 <a class="jxr_linenumber" name="762" href="#762">762</a> 
-<a class="jxr_linenumber" name="763" href="#763">763</a>     <strong class="jxr_keyword">if</strong> (masterStateValue == <strong class="jxr_keyword">null</strong>)
-<a class="jxr_linenumber" name="764" href="#764">764</a>     {
-<a class="jxr_linenumber" name="765" href="#765">765</a>       masterStateValue = slaveStateValue;
-<a class="jxr_linenumber" name="766" href="#766">766</a>     }
-<a class="jxr_linenumber" name="767" href="#767">767</a>     <strong class="jxr_keyword">if</strong> (idealState.getIdealStateMode() != IdealStateModeProperty.AUTO_REBALANCE)
-<a class="jxr_linenumber" name="768" href="#768">768</a>     {
-<a class="jxr_linenumber" name="769" href="#769">769</a>       <a href="../../../../org/apache/helix/ZNRecord.html">ZNRecord</a> newIdealState =
-<a class="jxr_linenumber" name="770" href="#770">770</a>           IdealStateCalculatorForStorageNode.calculateIdealState(InstanceNames,
-<a class="jxr_linenumber" name="771" href="#771">771</a>                                                                  partitions,
-<a class="jxr_linenumber" name="772" href="#772">772</a>                                                                  replica,
-<a class="jxr_linenumber" name="773" href="#773">773</a>                                                                  keyPrefix,
-<a class="jxr_linenumber" name="774" href="#774">774</a>                                                                  masterStateValue,
-<a class="jxr_linenumber" name="775" href="#775">775</a>                                                                  slaveStateValue);
-<a class="jxr_linenumber" name="776" href="#776">776</a> 
-<a class="jxr_linenumber" name="777" href="#777">777</a>       <em class="jxr_comment">// for now keep mapField in AUTO mode and remove listField in CUSTOMIZED mode</em>
-<a class="jxr_linenumber" name="778" href="#778">778</a>       <strong class="jxr_keyword">if</strong> (idealState.getIdealStateMode() == IdealStateModeProperty.AUTO)
-<a class="jxr_linenumber" name="779" href="#779">779</a>       {
-<a class="jxr_linenumber" name="780" href="#780">780</a>         idealState.getRecord().setListFields(newIdealState.getListFields());
-<a class="jxr_linenumber" name="781" href="#781">781</a>         idealState.getRecord().setMapFields(newIdealState.getMapFields());
-<a class="jxr_linenumber" name="782" href="#782">782</a>       }
-<a class="jxr_linenumber" name="783" href="#783">783</a>       <strong class="jxr_keyword">if</strong> (idealState.getIdealStateMode() == IdealStateModeProperty.CUSTOMIZED)
-<a class="jxr_linenumber" name="784" href="#784">784</a>       {
-<a class="jxr_linenumber" name="785" href="#785">785</a>         idealState.getRecord().setMapFields(newIdealState.getMapFields());
-<a class="jxr_linenumber" name="786" href="#786">786</a>       }
-<a class="jxr_linenumber" name="787" href="#787">787</a>     }
-<a class="jxr_linenumber" name="788" href="#788">788</a>     <strong class="jxr_keyword">else</strong>
-<a class="jxr_linenumber" name="789" href="#789">789</a>     {
-<a class="jxr_linenumber" name="790" href="#790">790</a>       <strong class="jxr_keyword">for</strong> (<strong class="jxr_keyword">int</strong> i = 0; i &lt; partitions; i++)
-<a class="jxr_linenumber" name="791" href="#791">791</a>       {
-<a class="jxr_linenumber" name="792" href="#792">792</a>         String partitionName = keyPrefix + <span class="jxr_string">"_"</span> + i;
-<a class="jxr_linenumber" name="793" href="#793">793</a>         idealState.getRecord().setMapField(partitionName, <strong class="jxr_keyword">new</strong> HashMap&lt;String, String&gt;());
-<a class="jxr_linenumber" name="794" href="#794">794</a>         idealState.getRecord().setListField(partitionName, <strong class="jxr_keyword">new</strong> ArrayList&lt;String&gt;());
-<a class="jxr_linenumber" name="795" href="#795">795</a>       }
-<a class="jxr_linenumber" name="796" href="#796">796</a>     }
-<a class="jxr_linenumber" name="797" href="#797">797</a>     _admin.setResourceIdealState(clusterName, resourceName, idealState);
-<a class="jxr_linenumber" name="798" href="#798">798</a>   }
-<a class="jxr_linenumber" name="799" href="#799">799</a> 
-<a class="jxr_linenumber" name="800" href="#800">800</a>   <em class="jxr_javadoccomment">/**</em>
-<a class="jxr_linenumber" name="801" href="#801">801</a> <em class="jxr_javadoccomment">   * setConfig</em>
-<a class="jxr_linenumber" name="802" href="#802">802</a> <em class="jxr_javadoccomment">   * </em>
-<a class="jxr_linenumber" name="803" href="#803">803</a> <em class="jxr_javadoccomment">   * @param scopeStr</em>
-<a class="jxr_linenumber" name="804" href="#804">804</a> <em class="jxr_javadoccomment">   *          : scope=value, ... where scope=CLUSTER, RESOURCE, PARTICIPANT, PARTITION</em>
-<a class="jxr_linenumber" name="805" href="#805">805</a> <em class="jxr_javadoccomment">   * @param properitesStr</em>
-<a class="jxr_linenumber" name="806" href="#806">806</a> <em class="jxr_javadoccomment">   *          : key=value, ... which represents a Map&lt;String, String&gt;</em>
-<a class="jxr_linenumber" name="807" href="#807">807</a> <em class="jxr_javadoccomment">   */</em>
-<a class="jxr_linenumber" name="808" href="#808">808</a>   <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">void</strong> setConfig(String scopesStr, String propertiesStr)
-<a class="jxr_linenumber" name="809" href="#809">809</a>   {
-<a class="jxr_linenumber" name="810" href="#810">810</a>     <a href="../../../../org/apache/helix/ConfigScope.html">ConfigScope</a> scope = <strong class="jxr_keyword">new</strong> <a href="../../../../org/apache/helix/ConfigScopeBuilder.html">ConfigScopeBuilder</a>().build(scopesStr);
-<a class="jxr_linenumber" name="811" href="#811">811</a> 
-<a class="jxr_linenumber" name="812" href="#812">812</a>     <em class="jxr_comment">// parse properties</em>
-<a class="jxr_linenumber" name="813" href="#813">813</a>     String[] properties = propertiesStr.split(<span class="jxr_string">"[&#92;&#92;s,]"</span>);
-<a class="jxr_linenumber" name="814" href="#814">814</a>     Map&lt;String, String&gt; propertiesMap = <strong class="jxr_keyword">new</strong> TreeMap&lt;String, String&gt;();
-<a class="jxr_linenumber" name="815" href="#815">815</a>     <strong class="jxr_keyword">for</strong> (String property : properties)
-<a class="jxr_linenumber" name="816" href="#816">816</a>     {
-<a class="jxr_linenumber" name="817" href="#817">817</a>       <strong class="jxr_keyword">int</strong> idx = property.indexOf('=');
-<a class="jxr_linenumber" name="818" href="#818">818</a>       <strong class="jxr_keyword">if</strong> (idx == -1)
-<a class="jxr_linenumber" name="819" href="#819">819</a>       {
-<a class="jxr_linenumber" name="820" href="#820">820</a>         logger.error(<span class="jxr_string">"Invalid property string: "</span> + property);
-<a class="jxr_linenumber" name="821" href="#821">821</a>         <strong class="jxr_keyword">continue</strong>;
-<a class="jxr_linenumber" name="822" href="#822">822</a>       }
-<a class="jxr_linenumber" name="823" href="#823">823</a> 
-<a class="jxr_linenumber" name="824" href="#824">824</a>       String key = property.substring(0, idx);
-<a class="jxr_linenumber" name="825" href="#825">825</a>       String value = property.substring(idx + 1);
-<a class="jxr_linenumber" name="826" href="#826">826</a>       propertiesMap.put(key, value);
-<a class="jxr_linenumber" name="827" href="#827">827</a>     }
-<a class="jxr_linenumber" name="828" href="#828">828</a>     logger.debug(<span class="jxr_string">"propertiesMap: "</span> + propertiesMap);
-<a class="jxr_linenumber" name="829" href="#829">829</a> 
-<a class="jxr_linenumber" name="830" href="#830">830</a>     _admin.setConfig(scope, propertiesMap);
-<a class="jxr_linenumber" name="831" href="#831">831</a>   }
-<a class="jxr_linenumber" name="832" href="#832">832</a> 
-<a class="jxr_linenumber" name="833" href="#833">833</a>   <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">void</strong> removeConfig(String scopesStr, String keysStr)
-<a class="jxr_linenumber" name="834" href="#834">834</a>   {
-<a class="jxr_linenumber" name="835" href="#835">835</a>     <a href="../../../../org/apache/helix/ConfigScope.html">ConfigScope</a> scope = <strong class="jxr_keyword">new</strong> <a href="../../../../org/apache/helix/ConfigScopeBuilder.html">ConfigScopeBuilder</a>().build(scopesStr);
-<a class="jxr_linenumber" name="836" href="#836">836</a> 
-<a class="jxr_linenumber" name="837" href="#837">837</a>     <em class="jxr_comment">// parse keys</em>
-<a class="jxr_linenumber" name="838" href="#838">838</a>     String[] keys = keysStr.split(<span class="jxr_string">"[&#92;&#92;s,]"</span>);
-<a class="jxr_linenumber" name="839" href="#839">839</a>     Set&lt;String&gt; keysSet = <strong class="jxr_keyword">new</strong> HashSet&lt;String&gt;(Arrays.asList(keys));
-<a class="jxr_linenumber" name="840" href="#840">840</a> 
-<a class="jxr_linenumber" name="841" href="#841">841</a>     _admin.removeConfig(scope, keysSet);
-<a class="jxr_linenumber" name="842" href="#842">842</a>   }
-<a class="jxr_linenumber" name="843" href="#843">843</a> 
-<a class="jxr_linenumber" name="844" href="#844">844</a>   <strong class="jxr_keyword">public</strong> String getConfig(String scopesStr, String keysStr)
-<a class="jxr_linenumber" name="845" href="#845">845</a>   {
-<a class="jxr_linenumber" name="846" href="#846">846</a>     <a href="../../../../org/apache/helix/ConfigScope.html">ConfigScope</a> scope = <strong class="jxr_keyword">new</strong> <a href="../../../../org/apache/helix/ConfigScopeBuilder.html">ConfigScopeBuilder</a>().build(scopesStr);
-<a class="jxr_linenumber" name="847" href="#847">847</a> 
-<a class="jxr_linenumber" name="848" href="#848">848</a>     <em class="jxr_comment">// parse keys</em>
-<a class="jxr_linenumber" name="849" href="#849">849</a>     String[] keys = keysStr.split(<span class="jxr_string">"[&#92;&#92;s,]"</span>);
-<a class="jxr_linenumber" name="850" href="#850">850</a>     Set&lt;String&gt; keysSet = <strong class="jxr_keyword">new</strong> HashSet&lt;String&gt;(Arrays.asList(keys));
-<a class="jxr_linenumber" name="851" href="#851">851</a> 
-<a class="jxr_linenumber" name="852" href="#852">852</a>     Map&lt;String, String&gt; propertiesMap = _admin.getConfig(scope, keysSet);
-<a class="jxr_linenumber" name="853" href="#853">853</a>     StringBuffer sb = <strong class="jxr_keyword">new</strong> StringBuffer();
-<a class="jxr_linenumber" name="854" href="#854">854</a>     <strong class="jxr_keyword">for</strong> (String key : keys)
-<a class="jxr_linenumber" name="855" href="#855">855</a>     {
-<a class="jxr_linenumber" name="856" href="#856">856</a>       <strong class="jxr_keyword">if</strong> (propertiesMap.containsKey(key))
-<a class="jxr_linenumber" name="857" href="#857">857</a>       {
-<a class="jxr_linenumber" name="858" href="#858">858</a>         <strong class="jxr_keyword">if</strong> (sb.length() &gt; 0)
-<a class="jxr_linenumber" name="859" href="#859">859</a>         {
-<a class="jxr_linenumber" name="860" href="#860">860</a>           sb.append(<span class="jxr_string">","</span> + key + <span class="jxr_string">"="</span> + propertiesMap.get(key));
-<a class="jxr_linenumber" name="861" href="#861">861</a>         }
-<a class="jxr_linenumber" name="862" href="#862">862</a>         <strong class="jxr_keyword">else</strong>
-<a class="jxr_linenumber" name="863" href="#863">863</a>         {
-<a class="jxr_linenumber" name="864" href="#864">864</a>           <em class="jxr_comment">// sb.length()==0 means the first key=value</em>
-<a class="jxr_linenumber" name="865" href="#865">865</a>           sb.append(key + <span class="jxr_string">"="</span> + propertiesMap.get(key));
-<a class="jxr_linenumber" name="866" href="#866">866</a>         }
-<a class="jxr_linenumber" name="867" href="#867">867</a>       }
-<a class="jxr_linenumber" name="868" href="#868">868</a>       <strong class="jxr_keyword">else</strong>
-<a class="jxr_linenumber" name="869" href="#869">869</a>       {
-<a class="jxr_linenumber" name="870" href="#870">870</a>         logger.error(<span class="jxr_string">"Config doesn't exist for key: "</span> + key);
-<a class="jxr_linenumber" name="871" href="#871">871</a>       }
-<a class="jxr_linenumber" name="872" href="#872">872</a>     }
-<a class="jxr_linenumber" name="873" href="#873">873</a> 
-<a class="jxr_linenumber" name="874" href="#874">874</a>     System.out.println(sb.toString());
-<a class="jxr_linenumber" name="875" href="#875">875</a>     <strong class="jxr_keyword">return</strong> sb.toString();
-<a class="jxr_linenumber" name="876" href="#876">876</a>   }
-<a class="jxr_linenumber" name="877" href="#877">877</a> 
-<a class="jxr_linenumber" name="878" href="#878">878</a>   <em class="jxr_javadoccomment">/**</em>
-<a class="jxr_linenumber" name="879" href="#879">879</a> <em class="jxr_javadoccomment">   * Sets up a cluster with 6 Instances[localhost:8900 to localhost:8905], 1</em>
-<a class="jxr_linenumber" name="880" href="#880">880</a> <em class="jxr_javadoccomment">   * resource[EspressoDB] with a replication factor of 3</em>
-<a class="jxr_linenumber" name="881" href="#881">881</a> <em class="jxr_javadoccomment">   * </em>
-<a class="jxr_linenumber" name="882" href="#882">882</a> <em class="jxr_javadoccomment">   * @param clusterName</em>
-<a class="jxr_linenumber" name="883" href="#883">883</a> <em class="jxr_javadoccomment">   */</em>
-<a class="jxr_linenumber" name="884" href="#884">884</a>   <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">void</strong> setupTestCluster(String clusterName)
-<a class="jxr_linenumber" name="885" href="#885">885</a>   {
-<a class="jxr_linenumber" name="886" href="#886">886</a>     addCluster(clusterName, <strong class="jxr_keyword">true</strong>);
-<a class="jxr_linenumber" name="887" href="#887">887</a>     String storageInstanceInfoArray[] = <strong class="jxr_keyword">new</strong> String[6];
-<a class="jxr_linenumber" name="888" href="#888">888</a>     <strong class="jxr_keyword">for</strong> (<strong class="jxr_keyword">int</strong> i = 0; i &lt; storageInstanceInfoArray.length; i++)
-<a class="jxr_linenumber" name="889" href="#889">889</a>     {
-<a class="jxr_linenumber" name="890" href="#890">890</a>       storageInstanceInfoArray[i] = <span class="jxr_string">"localhost:"</span> + (8900 + i);
-<a class="jxr_linenumber" name="891" href="#891">891</a>     }
-<a class="jxr_linenumber" name="892" href="#892">892</a>     addInstancesToCluster(clusterName, storageInstanceInfoArray);
-<a class="jxr_linenumber" name="893" href="#893">893</a>     addResourceToCluster(clusterName, <span class="jxr_string">"TestDB"</span>, 10, <span class="jxr_string">"MasterSlave"</span>);
-<a class="jxr_linenumber" name="894" href="#894">894</a>     rebalanceStorageCluster(clusterName, <span class="jxr_string">"TestDB"</span>, 3);
-<a class="jxr_linenumber" name="895" href="#895">895</a>   }
-<a class="jxr_linenumber" name="896" href="#896">896</a> 
-<a class="jxr_linenumber" name="897" href="#897">897</a>   <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">static</strong> <strong class="jxr_keyword">void</strong> printUsage(Options cliOptions)
-<a class="jxr_linenumber" name="898" href="#898">898</a>   {
-<a class="jxr_linenumber" name="899" href="#899">899</a>     HelpFormatter helpFormatter = <strong class="jxr_keyword">new</strong> HelpFormatter();
-<a class="jxr_linenumber" name="900" href="#900">900</a>     helpFormatter.setWidth(1000);
-<a class="jxr_linenumber" name="901" href="#901">901</a>     helpFormatter.printHelp(<span class="jxr_string">"java "</span> + ClusterSetup.<strong class="jxr_keyword">class</strong>.getName(), cliOptions);
-<a class="jxr_linenumber" name="902" href="#902">902</a>   }
-<a class="jxr_linenumber" name="903" href="#903">903</a> 
-<a class="jxr_linenumber" name="904" href="#904">904</a>   @SuppressWarnings(<span class="jxr_string">"static-access"</span>)
-<a class="jxr_linenumber" name="905" href="#905">905</a>   <strong class="jxr_keyword">private</strong> <strong class="jxr_keyword">static</strong> Options constructCommandLineOptions()
-<a class="jxr_linenumber" name="906" href="#906">906</a>   {
-<a class="jxr_linenumber" name="907" href="#907">907</a>     Option helpOption =
-<a class="jxr_linenumber" name="908" href="#908">908</a>         OptionBuilder.withLongOpt(help)
-<a class="jxr_linenumber" name="909" href="#909">909</a>                      .withDescription(<span class="jxr_string">"Prints command-line options info"</span>)
+<a class="jxr_linenumber" name="763" href="#763">763</a>     Option dropInstanceOption =
+<a class="jxr_linenumber" name="764" href="#764">764</a>         OptionBuilder.withLongOpt(dropInstance)
+<a class="jxr_linenumber" name="765" href="#765">765</a>                      .withDescription(<span class="jxr_string">"Drop an existing Instance from a cluster"</span>)
+<a class="jxr_linenumber" name="766" href="#766">766</a>                      .create();
+<a class="jxr_linenumber" name="767" href="#767">767</a>     dropInstanceOption.setArgs(2);
+<a class="jxr_linenumber" name="768" href="#768">768</a>     dropInstanceOption.setRequired(false);
+<a class="jxr_linenumber" name="769" href="#769">769</a>     dropInstanceOption.setArgName(<span class="jxr_string">"clusterName InstanceAddress(host:port)"</span>);
+<a class="jxr_linenumber" name="770" href="#770">770</a> 
+<a class="jxr_linenumber" name="771" href="#771">771</a>     Option swapInstanceOption =
+<a class="jxr_linenumber" name="772" href="#772">772</a>         OptionBuilder.withLongOpt(swapInstance)
+<a class="jxr_linenumber" name="773" href="#773">773</a>                      .withDescription(<span class="jxr_string">"Swap an old instance from a cluster with a new instance"</span>)
+<a class="jxr_linenumber" name="774" href="#774">774</a>                      .create();
+<a class="jxr_linenumber" name="775" href="#775">775</a>     swapInstanceOption.setArgs(3);
+<a class="jxr_linenumber" name="776" href="#776">776</a>     swapInstanceOption.setRequired(false);
+<a class="jxr_linenumber" name="777" href="#777">777</a>     swapInstanceOption.setArgName(<span class="jxr_string">"clusterName oldInstance newInstance"</span>);
+<a class="jxr_linenumber" name="778" href="#778">778</a> 
+<a class="jxr_linenumber" name="779" href="#779">779</a>     Option dropResourceOption =
+<a class="jxr_linenumber" name="780" href="#780">780</a>         OptionBuilder.withLongOpt(dropResource)
+<a class="jxr_linenumber" name="781" href="#781">781</a>                      .withDescription(<span class="jxr_string">"Drop an existing resource from a cluster"</span>)
+<a class="jxr_linenumber" name="782" href="#782">782</a>                      .create();
+<a class="jxr_linenumber" name="783" href="#783">783</a>     dropResourceOption.setArgs(2);
+<a class="jxr_linenumber" name="784" href="#784">784</a>     dropResourceOption.setRequired(false);
+<a class="jxr_linenumber" name="785" href="#785">785</a>     dropResourceOption.setArgName(<span class="jxr_string">"clusterName resourceName"</span>);
+<a class="jxr_linenumber" name="786" href="#786">786</a> 
+<a class="jxr_linenumber" name="787" href="#787">787</a>     Option rebalanceOption =
+<a class="jxr_linenumber" name="788" href="#788">788</a>         OptionBuilder.withLongOpt(rebalance)
+<a class="jxr_linenumber" name="789" href="#789">789</a>                      .withDescription(<span class="jxr_string">"Rebalance a resource in a cluster"</span>)
+<a class="jxr_linenumber" name="790" href="#790">790</a>                      .create();
+<a class="jxr_linenumber" name="791" href="#791">791</a>     rebalanceOption.setArgs(3);
+<a class="jxr_linenumber" name="792" href="#792">792</a>     rebalanceOption.setRequired(false);
+<a class="jxr_linenumber" name="793" href="#793">793</a>     rebalanceOption.setArgName(<span class="jxr_string">"clusterName resourceName replicas"</span>);
+<a class="jxr_linenumber" name="794" href="#794">794</a> 
+<a class="jxr_linenumber" name="795" href="#795">795</a>     Option instanceInfoOption =
+<a class="jxr_linenumber" name="796" href="#796">796</a>         OptionBuilder.withLongOpt(listInstanceInfo)
+<a class="jxr_linenumber" name="797" href="#797">797</a>                      .withDescription(<span class="jxr_string">"Query info of a Instance in a cluster"</span>)
+<a class="jxr_linenumber" name="798" href="#798">798</a>                      .create();
+<a class="jxr_linenumber" name="799" href="#799">799</a>     instanceInfoOption.setArgs(2);
+<a class="jxr_linenumber" name="800" href="#800">800</a>     instanceInfoOption.setRequired(false);
+<a class="jxr_linenumber" name="801" href="#801">801</a>     instanceInfoOption.setArgName(<span class="jxr_string">"clusterName InstanceName"</span>);
+<a class="jxr_linenumber" name="802" href="#802">802</a> 
+<a class="jxr_linenumber" name="803" href="#803">803</a>     Option clusterInfoOption =
+<a class="jxr_linenumber" name="804" href="#804">804</a>         OptionBuilder.withLongOpt(listClusterInfo)
+<a class="jxr_linenumber" name="805" href="#805">805</a>                      .withDescription(<span class="jxr_string">"Query info of a cluster"</span>)
+<a class="jxr_linenumber" name="806" href="#806">806</a>                      .create();
+<a class="jxr_linenumber" name="807" href="#807">807</a>     clusterInfoOption.setArgs(1);
+<a class="jxr_linenumber" name="808" href="#808">808</a>     clusterInfoOption.setRequired(false);
+<a class="jxr_linenumber" name="809" href="#809">809</a>     clusterInfoOption.setArgName(<span class="jxr_string">"clusterName"</span>);
+<a class="jxr_linenumber" name="810" href="#810">810</a> 
+<a class="jxr_linenumber" name="811" href="#811">811</a>     Option resourceInfoOption =
+<a class="jxr_linenumber" name="812" href="#812">812</a>         OptionBuilder.withLongOpt(listResourceInfo)
+<a class="jxr_linenumber" name="813" href="#813">813</a>                      .withDescription(<span class="jxr_string">"Query info of a resource"</span>)
+<a class="jxr_linenumber" name="814" href="#814">814</a>                      .create();
+<a class="jxr_linenumber" name="815" href="#815">815</a>     resourceInfoOption.setArgs(2);
+<a class="jxr_linenumber" name="816" href="#816">816</a>     resourceInfoOption.setRequired(false);
+<a class="jxr_linenumber" name="817" href="#817">817</a>     resourceInfoOption.setArgName(<span class="jxr_string">"clusterName resourceName"</span>);
+<a class="jxr_linenumber" name="818" href="#818">818</a> 
+<a class="jxr_linenumber" name="819" href="#819">819</a>     Option addResourcePropertyOption =
+<a class="jxr_linenumber" name="820" href="#820">820</a>         OptionBuilder.withLongOpt(addResourceProperty)
+<a class="jxr_linenumber" name="821" href="#821">821</a>                      .withDescription(<span class="jxr_string">"Add a resource property"</span>)
+<a class="jxr_linenumber" name="822" href="#822">822</a>                      .create();
+<a class="jxr_linenumber" name="823" href="#823">823</a>     addResourcePropertyOption.setArgs(4);
+<a class="jxr_linenumber" name="824" href="#824">824</a>     addResourcePropertyOption.setRequired(false);
+<a class="jxr_linenumber" name="825" href="#825">825</a>     addResourcePropertyOption.setArgName(<span class="jxr_string">"clusterName resourceName propertyName propertyValue"</span>);
+<a class="jxr_linenumber" name="826" href="#826">826</a> 
+<a class="jxr_linenumber" name="827" href="#827">827</a>     Option removeResourcePropertyOption =
+<a class="jxr_linenumber" name="828" href="#828">828</a>         OptionBuilder.withLongOpt(removeResourceProperty)
+<a class="jxr_linenumber" name="829" href="#829">829</a>                      .withDescription(<span class="jxr_string">"Remove a resource property"</span>)
+<a class="jxr_linenumber" name="830" href="#830">830</a>                      .create();
+<a class="jxr_linenumber" name="831" href="#831">831</a>     removeResourcePropertyOption.setArgs(3);
+<a class="jxr_linenumber" name="832" href="#832">832</a>     removeResourcePropertyOption.setRequired(false);
+<a class="jxr_linenumber" name="833" href="#833">833</a>     removeResourcePropertyOption.setArgName(<span class="jxr_string">"clusterName resourceName propertyName"</span>);
+<a class="jxr_linenumber" name="834" href="#834">834</a> 
+<a class="jxr_linenumber" name="835" href="#835">835</a>     Option partitionInfoOption =
+<a class="jxr_linenumber" name="836" href="#836">836</a>         OptionBuilder.withLongOpt(listPartitionInfo)
+<a class="jxr_linenumber" name="837" href="#837">837</a>                      .withDescription(<span class="jxr_string">"Query info of a partition"</span>)
+<a class="jxr_linenumber" name="838" href="#838">838</a>                      .create();
+<a class="jxr_linenumber" name="839" href="#839">839</a>     partitionInfoOption.setArgs(3);
+<a class="jxr_linenumber" name="840" href="#840">840</a>     partitionInfoOption.setRequired(false);
+<a class="jxr_linenumber" name="841" href="#841">841</a>     partitionInfoOption.setArgName(<span class="jxr_string">"clusterName resourceName partitionName"</span>);
+<a class="jxr_linenumber" name="842" href="#842">842</a> 
+<a class="jxr_linenumber" name="843" href="#843">843</a>     Option enableInstanceOption =

[... 1679 lines stripped ...]


Mime
View raw message