Permalink
Browse files

simple client, some helper scripts

  • Loading branch information...
1 parent c66df54 commit 75afa5d69f1a640909c4523e973b094553c994ce @freels freels committed Apr 12, 2011
Showing with 54 additions and 15 deletions.
  1. +16 −10 bin/rowz
  2. +10 −0 bin/setup
  3. +4 −4 config/development.scala
  4. +1 −1 config/test.scala
  5. +23 −0 src/main/scala/com/twitter/rowz/RowzClient.scala
View
26 bin/rowz
@@ -1,5 +1,5 @@
#!/bin/sh
-set -e
+
if [ $# -lt 1 ]; then
echo
echo "This runs a Rowz server in the foreground, suitable for experimentation"
@@ -11,18 +11,24 @@ fi
cd `dirname $0`/..
-echo | mysql -u "$1" --password="$2" rowz_nameserver
-if [ $? -eq 1 ]; then
- echo "Before running, you need to create a mysql database and:"
- echo "mysql> CREATE DATABASE rowz_nameserver;"
- exit 1
+mysql -u "$1" --password="$2" -e"show databases" rowz_nameserver > /dev/null 2>&1
+if [ $? -ge 1 ]; then
+ echo "Setting up a development db for rowz."
+ echo "For more involved nameserver config, check out http://github.com/twitter/gizzmo"
+mysql -u$1 -p$2 <<EOF
+create database if not exists rowz_nameserver;
+create database if not exists rowz
+EOF
fi
-
-if [ ! -f dist/rowz/rowz-1.0.jar ]; then
+
+if [ ! -f dist/Rowz/rowz-1.0.jar ]; then
echo "You need to build rows first. Try: "
- echo "ant dist -DDB_USERNAME=fixme -DDB_PASSWORD=fixmetoo"
+ echo "sbt package-dist"
exit 1
fi
echo "Starting rowz (it's kinda quiet at the moment)"
-java -DDB_USERNAME="$1" -DDB_PASSWORD="$2" -jar dist/rowz/rowz-1.0.jar -f config/development.conf
+env DB_USERNAME=$1 DB_PASSWORD=$2 java -jar dist/Rowz/rowz-1.0.jar config/development.scala
+
+
+
View
10 bin/setup
@@ -0,0 +1,10 @@
+#!/bin/sh
+
+echo "Setting up a development shard for rowz."
+echo "For more involved nameserver config, check out http://github.com/twitter/gizzmo"
+
+gizzmo -Hlocalhost -P7920 create SqlShard localhost/shard_1
+gizzmo -Hlocalhost -P7920 create ReplicatingShard localhost/shard_1_replicating
+gizzmo -Hlocalhost -P7920 addlink localhost/shard_1_replicating localhost/shard_1 1
+gizzmo -Hlocalhost -P7920 addforwarding -- 0 -9223372036854775808 localhost/shard_1_replicating
+gizzmo -Hlocalhost -P7920 -f reload
View
8 config/development.scala
@@ -11,7 +11,7 @@ trait Credentials extends Connection {
import scala.collection.JavaConversions._
val env = System.getenv().toMap
val username = env.getOrElse("DB_USERNAME", "root")
- val password = env.getOrElse("DB_PASSWORD", "")
+ val password = env.getOrElse("DB_PASSWORD", null)
}
class TestQueryEvaluator(label: String) extends QueryEvaluator {
@@ -51,14 +51,14 @@ new Rowz {
val connection = new Connection with Credentials {
val hostnames = Seq("localhost")
- val database = "rowz_nameserver_test"
+ val database = "rowz_nameserver"
}
})
}
val databaseConnection = new Connection with Credentials {
val hostnames = Seq("localhost")
- val database = "rowz_test"
+ val database = "rowz"
}
val rowzQueryEvaluator = new TestQueryEvaluator("rowz") {
@@ -89,6 +89,6 @@ new Rowz {
Priority.Low.id -> new TestScheduler("low")
)
- logging = new LogConfigString("level = \"debug\"\nfilename = \"test.log\"")
+ logging = new LogConfigString("level = \"debug\"")
}
View
2 config/test.scala
@@ -11,7 +11,7 @@ trait Credentials extends Connection {
import scala.collection.JavaConversions._
val env = System.getenv().toMap
val username = env.getOrElse("DB_USERNAME", "root")
- val password = env.getOrElse("DB_PASSWORD", "")
+ val password = env.getOrElse("DB_PASSWORD", null)
}
class TestQueryEvaluator(label: String) extends QueryEvaluator {
View
23 src/main/scala/com/twitter/rowz/RowzClient.scala
@@ -0,0 +1,23 @@
+package com.twitter.rowz
+
+import com.twitter.conversions.time._
+
+import org.apache.thrift.protocol.{TProtocol, TBinaryProtocol}
+import org.apache.thrift.transport.{TSocket, TFramedTransport}
+
+class RowzClient(hostname: String) {
+ def port = 7919
+ def socketTimeout = 5.seconds
+
+ val socket = new TSocket(hostname, port, socketTimeout.inMilliseconds.toInt)
+ val transport = new TFramedTransport(socket)
+ val protocol = new TBinaryProtocol(transport)
+ val client = new thrift.Rowz.Client.Factory().getClient(protocol)
+
+ transport.open
+
+ def create(name: String) = client.create(name)
+ def update(row: thrift.Row) = client.update(row)
+ def destroy(id: Long) = client.destroy(id)
+ def read(id: Long) = client.read(id)
+}

0 comments on commit 75afa5d

Please sign in to comment.