objects

package
v0.0.0-...-a69e935 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2019 License: Apache-2.0 Imports: 38 Imported by: 52

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Objs []base.Object

Objs is a global list of storage objects. Every storage object will be added using an init method to this list. This list will be used when creating the ORM client.

Functions

func GenerateTestCassandraConfig

func GenerateTestCassandraConfig() *cassandra.Config

GenerateTestCassandraConfig generates a test config for local C* client This is meant for sharing testing code only, not for production

func InitHostInfoOps

func InitHostInfoOps(s *Store)

InitHostInfoOps initializes HostInfoOps singleton

func MigrateSchema

func MigrateSchema(conf *cassandra.Config)

MigrateSchema will migrate DB schema on the peloton_test keyspace.

Types

type ActiveJobsObject

type ActiveJobsObject struct {
	// base.Object DB specific annotations.
	base.Object `cassandra:"name=active_jobs, primaryKey=((shard_id), job_id)"`
	// Shard id of the active job.
	ShardID *base.OptionalUInt64 `column:"name=shard_id"`
	// Job id of the active job.
	JobID *base.OptionalString `column:"name=job_id"`
}

ActiveJobsObject corresponds to a row in active_jobs table.

type ActiveJobsOps

type ActiveJobsOps interface {
	// Create inserts a jobID in the active_job table.
	Create(
		ctx context.Context,
		id *peloton.JobID,
	) error

	// GetAll retrieves all the job ids from the active_jobs table.
	GetAll(ctx context.Context) ([]*peloton.JobID, error)

	// Delete removes the job from the active_jobs table.
	Delete(ctx context.Context, jobID *peloton.JobID) error
}

ActiveJobsOps provides methods for manipulating active_jobs table.

func NewActiveJobsOps

func NewActiveJobsOps(s *Store) ActiveJobsOps

NewActiveJobsOps constructs a ActiveJobsOps object for provided Store.

type HostInfoObject

type HostInfoObject struct {
	// DB specific annotations.
	base.Object `cassandra:"name=host_info, primaryKey=((hostname))"`
	// Hostname of the host.
	Hostname *base.OptionalString `column:"name=hostname"`
	// IP address of the host.
	IP string `column:"name=ip"`
	// HostState of the host.
	State string `column:"name=state"`
	// GoalState of the host.
	GoalState string `column:"name=goal_state"`
	// Labels of the host.
	Labels string `column:"name=labels"`
	// Current host Pool for the host.
	// This will indicate which host pool this host belongs to.
	CurrentPool string `column:"name=current_pool"`
	// Desired host pool for the host
	// This will indicate which host pool this host should be.
	DesiredPool string `column:"name=desired_pool"`
	// Last update time of the host maintenance.
	UpdateTime time.Time `column:"name=update_time"`
}

HostInfoObject corresponds to a row in host_info table.

type HostInfoOps

type HostInfoOps interface {
	// Create inserts a row in the table.
	Create(
		ctx context.Context,
		hostname string,
		ip string,
		state hostpb.HostState,
		goalState hostpb.HostState,
		labels map[string]string,
		currentPool string,
		desiredPool string,
	) error

	// Get retrieves the row based on the primary key from the table.
	Get(
		ctx context.Context,
		hostname string,
	) (*hostpb.HostInfo, error)

	// GetAll retrieves all rows from the table (with no selection on any key).
	GetAll(ctx context.Context) ([]*hostpb.HostInfo, error)

	// UpdateState updates the state of an object in the table.
	UpdateState(
		ctx context.Context,
		hostname string,
		state hostpb.HostState,
	) error

	// UpdateGoalState updates the goal state of an object in the table.
	UpdateGoalState(
		ctx context.Context,
		hostname string,
		goalState hostpb.HostState,
	) error

	// UpdateLables updates the labels an object in the table.
	UpdateLabels(
		ctx context.Context,
		hostname string,
		labels map[string]string,
	) error

	// UpdatePool updates the current & desired host pool of an object
	// in the table.
	UpdatePool(
		ctx context.Context,
		hostname string,
		currentPool string,
		desiredPool string,
	) error

	// UpdateDesiredPool updates the desired host pool of an object in the table.
	UpdateDesiredPool(
		ctx context.Context,
		hostname string,
		desiredPool string,
	) error
	// Delete removes an object from the table based on primary key.
	Delete(ctx context.Context, hostname string) error

	// CompareAndSet compares and sets the host info fields
	CompareAndSet(
		ctx context.Context,
		hostname string,
		hostInfoDiff common.HostInfoDiff,
		compareFields common.HostInfoDiff,
	) error
}

