-
Notifications
You must be signed in to change notification settings - Fork 214
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add node manager for resilientdb.com
- Loading branch information
Showing
8 changed files
with
217 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
py_binary( | ||
name = "deploy_manager", | ||
srcs = ["deploy_manager.py"], | ||
deps = [ | ||
"//proto:replica_info_py_proto", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
Run Node Manager as backend to lauch Nexres locally. | ||
|
||
If you are under the repo root path, go the deploy/node_manager. | ||
Then | ||
``` | ||
bazel run :deploy_manager $PWD | ||
``` | ||
|
||
Launch your front end from : [resilientdb](https://github.com/resilientdb/resilientdb.github.io/tree/nexres) | ||
Change the [endpoint address](https://github.com/resilientdb/resilientdb.github.io/blob/nexres/src/api/endpoint.ts#L22) so all the deployment request will be sent to your node manager backend. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
from http.server import BaseHTTPRequestHandler | ||
from urllib import parse | ||
import subprocess | ||
import json | ||
import sys | ||
|
||
from proto.replica_info_pb2 import ResConfigData,ReplicaInfo | ||
from google.protobuf.json_format import MessageToJson | ||
from google.protobuf.json_format import Parse, ParseDict | ||
|
||
script_path="/home/ubuntu/nexres/deploy/node_manager" | ||
|
||
def RunCmd(cmd): | ||
p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) | ||
print("run:{}".format(cmd)) | ||
print("res:{}".format(p.stdout.readlines())) | ||
|
||
class GetHandler(BaseHTTPRequestHandler): | ||
|
||
def do_GET(self): | ||
parsed_path = parse.urlparse(self.path) | ||
print("path data:",parsed_path.path) | ||
if parsed_path.path == "/node/stop": | ||
self.Stop(); | ||
self.send_response_only(200) | ||
#self.send_header('Content-Type', | ||
# 'text/plain; charset=utf-8') | ||
#self.end_headers() | ||
#self.wfile.write(bytes(json.dumps(js).encode('utf-8'))) | ||
|
||
|
||
def do_POST(self): | ||
parsed_path = parse.urlparse(self.path) | ||
print("path data:",parsed_path.path) | ||
if parsed_path.path == "/node/deploy": | ||
content_len = int(self.headers['Content-Length']) | ||
post_body = str(self.rfile.read(content_len).decode()) | ||
post_body=post_body.replace("%3A",":") | ||
data_list = post_body.split('&') | ||
addresses = [] | ||
for data in data_list: | ||
if data.split("=")[0] == "address": | ||
addresses.append(data.split("=")[1]) | ||
self.StartServer(addresses) | ||
self.send_response_only(200) | ||
|
||
def GenerateServerConfig(self, addresses): | ||
config_data=ResConfigData() | ||
config_data.self_region_id=1 | ||
region = config_data.region.add() | ||
region.region_id = 1 | ||
idx=1 | ||
with open("{}/deploy/iplist.txt".format(script_path),"w") as f: | ||
for address in addresses: | ||
(ip,port) = address.split(':') | ||
f.write("{}:{}\n".format(ip,port)) | ||
replica = ReplicaInfo() | ||
replica.id = idx | ||
replica.ip = ip | ||
replica.port = int(port) | ||
region.replica_info.append(replica) | ||
idx+=1 | ||
json_obj = MessageToJson(config_data) | ||
with open("{}/deploy/server.config".format(script_path),"w") as f: | ||
f.write(json_obj) | ||
return idx-2 | ||
|
||
def Stop(self): | ||
RunCmd("{}/stop.sh".format(script_path)) | ||
|
||
def Start(self, server_num): | ||
RunCmd("{}/generate_key.sh {}".format(script_path, script_path)) | ||
RunCmd("{}/generate_config.sh {}".format(script_path, script_path)) | ||
RunCmd("{}/start_kv_server.sh {} {}".format(script_path, script_path, server_num)) | ||
|
||
def StartServer(self,addresses): | ||
server_num = self.GenerateServerConfig(addresses) | ||
self.Start(server_num) | ||
|
||
if __name__ == '__main__': | ||
if len(sys.argv) == 1: | ||
print ("please provide the script path paramaters. Usage: bazel run :deploy_manager $PWD") | ||
exit(0) | ||
print(" working path:",sys.argv[1]) | ||
script_path = sys.argv[1] | ||
from http.server import HTTPServer | ||
server = HTTPServer(('0.0.0.0', 4080), GetHandler) | ||
print('Starting server, use <Ctrl-C> to stop') | ||
server.serve_forever() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#!/bin/bash | ||
|
||
WORK_PATH=$1 | ||
WORK_SPACE=${WORK_PATH}/../../ | ||
|
||
cd "${WORK_PATH}" | ||
|
||
IPS=`cat ./deploy/iplist.txt` | ||
|
||
KEY_TOOLS_BIN=${WORK_SPACE}/bazel-bin/tools/key_generator_tools | ||
CERT_TOOLS_BIN=${WORK_SPACE}/bazel-bin/tools/certificate_tools | ||
ADMIN_PRIVATE_KEY=${WORK_SPACE}/cert/admin.key.pri | ||
ADMIN_PUBLIC_KEY=${WORK_SPACE}/cert/admin.key.pub | ||
CERT_PATH=deploy/cert/ | ||
DEPLOY_PATH=deploy | ||
CLIENT_NUM=1 | ||
|
||
bazel build //tools:certificate_tools | ||
|
||
echo "" > ${DEPLOY_PATH}/client.config | ||
idx=1 | ||
tot=0 | ||
for ip in ${IPS[@]} | ||
do | ||
((tot++)) | ||
done | ||
echo $tot | ||
|
||
for addr in ${IPS}; | ||
do | ||
t=(${addr//:/ }) | ||
ip=${t[0]} | ||
port=${t[1]} | ||
echo "ip:",${ip},"port",${port} | ||
public_key=${CERT_PATH}/node_${idx}.key.pub | ||
|
||
# create public key | ||
# create server config | ||
# create the public key and certificate | ||
if [ $(($idx+$CLIENT_NUM)) -gt $tot ] ; then | ||
$CERT_TOOLS_BIN ${CERT_PATH} ${ADMIN_PRIVATE_KEY} ${ADMIN_PUBLIC_KEY} ${public_key} ${idx} ${ip} ${port} client | ||
echo "${idx} ${ip} ${port}" >> ${DEPLOY_PATH}/client.config | ||
else | ||
$CERT_TOOLS_BIN ${CERT_PATH} ${ADMIN_PRIVATE_KEY} ${ADMIN_PUBLIC_KEY} ${public_key} ${idx} ${ip} ${port} replica | ||
fi | ||
|
||
idx=$(($idx+1)) | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
|
||
WORK_PATH=$1 | ||
WORK_SPACE=${WORK_PATH}/../../ | ||
|
||
cd "${WORK_PATH}" | ||
|
||
NUM=`cat deploy/iplist.txt| awk '{if (length($0) > 0) {print $0}}' | wc -l` | ||
|
||
echo "server num:$NUM" | ||
|
||
mkdir -p deploy/cert | ||
cd deploy | ||
bazel build //tools:key_generator_tools | ||
|
||
for idx in `seq 1 ${NUM}`; | ||
do | ||
echo `${WORK_SPACE}/bazel-bin/tools/key_generator_tools "./cert/node_${idx}" "AES"` | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Loading: | ||
Loading: 0 packages loaded | ||
Analyzing: target //deploy/node_manager:deploy_manager (0 packages loaded, 0 targets configured) | ||
INFO: Analyzed target //deploy/node_manager:deploy_manager (0 packages loaded, 0 targets configured). | ||
INFO: Found 1 target... | ||
[0 / 1] [Prepa] BazelWorkspaceStatusAction stable-status.txt | ||
Target //deploy/node_manager:deploy_manager up-to-date: | ||
bazel-bin/deploy/node_manager/deploy_manager | ||
INFO: Elapsed time: 0.316s, Critical Path: 0.01s | ||
INFO: 1 process: 1 internal. | ||
INFO: Build completed successfully, 1 total action | ||
INFO: Running command line: bazel-bin/deploy/node_manager/deploy_manager /home/ubuntu/nexres/deploy/node_manager | ||
INFO: Build completed successfully, 1 total action |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
!/bin/bash | ||
|
||
killall -9 kv_server | ||
|
||
WORK_PATH=$1 | ||
WORK_SPACE=${WORK_PATH}/../../ | ||
SERVER_PATH=${WORK_SPACE}/bazel-bin/kv_server/kv_server | ||
SERVER_CONFIG=${WORK_PATH}/deploy/server.config | ||
LOG_PATH=${WORK_PATH}/deploy/log | ||
|
||
cd ${WORK_PATH} | ||
|
||
bazel build //kv_server:kv_server | ||
mkdir -p ${LOG_PATH} | ||
|
||
SVR_NUM=$2 | ||
|
||
echo "server num:"${SVR_NUM} | ||
METRIC_PORT=8091 | ||
for i in `seq 1 ${SVR_NUM}`; | ||
do | ||
echo ${i} | ||
nohup $SERVER_PATH $SERVER_CONFIG $WORK_PATH/deploy/cert/node_${i}.key.pri $WORK_PATH/deploy/cert/cert_${i}.cert 0.0.0.0:${METRIC_PORT} > ${LOG_PATH}/server${i}.log 2>&1 & | ||
METRIC_PORT=`expr ${METRIC_PORT} + 1` | ||
done | ||
|
||
SVR_NUM=`expr ${SVR_NUM} + 1` | ||
echo ${SVR_NUM} | ||
|
||
nohup $SERVER_PATH $SERVER_CONFIG $WORK_PATH/deploy/cert/node_${SVR_NUM}.key.pri $WORK_PATH/deploy/cert/cert_${SVR_NUM}.cert 0.0.0.0:${METRIC_PORT} > ${LOG_PATH}/client.log 2>&1 & |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
killall -9 kv_server |