Browse Source

Fix packaging, REPL.

After some directory renaming, the final package was missing some jars.
Also, the REPL was not working after changes were made to stop using
fat jars.

To fix the REPL, I'm using a similar approach to that used by the local
client: copy the needed REPL jars to a repl-specific directory, and add
all jars to the Spark application using "--jars". The list of jars can
be configured so that they can point at cached locations (e.g. local: or
hdfs:).

Since setup-classpath was not useful for the livy-repl script, I inlined
it into livy-server; in fact, the livy-repl script is not used anywhere,
so maybe we could remove it.
Marcelo Vanzin 9 years ago
parent
commit
20f8aea3db

+ 8 - 1
assembly/assembly.xml

@@ -34,11 +34,18 @@
       </includes>
     </fileSet>
     <fileSet>
-      <directory>${project.parent.basedir}/livy-client-local/target/jars</directory>
+      <directory>${project.parent.basedir}/client-local/target/jars</directory>
       <outputDirectory>${install.dir}/client-jars</outputDirectory>
       <includes>
         <include>*</include>
       </includes>
     </fileSet>
+    <fileSet>
+      <directory>${project.parent.basedir}/repl/target/jars</directory>
+      <outputDirectory>${install.dir}/repl-jars</outputDirectory>
+      <includes>
+        <include>*</include>
+      </includes>
+    </fileSet>
   </fileSets>
 </assembly>

+ 0 - 6
assembly/pom.xml

@@ -36,12 +36,6 @@
 
   <dependencies>
 
-    <dependency>
-      <groupId>${project.groupId}</groupId>
-      <artifactId>livy-client-local_${scala.binary.version}</artifactId>
-      <version>${project.version}</version>
-    </dependency>
-
     <dependency>
       <groupId>${project.groupId}</groupId>
       <artifactId>livy-repl_${scala.binary.version}</artifactId>

+ 11 - 2
bin/livy-repl

@@ -29,10 +29,19 @@ else
 	SPARK_SUBMIT=spark-submit
 fi
 
-source ./bin/setup-classpath
+LIBDIR="$LIVY_HOME/repl-jars"
+if [ ! -d "$LIBDIR" ]; then
+  LIBDIR="$LIVY_HOME/repl/target/jars"
+fi
+if [ ! -d "$LIBDIR" ]; then
+  echo "Could not find Livy REPL jars directory." 1>&2
+  exit 1
+fi
 
+JARS=$(find $LIBDIR | paste -sd,)
 exec $SPARK_SUBMIT \
+  --jars "$JARS" \
 	--driver-java-options "$LIVY_REPL_JAVA_OPTS" \
 	--class com.cloudera.livy.repl.Main \
-	"$ASSEMBLY_JAR" \
+	"spark-internal" \
 	"$@"

+ 10 - 1
bin/livy-server

@@ -23,7 +23,16 @@ set -e
 export LIVY_HOME=$(cd $(dirname $0)/.. && pwd)
 cd $LIVY_HOME
 
-source ./bin/setup-classpath
+LIBDIR="$LIVY_HOME/jars"
+if [ ! -d "$LIBDIR" ]; then
+  LIBDIR="$LIVY_HOME/assembly/target/jars"
+fi
+if [ ! -d "$LIBDIR" ]; then
+  echo "Could not find Livy jars directory." 1>&2
+  exit 1
+fi
+
+CLASSPATH="$LIBDIR/*:$LIVY_HOME/conf:$CLASSPATH"
 
 exec java \
 	$LIVY_SERVER_JAVA_OPTS \

+ 0 - 28
bin/setup-classpath

@@ -1,28 +0,0 @@
-#!/usr/bin/env bash
-
-# Licensed to Cloudera, Inc. under one
-# or more contributor license agreements.  See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership.  Cloudera, Inc. licenses this file
-# to you 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.
-
-LIBDIR="$LIVY_HOME/jars"
-if [ ! -d "$LIBDIR" ]; then
-  LIBDIR="$LIVY_HOME/assembly/target/jars"
-fi
-if [ ! -d "$LIBDIR" ]; then
-  echo "Could not find Livy jars directory." 1>&2
-  exit 1
-fi
-
-CLASSPATH="$LIBDIR/*:$LIVY_HOME/conf:$CLASSPATH"

+ 0 - 6
core/pom.xml

@@ -37,12 +37,6 @@
       <artifactId>log4j</artifactId>
     </dependency>
 
-    <dependency>
-      <groupId>com.cloudera.livy</groupId>
-      <artifactId>livy-client-local_${scala.binary.version}</artifactId>
-      <version>${project.version}</version>
-    </dependency>
-
     <dependency>
       <groupId>javax.servlet</groupId>
       <artifactId>javax.servlet-api</artifactId>

+ 0 - 14
core/src/main/scala/com/cloudera/livy/Utils.scala

@@ -74,20 +74,6 @@ object Utils {
     }
   }
 
