Skip to content

Commit c828f64

Browse files
committed
SDKQE-3786: Bucket/scope/collection creation support in allocate command
1 parent d8079cd commit c828f64

3 files changed

Lines changed: 71 additions & 2 deletions

File tree

clusterdef/cluster.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,30 @@ type Cluster struct {
88
Expiry time.Duration `yaml:"expiry,omitempty"`
99
Purpose string `yaml:"purpose,omitempty"`
1010

11-
Columnar bool `yaml:"columnar,omitempty"`
12-
NodeGroups []*NodeGroup `yaml:"nodes,omitempty"`
11+
Columnar bool `yaml:"columnar,omitempty"`
12+
NodeGroups []*NodeGroup `yaml:"nodes,omitempty"`
13+
Buckets map[string]Bucket `yaml:"buckets,omitempty"`
1314

1415
Docker DockerCluster `yaml:"docker,omitempty"`
1516
Cao CaoCluster `yaml:"cao,omitempty"`
1617
Cloud CloudCluster `yaml:"cloud,omitempty"`
1718
}
1819

20+
type Bucket struct {
21+
Settings Settings `yaml:"settings,omitempty"`
22+
Scopes Scopes `yaml:",inline"`
23+
}
24+
25+
type Settings struct {
26+
RamQuotaMB int `yaml:"ram-quota-mb,omitempty"`
27+
FlushEnabled bool `yaml:"flush-enabled,omitempty"`
28+
NumReplicas int `yaml:"num-replicas,omitempty"`
29+
}
30+
31+
type Scopes map[string]Collections
32+
33+
type Collections []string
34+
1935
type DockerCluster struct {
2036
Username string `yaml:"username,omitempty"`
2137
Password string `yaml:"password,omitempty"`

cmd/allocate.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,41 @@ var allocateCmd = &cobra.Command{
7575
logger.Fatal("cluster deployment failed", zap.Error(err))
7676
}
7777

78+
if len(def.Buckets) > 0 {
79+
for bucketName, bucketDef := range def.Buckets {
80+
err := deployer.CreateBucket(ctx, cluster.GetID(), &deployment.CreateBucketOptions{
81+
Name: bucketName,
82+
RamQuotaMB: bucketDef.Settings.RamQuotaMB,
83+
FlushEnabled: bucketDef.Settings.FlushEnabled,
84+
NumReplicas: bucketDef.Settings.NumReplicas,
85+
})
86+
if err != nil {
87+
logger.Fatal("failed to create bucket", zap.String("bucket", bucketName), zap.Error(err))
88+
}
89+
logger.Info("bucket created", zap.String("bucket", bucketName))
90+
91+
for scopeName, collections := range bucketDef.Scopes {
92+
if scopeName == "" {
93+
continue
94+
}
95+
if err := deployer.CreateScope(ctx, cluster.GetID(), bucketName, scopeName); err != nil {
96+
logger.Fatal("failed to create scope", zap.String("bucket", bucketName), zap.String("scope", scopeName), zap.Error(err))
97+
}
98+
logger.Info("scope created", zap.String("bucket", bucketName), zap.String("scope", scopeName))
99+
100+
for _, collName := range collections {
101+
if collName == "" {
102+
continue
103+
}
104+
if err := deployer.CreateCollection(ctx, cluster.GetID(), bucketName, scopeName, collName); err != nil {
105+
logger.Fatal("failed to create collection", zap.String("bucket", bucketName), zap.String("scope", scopeName), zap.String("collection", collName), zap.Error(err))
106+
}
107+
logger.Info("collection created", zap.String("bucket", bucketName), zap.String("scope", scopeName), zap.String("collection", collName))
108+
}
109+
}
110+
}
111+
}
112+
78113
switch cluster := cluster.(type) {
79114
case *clouddeploy.ClusterInfo:
80115
if cluster.CloudClusterID != "" {
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
nodes:
2+
- count: 3
3+
services: [kv, n1ql, index]
4+
buckets:
5+
app-data:
6+
settings:
7+
ram-quota-mb: 512
8+
flush-enabled: true
9+
num-replicas: 1
10+
inventory:
11+
- products
12+
- warehouses
13+
sales: []
14+
logs:
15+
ops:
16+
- requests
17+
- errors
18+
client-info: {}

0 commit comments

Comments
 (0)