本文整理汇总了Golang中github.com/tsuru/tsuru/action.NewPipeline函数的典型用法代码示例。如果您正苦于以下问题:Golang NewPipeline函数的具体用法?Golang NewPipeline怎么用?Golang NewPipeline使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewPipeline函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: Destroy
func (p *dockerProvisioner) Destroy(app provision.App) error {
containers, err := p.listContainersByApp(app.GetName())
if err != nil {
log.Errorf("Failed to list app containers: %s", err.Error())
return err
}
args := changeUnitsPipelineArgs{
app: app,
toRemove: containers,
writer: ioutil.Discard,
provisioner: p,
appDestroy: true,
}
pipeline := action.NewPipeline(
&removeOldRoutes,
&provisionRemoveOldUnits,
&provisionUnbindOldUnits,
)
err = pipeline.Execute(args)
if err != nil {
return err
}
images, err := listAppImages(app.GetName())
if err != nil {
log.Errorf("Failed to get image ids for app %s: %s", app.GetName(), err.Error())
}
cluster := p.Cluster()
for _, imageId := range images {
err = cluster.RemoveImage(imageId)
if err != nil {
log.Errorf("Failed to remove image %s: %s", imageId, err.Error())
}
err = cluster.RemoveFromRegistry(imageId)
if err != nil {
log.Errorf("Failed to remove image %s from registry: %s", imageId, err.Error())
}
}
err = deleteAllAppImageNames(app.GetName())
if err != nil {
log.Errorf("Failed to remove image names from storage for app %s: %s", app.GetName(), err.Error())
}
r, err := getRouterForApp(app)
if err != nil {
log.Errorf("Failed to get router: %s", err.Error())
return err
}
err = r.RemoveBackend(app.GetName())
if err != nil {
log.Errorf("Failed to remove route backend: %s", err.Error())
return err
}
return nil
}
开发者ID:zhenruyan,项目名称:tsuru,代码行数:53,代码来源:provisioner.go
示例17: runReplaceUnitsPipeline
func (p *dockerProvisioner) runReplaceUnitsPipeline(w io.Writer, a provision.App, toAdd map[string]*containersToAdd, toRemoveContainers []container.Container, imageId string, toHosts ...string) ([]container.Container, error) {
var toHost string
if len(toHosts) > 0 {
toHost = toHosts[0]
}
if w == nil {
w = ioutil.Discard
}
args := changeUnitsPipelineArgs{
app: a,
toAdd: toAdd,
toRemove: toRemoveContainers,
toHost: toHost,
writer: w,
imageId: imageId,
provisioner: p,
}
var pipeline *action.Pipeline
if p.isDryMode {
pipeline = action.NewPipeline(
&provisionAddUnitsToHost,
&provisionRemoveOldUnits,
)
} else {
pipeline = action.NewPipeline(
&provisionAddUnitsToHost,
&bindAndHealthcheck,
&addNewRoutes,
&removeOldRoutes,
&updateAppImage,
&provisionRemoveOldUnits,
&provisionUnbindOldUnits,
)
}
err := pipeline.Execute(args)
if err != nil {
return nil, err
}
return pipeline.Result().([]container.Container), nil
}
开发者ID:gwmoura,项目名称:yati,代码行数:40,代码来源:containers.go
示例18: Update
// Update changes informations of the application.
func (app *App) Update(updateData App, w io.Writer) error {
description := updateData.Description
planName := updateData.Plan.Name
poolName := updateData.Pool
teamOwner := updateData.TeamOwner
if description != "" {
app.Description = description
}
if poolName != "" {
app.Pool = poolName
_, err := app.GetPoolForApp(app.Pool)
if err != nil {
return err
}
}
conn, err := db.Conn()
if err != nil {
return err
}
defer conn.Close()
if planName != "" {
plan, err := findPlanByName(planName)
if err != nil {
return err
}
var oldPlan Plan
oldPlan, app.Plan = app.Plan, *plan
actions := []*action.Action{
&moveRouterUnits,
&saveApp,
&restartApp,
&removeOldBackend,
}
err = action.NewPipeline(actions...).Execute(app, &oldPlan, w)
if err != nil {
return err
}
}
if teamOwner != "" {
team, err := auth.GetTeam(teamOwner)
if err != nil {
return err
}
app.TeamOwner = team.Name
err = app.validateTeamOwner()
if err != nil {
return err
}
app.Grant(team)
}
return conn.Apps().Update(bson.M{"name": app.Name}, app)
}
开发者ID:botvs,项目名称:tsuru,代码行数:53,代码来源:app.go
示例19: DeployPipeline
func (p *PipelineErrorFakeProvisioner) DeployPipeline() *action.Pipeline {
act := action.Action{
Name: "error-pipeline",
Forward: func(ctx action.FWContext) (action.Result, error) {
return nil, errors.New("deploy error")
},
Backward: func(ctx action.BWContext) {
},
}
actions := []*action.Action{&act}
pipeline := action.NewPipeline(actions...)
return pipeline
}
开发者ID:reoring,项目名称:tsuru,代码行数:13,代码来源:fake_provisioner.go
示例20: CreateServiceInstance
func CreateServiceInstance(instance ServiceInstance, service *Service, user *auth.User) error {
err := validateServiceInstanceName(service.Name, instance.Name)
if err != nil {
return err
}
instance.ServiceName = service.Name
if instance.TeamOwner == "" {
return ErrTeamMandatory
}
instance.Teams = []string{instance.TeamOwner}
actions := []*action.Action{&createServiceInstance, &insertServiceInstance}
pipeline := action.NewPipeline(actions...)
return pipeline.Execute(*service, instance, user.Email)
}
开发者ID:zhenruyan,项目名称:tsuru,代码行数:14,代码来源:service_instance.go
注:本文中的github.com/tsuru/tsuru/action.NewPipeline函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论