Skip to content

Commit

Permalink
完善example部署脚本
Browse files Browse the repository at this point in the history
  • Loading branch information
wenweihu86 committed Jun 28, 2018
1 parent 3cf5d9e commit 18b0b99
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 19 deletions.
1 change: 0 additions & 1 deletion raft-java-example/build.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env bash

mvn clean package
mvn dependency:copy-dependencies
39 changes: 39 additions & 0 deletions raft-java-example/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env bash

mvn clean package

EXAMPLE_ZIP=raft-java-example-1.8.0-deploy.zip
ROOT_DIR=./env
mkdir -p $ROOT_DIR
cd $ROOT_DIR

mkdir example1
cd example1
cp -f ../../target/$EXAMPLE_ZIP .
tar -zxvf $EXAMPLE_ZIP
chmod +x ./bin/*.sh
nohup ./bin/run_server.sh ./data "127.0.0.1:8051:1,127.0.0.1:8052:2,127.0.0.1:8053:3" "127.0.0.1:8051:1" &
cd -

mkdir example2
cd example2
cp -f ../../target/$EXAMPLE_ZIP .
tar -zxvf $EXAMPLE_ZIP
chmod +x ./bin/*.sh
nohup ./bin/run_server.sh ./data "127.0.0.1:8051:1,127.0.0.1:8052:2,127.0.0.1:8053:3" "127.0.0.1:8052:2" &
cd -

mkdir example3
cd example3
cp -f ../../target/$EXAMPLE_ZIP .
tar -zxvf $EXAMPLE_ZIP
chmod +x ./bin/*.sh
nohup ./bin/run_server.sh ./data "127.0.0.1:8051:1,127.0.0.1:8052:2,127.0.0.1:8053:3" "127.0.0.1:8053:3" &
cd -

mkdir client
cd client
cp -f ../../target/$EXAMPLE_ZIP .
tar -zxvf $EXAMPLE_ZIP
chmod +x ./bin/*.sh
cd -
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
*/
public class ClientMain {
public static void main(String[] args) {
if (args.length < 2) {
System.out.printf("Usage: ./run_server.sh CLUSTER KEY [VALUE]\n");
System.exit(-1);
}

// parse args
String ipPorts = args[0];
String key = args[1];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ public class ConcurrentClientMain {
private static JsonFormat.Printer printer = JsonFormat.printer().omittingInsignificantWhitespace();

public static void main(String[] args) {
if (args.length != 1) {
System.out.printf("Usage: ./run_concurrent_client.sh THREAD_NUM\n");
System.exit(-1);
}

// parse args
String ipPorts = args[0];
RPCClient rpcClient = new RPCClient(ipPorts);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,30 @@
*/
public class ServerMain {
public static void main(String[] args) {
if (args.length != 3) {
System.out.printf("Usage: ./run_server.sh DATA_PATH CLUSTER CURRENT_NODE\n");
System.exit(-1);
}
// parse args
// raft data dir
String dataPath = args[0];
// peers, format is "host:port:serverId,host2:port2:serverId2"
String servers = args[0];
String servers = args[1];
String[] splitArray = servers.split(",");
List<RaftMessage.Server> serverList = new ArrayList<>();
for (String serverString : splitArray) {
RaftMessage.Server server = parseServer(serverString);
serverList.add(server);
}
// local server
RaftMessage.Server localServer = parseServer(args[1]);
RaftMessage.Server localServer = parseServer(args[2]);

// 初始化RPCServer
RPCServer server = new RPCServer(localServer.getEndPoint().getPort());
// 设置Raft选项,比如:
// just for test snapshot
RaftOptions raftOptions = new RaftOptions();
raftOptions.setDataDir(dataPath);
raftOptions.setSnapshotMinLogSize(10 * 1024);
raftOptions.setSnapshotPeriodSeconds(30);
raftOptions.setMaxSegmentFileSize(1024 * 1024);
Expand Down
5 changes: 0 additions & 5 deletions raft-java-example/start_client.sh

This file was deleted.

11 changes: 0 additions & 11 deletions raft-java-example/start_server.sh

This file was deleted.

0 comments on commit 18b0b99

Please sign in to comment.