public class

IdealState

extends HelixProperty
java.lang.Object
   ↳ org.apache.helix.HelixProperty
     ↳ org.apache.helix.model.IdealState

Class Overview

The ideal states of all partitions in a resource

Summary

Nested Classes
enum IdealState.IdealStateModeProperty Deprecated. 
enum IdealState.IdealStateProperty Properties that are persisted and are queryable for an ideal state  
enum IdealState.RebalanceMode The mode used for rebalance. 
Constants
String QUERY_LIST
[Expand]
Inherited Fields
From class org.apache.helix.HelixProperty
Public Constructors
IdealState(String resourceName)
Instantiate an ideal state for a resource
IdealState(ResourceId resourceId)
Instantiate an ideal state for a resource
IdealState(ZNRecord record)
Instantiate an ideal state from a record
Public Methods
IdealState.IdealStateModeProperty getIdealStateMode()
Get the rebalancing mode on this resource
String getInstanceGroupTag()
Check for a tag that will restrict assignment to instances with a matching tag
Set<String> getInstanceSet(String partitionName)
Get the instances who host replicas of a partition
Map<StringString> getInstanceStateMap(String partitionName)
Get the current mapping of a partition
int getMaxPartitionsPerInstance()
Get the maximum number of partitions an instance can serve
int getNumPartitions()
Get the number of partitions of this resource
Set<ParticipantId> getParticipantSet(PartitionId partitionId)
Get the participants who host replicas of a partition
Map<ParticipantIdState> getParticipantStateMap(PartitionId partitionId)
Get the current mapping of a partition
Set<PartitionId> getPartitionIdSet()
Get all of the partitions
Set<String> getPartitionSet()
Get all of the partitions
List<ParticipantId> getPreferenceList(PartitionId partitionId)
Get the preference list of a partition
List<String> getPreferenceList(String partitionName)
Get the preference list of a partition
IdealState.RebalanceMode getRebalanceMode()
Get the rebalancing mode on this resource
int getRebalanceTimerPeriod()
Set the frequency with which to rebalance
String getRebalancerClassName()
Get the name of the user-defined rebalancer associated with this resource
RebalancerRef getRebalancerRef()
Get a reference to the user-defined rebalancer associated with this resource(if any)
String getReplicas()
Get the number of replicas for each partition of this resource
ResourceId getResourceId()
Get the associated resource
String getResourceName()
Get the associated resource
StateModelDefId getStateModelDefId()
Get the state model associated with this resource
String getStateModelDefRef()
Get the state model associated with this resource
StateModelFactoryId getStateModelFactoryId()
Get the state model factory associated with this resource
String getStateModelFactoryName()
Get the state model factory associated with this resource
boolean isValid()
Get property validity
static Map<ParticipantIdState> participantStateMapFromStringMap(Map<StringString> rawMap)
Convert a partition mapping as strings into a participant state map
static Map<? extends PartitionIdMap<ParticipantIdState>> participantStateMapsFromStringMaps(Map<StringMap<StringString>> rawMaps)
Convert a full state mapping as strings into participant state maps
static List<ParticipantId> preferenceListFromStringList(List<String> rawPreferenceList)
Convert a preference list of strings into a preference list of participants
static Map<? extends PartitionIdList<ParticipantId>> preferenceListsFromStringLists(Map<StringList<String>> rawPreferenceLists)
Convert preference lists of strings into preference lists of participants
IdealState.RebalanceMode rebalanceModeFromString(String mode, IdealState.RebalanceMode defaultMode)
Parse a rebalance mode from a string.
void setIdealStateMode(String mode)
Get the rebalance mode of the ideal state
void setInstanceGroupTag(String groupTag)
Set a tag to check to enforce assignment to certain instances
void setInstanceStateMap(String partitionName, Map<StringString> instanceStateMap)
Set the current mapping of a partition
void setMaxPartitionsPerInstance(int max)
Set the maximum number of partitions of this resource that an instance can serve
void setNumPartitions(int numPartitions)
Set the number of partitions of this resource
void setParticipantStateMap(PartitionId partitionId, Map<ParticipantIdState> participantStateMap)
Set the current mapping of a partition
void setPartitionState(PartitionId partitionId, ParticipantId participantId, State state)
Set the preferred participant placement and state for a partition replica
void setPartitionState(String partitionName, String instanceName, String state)
Set the preferred instance placement and state for a partition replica
void setPreferenceList(String partitionName, List<String> preferenceList)
Set the preference list of a partition
void setPreferenceList(PartitionId partitionId, List<ParticipantId> preferenceList)
Set the preference list of a partition
void setRebalanceMode(IdealState.RebalanceMode rebalancerType)
Get the rebalance mode of the resource
void setRebalancerClassName(String rebalancerClassName)
Define a custom rebalancer that implements HelixRebalancer
void setRebalancerRef(RebalancerRef rebalancerRef)
Set a reference to the user-defined rebalancer associated with this resource(if any)
void setReplicas(String replicas)
Set the number of replicas for each partition of this resource.
void setStateModelDefId(StateModelDefId stateModelDefId)
Set the state model associated with this resource
void setStateModelDefRef(String stateModel)
Set the state model associated with this resource
void setStateModelFactoryId(StateModelFactoryId stateModelFactoryId)
Set the state model factory associated with this resource
void setStateModelFactoryName(String name)
Set the state model factory associated with this resource
static List<String> stringListFromPreferenceList(List<ParticipantId> preferenceList)
Convert a preference list of participants into a preference list of strings
static Map<StringList<String>> stringListsFromPreferenceLists(Map<PartitionIdList<ParticipantId>> preferenceLists)
Convert preference lists of participants into preference lists of strings
static Map<StringString> stringMapFromParticipantStateMap(Map<ParticipantIdState> participantStateMap)
Convert a partition mapping into a mapping of string names
static Map<StringMap<StringString>> stringMapsFromParticipantStateMaps(Map<PartitionIdMap<ParticipantIdState>> participantStateMaps)
Convert a full state mapping into a mapping of string names
void updateFromAssignment(ResourceAssignment assignment, StateModelDefinition stateModelDef)
Update the ideal state from a ResourceAssignment computed during a rebalance
void updateUserConfig(UserConfig userConfig)
Get the non-Helix simple fields from this property and add them to a UserConfig
[Expand]
Inherited Methods
From class org.apache.helix.HelixProperty
From class java.lang.Object

