Skip to content

Commit

Permalink
release 1.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
tgpfeiffer committed Jun 29, 2015
1 parent e2b6ef4 commit 2ef682c
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 14 deletions.
20 changes: 20 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
*.class
*.log

# sbt specific
dist/*
target/
lib_managed/
src_managed/
project/boot/
project/plugins/project/

# Scala-IDE specific
.scala_dependencies
.idea

# emacs specific
*~

# auto-generated files
processor/start-script/run
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import com.typesafe.sbt.SbtStartScript

name := "JubaQL Client"

version := "1.2.0"
version := "1.3.0"

scalaVersion := "2.10.4"

Expand Down
21 changes: 21 additions & 0 deletions increase-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash

if [ $# -ne 1 ]; then
echo "Usage: increase-version.sh toversion"
exit 1
fi

OLDVERSION=$(grep "version := " build.sbt | sed 's/[^"]*"\([^"]*\).*/\1/')
NEWVERSION=$1

echo "Bumping version from $OLDVERSION to $NEWVERSION ..."

sed -i "s/$OLDVERSION/$NEWVERSION/g" build.sbt

sed -i "s/$OLDVERSION/$NEWVERSION/g" README.md

echo "Checking for old occurences of $OLDVERSION ..."

grep -F -R "$OLDVERSION" src
grep -F --directories=skip "$OLDVERSION" *

41 changes: 32 additions & 9 deletions src/main/scala/us/jubat/jubaql_client/JubaQLClient.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
package us.jubat.jubaql_client

import com.ning.http.client.Response
import dispatch._
import dispatch.Defaults._
import scopt.OptionParser
Expand All @@ -24,7 +25,7 @@ import java.io.{PrintStream, PrintWriter}
import jline.console.ConsoleReader
import java.nio.file.{Paths, Files}
import scala.io.Source
import org.json4s.JsonAST.JString
import org.json4s.JsonAST.{JNothing, JString}

object JubaQLClient {
/** Main function to start the JubaQL client shell.
Expand Down Expand Up @@ -82,6 +83,7 @@ object JubaQLClient {
// ask for commands and forward them to server
Console.err.println("Please enter your JubaQL commands. Type Ctrl+D or \"exit\" to quit.")
val reader = new ConsoleReader()
reader.setExpandEvents(false)
val output = new PrintWriter(reader.getOutput)
reader.setPrompt("jubaql> ")
var line = reader.readLine()
Expand Down Expand Up @@ -141,24 +143,33 @@ object JubaQLClient {
val url = :/(hostname, port) / "jubaql"
val payloadData = ("session_id" -> sessionId) ~ ("query" -> cmd)
val json: String = compact(render(payloadData))
val req = Http(url << json OK as.String)
req.either.apply() match {
case Left(error) =>
// if request fails or is non-2xx, print error
out.println("[ERROR] " + error.getCause + ": " + error.getMessage)
out.flush()
true
case Right(resultJson) =>
// create response handler
val printResponse: Response => Boolean = {
resp => {
val resultJson = resp.getResponseBody
// if we can parse JSON, print it nicely formatted;
// otherwise print an error
parseOpt(resultJson) match {
case Some(result) =>
if (resp.getStatusCode / 100 != 2) {
out.print("[ERROR/%s] ".format(resp.getStatusCode))
}
result \ "result" match {
case JString(status) if status == "STATUS" =>
out.println(status)
// print all but the "result" field
val withoutResult = result.removeField(_._1 == "result")
out.println(pretty(render(withoutResult)))
true
case JString(status) =>
out.println(status)
out.flush()
// return false if server shut down successfully
!status.startsWith("SHUTDOWN")
case JNothing =>
out.println("response did not contain a result")
out.flush()
true
case other =>
out.println(pretty(render(result \ "result")))
out.flush()
Expand All @@ -169,6 +180,18 @@ object JubaQLClient {
out.flush()
true
}
}
}
val req = Http(url << json > printResponse)
req.either.apply() match {
case Left(error) =>
// if request failed, print error
out.println("[ERROR] " + error.getCause + ": " + error.getMessage)
out.flush()
true
case Right(continue_?) =>
// if request succeeded, return the result of printResponse
continue_?
}
}

Expand Down
6 changes: 2 additions & 4 deletions src/test/scala/us/jubat/jubaql_client/SendCommandSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ class SendCommandSpec extends FlatSpec with Matchers with MockServer {
val mockPrintStream = new PrintStream(mockStdout)
JubaQLClient.handleCommand("localhost", 9877, "1234", "",
mockPrintStream)
mockStdout.toString should startWith(
"[ERROR] null: Unexpected response status: 400")
mockStdout.toString should startWith("[ERROR/400]")
}

"Sending a command with a valid session to a non-existing server" should
Expand Down Expand Up @@ -103,8 +102,7 @@ class SendCommandSpec extends FlatSpec with Matchers with MockServer {
val mockPrintStream = new PrintStream(mockStdout)
JubaQLClient.handleCommand("localhost", 9877, "123", "TRAIN jubatus",
mockPrintStream)
mockStdout.toString should startWith(
"[ERROR] null: Unexpected response status: 401")
mockStdout.toString should startWith("[ERROR/401]")
}

"Receiving invalid JSON" should "print an error" in {
Expand Down

0 comments on commit 2ef682c

Please sign in to comment.