Skip to content

Commit

Permalink
Tiered Storage: add JClouds HttpClient driver (apache#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
eolivelli authored Apr 11, 2022
1 parent 1cace22 commit 0862150
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 10 deletions.
7 changes: 7 additions & 0 deletions jclouds-shaded/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@
<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>
Expand Down Expand Up @@ -74,11 +79,13 @@
<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>com.google.code.gson:gson</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 @@ -236,7 +236,7 @@ flexible messaging model and an intuitive client API.</description>
<surefire.version>3.0.0-M3</surefire.version>
<maven-assembly-plugin.version>3.3.0</maven-assembly-plugin.version>
<maven-dependency-plugin.version>3.1.2</maven-dependency-plugin.version>
<maven-shade-plugin>3.2.4</maven-shade-plugin>
<maven-shade-plugin>3.3.0</maven-shade-plugin>
<maven-antrun-plugin.version>3.0.0</maven-antrun-plugin.version>
<nifi-nar-maven-plugin.version>1.2.0</nifi-nar-maven-plugin.version>
<maven-checkstyle-plugin.version>3.1.2</maven-checkstyle-plugin.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 @@ -38,17 +38,16 @@
import java.io.IOException;
import java.io.Serializable;
import java.nio.charset.Charset;
import java.util.Arrays;
import java.util.Properties;
import java.util.UUID;

import lombok.extern.slf4j.Slf4j;

import org.apache.bookkeeper.mledger.offload.jcloud.provider.TieredStorageConfiguration.BlobStoreBuilder;
import org.apache.bookkeeper.mledger.offload.jcloud.provider.TieredStorageConfiguration.ConfigValidation;
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 All @@ -62,7 +61,6 @@
import org.jclouds.domain.LocationScope;
import org.jclouds.googlecloud.GoogleCredentialsFromJson;
import org.jclouds.googlecloudstorage.GoogleCloudStorageProviderMetadata;
import org.jclouds.logging.slf4j.config.SLF4JLoggingModule;
import org.jclouds.providers.AnonymousProviderMetadata;
import org.jclouds.providers.ProviderMetadata;
import org.jclouds.s3.S3ApiMetadata;
Expand Down Expand Up @@ -142,7 +140,7 @@ public void validate(TieredStorageConfiguration config) throws IllegalArgumentEx
@Override
public BlobStore getBlobStore(TieredStorageConfiguration config) {
ContextBuilder contextBuilder = ContextBuilder.newBuilder(config.getProviderMetadata());
contextBuilder.modules(Arrays.asList(new SLF4JLoggingModule()));
ShadedJCloudsUtils.addStandardModules(contextBuilder);
contextBuilder.overrides(config.getOverrides());

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

ContextBuilder builder = ContextBuilder.newBuilder("transient");
builder.modules(Arrays.asList(new SLF4JLoggingModule()));
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 @@ -291,7 +289,7 @@ public ProviderMetadata getProviderMetadata() {

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

if (StringUtils.isNotEmpty(config.getServiceEndpoint())) {
Expand Down Expand Up @@ -376,7 +374,7 @@ public String getAWSSecretKey() {

static final BlobStoreBuilder ALIYUN_OSS_BLOB_STORE_BUILDER = (TieredStorageConfiguration config) -> {
ContextBuilder contextBuilder = ContextBuilder.newBuilder(config.getProviderMetadata());
contextBuilder.modules(Arrays.asList(new SLF4JLoggingModule()));
ShadedJCloudsUtils.addStandardModules(contextBuilder);
Properties overrides = config.getOverrides();
// For security reasons, OSS supports only virtual hosted style access.
overrides.setProperty(S3Constants.PROPERTY_S3_VIRTUAL_HOST_BUCKETS, "true");
Expand Down

0 comments on commit 0862150

Please sign in to comment.