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

Commit

Permalink
Merge pull request #161 from filecoin-saturn/feat/integrate-new-endpoint
Browse files Browse the repository at this point in the history
Integrate new orchestrator endpoint
  • Loading branch information
aarshkshah1992 authored Sep 18, 2023
2 parents 550cf5b + c0ea85c commit 608a668
Show file tree
Hide file tree
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
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

0 comments on commit 608a668

Please sign in to comment.