Skip to content

Commit

Permalink
use gateway selector in sciencemesh
Browse files Browse the repository at this point in the history
Signed-off-by: Jörn Friedrich Dreyer <[email protected]>
  • Loading branch information
butonic committed Sep 18, 2024
1 parent fb39458 commit 3b54966
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 15 deletions.
5 changes: 5 additions & 0 deletions changelog/unreleased/sciencemesh-gateway-selector.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Bugfix: use gateway selector in sciencemesh

We now use a selector to get fresh ip addresses when running ocis in a kubernetes clustern.

https://github.com/cs3org/reva/pull/4851
12 changes: 8 additions & 4 deletions internal/http/services/sciencemesh/apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ import (
)

type appsHandler struct {
gatewayClient gateway.GatewayAPIClient
ocmMountPoint string
gatewaySelector *pool.Selector[gateway.GatewayAPIClient]
ocmMountPoint string
}

func (h *appsHandler) init(c *config) error {
var err error
h.gatewayClient, err = pool.GetGatewayServiceClient(c.GatewaySvc)
h.gatewaySelector, err = pool.GatewaySelector(c.GatewaySvc)
if err != nil {
return err
}
Expand Down Expand Up @@ -99,7 +99,11 @@ func (h *appsHandler) OpenInApp(w http.ResponseWriter, r *http.Request) {
}

func (h *appsHandler) webappTemplate(ctx context.Context, id *ocmpb.ShareId) (string, error) {
res, err := h.gatewayClient.GetReceivedOCMShare(ctx, &ocmpb.GetReceivedOCMShareRequest{
gc, err := h.gatewaySelector.Next()
if err != nil {
return "", err
}
res, err := gc.GetReceivedOCMShare(ctx, &ocmpb.GetReceivedOCMShareRequest{
Ref: &ocmpb.ShareReference{
Spec: &ocmpb.ShareReference_Id{
Id: id,
Expand Down
11 changes: 8 additions & 3 deletions internal/http/services/sciencemesh/providers.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ import (
)

type providersHandler struct {
gatewayClient gateway.GatewayAPIClient
gatewaySelector *pool.Selector[gateway.GatewayAPIClient]
}

func (h *providersHandler) init(c *config) error {
var err error
h.gatewayClient, err = pool.GetGatewayServiceClient(c.GatewaySvc)
h.gatewaySelector, err = pool.GatewaySelector(c.GatewaySvc)
if err != nil {
return err
}
Expand All @@ -55,7 +55,12 @@ func (h *providersHandler) ListProviders(w http.ResponseWriter, r *http.Request)
ctx := r.Context()
term := strings.ToLower(r.URL.Query().Get("search"))

listRes, err := h.gatewayClient.ListAllProviders(ctx, &providerpb.ListAllProvidersRequest{})
gc, err := h.gatewaySelector.Next()
if err != nil {
reqres.WriteError(w, r, reqres.APIErrorServerError, "error selecting gateway client", err)
return
}
listRes, err := gc.ListAllProviders(ctx, &providerpb.ListAllProvidersRequest{})
if err != nil {
reqres.WriteError(w, r, reqres.APIErrorServerError, "error listing all providers", err)
return
Expand Down
46 changes: 38 additions & 8 deletions internal/http/services/sciencemesh/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ import (
)

type tokenHandler struct {
gatewayClient gateway.GatewayAPIClient
gatewaySelector *pool.Selector[gateway.GatewayAPIClient]
meshDirectoryURL string
providerDomain string
eventStream events.Stream
}

func (h *tokenHandler) init(c *config) error {
var err error
h.gatewayClient, err = pool.GetGatewayServiceClient(c.GatewaySvc)
h.gatewaySelector, err = pool.GatewaySelector(c.GatewaySvc)
if err != nil {
return err
}
Expand Down Expand Up @@ -85,7 +85,12 @@ func (h *tokenHandler) Generate(w http.ResponseWriter, r *http.Request) {
}

ctx := r.Context()
genTokenRes, err := h.gatewayClient.GenerateInviteToken(ctx, &invitepb.GenerateInviteTokenRequest{
gc, err := h.gatewaySelector.Next()
if err != nil {
reqres.WriteError(w, r, reqres.APIErrorServerError, "error selecting gateway client", err)
return
}
genTokenRes, err := gc.GenerateInviteToken(ctx, &invitepb.GenerateInviteTokenRequest{
Description: req.Description,
})
switch {
Expand Down Expand Up @@ -185,7 +190,12 @@ func (h *tokenHandler) AcceptInvite(w http.ResponseWriter, r *http.Request) {
return
}

providerInfo, err := h.gatewayClient.GetInfoByDomain(ctx, &ocmprovider.GetInfoByDomainRequest{
gc, err := h.gatewaySelector.Next()
if err != nil {
reqres.WriteError(w, r, reqres.APIErrorServerError, "error selecting gateway client", err)
return
}
providerInfo, err := gc.GetInfoByDomain(ctx, &ocmprovider.GetInfoByDomainRequest{
Domain: req.ProviderDomain,
})
if err != nil {
Expand All @@ -197,13 +207,18 @@ func (h *tokenHandler) AcceptInvite(w http.ResponseWriter, r *http.Request) {
return
}

gc, err = h.gatewaySelector.Next()
if err != nil {
reqres.WriteError(w, r, reqres.APIErrorServerError, "error selecting gateway client", err)
return
}
forwardInviteReq := &invitepb.ForwardInviteRequest{
InviteToken: &invitepb.InviteToken{
Token: req.Token,
},
OriginSystemProvider: providerInfo.ProviderInfo,
}
forwardInviteResponse, err := h.gatewayClient.ForwardInvite(ctx, forwardInviteReq)
forwardInviteResponse, err := gc.ForwardInvite(ctx, forwardInviteReq)
if err != nil {
reqres.WriteError(w, r, reqres.APIErrorServerError, "error sending a grpc forward invite request", err)
return
Expand Down Expand Up @@ -258,7 +273,12 @@ type remoteUser struct {
func (h *tokenHandler) FindAccepted(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()

res, err := h.gatewayClient.FindAcceptedUsers(ctx, &invitepb.FindAcceptedUsersRequest{})
gc, err := h.gatewaySelector.Next()
if err != nil {
reqres.WriteError(w, r, reqres.APIErrorServerError, "error selecting gateway client", err)
return
}
res, err := gc.FindAcceptedUsers(ctx, &invitepb.FindAcceptedUsersRequest{})
if err != nil {
reqres.WriteError(w, r, reqres.APIErrorServerError, "error sending a grpc find accepted users request", err)
return
Expand Down Expand Up @@ -292,7 +312,12 @@ func (h *tokenHandler) DeleteAccepted(w http.ResponseWriter, r *http.Request) {
return
}

res, err := h.gatewayClient.DeleteAcceptedUser(ctx, &invitepb.DeleteAcceptedUserRequest{
gc, err := h.gatewaySelector.Next()
if err != nil {
reqres.WriteError(w, r, reqres.APIErrorServerError, "error selecting gateway client", err)
return
}
res, err := gc.DeleteAcceptedUser(ctx, &invitepb.DeleteAcceptedUserRequest{
RemoteUserId: &userpb.UserId{
Idp: req.Idp,
OpaqueId: req.UserID,
Expand Down Expand Up @@ -331,7 +356,12 @@ func getDeleteAcceptedRequest(r *http.Request) (*deleteAcceptedRequest, error) {
func (h *tokenHandler) ListInvite(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()

res, err := h.gatewayClient.ListInviteTokens(ctx, &invitepb.ListInviteTokensRequest{})
gc, err := h.gatewaySelector.Next()
if err != nil {
reqres.WriteError(w, r, reqres.APIErrorServerError, "error selecting gateway client", err)
return
}
res, err := gc.ListInviteTokens(ctx, &invitepb.ListInviteTokensRequest{})
if err != nil {
reqres.WriteError(w, r, reqres.APIErrorServerError, "error listing tokens", err)
return
Expand Down

0 comments on commit 3b54966

Please sign in to comment.