HostInfoOps provides methods for manipulating host_maintenance table.

func GetHostInfoOps

func GetHostInfoOps() HostInfoOps

GetHostInfoOps returns the HostInfoOps singleton object.

type JobConfigObject

type JobConfigObject struct {
	// DB specific annotations
	base.Object `cassandra:"name=job_config, primaryKey=((job_id), version)"`

	// JobID of the job
	JobID string `column:"name=job_id"`
	// Number of task instances
	Version uint64 `column:"name=version"`
	// Config of the job
	Config []byte `column:"name=config"`
	// Config AddOn field for the job
	ConfigAddOn []byte `column:"name=config_addon"`
	// Spec of the job
	Spec []byte `column:"name=spec"`
	// API version of the job. This would be used for debugging.
	ApiVersion string `column:"name=api_version"`
	// Creation time of the job
	CreationTime time.Time `column:"name=creation_time"`
}

JobConfigObject corresponds to a row in job_config table.

type JobConfigOps

type JobConfigOps interface {
	// Create inserts a row in the table.
	Create(
		ctx context.Context,
		id *peloton.JobID,
		config *job.JobConfig,
		configAddOn *models.ConfigAddOn,
		spec *stateless.JobSpec,
		version uint64,
	) error

	// GetCurrentVersion retrieves current version of job_config
	GetCurrentVersion(
		ctx context.Context,
		id *peloton.JobID,
	) (*job.JobConfig, *models.ConfigAddOn, error)

	// Get retrieves a row from the table.
	Get(
		ctx context.Context,
		id *peloton.JobID,
		version uint64,
	) (*job.JobConfig, *models.ConfigAddOn, error)

	// Get retrieves a row from the job config table and returns the
	// unmarshalled blobs in form of a JobConfigOpsResult object.
	GetResult(
		ctx context.Context,
		id *peloton.JobID,
		version uint64,
	) (*JobConfigOpsResult, error)

	// GetResultCurrentVersion retrieves current version of job_config
	GetResultCurrentVersion(
		ctx context.Context,
		id *peloton.JobID,
	) (*JobConfigOpsResult, error)

	// Delete removes an object from the table.
	Delete(ctx context.Context, id *peloton.JobID, version uint64) error
}

JobConfigOps provides methods for manipulating job_config table.

func NewJobConfigOps

func NewJobConfigOps(s *Store) JobConfigOps

NewJobConfigOps constructs a jobConfigOps object for provided Store.

type JobConfigOpsResult

type JobConfigOpsResult struct {
	// JobConfig is the unmarshalled v0 job config
	JobConfig *job.JobConfig
	// ConfigAddOn is the unmarshalled config addon
	ConfigAddOn *models.ConfigAddOn
	// JobSpec is the unmarshalled v1alpha job spec
	JobSpec *stateless.JobSpec
	// ApiVersion contains the API version string
	ApiVersion string
}

JobConfigOpsResult contains the unmarshalled result of a job_config Get() From this object, the caller can retrieve v0 job config, v1alpha job spec as well as config addon.

type JobIndexObject

