-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.sh
More file actions
164 lines (155 loc) · 6.77 KB
/
utils.sh
File metadata and controls
164 lines (155 loc) · 6.77 KB
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
#!/bin/bash
################################################################################
# Utility bash function for the playcloud project #
################################################################################
################################################################################
# archive_repo
#
# Creates an archive from the local repository based on the last commit of the
# current branch.
#
# Return values:
# - path to the newly created archive
################################################################################
function archive_repo {
local branch="$(git rev-parse --abbrev-ref HEAD)"
local directory="$(basename "${PWD}")"
local archive_path="/tmp/${directory}.tar.gz"
git archive -o "${archive_path}" "${branch}"
echo "${archive_path}"
}
################################################################################
# setup_proxy
#
# A function that sends all the files required to operate a playcloud proxy to a
# machine using scp and (re-)starts the proxy.
#
# Parameters:
# 1: host The machine files should be sent to
# 2: archive The archive of the repo that should be used to run the proxy
# 3: env_file The environment files with the values that should be used by
# the application
################################################################################
function setup_proxy {
local host="${1}"
local archive="${2}"
local directory="$(basename "${PWD}")"
local env_file="${3}"
scp -o "StrictHostKeyChecking no" "${archive}" exports.source exports.env "${env_file}" "${host}:"
ssh "${host}" "mkdir -p app/ && tar xf ${directory}.tar.gz --directory app/ && \
source exports.source && cd app/ && cp ${env_file} erasure.env && sed --in-place 's/^export //' erasure.env && \
docker-compose -f compose-proxy.yml ps -q | xargs docker rm -f -v ; docker-compose -f compose-proxy.yml up -d"
}
################################################################################
# setup_coder
#
# A function that sends all the files required to operate a playcloud encoder/decoder to a
# machine using scp and (re-)starts the encode/decoder.
#
# Parameters:
# 1: host The machine files should be sent to
# 2: archive The archive of the repo that should be used to run the encoder/decoder
# 3: env_file The environment files with the values that should be used by
# the application
################################################################################
function setup_coder {
local host="${1}"
local archive="${2}"
local directory="$(basename "${PWD}")"
local env_file="${3}"
scp -o "StrictHostKeyChecking no" "${archive}" exports.source exports.env "${env_file}" "${host}:"
ssh "${host}" "mkdir -p app/ && tar xf ${directory}.tar.gz --directory app/ && \
source exports.source && cd app/ && cp ${env_file} erasure.env && sed --in-place 's/^export //' erasure.env && \
docker-compose -f compose-coder.yml ps -q | xargs docker rm -f -v ; docker-compose -f compose-coder.yml up -d"
}
################################################################################
# setup_redis
#
# A function that sends all the files required to operate a redis instance to a
# machine using scp and (re-)starts redis
#
# Parameters:
# 1: host The machine files should be sent to
# 2: archive The archive of the repo that should be used to run redis
# 3: env_file The environment files with the values that should be used by
# the application
################################################################################
function setup_redis {
local host="${1}"
local archive="${2}"
local directory="$(basename "${PWD}")"
local env_file="${3}"
scp -o "StrictHostKeyChecking no" "${archive}" exports.source exports.env "${env_file}" "${host}:"
ssh "${host}" "mkdir -p app/ && tar xf ${directory}.tar.gz --directory app/ && \
source exports.source && cd app/ && cp ${env_file} erasure.env && sed --in-place 's/^export //' erasure.env && \
docker-compose -f compose-redis.yml ps -q | xargs docker rm -f -v ; docker-compose -f compose-redis.yml up -d"
}
################################################################################
# setup_client
#
# A function that sends all the files required to operate a benchmarking client
# to a machine using scp.
#
# Parameters:
# 1: host The machine files should be sent to
# 2: archive The archive of the repo that should be used to run the
# benchmarking client
# 3: env_file The environment files with the values that should be used by
# the application
################################################################################
function setup_client {
local host="${1}"
local archive="${2}"
local directory="$(basename "${PWD}")"
local env_file="${3}"
shift 3
scp -o "StrictHostKeyChecking no" "${archive}" exports.source exports.env "${env_file}" "${host}:"
ssh "${host}" "mkdir -p playcloud/ && tar xf ${directory}.tar.gz --directory playcloud/ && \
cp ${directory}.tar.gz /tmp/ && cp exports.source playcloud/exports.source && cp exports.env playcloud/exports.env && \
echo -e '\n$(cat exports.source)' >> /home/ubuntu/.bashrc && echo -e '\n$(cat exports.source)' >> /home/ubuntu/.profile && \
source exports.source && cd playcloud/ && cp ${env_file} erasure.env && sed --in-place 's/^export //' erasure.env && \
sudo apt-get install --quiet --assume-yes redis-tools"
}
################################################################################
# fetch_microbench_experimental_data
#
# A function that recovers microbench data from a list of servers from the
# cluster.
#
# Parameters:
# n: ips IP addesses of the server on which microbench experiments
# werer run
################################################################################
function fetch_microbench_experimental_data {
local ips=("${@}")
for ip in "${ips[@]}"; do
rsync --recursive --update --partial --compress --quiet -e \
ssh "${ip}":app/xpdata/pyeclib/ data/pyeclib/
done
}
################################################################################
# gen_random_data
#
# Generates a file of random data of size n MB where n is given as a parameter.
#
# Parameters:
# 1: size Size in MB of the file to generate
# Return values:
# - path to the newly created file
################################################################################
function gen_random_data {
if [[ "${#}" == 0 ]]; then
echo "How to use:"
echo "$0 size_of_random_data [MB]"
return 1
fi
local size="${1}"
local file="/tmp/random${size}.dat"
if [[ -e "${file}" ]]; then
echo "${file}"
return 0
fi
dd if=/dev/urandom of="${file}" bs=1048576 count="${size}" > /dev/null 2>&1
echo "${file}"
return 0
}