app

package
v0.0.0-...-0cf49f2 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2015 License: BSD-3-Clause Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// InternalAppName is a reserved name used for token generation. For
	// backward compatibilty and historical purpose, the value remained
	// "tsr" when the name of the daemon changed to "tsurud".
	InternalAppName = "tsr"

	TsuruServicesEnvVar = "TSURU_SERVICES"
)

Variables

View Source
var (
	ErrAppAlreadyExists = errors.New("there is already an app with this name")
	ErrAppNotFound      = errors.New("App not found.")
)
View Source
var (
	ErrAlreadyHaveAccess = stderr.New("team already have access to this app")
	ErrNoAccess          = stderr.New("team does not have access to this app")
	ErrCannotOrphanApp   = stderr.New("cannot revoke access from this team, as it's the unique team with access to the app")
	ErrDisabledPlatform  = stderr.New("Disabled Platform, only admin users can create applications with the platform")
)
View Source
var (
	ErrPlanNotFound         = errors.New("plan not found")
	ErrPlanAlreadyExists    = errors.New("plan already exists")
	ErrPlanDefaultAmbiguous = errors.New("more than one default plan found")
)
View Source
var AuthScheme auth.Scheme
View Source
var LogPubSubQueuePrefix = "pubsub:"

Functions

func AcquireApplicationLock

func AcquireApplicationLock(appName string, owner string, reason string) (bool, error)

AcquireApplicationLock acquires an application lock by setting the lock field in the database. This method is already called by a connection middleware on requests with :app or :appname params that have side-effects.

func AcquireApplicationLockWait

func AcquireApplicationLockWait(appName string, owner string, reason string, timeout time.Duration) (bool, error)

Same as AcquireApplicationLock but it keeps trying to acquire the lock until timeout is reached.

func ChangeQuota

func ChangeQuota(app *App, limit int) error

ChangeQuota redefines the limit of the app. The new limit must be bigger than or equal to the current number of units in the app. The new limit may be smaller than 0, which means that the app should have an unlimited number of units.

func CreateApp

func CreateApp(app *App, user *auth.User) error

CreateApp creates a new app.

Creating a new app is a process composed of the following steps:

  1. Save the app in the database
  2. Create the git repository using the repository manager
  3. Provision the app using the provisioner

func Delete

func Delete(app *App, w io.Writer) error

Delete deletes an app.

func Deploy

func Deploy(opts DeployOptions) error

Deploy runs a deployment of an application. It will first try to run an archive based deploy (if opts.ArchiveURL is not empty), and then fallback to the Git based deployment.

func GetDiffInDeploys

func GetDiffInDeploys(d *DeployData) (string, error)

func LogReceiver

func LogReceiver() (chan<- *Applog, <-chan error)

func LogRemove

func LogRemove(a *App) error

LogRemove removes the app log.

func PlanRemove

func PlanRemove(planName string) error

func PlatformAdd

func PlatformAdd(opts provision.PlatformOptions) error

PlatformAdd add a new platform to tsuru

func PlatformRemove

func PlatformRemove(name string) error

func PlatformUpdate

func PlatformUpdate(opts provision.PlatformOptions) error

func ReleaseApplicationLock

func ReleaseApplicationLock(appName string)

ReleaseApplicationLock releases a lock hold on an app, currently it's called by a middleware, however, ideally, it should be called individually by each handler since they might be doing operations in background.

func Rollback

func Rollback(opts DeployOptions) error

func Swap

func Swap(app1, app2 *App) error

Swap calls the Provisioner.Swap. And updates the app.CName in the database.

Types

type App

type App struct {
	Env            map[string]bind.EnvVar
	Platform       string `bson:"framework"`
	Name           string
	Ip             string
	CName          []string
	Teams          []string
	TeamOwner      string
	Owner          string
	Deploys        uint
	UpdatePlatform bool
	Lock           AppLock
	Plan           Plan
	Pool           string

	quota.Quota
}

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 GetByName

func GetByName(name string) (*App, error)

GetByName queries the database to find an app identified by the given name.

func List

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

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

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

The list can be filtered through the filter parameter.

func (*App) AddCName

func (app *App) AddCName(cnames ...string) error

AddCName adds a CName to app. It updates the attribute, calls the SetCName function on the provisioner and saves the app in the database, returning an error when it cannot save the change in the database or add the CName on the provisioner.

func (*App) AddInstance

func (app *App) AddInstance(instanceApp bind.InstanceApp, writer io.Writer) error

