rest

package
v0.0.0-...-2a91a1d Latest Latest
Warning

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

Go to latest
Published: May 21, 2019 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ManagementClient

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

ManagementClient provides a go wrapper to the management service.

func NewManagementClient

func NewManagementClient(url string) *ManagementClient

NewManagementClient constructs a new ManagementClient instance that constructs a new http.Client.

func NewManagementClientFromExisting

func NewManagementClientFromExisting(client *http.Client, url string) *ManagementClient

NewManagementClientFromExisting builds a ManagementClient instance from an existing http.Client.

func (*ManagementClient) AbortAllJobs

func (c *ManagementClient) AbortAllJobs(ctx context.Context) error

AbortAllJobs issues the request to terminate all currently running jobs managed by the pool that backs the request.

func (*ManagementClient) AbortJob

func (c *ManagementClient) AbortJob(ctx context.Context, job string) error

AbortJob sends the abort signal for a running job to the management service, return any errors from the service. A nil response indicates that the job has been successfully terminated.

func (*ManagementClient) IsRunning

func (c *ManagementClient) IsRunning(ctx context.Context, job string) (bool, error)

IsRunning checks if a job with a specified id is currently running in the remote queue. Check the error value to identify if false response is due to a communication problem with the service or is legitimate.

func (*ManagementClient) ListJobs

func (c *ManagementClient) ListJobs(ctx context.Context) ([]string, error)

ListJobs returns a full list of all running jobs managed by the pool that the service reflects.

type ManagementService

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

ManagementService defines a set of rest routes that make it possible to remotely manage the jobs running in an abortable pool.

func NewManagementService

func NewManagementService(p amboy.AbortableRunner) *ManagementService

NewManagementService returns a service that defines REST routes can manage an abortable pool.

func (*ManagementService) AbortAllJobs

func (s *ManagementService) AbortAllJobs(rw http.ResponseWriter, r *http.Request)

AbortAllJobs is an http.HandlerFunc that sends the signal to abort all running jobs in the pool. May return a 408 (timeout) if the calling context was canceled before the operation returned. Otherwise, this handler returns 200. The body of the response is always empty.

func (*ManagementService) AbortRunningJob

func (s *ManagementService) AbortRunningJob(rw http.ResponseWriter, r *http.Request)

AbortRunningJob is an http.HandlerFunc that terminates the execution of a single running job, returning a 400 response when the job doesn't exist.

func (*ManagementService) App

func (s *ManagementService) App() *gimlet.APIApp

App returns a gimlet app with all of the routes registered.

func (*ManagementService) GetJobStatus

func (s *ManagementService) GetJobStatus(rw http.ResponseWriter, r *http.Request)

GetJobStatus is an http.HandlerFunc reports on the status (running or not running) of a specific job.

func (*ManagementService) ListJobs

func (s *ManagementService) ListJobs(rw http.ResponseWriter, r *http.Request)

ListJobs is an http.HandlerFunc that returns a list of all running jobs in the pool.

type QueueClient

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

QueueClient provides an interface for interacting with a remote amboy Service.

func NewQueueClient

func NewQueueClient(host string, port int, prefix string) (*QueueClient, error)

NewQueueClient takes host, port, and URI prefix information and constructs a new QueueClient.

func NewQueueClientFromExisting

func NewQueueClientFromExisting(client *http.Client, host string, port int, prefix string) (*QueueClient, error)

NewQueueClientFromExisting takes an existing http.Client object and produces a new QueueClient object.

func (*QueueClient) FetchJob

func (c *QueueClient) FetchJob(ctx context.Context, name string) (amboy.Job, error)

FetchJob takes the name of a queue, and returns if possible a representation of that job object.

func (*QueueClient) Host

func (c *QueueClient) Host() string

Host returns the current host.

func (*QueueClient) JobComplete

func (c *QueueClient) JobComplete(ctx context.Context, name string) (bool, error)

JobComplete checks the stats of a job, by name, and returns true if that job is complete. When false, check the second return value to ensure that the job exists in the remote queue.

func (*QueueClient) PendingJobs

func (c *QueueClient) PendingJobs(ctx context.Context) (int, error)

PendingJobs reports on the total number of jobs currently dispatched by the queue to workers.

func (*QueueClient) Port

func (c *QueueClient) Port() int

Port returns the current port value for the QueueClient.

func (*QueueClient) Prefix

func (c *QueueClient) Prefix() string

Prefix accesses the prefix for the client, The prefix is the part of the URI between the end-point and the hostname, of the API.

