View Javadoc

1   package org.apache.helix;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.io.IOException;
23  import java.util.List;
24  import java.util.Map;
25  import java.util.Set;
26  
27  import org.apache.helix.model.*;
28  import org.apache.helix.model.ClusterConstraints.ConstraintType;
29  import org.apache.helix.model.HelixConfigScope.ConfigScopeProperty;
30  
31  
32  public interface HelixAdmin
33  {
34    /**
35     * Get a list of clusters under "/"
36     * 
37     * @return
38     */
39    List<String> getClusters();
40  
41    /**
42     * Get a list of instances under a cluster
43     * 
44     * @param clusterName
45     * @return
46     */
47    List<String> getInstancesInCluster(String clusterName);
48  
49    /**
50     * Get instance configs
51     * 
52     * @param clusterName
53     * @param instanceName
54     * @return
55     */
56    InstanceConfig getInstanceConfig(String clusterName, String instanceName);
57  
58    /**
59     * Get a list of resources in a cluster
60     * 
61     * @param clusterName
62     * @return
63     */
64    List<String> getResourcesInCluster(String clusterName);
65  
66    /**
67     * Add a cluster
68     * 
69     * @param clusterName
70     * @return true if successfully created, or if cluster already exists
71       */
72    boolean addCluster(String clusterName);
73    /**
74     * Add a cluster
75     * 
76     * @param clusterName
77     * @param recreateIfExists If the cluster already exists, it will delete it and recreate
78     * @return true if successfully created, or if cluster already exists
79     */
80    boolean addCluster(String clusterName, boolean recreateIfExists);
81  
82    /**
83     * Add a cluster and also add this cluster as a resource group in the super cluster
84     * 
85     * @param clusterName
86     * @param grandCluster
87     */
88    void addClusterToGrandCluster(String clusterName, String grandCluster);
89  
90    /**
91     * Add a resource to a cluster, using the default ideal state mode AUTO
92     * 
93     * @param clusterName
94     * @param resourceName
95     * @param numResources
96     * @param stateModelRef
97     */
98    void addResource(String clusterName,
99                     String resourceName,
100                    int numResources,
101                    String stateModelRef);
102   /**
103    * 
104    * @param clusterName
105    * @param resourceName
106    * @param idealstate
107    */
108   void addResource(String clusterName,
109                    String resourceName,
110                    IdealState idealstate);
111 
112   /**
113    * Add a resource to a cluster
114    * 
115    * @param clusterName
116    * @param resourceName
117    * @param numResources
118    * @param stateModelRef
119    * @param idealStateMode
120    */
121   void addResource(String clusterName,
122                    String resourceName,
123                    int numResources,
124                    String stateModelRef,
125                    String idealStateMode);
126 
127   /**
128    * Add a resource to a cluster, using a bucket size > 1
129    * 
130    * @param clusterName
131    * @param resourceName
132    * @param numResources
133    * @param stateModelRef
134    * @param idealStateMode
135    * @param bucketSize
136    */
137   void addResource(String clusterName,
138                    String resourceName,
139                    int numResources,
140                    String stateModelRef,
141                    String idealStateMode,
142                    int bucketSize);
143   
144   /**
145    * Add a resource to a cluster, using a bucket size > 1
146    * 
147    * @param clusterName
148    * @param resourceName
149    * @param numResources
150    * @param stateModelRef
151    * @param idealStateMode
152    * @param bucketSize
153    * @param maxPartitionsPerInstance
154    */
155   void addResource(String clusterName,
156                    String resourceName,
157                    int numResources,
158                    String stateModelRef,
159                    String idealStateMode,
160                    int bucketSize,
161                    int maxPartitionsPerInstance);
162   
163   /**
164    * Add an instance to a cluster
165    * 
166    * @param clusterName
167    * @param instanceConfig
168    */
169   void addInstance(String clusterName, InstanceConfig instanceConfig);
170 
171   /**
172    * Drop an instance from a cluster
173    * 
174    * @param clusterName
175    * @param instanceConfig
176    */
177   void dropInstance(String clusterName, InstanceConfig instanceConfig);
178 
179   /**
180    * Get ideal state for a resource
181    * 
182    * @param clusterName
183    * @param resourceName
184    * @return
185    */
186   IdealState getResourceIdealState(String clusterName, String resourceName);
187 
188   /**
189    * Set ideal state for a resource
190    * 
191    * @param clusterName
192    * @param resourceName
193    * @param idealState
194    */
195   void setResourceIdealState(String clusterName,
196                              String resourceName,
197                              IdealState idealState);
198 
199   /**
200    * Disable or enable an instance
201    * 
202    * @param clusterName
203    * @param instanceName
204    * @param enabled
205    */
206   void enableInstance(String clusterName, String instanceName, boolean enabled);
207 
208   /**
209    * Disable or enable a list of partitions on an instance
210    * 
211    * @param enabled
212    * @param clusterName
213    * @param instanceName
214    * @param resourceName
215    * @param partitionNames
216    */
217   void enablePartition(boolean enabled,
218                        String clusterName,
219                        String instanceName,
220                        String resourceName,
221                        List<String> partitionNames);
222 
223   /**
224    * Disable or enable a cluster
225    * 
226    * @param clusterName
227    * @param enabled
228    */
229   void enableCluster(String clusterName, boolean enabled);
230 
231   /**
232    * Reset a list of partitions in error state for an instance
233    * 
234    * The partitions are assume to be in error state and reset will bring them from error
235    * to initial state. An error to initial state transition is required for reset.
236    * 
237    * @param clusterName
238    * @param instanceName
239    * @param resourceName
240    * @param partitionNames
241    */
242   void resetPartition(String clusterName,
243                       String instanceName,
244                       String resourceName,
245                       List<String> partitionNames);
246 
247   /**
248    * Reset all the partitions in error state for a list of instances
249    * 
250    * @param clusterName
251    * @param instanceNames
252    */
253   void resetInstance(String clusterName, List<String> instanceNames);
254 
255   /**
256    * Reset all partitions in error state for a list of resources
257    * 
258    * @param clusterName
259    * @param resourceNames
260    */
261   void resetResource(String clusterName, List<String> resourceNames);
262 
263   /**
264    * Add a state model definition
265    * 
266    * @param clusterName
267    * @param stateModelDef
268    * @param record
269    */
270   void addStateModelDef(String clusterName,
271                         String stateModelDef,
272                         StateModelDefinition record);
273 
274   /**
275    * Drop a resource from a cluster
276    * 
277    * @param clusterName
278    * @param resourceName
279    */
280   void dropResource(String clusterName, String resourceName);
281 
282   /**
283    * Add a statistics to a cluster
284    * 
285    * @param clusterName
286    * @param statName
287    */
288   void addStat(String clusterName, String statName);
289 
290   /**
291    * Add an alert to a cluster
292    * 
293    * @param clusterName
294    * @param alertName
295    */
296   void addAlert(String clusterName, String alertName);
297 
298   /**
299    * Drop a statistics from a cluster
300    * 
301    * @param clusterName
302    * @param statName
303    */
304   void dropStat(String clusterName, String statName);
305 
306   /**
307    * Drop an alert from a cluster
308    * 
309    * @param clusterName
310    * @param alertName
311    */
312   void dropAlert(String clusterName, String alertName);
313 
314   /**
315    * Get a list of state model definitions in a cluster
316    * 
317    * @param clusterName
318    * @return
319    */
320   List<String> getStateModelDefs(String clusterName);
321 
322   /**
323    * Get a state model definition in a cluster
324    * 
325    * @param clusterName
326    * @param stateModelName
327    * @return
328    */
329   StateModelDefinition getStateModelDef(String clusterName, String stateModelName);
330 
331   /**
332    * Get external view for a resource
333    * 
334    * @param clusterName
335    * @param resourceName
336    * @return
337    */
338   ExternalView getResourceExternalView(String clusterName, String resourceName);
339 
340   /**
341    * Drop a cluster
342    * 
343    * @param clusterName
344    */
345   void dropCluster(String clusterName);
346 
347   /**
348    * Set configuration values
349    * 
350    * @param scope
351    * @param properties
352    */
353   void setConfig(HelixConfigScope scope, Map<String, String> properties);
354 
355   /**
356    * Remove configuration values
357    * 
358    * @param scope
359    * @param keys
360    */
361   void removeConfig(HelixConfigScope scope, List<String> keys);
362 
363   /**
364    * Get configuration values
365    * 
366    * @param scope
367    * @param keys
368    * @return
369    */
370   Map<String, String> getConfig(HelixConfigScope scope, List<String> keys);
371 
372   /**
373    * Get configuration keys
374    * 
375    * @param scope
376    * @return
377    */
378   List<String> getConfigKeys(HelixConfigScope scope);
379 
380   /**
381    * Rebalance a resource in cluster
382    * 
383    * @param clusterName
384    * @param resourceName
385    * @param replica
386    */
387   void rebalance(String clusterName, String resourceName, int replica);
388 
389   /**
390    * Add ideal state using a json format file
391    * 
392    * @param clusterName
393    * @param resourceName
394    * @param idealStateFile
395    * @throws IOException
396    */
397   void addIdealState(String clusterName, String resourceName, String idealStateFile) throws IOException;
398 
399   /**
400    * Add state model definition using a json format file
401    * 
402    * @param clusterName
403    * @param stateModelDefName
404    * @param stateModelDefFile
405    * @throws IOException
406    */
407   void addStateModelDef(String clusterName,
408                         String stateModelDefName,
409                         String stateModelDefFile) throws IOException;
410 
411   /**
412    * Add a constraint item; create if not exist
413    * 
414    * @param clusterName
415    * @param constraintType
416    * @param constraintId
417    * @param constraintItem
418    */
419   void setConstraint(String clusterName,
420                      ConstraintType constraintType,
421                      String constraintId,
422                      ConstraintItem constraintItem);
423 
424   /**
425    * Remove a constraint item
426    * 
427    * @param clusterName
428    * @param constraintType
429    * @param constraintId
430    */
431   void removeConstraint(String clusterName, 
432                         ConstraintType constraintType, 
433                         String constraintId);
434   
435   /**
436    * Get all constraints for a type
437    * 
438    * @param clusterName
439    * @param constraintType
440    * @return
441    */
442   ClusterConstraints getConstraints(String clusterName,
443                                     ConstraintType constraintType);
444   
445   /**
446    * 
447    * @param clusterName
448    * @param currentIdealState
449    * @param instanceNames
450    * @return
451    */
452   void rebalance(String clusterName, 
453                        IdealState currentIdealState,
454                        List<String> instanceNames);
455   /**
456    * 
457    * @param clusterName
458    * @param resourceName
459    * @param replica
460    * @param instances
461    */
462   void rebalance(String clusterName, String resourceName, int replica,
463       List<String> instances);
464   /**
465    * 
466    * @param clusterName
467    * @param resourceName
468    * @param replica
469    * @param keyPrefix
470    */
471   void rebalance(String clusterName, String resourceName, int replica,
472       String keyPrefix, String group);
473   /**
474    * 
475    * @param clusterName
476    * @param tag
477    */
478   List<String> getInstancesInClusterWithTag(String clusterName, String tag);
479   
480   /**
481    * 
482    * @param clusterName
483    * @param instanceNames
484    * @param tag
485    * @return
486    */
487   void addInstanceTag(String clusterName, String instanceName, String tag);
488   
489   /**
490    * 
491    * @param clusterName
492    * @param instanceNames
493    * @param tag
494    * @return
495    */
496   void removeInstanceTag(String clusterName, String instanceName, String tag);
497   
498   /**
499    * Release resources 
500    */
501   void close();
502 }