metronome

package
v0.0.0-...-58e096f Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2017 License: Apache-2.0 Imports: 16 Imported by: 1

Documentation

Index

Constants

View Source
const (
	HTTPGet    = "GET"
	HTTPPut    = "PUT"
	HTTPDelete = "DELETE"
	HTTPPost   = "POST"
)

Constants to represent HTTP verbs

View Source
const (

	// POST /v1/jobs
	MetronomeAPIJobCreate = "/v1/jobs"
	// DELETE /v1/jobs/$jobId
	MetronomeAPIJobDelete = "/v1/jobs/%s"
	// GET /v1/jobs/$jobId
	MetronomeAPIJobGet = "/v1/jobs/%s"
	// GET /v1/jobs
	MetronomeAPIJobList = "/v1/jobs"
	// PUT /v1/jobs/$jobId
	MetronomeAPIJobUpdate = "/v1/jobs/%s"

	// GET /v1/jobs/$jobId/runs
	MetronomeAPIJobRunList = "/v1/jobs/%s/runs"
	// POST /v1/jobs/$jobId/runs
	MetronomeAPIJobRunStart = "/v1/jobs/%s/runs"
	// GET /v1/jobs/$jobId/runs/$runId
	MetronomeAPIJobRunStatus = "/v1/jobs/%s/runs/%s"
	// POST /v1/jobs/$jobId/runs/$runId/action/stop
	MetronomeAPIJobRunStop = "/v1/jobs/%s/runs/%s/actions/stop"

	// POST /v1/jobs/$jobId/schedules
	MetronomeAPIJobScheduleCreate = "/v1/jobs/%s/schedules"
	// GET /v1/jobs/$jobId/schedules/$scheduleId
	MetronomeAPIJobScheduleStatus = "/v1/jobs/%s/schedules/%s"
	// GET /v1/jobs/$jobId/schedules
	MetronomeAPIJobScheduleList = "/v1/jobs/%s/schedules"
	// DELETE /v1/jobs/$jobId/schedules/$scheduleId
	MetronomeAPIJobScheduleDelete = "/v1/jobs/%s/schedules/%s"
	// PUT /v1/jobs/$jobId/schedules/$scheduleId
	MetronomeAPIJobScheduleUpdate = "/v1/jobs/%s/schedules/%s"
	//  GET  /v1/metrics
	MetronomeAPIMetrics = "/v1/metrics"
	//  GET /v1/ping
	MetronomeAPIPing = "/ping"
)

Constants defining the various metronome endpoints

Variables

This section is empty.

Functions

func ConvertIso8601ToCron

func ConvertIso8601ToCron(isoRep string) (string, error)

ConvertIso8601ToCron - attempts to convert an iso8601, 3 -part date into a cron repre. Experimental

  • only simple cases will work without creating *multiple* schedules

func ImmediateCrontab

func ImmediateCrontab() string

ImmediateCrontab - generates a point in time crontab

func RunOnceNowSchedule

func RunOnceNowSchedule() string

RunOnceNowSchedule will return a schedule that starts immediately, runs once, and runs every 2 minutes until successful

func TwentyFourHoursAgo

func TwentyFourHoursAgo() int64

TwentyFourHoursAgo - return time 24 hours ago

Types

type ActiveRun

type ActiveRun struct {
	ID          string       `json:"id"`
	JobID       string       `json:"jobId"`
	Status      string       `json:"status"`
	CreatedAt   string       `json:"createdAt"`
	CompletedAt interface{}  `json:"completedAt"`
	Tasks       []TaskStatus `json:"tasks"`
}

ActiveRun - undocumented structure returned via api for job runs

type Artifact

type Artifact struct {
	URI        string `json:"uri"`
	Executable bool   `json:"executable"`
	Extract    bool   `json:"extract"`
	Cache      bool   `json:"cache"`
}

Artifact - Metronome Artifact

func (*Artifact) GetURI

func (theArtifact *Artifact) GetURI() string

GetURI - return string copy

func (*Artifact) IsExecutable

func (theArtifact *Artifact) IsExecutable() bool

IsExecutable - is the artifact executable

func (*Artifact) ShouldCache

func (theArtifact *Artifact) ShouldCache() bool

ShouldCache - should the artifact be cached

func (*Artifact) ShouldExtract

func (theArtifact *Artifact) ShouldExtract() bool

ShouldExtract - does the artifact need to be extracted

type Client

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

A Client can make http requests

func (*Client) CreateJob

func (client *Client) CreateJob(job *Job) (*Job, error)

CreateJob - create a metronome job. returns the job or an error

