當前位置: 首頁>>代碼示例>>Golang>>正文


Golang action.NewPipeline函數代碼示例

本文整理匯總了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
}
開發者ID:kennylixi,項目名稱:tsuru,代碼行數:32,代碼來源:docker.go

示例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
}
開發者ID:Zapelini,項目名稱:tsuru,代碼行數:67,代碼來源:app.go

示例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)
}
開發者ID:nicolas2bonfils,項目名稱:tsuru,代碼行數:32,代碼來源:auth.go

示例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)
}
開發者ID:kennylixi,項目名稱:tsuru,代碼行數:26,代碼來源:docker.go

示例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
}
開發者ID:4eek,項目名稱:tsuru,代碼行數:29,代碼來源:docker.go

示例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)
}
開發者ID:WIZARD-CXY,項目名稱:golang-devops-stuff,代碼行數:9,代碼來源:service_instance.go

示例7: DeployPipeline

func (p *dockerProvisioner) DeployPipeline() *action.Pipeline {
    actions := []*action.Action{
        &app.ProvisionerDeploy,
        &app.IncrementDeploy,
        &app.BindService,
    }
    pipeline := action.NewPipeline(actions...)
    return pipeline
}
開發者ID:tomzhang,項目名稱:golang-devops-stuff,代碼行數:9,代碼來源:provisioner.go

示例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)
}
開發者ID:tsuru,項目名稱:tsuru,代碼行數:57,代碼來源:containers_test.go

示例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)
}
開發者ID:RichardKnop,項目名稱:tsuru,代碼行數:11,代碼來源:service_instance.go

示例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
}
開發者ID:Zapelini,項目名稱:tsuru,代碼行數:12,代碼來源:app.go

示例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
}
開發者ID:tsuru,項目名稱:tsuru,代碼行數:15,代碼來源:app.go

示例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
}
開發者ID:ningjh,項目名稱:tsuru,代碼行數:11,代碼來源:docker.go

示例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
}
開發者ID:tsuru,項目名稱:tsuru,代碼行數:11,代碼來源:app.go

示例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
}
開發者ID:philiptzou,項目名稱:tsuru,代碼行數:13,代碼來源:app.go

示例15: DeployPipeline

func (p *dockerProvisioner) DeployPipeline() *action.Pipeline {
    actions := []*action.Action{
        &app.ProvisionerDeploy,
        &app.IncrementDeploy,
        //&saveUnits,
        &injectEnvirons,
        &bindService,
    }
    pipeline := action.NewPipeline(actions...)
    return pipeline
}
開發者ID:philiptzou,項目名稱:tsuru,代碼行數:11,代碼來源:provisioner.go


注:本文中的github.com/tsuru/tsuru/action.NewPipeline函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。