Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 883b677

Browse filesBrowse files
author
Mikhail Podtserkovskiy
committed
grid status method
1 parent 208d0ad commit 883b677
Copy full SHA for 883b677

File tree

Expand file treeCollapse file tree

4 files changed

+62
-17
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

4 files changed

+62
-17
lines changed
Open diff view settings
Collapse file

‎README.md‎

Copy file name to clipboardExpand all lines: README.md
+3Lines changed: 3 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,6 @@ Configurations are stored in json files. Example:
118118
| params.pod_creation_timeout | string as `12m`, `60s` | Max waiting time for creating a pod. |
119119
| node_list.[].params.image | string | Docker image with selenium. |
120120
| node_list.[].params.port | string | Port of selenium. |
121+
122+
## API
123+
- `/grid/status` - a method returns a status of a grid
Collapse file

‎handlers/gridStatus.go‎

Copy file name to clipboard
+43Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package handlers
2+
3+
import (
4+
"encoding/json"
5+
"fmt"
6+
"net/http"
7+
8+
log "github.com/sirupsen/logrus"
9+
10+
"github.com/qa-dev/jsonwire-grid/config"
11+
"github.com/qa-dev/jsonwire-grid/pool"
12+
)
13+
14+
// GridStatus - Returns a status.
15+
type GridStatus struct {
16+
Pool *pool.Pool
17+
Config config.Config
18+
}
19+
20+
type response struct {
21+
NodeList []pool.Node `json:"node_list"`
22+
Config config.Config `json:"config"`
23+
}
24+
25+
func (h *GridStatus) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
26+
nodeList, err := h.Pool.GetAll()
27+
if err != nil {
28+
http.Error(rw, fmt.Sprint("trying to get a node list from pool,", err), http.StatusInternalServerError)
29+
return
30+
}
31+
32+
resp := response{NodeList: nodeList, Config: h.Config}
33+
respJSON, err := json.Marshal(resp)
34+
if err != nil {
35+
http.Error(rw, fmt.Sprint("trying to encode a response,", err), http.StatusInternalServerError)
36+
return
37+
}
38+
39+
_, err = rw.Write(respJSON)
40+
if err != nil {
41+
log.Error("grid/status: write a response,", err)
42+
}
43+
}
Collapse file

‎main.go‎

Copy file name to clipboardExpand all lines: main.go
+8-9Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@ package main
33
import (
44
"context"
55
"fmt"
6+
"net/http"
7+
"os"
8+
"os/signal"
9+
"time"
10+
611
log "github.com/sirupsen/logrus"
12+
713
"github.com/qa-dev/jsonwire-grid/config"
814
"github.com/qa-dev/jsonwire-grid/handlers"
915
"github.com/qa-dev/jsonwire-grid/logger"
@@ -12,10 +18,6 @@ import (
1218
"github.com/qa-dev/jsonwire-grid/pool/capabilities"
1319
poolMetrics "github.com/qa-dev/jsonwire-grid/pool/metrics"
1420
"github.com/qa-dev/jsonwire-grid/utils/metrics"
15-
"net/http"
16-
"os"
17-
"os/signal"
18-
"time"
1921
)
2022

2123
func main() {
@@ -75,8 +77,6 @@ func main() {
7577
poolInstance.SetBusyNodeDuration(busyNodeDuration)
7678
poolInstance.SetReservedNodeDuration(reservedNodeDuration)
7779

78-
79-
8080
go func() {
8181
for {
8282
poolInstance.FixNodeStatuses()
@@ -93,8 +93,6 @@ func main() {
9393
}
9494
}()
9595

96-
97-
9896
if cfg.Statsd != nil {
9997
statsdClient, err := metrics.NewStatsd(
10098
cfg.Statsd.Host,
@@ -110,10 +108,11 @@ func main() {
110108
}
111109
middlewareWrap.Add(middleware.NewStatsd(log.StandardLogger(), statsdClient, true).RegisterMetrics)
112110
}
113-
111+
114112
http.Handle("/wd/hub/session", middlewareWrap.Do(&handlers.CreateSession{Pool: poolInstance, ClientFactory: clientFactory})) //selenium
115113
http.Handle("/session", middlewareWrap.Do(&handlers.CreateSession{Pool: poolInstance, ClientFactory: clientFactory})) //wda
116114
http.Handle("/grid/register", middlewareWrap.Do(&handlers.RegisterNode{Pool: poolInstance}))
115+
http.Handle("/grid/status", middlewareWrap.Do(&handlers.GridStatus{Pool: poolInstance, Config: *cfg}))
117116
http.Handle("/grid/api/proxy", &handlers.APIProxy{Pool: poolInstance})
118117
http.HandleFunc("/_info", heartbeat)
119118
http.Handle("/", middlewareWrap.Do(&handlers.UseSession{Pool: poolInstance, Cache: cache}))
Collapse file

‎pool/node.go‎

Copy file name to clipboardExpand all lines: pool/node.go
+8-8Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ type Node struct {
2222
// The value may depend on the strategy:
2323
// - for constant nodes ip: port
2424
// - for temporary pod.name
25-
Key string
26-
Type NodeType
27-
Address string
28-
Status NodeStatus
29-
SessionID string
30-
Updated int64
31-
Registered int64
32-
CapabilitiesList []capabilities.Capabilities
25+
Key string `json:"key"`
26+
Type NodeType `json:"type"`
27+
Address string `json:"address"`
28+
Status NodeStatus `json:"status"`
29+
SessionID string `json:"session_id"`
30+
Updated int64 `json:"updated"`
31+
Registered int64 `json:"registered"`
32+
CapabilitiesList []capabilities.Capabilities `json:"capabilities_list"`
3333
}
3434

3535
func (n *Node) String() string {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.