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

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use new orchestrator API
Browse files Browse the repository at this point in the history
aarshkshah1992 committed Sep 18, 2023
1 parent 550cf5b commit c0ea85c
Showing 3 changed files with 34 additions and 4 deletions.
9 changes: 9 additions & 0 deletions internal/state/state.go
Original file line number Diff line number Diff line change
@@ -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
@@ -5,6 +5,7 @@ import (
"crypto/tls"
"encoding/json"
"errors"
"math/rand"
"net/http"
"net/http/httptest"
"net/url"
@@ -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) {
14 changes: 12 additions & 2 deletions pool.go
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/filecoin-saturn/caboose/internal/state"
"io"
"math/rand"
"net/url"
@@ -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 {

0 comments on commit c0ea85c

Please sign in to comment.