aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuciano Resende <lresende@apache.org>2017-01-26 22:44:32 -0800
committerLuciano Resende <lresende@apache.org>2017-01-26 22:46:12 -0800
commite4b5e763f7f8e5d708c1e4f02f0e2b73dc077189 (patch)
tree67c703681a9742c3078e32917b239d46d3851eb3
parent0f3544a894a507b18cad857dabe68c1cd8b9215a (diff)
downloadtoree-gateway-config.tar.gz
toree-gateway-config.tar.bz2
toree-gateway-config.zip
Externalize the evaluation timeout configuration to properties fileconfig
-rw-r--r--src/main/scala/org/apache/toree/gateway/Config.scala66
-rw-r--r--src/main/scala/org/apache/toree/gateway/ToreeGateway.scala15
2 files changed, 76 insertions, 5 deletions
diff --git a/src/main/scala/org/apache/toree/gateway/Config.scala b/src/main/scala/org/apache/toree/gateway/Config.scala
new file mode 100644
index 0000000..cfce60d
--- /dev/null
+++ b/src/main/scala/org/apache/toree/gateway/Config.scala
@@ -0,0 +1,66 @@
+/*
+ * (C) Copyright IBM Corp. 2017
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.toree.gateway
+
+import java.io.{FileInputStream, InputStream}
+import java.nio.file.{Files, Path, Paths}
+import java.util.Properties
+
+object Config {
+ val CONFIG_FILE = "toree-gateway.properties"
+ var properties = new Properties()
+
+ // initialization
+ {
+ var home: String = ""
+ scala.util.control.Exception.ignoring(classOf[java.util.NoSuchElementException]) {
+ home = sys.env("TOREE_GATEWAY_HOME")
+ }
+ var configPath: Path = Paths.get(home + "/conf/" + CONFIG_FILE)
+ if (Files.exists(configPath) == false) {
+ configPath = Paths.get(getClass.getResource("/"+ CONFIG_FILE).getPath)
+ }
+ this.properties.load(new FileInputStream(configPath.toString))
+ }
+
+
+ def get(key: String): String = {
+ return this.properties.getProperty(key)
+ }
+
+ def getOrElse(key:String, default:String): String = {
+ val value = get(key)
+ if(value == null || value.isEmpty) {
+ return default
+ } else {
+ return value
+ }
+ }
+
+ def getAsInt(key: String): Int = {
+ return this.properties.getProperty(key).toInt
+ }
+
+ def getOrElseAsInt(key:String, default:Int): Int = {
+ val value = get(key)
+ if(value == null || value.isEmpty) {
+ return default
+ } else {
+ return value.toInt
+ }
+ }
+} \ No newline at end of file
diff --git a/src/main/scala/org/apache/toree/gateway/ToreeGateway.scala b/src/main/scala/org/apache/toree/gateway/ToreeGateway.scala
index e251ee1..1cac021 100644
--- a/src/main/scala/org/apache/toree/gateway/ToreeGateway.scala
+++ b/src/main/scala/org/apache/toree/gateway/ToreeGateway.scala
@@ -34,11 +34,9 @@ import org.slf4j.{Logger, LoggerFactory}
import play.api.libs.json._
-import scala.util.Try
-
class ToreeGateway(client: SparkKernelClient) {
final val log = LoggerFactory.getLogger(this.getClass.getName.stripSuffix("$"))
-
+ val configManager = Config
private def handleResult(promise:Promise[String], result: ExecuteResult) = {
log.info(s"Result was: ${result.data(MIMEType.PlainText)}")
@@ -61,8 +59,15 @@ class ToreeGateway(client: SparkKernelClient) {
promise.success(content.text)
}
- val ResponseTimeout = 1.seconds
- val EvalTimeout = Duration.Inf // 10.seconds
+ val ResponseTimeout: FiniteDuration = 1.seconds
+ val EvalTimeout: Duration = {
+ val timeout = configManager.getOrElse("toree.eval-timeout", "Inf")
+ if( "Inf".equalsIgnoreCase("Inf")) {
+ Duration("Inf")
+ } else {
+ Duration(timeout + " seconds")
+ }
+ } // 10.seconds
private def recoverTimeout[A](future: Future[A], timeout: FiniteDuration, default: A): Future[A] = try {
Await.ready(future, timeout)