-
Notifications
You must be signed in to change notification settings - Fork 2
/
deploy.py
120 lines (90 loc) · 3.87 KB
/
deploy.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import subprocess
from os import environ
from sys import stdout, stderr
from configparser import ConfigParser
from shlex import split as commandSplit
from shutil import copyfile
from time import sleep
### Read configuration file ###
config = ConfigParser()
config.read('cluster.conf')
g5kConfig = config['g5k']
deployImg = str(g5kConfig['deploy.image.name'])
userName = str(g5kConfig['user.name'])
oarFile = str(g5kConfig['oar.file.location'])
multiCluster = str(g5kConfig['multi.cluster']) in "yes"
flinkConfig = config['flink']
flinkVersion = str(flinkConfig['flink.version'])
ansibleConfig = config['ansible']
inventoryPath = str(ansibleConfig['inventory.file.path'])
playbookPath = str(ansibleConfig['playbook.file.path'])
### Variables ###
flinkConfYaml = 'flink-conf.yaml'
slavesConf = 'slaves'
mastersConf = 'masters'
### Obtain cluster's nodes list ###
print("OARFILE:",oarFile)
if oarFile == 'default':
try:
oarFile = environ.get('OAR_NODE_FILE')
except KeyError:
print("ERROR: nodefile not found")
exit()
else:
oarFile = oarFile.replace('~', environ.get('HOME'))
print("OARFILE:",oarFile)
with open(oarFile) as file:
clusterNodes = [line.strip() for line in file]
clusterNodes = list(set(clusterNodes))
nodesNbr = len(clusterNodes)
print("Your cluster is composed by {} nodes: {}".format(nodesNbr, clusterNodes))
### Deploy image through kadeploy in g5k ###
kadeployCommad = 'kadeploy3 -f {} -a {}.env -k'.format(oarFile, deployImg)
if multiCluster:
kadeployCommad = kadeployCommad + " --multi-server"
print(kadeployCommad)
kadeployArgs = commandSplit(kadeployCommad)
kadeployProcess = subprocess.Popen(kadeployArgs, stderr=stderr, stdout=stdout)
kadeployProcess.communicate()
### Create ansible host file ###
with open(inventoryPath, 'w') as inventoryFile:
inventoryFile.write('[all:vars]\n')
inventoryFile.write('flink_dir="~/flink-{}/"\n'.format(flinkVersion))
inventoryFile.write('flink_bin_dir="~/flink-{}/bin/"\n'.format(flinkVersion))
inventoryFile.write('flink_conf_dir="~/flink-{}/conf/"\n'.format(flinkVersion))
inventoryFile.write('\n')
inventoryFile.write('[jobmanager]\n')
inventoryFile.write(str(clusterNodes[0]) + '\n')
inventoryFile.write('\n')
inventoryFile.write('[taskmanager]\n')
for i in range(1, nodesNbr):
inventoryFile.write(str(clusterNodes[i]) + '\n')
with open(mastersConf, 'w') as masterFile:
masterFile.write('{}:8081'.format(clusterNodes[0]))
with open(slavesConf, 'w') as slavesFile:
for i in range(1, nodesNbr):
slavesFile.write("{}\n".format(clusterNodes[i]))
### Create flink configuration file to be deployed on host ###
with open(flinkConfYaml, 'r') as flinkConf:
flinkConfData = flinkConf.readlines()
for i in range(0, len(flinkConfData)):
if flinkConfData[i].find('jobmanager.rpc.address') >= 0:
print(flinkConfData[i].find('jobmanager.rpc.address'), flinkConfData[i])
flinkConfData[i] = 'jobmanager.rpc.address: {}\n'.format(clusterNodes[0])
print(i, flinkConfData[i])
break
with open(flinkConfYaml, 'w') as flinkConf:
flinkConf.writelines(flinkConfData)
### Copy nimbus configurations locally ###
copyfile(flinkConfYaml, environ.get('HOME') + '/flink-{}/conf/flink-conf.yaml'.format(flinkVersion)) # this will allow deploying topologies from g5k frontend
### Run ansible playbook ###
ansibleCommand = environ.get('HOME') + '/.local/bin/ansible-playbook -i {} {} --extra-vars "flink_yaml={} masters={} slaves={}"'.format(inventoryPath, playbookPath, flinkConfYaml, mastersConf, slavesConf)
print(ansibleCommand)
ansibleArgs = commandSplit(ansibleCommand)
ansibleProcess = subprocess.Popen(ansibleArgs, stderr=stderr, stdout=stdout)
ansibleProcess.communicate()
### Print ssh tunnel to run on host
print()
print()
print("**** ssh tunnel ***")
print("ssh {}@access.grid5000.fr -N -L8081:{}:8081".format(userName ,clusterNodes[0]))