Skip to content

Commit

Permalink
Merge pull request #112 from Scalingo/fix/storky/1/add_region_migrati…
Browse files Browse the repository at this point in the history
…ons_service

Add region migrations service
  • Loading branch information
Soulou authored Jul 16, 2019
2 parents ae4fb22 + 2e6a4ba commit 90775f6
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 0 deletions.
1 change: 1 addition & 0 deletions apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ type App struct {
} `json:"owner"`
GitUrl string `json:"git_url"`
Url string `json:"url"`
BaseURL string `json:"base_url"`
Status AppStatus `json:"status"`
LastDeployedAt *time.Time `json:"last_deployed_at"`
LastDeployedBy string `json:"last_deployed_by"`
Expand Down
1 change: 1 addition & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type API interface {
NotifiersService
OperationsService
RegionsService
RegionMigrationsService
RunsService
SignUpService
SourcesService
Expand Down
87 changes: 87 additions & 0 deletions region_migrations.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package scalingo

import (
"time"

errgo "gopkg.in/errgo.v1"
)

const (
RegionMigrationStatusScheduled RegionMigrationStatus = "scheduled"
RegionMigrationStatusPreflightError RegionMigrationStatus = "preflight-error"
RegionMigrationStatusRunning RegionMigrationStatus = "running"
RegionMigrationStatusError RegionMigrationStatus = "error"
RegionMigrationStatusDone RegionMigrationStatus = "done"

StepStatusRunning StepStatus = "running"
StepStatusDone StepStatus = "done"
StepStatusError StepStatus = "error"
)

type RegionMigrationsService interface {
CreateRegionMigration(appID string, params RegionMigrationParams) (RegionMigration, error)
ShowRegionMigration(appID, migrationID string) (RegionMigration, error)
ListRegionMigrations(appID string) ([]RegionMigration, error)
}

type RegionMigrationParams struct {
Destination string `json:"destination"`
}

type RegionMigration struct {
ID string `json:"id"`
AppName string `json:"app_name"`
AppID string `json:"app_id"`
NewAppID string `json:"new_app_id"`
Destination string `json:"destination"`
Status RegionMigrationStatus `json:"status"`
StartedAt time.Time `json:"started_at"`
FinishedAt time.Time `json:"finished_at"`
Steps Steps `json:"steps"`
}

type StepStatus string
type RegionMigrationStatus string
type Steps []Step

type Step struct {
ID string `json:"id"`
Name string `json:"name"`
Status StepStatus `json:"status"`
Logs string `json:"logs"`
}

func (c *Client) CreateRegionMigration(appID string, params RegionMigrationParams) (RegionMigration, error) {
var migration RegionMigration

err := c.ScalingoAPI().SubresourceAdd("apps", appID, "region_migrations", map[string]RegionMigrationParams{
"migration": params,
}, &migration)
if err != nil {
return migration, errgo.Notef(err, "fail to create migration")
}

return migration, nil
}

func (c *Client) ShowRegionMigration(appID, migrationID string) (RegionMigration, error) {
var migration RegionMigration

err := c.ScalingoAPI().SubresourceGet("apps", appID, "region_migrations", migrationID, nil, &migration)
if err != nil {
return migration, errgo.Notef(err, "fail to get migration")
}

return migration, nil
}

func (c *Client) ListRegionMigrations(appID string) ([]RegionMigration, error) {
var migrations []RegionMigration

err := c.ScalingoAPI().SubresourceList("apps", appID, "region_migrations", nil, &migrations)
if err != nil {
return migrations, errgo.Notef(err, "fail to list migrations")
}

return migrations, nil
}

0 comments on commit 90775f6

Please sign in to comment.