func (*Client) CreateSchedule

func (client *Client) CreateSchedule(jobID string, sched *Schedule) (interface{}, error)

CreateSchedule - assign a schedule to a job POST /v1/jobs/$jobId/schedules

func (*Client) DeleteJob

func (client *Client) DeleteJob(jobID string) (interface{}, error)

DeleteJob - deletes a job by calling metronome api DELETE /v1/jobs/$jobId

func (*Client) DeleteSchedule

func (client *Client) DeleteSchedule(jobID string, schedID string) (interface{}, error)

DeleteSchedule - delete a schedule DELETE /v1/jobs/$jobId/schedules/$scheduleId

func (*Client) GetJob

func (client *Client) GetJob(jobID string) (*Job, error)

GetJob - Gets a job by calling metronome api GET /v1/jobs/$jobId

func (*Client) GetSchedule

func (client *Client) GetSchedule(jobID string, schedID string) (*Schedule, error)

GetSchedule - get a schedule associated with a job GET /v1/jobs/$jobId/schedules/$scheduleId

func (*Client) Jobs

func (client *Client) Jobs() (*[]Job, error)

Jobs - get a list of all jobs by calling metronome api GET /v1/jobs

func (*Client) Metrics

func (client *Client) Metrics() (interface{}, error)

Metrics - returns metrics from the metronome service

GET  /v1/metrics

func (*Client) Ping

func (client *Client) Ping() (*string, error)

Ping - test if the metronome service is running. returns 'pong' on success

GET /v1/ping

func (*Client) RunLs

func (client *Client) RunLs(jobID string) (*[]JobStatus, error)

RunLs - list running jobs - standard

func (*Client) Runs

func (client *Client) Runs(jobID string, since int64) (*Job, error)

Runs - get all the 'runs' of a given job GET /v1/jobs/$jobId/runs

func (*Client) Schedules

func (client *Client) Schedules(jobID string) (*[]Schedule, error)

Schedules - get all schedules GET /v1/jobs/$jobId/schedules

func (*Client) StartJob

func (client *Client) StartJob(jobID string) (interface{}, error)

StartJob - starts a metronome job. Implies that CreateJob was already called. POST /v1/jobs/$jobId/runs

func (*Client) StatusJob

func (client *Client) StatusJob(jobID string, runID string) (*JobStatus, error)

StatusJob - get a job status GET /v1/jobs/$jobId/runs/$runId

func (*Client) StopJob

func (client *Client) StopJob(jobID string, runID string) (interface{}, error)

StopJob - stop a running job. returns and error on failure POST /v1/jobs/$jobId/runs/$runId/action/stop

func (*Client) UpdateJob

func (client *Client) UpdateJob(jobID string, job *Job) (interface{}, error)

UpdateJob - given jobID and new job structure, replace an existing job by calling metronome api PUT /v1/jobs/$jobId

func (*Client) UpdateSchedule

func (client *Client) UpdateSchedule(jobID string, schedID string, sched *Schedule) (interface{}, error)

UpdateSchedule - update an existing schedule associated with a job PUT /v1/jobs/$jobId/schedules/$scheduleId

type Config

type Config struct {
	/* the url for metronome */
	URL string
	/* switch on debugging */
	Debug bool
	/* the timeout for requests */
	RequestTimeout int
	/* allow unverified tls (self-signed certs) defaults to false */
	AllowUnverifiedTLS bool

	AuthToken string
	User      string
	Pw        string
}

A Config defines a client configuration

func NewDefaultConfig

func NewDefaultConfig() Config

NewDefaultConfig returns a default configuration. Helpful for local testing/development.

type Constraint

type Constraint struct {
	Attribute string `json:"attribute"`
	// operator is EQ, LIKE,UNLIKE
	Operator Operator `json:"operator"`
	Value    string   `json:"value"`
}

Constraint - Metronome constraint

func NewConstraint

func NewConstraint(attribute string, op Operator, value string) (*Constraint, error)

NewConstraint - create Metronome constraint

func StrToConstraint

func StrToConstraint(cli string) (*Constraint, error)

StrToConstraint - takes constraint as described in Metronome documentation

func (*Constraint) GetAttribute

func (theConstraint *Constraint) GetAttribute() string

GetAttribute - accessor

func (*Constraint) GetOperator

func (theConstraint *Constraint) GetOperator() Operator

GetOperator - accessor

func (*Constraint) GetValue

func (theConstraint *Constraint) GetValue() string

GetValue - accessor

type Container

