model

package
v0.0.0-...-896f72c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 30, 2016 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CurrentState

type CurrentState struct {
	*Record
}

func NewCurrentStateFromRecord

func NewCurrentStateFromRecord(r *Record) *CurrentState

func (*CurrentState) SetCurrentState

func (c *CurrentState) SetCurrentState(partitionName, state string)

type DynamicBound

type DynamicBound string
const (
	// The number of replicas in the state is at most the specified replica count for the partition.
	DynamicBoundR DynamicBound = "R"

	// The number of replicas in the state is at most the number of live participants in the cluster.
	DynamicBoundN DynamicBound = "N"
)

type ExternalView

type ExternalView struct {
	*Record
}

func NewExternalViewFromRecord

func NewExternalViewFromRecord(r *Record) *ExternalView

func (*ExternalView) IdealStateMode

func (e *ExternalView) IdealStateMode() string

func (*ExternalView) InstanceState

func (e *ExternalView) InstanceState(instance, partitionName string) string

func (*ExternalView) InstanceWithState

func (e *ExternalView) InstanceWithState(partitionName, state string) string

func (*ExternalView) NumPartitions

func (e *ExternalView) NumPartitions() int

func (*ExternalView) Replicas

func (e *ExternalView) Replicas() int

func (*ExternalView) Resource

func (e *ExternalView) Resource() string

type IdealState

type IdealState struct {
	*Record
}

ideal state content example:

{
  "id" : "MyResource",
  "simpleFields" : {
    "IDEAL_STATE_MODE" : "AUTO",
    "NUM_PARTITIONS" : "6",
    "REBALANCE_MODE" : "SEMI_AUTO",
    "REBALANCE_STRATEGY" : "DEFAULT",
    "REBALANCER_CLASS_NAME": "",
    "REPLICAS" : "3",
    "STATE_MODEL_DEF_REF" : "MyStateModel",
    "STATE_MODEL_FACTORY_NAME" : "DEFAULT"
  },
  "mapFields" : {
    "MyResource_0" : {
      "localhost_12000" : "SLAVE",
      "localhost_12001" : "MASTER",
      "localhost_12002" : "SLAVE"
    },
    "MyResource_1" : {
      "localhost_12000" : "SLAVE",
      "localhost_12001" : "SLAVE",
      "localhost_12002" : "MASTER"
    },
    "MyResource_2" : {
      "localhost_12000" : "MASTER",
      "localhost_12001" : "SLAVE",
      "localhost_12002" : "SLAVE"
    },
    "MyResource_3" : {
      "localhost_12000" : "SLAVE",
      "localhost_12001" : "SLAVE",
      "localhost_12002" : "MASTER"
    },
    "MyResource_4" : {
      "localhost_12000" : "MASTER",
      "localhost_12001" : "SLAVE",
      "localhost_12002" : "SLAVE"
    },
    "MyResource_5" : {
      "localhost_12000" : "SLAVE",
      "localhost_12001" : "MASTER",
      "localhost_12002" : "SLAVE"
    }
  },
  "listFields" : {
    "MyResource_0" : [ "localhost_12001", "localhost_12000", "localhost_12002" ],
    "MyResource_1" : [ "localhost_12002", "localhost_12000", "localhost_12001" ],
    "MyResource_2" : [ "localhost_12000", "localhost_12002", "localhost_12001" ],
    "MyResource_3" : [ "localhost_12002", "localhost_12001", "localhost_12000" ],
    "MyResource_4" : [ "localhost_12000", "localhost_12001", "localhost_12002" ],
    "MyResource_5" : [ "localhost_12001", "localhost_12000", "localhost_12002" ]
  }
}

func NewIdealStateFromRecord

func NewIdealStateFromRecord(record *Record) *IdealState

func (*IdealState) EnableGroupRouting

func (is *IdealState) EnableGroupRouting(yes bool)

func (IdealState) ExternalViewDisabled

func (is IdealState) ExternalViewDisabled() bool

func (*IdealState) IdealStateMode

func (is *IdealState) IdealStateMode() string

func (IdealState) InstanceGroupTag

func (is IdealState) InstanceGroupTag() string

func (*IdealState) InstanceState

func (is *IdealState) InstanceState(instance, partitionName string) string

func (*IdealState) MaxPartitionsPerInstance

func (is *IdealState) MaxPartitionsPerInstance() int

func (IdealState) NumPartitions

func (is IdealState) NumPartitions() int

func (IdealState) PreferenceList

func (is IdealState) PreferenceList(partitionName string) []string

func (*IdealState) RebalanceMode

func (is *IdealState) RebalanceMode() string

func (IdealState) RebalanceStrategy

func (is IdealState) RebalanceStrategy() string

