Browse Source

using DBHOST for database instead of hardcoding to localhost

David Denton 8 years ago
parent
commit
ced53a0912

+ 12 - 9
frameworks/Scala/fintrospect/src/main/scala/Database.scala

@@ -5,15 +5,18 @@ import com.twitter.finagle.stats.NullStatsReceiver
 import com.twitter.finagle.tracing.NullTracer
 import com.twitter.util.Duration.fromSeconds
 import com.twitter.util.NullMonitor
+import io.fintrospect.configuration.Host
 
 object Database {
-  def apply(): Client = Mysql.client
-    .withCredentials("benchmarkdbuser", "benchmarkdbpass")
-    .withDatabase("hello_world")
-    .configured(Param(low = 0, high = 10, idleTime = fromSeconds(5 * 60), bufferSize = 0, maxWaiters = Int.MaxValue))
-    .withStatsReceiver(NullStatsReceiver)
-    .withMonitor(NullMonitor)
-    .withTracer(NullTracer)
-    .withMaxConcurrentPrepareStatements(256)
-    .newRichClient("localhost:3306")
+  def apply(dbHost: Host): Client = {
+    Mysql.client
+      .withCredentials("benchmarkdbuser", "benchmarkdbpass")
+      .withDatabase("hello_world")
+      .configured(Param(low = 0, high = 10, idleTime = fromSeconds(5 * 60), bufferSize = 0, maxWaiters = Int.MaxValue))
+      .withStatsReceiver(NullStatsReceiver)
+      .withMonitor(NullMonitor)
+      .withTracer(NullTracer)
+      .withMaxConcurrentPrepareStatements(256)
+      .newRichClient(dbHost.value + ":3306")
+  }
 }

+ 6 - 2
frameworks/Scala/fintrospect/src/main/scala/FintrospectBenchmarkServer.scala

@@ -7,12 +7,15 @@ import com.twitter.finagle.tracing.NullTracer
 import com.twitter.finagle.{Filter, Http}
 import com.twitter.util.{Await, NullMonitor}
 import io.fintrospect.ModuleSpec
+import io.fintrospect.configuration.Host
 import io.fintrospect.renderers.simplejson.SimpleJson
 import org.apache.commons.lang.time.FastDateFormat.getInstance
 
+import scala.util.Properties
+
 object FintrospectBenchmarkServer extends App {
 
-  private val dateFormat = getInstance("EEE, dd MMM yyyy HH:mm:ss 'GMT'", getTimeZone("GMT"))
+  val dateFormat = getInstance("EEE, dd MMM yyyy HH:mm:ss 'GMT'", getTimeZone("GMT"))
 
   val addServerAndDate = Filter.mk[Request, Response, Request, Response] { (req, svc) =>
     svc(req).map(resp => {
@@ -22,7 +25,8 @@ object FintrospectBenchmarkServer extends App {
     })
   }
 
-  val database = Database()
+  val dbHost = Properties.envOrNone("DBHOST").map(Host(_)).getOrElse(Host.localhost)
+  val database = Database(dbHost)
 
   val module = ModuleSpec(Root, SimpleJson(), addServerAndDate)
     .withRoute(JsonRoute())