Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fd37657

Browse files
committed
Revert "cleanup: remove deploy/*"
This reverts commit f259ffa.
1 parent f259ffa commit fd37657

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+2266
-0
lines changed

deploy/Makefile

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
all:
2+
@cd products && for d in `ls .`; do make -C $$d || exit 1; done

deploy/products/alpha/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
instance.json

deploy/products/alpha/Makefile

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
all:
2+
./gen.py && ./render.py

deploy/products/alpha/config.json

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"product_name": "demo-alpha",
3+
"product_auth": "",
4+
"dashboard": {
5+
"admin_addr": "127.0.0.1:18080",
6+
"coordinator": {
7+
"name": "etcd",
8+
"addr": "127.0.0.1:2379"
9+
},
10+
"sentinel_quorum": 2,
11+
"sentinel_down_after": "10s"
12+
},
13+
"proxy": {
14+
"min_cpu": 4,
15+
"max_cpu": 8,
16+
"max_clients": 10000,
17+
"max_pipeline": 1024
18+
}
19+
}

deploy/products/alpha/gen.py

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env python3
2+
3+
import json
4+
5+
proxy = {
6+
"": [
7+
"127.0.0.1",
8+
]
9+
}
10+
11+
proxy_list = []
12+
13+
for dc, ip_list in proxy.items():
14+
for ip in ip_list:
15+
for i in [0, 1, 2]:
16+
proxy_list.append({
17+
"datacenter": dc,
18+
"admin_addr": "{}:{}".format(ip, 11080 + i),
19+
"proxy_addr": "{}:{}".format(ip, 19000 + i),
20+
})
21+
22+
with open("instance.json", 'w+') as f:
23+
f.write(json.dumps(proxy_list, indent=4))
24+
25+
for x in proxy:
26+
print("[{}]:".format(x))
27+
proxy_addr = ""
28+
for p in proxy_list:
29+
if p["datacenter"] == x:
30+
if len(proxy_addr) != 0:
31+
proxy_addr += ","
32+
proxy_addr += p["proxy_addr"]
33+
print(proxy_addr)
34+
print("\n")
35+

deploy/products/alpha/render.py

