store

package
v0.1.11 Latest Latest
Warning

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

Go to latest
Published: May 3, 2017 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SWAN_ATOMIC_STORE_NODE_PATH = "%s/atomic-store"
	SWAN_SNAPSHOT_PATH          = "%s/snapshot"
)

Variables

View Source
var (
	ErrAppNotFound          = errors.New("app not found")
	ErrAppAlreadyExists     = errors.New("app already exists")
	ErrSlotNotFound         = errors.New("slot not found")
	ErrSlotAlreadyExists    = errors.New("slot already exists")
	ErrVersionAlreadyExists = errors.New("version already exists")
)
View Source
var (
	ZK_DEFAULT_ACL = zookeeper.WorldACL(zookeeper.PermAll)
)

Functions

func InitZkStore

func InitZkStore(zkPath *url.URL) error

Types

type Application

type Application struct {
	ID              string        `json:"id,omitempty"`
	Name            string        `json:"name,omitempty"`
	Version         *Version      `json:"version,omitempty"`
	ProposedVersion *Version      `json:"proposedVersion,omitempty"`
	ClusterID       string        `json:"clusterId,omitempty"`
	StateMachine    *StateMachine `json:"stateMachine,omitempty"`
	CreatedAt       int64         `json:"createdAt,omitempty"`
	UpdatedAt       int64         `json:"updatedAt,omitempty"`
	State           string        `json:"State,omitempty"`
}

func (*Application) Bytes

func (app *Application) Bytes() []byte

func (*Application) FromBytes

func (app *Application) FromBytes(buf []byte) *Application

type AtomicOp

type AtomicOp struct {
	// atomic operaiton type, ADD | REMOVE | UPDATE
	Op StoreOp
	// which object type been operating
	Entity StoreEntity
	// can be explained by any specfic operation & object type operating on  appId/slotId maybe
	Param1 string
	// same as Param1
	Param2 string
	// same as Param1
	Param3 string
	// contains the data that the operation care, mostly object itself like App/Slot/Version
	Payload interface{}
}

type Container

type Container struct {
	Type    string    `json:"type,omitempty"`
	Docker  *Docker   `json:"docker,omitempty"`
	Volumes []*Volume `json:"volumes,omitempty"`
}

type Docker

type Docker struct {
	ForcePullImage bool           `json:"forcePullImage,omitempty"`
	Image          string         `json:"image,omitempty"`
	Network        string         `json:"network,omitempty"`
	Parameters     []*Parameter   `json:"parameters,omitempty"`
	PortMappings   []*PortMapping `json:"portMappings,omitempty"`
	Privileged     bool           `json:"privileged,omitempty"`
}

type DummyStore

type DummyStore struct {
	Apps           map[string]*appHolder
	OfferAllocator map[string]*OfferAllocatorItem
	FrameworkId    string
	// contains filtered or unexported fields
}

func NewDummyStore

func NewDummyStore() *DummyStore

func (*DummyStore) CreateApp

func (dummy *DummyStore) CreateApp(app *Application) error

func (*DummyStore) CreateOfferAllocatorItem

func (dummy *DummyStore) CreateOfferAllocatorItem(item *OfferAllocatorItem) error

func (*DummyStore) CreateSlot

func (dummy *DummyStore) CreateSlot(slot *Slot) error

func (*DummyStore) CreateVersion

func (dummy *DummyStore) CreateVersion(appId string, version *Version) error

func (*DummyStore) DeleteApp

func (dummy *DummyStore) DeleteApp(appId string) error

func (*DummyStore) DeleteOfferAllocatorItem

func (dummy *DummyStore) DeleteOfferAllocatorItem(slotId string) error

func (*DummyStore) DeleteSlot

func (dummy *DummyStore) DeleteSlot(appId, slotId string) error

func (*DummyStore) GetApp

func (dummy *DummyStore) GetApp(appId string) *Application

func (*DummyStore) GetFrameworkId

func (dummy *DummyStore) GetFrameworkId() string

func (*DummyStore) GetSlot

func (dummy *DummyStore) GetSlot(appId, slotId string) *Slot

func (*DummyStore) GetVersion

func (dummy *DummyStore) GetVersion(appId, versionId string) *Version

