From e4938cbd9bb7bf50e6ac241d8d00835ab0a6fece Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20H=C3=A1va?= Date: Thu, 16 Aug 2018 17:00:26 +0200 Subject: [PATCH] [SW-1005] Use correct scheme in sparkling water when ssl on flow is enabled (#905) --- .../main/scala/org/apache/spark/h2o/H2OContext.scala | 4 ++-- .../org/apache/spark/h2o/utils/H2OContextUtils.scala | 10 +++++++++- py/pysparkling/context.py | 11 ++++++----- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/core/src/main/scala/org/apache/spark/h2o/H2OContext.scala b/core/src/main/scala/org/apache/spark/h2o/H2OContext.scala index c723307b76..2563fe6e04 100644 --- a/core/src/main/scala/org/apache/spark/h2o/H2OContext.scala +++ b/core/src/main/scala/org/apache/spark/h2o/H2OContext.scala @@ -313,7 +313,7 @@ class H2OContext private(val sparkSession: SparkSession, conf: H2OConf) extends } /** Open H2O Flow running in this client. */ - def openFlow(): Unit = openURI(sparkContext, s"http://$h2oLocalClient") + def openFlow(): Unit = openURI(sparkContext, s"${getScheme(_conf)}://$h2oLocalClient") override def toString: String = { val basic = @@ -327,7 +327,7 @@ class H2OContext private(val sparkSession: SparkSession, conf: H2OConf) extends | ${h2oNodes.mkString("\n ")} | ------------------------ | - | Open H2O Flow in browser: http://$h2oLocalClient (CMD + click in Mac OSX) + | Open H2O Flow in browser: ${getScheme(_conf)}://$h2oLocalClient (CMD + click in Mac OSX) | """.stripMargin val sparkYarnAppId = if (sparkContext.master.toLowerCase.startsWith("yarn")) { diff --git a/core/src/main/scala/org/apache/spark/h2o/utils/H2OContextUtils.scala b/core/src/main/scala/org/apache/spark/h2o/utils/H2OContextUtils.scala index ae0169952e..3d87d41527 100644 --- a/core/src/main/scala/org/apache/spark/h2o/utils/H2OContextUtils.scala +++ b/core/src/main/scala/org/apache/spark/h2o/utils/H2OContextUtils.scala @@ -24,7 +24,7 @@ import java.util.Date import java.util.zip.{ZipEntry, ZipOutputStream} import org.apache.spark.SparkContext -import org.apache.spark.h2o.BuildInfo +import org.apache.spark.h2o.{BuildInfo, H2OConf} import org.apache.spark.internal.Logging import water.H2O import water.fvec.Frame @@ -53,6 +53,14 @@ private[spark] trait H2OContextUtils extends Logging { } } + def getScheme(hc: H2OConf) = { + if (hc.jks.isDefined && hc.jksPass.isDefined) { + "https" + } else { + "http" + } + } + /** * Return true if running inside spark/sparkling water test. * diff --git a/py/pysparkling/context.py b/py/pysparkling/context.py index 8aac31f7b0..033015f245 100644 --- a/py/pysparkling/context.py +++ b/py/pysparkling/context.py @@ -106,14 +106,15 @@ def __do_init(self, spark_session): self.is_initialized = False def __default_h2o_connect(h2o_context, **kwargs): + schema = h2o_context._jhc.h2oContext().getScheme(h2o_context._jhc.h2oContext()._conf()) + https = False + if schema == "https": + https = True if h2o_context._conf.context_path() is not None: - schema = "http" - if "https" in kwargs: - schema = "https" url = "{}://{}:{}/{}".format(schema, h2o_context._client_ip, h2o_context._client_port, h2o_context._conf.context_path()) - return h2o.connect(url=url, **kwargs) + return h2o.connect(url=url, https=https, **kwargs) else: - return h2o.connect(ip=h2o_context._client_ip, port=h2o_context._client_port, **kwargs) + return h2o.connect(ip=h2o_context._client_ip, port=h2o_context._client_port, https=https,**kwargs) @staticmethod