Skip to content

Commit e31d199

Browse files
committed
create: add template for non-vshard cluster
Closes #1182 @TarantoolBot document Title: `tt create` add template for non-vshard cluster. Configurable parameters: - Number of replicasets - Number of replicas per replicaset - User name - Password
1 parent 55e8ef6 commit e31d199

10 files changed

Lines changed: 308 additions & 94 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1010
### Added
1111

1212
- `tt create`: add template for Tarantool Config Storage.
13+
- `tt create`: add template for non-vshard Cluster.
1314

1415
### Changed
1516

cli/cmd/create.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ func NewCreateCmd() *cobra.Command {
4444
Built-in templates:
4545
cartridge: a simple Cartridge application.
4646
single_instance: Tarantool 3 application with a single instance configuration.
47+
cluster: Tarantool 3 cluster application.
4748
vshard_cluster: Tarantool 3 vshard cluster application.
4849
config_storage: Tarantool 3 cluster configuration storage.`,
4950
Example: `

cli/cmd/create_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ func TestCreateValidArgsFunction(t *testing.T) {
4242
"vshard_cluster",
4343
"single_instance",
4444
"config_storage",
45+
"cluster",
4546
"archive",
4647
"template2",
4748
tdir1Name,

cli/codegen/generate_code.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,14 @@ func main() {
144144
if err != nil {
145145
log.Errorf("error while generating file modes: %s", err)
146146
}
147+
err = generateFileModeFile(
148+
"cli/create/builtin_templates/templates/cluster",
149+
"cli/create/builtin_templates/static/cluster_template_filemodes_gen.go",
150+
"Cluster",
151+
)
152+
if err != nil {
153+
log.Errorf("error while generating file modes: %s", err)
154+
}
147155

148156
if err = generateLuaCodeVar(); err != nil {
149157
log.Errorf("error while generating lua code string variables: %s", err)

cli/create/builtin_templates/builtin_templates.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ var FileModes = map[string]map[string]int{
1515
"vshard_cluster": static.VshardClusterFileModes,
1616
"single_instance": static.SingleInstanceFileModes,
1717
"config_storage": static.ConfigStorageFileModes,
18+
"cluster": static.ClusterFileModes,
1819
}
1920

2021
// Names contains built-in template names.
@@ -23,4 +24,5 @@ var Names = [...]string{
2324
"vshard_cluster",
2425
"single_instance",
2526
"config_storage",
27+
"cluster",
2628
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
description: Cluster template
2+
follow-up-message: |
3+
What's next?
4+
Start '{{ .name }}' application:
5+
$ tt start {{ .name }}
6+
7+
Pay attention that default user and password were generated
8+
for the 'replication' role, you can change it in the config.yaml.
9+
10+
vars:
11+
- prompt: Number of replication sets
12+
name: num_replicasets
13+
default: '2'
14+
re: ^[1-9]\d*$
15+
16+
- prompt: Number of replicas per replication set (>=2)
17+
name: num_replicas
18+
default: '2'
19+
re: ^[2-9]|[1-9]\d+$
20+
21+
- prompt: User name
22+
name: username
23+
default: 'client'
24+
25+
- prompt: Password
26+
name: password
27+
default: 'secret'
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
log = require('log')
2+
3+
local app_name = os.getenv('TARANTOOL_APP_NAME')
4+
local inst_name = os.getenv('TARANTOOL_INSTANCE_NAME')
5+
6+
log.info(('%s:%s is started'):format(app_name, inst_name))
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
credentials:
2+
users:
3+
{{.username}}:
4+
password: '{{.password}}'
5+
roles: [super]
6+
replicator:
7+
password: 'topsecret'
8+
roles: [replication]
9+
10+
iproto:
11+
advertise:
12+
peer:
13+
login: replicator
14+
15+
replication:
16+
failover: manual
17+
18+
groups:
19+
group-001:
20+
app:
21+
file: 'app.lua'
22+
replicasets:
23+
{{- $num_replicasets := atoi .num_replicasets}}
24+
{{- $num_replicas := atoi .num_replicas}}
25+
{{- range replicasets "replicaset" $num_replicasets $num_replicas}}
26+
{{.Name}}:
27+
leader: {{index .InstNames 0}}
28+
instances:
29+
{{- range .InstNames}}
30+
{{.}}:
31+
iproto:
32+
listen:
33+
- uri: 127.0.0.1:{{port}}
34+
{{- end}}
35+
{{- end}}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
{{- $num_replicasets := atoi .num_replicasets}}
3+
{{- $num_replicas := atoi .num_replicas}}
4+
{{- range replicasets "replicaset" $num_replicasets $num_replicas}}
5+
{{- range .InstNames}}
6+
{{.}}:
7+
{{- end}}
8+
{{- end}}

0 commit comments

Comments
 (0)