Skip to content

Commit

Permalink
feat(config): add tenant&cluster config support
Browse files Browse the repository at this point in the history
  • Loading branch information
Jianhui Dong committed Oct 16, 2022
1 parent 9b07dda commit 6471d28
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
32 changes: 28 additions & 4 deletions pkg/boot/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,37 @@ func (fp *discovery) UpsertTenant(ctx context.Context, tenant string, body *Tena
}

func (fp *discovery) RemoveTenant(ctx context.Context, tenant string) error {
// TODO implement me
panic("implement me")
if err := fp.tenantOp.RemoveTenant(tenant); err != nil {
return errors.Wrapf(err, "failed to remove tenant '%s'", tenant)
}
return nil
}

func (fp *discovery) UpsertCluster(ctx context.Context, tenant, cluster string, body *ClusterBody) error {
// TODO implement me
panic("implement me")
op, ok := fp.centers[tenant]
if !ok {
return ErrorNoTenant
}

cfg, err := fp.GetTenant(ctx, tenant)
if err != nil {
return err
}

for _, newCluster := range cfg.DataSourceClusters {
if newCluster.Name == cluster {
newCluster.Type = body.Type
newCluster.Parameters = body.Parameters
newCluster.SqlMaxLimit = body.SqlMaxLimit
}
}

err = op.Write(ctx, "clusters", cfg)
if err != nil {
return err
}

return nil
}

func (fp *discovery) RemoveCluster(ctx context.Context, tenant, cluster string) error {
Expand Down
6 changes: 3 additions & 3 deletions pkg/config/config_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ func (c *configWriter) Write(ctx context.Context, item ConfigItem, cfg *Tenant)
allKeyMap := c.pathInfo.ConfigKeyMapping
ret := make(map[PathKey]string)

for i := range allKeyMap {
if allKeyMap[i] == string(item) {
ret[i] = allKeyMap[i]
for pathKey := range allKeyMap {
if allKeyMap[pathKey] == string(item) {
ret[pathKey] = allKeyMap[pathKey]
}
}

Expand Down

0 comments on commit 6471d28

Please sign in to comment.