func (app *App) AddInstance(serviceName string, instance bind.ServiceInstance, shouldRestart bool, writer io.Writer) error {

func (*App) AddUnits

func (app *App) AddUnits(n uint, process string, writer io.Writer) 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 or unreachable.

func (*App) BindUnit

func (app *App) BindUnit(unit *provision.Unit) error

func (*App) ChangePlan

func (app *App) ChangePlan(planName string, w io.Writer) error

ChangePlan changes the plan of the application.

It may change the state of the application if the new plan includes a new router or a change in the amount of available memory.

func (*App) ChangePool

func (app *App) ChangePool(newPoolName string) error

func (*App) Envs

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

Envs returns a map representing the apps environment variables.

func (*App) GetCpuShare

func (app *App) GetCpuShare() int

GetCpuShare returns the cpu share for the app.

func (*App) GetDefaultPool

func (app *App) GetDefaultPool() (string, error)

func (*App) GetDeploys

func (app *App) GetDeploys() uint

GetDeploys returns the amount of deploys of an app.

func (*App) GetIp

func (app *App) GetIp() string

GetIp returns the ip of the app.

func (*App) GetMemory

func (app *App) GetMemory() int64

GetMemory returns the memory limit (in bytes) for the app.

func (*App) GetName

func (app *App) GetName() string

GetName returns the name of the app.

func (*App) GetPlatform

func (app *App) GetPlatform() string

GetPlatform returns the platform of the app.

func (*App) GetPool

func (app *App) GetPool() string

GetPool returns the pool of the app.

func (*App) GetPoolForApp

func (app *App) GetPoolForApp(poolName string) (string, error)

func (*App) GetQuota

func (app *App) GetQuota() quota.Quota

func (*App) GetRouter

func (app *App) GetRouter() (string, error)

func (*App) GetSwap

func (app *App) GetSwap() int64

GetSwap returns the swap limit (in bytes) for the app.

func (*App) GetTeamOwner

func (app *App) GetTeamOwner() string

GetTeamOwner returns the team owner 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) GetTeamsName

func (app *App) GetTeamsName() []string

GetTeamsNames returns the names of teams app.

func (*App) GetUnits

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

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

func (*App) GetUpdatePlatform

func (app *App) GetUpdatePlatform() bool

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) 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).

func (*App) LastLogs

func (app *App) LastLogs(lines int, filterLog Applog) ([]Applog, error)

LastLogs returns a list of the last `lines` log of the app, matching the fields in the log instance received as an example.

func (*App) ListDeploys

func (app *App) ListDeploys(u *auth.User) ([]DeployData, error)

func (*App) Log

func (app *App) Log(message, source, unit 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.

func (*App) MetricEnvs

func (app *App) MetricEnvs() map[string]string

func (*App) RebuildRoutes

func (app *App) RebuildRoutes() (*RebuildRoutesResult, error)

func (*App) RegisterUnit

func (app *App) RegisterUnit(unitId string, customData map[string]interface{}) error

func (*App) RemoveCName

func (app *App) RemoveCName(cnames ...string) error

func (*App) RemoveInstance

func (app *App) RemoveInstance(instanceApp bind.InstanceApp, writer io.Writer) error

func (app *App) RemoveInstance(serviceName string, instance bind.ServiceInstance, shouldRestart bool, writer io.Writer) error {

func (*App) RemoveUnits

func (app *App) RemoveUnits(n uint, process string, writer io.Writer) error

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

  1. Remove units from the provisioner
  2. Update quota

func (*App) Restart

func (app *App) Restart(process string, 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, once bool) error

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

func (*App) SetEnvs

func (app *App) SetEnvs(setEnvs bind.SetEnvApp, w io.Writer) 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) SetPool

func (app *App) SetPool() error

func (*App) SetQuotaInUse

func (app *App) SetQuotaInUse(inUse int) error

func (*App) SetTeamOwner

func (app *App) SetTeamOwner(team *auth.Team, u *auth.User) error

SetTeamOwner sets the TeamOwner value.

func (*App) SetUnitStatus

func (app *App) SetUnitStatus(unitName string, status provision.Status) error

SetUnitStatus changes the status of the given unit.

func (*App) SetUpdatePlatform

func (app *App) SetUpdatePlatform(check bool) error

func (*App) Shell

func (app *App) Shell(opts provision.ShellOptions) error

func (*App) Start

func (app *App) Start(w io.Writer, process string) error

Start starts the app calling the provisioner.Start method and changing the units state to StatusStarted.

func (*App) Stop

func (app *App) Stop(w io.Writer, process string) error

func (*App) UnbindUnit

func (app *App) UnbindUnit(unit *provision.Unit) error

func (*App) Units

func (app *App) Units() ([]provision.Unit, error)

Units returns the list of units.

func (*App) UnsetEnvs

func (app *App) UnsetEnvs(unsetEnvs bind.UnsetEnvApp, w io.Writer) 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).