Constants

public static final String QUERY_LIST

Constant Value: "PREFERENCE_LIST_QUERYS"

Public Constructors

public IdealState (String resourceName)

Instantiate an ideal state for a resource

Parameters
resourceName the name of the resource

public IdealState (ResourceId resourceId)

Instantiate an ideal state for a resource

Parameters
resourceId the id of the resource

public IdealState (ZNRecord record)

Instantiate an ideal state from a record

Parameters
record ZNRecord corresponding to an ideal state

Public Methods

public IdealState.IdealStateModeProperty getIdealStateMode ()

Get the rebalancing mode on this resource

public String getInstanceGroupTag ()

Check for a tag that will restrict assignment to instances with a matching tag

Returns
  • the group tag, or null if none is present

public Set<String> getInstanceSet (String partitionName)

Get the instances who host replicas of a partition

Parameters
partitionName the partition to look up
Returns
  • set of instance names

public Map<StringString> getInstanceStateMap (String partitionName)

Get the current mapping of a partition

Parameters
partitionName the name of the partition
Returns
  • the instances where the replicas live and the state of each

public int getMaxPartitionsPerInstance ()

Get the maximum number of partitions an instance can serve

Returns
  • the partition capacity of an instance for this resource, or Integer.MAX_VALUE

public int getNumPartitions ()

Get the number of partitions of this resource

Returns
  • the number of partitions

public Set<ParticipantId> getParticipantSet (PartitionId partitionId)

