iron

package
v0.85.0 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2024 License: MIT Imports: 20 Imported by: 10

README

Using the Iron API client

HSDP uses Iron.io for container scheduling. This API client implements a basic set of functionality to create code definitions and queue tasks. The focus is on Docker code packages.

Registering a docker image

package main

import (
        "fmt"
        "github.com/philips-software/go-hsdp-api/iron"
)

var (
    projectID = "yourIronProjectID"
    projectToken = "yourIronProjectToken"
    clusterID = "yourIronClusterID"
)

func main() {
        client, err := iron.NewClient(&iron.Config{
                ProjectID: projectID,
                Token:     projectToken,
                ClusterInfo: []iron.ClusterInfo{
                        {
                                ClusterID: clusterID,
                        },
                },
        })
        if err != nil {
                fmt.Printf("Error creating IRON client: %v\n", err)
                return
        }
        result, resp, err := client.Codes.CreateOrUpdateCode(iron.Code{
                Name:  "mytest",
                Image: "loafoe/siderite:latest",
        })
        fmt.Printf("%v %v %v\n", result, resp, err)
}

Queueing a task

package main

import (
        "fmt"
        "github.com/philips-software/go-hsdp-api/iron"
)

var (
    projectID = "yourIronProjectID"
    projectToken = "yourIronProjectToken"
    clusterID = "yourIronClusterID"
    taskName = ""
)

func main() {
        client, err := iron.NewClient(&iron.Config{
                ProjectID: projectID,
                Token:     projectToken,
                ClusterInfo: []iron.ClusterInfo{
                        {
                                ClusterID: clusterID,
                        },
                },
        })
        if err != nil {
                fmt.Printf("Error creating IRON client: %v\n", err)
                return
        }
        result, resp, err := client.Tasks.QueueTask(iron.Task{
                CodeName:  "mytask",
                Payload:   `{"foo": "bar"}`,
        })
        fmt.Printf("%v %v %v\n", result, resp, err)
}

Encryption

Some Iron clusters expect the Payload of a task to be encrypted. You can use the iron.EncryptPayload function for this.

Documentation

Overview

Package iron provides support for HSDP Iron services

Index

Constants

View Source
const (
	IronBaseURL = "https://worker-aws-us-east-1.iron.io/"
)

Variables

View Source
var (
	ErrBaseIRONURLCannotBeEmpty = errors.New("base IRON URL cannot be empty")
	ErrNotImplemented           = errors.New("not implemented")
	ErrNotFound                 = errors.New("not found")
	ErrInvalidDockerCredentials = errors.New("invalid docker credentials. all fields required")
	ErrNoPublicKey              = errors.New("no public key present")
)

Functions

func DecryptPayload added in v0.38.0

func DecryptPayload(privKey []byte, payload string) ([]byte, error)

DecryptPayload decrypts a base64 encoded payload using private key

func EncryptPayload

func EncryptPayload(publicKey []byte, pbytes []byte) (string, error)

EncryptPayload encrypts pbytes using publicKey

func FormatBrokenPubkey

func FormatBrokenPubkey(pubkey []byte) []byte

FormatBrokenPubkey fixes to broken service broker pubkey format

Types

type Client

type Client struct {

	// User agent used when communicating with the HSDP IAM API.
	UserAgent string

	Tasks     *TasksServices
	Codes     *CodesServices
	Clusters  *ClustersServices
	Schedules *SchedulesServices
	// contains filtered or unexported fields
}

A Client manages communication with IronIO

func NewClient

func NewClient(config *Config) (*Client, error)

NewClient returns a new HSDP Iron API client. If a nil httpClient is provided, http.DefaultClient will be used. A configured IAM client must be provided as well

func (*Client) Close

func (c *Client) Close()

Close releases allocated resources of clients

func (*Client) Path

func (c *Client) Path(components ...string) string

func (*Client) SetBaseIronURL

func (c *Client) SetBaseIronURL(urlStr string) error

SetBaseIronURL sets the base URL for API requests to a custom endpoint. urlStr should always be specified with a trailing slash.

type Cluster

type Cluster struct {
	ID               string        `json:"id"`
	Name             string        `json:"name"`
	UserID           string        `json:"user_id"`
	Memory           int64         `json:"memory"`
	DiskSpace        int64         `json:"disk_space"`
	CPUShare         int           `json:"cpu_share"`
	SharedTo         []ClusterUser `json:"shared_to"`
	RunnersTotal     int           `json:"runners_total"`
	RunnersAvailable int           `json:"runners_available"`
	Machines         []Machine     `json:"machines"`
}

Cluster describes an Iron cluster

type ClusterInfo

type ClusterInfo struct {
	ClusterID   string `cloud:"cluster_id" json:"cluster_id"`
	ClusterName string `cloud:"cluster_name" json:"cluster_name"`
	Pubkey      string `cloud:"pubkey" json:"pubkey"`
	UserID      string `cloud:"user_id" json:"user_id"`
}

ClusterInfo contains details on an Iron cluster

func (ClusterInfo) Encrypt added in v0.19.0

func (c ClusterInfo) Encrypt(payload []byte) (string, error)

type ClusterStats

type ClusterStats struct {
	RunnersTotal     int       `json:"runners_total"`
	RunnersAvailable int       `json:"runners_available"`
	Queued           int       `json:"queued"`
	Ewma             int       `json:"ewma"`
	EwmaBeta         int       `json:"ewma_beta"`
	Instances        []Machine `json:"instances"`
}

type ClusterUser

type ClusterUser struct {
	UserID    string    `json:"user_id"`
	ClusterID string    `json:"cluster_id"`
	UpdatedAt time.Time `json:"updated_at"`
	Name      string    `json:"name"`
	Email     string    `json:"email"`
}

ClusterUser can share resources on a cluster

type ClustersServices

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

ClustersServices implements API calls to get details on Iron clusters. As HSDP Iron clusters are not user serviceable only informational API calls are implemented

func (*ClustersServices) GetCluster

func (c *ClustersServices) GetCluster(clusterID string) (*Cluster, *Response, error)

GetCluster gets cluster details

func (*ClustersServices) GetClusterStats

func (c *ClustersServices) GetClusterStats(clusterID string) (*ClusterStats, *Response, error)

GetClusterStats gets cluster statistics

func (*ClustersServices) GetClusters

func (c *ClustersServices) GetClusters() (*[]Cluster, *Response, error)

GetClusters gets the list of available clusters In some cases a token might not have the proper scope to retrieve a list of clusters in which case the list will be empty

type Code

type Code struct {
	ID              string     `json:"id,omitempty"`
	CreatedAt       *time.Time `json:"created_at,omitempty"`
	ProjectID       string     `json:"project_id,omitempty"`
	Name            string     `json:"name"`
	Image           string     `json:"image"`
	LatestChecksum  string     `json:"latest_checksum,omitempty"`
	Rev             int        `json:"rev,omitempty"`
	LatestHistoryID string     `json:"latest_history_id,omitempty"`
	LatestChange    *time.Time `json:"latest_change,omitempty"`
}

Code describes a Iron code package

type CodesServices

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

func (*CodesServices) CreateOrUpdateCode

func (c *CodesServices) CreateOrUpdateCode(code Code) (*Code, *Response, error)

CreateOrUpdateCode creates or updates code packages on Iron which can be used to run tasks

func (*CodesServices) DeleteCode

func (c *CodesServices) DeleteCode(codeID string) (bool, *Response, error)

DeleteCode deletes a code from Iron

func (*CodesServices) DockerLogin

func (c *CodesServices) DockerLogin(creds DockerCredentials) (bool, *Response, error)

DockerLogin stores private Docker registry credentials so Iron can fetch images when needed

func (*CodesServices) GetCode

func (c *CodesServices) GetCode(codeID string) (*Code, *Response, error)

func (*CodesServices) GetCodes

func (c *CodesServices) GetCodes() (*[]Code, *Response, error)

type Config

type Config struct {
	BaseURL     string        `cloud:"-" json:"base_url,omitempty"`
	Debug       bool          `cloud:"-" json:"-"`
	DebugLog    io.Writer     `cloud:"-" json:"-"`
	ClusterInfo []ClusterInfo `cloud:"cluster_info" json:"cluster_info"`
	Email       string        `cloud:"email" json:"email"`
	Password    string        `cloud:"password" json:"password"`
	Project     string        `cloud:"project" json:"project"`
	ProjectID   string        `cloud:"project_id" json:"project_id"`
	Token       string        `cloud:"token" json:"token"`
	UserID      string        `cloud:"user_id" json:"user_id"`
}

Config contains the configuration of a client

type DockerCredentials

type DockerCredentials struct {
	Email         string `json:"email"`
	Username      string `json:"username"`
	Password      string `json:"password"`
	ServerAddress string `json:"serveraddress"`
}

DockerCredentials describes a set of docker credentials

func (DockerCredentials) Valid

func (d DockerCredentials) Valid() bool

type Machine

type Machine struct {
	InstanceID       string `json:"instance_id"`
	Version          string `json:"version"`
	RunnersTotal     int    `json:"runners_total"`
	RunnersAvailable int    `json:"runners_available"`
}

Machine is a node in an Iron cluster

type OptionFunc

type OptionFunc func(*http.Request) error

OptionFunc is the function signature function for options

type Response

type Response struct {
	*http.Response
}

Response is a HSDP IAM API response. This wraps the standard http.Response returned from HSDP IAM and provides convenient access to things like errors

type Schedule

type Schedule struct {
	ID          string     `json:"id,omitempty"`
	CreatedAt   *time.Time `json:"created_at,omitempty"`
	UpdatedAt   *time.Time `json:"updated_at,omitempty"`
	ProjectID   string     `json:"project_id,omitempty"`
	Status      string     `json:"status,omitempty"`
	CodeName    string     `json:"code_name"`
	StartAt     *time.Time `json:"start_at,omitempty"`
	EndAt       *time.Time `json:"end_at,omitempty"`
	NextStart   *time.Time `json:"next_start,omitempty"`
	LastRunTime *time.Time `json:"last_run_time,omitempty"`
	Timeout     int        `json:"timeout"`
	RunTimes    int        `json:"run_times,omitempty"`
	RunEvery    int        `json:"run_every,omitempty"`
	Cluster     string     `json:"cluster,omitempty"`
	Payload     string     `json:"payload,omitempty"`
}

type SchedulesServices

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

func (*SchedulesServices) CancelSchedule

func (s *SchedulesServices) CancelSchedule(scheduleID string) (bool, *Response, error)

CancelSchedule cancels a schedule

func (*SchedulesServices) CreateSchedule

func (s *SchedulesServices) CreateSchedule(schedule Schedule) (*Schedule, *Response, error)

CreateSchedule creates a schedule

func (*SchedulesServices) CreateSchedules

func (s *SchedulesServices) CreateSchedules(schedules []Schedule) (*[]Schedule, *Response, error)

CreateSchedules creates one or more schedules

func (*SchedulesServices) GetSchedule

func (s *SchedulesServices) GetSchedule(scheduleID string) (*Schedule, *Response, error)

GetSchedule gets info on a schedule

func (*SchedulesServices) GetSchedules

func (s *SchedulesServices) GetSchedules() (*[]Schedule, *Response, error)

GetSchedules gets the schedules of the project

func (*SchedulesServices) GetSchedulesWithCode added in v0.38.0

func (s *SchedulesServices) GetSchedulesWithCode(codeName string) (*[]Schedule, *Response, error)

GetSchedulesWithCode gets schedules which use code

type Task

type Task struct {
	ID            string     `json:"id,omitempty"`
	CreatedAt     *time.Time `json:"created_at,omitempty"`
	UpdatedAt     *time.Time `json:"updated_at,omitempty"`
	ProjectID     string     `json:"project_id,omitempty"`
	CodeID        string     `json:"code_id,omitempty"`
	CodeHistoryID string     `json:"code_history_id,omitempty"`
	Status        string     `json:"status,omitempty"`
	Msg           string     `json:"msg,omitempty"`
	CodeName      string     `json:"code_name,omitempty"`
	CodeRev       string     `json:"code_rev,omitempty"`
	StartTime     *time.Time `json:"start_time,omitempty"`
	EndTime       *time.Time `json:"end_time,omitempty"`
	Timeout       int        `json:"timeout,omitempty"`
	Payload       string     `json:"payload,omitempty"`
	ScheduleID    string     `json:"schedule_id,omitempty"`
	MessageID     string     `json:"message_id,omitempty"`
	Cluster       string     `json:"cluster,omitempty"`
	Duration      int        `json:"duration,omitempty"`
	LogSize       int        `json:"log_size,omitempty"`
}

type TasksServices

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

func (*TasksServices) CancelTask

func (t *TasksServices) CancelTask(taskID string) (bool, *Response, error)

CancelTask cancels the given task

func (*TasksServices) GetTask

func (t *TasksServices) GetTask(taskID string) (*Task, *Response, error)

GetTask gets info on a single task

func (*TasksServices) GetTasks

func (t *TasksServices) GetTasks() (*[]Task, *Response, error)

GetTasks gets the tasks of the project

func (*TasksServices) QueueTask

func (t *TasksServices) QueueTask(task Task) (*Task, *Response, error)

QueueTask queues a single task for execution

func (*TasksServices) QueueTasks

func (t *TasksServices) QueueTasks(tasks []Task) (*[]Task, *Response, error)

QueueTasks queues one or more tasks for execution

Jump to

Keyboard shortcuts

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