func (*IdealState) RebalancerClassName

func (is *IdealState) RebalancerClassName() string

func (IdealState) Replicas

func (is IdealState) Replicas() string

func (*IdealState) Resource

func (is *IdealState) Resource() string

func (IdealState) ResourceGroupName

func (is IdealState) ResourceGroupName() string

func (*IdealState) SetIdealStateMode

func (is *IdealState) SetIdealStateMode(mode string)

func (*IdealState) SetInstanceGroupTag

func (is *IdealState) SetInstanceGroupTag(tag string)

func (*IdealState) SetMaxPartitionsPerInstance

func (is *IdealState) SetMaxPartitionsPerInstance(max int)

func (IdealState) SetNumPartitions

func (is IdealState) SetNumPartitions(n int)

func (*IdealState) SetRebalanceMode

func (is *IdealState) SetRebalanceMode(mode string)

func (*IdealState) SetRebalancerClassName

func (is *IdealState) SetRebalancerClassName(clazz string)

func (*IdealState) SetReplicas

func (is *IdealState) SetReplicas(replicas string)

func (IdealState) StateModelDefRef

func (is IdealState) StateModelDefRef() string

StateModelDefRef returns the state model associated with this resource.

func (IdealState) Valid

func (is IdealState) Valid() bool

type InstanceConfig

type InstanceConfig struct {
	*Record
}

func NewInstanceConfigFromRecord

func NewInstanceConfigFromRecord(record *Record) *InstanceConfig

func (*InstanceConfig) AddTag

func (ic *InstanceConfig) AddTag(tag string)

func (*InstanceConfig) ContainsTag

func (ic *InstanceConfig) ContainsTag(tag string) bool

func (InstanceConfig) DisabledPartitions

func (ic InstanceConfig) DisabledPartitions() []string

func (*InstanceConfig) Enable

func (ic *InstanceConfig) Enable(enabled bool)

func (InstanceConfig) EnablePartition

func (ic InstanceConfig) EnablePartition(partition string, yes bool)

TODO

func (InstanceConfig) Host

func (ic InstanceConfig) Host() string

func (InstanceConfig) InstanceName

func (ic InstanceConfig) InstanceName() string

func (*InstanceConfig) IsEnabled

func (ic *InstanceConfig) IsEnabled() bool

func (InstanceConfig) Node

func (ic InstanceConfig) Node() string

func (InstanceConfig) Port

func (ic InstanceConfig) Port() string

func (*InstanceConfig) RemoveTag

func (ic *InstanceConfig) RemoveTag(tag string)

func (InstanceConfig) SetHost

func (ic InstanceConfig) SetHost(host string)

func (InstanceConfig) SetPort

func (ic InstanceConfig) SetPort(port string)

func (InstanceConfig) String

func (ic InstanceConfig) String() string

func (InstanceConfig) Tags

func (ic InstanceConfig) Tags() []string

func (InstanceConfig) Validate

func (ic InstanceConfig) Validate() error

TODO

type LiveInstance

type LiveInstance struct {
	*Record
}

func NewLiveInstanceFromRecord

func NewLiveInstanceFromRecord(record *Record) *LiveInstance

func (*LiveInstance) Node

func (li *LiveInstance) Node() string

func (*LiveInstance) SessionID

func (li *LiveInstance) SessionID() string

func (*LiveInstance) SetSessionID

func (li *LiveInstance) SetSessionID(sessionID string)

type Message

type Message struct {
	*Record
}

Message is controller generated payload to instruct participant to carry out some tasks.

message content example:

{
    "id": "9ff57fc1-9f2a-41a5-af46-c4ae2a54c539",
    "simpleFields": {
        "CREATE_TIMESTAMP": "1425268051457",
        "ClusterEventName": "currentStateChange",
        "FROM_STATE": "OFFLINE",
        "MSG_ID": "9ff57fc1-9f2a-41a5-af46-c4ae2a54c539",
        "MSG_STATE": "new",
        "MSG_TYPE": "STATE_TRANSITION",
        "PARTITION_NAME": "myDB_5",
        "RESOURCE_NAME": "myDB",
        "SRC_NAME": "precise64-CONTROLLER",
        "SRC_SESSION_ID": "14bd852c528004c",
        "STATE_MODEL_DEF": "MasterSlave",
        "STATE_MODEL_FACTORY_NAME": "DEFAULT",
        "TGT_NAME": "localhost_12913",
        "TGT_SESSION_ID": "93406067297878252",
        "TO_STATE": "SLAVE"
    },
    "listFields": {},
    "mapFields": {}
}

func NewMessageFromRecord

func NewMessageFromRecord(record *Record) *Message

func (Message) ClusterEventName

