gordon

package module
v0.0.0-...-3681ca5 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2014 License: Apache-2.0 Imports: 4 Imported by: 2

README

Gordon

A simple Warden client. Automatically handles reconnecting and dynamically opening new connections to support concurrent requests.

Installation

cd $GOPATH
go get github.com/cloudfoundry-incubator/gordon

Usage

package main

import (
  "fmt"
  "github.com/cloudfoundry-incubator/gordon"
  "os"
)

func main() {
  client := warden.NewClient(
    &warden.ConnectionInfo{
      SocketPath: "/tmp/warden.sock"
    }
  )

  err := client.Connect()
  if err != nil {
    fmt.Println("Failed to connect to Warden: ", err)
    os.Exit(1)
    return
  }

  createResponse, err := client.Create()
  if err != nil {
    fmt.Println("Failed to create container: ", err)
    os.Exit(1)
    return
  }

  handle := createResponse.GetHandle()
  defer client.Destroy(handle)

  fmt.Printf("Container: %s\n", handle)

  spawnResponse, err := client.Spawn(handle, `
    for i in $(seq 10); do
      echo out $i;
      echo err $i 1>&2;
      sleep 1;
    done
  `)

  if err != nil {
    fmt.Println("Failed to spawn process: ", err)
    os.Exit(1)
    return
  }

  fmt.Println("Spawned!", spawnResponse)

  responses, err := client.Stream(handle, spawnResponse.GetJobId())
  if err != nil {
    fmt.Println("Failed to stream output: ", err)
    os.Exit(1)
    return
  }

  fmt.Println("Streaming output...")

  for {
    res, ok := <-responses
    if !ok {
      break
    }

    if res.ExitStatus == nil {
      fmt.Printf("%s: %s", res.GetName(), res.GetData())
    } else {
      fmt.Printf("exited: %d\n", res.GetExitStatus())
    }
  }
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	Connect() error

	Create(properties map[string]string) (*warden.CreateResponse, error)
	Stop(handle string, background, kill bool) (*warden.StopResponse, error)
	Destroy(handle string) (*warden.DestroyResponse, error)
	Run(handle, script string, resourceLimits ResourceLimits, environmentVariables []EnvironmentVariable) (uint32, <-chan *warden.ProcessPayload, error)
	Attach(handle string, processID uint32) (<-chan *warden.ProcessPayload, error)
	NetIn(handle string) (*warden.NetInResponse, error)
	LimitMemory(handle string, limit uint64) (*warden.LimitMemoryResponse, error)
	GetMemoryLimit(handle string) (uint64, error)
	LimitCPU(handle string, limitInShares uint64) (*warden.LimitCpuResponse, error)
	LimitDisk(handle string, limits DiskLimits) (*warden.LimitDiskResponse, error)
	GetDiskLimit(handle string) (uint64, error)
	List(filterProperties map[string]string) (*warden.ListResponse, error)
	Info(handle string) (*warden.InfoResponse, error)
	CopyIn(handle, src, dst string) (*warden.CopyInResponse, error)
	CopyOut(handle, src, dst, owner string) (*warden.CopyOutResponse, error)
}

func NewClient

func NewClient(cp ConnectionProvider) Client

type ConnectionInfo

type ConnectionInfo struct {
	Network string
	Addr    string
}

func (*ConnectionInfo) ProvideConnection

func (i *ConnectionInfo) ProvideConnection() (*connection.Connection, error)

type ConnectionProvider

type ConnectionProvider interface {
	ProvideConnection() (*connection.Connection, error)
}

type DiskLimits

type DiskLimits struct {
	ByteLimit  uint64
	InodeLimit uint64
}

type EnvironmentVariable

type EnvironmentVariable struct {
	Key   string
	Value string
}

type ResourceLimits

type ResourceLimits struct {
	FileDescriptors uint64
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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