Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,6 @@ Configurations are stored in json files. Example:
| node_list.[].params.port | string | Port of selenium. |

## API
- `/grid/status` - a method returns a status of a grid
- `/grid/status` - a method returns a status of a grid
- `/grid/session/info` - a returns a session info by session id.
Еxample: `curl -X http://localhost:4444/grid/session/info?sessionid=9fc185d2-7a3d-4660-877f-cd4ca2a2f5c3`
57 changes: 57 additions & 0 deletions handlers/sessionInfo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package handlers

import (
"encoding/json"
"fmt"
"net/http"

log "github.com/sirupsen/logrus"

"github.com/qa-dev/jsonwire-grid/pool"
)

// SessionInfo - Returns a session info (node address, status, etc)
type SessionInfo struct {
Pool *pool.Pool
}

type sessionInfoResponse struct {
NodeAddress string `json:"node_address"`
NodeType pool.NodeType `json:"node_type"`
Status pool.NodeStatus `json:"node_status"`
SessionID string `json:"session_id"`
Updated int64 `json:"updated"`
Registered int64 `json:"registered"`
}

func (h *SessionInfo) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
sessionId := r.URL.Query().Get("sessionid")
if sessionId == "" {
http.Error(rw, fmt.Sprint("session id must be specified,"), http.StatusBadRequest)
return
}
node, err := h.Pool.GetNodeBySessionID(sessionId)
if err != nil {
http.Error(rw, fmt.Sprint("trying to get a session data,", err), http.StatusInternalServerError)
return
}

resp := sessionInfoResponse{
node.Address,
node.Type,
node.Status,
node.SessionID,
node.Updated,
node.Registered,
}
respJSON, err := json.Marshal(resp)
if err != nil {
http.Error(rw, fmt.Sprint("trying to encode a response,", err), http.StatusInternalServerError)
return
}

_, err = rw.Write(respJSON)
if err != nil {
log.Error("session/info: write a response,", err)
}
}
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ func main() {
http.Handle("/session", middlewareWrap.Do(&handlers.CreateSession{Pool: poolInstance, ClientFactory: clientFactory})) //wda
http.Handle("/grid/register", middlewareWrap.Do(&handlers.RegisterNode{Pool: poolInstance}))
http.Handle("/grid/status", middlewareWrap.Do(&handlers.GridStatus{Pool: poolInstance, Config: *cfg}))
http.Handle("/grid/session/info", middlewareWrap.Do(&handlers.SessionInfo{Pool: poolInstance}))
http.Handle("/grid/api/proxy", &handlers.APIProxy{Pool: poolInstance})
http.HandleFunc("/_info", heartbeat)
http.Handle("/", middlewareWrap.Do(&handlers.UseSession{Pool: poolInstance, Cache: cache}))
Expand Down