Skip to content

Commit eeb6d01

Browse files
jerryshaoalex-the-man
authored andcommitted
LIVY-228. Shade json4s and py4j in repl.
Version of dependencies are different between Spark 1 and Spark 2 (e.g. json4s, py4j). Shade them to make supporting multiple versions simultaneously easier. Closes #207
1 parent 9bf35a6 commit eeb6d01

File tree

3 files changed

+55
-9
lines changed

3 files changed

+55
-9
lines changed

pom.xml

-4
Original file line numberDiff line numberDiff line change
@@ -985,8 +985,6 @@
985985
</activation>
986986
<properties>
987987
<spark.version>1.6.2</spark.version>
988-
<py4j.version>0.9</py4j.version>
989-
<json4s.version>3.2.10</json4s.version>
990988
</properties>
991989
</profile>
992990

@@ -999,8 +997,6 @@
999997
</activation>
1000998
<properties>
1001999
<spark.version>2.0.0</spark.version>
1002-
<py4j.version>0.10.1</py4j.version>
1003-
<json4s.version>3.2.11</json4s.version>
10041000
</properties>
10051001
</profile>
10061002
</profiles>

repl/pom.xml

+49-3
Original file line numberDiff line numberDiff line change
@@ -116,19 +116,16 @@
116116
<dependency>
117117
<groupId>org.json4s</groupId>
118118
<artifactId>json4s-ast_${scala.binary.version}</artifactId>
119-
<scope>provided</scope>
120119
</dependency>
121120

122121
<dependency>
123122
<groupId>org.json4s</groupId>
124123
<artifactId>json4s-core_${scala.binary.version}</artifactId>
125-
<scope>provided</scope>
126124
</dependency>
127125

128126
<dependency>
129127
<groupId>org.json4s</groupId>
130128
<artifactId>json4s-jackson_${scala.binary.version}</artifactId>
131-
<scope>provided</scope>
132129
</dependency>
133130

134131
<dependency>
@@ -165,6 +162,46 @@
165162

166163
<build>
167164
<plugins>
165+
166+
<plugin>
167+
<groupId>org.apache.maven.plugins</groupId>
168+
<artifactId>maven-shade-plugin</artifactId>
169+
<executions>
170+
<execution>
171+
<id>shade</id>
172+
<phase>package</phase>
173+
<goals>
174+
<goal>shade</goal>
175+
</goals>
176+
<configuration>
177+
<shadedArtifactAttached>false</shadedArtifactAttached>
178+
<artifactSet>
179+
<includes>
180+
<include>org.json4s:json4s-ast_${scala.binary.version}</include>
181+
<include>org.json4s:json4s-core_${scala.binary.version}</include>
182+
<include>org.json4s:json4s-jackson_${scala.binary.version}</include>
183+
</includes>
184+
</artifactSet>
185+
<filters>
186+
<filter>
187+
<artifact>*:*</artifact>
188+
<excludes>
189+
<exclude>*.jar</exclude>
190+
<exclude>META-INF/maven/**</exclude>
191+
</excludes>
192+
</filter>
193+
</filters>
194+
<relocations>
195+
<relocation>
196+
<pattern>org.json4s</pattern>
197+
<shadedPattern>com.cloudera.livy.shaded.json4s</shadedPattern>
198+
</relocation>
199+
</relocations>
200+
</configuration>
201+
</execution>
202+
</executions>
203+
</plugin>
204+
168205
<plugin>
169206
<groupId>org.apache.maven.plugins</groupId>
170207
<artifactId>maven-dependency-plugin</artifactId>
@@ -174,6 +211,15 @@
174211
<goals>
175212
<goal>copy-dependencies</goal>
176213
</goals>
214+
<configuration>
215+
<excludeArtifactIds>
216+
json4s-ast_${scala.binary.version},
217+
json4s-core_${scala.binary.version},
218+
json4s-jackson_${scala.binary.version},
219+
paranamer,
220+
scalap
221+
</excludeArtifactIds>
222+
</configuration>
177223
</execution>
178224
</executions>
179225
</plugin>

repl/src/main/scala/com/cloudera/livy/repl/PythonInterpreter.scala

+6-2
Original file line numberDiff line numberDiff line change
@@ -276,9 +276,13 @@ private class PythonInterpreter(process: Process, gatewayServer: GatewayServer,
276276

277277
private def updatePythonGatewayPort(port: Int): Unit = {
278278
// The python gateway port can be 0 only when LivyConf.TEST_MODE is true
279+
// Py4j 0.10 has different API signature for "getCallbackClient", use reflection to handle it.
279280
if (port != 0) {
280-
val callbackClient = gatewayServer.getCallbackClient
281-
val field = callbackClient.getClass.getDeclaredField("port")
281+
val callbackClient = gatewayServer.getClass
282+
.getMethod("getCallbackClient")
283+
.invoke(gatewayServer)
284+
285+
val field = Class.forName("py4j.CallbackClient").getDeclaredField("port")
282286
field.setAccessible(true)
283287
field.setInt(callbackClient, port.toInt)
284288
}

0 commit comments

Comments
 (0)