Documentation ¶
Index ¶
- Constants
- Variables
- func CreateRandomString() string
- func GetRandomPort() int32
- func IdealStateKey(clusterName string, resourceName string) string
- type Admin
- func (adm Admin) AddCluster(cluster string, recreateIfExists bool) bool
- func (adm Admin) AddNode(cluster string, node string) error
- func (adm Admin) AddResource(cluster string, resource string, partitions int, stateModel string) error
- func (adm Admin) DisableResource(cluster string, resource string) error
- func (adm Admin) DropCluster(cluster string) error
- func (adm Admin) DropInstance(cluster string, instance string) error
- func (adm Admin) DropNode(cluster string, node string) error
- func (adm Admin) DropResource(cluster string, resource string) error
- func (adm Admin) EnableResource(cluster string, resource string) error
- func (adm Admin) GetConfig(cluster string, scope string, builder []string) (map[string]interface{}, error)
- func (adm Admin) GetInstances(cluster string) error
- func (adm Admin) ListClusterInfo(cluster string) (string, error)
- func (adm Admin) ListClusters() (string, error)
- func (adm Admin) ListInstanceInfo(cluster string, instance string) (string, error)
- func (adm Admin) ListInstances(cluster string) (string, error)
- func (adm Admin) ListResources(cluster string) (string, error)
- func (adm Admin) SetConfig(cluster string, scope string, properties map[string]string) error
- type BaseHelixTestSuite
- type DataAccessor
- func (a *DataAccessor) CreateParticipantMsg(instanceName string, msg *model.Message) error
- func (a *DataAccessor) CurrentState(instanceName, session, resourceName string) (*model.CurrentState, error)
- func (a *DataAccessor) IdealState(resourceName string) (*model.IdealState, error)
- func (a *DataAccessor) InstanceConfig(path string) (*model.InstanceConfig, error)
- func (a *DataAccessor) LiveInstance(instanceName string) (*model.LiveInstance, error)
- func (a *DataAccessor) Msg(path string) (*model.Message, error)
- func (a *DataAccessor) StateModelDef(stateModel string) (*model.StateModelDef, error)
- type KeyBuilder
- type Participant
- type StateModel
- type StateModelProcessor
- type StateTransitionHandler
- type TestParticipant
- type Transition
Constants ¶
const ( StateModelNameOnlineOffline = "OnlineOffline" StateModelStateOnline = "ONLINE" StateModelStateOffline = "OFFLINE" StateModelStateDropped = "DROPPED" TargetController = "CONTROLLER" MsgTypeStateTransition = "STATE_TRANSITION" )
TODO: add all the shared constants here
const ( // TestClusterName is the name of cluster used in test TestClusterName = "test_cluster" // TestResource is the name of resource used in test TestResource = "test_resource" )
Variables ¶
var ( // ErrClusterNotSetup means the helix data structure in zookeeper /{CLUSTER_NAME} // is not correct or does not exist ErrClusterNotSetup = errors.New("cluster not setup") // ErrNodeAlreadyExists the zookeeper node exists when it is not expected to ErrNodeAlreadyExists = errors.New("node already exists in cluster") // ErrNodeNotExist the zookeeper node does not exist when it is expected to ErrNodeNotExist = errors.New("node does not exist in config for cluster") // ErrInstanceNotExist the instance of a cluster does not exist when it is expected to ErrInstanceNotExist = errors.New("node does not exist in instances for cluster") // ErrStateModelDefNotExist the state model definition is expected to exist in zookeeper ErrStateModelDefNotExist = errors.New("state model not exist in cluster") // ErrResourceExists the resource already exists in cluster and cannot be added again ErrResourceExists = errors.New("resource already exists in cluster") // ErrResourceNotExists the resource does not exists and cannot be removed ErrResourceNotExists = errors.New("resource not exists in cluster") )
var ( // ErrorNilUpdatedData returns when updateFn returns nil *model.ZNRecord without error ErrorNilUpdatedData = errors.New("data accessor: updated data is nil") )
Functions ¶
func CreateRandomString ¶
func CreateRandomString() string
CreateRandomString creates a random with numeric characters
func GetRandomPort ¶
func GetRandomPort() int32
GetRandomPort returns random valid port number (1~65535)
func IdealStateKey ¶
IdealStateKey returns path for ideal state of a given cluster and resource
Types ¶
type Admin ¶
type Admin struct {
// contains filtered or unexported fields
}
Admin handles the administration task for the Helix cluster. Many of the operations are mirroring the implementions documented at http://helix.apache.org/0.7.0-incubating-docs/Quickstart.html
func (Admin) AddCluster ¶
AddCluster add a cluster to Helix. As a result, a znode will be created in zookeeper root named after the cluster name, and corresponding data structures are populated under this znode. The cluster would be dropped and recreated if recreateIfExists is true
func (Admin) AddNode ¶
AddNode is the internal implementation corresponding to command ./helix-admin.sh --zkSvr <ZookeeperServerAddress> --addNode <clusterName instanceId> node is in the form of host_port
func (Admin) AddResource ¶
func (adm Admin) AddResource( cluster string, resource string, partitions int, stateModel string) error
AddResource implements the helix-admin.sh --addResource ./helix-admin.sh --zkSvr localhost:2199 --addResource MYCLUSTER myDB 6 MasterSlave
func (Admin) DisableResource ¶
DisableResource disables the specified resource in the cluster.
func (Admin) DropCluster ¶
DropCluster removes a helix cluster from zookeeper. This will remove the znode named after the cluster name from the zookeeper root.
func (Admin) DropInstance ¶
DropInstance removes a participating instance from the helix cluster
func (Admin) DropNode ¶
DropNode removes a node from a cluster. The corresponding znodes in zookeeper will be removed.
func (Admin) DropResource ¶
DropResource removes the specified resource from the cluster.
func (Admin) EnableResource ¶
EnableResource enables the specified resource in the cluster
func (Admin) GetConfig ¶
func (adm Admin) GetConfig( cluster string, scope string, builder []string) (map[string]interface{}, error)
GetConfig obtains the configuration value of a property, defined by a config scope
func (Admin) GetInstances ¶
GetInstances prints out lists of instances
func (Admin) ListClusterInfo ¶
ListClusterInfo shows the existing resources and instances in the glaster
func (Admin) ListClusters ¶
ListClusters shows all Helix managed clusters in the connected zookeeper cluster
func (Admin) ListInstanceInfo ¶
ListInstanceInfo shows detailed information of an inspace in the helix cluster
func (Admin) ListInstances ¶
ListInstances shows a list of instances participating the cluster.
func (Admin) ListResources ¶
ListResources shows a list of resources managed by the helix cluster
type BaseHelixTestSuite ¶
type BaseHelixTestSuite struct { zk.BaseZkTestSuite Admin *Admin }
BaseHelixTestSuite can be embedded in any test suites that need to interact with the test zk server or helix admin. It provides ZK connect string and Helix admin references for convenient uses in parent suites.
func (*BaseHelixTestSuite) SetupSuite ¶
func (s *BaseHelixTestSuite) SetupSuite()
SetupSuite ensures zk server is up
func (*BaseHelixTestSuite) TearDownSuite ¶
func (s *BaseHelixTestSuite) TearDownSuite()
TearDownSuite disconnects zk if not done already
type DataAccessor ¶
type DataAccessor struct {
// contains filtered or unexported fields
}
DataAccessor helps to interact with Helix Data Types like IdealState, LiveInstance, Message it mirrors org.apache.helix.HelixDataAccessor
func (*DataAccessor) CreateParticipantMsg ¶
func (a *DataAccessor) CreateParticipantMsg(instanceName string, msg *model.Message) error
CreateParticipantMsg creates a message for the participant
func (*DataAccessor) CurrentState ¶
func (a *DataAccessor) CurrentState(instanceName, session, resourceName string, ) (*model.CurrentState, error)
CurrentState helps get Helix property with type CurrentState
func (*DataAccessor) IdealState ¶
func (a *DataAccessor) IdealState(resourceName string) (*model.IdealState, error)
IdealState helps get Helix property with type IdealState
func (*DataAccessor) InstanceConfig ¶
func (a *DataAccessor) InstanceConfig(path string) (*model.InstanceConfig, error)
InstanceConfig helps get Helix property with type Message
func (*DataAccessor) LiveInstance ¶
func (a *DataAccessor) LiveInstance(instanceName string) (*model.LiveInstance, error)
LiveInstance returns Helix property with type LiveInstance
func (*DataAccessor) Msg ¶
func (a *DataAccessor) Msg(path string) (*model.Message, error)
Msg helps get Helix property with type Message
func (*DataAccessor) StateModelDef ¶
func (a *DataAccessor) StateModelDef(stateModel string) (*model.StateModelDef, error)
StateModelDef helps get Helix property with type StateModelDef
type KeyBuilder ¶
type KeyBuilder struct {
// contains filtered or unexported fields
}
KeyBuilder generates Zookeeper paths Mirrors org.apache.helix.PropertyKey#Builder
type Participant ¶
type Participant interface { Connect() error Disconnect() IsConnected() bool RegisterStateModel(stateModelName string, processor *StateModelProcessor) DataAccessor() *DataAccessor InstanceName() string Process(e zk.Event) }
Participant is the Helix participant
func NewParticipant ¶
func NewParticipant( logger *zap.Logger, scope tally.Scope, zkConnectString string, application string, clusterName string, resourceName string, host string, port int32, ) (Participant, <-chan error)
NewParticipant instantiates a Participant, when an error is sent from the error chan, it means participant sees nonrecoverable errors user is expected to clean up and restart the program
type StateModel ¶
type StateModel interface { // GetState returns the state of a resource/partition combination GetState(resourceName string, partitionKey string) (string, bool) // UpdateState updates the state of a resource/partition combination UpdateState(resourceName string, partitionKey string, state string) // RemoveState removes the state of a resource/partition combination RemoveState(resourceName string, partitionKey string) }
StateModel mirrors the behavior of org.apache.helix.participant.statemachine.StateModel and org.apache.helix.participant.statemachine.StateModelFactory it keeps the state of each resource/partition combination
type StateModelProcessor ¶
type StateModelProcessor struct { // fromState->toState->StateTransitionHandler Transitions map[string]map[string]StateTransitionHandler }
StateModelProcessor handles state transitions This mirrors org.apache.helix.participant.statemachine.StateModelFactory
func NewStateModelProcessor ¶
func NewStateModelProcessor() *StateModelProcessor
NewStateModelProcessor functions similarly to StateMachineEngine
func (*StateModelProcessor) AddTransition ¶
func (p *StateModelProcessor) AddTransition(fromState string, toState string, handler StateTransitionHandler)
AddTransition adds a new transition handler
type StateTransitionHandler ¶
StateTransitionHandler is type for handler method
type TestParticipant ¶
type TestParticipant struct {
Participant
}
TestParticipant is a participant used for test purpose
func NewTestParticipant ¶
func NewTestParticipant( logger *zap.Logger, scope tally.Scope, zkConnectString string, application string, clusterName string, resourceName string, host string, port int32, ) (*TestParticipant, <-chan error)
NewTestParticipant returns a TestParticipant
func (*TestParticipant) GetFatalErrorChan ¶
func (p *TestParticipant) GetFatalErrorChan() chan error
GetFatalErrorChan returns the fatal error chan, so user can send test error
type Transition ¶
type Transition struct { FromState string ToState string Handler StateTransitionHandler }
Transition associates a handler function with state transitions