-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into 246-show-migration-id-x-should-display-ac…
…tive-migrations
- Loading branch information
Showing
7 changed files
with
255 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package brain | ||
|
||
import ( | ||
"io" | ||
|
||
"github.com/BytemarkHosting/bytemark-client/lib/output" | ||
"github.com/BytemarkHosting/bytemark-client/lib/output/prettyprint" | ||
) | ||
|
||
// MigrationJobs represents more than one account in output.Outputtable form. | ||
type MigrationJobs []MigrationJob | ||
|
||
// DefaultFields returns the list of default fields to feed to github.com/BytemarkHosting/row.From for this type, which is the same as MigrationJob.DefaultFields. | ||
func (mjs MigrationJobs) DefaultFields(f output.Format) string { | ||
return (MigrationJob{}).DefaultFields(f) | ||
} | ||
|
||
// PrettyPrint writes a human-readable summary of the migration jobs to writer at the given detail level. | ||
func (mjs MigrationJobs) PrettyPrint(wr io.Writer, detail prettyprint.DetailLevel) error { | ||
migrationjobsTpl := ` | ||
{{ define "migrationjobs_sgl" }}{{ len . }} servers{{ end }} | ||
{{ define "migrationjobs_medium" -}} | ||
{{- range . -}} | ||
{{- prettysprint . "_sgl" }} | ||
{{ end -}} | ||
{{- end }} | ||
{{ define "migrationjobs_full" }}{{ template "migrationjobs_medium" . }}{{ end }} | ||
` | ||
return prettyprint.Run(wr, migrationjobsTpl, "migrationjobs"+string(detail), mjs) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package brain | ||
|
||
import ( | ||
"bytes" | ||
"testing" | ||
|
||
"github.com/BytemarkHosting/bytemark-client/lib/output/prettyprint" | ||
) | ||
|
||
func TestFormatMigrationJobs(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
in MigrationJobs | ||
detail prettyprint.DetailLevel | ||
exp string | ||
}{ | ||
{ | ||
name: "NoJobs", | ||
in: MigrationJobs{}, | ||
detail: prettyprint.Full, | ||
exp: ``, | ||
}, | ||
{ | ||
name: "OneJob", | ||
in: MigrationJobs{{ | ||
ID: 123, | ||
Queue: MigrationJobQueue{ | ||
Discs: []int{1, 2}, | ||
}, | ||
}}, | ||
detail: prettyprint.Full, | ||
exp: ` ▸ 123 queue: 1 2` + "\n", | ||
}, | ||
{ | ||
name: "TwoJobs", | ||
in: MigrationJobs{ | ||
{ | ||
ID: 123, | ||
Queue: MigrationJobQueue{ | ||
Discs: []int{1, 2}, | ||
}, | ||
}, | ||
{ | ||
ID: 456, | ||
Queue: MigrationJobQueue{ | ||
Discs: []int{3, 4}, | ||
}, | ||
}, | ||
}, | ||
detail: prettyprint.Full, | ||
exp: ` ▸ 123 queue: 1 2` + "\n" + ` ▸ 456 queue: 3 4` + "\n", | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.name, func(t *testing.T) { | ||
b := new(bytes.Buffer) | ||
err := test.in.PrettyPrint(b, test.detail) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
if b.String() != test.exp { | ||
t.Errorf("unexpected output: %s", b.String()) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package brain | ||
|
||
import ( | ||
"github.com/BytemarkHosting/bytemark-client/lib" | ||
"github.com/BytemarkHosting/bytemark-client/lib/brain" | ||
) | ||
|
||
// GetMigrationJobs returns an array of unfinished migration jobs | ||
func GetMigrationJobs(client lib.Client) (mjs brain.MigrationJobs, err error) { | ||
r, err := client.BuildRequest("GET", lib.BrainEndpoint, "/admin/migration_jobs?unfinished=1%s", "") | ||
if err != nil { | ||
return | ||
} | ||
|
||
_, _, err = r.Run(nil, &mjs) | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package brain_test | ||
|
||
import ( | ||
"encoding/json" | ||
"testing" | ||
|
||
"github.com/BytemarkHosting/bytemark-client/lib" | ||
"github.com/BytemarkHosting/bytemark-client/lib/brain" | ||
brainMethods "github.com/BytemarkHosting/bytemark-client/lib/requests/brain" | ||
"github.com/BytemarkHosting/bytemark-client/lib/testutil" | ||
"github.com/BytemarkHosting/bytemark-client/lib/testutil/assert" | ||
"github.com/BytemarkHosting/bytemark-client/lib/util" | ||
) | ||
|
||
func TestGetMigrationJobs(t *testing.T) { | ||
testName := testutil.Name(0) | ||
|
||
testMigrationJobs := brain.MigrationJobs{{ | ||
ID: 123, | ||
Args: brain.MigrationJobSpec{ | ||
Sources: brain.MigrationJobLocations{ | ||
Discs: []util.NumberOrString{"3"}, | ||
}, | ||
Destinations: brain.MigrationJobLocations{ | ||
Pools: []util.NumberOrString{"pool.21"}, | ||
}, | ||
}, | ||
Queue: brain.MigrationJobQueue{ | ||
Discs: []int{3}, | ||
}, | ||
Destinations: brain.MigrationJobDestinations{ | ||
Pools: []int{21}, | ||
}, | ||
Status: brain.MigrationJobStatus{ | ||
Discs: brain.MigrationJobDiscStatus{ | ||
Done: []int{}, | ||
Errored: []int{}, | ||
Cancelled: []int{}, | ||
Skipped: []int{}, | ||
}, | ||
}, | ||
Priority: 5, | ||
CreatedAt: "2018-03-15T14:23:00.579Z", | ||
UpdatedAt: "2018-03-15T15:28:28.244Z", | ||
}} | ||
|
||
rts := testutil.RequestTestSpec{ | ||
Method: "GET", | ||
URL: "/admin/migration_jobs", | ||
AssertRequest: assert.QueryValue("unfinished", "1"), | ||
Endpoint: lib.BrainEndpoint, | ||
Response: json.RawMessage(`[{ | ||
"id": 123, | ||
"args": { | ||
"options": {}, | ||
"sources": { | ||
"discs": [3] | ||
}, | ||
"destinations": { | ||
"pools": ["pool.21"] | ||
} | ||
}, | ||
"queue": { | ||
"discs": [3] | ||
}, | ||
"destinations": { | ||
"pools": [21] | ||
}, | ||
"status": { | ||
"discs": { | ||
"done": [], | ||
"errored": [], | ||
"cancelled": [], | ||
"skipped": [] | ||
} | ||
}, | ||
"priority": 5, | ||
"started_at": null, | ||
"finished_at": null, | ||
"created_at": "2018-03-15T14:23:00.579Z", | ||
"updated_at": "2018-03-15T15:28:28.244Z" | ||
}]`), | ||
} | ||
|
||
rts.Run(t, testName, true, func(client lib.Client) { | ||
migrationJobs, err := brainMethods.GetMigrationJobs(client) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
assert.Equal(t, testName, migrationJobs, testMigrationJobs) | ||
}) | ||
} |