-  def jarOfClass(cls: Class[_]): Option[String] = {
-    val uri = cls.getResource("/" + cls.getName.replace('.', '/') + ".class")
-    if (uri != null) {
-      val uriStr = uri.toString
-      if (uriStr.startsWith("jar:file:")) {
-        Some(uriStr.substring("jar:file:".length, uriStr.indexOf("!")))
-      } else {
-        None
-      }
-    } else {
-      None
-    }
-  }
-
   /**
    * Checks if event has occurred during some time period. This performs an exponential backoff
    * to limit the poll calls.

+ 35 - 0
repl/pom.xml

@@ -42,6 +42,7 @@
         <dependency>
             <groupId>com.fasterxml.jackson.core</groupId>
             <artifactId>jackson-core</artifactId>
+            <scope>provided</scope>
         </dependency>
 
         <dependency>
@@ -53,6 +54,7 @@
         <dependency>
             <groupId>com.fasterxml.jackson.core</groupId>
             <artifactId>jackson-databind</artifactId>
+            <scope>provided</scope>
         </dependency>
 
         <dependency>
@@ -63,6 +65,13 @@
         <dependency>
             <groupId>javax.servlet</groupId>
             <artifactId>javax.servlet-api</artifactId>
+            <scope>provided</scope>
+        </dependency>
+
+        <dependency>
+          <groupId>log4j</groupId>
+          <artifactId>log4j</artifactId>
+          <scope>provided</scope>
         </dependency>
 
         <dependency>
@@ -112,16 +121,19 @@
         <dependency>
             <groupId>org.json4s</groupId>
             <artifactId>json4s-ast_${scala.binary.version}</artifactId>
+            <scope>provided</scope>
         </dependency>
 
         <dependency>
             <groupId>org.json4s</groupId>
             <artifactId>json4s-core_${scala.binary.version}</artifactId>
+            <scope>provided</scope>
         </dependency>
 
         <dependency>
             <groupId>org.json4s</groupId>
             <artifactId>json4s-jackson_${scala.binary.version}</artifactId>
+            <scope>provided</scope>
         </dependency>
 
         <dependency>
@@ -161,6 +173,7 @@
         <dependency>
             <groupId>org.slf4j</groupId>
             <artifactId>slf4j-api</artifactId>
+            <scope>provided</scope>
         </dependency>
 
         <dependency>
@@ -184,6 +197,27 @@
 
     <build>
         <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-dependency-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <id>copy-dependencies</id>
+                        <phase>package</phase>
+                        <goals>
+                            <goal>copy-dependencies</goal>
+                        </goals>
+                        <configuration>
+                            <outputDirectory>${project.build.directory}/jars</outputDirectory>
+                            <useSubDirectoryPerType>false</useSubDirectoryPerType>
+                            <includeScope>runtime</includeScope>
+                            <silent>true</silent>
+                            <overWriteReleases>true</overWriteReleases>
+                            <overWriteSnapshots>true</overWriteSnapshots>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
 
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
@@ -194,6 +228,7 @@
                             <mainClass>com.cloudera.livy.repl.Main</mainClass>
                         </manifest>
                     </archive>
+                    <outputDirectory>${project.build.directory}/jars</outputDirectory>
                 </configuration>
             </plugin>
 

+ 6 - 0
spark/pom.xml

@@ -33,6 +33,12 @@
 
   <dependencies>
 
+    <dependency>
+      <groupId>com.cloudera.livy</groupId>
+      <artifactId>livy-client-local_${scala.binary.version}</artifactId>
+      <version>${project.version}</version>
+    </dependency>
+
     <dependency>
       <groupId>com.cloudera.livy</groupId>
       <artifactId>livy-core_${scala.binary.version}</artifactId>

+ 2 - 2
spark/src/main/scala/com/cloudera/livy/spark/SparkProcessBuilder.scala

@@ -219,7 +219,7 @@ class SparkProcessBuilder(livyConf: LivyConf, userConfigurableOptions: Set[Strin
     this
   }
 
-  def start(file: Path, args: Traversable[String]): SparkProcess = {
+  def start(file: Option[Path], args: Traversable[String]): SparkProcess = {
     var arguments = ArrayBuffer(fromPath(_executable))
 
     def addOpt(option: String, value: Option[String]): Unit = {
@@ -256,7 +256,7 @@ class SparkProcessBuilder(livyConf: LivyConf, userConfigurableOptions: Set[Strin
     addOpt("--queue", _queue)
     addList("--archives", _archives.map(fromPath))
 
-    arguments += fromPath(file)
+    arguments += file.map(fromPath).getOrElse("spark-internal")
     arguments ++= args
 
     val argsString = arguments

+ 1 - 1
spark/src/main/scala/com/cloudera/livy/spark/batch/BatchSessionFactory.scala

@@ -32,7 +32,7 @@ abstract class BatchSessionFactory(factory: SparkProcessBuilderFactory) extends
 
   def create(id: Int, request: CreateBatchRequest): BatchSession = {
     val builder = sparkBuilder(request)
-    val process = builder.start(RelativePath(request.file), request.args)
+    val process = builder.start(Some(RelativePath(request.file)), request.args)
     create(id, process)
   }
 

+ 24 - 13
spark/src/main/scala/com/cloudera/livy/spark/interactive/InteractiveSessionFactory.scala

@@ -22,6 +22,8 @@ import java.io.File
 import java.lang.ProcessBuilder.Redirect
 import java.nio.file.{Paths, Files}
 
+import scala.collection.JavaConverters._
+
 import com.cloudera.livy.sessions.interactive.InteractiveSession
 import com.cloudera.livy.sessions.{PySpark, SessionFactory, SessionKindSerializer}
 import com.cloudera.livy.spark.SparkProcessBuilder.{AbsolutePath, RelativePath}
@@ -30,14 +32,14 @@ import com.cloudera.livy.{LivyConf, Utils}
 import org.json4s.{DefaultFormats, Formats, JValue}
 
 object InteractiveSessionFactory {
-  private val LivyReplDriverClassPath = "livy.repl.driverClassPath"
-  private val LivyReplJar = "livy.repl.jar"
-  private val LivyServerUrl = "livy.server.serverUrl"
-  private val SparkDriverExtraJavaOptions = "spark.driver.extraJavaOptions"
-  private val SparkLivyCallbackUrl = "spark.livy.callbackUrl"
-  private val SparkLivyPort = "spark.livy.port"
-  private val SparkSubmitPyFiles = "spark.submit.pyFiles"
-  private val SparkYarnIsPython = "spark.yarn.isPython"
+  val LivyReplDriverClassPath = "livy.repl.driverClassPath"
+  val LivyReplJars = "livy.repl.jars"
+  val LivyServerUrl = "livy.server.serverUrl"
+  val SparkDriverExtraJavaOptions = "spark.driver.extraJavaOptions"
+  val SparkLivyCallbackUrl = "spark.livy.callbackUrl"
+  val SparkLivyPort = "spark.livy.port"
+  val SparkSubmitPyFiles = "spark.submit.pyFiles"
+  val SparkYarnIsPython = "spark.yarn.isPython"
 }
 
 abstract class InteractiveSessionFactory(processFactory: SparkProcessBuilderFactory)
@@ -53,7 +55,7 @@ abstract class InteractiveSessionFactory(processFactory: SparkProcessBuilderFact
   def create(id: Int, request: CreateInteractiveRequest): InteractiveSession = {
     val builder = sparkBuilder(id, request)
     val kind = request.kind.toString
-    val process = builder.start(AbsolutePath(livyJar(processFactory.livyConf)), List(kind))
+    val process = builder.start(None, List(kind))
 
     create(id, process, request)
   }
@@ -72,7 +74,10 @@ abstract class InteractiveSessionFactory(processFactory: SparkProcessBuilderFact
     request.executorMemory.foreach(builder.executorMemory)
     request.numExecutors.foreach(builder.numExecutors)
     request.files.map(RelativePath).foreach(builder.file)
-    request.jars.map(RelativePath).foreach(builder.jar)
+
+    val jars = request.jars.map(RelativePath) ++ livyJars(processFactory.livyConf).map(RelativePath)
+    jars.foreach(builder.jar)
+
     request.proxyUser.foreach(builder.proxyUser)
     request.queue.foreach(builder.queue)
     request.name.foreach(builder.name)
@@ -120,9 +125,15 @@ abstract class InteractiveSessionFactory(processFactory: SparkProcessBuilderFact
     builder
   }
 
-  private def livyJar(livyConf: LivyConf) = {
-    livyConf.getOption(LivyReplJar)
-      .getOrElse(Utils.jarOfClass(getClass).head)
+  private def livyJars(livyConf: LivyConf): Seq[String] = {
+    livyConf.getOption(LivyReplJars).map(_.split(",").toSeq).getOrElse {
+      val home = sys.env("LIVY_HOME")
+      val jars = Option(new File(home, "repl-jars"))
+        .filter(_.isDirectory())
+        .getOrElse(new File(home, "repl/target/jars"))
+      require(jars.isDirectory(), "Cannot find Livy REPL jars.")
+      jars.listFiles().map(_.getAbsolutePath()).toSeq
+    }
   }
 
   private def findPySparkArchives(): Seq[String] = {

+ 1 - 0
spark/src/test/scala/com/cloudera/livy/spark/interactive/InteractiveSessionProcessSpec.scala

@@ -27,6 +27,7 @@ class InteractiveSessionProcessSpec extends BaseInteractiveSessionSpec {
 
   val livyConf = new LivyConf()
   livyConf.set("livy.repl.driverClassPath", sys.props("java.class.path"))
+  livyConf.set(InteractiveSessionFactory.LivyReplJars, "")
 
   def createSession() = {
     assume(sys.env.get("SPARK_HOME").isDefined, "SPARK_HOME is not set.")