Skip to content

Commit

Permalink
Tiered Storage: add JClouds HttpClient driver (apache#15105)
Browse files Browse the repository at this point in the history
(cherry picked from commit e34448c)
  • Loading branch information
eolivelli authored and lhotari committed Apr 11, 2022
1 parent b0586cb commit 08e589d
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 3 deletions.
17 changes: 17 additions & 0 deletions jclouds-shaded/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,26 @@
<name>Apache Pulsar :: Jclouds shaded</name>

<dependencies>

<dependency>
<groupId>org.apache.jclouds</groupId>
<artifactId>jclouds-allblobstore</artifactId>
<version>${jclouds.version}</version>
</dependency>
<dependency>
<groupId>org.apache.jclouds.driver</groupId>
<artifactId>jclouds-apachehc</artifactId>
<version>${jclouds.version}</version>
</dependency>
<dependency>
<groupId>org.apache.jclouds.driver</groupId>
<artifactId>jclouds-slf4j</artifactId>
<version>${jclouds.version}</version>
</dependency>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
</dependency>
</dependencies>

<dependencyManagement>
Expand Down Expand Up @@ -75,10 +90,12 @@
<include>org.apache.jclouds:*</include>
<include>org.apache.jclouds.api:*</include>
<include>org.apache.jclouds.common:*</include>
<include>org.apache.jclouds.driver:*</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>org.apache.httpcomponents:*</include>
<include>javax.ws.rs:*</include>
<include>com.jamesmurty.utils:*</include>
<include>net.iharder:*</include>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/**
* 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.
*/
package org.apache.pulsar.jclouds;

import com.google.inject.AbstractModule;
import lombok.experimental.UtilityClass;
import lombok.extern.slf4j.Slf4j;
import org.jclouds.ContextBuilder;
import org.jclouds.http.apachehc.config.ApacheHCHttpCommandExecutorServiceModule;
import org.jclouds.logging.slf4j.config.SLF4JLoggingModule;

import java.util.ArrayList;
import java.util.List;

/**
* This utility class helps in dealing with shaded dependencies (especially Guice).
*/
@UtilityClass
@Slf4j
public class ShadedJCloudsUtils {

/**
* Use this System property to temporarily disable Apache Http Client Module.
* If you encounter problems and decide to use this flag please
* open a GH and share your problem.
* Apache Http Client module should work well in all the environments.
*/
private static final boolean ENABLE_APACHE_HC_MODULE = Boolean
.parseBoolean(System.getProperty("pulsar.jclouds.use_apache_hc", "true"));
static {
log.info("Considering -Dpulsar.jclouds.use_apache_hc=" + ENABLE_APACHE_HC_MODULE);
}

/**
* Setup standard modules.
* @param builder the build
*/
public static void addStandardModules(ContextBuilder builder) {
List<AbstractModule> modules = new ArrayList<>();
modules.add(new SLF4JLoggingModule());
if (ENABLE_APACHE_HC_MODULE) {
modules.add(new ApacheHCHttpCommandExecutorServiceModule());
}
builder.modules(modules);
}

}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ flexible messaging model and an intuitive client API.</description>
<maven-dependency-plugin.version>2.10</maven-dependency-plugin.version>
<maven-clean-plugin.version>2.4.1</maven-clean-plugin.version>
<maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version>
<maven-shade-plugin>3.2.4</maven-shade-plugin>
<maven-shade-plugin>3.3.0</maven-shade-plugin>
<maven-javadoc-plugin.version>2.10.3</maven-javadoc-plugin.version>
<exec-maven-plugin.version>1.6.0</exec-maven-plugin.version>
<maven-archiver.version>2.5</maven-archiver.version>
Expand Down
4 changes: 4 additions & 0 deletions tiered-storage/jcloud/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@
<groupId>org.apache.jclouds.provider</groupId>
<artifactId>*</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.jclouds.driver</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.apache.bookkeeper.mledger.offload.jcloud.provider.TieredStorageConfiguration.CredentialBuilder;

import org.apache.commons.lang3.StringUtils;
import org.apache.pulsar.jclouds.ShadedJCloudsUtils;
import org.jclouds.ContextBuilder;
import org.jclouds.aws.domain.SessionCredentials;
import org.jclouds.aws.s3.AWSS3ProviderMetadata;
Expand Down Expand Up @@ -133,6 +134,7 @@ public void validate(TieredStorageConfiguration config) throws IllegalArgumentEx
@Override
public BlobStore getBlobStore(TieredStorageConfiguration config) {
ContextBuilder contextBuilder = ContextBuilder.newBuilder(config.getProviderMetadata());
ShadedJCloudsUtils.addStandardModules(contextBuilder);
contextBuilder.overrides(config.getOverrides());

if (config.getProviderCredentials() != null) {
Expand Down Expand Up @@ -175,8 +177,9 @@ public void validate(TieredStorageConfiguration config) throws IllegalArgumentEx
@Override
public BlobStore getBlobStore(TieredStorageConfiguration config) {

ContextBuilder builder = ContextBuilder.newBuilder("transient");
BlobStoreContext ctx = builder
ContextBuilder contextBuilder = ContextBuilder.newBuilder("transient");
ShadedJCloudsUtils.addStandardModules(contextBuilder);
BlobStoreContext ctx = contextBuilder
.buildView(BlobStoreContext.class);

BlobStore bs = ctx.getBlobStore();
Expand Down Expand Up @@ -258,6 +261,7 @@ public ProviderMetadata getProviderMetadata() {

static final BlobStoreBuilder BLOB_STORE_BUILDER = (TieredStorageConfiguration config) -> {
ContextBuilder contextBuilder = ContextBuilder.newBuilder(config.getProviderMetadata());
ShadedJCloudsUtils.addStandardModules(contextBuilder);
contextBuilder.overrides(config.getOverrides());

if (StringUtils.isNotEmpty(config.getServiceEndpoint())) {
Expand Down

0 comments on commit 08e589d

Please sign in to comment.