GODT-1982: updated gRPC and GUI for disk cache.

Other: modified bridge-gui-tester for new cache related gRPC interface.
Other: bridge-gui-tester has buttons for cache related errors.
This commit is contained in:
Xavier Michelon
2022-10-27 18:59:42 +02:00
committed by James Houlahan
parent 93d9ae32fc
commit d9762010fa
27 changed files with 2662 additions and 3947 deletions

File diff suppressed because it is too large Load Diff

View File

@ -73,7 +73,7 @@ service Bridge {
// cache
rpc DiskCachePath(google.protobuf.Empty) returns (google.protobuf.StringValue);
rpc ChangeLocalCache(ChangeLocalCacheRequest) returns (google.protobuf.Empty);
rpc SetDiskCachePath(google.protobuf.StringValue) returns (google.protobuf.Empty);
// mail
rpc SetIsDoHEnabled(google.protobuf.BoolValue) returns (google.protobuf.Empty);
@ -157,13 +157,6 @@ message LoginAbortRequest {
string username = 1;
}
//**********************************************************
// Cache on disk related message
//**********************************************************
message ChangeLocalCacheRequest {
string diskCachePath = 2;
}
//**********************************************************
// Port related message
//**********************************************************
@ -222,7 +215,7 @@ message StreamEvent {
AppEvent app = 1;
LoginEvent login = 2;
UpdateEvent update = 3;
CacheEvent cache = 4;
DiskCacheEvent cache = 4;
MailSettingsEvent mailSettings = 5;
KeychainEvent keychain = 6;
MailEvent mail = 7;
@ -338,38 +331,35 @@ message UpdateCheckFinished {}
message UpdateVersionChanged {}
//**********************************************************
// Cache on disk related events
//**********************************************************
message CacheEvent {
message DiskCacheEvent {
oneof event {
CacheErrorEvent error = 1;
CacheLocationChangeSuccessEvent locationChangedSuccess = 2;
ChangeLocalCacheFinishedEvent changeLocalCacheFinished = 3;
DiskCachePathChanged diskCachePathChanged = 5;
DiskCacheErrorEvent error = 1;
DiskCachePathChangedEvent pathChanged = 2;
DiskCachePathChangeFinishedEvent pathChangeFinished = 3;
}
}
enum CacheErrorType {
CACHE_UNAVAILABLE_ERROR = 0;
CACHE_CANT_MOVE_ERROR = 1;
DISK_FULL = 2;
enum DiskCacheErrorType {
DISK_CACHE_UNAVAILABLE_ERROR = 0;
CANT_MOVE_DISK_CACHE_ERROR = 1;
DISK_FULL_ERROR = 2;
};
message CacheErrorEvent {
CacheErrorType type = 1;
message DiskCacheErrorEvent {
DiskCacheErrorType type = 1;
}
message CacheLocationChangeSuccessEvent {};
message ChangeLocalCacheFinishedEvent {
bool willRestart = 1;
};
message DiskCachePathChanged {
message DiskCachePathChangedEvent {
string path = 1;
}
message DiskCachePathChangeFinishedEvent {}
//**********************************************************
// Mail settings related events

View File

@ -1,7 +1,7 @@
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
// versions:
// - protoc-gen-go-grpc v1.2.0
// - protoc v3.19.4
// - protoc v3.21.3
// source: bridge.proto
package grpc
@ -66,7 +66,7 @@ type BridgeClient interface {
IsAutomaticUpdateOn(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*wrapperspb.BoolValue, error)
// cache
DiskCachePath(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*wrapperspb.StringValue, error)
ChangeLocalCache(ctx context.Context, in *ChangeLocalCacheRequest, opts ...grpc.CallOption) (*emptypb.Empty, error)
SetDiskCachePath(ctx context.Context, in *wrapperspb.StringValue, opts ...grpc.CallOption) (*emptypb.Empty, error)
// mail
SetIsDoHEnabled(ctx context.Context, in *wrapperspb.BoolValue, opts ...grpc.CallOption) (*emptypb.Empty, error)
IsDoHEnabled(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*wrapperspb.BoolValue, error)
@ -436,9 +436,9 @@ func (c *bridgeClient) DiskCachePath(ctx context.Context, in *emptypb.Empty, opt
return out, nil
}
func (c *bridgeClient) ChangeLocalCache(ctx context.Context, in *ChangeLocalCacheRequest, opts ...grpc.CallOption) (*emptypb.Empty, error) {
func (c *bridgeClient) SetDiskCachePath(ctx context.Context, in *wrapperspb.StringValue, opts ...grpc.CallOption) (*emptypb.Empty, error) {
out := new(emptypb.Empty)
err := c.cc.Invoke(ctx, "/grpc.Bridge/ChangeLocalCache", in, out, opts...)
err := c.cc.Invoke(ctx, "/grpc.Bridge/SetDiskCachePath", in, out, opts...)
if err != nil {
return nil, err
}
@ -711,7 +711,7 @@ type BridgeServer interface {
IsAutomaticUpdateOn(context.Context, *emptypb.Empty) (*wrapperspb.BoolValue, error)
// cache
DiskCachePath(context.Context, *emptypb.Empty) (*wrapperspb.StringValue, error)
ChangeLocalCache(context.Context, *ChangeLocalCacheRequest) (*emptypb.Empty, error)
SetDiskCachePath(context.Context, *wrapperspb.StringValue) (*emptypb.Empty, error)
// mail
SetIsDoHEnabled(context.Context, *wrapperspb.BoolValue) (*emptypb.Empty, error)
IsDoHEnabled(context.Context, *emptypb.Empty) (*wrapperspb.BoolValue, error)
@ -856,8 +856,8 @@ func (UnimplementedBridgeServer) IsAutomaticUpdateOn(context.Context, *emptypb.E
func (UnimplementedBridgeServer) DiskCachePath(context.Context, *emptypb.Empty) (*wrapperspb.StringValue, error) {
return nil, status.Errorf(codes.Unimplemented, "method DiskCachePath not implemented")
}
func (UnimplementedBridgeServer) ChangeLocalCache(context.Context, *ChangeLocalCacheRequest) (*emptypb.Empty, error) {
return nil, status.Errorf(codes.Unimplemented, "method ChangeLocalCache not implemented")
func (UnimplementedBridgeServer) SetDiskCachePath(context.Context, *wrapperspb.StringValue) (*emptypb.Empty, error) {
return nil, status.Errorf(codes.Unimplemented, "method SetDiskCachePath not implemented")
}
func (UnimplementedBridgeServer) SetIsDoHEnabled(context.Context, *wrapperspb.BoolValue) (*emptypb.Empty, error) {
return nil, status.Errorf(codes.Unimplemented, "method SetIsDoHEnabled not implemented")
@ -1604,20 +1604,20 @@ func _Bridge_DiskCachePath_Handler(srv interface{}, ctx context.Context, dec fun
return interceptor(ctx, in, info, handler)
}
func _Bridge_ChangeLocalCache_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(ChangeLocalCacheRequest)
func _Bridge_SetDiskCachePath_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(wrapperspb.StringValue)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(BridgeServer).ChangeLocalCache(ctx, in)
return srv.(BridgeServer).SetDiskCachePath(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/grpc.Bridge/ChangeLocalCache",
FullMethod: "/grpc.Bridge/SetDiskCachePath",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(BridgeServer).ChangeLocalCache(ctx, req.(*ChangeLocalCacheRequest))
return srv.(BridgeServer).SetDiskCachePath(ctx, req.(*wrapperspb.StringValue))
}
return interceptor(ctx, in, info, handler)
}
@ -2177,8 +2177,8 @@ var Bridge_ServiceDesc = grpc.ServiceDesc{
Handler: _Bridge_DiskCachePath_Handler,
},
{
MethodName: "ChangeLocalCache",
Handler: _Bridge_ChangeLocalCache_Handler,
MethodName: "SetDiskCachePath",
Handler: _Bridge_SetDiskCachePath_Handler,
},
{
MethodName: "SetIsDoHEnabled",

View File

@ -97,22 +97,16 @@ func NewUpdateVersionChangedEvent() *StreamEvent {
return updateEvent(&UpdateEvent{Event: &UpdateEvent_VersionChanged{VersionChanged: &UpdateVersionChanged{}}})
}
func NewCacheErrorEvent(err CacheErrorType) *StreamEvent {
return cacheEvent(&CacheEvent{Event: &CacheEvent_Error{Error: &CacheErrorEvent{Type: err}}})
func NewDiskCacheErrorEvent(err DiskCacheErrorType) *StreamEvent {
return cacheEvent(&DiskCacheEvent{Event: &DiskCacheEvent_Error{Error: &DiskCacheErrorEvent{Type: err}}})
}
func NewCacheLocationChangeSuccessEvent() *StreamEvent {
return cacheEvent(&CacheEvent{Event: &CacheEvent_LocationChangedSuccess{LocationChangedSuccess: &CacheLocationChangeSuccessEvent{}}})
func NewDiskCachePathChangedEvent(path string) *StreamEvent {
return cacheEvent(&DiskCacheEvent{Event: &DiskCacheEvent_PathChanged{PathChanged: &DiskCachePathChangedEvent{Path: path}}})
}
func NewCacheChangeLocalCacheFinishedEvent(willRestart bool) *StreamEvent {
return cacheEvent(&CacheEvent{Event: &CacheEvent_ChangeLocalCacheFinished{
ChangeLocalCacheFinished: &ChangeLocalCacheFinishedEvent{WillRestart: willRestart},
}})
}
func NewDiskCachePathChanged(path string) *StreamEvent {
return cacheEvent(&CacheEvent{Event: &CacheEvent_DiskCachePathChanged{DiskCachePathChanged: &DiskCachePathChanged{Path: path}}})
func NewDiskCachePathChangeFinishedEvent() *StreamEvent {
return cacheEvent(&DiskCacheEvent{Event: &DiskCacheEvent_PathChangeFinished{PathChangeFinished: &DiskCachePathChangeFinishedEvent{}}})
}
func NewMailSettingsErrorEvent(err MailSettingsErrorType) *StreamEvent {
@ -185,7 +179,7 @@ func updateEvent(event *UpdateEvent) *StreamEvent {
return &StreamEvent{Event: &StreamEvent_Update{Update: event}}
}
func cacheEvent(event *CacheEvent) *StreamEvent {
func cacheEvent(event *DiskCacheEvent) *StreamEvent {
return &StreamEvent{Event: &StreamEvent_Cache{Cache: event}}
}

View File

@ -249,7 +249,7 @@ func (s *Service) LicensePath(ctx context.Context, _ *emptypb.Empty) (*wrappersp
return wrapperspb.String(s.bridge.GetLicenseFilePath()), nil
}
func (s *Service) DependencyLicensesLink(ctx context.Context, _ *emptypb.Empty) (*wrapperspb.StringValue, error) {
func (s *Service) DependencyLicensesLink(_ context.Context, _ *emptypb.Empty) (*wrapperspb.StringValue, error) {
return wrapperspb.String(s.bridge.GetDependencyLicensesLink()), nil
}
@ -257,7 +257,7 @@ func (s *Service) ReleaseNotesPageLink(ctx context.Context, _ *emptypb.Empty) (*
return wrapperspb.String(s.newVersionInfo.ReleaseNotesPage), nil
}
func (s *Service) LandingPageLink(ctx context.Context, _ *emptypb.Empty) (*wrapperspb.StringValue, error) {
func (s *Service) LandingPageLink(_ context.Context, _ *emptypb.Empty) (*wrapperspb.StringValue, error) {
return wrapperspb.String(s.newVersionInfo.LandingPage), nil
}
@ -535,30 +535,30 @@ func (s *Service) DiskCachePath(ctx context.Context, _ *emptypb.Empty) (*wrapper
return wrapperspb.String(s.bridge.GetGluonDir()), nil
}
func (s *Service) ChangeLocalCache(ctx context.Context, change *ChangeLocalCacheRequest) (*emptypb.Empty, error) {
s.log.WithField("diskCachePath", change.DiskCachePath).Debug("DiskCachePath")
func (s *Service) SetDiskCachePath(ctx context.Context, newPath *wrapperspb.StringValue) (*emptypb.Empty, error) {
s.log.WithField("path", newPath.Value).Debug("setDiskCachePath")
defer func() {
_ = s.SendEvent(NewCacheChangeLocalCacheFinishedEvent(false))
}()
go func() {
defer func() {
_ = s.SendEvent(NewDiskCachePathChangeFinishedEvent())
}()
path := change.DiskCachePath
//goland:noinspection GoBoolExpressions
if (runtime.GOOS == "windows") && (path[0] == '/') {
path = path[1:]
}
if path != s.bridge.GetGluonDir() {
if err := s.bridge.SetGluonDir(ctx, path); err != nil {
s.log.WithError(err).Error("The local cache location could not be changed.")
_ = s.SendEvent(NewCacheErrorEvent(CacheErrorType_CACHE_CANT_MOVE_ERROR))
return &emptypb.Empty{}, nil
path := newPath.Value
//goland:noinspection GoBoolExpressions
if (runtime.GOOS == "windows") && (path[0] == '/') {
path = path[1:]
}
_ = s.SendEvent(NewDiskCachePathChanged(s.bridge.GetGluonDir()))
}
if path != s.bridge.GetGluonDir() {
if err := s.bridge.SetGluonDir(context.Background(), path); err != nil {
s.log.WithError(err).Error("The local cache location could not be changed.")
_ = s.SendEvent(NewDiskCacheErrorEvent(DiskCacheErrorType_CANT_MOVE_DISK_CACHE_ERROR))
return
}
_ = s.SendEvent(NewCacheLocationChangeSuccessEvent())
_ = s.SendEvent(NewDiskCachePathChangedEvent(s.bridge.GetGluonDir()))
}
}()
return &emptypb.Empty{}, nil
}

View File

@ -75,7 +75,7 @@ func (s *Service) RunEventStream(request *EventStreamRequest, server Bridge_RunE
}
// StopEventStream stops the event stream.
func (s *Service) StopEventStream(ctx context.Context, _ *emptypb.Empty) (*emptypb.Empty, error) {
func (s *Service) StopEventStream(_ context.Context, _ *emptypb.Empty) (*emptypb.Empty, error) {
if s.eventStreamCh == nil {
return nil, status.Errorf(codes.NotFound, "The service is not streaming")
}
@ -127,10 +127,10 @@ func (s *Service) StartEventTest() error { //nolint:funlen
NewUpdateCheckFinishedEvent(),
// cache
NewCacheErrorEvent(CacheErrorType_CACHE_UNAVAILABLE_ERROR),
NewCacheLocationChangeSuccessEvent(),
NewCacheChangeLocalCacheFinishedEvent(true),
NewDiskCachePathChanged("/dummy/path"),
NewDiskCacheErrorEvent(DiskCacheErrorType_CANT_MOVE_DISK_CACHE_ERROR),
NewDiskCachePathChangedEvent("/dummy/path/"),
NewDiskCachePathChangeFinishedEvent(),
// mail settings
NewMailSettingsErrorEvent(MailSettingsErrorType_IMAP_PORT_ISSUE),