Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'multi_cluster' of github.com:twitter/gizzard into multi…

…_cluster
  • Loading branch information...
commit ce950ddc38df20d203cab9e3cc8426c72cf23a38 2 parents 6ec6a43 + c6eadab
eaceaser authored
View
4 src/main/scala/com/twitter/gizzard/scheduler/JournaledJob.scala
@@ -11,11 +11,11 @@ class JournaledJob(val job: JsonJob, journaller: String => Unit) extends JsonJob
def apply() {
job()
try {
- journaller(new String(job.toJson, "UTF-8"))
+ journaller(job.toJson)
} catch {
case e: Exception =>
val log = Logger.get(getClass.getName)
- log.warning(e, "Failed to journal job: %s", job.toString)
+ log.warning(e, "Failed to journal job: %s", job.toJson)
}
}
}
View
2  src/main/scala/com/twitter/gizzard/scheduler/JsonCodec.scala
@@ -36,7 +36,7 @@ class JsonCodec(unparsableJobHandler: Array[Byte] => Unit) extends Codec[JsonJob
def +=(item: (Regex, JsonJobParser)) = processors += item
def +=(r: Regex, p: JsonJobParser) = processors += ((r, p))
- def flatten(job: JsonJob): Array[Byte] = job.toJson
+ def flatten(job: JsonJob): Array[Byte] = job.toJsonBytes
def inflate(data: Array[Byte]): JsonJob = {
try {
View
6 src/main/scala/com/twitter/gizzard/scheduler/JsonJob.scala
@@ -23,12 +23,14 @@ trait JsonJob extends Job {
def shouldReplicate = true
def className = getClass.getName
- def toJson = {
+ def toJsonBytes = {
def json = toMap ++ Map("error_count" -> errorCount, "error_message" -> errorMessage)
val javaMap = deepConvert(Map(className -> json))
JsonJob.mapper.writeValueAsBytes(javaMap)
}
+ def toJson = new String(toJsonBytes, "UTF-8")
+
private def deepConvert(scalaMap: Map[String, Any]): JMap[String, Any] = {
val map = new java.util.LinkedHashMap[String, Any]()
scalaMap.map { case (k, v) =>
@@ -53,7 +55,7 @@ trait JsonJob extends Job {
list
}
- override def toString = new String(toJson, "UTF-8")
+ override def toString = toJson
}
/**
View
2  src/main/scala/com/twitter/gizzard/scheduler/ReplicatingJob.scala
@@ -59,7 +59,7 @@ class ReplicatingJob(
extends JsonNestedJob(jobs) {
def this(relay: JobRelay, jobs: Iterable[JsonJob], clusters: Iterable[String]) =
- this(relay, jobs, clusters, jobs.map(_.toJson))
+ this(relay, jobs, clusters, jobs.map(_.toJsonBytes))
def this(relay: JobRelay, jobs: Iterable[JsonJob]) = this(relay, jobs, relay.clusters)
View
4 src/main/scala/com/twitter/gizzard/thrift/JobInjectorService.scala
@@ -27,9 +27,9 @@ extends JobInjector.Iface {
def apply = deserialized.apply()
def toMap = deserialized.toMap
- override def toJson = {
+ override def toJsonBytes = {
if (isDeserialized) {
- deserialized.toJson
+ deserialized.toJsonBytes
} else {
serialized
}
View
2  src/test/scala/com/twitter/gizzard/scheduler_new/CopyJobSpec.scala
@@ -46,7 +46,7 @@ object CopyJobSpec extends ConfiguredSpecification with JMocker with ClassMocker
"toJson" in {
val copy = makeCopy(Some(nextCopy))
- val json = new String(copy.toJson, "UTF-8")
+ val json = copy.toJson
json mustMatch "Copy"
json mustMatch "\"source_shard_hostname\":\"%s\"".format(sourceShardId.hostname)
json mustMatch "\"source_shard_table_prefix\":\"%s\"".format(sourceShardId.tablePrefix)
View
2  src/test/scala/com/twitter/gizzard/scheduler_new/JournaledJobSpec.scala
@@ -14,7 +14,7 @@ class JournaledJobSpec extends ConfiguredSpecification with JMocker with ClassMo
"journal on success" in {
expect {
one(job).apply()
- one(job).toJson willReturn "hello".getBytes("UTF-8")
+ one(job).toJson willReturn "hello"
one(queue).apply("hello")
}
View
6 src/test/scala/com/twitter/gizzard/scheduler_new/JsonJobParserSpec.scala
@@ -55,7 +55,7 @@ class JsonJobParserSpec extends ConfiguredSpecification with JMocker with ClassM
}
"JsonJob" in {
- val json = new String(job.toJson, "UTF-8")
+ val json = job.toJson
json mustMatch "\"FakeJob\""
json mustMatch "\"a\":1"
json mustMatch "\"error_count\":0"
@@ -64,7 +64,7 @@ class JsonJobParserSpec extends ConfiguredSpecification with JMocker with ClassM
"JsonNestedJob" in {
val nestedJob = new JsonNestedJob(List(job))
- val json = new String(nestedJob.toJson, "UTF-8")
+ val json = nestedJob.toJson
json mustMatch "\"com.twitter.gizzard.scheduler.JsonNestedJob\":\\{"
json mustMatch "\"error_count\":0"
@@ -76,7 +76,7 @@ class JsonJobParserSpec extends ConfiguredSpecification with JMocker with ClassM
job.errorCount = 23
job.errorMessage = "Good heavens!"
- val json = new String(job.toJson, "UTF-8")
+ val json = job.toJson
json mustMatch "\\{\"FakeJob\":\\{"
json mustMatch "\"a\":1"
json mustMatch "\"error_count\":23"
View
10 src/test/scala/com/twitter/gizzard/scheduler_new/ReplicatingJobSpec.scala
@@ -13,9 +13,9 @@ class ReplicatingJobSpec extends ConfiguredSpecification with JMocker with Class
"toMap" in {
expect {
- one(job1).toJson willReturn """{"foo":"bar"}""".getBytes("UTF-8")
- one(job1).className willReturn testJsonJobClass
- one(job1).toMap willReturn Map[String, Any]()
+ one(job1).toJsonBytes willReturn """{"foo":"bar"}""".getBytes("UTF-8")
+ one(job1).className willReturn testJsonJobClass
+ one(job1).toMap willReturn Map[String, Any]()
}
val job = new ReplicatingJob(relay, Array(job1), List("c1"))
@@ -31,7 +31,7 @@ class ReplicatingJobSpec extends ConfiguredSpecification with JMocker with Class
val json = """{"foo":"bar"}""".getBytes("UTF-8")
expect {
- one(job1).toJson willReturn json
+ one(job1).toJsonBytes willReturn json
}
val job = new ReplicatingJob(relay, List(job1), List("c1"))
@@ -48,7 +48,7 @@ class ReplicatingJobSpec extends ConfiguredSpecification with JMocker with Class
"not replicate when list of clusters is empty" in {
expect {
- one(job1).toJson willReturn """{"foo":"bar"}""".getBytes("UTF-8")
+ one(job1).toJsonBytes willReturn """{"foo":"bar"}""".getBytes("UTF-8")
one(job1).apply()
}
Please sign in to comment.
Something went wrong with that request. Please try again.