func (*QueueClient) Running

func (c *QueueClient) Running(ctx context.Context) (bool, error)

Running is true when the underlying queue is running and accepting jobs, and false when the queue is not runner or if there's a problem connecting to the queue.

func (*QueueClient) SetHost

func (c *QueueClient) SetHost(h string) error

SetHost allows callers to change the hostname (including leading "http(s)") for the Client. Returns an error if the specified host does not start with "http".

func (*QueueClient) SetPort

func (c *QueueClient) SetPort(p int) error

SetPort allows callers to change the port used for the client. If the port is invalid, returns an error and sets the port to the default value. (3000)

func (*QueueClient) SetPrefix

func (c *QueueClient) SetPrefix(p string) error

SetPrefix allows callers to modify the prefix, for this client,

func (*QueueClient) SubmitJob

func (c *QueueClient) SubmitJob(ctx context.Context, j amboy.Job) (string, error)

SubmitJob adds a job to a remote queue connected to the rest interface.

func (*QueueClient) Wait

func (c *QueueClient) Wait(ctx context.Context, name string) bool

Wait blocks until the job identified by the name argument is complete. Does not handle the case where a job does not exist.

func (*QueueClient) WaitAll

func (c *QueueClient) WaitAll(ctx context.Context) bool

WaitAll waits for *all* pending jobs in the queue to complete.

type QueueService

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

QueueService is used as a place holder for application state and configuration.

func NewQueueService

func NewQueueService() *QueueService

NewQueueService constructs a new service object. Use the Open() method to initialize the service. The Open and OpenWithOptions methods configure an embedded amboy service. If you use SetQueue you do not need to call an open method.

Use the App() method to get a gimlet Application that you can use to run the service.

func (*QueueService) App

func (s *QueueService) App() *gimlet.APIApp

App provides access to the gimplet.APIApp instance which builds and orchestrates the REST API. Use this method if you want to combine the routes in this QueueService with another service, or add additional routes to support other application functionality.

func (*QueueService) Close

func (s *QueueService) Close()

Close releases resources (i.e. the queue) associated with the service. If you've used SetQueue to define the embedded queue, rather than Open/OpenWithOptions,

func (*QueueService) Create

func (s *QueueService) Create(w http.ResponseWriter, r *http.Request)

Create provides an interface for REST clients to create jobs in the local queue that backs the service.

func (*QueueService) Fetch

func (s *QueueService) Fetch(w http.ResponseWriter, r *http.Request)

Fetch is an http handler that writes a job interchange object to a the response, and allows clients to retrieve jobs from the service.

func (*QueueService) JobStatus

func (s *QueueService) JobStatus(w http.ResponseWriter, r *http.Request)

JobStatus is a http.HandlerFunc that writes a job status document to the request.

func (*QueueService) Open

func (s *QueueService) Open(ctx context.Context) error

Open populates the application and starts the underlying queue. This method sets and initializes a LocalLimitedSize queue implementation, with 2 workers and storage for 256 jobs. Use OpenInfo to have more control over the embedded queue. Use the Close() method on the service to terminate the queue.

func (*QueueService) OpenWithOptions

func (s *QueueService) OpenWithOptions(ctx context.Context, opts QueueServiceOptions) error

OpenWithOptions makes it possible to configure the underlying queue in a service. Use the Close() method on the service to terminate the queue.

func (*QueueService) Queue

func (s *QueueService) Queue() amboy.Queue

Queue provides access to the underlying queue object for the service.

func (*QueueService) SetQueue

func (s *QueueService) SetQueue(q amboy.Queue) error

SetQueue allows callers to inject an alternate queue implementation.

func (*QueueService) Status

func (s *QueueService) Status(w http.ResponseWriter, r *http.Request)

Status defines an http.HandlerFunc that returns health check and current staus status information for the entire service.

func (*QueueService) WaitAll

func (s *QueueService) WaitAll(w http.ResponseWriter, r *http.Request)

WaitAll blocks waiting for all pending jobs in the queue to stop. Has a default timeout of 10 seconds, and returns 408 (request timeout) when the timeout succeeds.

func (*QueueService) WaitJob

func (s *QueueService) WaitJob(w http.ResponseWriter, r *http.Request)

WaitJob waits for a single job to be complete. It takes a timeout argument, which defaults to 10 seconds, and returns 408 (request timeout) if the timeout is reached before the job completes.

type QueueServiceOptions