+213
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
1+
#!/usr/bin/env python3
2+
3+
import os
4+
import json
5+
import stat
6+
7+
template_root = "../../templates"
8+
generate_root = "../../root"
9+
10+
def readfile(path, name):
11+
file = os.path.join(path, name)
12+
with open(file) as f:
13+
return f.read()
14+
15+
16+
def generate(path, name, content):
17+
if path != "":
18+
os.makedirs(path, exist_ok=True)
19+
file = os.path.join(path, name)
20+
print("Generate: {}".format(os.path.abspath(file)))
21+
with open(file, 'w+') as f:
22+
f.write(content)
23+
24+
25+
def generate_bash(path, name, content):
26+
content = "#!/usr/bin/env bash\n\nset -x\nset -e\n\n" + content + "\n"
27+
generate(path, name, content)
28+
file = os.path.join(path, name)
29+
os.chmod(file, os.stat(file).st_mode | stat.S_IEXEC)
30+
31+
32+
def symlink(src, dst):
33+
try:
34+
os.remove(dst)
35+
except OSError:
36+
pass
37+
os.symlink(src, dst)
38+
39+
40+
class Coordinator:
41+
def __init__(self, config):
42+
self.name = config.get("name", "")
43+
self.addr = config.get("addr", "")
44+
45+
46+
class Dashboard():
47+
def __init__(self, product, config):
48+
self.product = product
49+
self.env = product.env
50+
self.admin_addr = config.get("admin_addr", "")
51+
52+
self.sentinel_quorum = config.get("sentinel_quorum", 2)
53+
self.sentinel_down_after = config.get("sentinel_down_after", "30s")
54+
self.coordinator = Coordinator(config.get("coordinator", {}))
55+
56+
if self.admin_addr == "":
57+
raise Exception("dashboard.admin_addr not found")
58+
if self.coordinator.name == "":
59+
raise Exception("coordinator.name not found")
60+
if self.coordinator.addr == "":
61+
raise Exception("coordinator.addr not found or empty")
62+
63+
self.admin_port = self.admin_addr.rsplit(':', 1)[1]
64+
65+
def render(self, proxylist):
66+
kwargs = {
67+
'PRODUCT_NAME': self.product.name,
68+
'PRODUCT_AUTH': self.product.auth,
69+
'COORDINATOR_NAME': self.coordinator.name,
70+
'COORDINATOR_ADDR': self.coordinator.addr,
71+
'ADMIN_ADDR': self.admin_addr,
72+
'ADMIN_PORT': self.admin_port,
73+
'SENTINEL_QUORUM': self.sentinel_quorum,
74+
'SENTINEL_DOWN_AFTER': self.sentinel_down_after,
75+
'BIN_PATH': self.env.bin_path,
76+
'ETC_PATH': self.env.etc_path,
77+
'LOG_PATH': self.env.log_path,
78+
}
79+
base = os.path.join(generate_root, self.env.etc_path.lstrip('/'), self.admin_addr.replace(':', '_'))
80+
81+
temp = readfile(template_root, "dashboard.toml.template")
82+
generate(base, "dashboard.toml", temp.format(**kwargs))
83+
84+
temp = readfile(template_root, "dashboard.service.template")
85+
generate(base, "codis_dashboard_{}.service".format(self.admin_port), temp.format(**kwargs))
86+
87+
admin = os.path.join(self.env.bin_path, "codis-admin")
88+
generate_bash(base, "dashboard_admin", "{} --dashboard={} $@".format(admin, self.admin_addr))
89+
90+
scripts = 'd=1\n'
91+
for p in proxylist:
92+
scripts += "sleep $d; {} --dashboard={} --online-proxy --addr={}".format(admin, self.admin_addr, p.admin_addr)
93+
scripts += "\n"
94+
generate_bash(base, "foreach_proxy_online", scripts)
95+
96+
scripts = 'd=1\n'
97+
for p in proxylist:
98+
scripts += "sleep $d; {} --dashboard={} --reinit-proxy --addr={}".format(admin, self.admin_addr, p.admin_addr)
99+
scripts += "\n"
100+
generate_bash(base, "foreach_proxy_reinit", scripts)
101+
102+
scripts = 'd=1\n'
103+
for p in proxylist:
104+
scripts += "sleep $d; {} --proxy={} $@".format(admin, p.admin_addr)
105+
scripts += "\n"
106+
generate_bash(base, "foreach_proxy", scripts)
107+
108+
cwd = os.getcwd()
109+
os.chdir(os.path.join(base, ".."))
110+
symlink(self.admin_addr.replace(':', '_'), self.product.name)
111+
os.chdir(cwd)
112+
113+
114+
class Template:
115+
def __init__(self, config):
116+
self.min_cpu = config.get("min_cpu", 4)
117+
self.max_cpu = config.get("max_cpu", 0)
118+
self.max_clients = config.get("max_clients", 10000)
119+
self.max_pipeline = config.get("max_pipeline", 1024)
120+
self.log_level = config.get("log_level", "INFO")
121+
self.jodis_name = config.get("jodis_name", "")
122+
self.jodis_addr = config.get("jodis_addr", "")
123+
124+
125+
class Proxy():
126+
def __init__(self, product, template, config):
127+
self.product = product
128+
self.env = product.env
129+
self.template = template
130+
self.datacenter = config.get("datacenter", "")
131+
self.admin_addr = config.get("admin_addr", "")
132+
self.proxy_addr = config.get("proxy_addr", "")
133+
134+
if self.admin_addr == "":
135+
raise Exception("proxy.admin_addr not found")
136+
if self.proxy_addr == "":
137+
raise Exception("proxy.proxy_addr not found")
138+
139+
self.proxy_port = self.proxy_addr.rsplit(':', 1)[1]
140+
141+
def render(self):
142+
kwargs = {
143+
'PRODUCT_NAME': self.product.name,
144+
'PRODUCT_AUTH': self.product.auth,
145+
'ADMIN_ADDR': self.admin_addr,
146+
'PROXY_ADDR': self.proxy_addr,
147+
'PROXY_PORT': self.proxy_port,
148+
'DATACENTER': self.datacenter,
149+
'MAX_CLIENTS': self.template.max_clients,
150+
'MAX_PIPELINE': self.template.max_pipeline,
151+
'JODIS_NAME': self.template.jodis_name,
152+
'JODIS_ADDR': self.template.jodis_addr,
153+
'MIN_CPU': self.template.min_cpu,
154+
'MAX_CPU': self.template.max_cpu,
155+
'LOG_LEVEL': self.template.log_level,
156+
'BIN_PATH': self.env.bin_path,
157+
'ETC_PATH': self.env.etc_path,
158+
'LOG_PATH': self.env.log_path,
159+
}
160+
base = os.path.join(generate_root, self.env.etc_path.lstrip('/'), self.proxy_addr.replace(':', '_'))
161+
162+
temp = readfile(template_root, "proxy.toml.template")
163+
generate(base, "proxy.toml", temp.format(**kwargs))
164+
165+
temp = readfile(template_root, "proxy.service.template")
166+
generate(base, "codis_proxy_{}.service".format(self.proxy_port), temp.format(**kwargs))
167+
168+
admin = os.path.join(self.env.bin_path, "codis-admin")
169+
generate_bash(base, "proxy_admin", "{} --proxy={} $@".format(admin, self.admin_addr))
170+
171+
172+
class Env:
173+
def __init__(self, config):
174+
self.bin_path = os.path.abspath(config.get("bin_path", "/opt/codis/bin"))
175+
self.etc_path = os.path.abspath(config.get("etc_path", "/opt/codis/etc"))
176+
self.log_path = os.path.abspath(config.get("log_path", "/opt/codis/log"))
177+
self.log_level = config.get("log_level", "INFO").upper()
178+
179+
180+
class Product:
181+
def __init__(self, config):
182+
self.name = config.get("product_name", "")
183+
self.auth = config.get("product_auth", "")
184+
185+
if self.name == "":
186+
raise Exception("product_name not found")
187+
188+
self.env = Env(config.get("env", {}))
189+
self.dashboard = Dashboard(self, config.get("dashboard", {}))
190+
191+
self.proxylist = []
192+
if "proxy" in config:
193+
template = Template(config.get("proxy", {}))
194+
for p in config.get("instance", []):
195+
self.proxylist.append(Proxy(self, template, p))
196+
self.proxylist.sort(key=lambda p: p.datacenter + "|" + p.proxy_addr)
197+
198+
def render(self):
199+
self.dashboard.render(self.proxylist)
200+
for p in self.proxylist:
201+
p.render()
202+
203+
204+
config = {}
205+
206+
with open('config.json') as f:
207+
config = json.loads(f.read())
208+
209+
with open('instance.json') as f:
210+
config["instance"] = json.loads(f.read())
211+
212+
product = Product(config)
213+
product.render()

