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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,6 @@ Configurations are stored in json files. Example:
| params.pod_creation_timeout | string as `12m`, `60s` | Max waiting time for creating a pod. |
| node_list.[].params.image | string | Docker image with selenium. |
| node_list.[].params.port | string | Port of selenium. |

## API
- `/grid/status` - a method returns a status of a grid
43 changes: 43 additions & 0 deletions handlers/gridStatus.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package handlers

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

log "github.com/sirupsen/logrus"

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

// GridStatus - Returns a status.
type GridStatus struct {
Pool *pool.Pool
Config config.Config
}

type response struct {
NodeList []pool.Node `json:"node_list"`
Config config.Config `json:"config"`
}

func (h *GridStatus) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
nodeList, err := h.Pool.GetAll()
if err != nil {
http.Error(rw, fmt.Sprint("trying to get a node list from pool,", err), http.StatusInternalServerError)
return
}

resp := response{NodeList: nodeList, Config: h.Config}
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("grid/status: write a response,", err)
}
}
17 changes: 8 additions & 9 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@ package main
import (
"context"
"fmt"
"net/http"
"os"
"os/signal"
"time"

log "github.com/sirupsen/logrus"

"github.com/qa-dev/jsonwire-grid/config"
"github.com/qa-dev/jsonwire-grid/handlers"
"github.com/qa-dev/jsonwire-grid/logger"
Expand All @@ -12,10 +18,6 @@ import (
"github.com/qa-dev/jsonwire-grid/pool/capabilities"
poolMetrics "github.com/qa-dev/jsonwire-grid/pool/metrics"
"github.com/qa-dev/jsonwire-grid/utils/metrics"
"net/http"
"os"
"os/signal"
"time"
)

func main() {
Expand Down Expand Up @@ -75,8 +77,6 @@ func main() {
poolInstance.SetBusyNodeDuration(busyNodeDuration)
poolInstance.SetReservedNodeDuration(reservedNodeDuration)



go func() {
for {
poolInstance.FixNodeStatuses()
Expand All @@ -93,8 +93,6 @@ func main() {
}
}()



if cfg.Statsd != nil {
statsdClient, err := metrics.NewStatsd(
cfg.Statsd.Host,
Expand All @@ -110,10 +108,11 @@ func main() {
}
middlewareWrap.Add(middleware.NewStatsd(log.StandardLogger(), statsdClient, true).RegisterMetrics)
}

http.Handle("/wd/hub/session", middlewareWrap.Do(&handlers.CreateSession{Pool: poolInstance, ClientFactory: clientFactory})) //selenium
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/api/proxy", &handlers.APIProxy{Pool: poolInstance})
http.HandleFunc("/_info", heartbeat)
http.Handle("/", middlewareWrap.Do(&handlers.UseSession{Pool: poolInstance, Cache: cache}))
Expand Down
16 changes: 8 additions & 8 deletions pool/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ type Node struct {
// The value may depend on the strategy:
// - for constant nodes ip: port
// - for temporary pod.name
Key string
Type NodeType
Address string
Status NodeStatus
SessionID string
Updated int64
Registered int64
CapabilitiesList []capabilities.Capabilities
Key string `json:"key"`
Type NodeType `json:"type"`
Address string `json:"address"`
Status NodeStatus `json:"status"`
SessionID string `json:"session_id"`
Updated int64 `json:"updated"`
Registered int64 `json:"registered"`
CapabilitiesList []capabilities.Capabilities `json:"capabilities_list"`
}

func (n *Node) String() string {
Expand Down