type JobIndexObject struct {
	// DB specific annotations
	base.Object `cassandra:"name=job_index, primaryKey=((job_id))"`

	// JobID of the job
	JobID *base.OptionalString `column:"name=job_id"`
	// Type of job
	JobType uint32 `column:"name=job_type"`

	// Name of the job
	Name string `column:"name=name"`
	// Owner of the job
	Owner string `column:"name=owner"`
	// Resource-pool to which the job belongs
	RespoolID string `column:"name=respool_id"`

	// Configuration of the job
	Config string `column:"name=config"`
	// Number of task instances
	InstanceCount uint32 `column:"name=instance_count"`
	// Labels for the job
	Labels string `column:"name=labels"`

	// Runtime info of the job
	RuntimeInfo string `column:"name=runtime_info"`
	// State of the job
	State string `column:"name=state"`

	// Creation time of the job
	CreationTime time.Time `column:"name=creation_time"`
	// Start time of the job
	StartTime time.Time `column:"name=start_time"`
	// Completion time of the job
	CompletionTime time.Time `column:"name=completion_time"`
	// Time when job was updated
	UpdateTime time.Time `column:"name=update_time"`
	// Sla of the job
	SLA string `column:"name=sla"`
}

JobIndexObject corresponds to a row in job_index table.

func (*JobIndexObject) ToJobSummary

func (j *JobIndexObject) ToJobSummary() (*job.JobSummary, error)

ToJobSummary generates a JobSummary from the JobIndexObject

type JobIndexOps

type JobIndexOps interface {
	// Create inserts a row in the table.
	Create(
		ctx context.Context,
		id *peloton.JobID,
		config *job.JobConfig,
		runtime *job.RuntimeInfo,
	) error

	// Get retrieves a row from the table.
	Get(ctx context.Context, id *peloton.JobID) (*JobIndexObject, error)

	// GetAll returns the job summaries of all the jobs.
	GetAll(ctx context.Context) ([]*job.JobSummary, error)

	// GetSummary returns a JobSummary for a row in the table
	GetSummary(ctx context.Context, id *peloton.JobID) (*job.JobSummary, error)

	// Update modifies an object in the table.
	Update(
		ctx context.Context,
		id *peloton.JobID,
		config *job.JobConfig,
		runtime *job.RuntimeInfo,
	) error

	// Delete removes an object from the table.
	Delete(ctx context.Context, id *peloton.JobID) error
}

JobIndexOps provides methods for manipulating job_index table.

func NewJobIndexOps

func NewJobIndexOps(s *Store) JobIndexOps

NewJobIndexOps constructs a JobIndexOps object for provided Store.

type JobNameToIDObject

type JobNameToIDObject struct {
	// DB specific annotations
	base.Object `cassandra:"name=job_name_to_id, primaryKey=((job_name), update_time)"`

	// Name of the job
	JobName string `column:"name=job_name"`
	// Update time of the job
	UpdateTime *base.OptionalString `column:"name=update_time"`
	// JobID of the job
	JobID string `column:"name=job_id"`
}

JobNameToIDObject corresponds to a row in job_name_to_id table.

type JobNameToIDOps

type JobNameToIDOps interface {
	// Create inserts a row in the table.
	Create(
		ctx context.Context,
		jobName string,
		id *peloton.JobID,
	) error

	// GetAll retrieves a row from the table.
	GetAll(
		ctx context.Context,
		jobName string,
	) ([]*JobNameToIDObject, error)
}

JobNameToIDOps provides methods for manipulating job_name_to_id table.

func NewJobNameToIDOps

func NewJobNameToIDOps(s *Store) JobNameToIDOps

NewJobNameToIDOps constructs a JobNameToIDOps object for provided Store.

type JobRuntimeObject

type JobRuntimeObject struct {
	// DB specific annotations
	base.Object `cassandra:"name=job_runtime, primaryKey=((job_id))"`

	// JobID of the job
	JobID string `column:"name=job_id"`
	// RuntimeInfo of the job
	RuntimeInfo []byte `column:"name=runtime_info"`
	// Current state of the job
	State string `column:"name=state"`
	// Update time of the job
	UpdateTime time.Time `column:"name=update_time"`
}

JobRuntimeObject corresponds to a row in job_config table.

type JobRuntimeOps