func (*App) ValidateTeamOwner

func (app *App) ValidateTeamOwner(user *auth.User) error

type AppCreationError

type AppCreationError struct {
	Err error
	// contains filtered or unexported fields
}

func (*AppCreationError) Error

func (e *AppCreationError) Error() string

type AppLock

type AppLock struct {
	Locked      bool
	Reason      string
	Owner       string
	AcquireDate time.Time
}

AppLock stores information about a lock hold on the app

func (*AppLock) String

func (l *AppLock) String() string

type Applog

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

Applog represents a log entry.

type DeployData

type DeployData struct {
	ID          bson.ObjectId `bson:"_id,omitempty"`
	App         string
	Timestamp   time.Time
	Duration    time.Duration
	Commit      string
	Error       string
	Image       string
	Log         string
	User        string
	Origin      string
	CanRollback bool
	RemoveDate  time.Time `bson:",omitempty"`
}

func GetDeploy

func GetDeploy(id string, u *auth.User) (*DeployData, error)

func ListDeploys

func ListDeploys(app *App, s *service.Service, u *auth.User, skip, limit int) ([]DeployData, error)

ListDeploys returns the list of deploy that the given user has access to.

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

The deploy list can be filtered by app or service.

type DeployOptions

type DeployOptions struct {
	App          *App
	Version      string
	Commit       string
	ArchiveURL   string
	File         io.ReadCloser
	OutputStream io.Writer
	User         string
	Image        string
}

type DiffDeployData

type DiffDeployData struct {
	DeployData
	Diff string
}

func (*DiffDeployData) MarshalJSON

func (d *DiffDeployData) MarshalJSON() ([]byte, error)

type DuplicatePlatformError

type DuplicatePlatformError struct{}

func (DuplicatePlatformError) Error

type Filter

type Filter struct {
	Name      string
	Platform  string
	TeamOwner string
	UserOwner string
	Pool      string
	Locked    bool
}

func (*Filter) Query

func (f *Filter) Query() bson.M

type InvalidPlatformError

type InvalidPlatformError struct{}

func (InvalidPlatformError) Error

func (InvalidPlatformError) Error() string

type LogListener

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

func NewLogListener

func NewLogListener(a *App, filterLog Applog) (*LogListener, error)

func (*LogListener) Close

func (l *LogListener) Close() (err error)

type LogWriter

type LogWriter struct {
	App    Logger
	Source string
	// contains filtered or unexported fields
}

func (*LogWriter) Async

func (w *LogWriter) Async()

func (*LogWriter) Close

func (w *LogWriter) Close()

func (*LogWriter) Wait

func (w *LogWriter) Wait(timeout time.Duration) error

func (*LogWriter) Write

func (w *LogWriter) Write(data []byte) (int, error)

Write writes and logs the data.

type Logger

type Logger interface {
	Log(string, string, string) error
}

type ManyTeamsError

type ManyTeamsError struct{}

ManyTeamsError is the error returned when the user has more than one team and tries to create an app without specify a app team owner.

func (ManyTeamsError) Error

func (err ManyTeamsError) Error() string

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 Plan

type Plan struct {
	Name     string `bson:"_id" json:"name"`
	Memory   int64  `json:"memory"`
	Swap     int64  `json:"swap"`
	CpuShare int    `json:"cpushare"`
	Default  bool   `json:"default,omitempty"`
	Router   string `json:"router,omitempty"`
}

func DefaultPlan

func DefaultPlan() (*Plan, error)

func PlansList

func PlansList() ([]Plan, error)

func (*Plan) Save

func (plan *Plan) Save() error

type PlanValidationError

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

func (PlanValidationError) Error

func (p PlanValidationError) Error() string

type Platform

type Platform struct {
	Name     string `bson:"_id"`
	Disabled bool
}

func Platforms

func Platforms(enabledOnly bool) ([]Platform, error)

Platforms returns the list of available platforms.

type ProcfileError

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

func (*ProcfileError) Error

func (e *ProcfileError) Error() string

type RebuildRoutesResult

type RebuildRoutesResult struct {
	Added   []string
	Removed []string
}

type UpdateUnitsData

type UpdateUnitsData struct {
	ID     string
	Name   string
	Status provision.Status
}

type UpdateUnitsResult

type UpdateUnitsResult struct {
	ID    string
	Found bool
}

func UpdateUnitsStatus

func UpdateUnitsStatus(units []UpdateUnitsData) ([]UpdateUnitsResult, error)

UpdateUnitsStatus updates the status of the given units, returning a map which units were found during the update.

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