-
Notifications
You must be signed in to change notification settings - Fork 117
/
registry.go
74 lines (62 loc) · 1.64 KB
/
registry.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package runtime
import (
"context"
"errors"
"fmt"
"github.com/rilldata/rill/runtime/drivers"
)
func (r *Runtime) FindInstances(ctx context.Context) ([]*drivers.Instance, error) {
return r.Registry().FindInstances(ctx)
}
func (r *Runtime) FindInstance(ctx context.Context, instanceID string) (*drivers.Instance, error) {
return r.Registry().FindInstance(ctx, instanceID)
}
func (r *Runtime) CreateInstance(ctx context.Context, inst *drivers.Instance) error {
// Check OLAP connection
olap, err := drivers.Open(inst.OLAPDriver, inst.OLAPDSN, r.logger)
if err != nil {
return err
}
_, ok := olap.OLAPStore()
if !ok {
return fmt.Errorf("not a valid OLAP driver: '%s'", inst.OLAPDriver)
}
// Check repo connection
repo, err := drivers.Open(inst.RepoDriver, inst.RepoDSN, r.logger)
if err != nil {
return err
}
_, ok = repo.RepoStore()
if !ok {
return fmt.Errorf("not a valid repo driver: '%s'", inst.RepoDriver)
}
// Check that it's a driver that supports embedded catalogs
if inst.EmbedCatalog {
_, ok := olap.CatalogStore()
if !ok {
return errors.New("driver does not support embedded catalogs")
}
}
// Prepare connections for use
err = olap.Migrate(ctx)
if err != nil {
return fmt.Errorf("failed to prepare instance: %w", err)
}
err = repo.Migrate(ctx)
if err != nil {
return fmt.Errorf("failed to prepare instance: %w", err)
}
// Create instance
err = r.Registry().CreateInstance(ctx, inst)
if err != nil {
return err
}
return nil
}
func (r *Runtime) DeleteInstance(ctx context.Context, instanceID string) error {
err := r.Registry().DeleteInstance(ctx, instanceID)
if err != nil {
return err
}
return nil
}