type JobRuntimeOps interface {
	// Upsert inserts/updates a row in the table.
	Upsert(
		ctx context.Context,
		id *peloton.JobID,
		runtime *job.RuntimeInfo,
	) error

	// Get retrieves a row from the table.
	Get(
		ctx context.Context,
		id *peloton.JobID,
	) (*job.RuntimeInfo, error)

	// Delete removes an object from the table.
	Delete(
		ctx context.Context,
		id *peloton.JobID,
	) error
}

JobRuntimeOps provides methods for manipulating job_config table.

func NewJobRuntimeOps

func NewJobRuntimeOps(s *Store) JobRuntimeOps

NewJobRuntimeOps constructs a jobRuntimeOps object for provided Store.

type JobUpdateEventsObject

type JobUpdateEventsObject struct {
	// base.Object DB specific annotations
	base.Object `cassandra:"name=job_update_events, primaryKey=((update_id),create_time)"`
	// UpdateID of the update (uuid)
	UpdateID string `column:"name=update_id"`
	// Type of the job update
	Type string `column:"name=type"`
	// State of the job update
	State string `column:"name=state"`
	// CreateTime of the job update events
	CreateTime *base.OptionalString `column:"name=create_time"`
}

JobUpdateEventsObject corresponds to a row in job_update_events table.

type JobUpdateEventsOps

type JobUpdateEventsOps interface {
	// Create upserts single job state state change for a job.
	Create(
		ctx context.Context,
		updateID *peloton.UpdateID,
		updateType models.WorkflowType,
		updateState update.State,
	) error

	// GetAll returns job update events for an update.
	// Update state events are sorted by
	// reverse order of time of event.
	GetAll(
		ctx context.Context,
		updateID *peloton.UpdateID,
	) ([]*stateless.WorkflowEvent, error)

	// Delete deletes job update events for an update of a job
	Delete(
		ctx context.Context,
		updateID *peloton.UpdateID,
	) error
}

JobUpdateEventsOps provides methods for manipulating job_update_events table.

func NewJobUpdateEventsOps

func NewJobUpdateEventsOps(s *Store) JobUpdateEventsOps

NewJobUpdateEventsOps constructs a JobUpdateEventsOps object for provided Store.

type PodEventsObject

type PodEventsObject struct {
	// base.Object DB specific annotations
	base.Object `cassandra:"name=pod_events, primaryKey=((job_id,instance_id), run_id, update_time)"`
	// JobID of the job (uuid)
	JobID string `column:"name=job_id"`
	// InstanceID of the pod event
	InstanceID uint32 `column:"name=instance_id"`
	// RunID of the pod event
	RunID *base.OptionalUInt64 `column:"name=run_id"`
	// UpdateTime of the pod event
	UpdateTime *base.OptionalString `column:"name=update_time"`
	// ActualState of the pod event
	ActualState string `column:"name=actual_state"`
	// AgentID of the pod event
	AgentID string `column:"name=agent_id"`
	// ConfigVersion of the pod event
	ConfigVersion uint64 `column:"name=config_version"`
	// DesiredConfigVersion of the pod event
	DesiredConfigVersion uint64 `column:"name=desired_config_version"`
	// DesiredRunID of the pod event
	DesiredRunID uint64 `column:"name=desired_run_id"`
	// GoalState of the pod event
	GoalState string `column:"name=goal_state"`
	// Healthy of the pod event
	Healthy string `column:"name=healthy"`
	// Hostname of the pod event
	Hostname string `column:"name=hostname"`
	// Message of the pod event
	Message string `column:"name=message"`
	// PodStatus of the pod event
	PodStatus []byte `column:"name=pod_status"`
	// PreviousRunID of the pod event
	PreviousRunID uint64 `column:"name=previous_run_id"`
	// Reason of the pod event
	Reason string `column:"name=reason"`
	// VolumeID of the pod event
	VolumeID string `column:"name=volumeid"`
}

PodEventsObject corresponds to a row in pod_events table.

type PodEventsOps