type Container struct {
	Type    string              `json:"type,omitempty"`
	Image   string              `json:"image,omitempty"`
	Network string              `json:"network,omitempty"`
	Volumes []map[string]string `json:"volumes,omitempty"`
}

A Container defines a metronome container

type ContainerPath

type ContainerPath string

ContainerPath - type for contraining json values to limited paths spec'd in metronome api

func NewContainerPath

func NewContainerPath(path string) (self ContainerPath, err error)

NewContainerPath - create a new container path that's checked for validity per Metronome's doc

func (*ContainerPath) MarshalJSON

func (cp *ContainerPath) MarshalJSON() ([]byte, error)

MarshalJSON - json interface implementation

func (*ContainerPath) UnmarshalJSON

func (cp *ContainerPath) UnmarshalJSON(raw []byte) error

UnmarshalJSON - json interface implementation. ensure valid path as spec'd by metronome api

type Docker

type Docker struct {
	Image string `json:"image"`
}

Docker - metronome limited docker image

func NewDockerImage

func NewDockerImage(image string) (*Docker, error)

NewDockerImage - create a new image

func (*Docker) GetImage

func (docker *Docker) GetImage() string

GetImage - the docker image

type History

type History struct {
	SuccessCount           int             `json:"successCount"`
	FailureCount           int             `json:"failureCount"`
	LastSuccessAt          string          `json:"lastSuccessAt"`
	LastFailureAt          string          `json:"lastFailureAt"`
	SuccessfulFinishedRuns []HistoryStatus `json:"successfulFinishedRuns"`
	FailedFinishedRuns     []HistoryStatus `json:"failedFinishedRuns"`
}

History - undocumented structure returned by Metronome api for job runs

type HistoryStatus

type HistoryStatus struct {
	ID         string `json:"id"`
	CreatedAt  string `json:"createdAt"`
	FinishedAt string `json:"finishedAt"`
}

HistoryStatus - history outcome of previous jobs

type HistorySummary

type HistorySummary struct {
	SuccessCount  int    `json:"successCount"`
	FailureCount  int    `json:"failureCount"`
	LastSuccessAt string `json:"lastSuccessAt"`
	LastFailureAt string `json:"lastFailureAt"`
}

HistorySummary - undocumented structure returned by Metronome api for job runs

type Job

type Job struct {
	Description    string          `json:"description"`
	ID             string          `json:"id"`
	Labels         *Labels         `json:"labels,omitempty"`
	Run            *Run            `json:"run"`
	Schedules      []*Schedule     `json:"schedules,omitempty"`
	ActiveRuns     []*ActiveRun    `json:"activeRuns,omitempty"`
	History        *History        `json:"history,omitempty"`
	HistorySummary *HistorySummary `json:"historySummary,omitempty"`
}

Job - toplevel metronome structure for creating and managing a job

func NewJob

func NewJob(id string, description string, labels Labels, run *Run) (*Job, error)

NewJob - create a job checking for some required fields

func (*Job) GetDescription

func (theJob *Job) GetDescription() string

GetDescription - get the job description

func (*Job) GetID

func (theJob *Job) GetID() string

GetID - get the job id

func (*Job) GetLabels

func (theJob *Job) GetLabels() *Labels

GetLabels - get the job labels

func (*Job) GetRun

func (theJob *Job) GetRun() *Run

GetRun - the Run structure for the job

func (*Job) SetDescription

func (theJob *Job) SetDescription(desc string) *Job

SetDescription - set the job description.

func (*Job) SetID

func (theJob *Job) SetID(id string) *Job

SetID - the job id

func (*Job) SetLabel

func (theJob *Job) SetLabel(label Labels) *Job

SetLabel - set the job lables

func (*Job) SetRun

func (theJob *Job) SetRun(run *Run) *Job

SetRun - set the run structure

type JobStatus

type JobStatus struct {
	CompletedAt interface{}  `json:"completedAt"`
	CreatedAt   string       `json:"createdAt"`
	ID          string       `json:"id"`
	JobID       string       `json:"jobId"`
	Status      string       `json:"status"`
	Tasks       []TaskStatus `json:"tasks"`
}

JobStatus - represents a metronome job status

type Jobs

type Jobs []Job

Jobs - list of jobs

type Labels

type Labels map[string]string

Labels - list of labels that get converted to environment variables on job

type Metronome

