Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added configuration options to TSOServer

Use JCommander to parse configuration options from command line
  • Loading branch information...
commit 9d6d1a074b84ee072a54ee54e1f8ec96cc04a2b0 1 parent 7956078
@dgomezferro authored
View
2  bin/omid.sh
@@ -41,7 +41,7 @@ fi
tso() {
export LD_LIBRARY_PATH=`$READLINK -f ../src/main/native`
- exec java -Xmx1024m -cp $CLASSPATH -Domid.maxItems=100000 -Domid.maxCommits=100000 -Djava.library.path=$LD_LIBRARY_PATH -Dlog4j.configuration=log4j.properties com.yahoo.omid.tso.TSOServer 1234 $BATCHSIZE 4 2 localhost:2181
+ exec java -Xmx1024m -cp $CLASSPATH -Domid.maxItems=100000 -Domid.maxCommits=100000 -Djava.library.path=$LD_LIBRARY_PATH -Dlog4j.configuration=log4j.properties com.yahoo.omid.tso.TSOServer -port 1234 -batch $BATCHSIZE -ensemble 4 -quorum 2 -zk localhost:2181
}
tsobench() {
View
7 pom.xml
@@ -147,5 +147,12 @@
<type>jar</type>
<scope>compile</scope>
</dependency>
+ <dependency>
+ <groupId>com.beust</groupId>
+ <artifactId>jcommander</artifactId>
+ <version>1.23</version>
+ <type>jar</type>
+ <scope>compile</scope>
+ </dependency>
</dependencies>
</project>
View
14 src/main/java/com/yahoo/omid/tso/TSOServer.java
@@ -79,19 +79,9 @@ public TSOState getState() {
* @throws Exception
*/
public static void main(String[] args) throws Exception {
- // Print usage if no argument is specified.
- if (args.length < 1) {
- System.err.println("Usage: " + TSOServer.class.getSimpleName() + " <port>");
- return;
- }
-
- // Parse options.
- int port = Integer.parseInt(args[0]);
- int batch = Integer.parseInt(args[1]);
- int ensSize = Integer.parseInt(args[2]), qSize = Integer.parseInt(args[3]);
- String zkservers = args[4];
+ TSOServerConfig config = TSOServerConfig.parseConfig(args);
- new TSOServer(TSOServerConfig.configFactory(port, batch, (zkservers != null), ensSize, qSize, zkservers)).run();
+ new TSOServer(config).run();
}
@Override
View
31 src/main/java/com/yahoo/omid/tso/TSOServerConfig.java
@@ -16,6 +16,9 @@
package com.yahoo.omid.tso;
+import com.beust.jcommander.JCommander;
+import com.beust.jcommander.Parameter;
+
/**
* Holds the configuration parameters of a TSO server instance.
*
@@ -39,17 +42,41 @@ static public TSOServerConfig configFactory(int port, int batch, boolean recover
return config;
}
-
+
+ static public TSOServerConfig parseConfig(String args[]){
+ config = new TSOServerConfig();
+
+ if (args.length == 0) {
+ new JCommander(config).usage();
+ System.exit(0);
+ }
+
+ new JCommander(config, args);
+
+ return config;
+ }
+
+ @Parameter(names = "-port", description = "Port reserved by the Status Oracle", required = true)
private int port;
+
+ @Parameter(names = "-batch", description = "Threshold for the batch sent to the WAL")
private int batch;
+
+ @Parameter(names = "-ha", description = "Highly Available status oracle: logs operations to the WAL and recovers from a crash")
private boolean recoveryEnabled;
+
+ @Parameter(names = "-zk", description = "ZooKeeper ensemble: host1:port1,host2:port2...")
private String zkServers;
+
+ @Parameter(names = "-ensemble", description = "WAL ensemble size")
private int ensemble;
+
+ @Parameter(names = "-quorum", description = "WAL quorum size")
private int quorum;
TSOServerConfig(){
this.port = Integer.parseInt(System.getProperty("PORT", "1234"));
- this.batch = Integer.parseInt(System.getProperty("batch", "0"));
+ this.batch = Integer.parseInt(System.getProperty("BATCH", "0"));
this.recoveryEnabled = Boolean.parseBoolean(System.getProperty("RECOVERABLE", "false"));
this.zkServers = System.getProperty("ZKSERVERS");
this.ensemble = Integer.parseInt(System.getProperty("ENSEMBLE", "3"));
View
13 src/test/java/com/yahoo/omid/OmidTestBase.java
@@ -76,12 +76,13 @@ public void run() {
tsothread = new Thread("TSO Thread") {
public void run() {
try {
- String[] args = new String[5];
- args[0] = "1234";
- args[1] = "100";
- args[2] = "4";
- args[3] = "2";
- args[4] = "localhost:2181";
+ String[] args = new String[] {
+ "-port", "1234",
+ "-batch", "100",
+ "-ensemble", "4",
+ "-quorum", "2",
+ "-zk", "localhost:2181"
+ };
TSOServer.main(args);
} catch (InterruptedException e) {
// go away quietly
Please sign in to comment.
Something went wrong with that request. Please try again.