Community Articles
Find and share helpful community-sourced technical articles.
Labels (2)

1. Introduction

This article is an extension of the one created by @Dan Zaratsian - H2O on Livy

2. Environment Details

Here are the environment details I did test it:

HDP: 2.6.1


OS: 7.3.1611

python: 2.7.5

IMPORTANT NOTE: H2O requires python ver. 2.7+

3. Installing H2O

Go to Zeppelin node and do the following:

$ mkdir /tmp/H2O
$ cd /tmp/H2O
$ wget
$ unzip

4. Testing H2O from CLI

Go to Zeppelin node where you downloaded and installed H2O

$ export SPARK_HOME='/usr/hdp/current/spark2-client'
$ export HADOOP_CONF_DIR=/etc/hadoop/conf
$ export MASTER="yarn-client"
$ cd /tmp/H2O/sparkling-water-2.1.16/bin
$ ./pysparkling
>>> from pysparkling import *
>>> hc = H2OContext.getOrCreate(spark)

My test

[root@dkozlowski-dkhdp262 bin]# ./pysparkling
Python 2.7.5 (default, Jun 17 2014, 18:11:42)
[GCC 4.8.2 20140120 (Red Hat 4.8.2-16)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Warning: Master yarn-client is deprecated since 2.0. Please use master "yarn" with specified deploy mode instead.
Setting default log level to "WARN".
To adjust logging level use sc.setLogLevel(newLevel). For SparkR, use setLogLevel(newLevel).
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/usr/hdp/!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/usr/hdp/!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]
17/11/08 14:33:06 WARN HiveConf: HiveConf of name hive.llap.daemon.service.hosts does not exist
17/11/08 14:33:06 WARN HiveConf: HiveConf of name hive.llap.daemon.service.hosts does not exist
Welcome to
      ____              __
     / __/__  ___ _____/ /__
    _\ \/ _ \/ _ `/ __/  '_/
   /__ / .__/\_,_/_/ /_/\_\   version

Using Python version 2.7.5 (default, Jun 17 2014 18:11:42)
SparkSession available as 'spark'.
>>> from pysparkling import *
>>> hc = H2OContext.getOrCreate(spark)
17/11/08 14:33:57 WARN H2OContext: Method H2OContext.getOrCreate with an argument of type SparkContext is deprecated and parameter of type SparkSession is preferred.
17/11/08 14:33:57 WARN InternalH2OBackend: Increasing 'spark.locality.wait' to value 30000
17/11/08 14:33:57 WARN InternalH2OBackend: Due to non-deterministic behavior of Spark broadcast-based joins
We recommend to disable them by
configuring `spark.sql.autoBroadcastJoinThreshold` variable to value `-1`:
sqlContext.sql("SET spark.sql.autoBroadcastJoinThreshold=-1")
17/11/08 14:33:57 WARN InternalH2OBackend: The property 'spark.scheduler.minRegisteredResourcesRatio' is not specified!
We recommend to pass `--conf spark.scheduler.minRegisteredResourcesRatio=1`
Connecting to H2O server at successful.
--------------------------  ---------------------------------------------------
H2O cluster uptime:         25 secs
H2O cluster version:
H2O cluster version age:    18 days
H2O cluster name:           sparkling-water-root_application_1507531306616_0032
H2O cluster total nodes:    2
H2O cluster free memory:    1.693 Gb
H2O cluster total cores:    8
H2O cluster allowed cores:  8
H2O cluster status:         accepting new members, healthy
H2O connection url:
H2O connection proxy:
H2O internal security:      False
H2O API Extensions:         XGBoost, Algos, AutoML, Core V3, Core V4
Python version:             2.7.5 final
--------------------------  ---------------------------------------------------

Sparkling Water Context:
 * H2O name: sparkling-water-root_application_1507531306616_0032
 * cluster size: 2
 * list of used nodes:
  (executorId, host, port)

  Open H2O Flow in browser: (CMD + click in Mac OSX)

5. Zeppelin site

Before following up the below steps ensure point 4. Testing H2O from CLI runs successfully

a) Ambari UI

Ambari -> Zeppelin -> Configs -> Advanced zeppelin-env -> zeppelin_env_template

export SPARK_SUBMIT_OPTIONS="--files /tmp/H2O/sparkling-water-2.1.16/py/build/dist/" 
export PYTHONPATH="/tmp/H2O/sparkling-water-2.1.16/py/build/dist/${SPARK_HOME}/python:${SPARK_HOME}/python/lib/" 

b) Zeppelin UI

Zeppelin UI -> Interpreter -> Spark2 (H2O does not work with dynamicAllocation enabled)


c) Sample code

from pysparkling import *
hc = H2OContext.getOrCreate(spark)


import h2o
from h2o.estimators.gbm import H2OGradientBoostingEstimator
from h2o.grid.grid_search import H2OGridSearch
import sys
sys.stdout.isatty = lambda : False
sys.stdout.encoding = None
training_data = h2o.import_file("hdfs://dkhdp261:8020/tmp/test1.csv")


; ;