Skip to content

Commit

Permalink
[FLINK-7778] [build] Shade ZooKeeper dependency (part 2)
Browse files Browse the repository at this point in the history
This closes apache#4927
  • Loading branch information
zentol authored and StephanEwen committed Nov 2, 2017
1 parent 4d02823 commit d368a07
Show file tree
Hide file tree
Showing 7 changed files with 188 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,16 @@
import org.apache.flink.runtime.zookeeper.ZooKeeperSharedValue;
import org.apache.flink.runtime.zookeeper.ZooKeeperStateHandleStore;
import org.apache.flink.runtime.zookeeper.ZooKeeperVersionedValue;
import org.apache.flink.runtime.zookeeper.ZookeeperAccess;
import org.apache.flink.util.FlinkException;

import org.apache.mesos.Protos;
import org.apache.zookeeper.KeeperException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.ConcurrentModificationException;
import java.util.List;

import scala.Option;
Expand Down Expand Up @@ -218,15 +217,15 @@ public void putWorker(MesosWorkerStore.Worker worker) throws Exception {
try {
workersInZooKeeper.addAndLock(path, worker);
LOG.debug("Added {} in ZooKeeper.", worker);
} catch (KeeperException.NodeExistsException ex) {
throw new ConcurrentModificationException("ZooKeeper unexpectedly modified", ex);
} catch (Exception ex) {
throw ZookeeperAccess.wrapIfZooKeeperNodeExistsException(ex);
}
} else {
try {
workersInZooKeeper.replace(path, currentVersion, worker);
LOG.debug("Updated {} in ZooKeeper.", worker);
} catch (KeeperException.NoNodeException ex) {
throw new ConcurrentModificationException("ZooKeeper unexpectedly modified", ex);
} catch (Exception ex) {
throw ZookeeperAccess.wrapIfZooKeeperNoNodeException(ex);
}
}
}
Expand Down
27 changes: 12 additions & 15 deletions flink-runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -178,17 +178,9 @@ under the License.
</dependency>

<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-recipes</artifactId>
<version>${curator.version}</version>
<exclusions>
<!-- curator shades guava, but still has a dependency on it. -->
<!-- We can safely exclude Guava here -->
<exclusion>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</exclusion>
</exclusions>
<groupId>org.apache.flink</groupId>
<artifactId>flink-shaded-curator-recipes</artifactId>
<version>${project.version}</version>
</dependency>

<!-- test dependencies -->
Expand Down Expand Up @@ -448,7 +440,6 @@ under the License.
<include>com.typesafe.akka:akka-remote_*</include>
<include>io.netty:netty</include>
<include>org.uncommons.maths:uncommons-maths</include>
<include>org.apache.curator:*</include>
<include>org.apache.zookeeper:*</include>
</includes>
</artifactSet>
Expand All @@ -463,16 +454,22 @@ under the License.
</relocation>
<relocation>
<pattern>org.apache.curator</pattern>
<shadedPattern>org.apache.flink.shaded.org.apache.curator</shadedPattern>
<shadedPattern>org.apache.flink.shaded.curator.org.apache.curator</shadedPattern>
<excludes>
<!-- Do not relocate curator-test. This leads to problems for downstream
users of runtime test classes that make use of it as the relocated
dependency is not included in the test-jar.-->
<exclude>org.apache.curator.test.*</exclude>
</excludes>
</relocation>
<relocation>
<pattern>org.apache.zookeeper</pattern>
<shadedPattern>org.apache.flink.shaded.org.apache.zookeeper</shadedPattern>
<shadedPattern>org.apache.flink.shaded.zookeeper.org.apache.zookeeper</shadedPattern>
</relocation>
<!-- jute is already shaded into the ZooKeeper jar -->
<relocation>
<pattern>org.apache.jute</pattern>
<shadedPattern>org.apache.flink.shaded.org.apache.zookeeper.jute</shadedPattern>
<shadedPattern>org.apache.flink.shaded.zookeeper.org.apache.zookeeper.jute</shadedPattern>
</relocation>
</relocations>
<filters>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF 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:https://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.
*/

package org.apache.flink.runtime.zookeeper;

import org.apache.zookeeper.KeeperException;

import java.util.ConcurrentModificationException;