Get the participants who host replicas of a partition

Parameters
partitionId the partition to look up
Returns
  • set of participant ids

public Map<ParticipantIdState> getParticipantStateMap (PartitionId partitionId)

Get the current mapping of a partition

Parameters
partitionId the name of the partition
Returns
  • the instances where the replicas live and the state of each

public Set<PartitionId> getPartitionIdSet ()

Get all of the partitions

Returns
  • a set of partitions

public Set<String> getPartitionSet ()

Get all of the partitions

Returns
  • a set of partition names

public List<ParticipantId> getPreferenceList (PartitionId partitionId)

Get the preference list of a partition

Parameters
partitionId the partition id
Returns
  • an ordered list of participants that can serve replicas of the partition

public List<String> getPreferenceList (String partitionName)

Get the preference list of a partition

Parameters
partitionName the name of the partition
Returns
  • a list of instances that can serve replicas of the partition

public IdealState.RebalanceMode getRebalanceMode ()

Get the rebalancing mode on this resource

public int getRebalanceTimerPeriod ()

Set the frequency with which to rebalance

Returns
  • the rebalancing timer period

public String getRebalancerClassName ()

Get the name of the user-defined rebalancer associated with this resource

Returns
  • the rebalancer class name, or null if none is being used

public RebalancerRef getRebalancerRef ()

Get a reference to the user-defined rebalancer associated with this resource(if any)

Returns
  • RebalancerRef

public String getReplicas ()

Get the number of replicas for each partition of this resource

Returns
  • number of replicas (as a string)

public ResourceId getResourceId ()

Get the associated resource

Returns
  • the id of the resource

public String getResourceName ()

Get the associated resource

Returns
  • the name of the resource

public StateModelDefId getStateModelDefId ()

Get the state model associated with this resource

Returns
  • an identifier of the state model

public String getStateModelDefRef ()

Get the state model associated with this resource

Returns
  • an identifier of the state model

public StateModelFactoryId getStateModelFactoryId ()

Get the state model factory associated with this resource

Returns
  • state model factory id

public String getStateModelFactoryName ()

Get the state model factory associated with this resource

Returns
  • state model factory name

public boolean isValid ()

Get property validity

Returns
  • true if valid, false if invalid

public static Map<ParticipantIdState> participantStateMapFromStringMap (Map<StringString> rawMap)

Convert a partition mapping as strings into a participant state map

Parameters
rawMap the map of participant name to state
Returns
  • converted map

public static Map<? extends PartitionIdMap<ParticipantIdState>> participantStateMapsFromStringMaps (Map<StringMap<StringString>> rawMaps)

Convert a full state mapping as strings into participant state maps

Parameters
rawMaps the map of partition name to participant name and state
Returns
  • converted maps

public static List<ParticipantId> preferenceListFromStringList (List<String> rawPreferenceList)

Convert a preference list of strings into a preference list of participants

Parameters
rawPreferenceList the list of strings representing participant names
Returns
  • converted list

public static Map<? extends PartitionIdList<ParticipantId>> preferenceListsFromStringLists (Map<StringList<String>> rawPreferenceLists)

Convert preference lists of strings into preference lists of participants

Parameters
rawPreferenceLists a map of partition name to a list of participant names
Returns
  • converted lists as a map

public IdealState.RebalanceMode rebalanceModeFromString (String mode, IdealState.RebalanceMode defaultMode)

Parse a rebalance mode from a string. It can also understand IdealStateModeProperty values

Parameters
mode string containing a RebalanceMode value
defaultMode the mode to use if the string is not valid
Returns
  • converted RebalanceMode value

public void setIdealStateMode (String mode)

Get the rebalance mode of the ideal state

public void setInstanceGroupTag (String groupTag)

Set a tag to check to enforce assignment to certain instances

Parameters
groupTag the instance group tag

public void setInstanceStateMap (String partitionName, Map<StringString> instanceStateMap)

Set the current mapping of a partition

