Skip to content

Commit

Permalink
Separate h2o.jar from h2o R package except for developer build number…
Browse files Browse the repository at this point in the history
… 99999. For official releases, the user must obtain h2o.jar separately from our S3 site and place it in the correct R subdirectory listed in the h2o.init.Rd docs. The method h2o.init will attempt to do this automatically if it cannot find the file when the user tries to initialize H2O locally.
  • Loading branch information
anqi committed Apr 29, 2014
1 parent 91f1d55 commit f9f76a2
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 24 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ build:
@echo
@echo "PHASE: Building R package..."
@echo
$(MAKE) -C R PROJECT_VERSION=$(PROJECT_VERSION) 1> target/logs/r_build.log
$(MAKE) -C R PROJECT_VERSION=$(PROJECT_VERSION) BUILD_NUMBER=$(BUILD_NUMBER) 1> target/logs/r_build.log

@echo
@echo "PHASE: Building zip package..."
Expand Down
23 changes: 14 additions & 9 deletions R/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

PROJECT_VERSION ?= 99.70
BUILD_NUMBER ?= 99999
BUILD_BRANCH = $(shell git branch | grep '*' | sed 's/* //')
R_VERSION = 3.1
REPO_PATH_WIN = bin/windows/contrib/$(R_VERSION)
Expand Down Expand Up @@ -46,15 +47,19 @@ else
cp -p h2o_package.pdf ../target/R
endif
rm -rf h2o-package/inst/java
mkdir -p h2o-package/inst/java/tmp
cp -f ../target/h2o.jar h2o-package/inst/java/tmp/h2o_full.jar
(cd h2o-package/inst/java/tmp && jar xf h2o_full.jar)
(cd h2o-package/inst/java/tmp && rm -fr hadoop/0.* hadoop/1.* hadoop/cdh[35]* hadoop/cdh4_yarn)
(cd h2o-package/inst/java/tmp && rm -f h2o_full.jar)
(cd h2o-package/inst/java/tmp && cp META-INF/MANIFEST.MF ..)
(cd h2o-package/inst/java/tmp && rm -fr META-INF)
(cd h2o-package/inst/java/tmp && jar cfm ../h2o.jar ../MANIFEST.MF *)
rm -rf h2o-package/inst/java/tmp
# mkdir -p h2o-package/inst/java/tmp
# cp -f ../target/h2o.jar h2o-package/inst/java/tmp/h2o_full.jar
# (cd h2o-package/inst/java/tmp && jar xf h2o_full.jar)
# (cd h2o-package/inst/java/tmp && rm -fr hadoop/0.* hadoop/1.* hadoop/cdh[35]* hadoop/cdh4_yarn)
# (cd h2o-package/inst/java/tmp && rm -f h2o_full.jar)
# (cd h2o-package/inst/java/tmp && cp META-INF/MANIFEST.MF ..)
# (cd h2o-package/inst/java/tmp && rm -fr META-INF)
# (cd h2o-package/inst/java/tmp && jar cfm ../h2o.jar ../MANIFEST.MF *)
# rm -rf h2o-package/inst/java/tmp
mkdir -p h2o-package/inst/java
ifeq ($(BUILD_NUMBER),99999)
cp -f ../target/h2o.jar h2o-package/inst/java
endif
R CMD build h2o-package

