Skip to content

Commit 63c1f8d

Browse files
committed
3.0 config
1 parent 35d52d8 commit 63c1f8d

23 files changed

+1612
-451
lines changed

doc/book/admin/start_stop_instance.rst

+2
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ With a single ``tt`` call, you can:
124124
* connect to a specific instance of an application
125125
* stop a specific instance of an application or all its instances
126126

127+
.. _admin-start_stop_instance-multi-instance-layout:
128+
127129
Application layout
128130
~~~~~~~~~~~~~~~~~~
129131

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
local fio = require('fio')
2+
local server = require('luatest.server')
3+
local t = require('luatest')
4+
local treegen = require('test.treegen')
5+
local justrun = require('test.justrun')
6+
local g = t.group()
7+
8+
g.before_all(function()
9+
treegen.init(g)
10+
end)
11+
12+
g.after_all(function()
13+
treegen.clean(g)
14+
end)
15+
16+
g.before_each(function(cg)
17+
cg.server = server:new {
18+
box_cfg = {},
19+
workdir = fio.cwd() .. '/tmp'
20+
}
21+
cg.server:start()
22+
cg.server:exec(function()
23+
box.schema.space.create('bands')
24+
box.space.bands:format({
25+
{ name = 'id', type = 'unsigned' },
26+
{ name = 'band_name', type = 'string' },
27+
{ name = 'year', type = 'unsigned' }
28+
})
29+
box.space.bands:create_index('primary', { parts = { 'id' } })
30+
end)
31+
end)
32+
33+
g.after_each(function(cg)
34+
cg.server:stop()
35+
cg.server:drop()
36+
end)
37+
38+
g.test_config_option = function()
39+
local dir = treegen.prepare_directory(g, {}, {})
40+
local file_config = [[
41+
log:
42+
level: 7
43+
44+
memtx:
45+
min_tuple_size: 32
46+
memory: 100000000
47+
48+
groups:
49+
group-001:
50+
replicasets:
51+
replicaset-001:
52+
instances:
53+
instance-001: {}
54+
]]
55+
treegen.write_script(dir, 'config.yaml', file_config)
56+
57+
local script = [[
58+
print(box.cfg.memtx_min_tuple_size)
59+
print(box.cfg.memtx_memory)
60+
print(box.cfg.log_level)
61+
os.exit(0)
62+
]]
63+
treegen.write_script(dir, 'main.lua', script)
64+
65+
local env = {TT_LOG_LEVEL = 0}
66+
local opts = {nojson = true, stderr = false}
67+
local args = {'--name', 'instance-001', '--config', 'config.yaml',
68+
'main.lua'}
69+
local res = justrun.tarantool(dir, env, args, opts)
70+
t.assert_equals(res.exit_code, 0)
71+
t.assert_equals(res.stdout, table.concat({32, 100000000, 0}, "\n"))
72+
end
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
config:
2+
etcd:
3+
prefix: /example
4+
endpoints:
5+
- http://localhost:2379
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
app.instance-001:
2+
app.instance-002:
3+
app.instance-003:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
iproto:
2+
listen: "3301"
3+
4+
groups:
5+
group-001:
6+
replicasets:
7+
replicaset-001:
8+
instances:
9+
instance-001: {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
groups:
2+
group-001:
3+
iproto:
4+
listen: "3301"
5+
replicasets:
6+
replicaset-001:
7+
instances:
8+
instance-001: {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
groups:
2+
group-001:
3+
replicasets:
4+
replicaset-001:
5+
instances:
6+
instance-001:
7+
iproto:
8+
listen: "3301"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
groups:
2+
group-001:
3+
replicasets:
4+
replicaset-001:
5+
iproto:
6+
listen: "3301"
7+
instances:
8+
instance-001: {}
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
local log = require('log').new("myapp")
2+
local config = require('config')
3+
log.info("%s from app, %s!", config:get('app.cfg.greeting'), box.info.name)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
credentials:
2+
users:
3+
replicator:
4+
password: 'topsecret'
5+
roles: [replication]
6+
client:
7+
password: 'secret'
8+
roles: [super]
9+
10+
iproto:
11+
advertise:
12+
peer: replicator@
13+
14+
replication:
15+
failover: election
16+
17+
groups:
18+
group-001:
19+
replicasets:
20+
replicaset-001:
21+
instances:
22+
instance-001:
23+
iproto:
24+
listen: 127.0.0.1:3301
25+
instance-002:
26+
iproto:
27+
listen: 127.0.0.1:3302
28+
instance-003:
29+
iproto:
30+
listen: 127.0.0.1:3303
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
credentials:
2+
users:
3+
replicator:
4+
password: 'topsecret'
5+
roles: [replication]
6+
client:
7+
password: 'secret'
8+
roles: [super]
9+
10+
iproto:
11+
advertise:
12+
peer: replicator@
13+
14+
replication:
15+
failover: manual
16+
17+
groups:
18+
group-001:
19+
replicasets:
20+
replicaset-001:
21+
leader: instance-001
22+
instances:
23+
instance-001:
24+
iproto:
25+
listen: 127.0.0.1:3301
26+
instance-002:
27+
iproto:
28+
listen: 127.0.0.1:3302
29+
instance-003:
30+
iproto:
31+
listen: 127.0.0.1:3303
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
app:
2+
file: 'myapp.lua'
3+
cfg:
4+
greeting: 'Hello'
5+
6+
groups:
7+
group-001:
8+
replicasets:
9+
replicaset-001:
10+
instances:
11+
instance-001:
12+
iproto:
13+
listen: "3301"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
groups:
2+
group-001:
3+
replicasets:
4+
replicaset-001:
5+
instances:
6+
instance-001:
7+
snapshot:
8+
dir: ./var/{{ instance_name }}/snapshots
9+
wal:
10+
dir: ./var/{{ instance_name }}/wals

doc/code_snippets/test/justrun.lua

+144
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
local fun = require('fun')
2+
local log = require('log')
3+
local json = require('json')
4+
local fiber = require('fiber')
5+
local popen = require('popen')
6+
7+
local justrun = {}
8+
9+
local function collect_stderr(ph)
10+
local f = fiber.new(function()
11+
local fiber_name = "child's stderr collector"
12+
fiber.name(fiber_name, {truncate = true})
13+
14+
local chunks = {}
15+
16+
while true do
17+
local chunk, err = ph:read({stderr = true})
18+
if chunk == nil then
19+
log.warn(('%s: got error, exiting: %s'):format(
20+
fiber_name, tostring(err)))
21+
break
22+
end
23+
if chunk == '' then
24+
log.info(('%s: got EOF, exiting'):format(fiber_name))
25+
break
26+
end
27+
table.insert(chunks, chunk)
28+
end
29+
30+
-- Glue all chunks, strip trailing newline.
31+
return table.concat(chunks):rstrip()
32+
end)
33+
f:set_joinable(true)
34+
return f
35+
end
36+
37+
local function cancel_stderr_fiber(stderr_fiber)
38+
if stderr_fiber == nil then
39+
return
40+
end
41+
stderr_fiber:cancel()
42+
end
43+
44+
local function join_stderr_fiber(stderr_fiber)
45+
if stderr_fiber == nil then
46+
return
47+
end
48+
return select(2, assert(stderr_fiber:join()))
49+
end
50+
51+
-- Run tarantool in given directory with given environment and
52+
-- command line arguments and catch its output.
53+
--
54+
-- Expects JSON lines as the output and parses it into an array
55+
-- (it can be disabled using `nojson` option).
56+
--
57+
-- Options:
58+
--
59+
-- - nojson (boolean, default: false)
60+
--
61+
-- Don't attempt to decode stdout as a stream of JSON lines,
62+
-- return as is.
63+
--
64+
-- - stderr (boolean, default: false)
65+
--
66+
-- Collect stderr and place it into the `stderr` field of the
67+
-- return value
68+
function justrun.tarantool(dir, env, args, opts)
69+
assert(type(dir) == 'string')
70+
assert(type(env) == 'table')
71+
assert(type(args) == 'table')
72+
local opts = opts or {}
73+
assert(type(opts) == 'table')
74+
75+
-- Prevent system/user inputrc configuration file from
76+
-- influencing testing code.
77+
env['INPUTRC'] = '/dev/null'
78+
79+
local tarantool_exe = arg[-1]
80+
-- Use popen.shell() instead of popen.new() due to lack of
81+
-- cwd option in popen (gh-5633).
82+
local env_str = table.concat(fun.iter(env):map(function(k, v)
83+
return ('%s=%q'):format(k, v)
84+
end):totable(), ' ')
85+
local command = ('cd %s && %s %s %s'):format(dir, env_str, tarantool_exe,
86+
table.concat(args, ' '))
87+
log.info(('Running a command: %s'):format(command))
88+
local mode = opts.stderr and 'rR' or 'r'
89+
local ph = popen.shell(command, mode)
90+
91+
local stderr_fiber
92+
if opts.stderr then
93+
stderr_fiber = collect_stderr(ph)
94+
end
95+
96+
-- Read everything until EOF.
97+
local chunks = {}
98+
while true do
99+
local chunk, err = ph:read()
100+
if chunk == nil then
101+
cancel_stderr_fiber(stderr_fiber)
102+
ph:close()
103+
error(err)
104+
end
105+
if chunk == '' then -- EOF
106+
break
107+
end
108+
table.insert(chunks, chunk)
109+
end
110+
111+
local exit_code = ph:wait().exit_code
112+
local stderr = join_stderr_fiber(stderr_fiber)
113+
ph:close()
114+
115+
-- If an error occurs, discard the output and return only the
116+
-- exit code. However, return stderr.
117+
if exit_code ~= 0 then
118+
return {
119+
exit_code = exit_code,
120+
stderr = stderr,
121+
}
122+
end
123+
124+
-- Glue all chunks, strip trailing newline.
125+
local res = table.concat(chunks):rstrip()
126+
log.info(('Command output:\n%s'):format(res))
127+
128+
-- Decode JSON object per line into array of tables (if
129+
-- `nojson` option is not passed).
130+
local decoded
131+
if opts.nojson then
132+
decoded = res
133+
else
134+
decoded = fun.iter(res:split('\n')):map(json.decode):totable()
135+
end
136+
137+
return {
138+
exit_code = exit_code,
139+
stdout = decoded,
140+
stderr = stderr,
141+
}
142+
end
143+
144+
return justrun

0 commit comments

Comments
 (0)