/**
* Utility class providing access to relocated zookeeper classes.
*
* <p>This class is necessary as flink-runtime relocates its ZooKeeper dependency.
* Other modules may still depend on this dependency but will encounter a ClassNotFoundException
* on access as they don't apply the relocation pattern of flink-runtime.
*/
public final class ZookeeperAccess {

private ZookeeperAccess(){
}

/**
* Wraps and returns the given exception in a {@link ConcurrentModificationException} if it is a
* {@link org.apache.zookeeper.KeeperException.NodeExistsException}. Otherwise the
* given exception is returned.
*
* @param ex exception to wrap
* @return wrapping ConcurrentModificationException if it is a NodeExistsException, otherwise the given exception
*/
public static Exception wrapIfZooKeeperNodeExistsException(Exception ex) {
if (ex instanceof KeeperException.NodeExistsException) {
return new ConcurrentModificationException("ZooKeeper unexpectedly modified", ex);
}
return ex;
}

/**
* Wraps and returns the given exception in a {@link ConcurrentModificationException} if it is a
* {@link org.apache.zookeeper.KeeperException.NoNodeException}. Otherwise the
* given exception is returned.
*
* @param ex exception to wrap
* @return wrapping ConcurrentModificationException if it is a NoNodeException, otherwise the given exception
*/
public static Exception wrapIfZooKeeperNoNodeException(Exception ex) {
if (ex instanceof KeeperException.NoNodeException) {
return new ConcurrentModificationException("ZooKeeper unexpectedly modified", ex);
}
return ex;
}
}
88 changes: 88 additions & 0 deletions flink-shaded-curator-recipes/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF 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:https://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.
-->
<project xmlns="http:https://maven.apache.org/POM/4.0.0" xmlns:xsi="http:https://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http:https://maven.apache.org/POM/4.0.0 http:https://maven.apache.org/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.apache.flink</groupId>
<artifactId>flink-parent</artifactId>
<version>1.4-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>

<artifactId>flink-shaded-curator-recipes</artifactId>
<name>flink-shaded-curator-recipes</name>

<packaging>jar</packaging>


<dependencies>
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-recipes</artifactId>
<version>${curator.version}</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<id>shade-flink</id>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<artifactSet>
<includes>
<include>com.google.guava:guava</include>
<include>org.apache.curator:*</include>
</includes>
</artifactSet>
<filters>
<filter>
<artifact>com.google.guava:guava</artifact>
<!-- Shade guava classes that are not included by curator -->
<includes>
<include>com/google/common/base/Function.class</include>
<include>com/google/common/base/Predicate.class</include>
<include>com/google/common/reflect/TypeToken.class</include>
</includes>
</filter>
</filters>
<relocations>
<relocation>
<pattern>com.google.common</pattern>
<shadedPattern>org.apache.flink.curator.shaded.com.google.common</shadedPattern>
</relocation>
</relocations>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
5 changes: 0 additions & 5 deletions flink-shaded-hadoop/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,6 @@ under the License.
<artifactId>slf4j-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.avro</groupId>
<artifactId>avro</artifactId>
Expand Down
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ under the License.
<module>tools/force-shading</module>
<module>flink-annotations</module>
<module>flink-shaded-hadoop</module>
<module>flink-shaded-curator-recipes</module>
<module>flink-core</module>
<module>flink-java</module>
<module>flink-java8</module>
Expand Down
16 changes: 16 additions & 0 deletions tools/travis_mvn_watchdog.sh
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,22 @@ check_shaded_artifacts() {
return 1
fi

ZOOKEEPER=`cat allClasses | grep '^org/apache/zookeeper' | wc -l`
if [ "$ZOOKEEPER" != "0" ]; then
echo "=============================================================================="
echo "Detected '$ZOOKEEPER' unshaded org.apache.zookeeper classes in fat jar"
echo "=============================================================================="
return 1
fi

CURATOR=`cat allClasses | grep '^org/apache/curator' | wc -l`
if [ "$CURATOR" != "0" ]; then
echo "=============================================================================="
echo "Detected '$CURATOR' unshaded org.apache.curator classes in fat jar"
echo "=============================================================================="
return 1
fi

FLINK_PYTHON=`cat allClasses | grep '^org/apache/flink/python' | wc -l`
if [ "$FLINK_PYTHON" != "0" ]; then
echo "=============================================================================="
Expand Down

0 comments on commit d368a07

Please sign in to comment.