func (m Message) ClusterEventName() string

func (Message) CreateReplyMessage

func (m Message) CreateReplyMessage(src *Message)

TODO CreateReplyMessage creates a reply based on an incoming message.

func (Message) CreateTimeStamp

func (m Message) CreateTimeStamp() int64

CreateTimeStamp returns the time that this message was created.

func (Message) ExecutionTimeout

func (m Message) ExecutionTimeout() int

ExecutionTimeout returns the time to wait before stopping execution of this message.

func (Message) FromState

func (m Message) FromState() string

func (Message) ID

func (m Message) ID() string

ID returns the unique identifier of this message.

func (Message) IsControllerMsg

func (m Message) IsControllerMsg() bool

IsControllerMsg checks if this message is targetted for a controller.

func (Message) MessageState

func (m Message) MessageState() string

func (Message) MessageSubType

func (m Message) MessageSubType() string

func (Message) MessageType

func (m Message) MessageType() string

func (Message) PartitionName

func (m Message) PartitionName() string

PartitionName returns the name of the partition this message concerns.

func (Message) PartitionNames

func (m Message) PartitionNames() []string

PartitionNames returns a list of partitions associated with this message.

func (Message) Resource

func (m Message) Resource() string

Resource returns the resource associated with this message.

func (Message) ResourceGroupName

func (m Message) ResourceGroupName() string

ResourceGroupName returns the resource group associated with this message.

func (Message) ResourceTag

func (m Message) ResourceTag() string

ResourceTag returns the resource tag associated with this message.

func (Message) RetryCount

func (m Message) RetryCount() int

func (*Message) SetExecuteSessionID

func (m *Message) SetExecuteSessionID(sessID string)

SetExecuteSessionID sets the session identifier of the node that executes the message.

func (*Message) SetExecuteStartTimeStamp

func (m *Message) SetExecuteStartTimeStamp(val int64)

SetExecuteStartTimeStamp sets the time that the instance executes tasks as instructed by this message.

func (*Message) SetMessageState

func (m *Message) SetMessageState(state string)

func (*Message) SetReadTimestamp

func (m *Message) SetReadTimestamp(val int64)

SetReadTimestamp sets the time that this message was read.

func (Message) SetToState

func (m Message) SetToState(state string)

func (Message) SrcInstanceType

func (m Message) SrcInstanceType() string

func (Message) SrcName

func (m Message) SrcName() string

SrcName returns the instance from which the message originated.

func (Message) SrcSessionID

func (m Message) SrcSessionID() string

SrcSessionID returns the session identifier of the source node.

func (Message) StateModelDef

func (m Message) StateModelDef() string

StateModelDef returns the state model definition name.

func (Message) StateModelFactory

func (m Message) StateModelFactory() string

func (Message) TargetName

func (m Message) TargetName() string

TargetName returns the target instance name.

func (Message) TargetSessionID

func (m Message) TargetSessionID() string

TargetSessionID returns the session identifier of the destination node.

func (Message) ToState

func (m Message) ToState() string

func (Message) Valid

func (m Message) Valid() bool

type Messages

type Messages []Message

func (Messages) Len

func (ms Messages) Len() int

func (Messages) Less

func (ms Messages) Less(i, j int) bool

func (Messages) Swap

func (ms Messages) Swap(i, j int)

type Record

type Record struct {
	ID string `json:"id"`

	// plain key, value fields
	SimpleFields map[string]interface{} `json:"simpleFields"`

	// all fields whose values are a list of values
	ListFields map[string][]string `json:"listFields"`

	// all fields whose values are key, value
	MapFields map[string]map[string]string `json:"mapFields"`
}

Generic Record Format to store data at a storage Node. simpleFields mapFields listFields.

func NewLiveInstanceRecord

func NewLiveInstanceRecord(participantID string, sessionID string) *Record

NewLiveInstanceRecord creates a new instance of Record for representing a live instance.

func NewRecord

func NewRecord(id string) *Record

NewRecord creates a new instance of Record instance

func NewRecordFromBytes

func NewRecordFromBytes(data []byte) (*Record, error)

NewRecordFromBytes creates a Record from a byte slice. If data is empty, returns an empty Record with nil error.

func (*Record) AddListField

func (r *Record) AddListField(key string, value string)

func (Record) BatchMessageMode

func (r Record) BatchMessageMode() bool

func (Record) BucketSize

func (r Record) BucketSize() int

func (Record) Equals

func (r1 Record) Equals(r2 *Record) bool

FIXME

func (Record) GetBooleanField

func (r Record) GetBooleanField(key string, defaultValue bool) bool

GetBooleanField gets the value of a key under SimpleField and convert the result to bool type. That is, if the value is "true", the result is true.