# Create file with description of all packages
Expand Down
33 changes: 23 additions & 10 deletions R/h2o-package/R/Wrapper.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# 1) If can't connect and user doesn't want to start H2O, stop immediately
# 2) If user does want to start H2O and running locally, attempt to bring up H2O launcher
# 3) If user does want to start H2O, but running non-locally, print an error
h2o.init <- function(ip = "127.0.0.1", port = 54321, startH2O = TRUE, Xmx = "1g", beta = FALSE) {
h2o.init <- function(ip = "127.0.0.1", port = 54321, startH2O = TRUE, forceDL = FALSE, Xmx = "1g", beta = FALSE) {
if(!is.character(ip)) stop("ip must be of class character")
if(!is.numeric(port)) stop("port must be of class numeric")
if(!is.logical(startH2O)) stop("startH2O must be of class logical")
Expand All @@ -16,7 +16,7 @@ h2o.init <- function(ip = "127.0.0.1", port = 54321, startH2O = TRUE, Xmx = "1g"
stop(paste("Cannot connect to H2O server. Please check that H2O is running at", myURL))
else if(ip == "localhost" || ip == "127.0.0.1") {
cat("\nH2O is not running yet, starting it now...\n")
.h2o.startJar(Xmx, beta)
.h2o.startJar(Xmx, beta, forceDL)
count = 0; while(!url.exists(myURL) && count < 60) { Sys.sleep(1); count = count + 1 }
if(!url.exists(myURL)) stop("H2O failed to start, stopping execution.")
} else stop("Can only start H2O launcher if IP address is localhost.")
Expand Down Expand Up @@ -158,7 +158,7 @@ h2o.clusterStatus <- function(client) {
# h2o.shutdown(new("H2OClient", ip=ip, port=port), FALSE)
# }

.h2o.startJar <- function(memory = "1g", beta = FALSE) {
.h2o.startJar <- function(memory = "1g", beta = FALSE, forceDL = FALSE) {
command <- .h2o.checkJava()

#
Expand All @@ -185,7 +185,8 @@ h2o.clusterStatus <- function(client) {
stderr <- paste("/tmp/h2o", usr, "started_from_r.err", sep="_")
}

jar_file <- paste(.h2o.pkg.path, "java", "h2o.jar", sep = .Platform$file.sep)
# jar_file <- paste(.h2o.pkg.path, "java", "h2o.jar", sep = .Platform$file.sep)
jar_file <- .h2o.downloadJar(overwrite = forceDL)
jar_file <- paste('"', jar_file, '"', sep = "")
args <- c(paste("-Xms", memory, sep=""),
paste("-Xmx", memory, sep=""),
Expand Down Expand Up @@ -246,14 +247,26 @@ h2o.clusterStatus <- function(client) {
stop("Cannot find Java. Please install the latest JDK from http://www.oracle.com/technetwork/java/javase/downloads/index.html")
}

.h2o.downloadJar <- function(branch = "rel-kahan", version) {
if(missing(version))
version <- packageVersion("h2o")[1,4]
dest_file <- paste(.h2o.pkg.path, "java", "h2o.jar", sep = .Platform$file.sep)
if(!file.exists(dest_file)) {
if(version == '99999') stop("Cannot find ", dest_file, "\nPlease check that Makefile copied the jar correctly.")
.h2o.downloadJar <- function(branch, version, overwrite = FALSE) {
dest_folder <- paste(.h2o.pkg.path, "java", sep = .Platform$file.sep)
if(!file.exists(dest_folder)) dir.create(dest_folder)
dest_file <- paste(dest_folder, "h2o.jar", sep = .Platform$file.sep)

# Download if h2o.jar doesn't already exist or user specifies force overwrite
if(overwrite || !file.exists(dest_file)) {
if(missing(branch)) branch <- packageDescription("h2o")$Branch
if(missing(version)) version <- packageVersion("h2o")[1,4]

# Production version must exist on local drive
if(version == '99999' && !file.exists(dest_file))
stop("Cannot find ", dest_file, "\nPlease check that Makefile copied the jar correctly.")

h2o_url <- paste("http://s3.amazonaws.com/h2o-release/h2o", branch, version, "h2o.jar", sep = "/")
download.file(h2o_url, dest_file, mode = "wb")

# TODO: Check file integrity to ensure download okay
if(!file.exists(dest_file))
stop("Error: Transfer failed. Please download ", h2o_url, " and place h2o.jar in ", dest_folder)
}
return(dest_file)
}
Expand Down
14 changes: 10 additions & 4 deletions R/h2o-package/man/h2o.init.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,26 @@
\description{
Connects to a running H2O instance and checks the local H2O R package is the correct version (i.e. that the version of the R package and the version of H2O are the same).}
\usage{
h2o.init(ip = "127.0.0.1", port = 54321, startH2O = TRUE, Xmx = "1g", beta = FALSE)}
h2o.init(ip = "127.0.0.1", port = 54321, startH2O = TRUE, forceDL = FALSE, Xmx = "1g",
beta = FALSE)}

\arguments{
\item{ip}{Object of class \code{"character"} representing the IP address of the server where H2O is running.}
\item{port}{Object of class \code{"numeric"} representing the port number of the H2O server.}
\item{startH2O}{ (Optional) A logical value indicating whether to start the H2O launcher GUI if no connection with H2O is detected. This is only possible if H2O was installed from the InstallBuilder executable and \code{ip = "localhost"} or \code{ip = "127.0.0.1"}.}
\item{startH2O}{(Optional) A logical value indicating whether to start the H2O launcher GUI if no connection with H2O is detected. This is only possible if \code{ip = "localhost"} or \code{ip = "127.0.0.1"}.}
\item{forceDL}{(Optional) A logical value indicating whether to force download of the H2O executable. Defaults to FALSE, so the executable will only be downloaded if it does not already exist in the h2o R library resources directory \code{h2o/java/h2o.jar}.}
\item{Xmx}{(Optional) A string specifying the maximum size, in bytes, of the memory allocation pool to H2O. This value must a multiple of 1024 greater than 2MB. Append the letter m or M to indicate megabytes, or g or G to indicate gigabytes.}
\item{beta}{(Optional) A logical value indicating whether H2O should be launch in beta mode.}
}
\details{
This method first checks if H2O is connectable. If it cannot connect and \code{startH2O = TRUE} with IP of localhost, it will attempt to start an instance of H2O with IP = localhost, port = 54321. Otherwise, it stops immediately with an error. Once connected, the method checks to see if the local H2O R package version matches the version of H2O running on the server. If there is a mismatch and the user indicates she wishes to upgrade, it will remove the local H2O R package and download/install the H2O R package from the server.
This method first checks if H2O is connectable. If it cannot connect and \code{startH2O = TRUE} with IP of localhost, it will attempt to start an instance of H2O with IP = localhost, port = 54321. Otherwise, it stops immediately with an error.

When initializing H2O locally, this method searches for h2o.jar in the R library resources (\code{system.file("java", "h2o.jar", package = "h2o")}), and if the file does not exist, it will automatically attempt to download the correct version from Amazon S3. The user must have Internet access for this process to be successful.

Once connected, the method checks to see if the local H2O R package version matches the version of H2O running on the server. If there is a mismatch and the user indicates she wishes to upgrade, it will remove the local H2O R package and download/install the H2O R package from the server.
}
\value{
Once the package is successfully installed, this method will load it and return a \code{H2OClient} object containing the IP address and port number of the H2O server. See the \href{http://docs.0xdata.com/userguide/topR.html}{H2O R package documentation} for more details, or type \code{??h2o}.
Once the package is successfully installed, this method will load it and return a \code{H2OClient} object containing the IP address and port number of the H2O server. See the \href{http://docs.0xdata.com/userguide/topR.html}{H2O R package documentation} for more details, or type \code{??h2o} in the R console.
}
\note{ Users may wish to manually upgrade their package (rather than waiting
until being prompted), which requires that they fully uninstall and reinstall
Expand Down

0 comments on commit f9f76a2

Please sign in to comment.