Parameters
partitionName the partition to set
instanceStateMap (participant name, state) pairs

public void setMaxPartitionsPerInstance (int max)

Set the maximum number of partitions of this resource that an instance can serve

Parameters
max the maximum number of partitions supported

public void setNumPartitions (int numPartitions)

Set the number of partitions of this resource

Parameters
numPartitions the number of partitions

public void setParticipantStateMap (PartitionId partitionId, Map<ParticipantIdState> participantStateMap)

Set the current mapping of a partition

Parameters
partitionId the partition to set
participantStateMap (participant id, state) pairs

public void setPartitionState (PartitionId partitionId, ParticipantId participantId, State state)

Set the preferred participant placement and state for a partition replica

Parameters
partitionId the replica to set
participantId the assigned participant
state the replica state in this instance

public void setPartitionState (String partitionName, String instanceName, String state)

Set the preferred instance placement and state for a partition replica

Parameters
partitionName the replica to set
instanceName the assigned instance
state the replica state in this instance

public void setPreferenceList (String partitionName, List<String> preferenceList)

Set the preference list of a partition

Parameters
partitionName the name of the partition to set
preferenceList a list of participants that can serve replicas of the partition

public void setPreferenceList (PartitionId partitionId, List<ParticipantId> preferenceList)

Set the preference list of a partition

Parameters
partitionId the id of the partition to set
preferenceList a list of participants that can serve replicas of the partition

public void setRebalanceMode (IdealState.RebalanceMode rebalancerType)

Get the rebalance mode of the resource

public void setRebalancerClassName (String rebalancerClassName)

Define a custom rebalancer that implements HelixRebalancer

Parameters
rebalancerClassName the name of the custom rebalancing class

public void setRebalancerRef (RebalancerRef rebalancerRef)

Set a reference to the user-defined rebalancer associated with this resource(if any)

Parameters
rebalancerRef a reference to a user-defined rebalancer

public void setReplicas (String replicas)

Set the number of replicas for each partition of this resource. There are documented special values for the replica count, so this is a String.

Parameters
replicas replica count (as a string)

public void setStateModelDefId (StateModelDefId stateModelDefId)

Set the state model associated with this resource

public void setStateModelDefRef (String stateModel)

Set the state model associated with this resource

Parameters
stateModel state model identifier

public void setStateModelFactoryId (StateModelFactoryId stateModelFactoryId)

Set the state model factory associated with this resource

public void setStateModelFactoryName (String name)

Set the state model factory associated with this resource

Parameters
name state model factory name

public static List<String> stringListFromPreferenceList (List<ParticipantId> preferenceList)

Convert a preference list of participants into a preference list of strings

Parameters
preferenceList the list of strings representing participant ids
Returns
  • converted list

public static Map<StringList<String>> stringListsFromPreferenceLists (Map<PartitionIdList<ParticipantId>> preferenceLists)

Convert preference lists of participants into preference lists of strings

Parameters
preferenceLists a map of partition id to a list of participant ids
Returns
  • converted lists as a map

public static Map<StringString> stringMapFromParticipantStateMap (Map<ParticipantIdState> participantStateMap)

Convert a partition mapping into a mapping of string names

Parameters
participantStateMap the map of participant id to state
Returns
  • converted map

public static Map<StringMap<StringString>> stringMapsFromParticipantStateMaps (Map<PartitionIdMap<ParticipantIdState>> participantStateMaps)

Convert a full state mapping into a mapping of string names

Parameters
participantStateMaps the map of partition id to participant id and state
Returns
  • converted maps

public void updateFromAssignment (ResourceAssignment assignment, StateModelDefinition stateModelDef)

Update the ideal state from a ResourceAssignment computed during a rebalance

Parameters
assignment the new resource assignment
stateModelDef state model of the resource

public void updateUserConfig (UserConfig userConfig)

Get the non-Helix simple fields from this property and add them to a UserConfig

Parameters
userConfig the user config to update