Skip to content

Commit

Permalink
move viz to a job
Browse files Browse the repository at this point in the history
Docker-DCO-1.1-Signed-off-by: Victor Vieux <[email protected]> (github: vieux)
  • Loading branch information
vieux committed Jan 15, 2014
1 parent 0113c08 commit 7fbc315
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
5 changes: 1 addition & 4 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,10 +238,7 @@ func getImagesViz(srv *Server, version float64, w http.ResponseWriter, r *http.R
w.WriteHeader(http.StatusNotFound)
return fmt.Errorf("This is now implemented in the client.")
}

if err := srv.ImagesViz(w); err != nil {
return err
}
srv.Eng.ServeHTTP(w, r)
return nil
}

Expand Down
6 changes: 4 additions & 2 deletions engine/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ import (
// as the exit status.
//
func (eng *Engine) ServeHTTP(w http.ResponseWriter, r *http.Request) {
jobName := path.Base(r.URL.Path)
jobArgs, exists := r.URL.Query()["a"]
var (
jobName = path.Base(r.URL.Path)
jobArgs, exists = r.URL.Query()["a"]
)
if !exists {
jobArgs = []string{}
}
Expand Down
23 changes: 14 additions & 9 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ func jobInitApi(job *engine.Job) engine.Status {
job.Error(err)
return engine.StatusErr
}
if err := job.Eng.Register("viz", srv.ImagesViz); err != nil {
job.Error(err)
return engine.StatusErr
}
return engine.StatusOK
}

Expand Down Expand Up @@ -538,12 +542,12 @@ func (srv *Server) ImageInsert(name, url, path string, out io.Writer, sf *utils.
return nil
}

func (srv *Server) ImagesViz(out io.Writer) error {
func (srv *Server) ImagesViz(job *engine.Job) engine.Status {
images, _ := srv.runtime.graph.Map()
if images == nil {
return nil
return engine.StatusOK
}
out.Write([]byte("digraph docker {\n"))
job.Stdout.Write([]byte("digraph docker {\n"))

var (
parentImage *Image
Expand All @@ -552,12 +556,13 @@ func (srv *Server) ImagesViz(out io.Writer) error {
for _, image := range images {
parentImage, err = image.GetParent()
if err != nil {
return fmt.Errorf("Error while getting parent image: %v", err)
job.Errorf("Error while getting parent image: %v", err)
return engine.StatusErr
}
if parentImage != nil {
out.Write([]byte(" \"" + parentImage.ID + "\" -> \"" + image.ID + "\"\n"))
job.Stdout.Write([]byte(" \"" + parentImage.ID + "\" -> \"" + image.ID + "\"\n"))
} else {
out.Write([]byte(" base -> \"" + image.ID + "\" [style=invis]\n"))
job.Stdout.Write([]byte(" base -> \"" + image.ID + "\" [style=invis]\n"))
}
}

Expand All @@ -570,10 +575,10 @@ func (srv *Server) ImagesViz(out io.Writer) error {
}

for id, repos := range reporefs {
out.Write([]byte(" \"" + id + "\" [label=\"" + id + "\\n" + strings.Join(repos, "\\n") + "\",shape=box,fillcolor=\"paleturquoise\",style=\"filled,rounded\"];\n"))
job.Stdout.Write([]byte(" \"" + id + "\" [label=\"" + id + "\\n" + strings.Join(repos, "\\n") + "\",shape=box,fillcolor=\"paleturquoise\",style=\"filled,rounded\"];\n"))
}
out.Write([]byte(" base [style=invisible]\n}\n"))
return nil
job.Stdout.Write([]byte(" base [style=invisible]\n}\n"))
return engine.StatusOK
}

func (srv *Server) Images(job *engine.Job) engine.Status {
Expand Down

0 comments on commit 7fbc315

Please sign in to comment.