Skip to content

Commit b0ae53e

Browse files
committed
create: add config_storage template
Closes #1180 @TarantoolBot document Title: `tt create` support `config_storage` template. Configurable parameters: - Number of instances in replicaset - Interval of status checking
1 parent 32ed4d0 commit b0ae53e

File tree

8 files changed

+102
-3
lines changed

8 files changed

+102
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
99

1010
### Added
1111

12+
- `tt create`: add `config_storage` template
13+
1214
### Changed
1315

1416
### Fixed

cli/cmd/create.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ 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-
vshard_cluster: Tarantool 3 vshard cluster application.`,
47+
vshard_cluster: Tarantool 3 vshard cluster application.
48+
config_storage: Tarantool 3 cluster configuration storage.`,
4849
Example: `
4950
# Create an application app1 from a template.
5051
@@ -62,7 +63,11 @@ Built-in templates:
6263
6364
# Create Tarantool 3 vshard cluster.
6465
65-
$ tt create vshard_cluster --name cluster_app`,
66+
$ tt create vshard_cluster --name cluster_app
67+
68+
# Create Tarantool 3 cluster configuration storage.
69+
70+
$ tt create config_storage --name tcs`,
6671
}
6772

6873
createCmd.Flags().StringVarP(&appName, "name", "n", "", "Application name")

cli/cmd/create_test.go

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

cli/codegen/generate_code.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,14 @@ func main() {
136136
if err != nil {
137137
log.Errorf("error while generating file modes: %s", err)
138138
}
139+
err = generateFileModeFile(
140+
"cli/create/builtin_templates/templates/config_storage",
141+
"cli/create/builtin_templates/static/config_storage_template_filemodes_gen.go",
142+
"ConfigStorage",
143+
)
144+
if err != nil {
145+
log.Errorf("error while generating file modes: %s", err)
146+
}
139147

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

cli/create/builtin_templates/builtin_templates.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,13 @@ var FileModes = map[string]map[string]int{
1414
"cartridge": static.CartridgeFileModes,
1515
"vshard_cluster": static.VshardClusterFileModes,
1616
"single_instance": static.SingleInstanceFileModes,
17+
"config_storage": static.ConfigStorageFileModes,
1718
}
1819

1920
// Names contains built-in template names.
20-
var Names = [...]string{"cartridge", "vshard_cluster", "single_instance"}
21+
var Names = [...]string{
22+
"cartridge",
23+
"vshard_cluster",
24+
"single_instance",
25+
"config_storage",
26+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
description: Config storage template
2+
follow-up-message: |
3+
What's next?
4+
Build and start '{{ .name }}' application:
5+
$ tt build {{ .name }}
6+
$ tt start {{ .name }}
7+
8+
Pay attention that default passwords were generated,
9+
you can change it in the config.yaml.
10+
11+
vars:
12+
- prompt: Storages replicas (odd, >=3)
13+
name: replicas_count
14+
default: '3'
15+
re: ^([3579]|[1-9]\d*[13579])$
16+
17+
- prompt: Status check interval
18+
name: status_check_interval
19+
default: '5'
20+
re: ^[1-9]\d*$
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
credentials:
2+
users:
3+
replicator:
4+
password: 'topsecret'
5+
roles: [replication]
6+
client:
7+
password: 'secret'
8+
privileges:
9+
- permissions: [execute]
10+
lua_call:
11+
- config.storage.get
12+
- config.storage.put
13+
- config.storage.delete
14+
- config.storage.keepalive
15+
- config.storage.txn
16+
- config.storage.info
17+
# Not necessary since tarantool 3.5.0, 3.4.1, 3.3.3, 3.2.2.
18+
- permissions: [read, write]
19+
spaces: [config_storage, config_storage_meta]
20+
21+
iproto:
22+
advertise:
23+
peer:
24+
login: replicator
25+
26+
replication:
27+
failover: election
28+
29+
database:
30+
use_mvcc_engine: true
31+
32+
groups:
33+
group-001:
34+
replicasets:
35+
{{- $status_check_interval := atoi .status_check_interval}}
36+
{{- $replicas := atoi .replicas_count}}
37+
{{- range replicasets "replicaset" 1 $replicas}}
38+
{{.Name}}:
39+
roles: [config.storage]
40+
roles_cfg:
41+
config.storage:
42+
status_check_interval: {{$status_check_interval}}
43+
instances:
44+
{{- range .InstNames}}
45+
{{.}}:
46+
iproto:
47+
listen:
48+
- uri: 127.0.0.1:{{port}}
49+
{{- end}}
50+
{{- end}}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
{{- $replicas := atoi .replicas_count}}
3+
{{- range replicasets "replicaset" 1 $replicas}}
4+
{{- range .InstNames}}
5+
{{.}}:
6+
{{- end}}
7+
{{- end}}

0 commit comments

Comments
 (0)