deploy/products/beta/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
instance.json

deploy/products/beta/Makefile

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
all:
2+
./gen.py && ./render.py

deploy/products/beta/config.json

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"env": {
3+
"bin_path": "/opt/codis/bin",
4+
"etc_path": "/opt/codis/etc",
5+
"log_path": "/opt/codis/log"
6+
},
7+
"product_name": "demo-beta",
8+
"product_auth": "",
9+
"dashboard": {
10+
"admin_addr": "10.4.10.100:18080",
11+
"coordinator": {
12+
"name": "zookeeper",
13+
"addr": "10.4.10.101:2181,10.4.10.102:2181,10.4.10.103:2181,10.4.10.104:2181,10.4.10.105:2181"
14+
},
15+
"sentinel_quorum": 2,
16+
"sentinel_down_after": "10s"
17+
},
18+
"proxy": {
19+
"min_cpu": 4,
20+
"max_cpu": 8,
21+
"max_clients": 2000,
22+
"max_pipeline": 512,
23+
"log_level": "WARN",
24+
"jodis_name": "zookeeper",
25+
"jodis_addr": "10.4.10.101:2181,10.4.10.102:2181,10.4.10.103:2181,10.4.10.104:2181,10.4.10.105:2181"
26+
}
27+
}

deploy/products/beta/gen.py

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env python3
2+
3+
import json
4+
5+
proxy = {
6+
"dc1": [
7+
"10.4.10.200",
8+
"10.4.10.201",
9+
],
10+
"dc2":[
11+
"10.2.16.200",
12+
"10.2.16.201",
13+
"10.2.16.202",
14+
],
15+
}
16+
17+
proxy_list = []
18+
19+
for dc, ip_list in proxy.items():
20+
for ip in ip_list:
21+
for i in [0, 2]:
22+
proxy_list.append({
23+
"datacenter": dc,
24+
"admin_addr": "{}:{}".format(ip, 11080 + i),
25+
"proxy_addr": "{}:{}".format(ip, 19000 + i),
26+
})
27+
28+
with open("instance.json", 'w+') as f:
29+
f.write(json.dumps(proxy_list, indent=4))
30+
31+
for x in proxy:
32+
print("[{}]:".format(x))
33+
proxy_addr = ""
34+
for p in proxy_list:
35+
if p["datacenter"] == x:
36+
if len(proxy_addr) != 0:
37+
proxy_addr += ","
38+
proxy_addr += p["proxy_addr"]
39+
print(proxy_addr)
40+
print("\n")
41+

0 commit comments

Comments
 (0)