app

package
v0.0.0-...-e22f67b Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2013 License: BSD-3-Clause Imports: 35 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RegenerateApprcAndStart = "regenerate-apprc-start-app"
)

Variables

Functions

func CreateApp

func CreateApp(app *App, units uint, teams []auth.Team) error

CreateApp creates a new app.

Creating a new app is a process composed of four steps:

  1. Save the app in the database
  2. Create IAM credentials for the app
  3. Create S3 bucket for the app (if the bucket support is enabled)
  4. Create the git repository using gandalf
  5. Provision units within the provisioner

func Enqueue

func Enqueue(msgs ...queue.Message)

Enqueue puts the given message in the queue. The app queue is able to handle only messages defined in this package.

Here is a functional example for this function:

msg := queue.Message{Action: app.RegenerateApprcAndStart, Args: []string{"myapp"}}
app.Enqueue(msg)

func ForceDestroy

func ForceDestroy(app *App) error

ForceDestroy destroys an app with force.

Destroying an app is a process composed of four steps:

  1. Destroy the bucket and S3 credentials (if bucket-support is enabled).
  2. Destroy the app unit using juju
  3. Unbind all service instances from the app
  4. Remove the app from the database

Types

type App

type App struct {
	Env       map[string]bind.EnvVar
	Framework string
	Logs      []Applog
	Name      string
	Ip        string
	CName     string
	Units     []Unit
	Teams     []string
	// contains filtered or unexported fields
}

App is the main type in tsuru. An app represents a real world application. This struct holds information about the app: its name, address, list of teams that have access to it, used platform, etc.

func List

func List(u *auth.User) ([]App, error)

List returns the list of apps that the given user has access to.

If the user does not have acces to any app, this function returns an empty list and a nil error.

func (*App) AddUnit

func (app *App) AddUnit(u *Unit)

AddUnit adds a new unit to the app (or update an existing unit). It just updates the internal list of units, it does not talk to the provisioner. For provisioning a new unit for the app, one should use AddUnits method, which receives the number of units that you want to provision.

func (*App) AddUnits

func (app *App) AddUnits(n uint) error

AddUnits creates n new units within the provisioner, saves new units in the database and enqueues the apprc serialization.

func (*App) Available

func (app *App) Available() bool

Available returns true if at least one of N units is started.

func (*App) Command

func (app *App) Command(stdout, stderr io.Writer, cmdArgs ...string) error

Command is declared just to satisfy repository.Unit interface.

func (*App) Get

func (app *App) Get() error

Get queries the database and fills the App object with data retrieved from the database. It uses the name of the app as filter in the query, so you can provide this field:

app := App{Name: "myapp"}
err := app.Get()
// do something with the app

func (*App) GetFramework

func (app *App) GetFramework() string

GetFramework returns the framework of the app.

func (*App) GetIp

func (app *App) GetIp() string

GetIp returns the ip of the app.

func (*App) GetName

func (app *App) GetName() string

GetName returns the name of the app.

func (*App) GetTeams

func (app *App) GetTeams() []auth.Team

GetTeams returns a slice of teams that have access to the app.

func (*App) GetUnits

func (app *App) GetUnits() []bind.Unit

GetUnits returns the internal list of units converted to bind.Unit.

func (*App) Grant

func (app *App) Grant(team *auth.Team) error

Grant allows a team to have access to an app. It returns an error if the team already have access to the app.

func (*App) InstallDeps

func (app *App) InstallDeps(w io.Writer) error

InstallDeps runs the dependencies hook for the app, writing its output to w.

func (*App) InstanceEnv

func (app *App) InstanceEnv(name string) map[string]bind.EnvVar

InstanceEnv returns a map of environment variables that belongs to the given service instance (identified by the name only).

TODO(fss): this method should not be exported.

func (*App) LastLogs

func (a *App) LastLogs(lines int, source string) ([]Applog, error)

LastLogs returns a list of the last `lines` log of the app, matching the given source.

func (*App) Log

func (app *App) Log(message, source string) error

Log adds a log message to the app. Specifying a good source is good so the user can filter where the message come from.

func (*App) MarshalJSON

func (app *App) MarshalJSON() ([]byte, error)

