本文整理汇总了Golang中github.com/tsuru/tsuru/action.NewPipeline函数的典型用法代码示例。如果您正苦于以下问题:Golang NewPipeline函数的具体用法?Golang NewPipeline怎么用?Golang NewPipeline使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewPipeline函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: deploy
func deploy(app provision.App, version string, w io.Writer) (string, error) {
commands, err := deployCmds(app, version)
if err != nil {
return "", err
}
imageId := getImage(app)
actions := []*action.Action{&insertEmptyContainerInDB, &createContainer, &startContainer, &updateContainerInDB}
pipeline := action.NewPipeline(actions...)
err = pipeline.Execute(app, imageId, commands)
if err != nil {
log.Errorf("error on execute deploy pipeline for app %s - %s", app.GetName(), err)
return "", err
}
c := pipeline.Result().(container)
err = c.logs(w)
if err != nil {
log.Errorf("error on get logs for container %s - %s", c.ID, err)
return "", err
}
_, err = dockerCluster().WaitContainer(c.ID)
if err != nil {
log.Errorf("Process failed for container %q: %s", c.ID, err)
return "", err
}
imageId, err = c.commit()
if err != nil {
log.Errorf("error on commit container %s - %s", c.ID, err)
return "", err
}
c.remove()
return imageId, nil
}
示例2: CreateApp
// 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 CreateApp(app *App, user *auth.User) error {
teams, err := user.Teams()
if err != nil {
return err
}
if len(teams) == 0 {
return NoTeamsError{}
}
platform, err := getPlatform(app.Platform)
if err != nil {
return err
}
if platform.Disabled && !user.IsAdmin() {
return InvalidPlatformError{}
}
var plan *Plan
if app.Plan.Name == "" {
plan, err = DefaultPlan()
} else {
plan, err = findPlanByName(app.Plan.Name)
}
if err != nil {
return err
}
if app.TeamOwner == "" {
if len(teams) > 1 {
return ManyTeamsError{}
}
app.TeamOwner = teams[0].Name
}
err = app.ValidateTeamOwner(user)
if err != nil {
return err
}
app.Plan = *plan
err = app.SetPool()
if err != nil {
return err
}
app.Teams = []string{app.TeamOwner}
app.Owner = user.Email
err = app.validate()
if err != nil {
return err
}
actions := []*action.Action{
&reserveUserApp,
&insertApp,
&exportEnvironmentsAction,
&createRepository,
&provisionApp,
&setAppIp,
}
pipeline := action.NewPipeline(actions...)
err = pipeline.Execute(app, user)
if err != nil {
return &AppCreationError{app: app.Name, Err: err}
}
return nil
}
示例3: addUserToTeam
func addUserToTeam(w http.ResponseWriter, r *http.Request, t auth.Token) error {
teamName := r.URL.Query().Get(":team")
email := r.URL.Query().Get(":user")
u, err := t.User()
if err != nil {
return err
}
rec.Log(u.Email, "add-user-to-team", "team="+teamName, "user="+email)
conn, err := db.Conn()
if err != nil {
return err
}
defer conn.Close()
team, err := auth.GetTeam(teamName)
if err != nil {
return &errors.HTTP{Code: http.StatusNotFound, Message: "Team not found"}
}
if !team.ContainsUser(u) {
msg := fmt.Sprintf("You are not authorized to add new users to the team %s", team.Name)
return &errors.HTTP{Code: http.StatusForbidden, Message: msg}
}
user, err := auth.GetUserByEmail(email)
if err != nil {
return &errors.HTTP{Code: http.StatusNotFound, Message: "User not found"}
}
actions := []*action.Action{
&addUserToTeamInRepositoryAction,
&addUserToTeamInDatabaseAction,
}
pipeline := action.NewPipeline(actions...)
return pipeline.Execute(user, team)
}
示例4: moveOneContainer
func moveOneContainer(c container, toHost string, errors chan error, wg *sync.WaitGroup, encoder *json.Encoder) {
a, err := app.GetByName(c.AppName)
defer wg.Done()
if err != nil {
errors <- err
return
}
logProgress(encoder, "Moving unit %s for %q: %s -> %s...", c.ID, c.AppName, c.HostAddr, toHost)
pipeline := action.NewPipeline(
&provisionAddUnitToHost,
&provisionRemoveOldUnit,
)
err = pipeline.Execute(a, toHost, c)
if err != nil {
errors <- err
return
}
logProgress(encoder, "Finished moving unit %s for %q.", c.ID, c.AppName)
addedUnit := pipeline.Result().(provision.Unit)
err = moveOneContainerInDB(a, c, addedUnit)
if err != nil {
errors <- err
return
}
logProgress(encoder, "Moved unit %s -> %s for %s in DB.", c.ID, addedUnit.Name, c.AppName)
}
示例5: deployPipeline
func (p *dockerProvisioner) deployPipeline(app provision.App, imageId string, commands []string, w io.Writer) (string, error) {
actions := []*action.Action{
&insertEmptyContainerInDB,
&createContainer,
&startContainer,
&updateContainerInDB,
&followLogsAndCommit,
}
pipeline := action.NewPipeline(actions...)
buildingImage, err := appNewImageName(app.GetName())
if err != nil {
return "", log.WrapError(fmt.Errorf("error getting new image name for app %s", app.GetName()))
}
args := runContainerActionsArgs{
app: app,
imageID: imageId,
commands: commands,
writer: w,
isDeploy: true,
buildingImage: buildingImage,
provisioner: p,
}
err = pipeline.Execute(args)
if err != nil {
log.Errorf("error on execute deploy pipeline for app %s - %s", app.GetName(), err)
return "", err
}
return buildingImage, nil
}
示例6: BindApp
// BindApp makes the bind between the service instance and an app.
func (si *ServiceInstance) BindApp(app bind.App) error {
actions := []*action.Action{
&addAppToServiceInstance,
&setEnvironVariablesToApp,
}
pipeline := action.NewPipeline(actions...)
return pipeline.Execute(app, *si)
}
示例7: DeployPipeline
func (p *dockerProvisioner) DeployPipeline() *action.Pipeline {
actions := []*action.Action{
&app.ProvisionerDeploy,
&app.IncrementDeploy,
&app.BindService,
}
pipeline := action.NewPipeline(actions...)
return pipeline
}
示例8: TestRebalanceContainersDry
func (s *S) TestRebalanceContainersDry(c *check.C) {
p, err := s.startMultipleServersCluster()
c.Assert(err, check.IsNil)
err = s.newFakeImage(p, "tsuru/app-myapp", nil)
c.Assert(err, check.IsNil)
appInstance := provisiontest.NewFakeApp("myapp", "python", 0)
defer p.Destroy(appInstance)
p.Provision(appInstance)
imageId, err := image.AppCurrentImageName(appInstance.GetName())
c.Assert(err, check.IsNil)
args := changeUnitsPipelineArgs{
app: appInstance,
toAdd: map[string]*containersToAdd{"web": {Quantity: 5}},
imageId: imageId,
provisioner: p,
toHost: "localhost",
}
pipeline := action.NewPipeline(
&provisionAddUnitsToHost,
&bindAndHealthcheck,
&addNewRoutes,
&setRouterHealthcheck,
&updateAppImage,
)
err = pipeline.Execute(args)
c.Assert(err, check.IsNil)
appStruct := &app.App{
Name: appInstance.GetName(),
Pool: "test-default",
}
err = s.storage.Apps().Insert(appStruct)
c.Assert(err, check.IsNil)
router, err := getRouterForApp(appInstance)
c.Assert(err, check.IsNil)
beforeRoutes, err := router.Routes(appStruct.Name)
c.Assert(err, check.IsNil)
c.Assert(beforeRoutes, check.HasLen, 5)
var serviceCalled bool
rollback := s.addServiceInstance(c, appInstance.GetName(), nil, func(w http.ResponseWriter, r *http.Request) {
serviceCalled = true
w.WriteHeader(http.StatusOK)
})
defer rollback()
buf := safe.NewBuffer(nil)
err = p.rebalanceContainers(buf, true)
c.Assert(err, check.IsNil)
c1, err := p.listContainersByHost("localhost")
c.Assert(err, check.IsNil)
c2, err := p.listContainersByHost("127.0.0.1")
c.Assert(err, check.IsNil)
c.Assert(c1, check.HasLen, 5)
c.Assert(c2, check.HasLen, 0)
routes, err := router.Routes(appStruct.Name)
c.Assert(err, check.IsNil)
c.Assert(routes, check.DeepEquals, beforeRoutes)
c.Assert(serviceCalled, check.Equals, false)
}
示例9: BindApp
// BindApp makes the bind between the service instance and an app.
func (si *ServiceInstance) BindApp(app bind.App, writer io.Writer) error {
actions := []*action.Action{
&addAppToServiceInstance,
&setBindAppAction,
&setTsuruServices,
&bindUnitsToServiceInstance,
}
pipeline := action.NewPipeline(actions...)
return pipeline.Execute(app, *si, writer)
}
示例10: AddUnits
// AddUnits creates n new units within the provisioner, saves new units in the
// database and enqueues the apprc serialization.
func (app *App) AddUnits(n uint, process string, writer io.Writer) error {
if n == 0 {
return stderr.New("Cannot add zero units.")
}
err := action.NewPipeline(
&reserveUnitsToAdd,
&provisionAddUnits,
).Execute(app, n, writer, process)
return err
}
示例11: AddCName
// 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 *App) AddCName(cnames ...string) error {
actions := []*action.Action{
&validateNewCNames,
&setNewCNamesToProvisioner,
&saveCNames,
&updateApp,
}
err := action.NewPipeline(actions...).Execute(app, cnames)
rebuild.RoutesRebuildOrEnqueue(app.Name)
return err
}
示例12: deploy
func deploy(app provision.App, commands []string, w io.Writer) (string, error) {
imageId := getImage(app)
actions := []*action.Action{&insertEmptyContainerInDB, &createContainer, &startContainer, &updateContainerInDB, &followLogsAndCommit}
pipeline := action.NewPipeline(actions...)
err := pipeline.Execute(app, imageId, commands, []string{}, w)
if err != nil {
log.Errorf("error on execute deploy pipeline for app %s - %s", app.GetName(), err)
return "", err
}
return pipeline.Result().(string), nil
}
示例13: RemoveCName
func (app *App) RemoveCName(cnames ...string) error {
actions := []*action.Action{
&checkCNameExists,
&unsetCNameFromProvisioner,
&removeCNameFromDatabase,
&removeCNameFromApp,
}
err := action.NewPipeline(actions...).Execute(app, cnames)
rebuild.RoutesRebuildOrEnqueue(app.Name)
return err
}
示例14: AddUnits
// AddUnits creates n new units within the provisioner, saves new units in the
// database and enqueues the apprc serialization.
func (app *App) AddUnits(n uint) error {
if n == 0 {
return stderr.New("Cannot add zero units.")
}
err := action.NewPipeline(
&reserveUnitsToAdd,
&provisionAddUnits,
&saveNewUnitsInDatabase,
).Execute(app, n)
return err
}
示例15: DeployPipeline
func (p *dockerProvisioner) DeployPipeline() *action.Pipeline {
actions := []*action.Action{
&app.ProvisionerDeploy,
&app.IncrementDeploy,
//&saveUnits,
&injectEnvirons,
&bindService,
}
pipeline := action.NewPipeline(actions...)
return pipeline
}