From c6b26c4e32f1b26dd3cb121a80b29ce76200308f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toma=C5=BE=20Jerman?= Date: Tue, 31 May 2022 12:48:46 +0200 Subject: [PATCH] Temporary patch for primary connection updating --- pkg/dal/service.go | 33 +++++++++++++++++++++++---------- pkg/label/label.go | 6 +++++- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/pkg/dal/service.go b/pkg/dal/service.go index c58c43e33..38af8d458 100644 --- a/pkg/dal/service.go +++ b/pkg/dal/service.go @@ -33,8 +33,9 @@ type ( } service struct { - connections map[uint64]*connectionWrap - primary *connectionWrap + connections map[uint64]*connectionWrap + primary *connectionWrap + primaryConnectionID uint64 // Indexed by corresponding storeID models map[uint64]ModelSet @@ -60,9 +61,10 @@ func InitGlobalService(ctx context.Context, log *zap.Logger, inDev bool, connect log.Debug("initializing DAL service with primary connection", zap.Any("connection params", cp)) gSvc = &service{ - connections: make(map[uint64]*connectionWrap), - models: make(map[uint64]ModelSet), - primary: nil, + connections: make(map[uint64]*connectionWrap), + models: make(map[uint64]ModelSet), + primary: nil, + primaryConnectionID: connectionID, logger: log, inDev: inDev, @@ -143,7 +145,11 @@ func (svc *service) AddConnection(ctx context.Context, connectionID uint64, cp C if err != nil { return } - svc.connections[connectionID] = cw + if connectionID == DefaultConnectionID || connectionID == svc.primaryConnectionID { + svc.primary = cw + } else { + svc.connections[connectionID] = cw + } return } @@ -151,9 +157,9 @@ func (svc *service) AddConnection(ctx context.Context, connectionID uint64, cp C func (svc *service) RemoveConnection(ctx context.Context, connectionID uint64) (err error) { svc.logger.Debug("removing connection", zap.Uint64("connectionID", connectionID)) - c := svc.connections[connectionID] - if c == nil { - return fmt.Errorf("can not remove connection %d: connection does not exist", connectionID) + c, _, err := svc.getConnection(ctx, connectionID) + if err != nil { + return fmt.Errorf("can not remove connection %d: %w", connectionID, err) } // Potential cleanups @@ -164,7 +170,14 @@ func (svc *service) RemoveConnection(ctx context.Context, connectionID uint64) ( } // Remove from registry - delete(svc.connections, connectionID) + // + // @todo this is temporary until a proper update function is prepared. + // The primary connection must not be removable! + if connectionID == DefaultConnectionID || connectionID == svc.primary.connectionID { + svc.primary = nil + } else { + delete(svc.connections, connectionID) + } return nil } diff --git a/pkg/label/label.go b/pkg/label/label.go index a8ad05140..e27c60a1e 100644 --- a/pkg/label/label.go +++ b/pkg/label/label.go @@ -4,10 +4,11 @@ import ( "context" "encoding/json" "fmt" + "strings" + "github.com/cortezaproject/corteza-server/pkg/handle" "github.com/cortezaproject/corteza-server/pkg/label/types" "github.com/cortezaproject/corteza-server/store" - "strings" ) type ( @@ -157,6 +158,9 @@ func Create(ctx context.Context, s store.Labels, r LabeledResource) error { // Update updates or creates all labels on labeled resource and removes all non explicitly defined func Update(ctx context.Context, s store.Labels, r LabeledResource) error { + // @tmp + return nil + var ( err error labels = r.GetLabels()