mirror of
https://github.com/status-im/consul.git
synced 2025-01-12 23:05:28 +00:00
consul: Adding session lookup methods
This commit is contained in:
parent
836e1b5a10
commit
4695da527a
@ -299,6 +299,9 @@ func (s *StateStore) initialize() error {
|
||||
"KVSGet": MDBTables{s.kvsTable},
|
||||
"KVSList": MDBTables{s.kvsTable},
|
||||
"KVSListKeys": MDBTables{s.kvsTable},
|
||||
"SessionGet": MDBTables{s.sessionTable},
|
||||
"SessionList": MDBTables{s.sessionTable},
|
||||
"NodeSessions": MDBTables{s.sessionTable},
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@ -1212,6 +1215,36 @@ func (s *StateStore) SessionRestore(session *structs.Session) error {
|
||||
return tx.Commit()
|
||||
}
|
||||
|
||||
// SessionGet is used to get a session entry
|
||||
func (s *StateStore) SessionGet(id string) (uint64, *structs.Session, error) {
|
||||
idx, res, err := s.sessionTable.Get("id", id)
|
||||
var d *structs.Session
|
||||
if len(res) > 0 {
|
||||
d = res[0].(*structs.Session)
|
||||
}
|
||||
return idx, d, err
|
||||
}
|
||||
|
||||
// SessionList is used to list all the open sessions
|
||||
func (s *StateStore) SessionList() (uint64, []*structs.Session, error) {
|
||||
idx, res, err := s.sessionTable.Get("id")
|
||||
out := make([]*structs.Session, len(res))
|
||||
for i, raw := range res {
|
||||
out[i] = raw.(*structs.Session)
|
||||
}
|
||||
return idx, out, err
|
||||
}
|
||||
|
||||
// NodeSessions is used to list all the open sessions for a node
|
||||
func (s *StateStore) NodeSessions(node string) (uint64, []*structs.Session, error) {
|
||||
idx, res, err := s.sessionTable.Get("node", node)
|
||||
out := make([]*structs.Session, len(res))
|
||||
for i, raw := range res {
|
||||
out[i] = raw.(*structs.Session)
|
||||
}
|
||||
return idx, out, err
|
||||
}
|
||||
|
||||
// Snapshot is used to create a point in time snapshot
|
||||
func (s *StateStore) Snapshot() (*StateSnapshot, error) {
|
||||
// Begin a new txn on all tables
|
||||
|
Loading…
x
Reference in New Issue
Block a user