func (*DummyStore) ListApps

func (dummy *DummyStore) ListApps() []*Application

func (*DummyStore) ListOfferallocatorItems

func (dummy *DummyStore) ListOfferallocatorItems() []*OfferAllocatorItem

func (*DummyStore) ListSlots

func (dummy *DummyStore) ListSlots(appId string) []*Slot

func (*DummyStore) ListTaskHistory

func (dummy *DummyStore) ListTaskHistory(appId, slotId string) []*Task

func (*DummyStore) ListVersions

func (dummy *DummyStore) ListVersions(appId string) []*Version

func (*DummyStore) Synchronize

func (dummy *DummyStore) Synchronize() error

func (*DummyStore) UpdateApp

func (dummy *DummyStore) UpdateApp(app *Application) error

func (*DummyStore) UpdateCurrentTask

func (dummy *DummyStore) UpdateCurrentTask(appId, slotId string, task *Task) error

func (*DummyStore) UpdateFrameworkId

func (dummy *DummyStore) UpdateFrameworkId(frameworkId string) error

func (*DummyStore) UpdateSlot

func (dummy *DummyStore) UpdateSlot(appId, slotId string, slot *Slot) error

type HealthCheck

type HealthCheck struct {
	ID                  string  `json:"id,omitempty"`
	Address             string  `json:"address,omitempty"`
	Protocol            string  `json:"protocol,omitempty"`
	Port                int32   `json:"port,omitempty"`
	PortIndex           int32   `json:"portIndex,omitempty"`
	PortName            string  `json:"portName,omitempty"`
	Value               string  `json:"value,omitempty"`
	Path                string  `json:"path,omitempty"`
	ConsecutiveFailures uint32  `json:"consecutiveFailures,omitempty"`
	GracePeriodSeconds  float64 `json:"gracePeriodSeconds,omitempty"`
	IntervalSeconds     float64 `json:"intervalSeconds,omitempty"`
	TimeoutSeconds      float64 `json:"timeoutSeconds,omitempty"`
	DelaySeconds        float64 `json:"delaySeconds,omitempty"`
}

type KillPolicy

type KillPolicy struct {
	Duration int64 `json:"duration,omitempty"`
}

type OfferAllocatorItem

type OfferAllocatorItem struct {
	SlotID   string `json:"slotId,omitempty"`
	OfferID  string `json:"offerId,omitempty"`
	Hostname string `json:"hostname,omitempty"`
	AgentID  string `json:"agentId,omitempty"`
}

type Parameter

type Parameter struct {
	Key   string `json:"key,omitempty"`
	Value string `json:"value,omitempty"`
}

type PortMapping

type PortMapping struct {
	ContainerPort int32  `json:"containerPort,omitempty"`
	HostPort      int32  `json:"hostPort,omitempty"`
	Name          string `json:"name,omitempty"`
	Protocol      string `json:"protocol,omitempty"`
}

type RestartPolicy

type RestartPolicy struct {
}

type Slot

type Slot struct {
	Index                int32          `json:"index,omitempty"`
	ID                   string         `json:"id,omitempty"`
	AppID                string         `json:"appId,omitempty"`
	VersionID            string         `json:"versionId,omitempty"`
	State                string         `json:"state,omitempty"`
	MarkForDeletion      bool           `json:"markForDeletion,omitempty"`
	MarkForRollingUpdate bool           `json:"markForRollingUpdate,omitempty"`
	Healthy              bool           `json:"healthy,omitempty"`
	CurrentTask          *Task          `json:"CurrentTask,omitempty"`
	TaskHistory          []*Task        `json:"TaskHistory,omitempty"`
	RestartPolicy        *RestartPolicy `json:"restartPolicy,omitempty"`
	Weight               float64        `json:"weight,omitempty"`
}

func (*Slot) Bytes

func (slot *Slot) Bytes() []byte

func (*Slot) FromBytes

func (slot *Slot) FromBytes(buf []byte) *Slot

type State

type State struct {
	Name                string `json:"name,omitempty"`
	CurrentSlotIndex    int64  `json:"currentSlotIndex,omitempty"`
	TargetSlotIndex     int64  `json:"targetSlotIndex,omitempty"`
	SlotCountNeedUpdate int64  `json:"slotCountNeedUpdate,omitempty"`
}

