Skip to content

Commit

Permalink
Delay registering app
Browse files Browse the repository at this point in the history
  • Loading branch information
ishank011 committed Jul 1, 2021
1 parent 290c1b2 commit 00b96bf
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 28 deletions.
15 changes: 7 additions & 8 deletions examples/ocmd/ocmd-server-1.toml
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,18 @@ providers = "providers.demo.json"
[grpc.services.publicshareprovider]
driver = "memory"

[grpc.services.appregistry]
driver = "static"

[grpc.services.appprovider]
driver = "wopi"
driver = "demo"
app_provider_url = "localhost:19000"

[grpc.services.appprovider.drivers.wopi]
iop_secret = "hello"
wopi_url = "http://0.0.0.0:8880/"
wopi_bridge_url = "http://localhost:8000/wopib"

[grpc.services.appregistry]
driver = "static"

[grpc.services.appregistry.drivers.static.providers]
"localhost:19000" = {"address" = "localhost:19000", "name" = "WOPIServer", mimetypes = ["text/plain", "text/markdown", "application/compressed-markdown", "application/vnd.oasis.opendocument.text", "application/vnd.oasis.opendocument.spreadsheet", "application/vnd.oasis.opendocument.presentation"]}
app_name = "Collabora"
app_url = "https://your-collabora-server.org:9980"

[grpc.services.storageprovider]
driver = "localhome"
Expand Down
43 changes: 29 additions & 14 deletions internal/grpc/services/appprovider/appprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,16 @@ package appprovider

import (
"context"
"os"
"time"

providerpb "github.com/cs3org/go-cs3apis/cs3/app/provider/v1beta1"
registrypb "github.com/cs3org/go-cs3apis/cs3/app/registry/v1beta1"
rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
"github.com/cs3org/reva/pkg/app"
"github.com/cs3org/reva/pkg/app/provider/registry"
"github.com/cs3org/reva/pkg/errtypes"
"github.com/cs3org/reva/pkg/logger"
"github.com/cs3org/reva/pkg/rgrpc"
"github.com/cs3org/reva/pkg/rgrpc/status"
"github.com/cs3org/reva/pkg/rgrpc/todo/pool"
Expand Down Expand Up @@ -81,31 +84,43 @@ func New(m map[string]interface{}, ss *grpc.Server) (rgrpc.Service, error) {
return nil, err
}

service := &service{
conf: c,
provider: provider,
}

go service.registerProvider()
return service, nil
}

func (s *service) registerProvider() {
// Give the appregistry service time to come up
time.Sleep(2 * time.Second)

ctx := context.Background()
pInfo, err := provider.GetAppProviderInfo(ctx)
log := logger.New().With().Int("pid", os.Getpid()).Logger()
pInfo, err := s.provider.GetAppProviderInfo(ctx)
if err != nil {
return nil, err
log.Error().Err(err).Msgf("error registering app provider: could not get provider info")
return
}
pInfo.Address = c.AppProviderURL
pInfo.Address = s.conf.AppProviderURL

client, err := pool.GetGatewayServiceClient(c.GatewaySvc)
client, err := pool.GetGatewayServiceClient(s.conf.GatewaySvc)
if err != nil {
return nil, err
log.Error().Err(err).Msgf("error registering app provider: could not get gateway client")
return
}
res, err := client.AddAppProvider(ctx, &registrypb.AddAppProviderRequest{Provider: pInfo})
if err != nil {
return nil, err
log.Error().Err(err).Msgf("error registering app provider: error calling add app provider")
return
}
if res.Status.Code != rpc.Code_CODE_OK {
return nil, status.NewErrorFromCode(res.Status.Code, "appprovider")
err = status.NewErrorFromCode(res.Status.Code, "appprovider")
log.Error().Err(err).Msgf("error registering app provider: add app provider returned error")
return
}

service := &service{
conf: c,
provider: provider,
}

return service, nil
}

func (s *service) Close() error {
Expand Down
2 changes: 1 addition & 1 deletion internal/grpc/services/appregistry/appregistry.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (s *svc) Close() error {
}

func (s *svc) UnprotectedEndpoints() []string {
return []string{"/cs3.app.registry.v1beta1.UserAPI/AddAppProvider"}
return []string{"/cs3.app.registry.v1beta1.RegistryAPI/AddAppProvider"}
}

func (s *svc) Register(ss *grpc.Server) {
Expand Down
10 changes: 5 additions & 5 deletions pkg/app/provider/wopi/wopi.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ func parseWopiDiscovery(body io.Reader) (map[string]map[string]string, error) {
if _, ok := appURLs[access]; !ok {
appURLs[access] = make(map[string]string)
}
appURLs[access][ext] = url
appURLs[access]["."+ext] = url
}
}
}
Expand All @@ -298,17 +298,17 @@ func parseWopiDiscovery(body io.Reader) (map[string]map[string]string, error) {
func getCodimdExtensions(appURL string) map[string]map[string]string {
appURLs := make(map[string]map[string]string)
appURLs["edit"] = map[string]string{
"txt": appURL,
"md": appURL,
"zmd": appURL,
".txt": appURL,
".md": appURL,
".zmd": appURL,
}
return appURLs
}

func getEtherpadExtensions(appURL string) map[string]map[string]string {
appURLs := make(map[string]map[string]string)
appURLs["edit"] = map[string]string{
"etherpad": appURL,
".etherpad": appURL,
}
return appURLs
}

0 comments on commit 00b96bf

Please sign in to comment.