Skip to content

Commit

Permalink
shaded jclouds to avoid gson conflict (apache#7435)
Browse files Browse the repository at this point in the history
Fixes apache#7402 

### Motivation

Currently, the GCS offload error is still existing. In jclouds `2.2.0` and `2.2.1`, it only shaded the package [`com.google.gson.internal`](https://github.com/apache/jclouds/blob/master/gson/gson-shaded/pom.xml#L70), and in the class  [`org.jclouds.json.internal.NullFilteringTypeAdapterFactories`](https://github.com/apache/jclouds/blob/master/core/src/main/java/org/jclouds/json/internal/NullFilteringTypeAdapterFactories.java#L319) the shaded class `org.jclouds.json.gson.internal.JsonReaderInternalAccess` will be initialized by `com.google.gson.stream.JsonReader` which is in jclouds, the Pulsar include the same class `com.google.gson.stream.JsonReader` and when Pulsar broker start it will be loaded before  jclouds's, so this will cause the `org.jclouds.json.gson.internal.JsonReaderInternalAccess` can't be initialized successfully, and occurs NPE. 




### Modifications

Shaded the jclouds to make the class `org.jclouds.json.gson.internal.JsonReaderInternalAccess` could be initialized normally.
  • Loading branch information
gaoran10 authored Jul 5, 2020
1 parent d83133a commit 53c50c1
Show file tree
Hide file tree
Showing 6 changed files with 175 additions and 26 deletions.
140 changes: 140 additions & 0 deletions jclouds-shaded/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
<?xml version="1.0"?>
<!--
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://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
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.pulsar</groupId>
<artifactId>pulsar</artifactId>
<version>2.7.0-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>

<artifactId>jclouds-shaded</artifactId>
<name>Apache Pulsar :: Jclouds shaded</name>

<dependencies>
<dependency>
<groupId>org.apache.jclouds</groupId>
<artifactId>jclouds-allblobstore</artifactId>
<version>${jclouds.version}</version>
</dependency>
</dependencies>

<dependencyManagement>
<dependencies>
<!-- JClouds still is using Guava 18.0 and it won't work with newer versions -->
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>18.0</version>
</dependency>
</dependencies>
</dependencyManagement>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<createDependencyReducedPom>true</createDependencyReducedPom>
<promoteTransitiveDependencies>true</promoteTransitiveDependencies>
<minimizeJar>false</minimizeJar>

<artifactSet>
<includes>
<include>com.google.guava:guava</include>
<include>org.apache.jclouds:*</include>
<include>org.apache.jclouds.api:*</include>
<include>org.apache.jclouds.common:*</include>
<include>org.apache.jclouds.provider:*</include>
<include>com.google.inject.extensions:guice-assistedinject</include>
<include>com.google.inject:guice</include>
<include>com.google.inject.extensions:guice-multibindings</include>
<include>javax.ws.rs:*</include>
<include>com.jamesmurty.utils:*</include>
<include>net.iharder:*</include>
<include>aopalliance:*</include>
<include>javax.inject:*</include>
<include>javax.annotation:*</include>
<include>com.google.errorprone:*</include>
</includes>
</artifactSet>

<relocations>
<relocation>
<pattern>com.google.gson.internal</pattern>
<shadedPattern>org.jclouds.json.gson.internal</shadedPattern>
</relocation>
<relocation>
<pattern>com.google</pattern>
<shadedPattern>org.apache.pulsar.jcloud.shade.com.google</shadedPattern>
</relocation>
<relocation>
<pattern>javax.ws</pattern>
<shadedPattern>org.apache.pulsar.jcloud.shade.javax.ws</shadedPattern>
</relocation>
<relocation>
<pattern>com.jamesmurty.utils</pattern>
<shadedPattern>org.apache.pulsar.jcloud.shade.com.jamesmurty.utils</shadedPattern>
</relocation>
<relocation>
<pattern>aopalliance</pattern>
<shadedPattern>org.apache.pulsar.jcloud.shade.aopalliance</shadedPattern>
</relocation>
<relocation>
<pattern>net.iharder</pattern>
<shadedPattern>org.apache.pulsar.jcloud.shade.net.iharder</shadedPattern>
</relocation>
<relocation>
<pattern>javax.inject</pattern>
<shadedPattern>org.apache.pulsar.jcloud.shade.javax.inject</shadedPattern>
</relocation>
<relocation>
<pattern>javax.annotation</pattern>
<shadedPattern>org.apache.pulsar.jcloud.shade.javax.annotation</shadedPattern>
</relocation>
<relocation>
<pattern>com.google.errorprone</pattern>
<shadedPattern>org.apache.pulsar.jcloud.shade.com.google.errorprone</shadedPattern>
</relocation>

</relocations>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
<transformer implementation="org.apache.maven.plugins.shade.resource.PluginXmlResourceTransformer"/>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
13 changes: 1 addition & 12 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ flexible messaging model and an intuitive client API.</description>
<module>docker</module>
<module>tests</module>
<module>pulsar-metadata</module>
<module>jclouds-shaded</module>
</modules>

<issueManagement>
Expand Down Expand Up @@ -1005,18 +1006,6 @@ flexible messaging model and an intuitive client API.</description>
<version>${commons.collections.version}</version>
</dependency>

<dependency>
<groupId>org.apache.jclouds</groupId>
<artifactId>jclouds-allblobstore</artifactId>
<version>${jclouds.version}</version>
</dependency>

<dependency>
<groupId>org.apache.jclouds</groupId>
<artifactId>jclouds-blobstore</artifactId>
<version>${jclouds.version}</version>
</dependency>

<!-- test dependencies -->
<dependency>
<groupId>com.lmax</groupId>
Expand Down
36 changes: 26 additions & 10 deletions tiered-storage/jcloud/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,40 @@
<groupId>org.apache.pulsar</groupId>
<artifactId>managed-ledger</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.apache.pulsar</groupId>
<artifactId>jclouds-shaded</artifactId>
<version>${pulsar.jclouds.shaded.version}</version>
<exclusions>
<exclusion>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</exclusion>
<exclusion>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.jclouds</groupId>
<artifactId>*</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.jclouds.api</groupId>
<artifactId>*</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.jclouds.common</groupId>
<artifactId>*</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.jclouds.provider</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>org.apache.jclouds</groupId>
<artifactId>jclouds-allblobstore</artifactId>
</dependency>

<dependency>
<groupId>org.apache.jclouds</groupId>
<artifactId>jclouds-blobstore</artifactId>
</dependency>

<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import com.amazonaws.auth.AWSSessionCredentials;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Strings;
import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
Expand All @@ -50,6 +49,7 @@
import org.apache.bookkeeper.mledger.offload.jcloud.OffloadIndexBlockBuilder;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.pulsar.common.policies.data.OffloadPolicies;
import org.apache.pulsar.jcloud.shade.com.google.common.base.Supplier;
import org.jclouds.Constants;
import org.jclouds.ContextBuilder;
import org.jclouds.aws.domain.SessionCredentials;
Expand All @@ -69,10 +69,10 @@
import org.jclouds.googlecloudstorage.GoogleCloudStorageProviderMetadata;
import org.jclouds.io.Payload;
import org.jclouds.io.Payloads;
import org.jclouds.osgi.ProviderRegistry;
import org.jclouds.s3.reference.S3Constants;
import org.jclouds.osgi.ApiRegistry;
import org.jclouds.osgi.ProviderRegistry;
import org.jclouds.s3.S3ApiMetadata;
import org.jclouds.s3.reference.S3Constants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.AWSCredentialsProvider;
import com.amazonaws.auth.AWSSessionCredentials;
import com.google.common.base.Supplier;
import com.google.common.util.concurrent.MoreExecutors;
import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -56,6 +55,7 @@
import org.apache.bookkeeper.mledger.offload.jcloud.CredentialsUtil;
import org.apache.bookkeeper.util.ZkUtils;
import org.apache.pulsar.common.policies.data.OffloadPolicies;
import org.apache.pulsar.jcloud.shade.com.google.common.base.Supplier;
import org.apache.zookeeper.CreateMode;
import org.apache.zookeeper.MockZooKeeper;
import org.apache.zookeeper.data.ACL;
Expand Down
4 changes: 4 additions & 0 deletions tiered-storage/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
<artifactId>tiered-storage-parent</artifactId>
<name>Apache Pulsar :: Tiered Storage :: Parent</name>

<properties>
<pulsar.jclouds.shaded.version>${project.version}</pulsar.jclouds.shaded.version>
</properties>

<modules>
<module>jcloud</module>
<module>file-system</module>
Expand Down

0 comments on commit 53c50c1

Please sign in to comment.