type StateMachine

type StateMachine struct {
	State *State `json:"state,omitempty"`
}

type Storage

type Storage struct {
	Apps           map[string]*appHolder          `json:"apps"`
	OfferAllocator map[string]*OfferAllocatorItem `json:"offerAllocator"`
	FrameworkId    string                         `json:"frameworkid"`
}

func NewStorage

func NewStorage() *Storage

type Store

type Store interface {
	CreateApp(app *Application) error
	UpdateApp(app *Application) error
	GetApp(appId string) *Application
	ListApps() []*Application
	DeleteApp(appId string) error

	CreateVersion(appId string, version *Version) error
	GetVersion(appId, versionId string) *Version
	ListVersions(appId string) []*Version

	CreateSlot(slot *Slot) error
	GetSlot(appId, slotId string) *Slot
	ListSlots(appId string) []*Slot
	UpdateSlot(appId, slotId string, slot *Slot) error
	DeleteSlot(appId, slotId string) error

	UpdateCurrentTask(appId, slotId string, task *Task) error
	ListTaskHistory(appId, slotId string) []*Task

	UpdateFrameworkId(frameworkId string) error
	GetFrameworkId() string

	CreateOfferAllocatorItem(item *OfferAllocatorItem) error
	DeleteOfferAllocatorItem(slotId string) error
	ListOfferallocatorItems() []*OfferAllocatorItem

	Recover() error
	Start(context.Context) error
}

type StoreEntity

type StoreEntity uint8

represents the object type been manipulation by any specfic operation

var (
	ENTITY_APP                  StoreEntity = 1
	ENTITY_SLOT                 StoreEntity = 2
	ENTITY_VERSION              StoreEntity = 3
	ENTITY_CURRENT_TASK         StoreEntity = 4
	ENTITY_FRAMEWORKID          StoreEntity = 5
	ENTITY_OFFER_ALLOCATOR_ITEM StoreEntity = 6
)

func (StoreEntity) String

func (entity StoreEntity) String() string

type StoreOp

type StoreOp uint8

represents atomic operation both apply to ZK and intertal storage structure

var (
	OP_ADD    StoreOp = 1
	OP_REMOVE StoreOp = 2
	OP_UPDATE StoreOp = 3
)

func (StoreOp) String

func (op StoreOp) String() string

type Task

type Task struct {
	ID            string   `json:"id,omitempty"`
	AppID         string   `json:"appId,omitempty"`
	VersionID     string   `json:"versionId,omitempty"`
	SlotID        string   `json:"slotId,omitempty"`
	State         string   `json:"state,omitempty"`
	Stdout        string   `json:"stdout,omitempty"`
	Stderr        string   `json:"stderr,omitempty"`
	HostPorts     []uint64 `json:"hostPorts,omitempty"`
	OfferID       string   `json:"offerId,omitempty"`
	AgentID       string   `json:"agentId,omitempty"`
	Ip            string   `json:"ip,omitempty"`
	AgentHostName string   `json:"agentHostName,omitempty"`
	Reason        string   `json:"reason,omitempty"`
	Message       string   `json:"message,omitempty"`
	CreatedAt     int64    `json:"createdAt,omitempty"`
	ArchivedAt    int64    `json:"archivedAt,omitempty"`
	ContainerId   string   `json:"containerId,omitempty"`
	ContainerName string   `json:"containerName,omitempty"`
	Weight        float64  `json:"weight,omitempty"`
}

type UpdatePolicy

type UpdatePolicy struct {
	UpdateDelay  int32  `json:"updateDelay,omitempty"`
	MaxRetries   int32  `json:"maxRetries,omitempty"`
	MaxFailovers int32  `json:"maxFailovers,omitempty"`
	Action       string `json:"action,omitempty"`
}

type Version

