mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
move legacy stuff outside the job
Docker-DCO-1.1-Signed-off-by: Victor Vieux <victor.vieux@docker.com> (github: vieux)
This commit is contained in:
parent
aca1270104
commit
16ca6a1c12
6 changed files with 58 additions and 44 deletions
49
api.go
49
api.go
|
@ -10,6 +10,7 @@ import (
|
|||
"fmt"
|
||||
"github.com/dotcloud/docker/archive"
|
||||
"github.com/dotcloud/docker/auth"
|
||||
"github.com/dotcloud/docker/engine"
|
||||
"github.com/dotcloud/docker/pkg/systemd"
|
||||
"github.com/dotcloud/docker/utils"
|
||||
"github.com/gorilla/mux"
|
||||
|
@ -181,16 +182,54 @@ func getImagesJSON(srv *Server, version float64, w http.ResponseWriter, r *http.
|
|||
if err := parseForm(r); err != nil {
|
||||
return err
|
||||
}
|
||||
job := srv.Eng.Job("images")
|
||||
|
||||
var (
|
||||
buffer *bytes.Buffer
|
||||
job = srv.Eng.Job("images")
|
||||
)
|
||||
|
||||
job.Setenv("filter", r.Form.Get("filter"))
|
||||
job.Setenv("all", r.Form.Get("all"))
|
||||
job.SetenvBool("list", version <= 1.8)
|
||||
job.SetenvBool("legacy", version <= 1.7)
|
||||
job.Stdout.Add(w)
|
||||
w.WriteHeader(http.StatusOK)
|
||||
|
||||
if version >= 1.9 {
|
||||
job.Stdout.Add(w)
|
||||
} else {
|
||||
buffer = bytes.NewBuffer(nil)
|
||||
job.Stdout.Add(buffer)
|
||||
}
|
||||
|
||||
if err := job.Run(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if version < 1.9 { // Send as a valide JSON array
|
||||
outs := engine.NewTable("Created", 0)
|
||||
if _, err := outs.ReadFrom(buffer); err != nil {
|
||||
return err
|
||||
}
|
||||
if version < 1.8 { // Convert to legacy format
|
||||
outsLegacy := engine.NewTable("Created", 0)
|
||||
for _, out := range outs.Data {
|
||||
for _, repoTag := range out.GetList("RepoTags") {
|
||||
parts := strings.Split(repoTag, ":")
|
||||
outLegacy := &engine.Env{}
|
||||
outLegacy.Set("Repository", parts[0])
|
||||
outLegacy.Set("Tag", parts[1])
|
||||
outLegacy.Set("ID", out.Get("ID"))
|
||||
outLegacy.SetInt64("Created", out.GetInt64("Created"))
|
||||
outLegacy.SetInt64("Size", out.GetInt64("Size"))
|
||||
outLegacy.SetInt64("VirtualSize", out.GetInt64("VirtualSize"))
|
||||
outsLegacy.Add(outLegacy)
|
||||
}
|
||||
}
|
||||
if _, err := outsLegacy.WriteListTo(w); err != nil {
|
||||
return err
|
||||
}
|
||||
} else if _, err := outs.WriteListTo(w); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package engine
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestTableWriteTo(t *testing.T) {
|
||||
|
@ -19,7 +19,7 @@ func TestTableWriteTo(t *testing.T) {
|
|||
if err := json.Unmarshal(buf.Bytes(), &output); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(output) != 1 {
|
||||
if len(output) != 1 {
|
||||
t.Fatalf("Incorrect output: %v", output)
|
||||
}
|
||||
if val, exists := output["foo"]; !exists || val != "bar" {
|
||||
|
|
|
@ -59,7 +59,7 @@ func pingRegistryEndpoint(endpoint string) (bool, error) {
|
|||
// versions of the registry
|
||||
if standalone == "" {
|
||||
return true, nil
|
||||
// Accepted values are "true" (case-insensitive) and "1".
|
||||
// Accepted values are "true" (case-insensitive) and "1".
|
||||
} else if strings.EqualFold(standalone, "true") || standalone == "1" {
|
||||
return true, nil
|
||||
}
|
||||
|
|
37
server.go
37
server.go
|
@ -601,27 +601,12 @@ func (srv *Server) Images(job *engine.Job) engine.Status {
|
|||
}
|
||||
|
||||
if out, exists := lookup[id]; exists {
|
||||
if job.GetenvBool("legacy") {
|
||||
out2 := &engine.Env{}
|
||||
out2.Set("Repository", name)
|
||||
out2.Set("Tag", tag)
|
||||
out2.Set("ID", out.Get("ID"))
|
||||
out2.SetInt64("Created", out.GetInt64("Created"))
|
||||
out2.SetInt64("Size", out.GetInt64("Size"))
|
||||
out2.SetInt64("VirtualSize", out.GetInt64("VirtualSize"))
|
||||
} else {
|
||||
out.SetList("RepoTags", append(out.GetList("RepoTags"), fmt.Sprintf("%s:%s", name, tag)))
|
||||
}
|
||||
out.SetList("RepoTags", append(out.GetList("RepoTags"), fmt.Sprintf("%s:%s", name, tag)))
|
||||
} else {
|
||||
out := &engine.Env{}
|
||||
delete(allImages, id)
|
||||
if job.GetenvBool("legacy") {
|
||||
out.Set("Repository", name)
|
||||
out.Set("Tag", tag)
|
||||
} else {
|
||||
out.Set("ParentId", image.Parent)
|
||||
out.SetList("RepoTags", []string{fmt.Sprintf("%s:%s", name, tag)})
|
||||
}
|
||||
out.Set("ParentId", image.Parent)
|
||||
out.SetList("RepoTags", []string{fmt.Sprintf("%s:%s", name, tag)})
|
||||
out.Set("ID", image.ID)
|
||||
out.SetInt64("Created", image.Created.Unix())
|
||||
out.SetInt64("Size", image.Size)
|
||||
|
@ -641,13 +626,8 @@ func (srv *Server) Images(job *engine.Job) engine.Status {
|
|||
if job.Getenv("filter") == "" {
|
||||
for _, image := range allImages {
|
||||
out := &engine.Env{}
|
||||
if job.GetenvBool("legacy") {
|
||||
out.Set("Repository", "<none>")
|
||||
out.Set("Tag", "<none>")
|
||||
} else {
|
||||
out.Set("ParentId", image.Parent)
|
||||
out.SetList("RepoTags", []string{"<none>:<none>"})
|
||||
}
|
||||
out.Set("ParentId", image.Parent)
|
||||
out.SetList("RepoTags", []string{"<none>:<none>"})
|
||||
out.Set("ID", image.ID)
|
||||
out.SetInt64("Created", image.Created.Unix())
|
||||
out.SetInt64("Size", image.Size)
|
||||
|
@ -657,12 +637,7 @@ func (srv *Server) Images(job *engine.Job) engine.Status {
|
|||
}
|
||||
|
||||
outs.ReverseSort()
|
||||
if job.GetenvBool("list") {
|
||||
if _, err := outs.WriteListTo(job.Stdout); err != nil {
|
||||
job.Errorf("%s", err)
|
||||
return engine.StatusErr
|
||||
}
|
||||
} else if _, err := outs.WriteTo(job.Stdout); err != nil {
|
||||
if _, err := outs.WriteTo(job.Stdout); err != nil {
|
||||
job.Errorf("%s", err)
|
||||
return engine.StatusErr
|
||||
}
|
||||
|
|
|
@ -92,7 +92,7 @@ func Purge(maxAge int) int {
|
|||
datat = make(map[*http.Request]int64)
|
||||
} else {
|
||||
min := time.Now().Unix() - int64(maxAge)
|
||||
for r, _ := range data {
|
||||
for r := range data {
|
||||
if datat[r] < min {
|
||||
clear(r)
|
||||
count++
|
||||
|
|
|
@ -96,8 +96,8 @@ func TestRouteMatchers(t *testing.T) {
|
|||
method = "GET"
|
||||
headers = map[string]string{"X-Requested-With": "XMLHttpRequest"}
|
||||
resultVars = map[bool]map[string]string{
|
||||
true: map[string]string{"var1": "www", "var2": "product", "var3": "42"},
|
||||
false: map[string]string{},
|
||||
true: {"var1": "www", "var2": "product", "var3": "42"},
|
||||
false: {},
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -110,8 +110,8 @@ func TestRouteMatchers(t *testing.T) {
|
|||
method = "POST"
|
||||
headers = map[string]string{"Content-Type": "application/json"}
|
||||
resultVars = map[bool]map[string]string{
|
||||
true: map[string]string{"var4": "google", "var5": "product", "var6": "42"},
|
||||
false: map[string]string{},
|
||||
true: {"var4": "google", "var5": "product", "var6": "42"},
|
||||
false: {},
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue