diff options
author | Matthew Heon <matthew.heon@gmail.com> | 2018-02-23 15:28:56 -0500 |
---|---|---|
committer | Atomic Bot <atomic-devel@projectatomic.io> | 2018-03-01 21:17:50 +0000 |
commit | 2a0c949b9bab88f4e05d39b5e6d7db62bb39df11 (patch) | |
tree | 35c75dcf96b4d571c29daafb54c6bc0c4be29c41 /libpod/sql_state_internal.go | |
parent | 920b66707ece354b8dbf00416b5a26abdee93a2f (diff) | |
download | podman-2a0c949b9bab88f4e05d39b5e6d7db62bb39df11.tar.gz podman-2a0c949b9bab88f4e05d39b5e6d7db62bb39df11.tar.bz2 podman-2a0c949b9bab88f4e05d39b5e6d7db62bb39df11.zip |
Add tracking for container exec sessions to DB
Signed-off-by: Matthew Heon <matthew.heon@gmail.com>
Closes: #412
Approved by: baude
Diffstat (limited to 'libpod/sql_state_internal.go')
-rw-r--r-- | libpod/sql_state_internal.go | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/libpod/sql_state_internal.go b/libpod/sql_state_internal.go index d0771e0d8..6f0e2284c 100644 --- a/libpod/sql_state_internal.go +++ b/libpod/sql_state_internal.go @@ -33,7 +33,8 @@ const ( containerState.Pid, containerState.NetNSPath, containerState.IPAddress, - containerState.SubnetMask + containerState.SubnetMask, + containerState.ExecSessions FROM containers INNER JOIN containerState ON containers.Id = containerState.Id ` @@ -274,6 +275,7 @@ func prepareDB(db *sql.DB) (err error) { NetNSPath TEXT NOT NULL, IPAddress TEXT NOT NULL, SubnetMask TEXT NOT NULL, + ExecSessions TEXT NOT NULL, CHECK (State>0), CHECK (OomKilled IN (0, 1)), @@ -483,6 +485,7 @@ func (s *SQLState) ctrFromScannable(row scannable) (*Container, error) { netNSPath string ipAddress string subnetMask string + execSessions string ) err := row.Scan( @@ -536,7 +539,8 @@ func (s *SQLState) ctrFromScannable(row scannable) (*Container, error) { &pid, &netNSPath, &ipAddress, - &subnetMask) + &subnetMask, + &execSessions) if err != nil { if err == sql.ErrNoRows { return nil, ErrNoSuchCtr @@ -616,6 +620,11 @@ func (s *SQLState) ctrFromScannable(row scannable) (*Container, error) { return nil, errors.Wrapf(err, "error parsing container %s DNS server JSON", id) } + ctr.state.ExecSessions = make(map[string]int) + if err := json.Unmarshal([]byte(execSessions), &ctr.state.ExecSessions); err != nil { + return nil, errors.Wrapf(err, "error parsing container %s exec sessions JSON", id) + } + labels := make(map[string]string) if err := json.Unmarshal([]byte(labelsJSON), &labels); err != nil { return nil, errors.Wrapf(err, "error parsing container %s labels JSON", id) @@ -753,7 +762,7 @@ func (s *SQLState) addContainer(ctr *Container, pod *Pod) (err error) { addCtrState = `INSERT INTO containerState VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, - ?, ?, ? + ?, ?, ?, ? );` addRegistry = "INSERT INTO registry VALUES (?, ?);" checkCtrInPod = "SELECT 1 FROM containers WHERE Id=? AND Pod=?;" @@ -795,6 +804,11 @@ func (s *SQLState) addContainer(ctr *Container, pod *Pod) (err error) { return errors.Wrapf(err, "error marshaling container %s labels to JSON", ctr.ID()) } + execSessionsJSON, err := json.Marshal(ctr.state.ExecSessions) + if err != nil { + return errors.Wrapf(err, "error marshalling container %s exec sessions to JSON", ctr.ID()) + } + netNSPath := "" if ctr.state.NetNS != nil { netNSPath = ctr.state.NetNS.Path() @@ -918,7 +932,8 @@ func (s *SQLState) addContainer(ctr *Container, pod *Pod) (err error) { ctr.state.PID, netNSPath, ctr.state.IPAddress, - ctr.state.SubnetMask) + ctr.state.SubnetMask, + execSessionsJSON) if err != nil { return errors.Wrapf(err, "error adding container %s state to database", ctr.ID()) } |