client

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2021 License: Apache-2.0 Imports: 15 Imported by: 2

Documentation

Overview

Package client provides methods for interaction with Boruta REST API server.

Provided BorutaClient type besides implementing boruta.Requests and boruta.Workers interfaces provides few convenient methods that allow to quickly check boruta.Request state, timeout and boruta.Worker state.

Example
package main

import (
	"log"
	"os"
	"time"

	"github.com/SamsungSLAV/boruta"
	"github.com/SamsungSLAV/boruta/http/client"
)

func main() {
	cl := client.NewBorutaClient("http://localhost:1234")

	v, err := cl.Version()
	if err != nil {
		log.Fatalln("unable to check Boruta server version")
	}
	log.Printf("client package version: %s\nserver version: %s\nAPI version: %s (%s)\n",
		v.Client, v.Server, v.API, v.State)

	caps := make(boruta.Capabilities)
	caps["arch"] = "armv7l"
	validAfter := time.Now()
	deadline := validAfter.Add(time.Hour)

	// Create new Boruta request.
	id, err := cl.NewRequest(caps, boruta.Priority(4), boruta.UserInfo{},
		validAfter, deadline)
	if err != nil {
		log.Fatalln("unable to create new request:", err)
	}

	// Check state of created request.
	state, err := cl.GetRequestState(id)
	if err != nil {
		log.Fatalln("unable to check state of request:", err)
	}
	if state == boruta.INPROGRESS {
		// Acquire worker if the request is in "IN PROGRESS" state.
		access, err := cl.AcquireWorker(id)
		if err != nil {
			log.Fatalln("unable to acquire worker:", err)
		}
		log.Println("dryad address:", access.Addr)
		log.Println("dryad username:", access.Username)
		// Connect to dryad using access variable (boruta.AccessInfo type).
		// ...
		timeout, err := cl.GetJobTimeout(id)
		if err != nil {
			log.Fatalln("unable to check timeout of a job:", err)
		}
		log.Println("job will timeout on", timeout)

		select {
		case <-time.After(timeout.Sub(time.Now())):
			log.Fatalln("job timeout passed, prolong access next time")
		default:
			// Do stuff.
			// ...

			// Close request after stuff was done.
			if err = cl.CloseRequest(id); err != nil {
				log.Fatalln("unable to close request", err)
			}
			log.Println("closed request", id)
			os.Exit(0)
		}
	}
	log.Printf("request %d in state %s\n", id, state)
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BorutaClient

type BorutaClient struct {
	boruta.Requests
	boruta.Workers
	// contains filtered or unexported fields
}

BorutaClient handles interaction with specified Boruta server.

func NewBorutaClient

func NewBorutaClient(url string) *BorutaClient

NewBorutaClient provides BorutaClient ready to communicate with specified Boruta server.

cl := NewBorutaClient("http://127.0.0.1:1234")

func (*BorutaClient) AcquireWorker

func (client *BorutaClient) AcquireWorker(reqID boruta.ReqID) (boruta.AccessInfo, error)

AcquireWorker queries Boruta server for information required to access assigned Dryad. Access information may not be available when the call is issued because requests need to have assigned worker.

func (*BorutaClient) CloseRequest

func (client *BorutaClient) CloseRequest(reqID boruta.ReqID) error

CloseRequest closes or cancels Boruta request.

func (*BorutaClient) Deregister

func (client *BorutaClient) Deregister(uuid boruta.WorkerUUID) error

Deregister requests Boruta server to deregister worker with provided UUID. Deregister is intended only for Boruta server administrators.

func (*BorutaClient) GetJobTimeout

func (client *BorutaClient) GetJobTimeout(reqID boruta.ReqID) (time.Time, error)

GetJobTimeout is convenient way to check when Job of a request with given reqID will timeout. The request must be in INPROGRESS state.

func (*BorutaClient) GetRequestInfo

func (client *BorutaClient) GetRequestInfo(reqID boruta.ReqID) (boruta.ReqInfo, error)

GetRequestInfo queries Boruta server for details about given request ID.

func (*BorutaClient) GetRequestState

func (client *BorutaClient) GetRequestState(reqID boruta.ReqID) (boruta.ReqState, error)

GetRequestState is convenient way to check state of a request with given reqID. When error occurs then returned boruta.ReqState will make no sense. Developer should always check for an error before proceeding with actions dependent on request state.

func (*BorutaClient) GetWorkerInfo

func (client *BorutaClient) GetWorkerInfo(uuid boruta.WorkerUUID) (boruta.WorkerInfo, error)

GetWorkerInfo queries Boruta server for information about worker with given UUID.

func (*BorutaClient) GetWorkerState

func (client *BorutaClient) GetWorkerState(uuid boruta.WorkerUUID) (boruta.WorkerState, error)

GetWorkerState is convenient way to check state of a worker with given UUID.

func (*BorutaClient) ListRequests

ListRequests queries Boruta server for list of requests that match given filter. Filter may be empty or nil to get list of all requests. If sorter is nil then the default sorting is used (ascending, by ID). List may be divided into pages. Division is made according to boruta.RequestsPaginator. To iterate through whole list, ListRequests should be called repetedly with ID changed to ID of last (or first if going backwards) request of slice returned by previous call. If paginator is nil then server will use default values. boruta.ListInfo contains information how many requests are in filtered list and how many are left till the end of the list.

func (*BorutaClient) ListWorkers

ListWorkers queries Boruta server for list of workers that are in given groups and have provided capabilities. Setting both caps and groups to empty or nil lists all workers. If sorter is nil then the default sorting is used (ascending, by UUID).

func (*BorutaClient) NewRequest

func (client *BorutaClient) NewRequest(caps boruta.Capabilities,
	priority boruta.Priority, owner boruta.UserInfo, validAfter time.Time,
	deadline time.Time) (boruta.ReqID, error)

NewRequest creates new Boruta request.

func (*BorutaClient) ProlongAccess

func (client *BorutaClient) ProlongAccess(reqID boruta.ReqID) error

ProlongAccess requests Boruta server to extend running time of job. User may need to call this method multiple times as long as access to Dryad is needed. If not called, Boruta server will terminate the tunnel when ReqInfo.Job.Timeout passes, and change state of request to CLOSED.

func (*BorutaClient) SetGroups

func (client *BorutaClient) SetGroups(uuid boruta.WorkerUUID, groups boruta.Groups) error

SetGroups requests Boruta server to change groups of worker with provided UUID. SetGroups is intended only for Boruta server administrators.

func (*BorutaClient) SetState

func (client *BorutaClient) SetState(uuid boruta.WorkerUUID, state boruta.WorkerState) error

SetState requests Boruta server to change state of worker with provided UUID. SetState is intended only for Boruta server administrators.

func (*BorutaClient) UpdateRequest

func (client *BorutaClient) UpdateRequest(reqInfo *boruta.ReqInfo) error

UpdateRequest prepares JSON with fields that should be changed for given request ID.

func (*BorutaClient) Version

func (client *BorutaClient) Version() (*Version, error)

Version provides information about version of Boruta client package, server, REST API version and REST API state.

type Version

type Version struct {
	// Client contains version string of client package.
	Client string
	util.BorutaVersion
}

Version provides information about version of Boruta client package, server, REST API and state of the REST API (devel, stable, deprecated).

Jump to

Keyboard shortcuts

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