summaryrefslogtreecommitdiff
path: root/pkg/api/handlers/containers_top.go
diff options
context:
space:
mode:
authorValentin Rothberg <rothberg@redhat.com>2020-01-15 16:36:27 +0100
committerValentin Rothberg <rothberg@redhat.com>2020-01-15 17:08:22 +0100
commit9d54815c2690353a295b602b67084fd1f3c095e8 (patch)
tree96d38c68f56b566efedfc4632a5241ce8fe21d2d /pkg/api/handlers/containers_top.go
parent88372c2c21b653131f993825484bf9a5ea509bdf (diff)
downloadpodman-9d54815c2690353a295b602b67084fd1f3c095e8.tar.gz
podman-9d54815c2690353a295b602b67084fd1f3c095e8.tar.bz2
podman-9d54815c2690353a295b602b67084fd1f3c095e8.zip
refactor top code
Move the top logic from pkg/adapter into the (*libpod.Container).Top(). This way, we drop the dependency from pkg/api on pkg/adapters and have a clearer separation of concerns. Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
Diffstat (limited to 'pkg/api/handlers/containers_top.go')
-rw-r--r--pkg/api/handlers/containers_top.go20
1 files changed, 6 insertions, 14 deletions
diff --git a/pkg/api/handlers/containers_top.go b/pkg/api/handlers/containers_top.go
index 711f6858f..1a310262c 100644
--- a/pkg/api/handlers/containers_top.go
+++ b/pkg/api/handlers/containers_top.go
@@ -4,10 +4,7 @@ import (
"net/http"
"strings"
- "github.com/containers/libpod/cmd/podman/cliconfig"
"github.com/containers/libpod/libpod"
- "github.com/containers/libpod/libpod/define"
- "github.com/containers/libpod/pkg/adapter"
"github.com/containers/libpod/pkg/api/handlers/utils"
"github.com/gorilla/mux"
"github.com/gorilla/schema"
@@ -30,19 +27,14 @@ func TopContainer(w http.ResponseWriter, r *http.Request) {
}
name := mux.Vars(r)["name"]
+ c, err := runtime.LookupContainer(name)
+ if err != nil {
+ utils.ContainerNotFound(w, name, err)
+ return
+ }
- adapterRuntime := adapter.LocalRuntime{}
- adapterRuntime.Runtime = runtime
-
- topValues := cliconfig.TopValues{}
- topValues.InputArgs = []string{name, query.PsArgs}
-
- output, err := adapterRuntime.Top(&topValues)
+ output, err := c.Top([]string{query.PsArgs})
if err != nil {
- if errors.Cause(err) == define.ErrNoSuchCtr {
- utils.ContainerNotFound(w, name, err)
- return
- }
utils.InternalServerError(w, err)
return
}