mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-05-24 05:48:36 -05:00
First part of index reset
This commit is contained in:
@@ -42,6 +42,16 @@ func getRegistryStrategy(cfg *config.Config) string {
|
||||
return "cs3"
|
||||
}
|
||||
|
||||
func (i Indexer) Reset() error {
|
||||
for k := range i.indices {
|
||||
delete(i.indices, k)
|
||||
}
|
||||
|
||||
// TODO: delete indexes from storage (cs3 / disk)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// AddIndex adds a new index to the indexer receiver.
|
||||
func (i Indexer) AddIndex(t interface{}, indexBy, pkName, entityDirName, indexType string, bound *option.Bound, caseInsensitive bool) error {
|
||||
strategy := getRegistryStrategy(i.config)
|
||||
|
||||
+1941
-985
File diff suppressed because it is too large
Load Diff
@@ -551,3 +551,77 @@ func (h *groupsServiceHandler) RemoveMember(ctx context.Context, in *RemoveMembe
|
||||
func (h *groupsServiceHandler) ListMembers(ctx context.Context, in *ListMembersRequest, out *ListMembersResponse) error {
|
||||
return h.GroupsServiceHandler.ListMembers(ctx, in, out)
|
||||
}
|
||||
|
||||
// Api Endpoints for IndexService service
|
||||
|
||||
func NewIndexServiceEndpoints() []*api.Endpoint {
|
||||
return []*api.Endpoint{
|
||||
&api.Endpoint{
|
||||
Name: "IndexService.RebuildIndex",
|
||||
Path: []string{"/api/v0/index/rebuild"},
|
||||
Method: []string{"POST"},
|
||||
Body: "*",
|
||||
Handler: "rpc",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// Client API for IndexService service
|
||||
|
||||
type IndexService interface {
|
||||
RebuildIndex(ctx context.Context, in *RebuildIndexRequest, opts ...client.CallOption) (*RebuildIndexResponse, error)
|
||||
}
|
||||
|
||||
type indexService struct {
|
||||
c client.Client
|
||||
name string
|
||||
}
|
||||
|
||||
func NewIndexService(name string, c client.Client) IndexService {
|
||||
return &indexService{
|
||||
c: c,
|
||||
name: name,
|
||||
}
|
||||
}
|
||||
|
||||
func (c *indexService) RebuildIndex(ctx context.Context, in *RebuildIndexRequest, opts ...client.CallOption) (*RebuildIndexResponse, error) {
|
||||
req := c.c.NewRequest(c.name, "IndexService.RebuildIndex", in)
|
||||
out := new(RebuildIndexResponse)
|
||||
err := c.c.Call(ctx, req, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// Server API for IndexService service
|
||||
|
||||
type IndexServiceHandler interface {
|
||||
RebuildIndex(context.Context, *RebuildIndexRequest, *RebuildIndexResponse) error
|
||||
}
|
||||
|
||||
func RegisterIndexServiceHandler(s server.Server, hdlr IndexServiceHandler, opts ...server.HandlerOption) error {
|
||||
type indexService interface {
|
||||
RebuildIndex(ctx context.Context, in *RebuildIndexRequest, out *RebuildIndexResponse) error
|
||||
}
|
||||
type IndexService struct {
|
||||
indexService
|
||||
}
|
||||
h := &indexServiceHandler{hdlr}
|
||||
opts = append(opts, api.WithEndpoint(&api.Endpoint{
|
||||
Name: "IndexService.RebuildIndex",
|
||||
Path: []string{"/api/v0/index/rebuild"},
|
||||
Method: []string{"POST"},
|
||||
Body: "*",
|
||||
Handler: "rpc",
|
||||
}))
|
||||
return s.Handle(s.NewHandler(&IndexService{h}, opts...))
|
||||
}
|
||||
|
||||
type indexServiceHandler struct {
|
||||
IndexServiceHandler
|
||||
}
|
||||
|
||||
func (h *indexServiceHandler) RebuildIndex(ctx context.Context, in *RebuildIndexRequest, out *RebuildIndexResponse) error {
|
||||
return h.IndexServiceHandler.RebuildIndex(ctx, in, out)
|
||||
}
|
||||
|
||||
@@ -372,6 +372,120 @@ func RegisterGroupsServiceWeb(r chi.Router, i GroupsServiceHandler, middlewares
|
||||
r.MethodFunc("POST", "/api/v0/groups/{id=*}/members/$ref", handler.ListMembers)
|
||||
}
|
||||
|
||||
type webIndexServiceHandler struct {
|
||||
r chi.Router
|
||||
h IndexServiceHandler
|
||||
}
|
||||
|
||||
func (h *webIndexServiceHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
h.r.ServeHTTP(w, r)
|
||||
}
|
||||
|
||||
func (h *webIndexServiceHandler) RebuildIndex(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
req := &RebuildIndexRequest{}
|
||||
|
||||
resp := &RebuildIndexResponse{}
|
||||
|
||||
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
||||
http.Error(w, err.Error(), http.StatusPreconditionFailed)
|
||||
return
|
||||
}
|
||||
|
||||
if err := h.h.RebuildIndex(
|
||||
r.Context(),
|
||||
req,
|
||||
resp,
|
||||
); err != nil {
|
||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
render.Status(r, http.StatusCreated)
|
||||
render.JSON(w, r, resp)
|
||||
}
|
||||
|
||||
func RegisterIndexServiceWeb(r chi.Router, i IndexServiceHandler, middlewares ...func(http.Handler) http.Handler) {
|
||||
handler := &webIndexServiceHandler{
|
||||
r: r,
|
||||
h: i,
|
||||
}
|
||||
|
||||
r.MethodFunc("POST", "/api/v0/index/rebuild", handler.RebuildIndex)
|
||||
}
|
||||
|
||||
// RebuildIndexRequestJSONMarshaler describes the default jsonpb.Marshaler used by all
|
||||
// instances of RebuildIndexRequest. This struct is safe to replace or modify but
|
||||
// should not be done so concurrently.
|
||||
var RebuildIndexRequestJSONMarshaler = new(jsonpb.Marshaler)
|
||||
|
||||
// MarshalJSON satisfies the encoding/json Marshaler interface. This method
|
||||
// uses the more correct jsonpb package to correctly marshal the message.
|
||||
func (m *RebuildIndexRequest) MarshalJSON() ([]byte, error) {
|
||||
if m == nil {
|
||||
return json.Marshal(nil)
|
||||
}
|
||||
|
||||
buf := &bytes.Buffer{}
|
||||
|
||||
if err := RebuildIndexRequestJSONMarshaler.Marshal(buf, m); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
|
||||
var _ json.Marshaler = (*RebuildIndexRequest)(nil)
|
||||
|
||||
// RebuildIndexRequestJSONUnmarshaler describes the default jsonpb.Unmarshaler used by all
|
||||
// instances of RebuildIndexRequest. This struct is safe to replace or modify but
|
||||
// should not be done so concurrently.
|
||||
var RebuildIndexRequestJSONUnmarshaler = new(jsonpb.Unmarshaler)
|
||||
|
||||
// UnmarshalJSON satisfies the encoding/json Unmarshaler interface. This method
|
||||
// uses the more correct jsonpb package to correctly unmarshal the message.
|
||||
func (m *RebuildIndexRequest) UnmarshalJSON(b []byte) error {
|
||||
return RebuildIndexRequestJSONUnmarshaler.Unmarshal(bytes.NewReader(b), m)
|
||||
}
|
||||
|
||||
var _ json.Unmarshaler = (*RebuildIndexRequest)(nil)
|
||||
|
||||
// RebuildIndexResponseJSONMarshaler describes the default jsonpb.Marshaler used by all
|
||||
// instances of RebuildIndexResponse. This struct is safe to replace or modify but
|
||||
// should not be done so concurrently.
|
||||
var RebuildIndexResponseJSONMarshaler = new(jsonpb.Marshaler)
|
||||
|
||||
// MarshalJSON satisfies the encoding/json Marshaler interface. This method
|
||||
// uses the more correct jsonpb package to correctly marshal the message.
|
||||
func (m *RebuildIndexResponse) MarshalJSON() ([]byte, error) {
|
||||
if m == nil {
|
||||
return json.Marshal(nil)
|
||||
}
|
||||
|
||||
buf := &bytes.Buffer{}
|
||||
|
||||
if err := RebuildIndexResponseJSONMarshaler.Marshal(buf, m); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
|
||||
var _ json.Marshaler = (*RebuildIndexResponse)(nil)
|
||||
|
||||
// RebuildIndexResponseJSONUnmarshaler describes the default jsonpb.Unmarshaler used by all
|
||||
// instances of RebuildIndexResponse. This struct is safe to replace or modify but
|
||||
// should not be done so concurrently.
|
||||
var RebuildIndexResponseJSONUnmarshaler = new(jsonpb.Unmarshaler)
|
||||
|
||||
// UnmarshalJSON satisfies the encoding/json Unmarshaler interface. This method
|
||||
// uses the more correct jsonpb package to correctly unmarshal the message.
|
||||
func (m *RebuildIndexResponse) UnmarshalJSON(b []byte) error {
|
||||
return RebuildIndexResponseJSONUnmarshaler.Unmarshal(bytes.NewReader(b), m)
|
||||
}
|
||||
|
||||
var _ json.Unmarshaler = (*RebuildIndexResponse)(nil)
|
||||
|
||||
// ListAccountsRequestJSONMarshaler describes the default jsonpb.Marshaler used by all
|
||||
// instances of ListAccountsRequest. This struct is safe to replace or modify but
|
||||
// should not be done so concurrently.
|
||||
|
||||
@@ -137,7 +137,14 @@ service GroupsService {
|
||||
}
|
||||
|
||||
service IndexService {
|
||||
rpc RebuildIndex(RebuildIndexRequest) returns (RebuildIndexResponse);
|
||||
rpc RebuildIndex(RebuildIndexRequest) returns (RebuildIndexResponse) {
|
||||
// All request parameters go into body.
|
||||
option (google.api.http) = {
|
||||
// URLs are broken
|
||||
post: "/api/v0/index/rebuild"
|
||||
body: "*"
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
message RebuildIndexRequest {
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -26,6 +26,9 @@ func Server(opts ...Option) grpc.Service {
|
||||
if err := proto.RegisterGroupsServiceHandler(service.Server(), handler); err != nil {
|
||||
options.Logger.Fatal().Err(err).Msg("could not register groups handler")
|
||||
}
|
||||
if err := proto.RegisterIndexServiceHandler(service.Server(), handler); err != nil {
|
||||
options.Logger.Fatal().Err(err).Msg("could not register index handler")
|
||||
}
|
||||
|
||||
service.Init()
|
||||
return service
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/owncloud/ocis/accounts/pkg/proto/v0"
|
||||
)
|
||||
|
||||
func (s Service) RebuildIndex(ctx context.Context, request *proto.RebuildIndexRequest, response *proto.RebuildIndexResponse) error {
|
||||
if err := s.index.Reset(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user