type Version struct {
	ID           string            `json:"id,omitempty"`
	Command      string            `json:"command,omitempty"`
	Cpus         float64           `json:"cpus,omitempty"`
	Mem          float64           `json:"mem,omitempty"`
	Disk         float64           `json:"disk,omitempty"`
	Instances    int32             `json:"instances,omitempty"`
	RunAs        string            `json:"runAs,omitempty"`
	Container    *Container        `json:"container,omitempty"`
	Labels       map[string]string `protobuf_val:"bytes,2,opt,name=value,proto3"`
	HealthCheck  *HealthCheck      `json:"healthCheck,omitempty"`
	Env          map[string]string `protobuf_val:"bytes,2,opt,name=value,proto3"`
	KillPolicy   *KillPolicy       `json:"killPolicy,omitempty"`
	UpdatePolicy *UpdatePolicy     `json:"updatePolicy,omitempty"`
	Constraints  string            `json:"constraints,omitempty"`
	Uris         []string          `json:"uris,omitempty"`
	Ip           []string          `json:"ip,omitempty"`
	Mode         string            `json:"mode,omitempty"`
	AppName      string            `json:"appName,omitempty"`
	AppID        string            `json:"appID,omitempty"`
	Priority     int32             `json:"priority,omitempty"`
	Args         []string          `json:"args,omitempty"`
	AppVersion   string            `json:"appVersion,omitempty"`
}

func (*Version) Bytes

func (version *Version) Bytes() []byte

func (*Version) FromBytes

func (version *Version) FromBytes(buf []byte) *Version

type Volume

type Volume struct {
	ContainerPath string `json:"containerPath,omitempty"`
	HostPath      string `json:"hostPath,omitempty"`
	Mode          string `json:"mode,omitempty"`
}

type ZkStore

type ZkStore struct {
	Storage *Storage
	// contains filtered or unexported fields
}

func DB

func DB() *ZkStore

func (*ZkStore) Apply

func (zk *ZkStore) Apply(op *AtomicOp, zkPersistNeeded bool) error

func (*ZkStore) CreateApp

func (zk *ZkStore) CreateApp(app *Application) error

func (*ZkStore) CreateOfferAllocatorItem

func (zk *ZkStore) CreateOfferAllocatorItem(item *OfferAllocatorItem) error

func (*ZkStore) CreateSlot

func (zk *ZkStore) CreateSlot(slot *Slot) error

func (*ZkStore) CreateVersion

func (zk *ZkStore) CreateVersion(appId string, version *Version) error

func (*ZkStore) DeleteApp

func (zk *ZkStore) DeleteApp(appId string) error

func (*ZkStore) DeleteOfferAllocatorItem

func (zk *ZkStore) DeleteOfferAllocatorItem(offerId string) error

func (*ZkStore) DeleteSlot

func (zk *ZkStore) DeleteSlot(appId, slotId string) error

func (*ZkStore) GetApp

func (zk *ZkStore) GetApp(appId string) *Application

func (*ZkStore) GetFrameworkId

func (zk *ZkStore) GetFrameworkId() string

func (*ZkStore) GetSlot

func (zk *ZkStore) GetSlot(appId, slotId string) *Slot

func (*ZkStore) GetVersion

func (zk *ZkStore) GetVersion(appId, versionId string) *Version

func (*ZkStore) ListApps

func (zk *ZkStore) ListApps() []*Application

func (*ZkStore) ListOfferallocatorItems

func (zk *ZkStore) ListOfferallocatorItems() []*OfferAllocatorItem

func (*ZkStore) ListSlots

func (zk *ZkStore) ListSlots(appId string) []*Slot

func (*ZkStore) ListTaskHistory

func (zk *ZkStore) ListTaskHistory(appId, slotId string) []*Task

func (*ZkStore) ListVersions

func (zk *ZkStore) ListVersions(appId string) []*Version

func (*ZkStore) Recover

func (zk *ZkStore) Recover() error

func (*ZkStore) Start

func (zk *ZkStore) Start(ctx context.Context) error

func (*ZkStore) UpdateApp

func (zk *ZkStore) UpdateApp(app *Application) error

func (*ZkStore) UpdateCurrentTask

func (zk *ZkStore) UpdateCurrentTask(appId, slotId string, task *Task) error

func (*ZkStore) UpdateFrameworkId

func (zk *ZkStore) UpdateFrameworkId(frameworkId string) error

func (*ZkStore) UpdateSlot

func (zk *ZkStore) UpdateSlot(appId, slotId string, slot *Slot) error

Jump to

Keyboard shortcuts

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