-
Notifications
You must be signed in to change notification settings - Fork 12
/
fabfile.py
215 lines (177 loc) · 8.49 KB
/
fabfile.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
import os
import json
from collections import OrderedDict
from fabric.api import *
from fabric.contrib.files import exists
from pathlib import Path
env.hosts = open('InstancesConfigurations/public_ips', 'r').read().splitlines()
env.user = 'ubuntu'
# env.password=''
env.key_filename = ['%s/Keys/matrix.pem' % Path.home()]
@task
def pre_process(working_directory, task_idx):
sudo('apt-get install python3 -y')
with cd(working_directory):
put('%s/ExperimentExecute/pre_process.py' % Path.home())
run('python3 pre_process.py %s' % task_idx)
@task
def install_git_project(git_branch, working_directory, git_address, external):
if not exists('%s' % working_directory):
run('git clone %s %s' % (git_address, working_directory))
with cd('%s' % working_directory):
run('git pull')
run('git checkout %s ' % git_branch)
if external:
with cd('%s/MATRIX' % working_directory):
run('. ./build.sh')
else:
if exists('%s/CMakeLists.txt' % working_directory):
sudo('rm -rf CMakeFiles CMakeCache.txt Makefile')
run('cmake .')
run('make')
with warn_only():
run('7za -y x \"*.7z\"')
@task
def update_libscapi(branch):
with cd('libscapi/'):
run('git checkout %s' % branch)
run('git pull')
run('make')
@task
def run_protocol(config_file, args, executable_name, working_directory):
with open(config_file) as data_file:
data = json.load(data_file, object_pairs_hook=OrderedDict)
external_protocol = json.loads(data['isExternal'].lower())
if 'aws' in data['CloudProviders']:
regions = data['CloudProviders']['aws']['regions']
elif 'scaleway' in data['CloudProviders']:
regions = data['CloudProviders']['scaleway']['regions']
else:
regions = data['CloudProviders']['aws']['regions'] + data['CloudProviders']['scaleway']['regions']
vals = args.split('@')
values_str = ''
for val in vals:
# for external protocols
if val == 'partyid':
values_str += '%s ' % str(env.hosts.index(env.host) - 1)
else:
values_str += '%s ' % val
with cd(working_directory):
if env.user == 'root':
party_id = env.hosts.index('root@%s' % env.host)
else:
party_id = env.hosts.index(env.host)
with warn_only():
sudo("kill -9 `ps aux | grep %s | awk '{print $2}'`" % executable_name)
if 'inputs0' in values_str:
values_str = values_str.replace('input_0.txt', 'input_%s.txt' % str(party_id))
if not external_protocol:
if len(regions) > 1:
put('InstancesConfigurations/parties%s.conf' % party_id, run('pwd'))
run('mv parties%s.conf parties.conf' % party_id)
else:
put('InstancesConfigurations/parties.conf', run('pwd'))
run('./%s partyID %s %s' % (executable_name, party_id, values_str))
with open('Execution/execution_log.log', 'a+') as log_file:
log_file.write('%s\n' % values_str)
else:
# run external protocols
with cd('MATRIX'):
if 'coordinatorConfig' in data:
# run protocols with coordinator
if env.hosts.index(env.host) == 0:
coordinator_executable = data['coordinatorExecutable']
coordinator_args = data['coordinatorConfig'].split('@')
coordinator_values_str = ''
for coordinator_val in coordinator_args:
coordinator_values_str += '%s ' % coordinator_val
sudo("kill -9 `ps aux | grep %s | awk '{print $2}'`" % coordinator_executable)
run('./%s %s' % (coordinator_executable, coordinator_values_str))
with open('Execution/execution_log.log', 'a+') as log_file:
log_file.write('%s\n' % values_str)
else:
if len(regions) > 1:
put('InstancesConfigurations/parties%s.conf' % party_id, run('pwd'))
run('mv parties%s.conf parties.conf' % party_id)
else:
put('InstancesConfigurations/parties.conf', run('pwd'))
run('. ./%s %s %s' % (executable_name, party_id - 1, values_str))
with open('Execution/execution_log.log', 'a+') as log_file:
log_file.write('%s\n' % values_str)
else:
# run external protocols with no coordinator
run('. ./%s %s %s' % (executable_name, party_id, values_str))
with open('Execution/execution_log.log', 'a+') as log_file:
log_file.write('%s\n' % values_str)
@task
def run_protocol_profiler(config_file, args, executable_name, working_directory):
with open(config_file) as data_file:
data = json.load(data_file, object_pairs_hook=OrderedDict)
external_protocol = json.loads(data['isExternal'].lower())
if 'aws' in data['CloudProviders']:
regions = data['CloudProviders']['aws']['regions']
elif 'scaleway' in data['CloudProviders']:
regions = data['CloudProviders']['scaleway']['regions']
else:
regions = data['CloudProviders']['aws']['regions'] + data['CloudProviders']['scaleway']['regions']
vals = args.split('@')
values_str = ''
for val in vals:
# for external protocols
if val == 'partyid':
values_str += '%s ' % str(env.hosts.index(env.host) - 1)
else:
values_str += '%s ' % val
with cd(working_directory):
if env.user == 'root':
party_id = env.hosts.index('root@%s' % env.host)
else:
party_id = env.hosts.index(env.host)
with warn_only():
sudo("kill -9 `ps aux | grep %s | awk '{print $2}'`" % executable_name[idx])
if 'inputs0' in values_str:
values_str = values_str.replace('input_0.txt', 'input_%s.txt' % str(party_id))
if not external_protocol:
if len(regions) > 1:
put('InstancesConfigurations/parties%s.conf' % party_id, run('pwd'))
run('mv parties%s.conf parties.conf' % party_id)
else:
put('InstancesConfigurations/parties.conf', run('pwd'))
if party_id == 0:
run('valgrind --tool=callgrind ./%s partyID %s %s'
% (executable_name, party_id, values_str))
get('callgrind.out.*', os.getcwd())
else:
run('./%s partyID %s %s' % (executable_name, party_id, values_str))
with open('Execution/execution_log.log', 'a+') as log_file:
log_file.write('%s\n' % values_str)
@task
def collect_results(results_server_directory, results_local_directory, is_external):
local('mkdir -p %s' % results_local_directory)
if not is_external:
get('%s/*.json' % results_server_directory, results_local_directory)
else:
get('%s/MATRIX/logs/*.log' % results_server_directory, results_local_directory)
@task
def get_logs(working_directory):
local('mkdir -p logs')
get('%s/logs/*.log' % working_directory, '%s/MATRIX/logs' % Path.home())
@task
def update_acp_protocol():
with cd('ACP'):
run('git pull https://github.com/cryptobiu/ACP')
with cd('comm_client'):
run('cmake .')
run('make')
@task
def deploy_proxy(number_of_proxies):
# set hosts to be proxy server
env.host = ['34.239.19.87']
# kill all existing proxies
with warn_only():
sudo("kill -9 `ps aux | grep cct_proxy | awk '{print $2}'`")
with cd('ACP/cct_proxy'):
put('NodeApp/public/assets/parties.conf', run('pwd'))
with open('NodeApp/public/assets/parties.conf') as parties_file:
number_of_peers = len(parties_file.readlines())
run('./run_multiple_proxies %s %s' % ((int(number_of_proxies) - 1), number_of_peers))