type Metronome interface {
	// POST /v1/jobs
	CreateJob(*Job) (*Job, error)
	// DELETE /v1/jobs/$jobId
	DeleteJob(jobID string) (interface{}, error)
	// GET /v1/jobs/$jobId
	GetJob(jobID string) (*Job, error)
	// GET /v1/jobs
	Jobs() (*[]Job, error)
	// PUT /v1/jobs/$jobId
	UpdateJob(jobID string, job *Job) (interface{}, error)

	Runs(jobID string, statusSince int64) (*Job, error)
	// POST /v1/jobs/$jobId/runs
	StartJob(jobID string) (interface{}, error)
	// GET /v1/jobs/$jobId/runs/$runId
	StatusJob(jobID string, runID string) (*JobStatus, error)
	// POST /v1/jobs/$jobId/runs/$runId/action/stop
	StopJob(jobID string, runID string) (interface{}, error)

	//
	// Schedules
	//
	// POST /v1/jobs/$jobId/schedules
	CreateSchedule(jobID string, new *Schedule) (interface{}, error)
	// GET /v1/jobs/$jobId/schedules/$scheduleId
	GetSchedule(jobID string, schedID string) (*Schedule, error)
	// GET /v1/jobs/$jobId/schedules
	Schedules(jobID string) (*[]Schedule, error)
	// DELETE /v1/jobs/$jobId/schedules/$scheduleId
	DeleteSchedule(jobID string, schedID string) (interface{}, error)
	// PUT /v1/jobs/$jobId/schedules/$scheduleId
	UpdateSchedule(jobID string, schedID string, sched *Schedule) (interface{}, error)

	//  GET  /v1/metrics
	Metrics() (interface{}, error)
	//  GET /v1/ping
	Ping() (*string, error)
}

Metronome represents the client interface for interacting with the metronome API

func NewClient

func NewClient(config Config) (Metronome, error)

NewClient returns a new client, initialzed with the provided config

type MountMode

type MountMode int

MountMode - type for constraining json values to those spec'd in metronome api

const (
	// RO - read-only mount
	RO MountMode = 1 + iota
	// RW - read/write mount
	RW
)

func (*MountMode) MarshalJSON

func (mm *MountMode) MarshalJSON() ([]byte, error)

MarshalJSON - json interface requirement

func (MountMode) String

func (mm MountMode) String() string

String - stringrep

func (*MountMode) UnmarshalJSON

func (mm *MountMode) UnmarshalJSON(raw []byte) error

UnmarshalJSON - json interface implementation. Ensure we have a valid mount value

type Operator

type Operator int

Operator - constrain operator values

const (
	// EQ - Valid Operator values
	EQ Operator = 1 + iota
	// LIKE - operator
	LIKE
	// UNLIKE - operator
	UNLIKE
)

func (*Operator) MarshalJSON

func (theOp *Operator) MarshalJSON() ([]byte, error)

MarshalJSON - implement json interface for marshalling json

func (*Operator) String

func (theOp *Operator) String() string

String - string rep of operator

func (*Operator) UnmarshalJSON

func (theOp *Operator) UnmarshalJSON(raw []byte) error

UnmarshalJSON - hand json unmarshalling

type Placement

type Placement struct {
	Constraints []Constraint `json:"constraints"`
}

Placement - Metronome placement

func (*Placement) GetConstraints

func (thePlacement *Placement) GetConstraints() ([]Constraint, error)

GetConstraints - return constraints

type Restart

type Restart struct {
	ActiveDeadlineSeconds int    `json:"activeDeadlineSeconds"`
	Policy                string `json:"policy"`
}

Restart - structure representing a Metronome structure

func NewRestart

func NewRestart(activeDeadlineSeconds int, policy string) (*Restart, error)

NewRestart - create a valid Restart policy

type Run

type Run struct {
	Artifacts []Artifact `json:"artifacts,omitempty"`
	Cmd       string     `json:"cmd,omitempty"`

	Args           []string          `json:"args,omitempty"`
	Cpus           float64           `json:"cpus"`
	Mem            int               `json:"mem"`
	Disk           int               `json:"disk"`
	Docker         *Docker           `json:"docker,omitempty"`
	Env            map[string]string `json:"env,omitempty"`
	MaxLaunchDelay int               `json:"maxLaunchDelay"`
	Placement      *Placement        `json:"placement,omitempty"`
	Restart        *Restart          `json:"restart,omitempty"`
	User           string            `json:"user,omitempty"`
	Volumes        []Volume          `json:"volumes"`
}

Run - composite structure representing Metronone run

func NewRun

func NewRun(cpus float64, mem int, disk int) (*Run, error)

NewRun - create a run structure needed for a job

func (*Run) AddArg

func (runner *Run) AddArg(item string)

AddArg - appends an argument to the list

func (*Run) GetArgs

func (runner *Run) GetArgs() *[]string