MarshalJSON marshals the app in json format. It returns a JSON object with the following keys: Name, Framework, Teams, Units, Repository and Ip.

func (*App) ProvisionUnits

func (app *App) ProvisionUnits() []provision.AppUnit

ProvisionUnits returns the internal list of units converted to provision.AppUnit.

func (*App) RemoveUnit

func (app *App) RemoveUnit(id string) error

RemoveUnit removes a unit by its InstanceId or Name.

Will search first by InstanceId, if no instance is found, then tries to search using the unit name, then calls the removal function from provisioner

Returns an error in case of failure.

func (*App) RemoveUnits

func (app *App) RemoveUnits(n uint) error

RemoveUnits removes n units from the app. It's a process composed of x steps:

  1. Remove units from the provisioner
  2. Unbind units from service instances bound to the app
  3. Remove units from the app list
  4. Update the app in the database

func (*App) Restart

func (app *App) Restart(w io.Writer) error

Restart runs the restart hook for the app, writing its output to w.

func (*App) Revoke

func (app *App) Revoke(team *auth.Team) error

Revoke removes the access from a team. It returns an error if the team do not have access to the app.

func (*App) Run

func (app *App) Run(cmd string, w io.Writer) error

Run executes the command in app units, sourcing apprc before running the command.

func (*App) SetCName

func (app *App) SetCName(cname string) error

SetCName defines the CName of the app. It updates the attribute and saves the app in the database, returning an error when it cannot save the change in the database.

func (*App) SetEnvs

func (app *App) SetEnvs(envs []bind.EnvVar, publicOnly bool) error

SetEnvs saves a list of environment variables in the app. The publicOnly parameter indicates whether only public variables can be overridden (if set to false, SetEnvs may override a private variable).

func (*App) SetTeams

func (app *App) SetTeams(teams []auth.Team)

SetTeams sets the values of the internal te

TODO(fss): this method should not be exported.

func (*App) UnsetEnvs

func (app *App) UnsetEnvs(variableNames []string, publicOnly bool) error

UnsetEnvs removes environment variables from an app, serializing the remaining list of environment variables to all units of the app.

Besides the slice with the name of the variables, this method also takes the parameter publicOnly, which indicates whether only public variables can be overridden (if set to false, setEnvsToApp may override a private variable).

type Applog

type Applog struct {
	Date    time.Time
	Message string
	Source  string
}

Applog represents a log entry.

type LogListener

type LogListener struct {
	C <-chan Applog
	// contains filtered or unexported fields
}

func NewLogListener

func NewLogListener(a *App) *LogListener

func (*LogListener) Close

func (l *LogListener) Close() error

type NoTeamsError

type NoTeamsError struct{}

NoTeamsError is the error returned when one tries to create an app without any team.

func (NoTeamsError) Error

func (err NoTeamsError) Error() string

type Unit

type Unit struct {
	Name       string
	Type       string
	Machine    int
	InstanceId string
	Ip         string
	State      string
	// contains filtered or unexported fields
}

Unit is the smaller bit in tsuru. Each app is composed of one or more units.

The unit is equivalent to a machine. How the machine is actually represented (baremetal, virtual machine, jails, containers, etc.) is up to the provisioner.

func (*Unit) GetInstanceId

func (u *Unit) GetInstanceId() string

func (*Unit) GetIp

func (u *Unit) GetIp() string

func (*Unit) GetMachine

func (u *Unit) GetMachine() int

func (*Unit) GetName

func (u *Unit) GetName() string

func (*Unit) GetStatus

func (u *Unit) GetStatus() provision.Status

type UnitSlice

type UnitSlice []Unit

UnitSlice attaches the methods of sort.Interface to []Unit, sorting in increasing order.

func (UnitSlice) Len

func (u UnitSlice) Len() int

func (UnitSlice) Less

func (u UnitSlice) Less(i, j int) bool

func (UnitSlice) Swap

func (u UnitSlice) Swap(i, j int)

Directories

Path Synopsis
Package bind provides interfaces and types for use when binding an app to a service.
Package bind provides interfaces and types for use when binding an app to a service.

Jump to

Keyboard shortcuts

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