type QueueServiceOptions struct {
	// ForceTimeout makes it possible to control how long to wait
	// for pending jobs to complete before canceling existing
	// work. If this value is zeroed, the Open operation will
	// close the previous queue and start a new queue, otherwise
	// it will attempt to wait for the specified time before closing
	// the previous queue.
	ForceTimeout time.Duration `bson:"force_timeout,omitempty" json:"force_timeout,omitempty" yaml:"force_timeout,omitempty"`

	// The default queue constructed by Open/OpenWith retains a
	// limited number of completed jobs to avoid unbounded memory
	// growth. This value *must* be specified.
	QueueSize int `bson:"queue_size" json:"queue_size" yaml:"queue_size"`

	// Controls the maximum number of go routines that can service
	// jobs in a queue.
	NumWorkers int `bson:"num_workers" json:"num_workers" yaml:"num_workers"`
}

QueueServiceOptions provides a way to configure resources allocated by a service.

type ReportingClient

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

ReportingClient provides a wrapper for communicating with an amboy rest service for queue reporting. It implements the reporting.Reporter interface and allows you to remotely interact with running jobs on a system.

func NewReportingClient

func NewReportingClient(url string) *ReportingClient

NewReportingClient constructs a ReportingClient instance constructing a new HTTP client.

func NewReportingClientFromExisting

func NewReportingClientFromExisting(client *http.Client, url string) *ReportingClient

NewReportingClientFromExisting constructs a new ReportingClient instance from an existing HTTP Client.

func (*ReportingClient) JobIDsByState

func (c *ReportingClient) JobIDsByState(ctx context.Context, jobType string, filter reporting.CounterFilter) (*reporting.JobReportIDs, error)

JobIDsByState returns a list of job IDs for each job type, for all jobs matching the filter. Filuter value are defined as constants in the reporting package.

func (*ReportingClient) JobStatus

JobStatus a count, by job type, for all jobs that match the Counter filter. CounterFilter values are defined as constants in the reporting package.

func (*ReportingClient) RecentErrors

RecentErrors returns an error report for jobs that have completed in the given window that have had errors. Use the filter to de-duplicate errors. ErrorFilter values are defined as constants in the reporting package.

func (*ReportingClient) RecentJobErrors

func (c *ReportingClient) RecentJobErrors(ctx context.Context, jobType string, dur time.Duration, filter reporting.ErrorFilter) (*reporting.JobErrorsReport, error)

RecentJobErrors returns an error report for jobs of a specific type that have encountered errors that have completed within the specified window. The ErrorFilter values are defined as constants in the reporting package.

func (*ReportingClient) RecentTiming

RecentTiming returns timing data latency or duration of job run time for jobs in the window defined by the duration value. You must specify a timing filter (e.g. Latency or Duration) with a constant defined in the reporting package.

type ReportingService

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

ReportingService wraps a reporter instance as described in the reporting package and provides an HTTP interface for all of the methods provided by the reporter.

func NewReportingService

func NewReportingService(r reporting.Reporter) *ReportingService

NewReportingService constructs a reporting service from the reporter provided.

func (*ReportingService) App

func (s *ReportingService) App() *gimlet.APIApp

App returns a gimlet application with all of the routes configured.

func (*ReportingService) GetJobStatus

func (s *ReportingService) GetJobStatus(rw http.ResponseWriter, r *http.Request)

GetJobStatus is an http.HandlerFunc that provides access to counts of all jobs that match a defined filter.

func (*ReportingService) GetJobStatusByType

func (s *ReportingService) GetJobStatusByType(rw http.ResponseWriter, r *http.Request)

GetJobStatusByType is an http.HandlerFunc that produces a list of job IDs for jobs that match a defined filter.

func (*ReportingService) GetRecentErrors

func (s *ReportingService) GetRecentErrors(rw http.ResponseWriter, r *http.Request)

GetRecentErrors is an http.HandlerFunc that returns an error report including number of errors, total number of jobs, grouped by type, with the error messages. Uses a filter that can optionally remove duplicate errors.

func (*ReportingService) GetRecentErrorsByType

func (s *ReportingService) GetRecentErrorsByType(rw http.ResponseWriter, r *http.Request)

GetRecentErrorsByType is an http.Handlerfunc returns an errors report for only a single type of jobs.

func (*ReportingService) GetRecentTimings

func (s *ReportingService) GetRecentTimings(rw http.ResponseWriter, r *http.Request)

GetRecentTimings is an http.HandlerFunc that produces a report that lists the average runtime (duration) or latency of jobs.

Jump to

Keyboard shortcuts

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