Skip to content

Commit

Permalink
Coded DonCorleoneUtils get_configuration in scala
Browse files Browse the repository at this point in the history
, #110 - took 2h because of reflection API in scala
  • Loading branch information
kudkudak committed Apr 18, 2014
1 parent ba6f822 commit 0dc6448
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 6 deletions.
3 changes: 3 additions & 0 deletions mantis_shrimp/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
Read wiki Deployment Installation -> Scala page

Make sure sbt is above 13.0 (`sbt --version`). SBT installation is easy - follow
setup documentation on scala-sbt

Run

`sbt update`
Expand Down
6 changes: 6 additions & 0 deletions mantis_shrimp/build.sbt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import sbt._
import sbt.Keys._


name := "mantis_shrimp"

version := "1.0"
Expand All @@ -6,6 +10,8 @@ scalaVersion := "2.10.2"

resolvers += "Typesafe Repository" at "http://repo.typesafe.com/typesafe/releases/"

libraryDependencies += "org.scala-sbt" % "sbt" % "0.13.1"

libraryDependencies += "com.typesafe.akka" % "akka-actor_2.10" % "2.2-M1"

libraryDependencies += "com.typesafe.akka" % "akka-actor_2.10" % "2.2-M1" classifier "javadoc"
Expand Down
1 change: 1 addition & 0 deletions mantis_shrimp/project/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sbt.version=0.13.1
34 changes: 29 additions & 5 deletions mantis_shrimp/src/main/scala/DonCorleoneUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,43 @@
*/

package mantis_shrimp
import rapture.core._
import rapture.json._
import rapture.fs._
import rapture.io._
import rapture.net._
import rapture.core._
import rapture.json._
import jsonParsers.scalaJson._

//SBT configuration to retrieve settings - for instance base directory
//Unfortunately I do not know how to get it to work (2h research..)
import sbt._

//Internal strategy for Rapture.io - I dont see this design choice..
import strategy.throwExceptions

import scala.reflect.Manifest
import scala.reflect.ClassTag

object DonCorleoneUtils extends App {
object DonCorleoneUtils{
implicit val enc = Encodings.`UTF-8`
val txt = (Http / "rapture.io" / "welcome.txt").slurp[Char]
println(txt)
//Not beautiful but works
val mantis_shrimp_dir = new java.io.File(".").getCanonicalPath
val config = JsonBuffer.parse((File / mantis_shrimp_dir / "../don_corleone" / "config.json").slurp[Char])
val don_url: String = if (config.master_local.as[Boolean]) config.master_local.as[String] else config.master.as[String]

/*
* @returns Configuration of service
* @note Abridged and simplified version of get_configuration from don_utils.py
*
*/
def get_configuration[T](service_name:String, config_name: String)(implicit m: scala.reflect.Manifest[T]): T={
val request_url = "get_configuration?service_name="+service_name+"&config_name="+config_name+"&node_id="+this.config.node_id.as[String]
println("Connecting to "+(this.don_url.replaceAll("http://","") / request_url).toString())
val value = JsonBuffer.parse((Http / this.don_url.replace("http://", "") / request_url).slurp[Char]).result
return value.asInstanceOf[T]
}

//Demo functions: TODO: convert to tests
println(get_configuration[String]("kafka","port"))
val txt = (Http / "rapture.io" / "welcome.txt").slurp[Char]
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import scala.util.parsing.json._
//Internal strategy for Rapture.io - I dont see this design choice..
import strategy.throwExceptions

object JsonTests extends App {
object Sandbox extends App {
def runTest(implicit parser: JsonBufferParser[String]){

val json_example = json""" {"ala":13, "beka":[1,2,"ala2"]} """
Expand Down

0 comments on commit 0dc6448

Please sign in to comment.