Skip to content

Commit

Permalink
fix: REST fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Hare committed Apr 4, 2024
1 parent 2c0730a commit 8154508
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 19 deletions.
15 changes: 15 additions & 0 deletions cmd/provider-services/cmd/grpc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package cmd

import (
"fmt"
"net"
)

func grpcURI(hostURI string) (string, error) {
host, _, err := net.SplitHostPort(hostURI)
if err != nil {
return "", fmt.Errorf("split host port: %w", err)
}

return net.JoinHostPort(host, "8442"), nil
}
42 changes: 31 additions & 11 deletions cmd/provider-services/cmd/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmd
import (
"bytes"
"context"
"crypto/tls"
"encoding/json"
"fmt"
"time"
Expand All @@ -22,6 +23,7 @@ import (

aclient "github.com/akash-network/provider/client"
gwgrpc "github.com/akash-network/provider/gateway/grpc"
gwrest "github.com/akash-network/provider/gateway/rest"
)

var errSubmitManifestFailed = errors.New("submit manifest to some providers has been failed")
Expand Down Expand Up @@ -111,25 +113,43 @@ func doSendManifest(cmd *cobra.Command, sdlpath string) error {
return fmt.Errorf("query client provider: %w", err)
}

c, err := gwgrpc.NewClient(ctx, prov.GetProvider().HostURI, cert, cl)
hostURIgRPC, err := grpcURI(prov.GetProvider().HostURI)
if err != nil {
return fmt.Errorf("new grpc conn: %w", err)
return fmt.Errorf("grpc uri: %w", err)
}

defer c.Close()

res := result{
Provider: provAddr,
Status: "PASS",
}

if _, err = c.SendManifest(ctx, &leasev1.SendManifestRequest{
LeaseId: lid,
Manifest: mani,
}); err != nil {
res.Error = err.Error()
res.Status = "FAIL"
submitFailed = true
c, err := gwgrpc.NewClient(ctx, hostURIgRPC, cert, cl)
if err == nil {
defer c.Close()

if _, err = c.SendManifest(ctx, &leasev1.SendManifestRequest{
LeaseId: lid,
Manifest: mani,
}); err != nil {
res.Error = err.Error()
res.Status = "FAIL"
submitFailed = true
}
} else {
gclient, err := gwrest.NewClient(cl, provAddr, []tls.Certificate{cert})
if err != nil {
return fmt.Errorf("gwrest new client: %w", err)
}

err = gclient.SubmitManifest(cmd.Context(), dseq, mani)
if err != nil {
res.Error = err.Error()
if e, valid := err.(gwrest.ClientResponseError); valid {
res.ErrorMessage = e.Message
}
res.Status = "FAIL"
submitFailed = true
}
}

results[i] = res
Expand Down
5 changes: 3 additions & 2 deletions cmd/provider-services/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"strings"
"time"

cltypes "github.com/akash-network/akash-api/go/node/client/types"
sdkclient "github.com/cosmos/cosmos-sdk/client"
"github.com/pkg/errors"
"github.com/shopspring/decimal"
Expand All @@ -21,6 +20,8 @@ import (
"golang.org/x/sync/errgroup"
"k8s.io/client-go/kubernetes"

cltypes "github.com/akash-network/akash-api/go/node/client/types"

"github.com/tendermint/tendermint/libs/log"

"github.com/cosmos/cosmos-sdk/client/flags"
Expand Down Expand Up @@ -204,7 +205,7 @@ func RunCmd() *cobra.Command {
panic(err)
}

cmd.Flags().String(FlagGatewayGRPCListenAddress, "0.0.0.0:8442", "Gateway gRPC listen address")
cmd.Flags().String(FlagGatewayGRPCListenAddress, "0.0.0.0:8444", "Gateway gRPC listen address")
if err := viper.BindPFlag(FlagGatewayGRPCListenAddress, cmd.Flags().Lookup(FlagGatewayGRPCListenAddress)); err != nil {
panic(err)
}
Expand Down
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ require (
github.com/cosmos/cosmos-sdk v0.45.16
github.com/desertbit/timer v0.0.0-20180107155436-c41aec40b27f
github.com/fsnotify/fsnotify v1.7.0
github.com/go-andiamo/splitter v1.2.5
github.com/go-kit/kit v0.12.0
github.com/go-logr/logr v1.2.4
github.com/go-logr/zapr v1.2.4
Expand Down Expand Up @@ -262,7 +261,7 @@ require (
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto v0.0.0-20240318140521-94a12d6c2237 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240318140521-94a12d6c2237 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240318140521-94a12d6c2237 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240325203815-454cdb8f5daa // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/square/go-jose.v2 v2.6.0 // indirect
Expand Down
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -629,8 +629,6 @@ github.com/globalsign/mgo v0.0.0-20180905125535-1ca0a4f7cbcb/go.mod h1:xkRDCp4j0
github.com/globalsign/mgo v0.0.0-20181015135952-eeefdecb41b8/go.mod h1:xkRDCp4j0OGD1HRkm4kmhM+pmpv3AKq5SU7GMg4oO/Q=
github.com/glycerine/go-unsnap-stream v0.0.0-20180323001048-9f0cb55181dd/go.mod h1:/20jfyN9Y5QPEAprSgKAUr+glWDY39ZiUEAYOEv5dsE=
github.com/glycerine/goconvey v0.0.0-20190410193231-58a59202ab31/go.mod h1:Ogl1Tioa0aV7gstGFO7KhffUsb9M4ydbEbbxpcEDc24=
github.com/go-andiamo/splitter v1.2.5 h1:P3NovWMY2V14TJJSolXBvlOmGSZo3Uz+LtTl2bsV/eY=
github.com/go-andiamo/splitter v1.2.5/go.mod h1:8WHU24t9hcMKU5FXDQb1hysSEC/GPuivIp0uKY1J8gw=
github.com/go-asn1-ber/asn1-ber v1.3.1/go.mod h1:hEBeB/ic+5LoWskz+yKT7vGhhPYkProFKoKdwZRWMe0=
github.com/go-check/check v0.0.0-20180628173108-788fd7840127/go.mod h1:9ES+weclKsC9YodN5RgxqK/VD9HM9JsCSh7rNhMZE98=
github.com/go-chi/chi/v5 v5.0.0/go.mod h1:BBug9lr0cqtdAhsu6R4AAdvufI0/XBzAQSsUqJpoZOs=
Expand Down Expand Up @@ -2544,8 +2542,8 @@ google.golang.org/genproto v0.0.0-20240318140521-94a12d6c2237 h1:PgNlNSx2Nq2/j4j
google.golang.org/genproto v0.0.0-20240318140521-94a12d6c2237/go.mod h1:9sVD8c25Af3p0rGs7S7LLsxWKFiJt/65LdSyqXBkX/Y=
google.golang.org/genproto/googleapis/api v0.0.0-20240318140521-94a12d6c2237 h1:RFiFrvy37/mpSpdySBDrUdipW/dHwsRwh3J3+A9VgT4=
google.golang.org/genproto/googleapis/api v0.0.0-20240318140521-94a12d6c2237/go.mod h1:Z5Iiy3jtmioajWHDGFk7CeugTyHtPvMHA4UTmUkyalE=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240318140521-94a12d6c2237 h1:NnYq6UN9ReLM9/Y01KWNOWyI5xQ9kbIms5GGJVwS/Yc=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240318140521-94a12d6c2237/go.mod h1:WtryC6hu0hhx87FDGxWCDptyssuo68sk10vYjF+T9fY=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240325203815-454cdb8f5daa h1:RBgMaUMP+6soRkik4VoN8ojR2nex2TqZwjSSogic+eo=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240325203815-454cdb8f5daa/go.mod h1:WtryC6hu0hhx87FDGxWCDptyssuo68sk10vYjF+T9fY=
google.golang.org/grpc v1.8.0/go.mod h1:yo6s7OP7yaDglbqo1J04qKzAhqBH6lvTonzMVmEdcZw=
google.golang.org/grpc v1.12.0/go.mod h1:yo6s7OP7yaDglbqo1J04qKzAhqBH6lvTonzMVmEdcZw=
google.golang.org/grpc v1.14.0/go.mod h1:yo6s7OP7yaDglbqo1J04qKzAhqBH6lvTonzMVmEdcZw=
Expand Down

0 comments on commit 8154508

Please sign in to comment.