Skip to content
This repository has been archived by the owner on Apr 18, 2024. It is now read-only.

Integrate new orchestrator endpoint #161

Merged
merged 1 commit into from
Sep 18, 2023
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
9 changes: 9 additions & 0 deletions internal/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,12 @@ type State struct {
type PoolController interface {
DoRefresh()
}

type NodeInfo struct {
ID string `json:"id"`
IP string `json:"ip"`
Distance float32 `json:"distance"`
Weight int `json:"weight"`
ComplianceCid string `json:"complianceCid"`
Core bool `json:"core"`
}
15 changes: 13 additions & 2 deletions internal/util/harness.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"crypto/tls"
"encoding/json"
"errors"
"math/rand"
"net/http"
"net/http/httptest"
"net/url"
Expand All @@ -26,11 +27,21 @@ func BuildCabooseHarness(t *testing.T, n int, maxRetries int, opts ...HarnessOpt
ch := &CabooseHarness{}

ch.Endpoints = make([]*Endpoint, n)
purls := make([]string, n)
purls := make([]state.NodeInfo, n)
for i := 0; i < len(ch.Endpoints); i++ {
ch.Endpoints[i] = &Endpoint{}
ch.Endpoints[i].Setup()
purls[i] = strings.TrimPrefix(ch.Endpoints[i].Server.URL, "https://")
ip := strings.TrimPrefix(ch.Endpoints[i].Server.URL, "https://")

cid, _ := cid.V1Builder{Codec: uint64(multicodec.Raw), MhType: uint64(multicodec.Sha2_256)}.Sum([]byte(ip))

purls[i] = state.NodeInfo{
IP: ip,
ID: "node-id",
Weight: rand.Intn(100),
Distance: rand.Float32(),
ComplianceCid: cid.String(),
}
}
ch.goodOrch = true
orch := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
Expand Down
14 changes: 12 additions & 2 deletions pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/filecoin-saturn/caboose/internal/state"
"io"
"math/rand"
"net/url"
Expand Down Expand Up @@ -38,13 +39,22 @@ func (p *pool) loadPool() ([]string, error) {
}
defer resp.Body.Close()

responses := make([]string, 0)
responses := make([]state.NodeInfo, 0)

if err := json.NewDecoder(resp.Body).Decode(&responses); err != nil {
goLogger.Warnw("failed to decode backends from orchestrator", "err", err, "endpoint", p.config.OrchestratorEndpoint.String())
return nil, err
}

goLogger.Infow("got backends from orchestrators", "cnt", len(responses), "endpoint", p.config.OrchestratorEndpoint.String())
return responses, nil

var ips []string

for _, r := range responses {
ips = append(ips, r.IP)
}

return ips, nil
}

type mirroredPoolRequest struct {
Expand Down
Loading