type PodEventsOps interface {
	// Add upserts single pod state change for a Job -> Instance -> Run.
	// Task state events are sorted by
	// reverse chronological run_id and time of event.
	Create(
		ctx context.Context,
		jobID *peloton.JobID,
		instanceID uint32,
		runtime *task.RuntimeInfo,
	) error

	// Get returns pod events for a Job + Instance + PodID (optional)
	// Pod events are sorted by PodID + Timestamp
	GetAll(
		ctx context.Context,
		jobID string,
		instanceID uint32,
		podID ...string,
	) ([]*task.PodEvent, error)
}

PodEventsOps provides methods for manipulating pod_events table.

func NewPodEventsOps

func NewPodEventsOps(s *Store) PodEventsOps

NewPodEventsOps constructs a PodEventsOps object for provided Store.

type ResPoolObject

type ResPoolObject struct {
	// base.Object DB specific annotations.
	base.Object `cassandra:"name=respools, primaryKey=((respool_id))"`
	// RespoolID is the ID of the resource pool being created.
	RespoolID *base.OptionalString `column:"name=respool_id"`
	// RespoolConfig contains the resource pool's basic config information.
	RespoolConfig string `column:"name=respool_config"`
	// Owner of the resource pool.
	Owner string `column:"name=owner"`
	// Timestamp of the resource pool when it's created.
	CreationTime time.Time `column:"name=creation_time"`
	// Most recent timestamp when resource pool is updated.
	UpdateTime time.Time `column:"name=update_time"`
}

ResPoolObject corresponds to a row in respools table.

type ResPoolOps

type ResPoolOps interface {
	// Create inserts a new respool in the table.
	Create(
		ctx context.Context,
		id *peloton.ResourcePoolID,
		config *respool.ResourcePoolConfig,
		owner string,
	) error

	// GetAll gets all the resource pool configs.
	GetAll(
		ctx context.Context,
	) (map[string]*respool.ResourcePoolConfig, error)

	// Update modifies the respool in the table.
	Update(
		ctx context.Context,
		id *peloton.ResourcePoolID,
		config *respool.ResourcePoolConfig,
	) error

	// Delete removes the respool from the table.
	Delete(
		ctx context.Context,
		id *peloton.ResourcePoolID,
	) error

	// GetResult retrieves the ResPoolObject from the table.
	GetResult(
		ctx context.Context,
		respoolId string,
	) (*ResPoolOpsResult, error)
}

ResPoolOps provides methods for manipulating respool table.

func NewResPoolOps

func NewResPoolOps(s *Store) ResPoolOps

NewResPoolOps constructs a ResPoolOps object for provided Store.

type ResPoolOpsResult

type ResPoolOpsResult struct {
	// Timestamp of the resource pool when it's created.
	CreationTime time.Time
	// Owner of the resource pool.
	Owner string
	// RespoolConfig is the unmarshalled respool config
	RespoolConfig *respool.ResourcePoolConfig
}

ResPoolOpsResult contains the unmarshalled result of a respool_config Get() From this object, the caller can retrieve respool config.

type SecretInfoObject

type SecretInfoObject struct {
	// DB specific annotations
	base.Object `cassandra:"name=secret_info, primaryKey=((secret_id), valid)"`
	// SecretID is the ID of the secret being created
	SecretID string `column:"name=secret_id"`
	// JobID of the job for which the secret is created
	JobID string `column:"name=job_id"`
	// Container mount path of this secret
	Path string `column:"name=path"`
	// Secret Data (base64 encoded string)
	Data string `column:"name=data"`
	// Creation time of the secret
	CreationTime time.Time `column:"name=creation_time"`
	// Version of this secret
	Version int64 `column:"name=version"`
	// This flag indicates that the secret is valid or invalid
	Valid bool `column:"name=valid"`
}

SecretInfoObject corresponds to a peloton secret. All fields should be exported. SecretInfoObject contains base.Object which has ORM annotations that describe the secret_info table and each column name as well as primary key information. This is used by ORM when creating DB queries.

func (*SecretInfoObject) ToProto

func (s *SecretInfoObject) ToProto() *peloton.Secret

ToProto returns the unmarshaled *peloton.Secret