func (Record) GetIntField

func (r Record) GetIntField(key string, defaultValue int) int

GetIntField returns the integer value of a field in the SimpleField

func (*Record) GetListField

func (r *Record) GetListField(key string) []string

func (Record) GetMapField

func (r Record) GetMapField(key string, property string) string

GetMapField returns the string value of the property of a key under MapField.

func (Record) GetSimpleField

func (r Record) GetSimpleField(key string) interface{}

GetSimpleField returns a value of a key in SimpleField structure

func (Record) GetStringField

func (r Record) GetStringField(key string, defaultValue string) string

GetStringField returns the string value of a field in the SimpleField

func (Record) Marshal

func (r Record) Marshal() []byte

Marshal generates the beautified json in byte array format

func (*Record) RemoveListField

func (r *Record) RemoveListField(key string, value string)

func (*Record) RemoveMapField

func (r *Record) RemoveMapField(key string)

RemoveMapField deletes a key from MapField

func (*Record) SetBatchMessageMode

func (r *Record) SetBatchMessageMode(yes bool)

func (*Record) SetBooleanField

func (r *Record) SetBooleanField(key string, value bool)

SetBooleanField sets a key under SimpleField with a specified bool value, serialized to string. For example, true will be stored as "TRUE"

func (*Record) SetBucketSize

func (r *Record) SetBucketSize(size int)

func (*Record) SetIntField

func (r *Record) SetIntField(key string, value int)

SetIntField sets the integer value of a key under SimpleField. the value is stored as in string form

func (*Record) SetMapField

func (r *Record) SetMapField(key string, property string, value string)

SetMapField sets the value of a key under MapField. Both key and value are string format.

func (*Record) SetSimpleField

func (r *Record) SetSimpleField(key string, value interface{})

SetSimpleField sets the value of a key under SimpleField

func (Record) SetStringField

func (r Record) SetStringField(key string, value string)

func (Record) String

func (r Record) String() string

String returns the beautified JSON string for the Record

type Resource

type Resource struct {
	// contains filtered or unexported fields
}

A resource contains a set of partitions and its replicas are managed by a state model.

func NewResource

func NewResource(name string) *Resource

func (*Resource) AddPartition

func (r *Resource) AddPartition(partitionName string) *Resource

func (Resource) BatchMessageMode

func (r Resource) BatchMessageMode() bool

func (Resource) BucketSize

func (r Resource) BucketSize() int

func (Resource) Name

func (r Resource) Name() string

func (Resource) Partitions

func (r Resource) Partitions() []string

func (*Resource) SetBatchMessageMode

func (r *Resource) SetBatchMessageMode(yes bool)

func (*Resource) SetBucketSize

func (r *Resource) SetBucketSize(size int)

func (*Resource) SetStateModelDef

func (r *Resource) SetStateModelDef(def string)

func (*Resource) SetStateModelFactory

func (r *Resource) SetStateModelFactory(f string)

func (Resource) String

func (r Resource) String() string

type ResourceAssignment

type ResourceAssignment struct {
	*Record
}

ResourceAssignment represents the assignments of replicas for an entire resource, keyed on partitions of the resource.

func (*ResourceAssignment) MappedPartitions

func (ra *ResourceAssignment) MappedPartitions() []string

MappedPartitions returns the currently mapped partition names.

func (*ResourceAssignment) ReplicaMap

func (ra *ResourceAssignment) ReplicaMap(partition string) map[string]string

ReplicaMap returns the instance, state pairs for a partition. e,g. {"localhost_10001": "MASTER"}

func (*ResourceAssignment) Resource

func (ra *ResourceAssignment) Resource() string

type StateModelDef

type StateModelDef struct {
	*Record
}

func NewStateModelDef

func NewStateModelDef(stateModel string) *StateModelDef

func NewStateModelDefFromRecord

func NewStateModelDefFromRecord(r *Record) *StateModelDef

func (*StateModelDef) AddState

func (smd *StateModelDef) AddState(state string, priority int) *StateModelDef

TODO

func (*StateModelDef) AddTransition

func (smd *StateModelDef) AddTransition(fromState, toState string) *StateModelDef

TODO

func (*StateModelDef) InitialState

func (smd *StateModelDef) InitialState() string

func (*StateModelDef) SetDynamicUpperBound

func (smd *StateModelDef) SetDynamicUpperBound(state string, bound DynamicBound) *StateModelDef

TODO

func (*StateModelDef) SetInitialState

func (smd *StateModelDef) SetInitialState(state string) *StateModelDef

func (*StateModelDef) SetStaticUpperBound

func (smd *StateModelDef) SetStaticUpperBound(state string, bound int) *StateModelDef

TODO

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL