Documentation ¶
Index ¶
- Constants
- Variables
- func Copyfile(dst, src string) error
- func DebugPrint(v ...interface{})
- func DebugPrintf(format string, v ...interface{})
- func GetLoadAverage() (float64, error)
- func MakeCompileJob(compiler string, b Build) (j CompileJob, results ExecResult, err error)
- func NetListen(iport int) (ln net.Listener, port int, err error)
- func TempFile(dir, prefix string, suffix string) (f *os.File, err error)
- type Build
- type ByPrivateIPAddr
- type CompileJob
- type CompileResult
- type CompletedJob
- type DeadlineReadWriter
- type ExecResult
- type FifoScheduler
- type GUID
- type MachineID
- type MachineName
- type MessageConn
- func (mc MessageConn) Read() (MessageHeader, interface{}, error)
- func (mc MessageConn) ReadCompileJob() (j CompileJob, err error)
- func (mc MessageConn) ReadCompileResult() (r CompileResult, err error)
- func (mc MessageConn) ReadCompletedJob() (c CompletedJob, err error)
- func (mc MessageConn) ReadType(eID MessageID) (interface{}, error)
- func (mc MessageConn) ReadWorkerResponse() (r WorkerResponse, err error)
- func (mc MessageConn) ReadWorkerState() (s WorkerState, err error)
- func (mc MessageConn) Send(i interface{}) (err error)
- type MessageHeader
- type MessageID
- type Monitor
- type MonitorRequest
- type ResponseType
- type Scheduler
- type SchedulerRequest
- type ServerState
- type Worker
- type WorkerRequest
- type WorkerResponse
- type WorkerState
- type WorkerStateList
Constants ¶
const ( // Default port used by the server DefaultServerPort = uint(15796) // Default port used by the worker DefaultWorkerPort = uint(15797) // Beginning of our worker listen port range StartPort = DefaultWorkerPort // End of our listen port range EndPort = 15900 // UPD port used for auto discovery DiscoveryPort = 15932 )
const ( DISC_SERVER = uint8(iota) DISC_CLIENT = uint8(iota) )
Packet types
Variables ¶
var ( // Whether or not we have debug logging on DebugLogging = false )
Functions ¶
func DebugPrint ¶
func DebugPrint(v ...interface{})
Make this log statement only when debugging logging is on
func GetLoadAverage ¶
GetLoadAverage returns the 1 minute system load average TODO: linux only, support more of unix by using cgo and getloadavg
func MakeCompileJob ¶
func MakeCompileJob(compiler string, b Build) (j CompileJob, results ExecResult, err error)
MakeCompileJob takes the requested Build, pre-processses the needed file and returns a CompileJob with code.
Types ¶
type Build ¶
type Build struct { Args []string // Command line arguments Oindex int // Index of argument *before* the output file Iindex int // Index of input file option Cindex int // Index of "type" flag Distributable bool // A job we can distribute }
type ByPrivateIPAddr ¶
Custom IP sortring (doesn't support IPv6), which puts private IP addresses first, 192, then 172, then 10, then public
func (ByPrivateIPAddr) Len ¶
func (a ByPrivateIPAddr) Len() int
func (ByPrivateIPAddr) Less ¶
func (a ByPrivateIPAddr) Less(i, j int) bool
func (ByPrivateIPAddr) Swap ¶
func (a ByPrivateIPAddr) Swap(i, j int)
type CompileJob ¶
type CompileJob struct { Host string // The host requesting it Build Build // The commands to build it with Input []byte // The data to build Compiler string // The compiler to run it with }
A job to be farmed out to our cluster
func (CompileJob) Compile ¶
func (c CompileJob) Compile() (result CompileResult, err error)
Compile a job locally using temporary files and return the result
func (CompileJob) Validate ¶
func (c CompileJob) Validate() (err error)
Return an error if there is something wrong with the build job
type CompileResult ¶
type CompileResult struct { ExecResult // Results of the compiler command ObjectCode []byte // The compiled object code }
The result of a compile
func ClientBuildJob ¶
func ClientBuildJob(job CompileJob) (cresults CompileResult, err error)
TODO: this needs some tests
type CompletedJob ¶
type CompletedJob struct { Client MachineName // Machine that requested the job Worker MachineName // Worker that build the job InputSize int // Bytes of source code compiled OutputSize int // Bytes of object code produced CompileTime time.Duration // How long the job took to complete CompileSpeed float64 // Speed rating used for the job }
CompletedJob is one updated about a job completed on the cluster
type DeadlineReadWriter ¶
type DeadlineReadWriter interface { io.Reader io.Writer // SetReadDeadline sets the deadline for future Read calls. // A zero value for t means Read will not time out. SetReadDeadline(t time.Time) error // SetWriteDeadline sets the deadline for future Write calls. // Even if write times out, it may return n > 0, indicating that // some of the data was successfully written. // A zero value for t means Write will not time out. SetWriteDeadline(t time.Time) error }
DeadlineReadWriter is an interface that lets you read and write with a possible timeut based on deadlines.
type ExecResult ¶
type ExecResult struct { Output []byte // Output of the command Return int // Return code of program }
The result of running a command
func Compile ¶
func Compile(compiler string, b Build, input string) (resultPath string, result ExecResult, err error)
Build the file at the temporary location, you must clean up the returned file.
func Preprocess ¶
func Preprocess(compiler string, b Build) (resultPath string, result ExecResult, err error)
Build the file at the temporary location, you must clean up the returned file.
type FifoScheduler ¶
type FifoScheduler struct {
// contains filtered or unexported fields
}
type MachineID ¶
type MachineID string
String that unique identifies a machine
func GetMachineID ¶
Returns the ID of the current machine
type MachineName ¶
type MachineName struct { ID MachineID // The unique ID of the machine Host string // The host name of the machine }
Convenient wrapper for ID & Host
func (*MachineName) ToString ¶
func (mn *MachineName) ToString() string
type MessageConn ¶
type MessageConn struct {
// contains filtered or unexported fields
}
A connection which you can send and receive messages over
func NewMessageConn ¶
func NewMessageConn(c DeadlineReadWriter, d time.Duration) *MessageConn
Create a message connection with the given buffer
func NewTCPMessageConn ¶
func NewTCPMessageConn(address string, d time.Duration) (*MessageConn, error)
Create a TCP based message conn
func (MessageConn) Read ¶
func (mc MessageConn) Read() (MessageHeader, interface{}, error)
Generic Read function makes it possible to read messages of different types on the same pipe
func (MessageConn) ReadCompileJob ¶
func (mc MessageConn) ReadCompileJob() (j CompileJob, err error)
func (MessageConn) ReadCompileResult ¶
func (mc MessageConn) ReadCompileResult() (r CompileResult, err error)
func (MessageConn) ReadCompletedJob ¶
func (mc MessageConn) ReadCompletedJob() (c CompletedJob, err error)
func (MessageConn) ReadType ¶
func (mc MessageConn) ReadType(eID MessageID) (interface{}, error)
func (MessageConn) ReadWorkerResponse ¶
func (mc MessageConn) ReadWorkerResponse() (r WorkerResponse, err error)
func (MessageConn) ReadWorkerState ¶
func (mc MessageConn) ReadWorkerState() (s WorkerState, err error)
func (MessageConn) Send ¶
func (mc MessageConn) Send(i interface{}) (err error)
Generic send function, makes it simpler to send messages
type MessageHeader ¶
type MessageHeader struct {
ID MessageID
}
The MessageHeader procedes each message in our data stream, it lets us determine what exact type is in the nessage
type MessageID ¶
type MessageID int
type Monitor ¶
type Monitor struct {
// contains filtered or unexported fields
}
func (*Monitor) BasicReport ¶
Print out report data in raw form, connecting if needed
type MonitorRequest ¶
type MonitorRequest struct {
Host string
}
MonitorRequest is sent from a client that wishes to be sent information about the current jobs running on the build cluster.
type ResponseType ¶
type ResponseType int
Determine what kind of response the server sent
const ( Queued ResponseType = iota // No data, we are queued NoWorkers // No workers at all available Valid // Valid response )
type Scheduler ¶
type Scheduler interface {
// contains filtered or unexported methods
}
Schedules jobs amongst a pool of workers
type SchedulerRequest ¶
type SchedulerRequest struct {
// contains filtered or unexported fields
}
The information needed
func NewSchedulerRequest ¶
func NewSchedulerRequest(addrs []net.IPNet) *SchedulerRequest
type ServerState ¶
type ServerState struct {
// contains filtered or unexported fields
}
ServerState is all the state of our server TODO: consider some kind of channel system instead of a mutex to get sync access to these data structures.
func NewServerState ¶
func NewServerState() *ServerState
func (*ServerState) Serve ¶
func (s *ServerState) Serve(ln net.Listener)
server accepts incoming connections
type Worker ¶
type Worker struct {
// contains filtered or unexported fields
}
type WorkerRequest ¶
type WorkerRequest struct { Client string // Host request a worker Addrs []net.IPNet // IP addresses of the client }
WorkerRequest is sent from the client to the server in order to find a worker to process a job
type WorkerResponse ¶
type WorkerState ¶
type WorkerState struct { ID MachineID // Uniquely id for the worker machine Host string // Host the worker resides one Addrs []net.IPNet // IP addresses of the worker Port int // Port the worker accepts jobs on Capacity int // Number of available cores for building Load int // How many cores are current in use Updated time.Time // When the state was last updated Speed float64 // The speed of the worker, computed on the server }
WorkState represents the load and capacity of a worker
type WorkerStateList ¶
type WorkerStateList struct {
Workers []WorkerState
}
List of all currently active works