type SecretInfoOps

type SecretInfoOps interface {
	// Create inserts the SecretInfoObject in the table.
	CreateSecret(
		ctx context.Context,
		jobID string,
		now time.Time,
		secretID, secretString, secretPath string,
	) error

	// Get retrieves the SecretInfoObject from the table.
	GetSecret(
		ctx context.Context,
		secretID string,
	) (*SecretInfoObject, error)

	// Update modifies the SecretInfoObject in the table.
	UpdateSecretData(
		ctx context.Context,
		secretID, secretString string,
	) error

	// Delete removes the SecretInfoObject from the table.
	DeleteSecret(
		ctx context.Context,
		secretID string,
	) error
}

SecretInfoOps provides methods for manipulating secret table.

func NewSecretInfoOps

func NewSecretInfoOps(s *Store) SecretInfoOps

NewSecretInfoOps constructs a SecretInfoOps object for provided Store.

type Store

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

Store contains ORM client as well as metrics

func NewCassandraStore

func NewCassandraStore(
	config *cassandra.Config,
	scope tally.Scope,
) (*Store, error)

NewCassandraStore creates a new Cassandra storage client

type TaskConfigObject

type TaskConfigObject struct {
	// base.Object DB specific annotations
	base.Object `cassandra:"name=task_config, primaryKey=((job_id),version,instance_id)"`
	// JobID of the job which the task belongs to (uuid)
	JobID string `column:"name=job_id"`
	// Version of the config
	Version uint64 `column:"name=version"`
	// InstanceID of the task
	InstanceID int64 `column:"name=instance_id"`
	// Config of the task config
	Config []byte `column:"name=config"`
	// ConfigAddOn of the task config
	ConfigAddOn []byte `column:"name=config_addon"`
	// CreationTime of the task config
	CreationTime time.Time `column:"name=creation_time"`
}

TaskConfigObject corresponds to a row in task_config table. This is a legacy table to which nothing should be written, only used for reading.

type TaskConfigV2Object

type TaskConfigV2Object struct {
	// base.Object DB specific annotations
	base.Object `cassandra:"name=task_config_v2, primaryKey=((job_id,version,instance_id))"`
	// JobID of the job which the task belongs to (uuid)
	JobID string `column:"name=job_id"`
	// Version of the config
	Version uint64 `column:"name=version"`
	// InstanceID of the task
	InstanceID int64 `column:"name=instance_id"`
	// Config of the task config
	Config []byte `column:"name=config"`
	// ConfigAddOn of the task config
	ConfigAddOn []byte `column:"name=config_addon"`
	// CreationTime of the task config
	CreationTime time.Time `column:"name=creation_time"`
	// Spec of the task config
	Spec []byte `column:"name=spec"`
	// APIVersion of the task config
	APIVersion string `column:"name=api_version"`
}

TaskConfigV2Object corresponds to a row in task_config_v2 table.

type TaskConfigV2Ops

type TaskConfigV2Ops interface {
	// Create creates task config with version number for a task
	Create(
		ctx context.Context,
		id *peloton.JobID,
		instanceID int64,
		taskConfig *pbtask.TaskConfig,
		configAddOn *models.ConfigAddOn,
		podSpec *pbpod.PodSpec,
		version uint64,
	) error

	// GetPodSpec returns the pod spec of a task config
	GetPodSpec(
		ctx context.Context,
		id *peloton.JobID,
		instanceID uint32,
		version uint64,
	) (*pbpod.PodSpec, error)

	// GetTaskConfig returns the task specific config
	GetTaskConfig(
		ctx context.Context,
		id *peloton.JobID,
		instanceID uint32,
		version uint64,
	) (*pbtask.TaskConfig, *models.ConfigAddOn, error)
}

TaskConfigV2Ops provides methods for manipulating task_config_v2 table.

func NewTaskConfigV2Ops

func NewTaskConfigV2Ops(s *Store) TaskConfigV2Ops

NewTaskConfigV2Ops constructs a TaskConfigV2Ops object for provided Store.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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