GetArgs - accessor returning the list of arguments

func (*Run) GetArtifacts

func (runner *Run) GetArtifacts() []Artifact

GetArtifacts - accessor returning Artifacts

func (*Run) GetCmd

func (runner *Run) GetCmd() string

GetCmd - accessor for the cmd to run

func (*Run) GetCpus

func (runner *Run) GetCpus() float64

GetCpus - the number of cpus to assign

func (*Run) GetDisk

func (runner *Run) GetDisk() int

GetDisk - accesor returning the disk space to assign

func (*Run) GetDocker

func (runner *Run) GetDocker() *Docker

GetDocker - accessor returning the docker structure if set

func (*Run) GetEnv

func (runner *Run) GetEnv() map[string]string

GetEnv - return the current environment

func (*Run) GetMaxLaunchDelay

func (runner *Run) GetMaxLaunchDelay() int

GetMaxLaunchDelay - accessor returning the maximum launch delay

func (*Run) GetMem

func (runner *Run) GetMem() int

GetMem - accessor returning the amount of memory to use

func (*Run) GetPlacement

func (runner *Run) GetPlacement() *Placement

GetPlacement - get the placement

func (*Run) GetRestart

func (runner *Run) GetRestart() *Restart

GetRestart - the restart structure

func (*Run) GetUser

func (runner *Run) GetUser() string

GetUser - get the user

func (*Run) GetVolumes

func (runner *Run) GetVolumes() *[]Volume

GetVolumes - get job's Volume mappings

func (*Run) SetArgs

func (runner *Run) SetArgs(newargs []string) *Run

SetArgs - replace the entire argument list

func (*Run) SetArtifacts

func (runner *Run) SetArtifacts(artifacts []Artifact) *Run

SetArtifacts - set Artifacts returning pointer to Run so they can be setters can be chained together

func (*Run) SetCmd

func (runner *Run) SetCmd(cmd string) *Run

SetCmd - set the command to run

func (*Run) SetCpus

func (runner *Run) SetCpus(p float64) *Run

SetCpus - set the number of cpus to use

func (*Run) SetDisk

func (runner *Run) SetDisk(p int) *Run

SetDisk - set the amount of disk space to use

func (*Run) SetDocker

func (runner *Run) SetDocker(docker *Docker) *Run

SetDocker - replace the Docker image to use

func (*Run) SetEnv

func (runner *Run) SetEnv(mp map[string]string) *Run

SetEnv - replace the environment to use

func (*Run) SetMaxLaunchDelay

func (runner *Run) SetMaxLaunchDelay(p int) *Run

SetMaxLaunchDelay - set the delay

func (*Run) SetMem

func (runner *Run) SetMem(p int) *Run

SetMem - set the amount of memory to assign

func (*Run) SetPlacement

func (runner *Run) SetPlacement(p *Placement) *Run

SetPlacement - set the job placement

func (*Run) SetRestart

func (runner *Run) SetRestart(restart *Restart) *Run

SetRestart - set the restart structure

func (*Run) SetUser

func (runner *Run) SetUser(user string) *Run

SetUser - set the user

func (*Run) SetVolumes

func (runner *Run) SetVolumes(vols []Volume) *Run

SetVolumes - set the job's Volume mappings

type Schedule

type Schedule struct {
	ID                      string `json:"id"`
	Cron                    string `json:"cron"`
	ConcurrencyPolicy       string `json:"concurrencyPolicy"`
	Enabled                 bool   `json:"enabled"`
	StartingDeadlineSeconds int    `json:"startingDeadlineSeconds"`
	Timezone                string `json:"timezone"`
	NextRunAt               string `json:"nextRunAt,omitempty"`
}

Schedule - represent a metronome schedule

func ImmediateSchedule

func ImmediateSchedule() (*Schedule, error)

ImmediateSchedule - create a metronome schedule

type TaskStatus

type TaskStatus struct {
	ID        string `json:"id"`
	StartedAt string `json:"startedAt"`
	Status    string `json:"status"`
}

TaskStatus - status of currently running task representing job

type Volume

type Volume struct {
	// minlength 1; pattern: ^/[^/].*$
	ContainerPath ContainerPath `json:"containerPath"`
	HostPath      string        `json:"hostPath"`
	// Values: RW,RO
	Mode MountMode `json:"mode"`
}

Volume - structure representing a Metronome Volume validated types

func NewVolume

func NewVolume(rawPath string, hostPath string, modestr string) (*Volume, error)

NewVolume - creates a new volume from raw strings

Jump to

Keyboard shortcuts

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