forked from ome/omero-server-docker
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
process_defaultxml.py
executable file
·73 lines (57 loc) · 1.99 KB
/
process_defaultxml.py
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
#!/usr/bin/env python
"""
Convert the nodes and server-instances in default.xml to a multi-node
configuration
The configuration string should be in the form node1:s1,s2,... node2:s3 ...
Examples
Everything on a single node (default, the same as passing no config):
master:Blitz-0,Indexer-0,DropBox,MonitorServer,FileServer,Storm,PixelData-0,Processor-0,Tables-0,TestDropBox
Processor on a separate node:
master:Blitz-0,Indexer-0,DropBox,MonitorServer,FileServer,Storm,PixelData-0,Tables-0,TestDropBox slave:Processor-0
Two Processor and two PixelData on two separate nodes:
master:Blitz-0,Indexer-0,DropBox,MonitorServer,FileServer,Storm,Tables-0,TestDropBox slave-1:Processor-0,PixelData-0 slave-2:Processor-1,PixelData-1
"""
import re
import sys
def getnodes(nodedescs):
nodes = {}
for nd in nodedescs:
s = ''
node, descs = nd.split(':')
descs = descs.split(',')
for d in descs:
try:
t, i = d.split('-')
except ValueError:
t = d
i = None
s += ' <server-instance template="%sTemplate"' % t
if i is not None:
s += ' index="%s"' % i
if t in ('Blitz',):
s += ' config="default"'
if t in ('PixelData', 'Processor', 'Tables'):
s += ' dir=""'
s += '/>\n'
nodes[node] = s
return nodes
with open(sys.argv[1]) as f:
xml = f.read()
pattern = r'\<node name="master"\>\s*\<server-instance[^\>]*\>(.*?\</node\>)'
m = re.search(pattern, xml, re.DOTALL)
assert m
nodedescs = sys.argv[2:]
master = '\n </node>\n'
slaves = ''
nodes = getnodes(nodedescs)
for nodename in sorted(nodes.keys()):
servers = nodes[nodename]
if nodename == 'master':
master = '%s%s' % (servers, master)
else:
slaves += ' <node name="%s">\n%s </node>\n' % (nodename, servers)
if nodes:
xmlout = xml[:m.start(1)] + master + slaves + xml[m.end(1):]
else:
xmlout = xml
print xmlout