-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Iceberg]Support s3 path as warehouse dir for hadoop catalog
- Loading branch information
1 parent
b94b05a
commit 7d5ef60
Showing
11 changed files
with
332 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
117 changes: 117 additions & 0 deletions
117
presto-iceberg/src/test/java/com/facebook/presto/iceberg/container/IcebergMinIODataLake.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
/* | ||
* Licensed 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 com.facebook.presto.iceberg.container; | ||
|
||
import com.amazonaws.auth.AWSStaticCredentialsProvider; | ||
import com.amazonaws.auth.BasicAWSCredentials; | ||
import com.amazonaws.client.builder.AwsClientBuilder; | ||
import com.amazonaws.services.s3.AmazonS3; | ||
import com.amazonaws.services.s3.AmazonS3ClientBuilder; | ||
import com.facebook.presto.testing.containers.MinIOContainer; | ||
import com.facebook.presto.util.AutoCloseableCloser; | ||
import com.google.common.collect.ImmutableMap; | ||
import org.testcontainers.containers.Network; | ||
|
||
import java.io.Closeable; | ||
import java.io.IOException; | ||
import java.util.concurrent.atomic.AtomicBoolean; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static org.testcontainers.containers.Network.newNetwork; | ||
|
||
public class IcebergMinIODataLake | ||
implements Closeable | ||
{ | ||
public static final String ACCESS_KEY = "accesskey"; | ||
public static final String SECRET_KEY = "secretkey"; | ||
|
||
private final String bucketName; | ||
private final String warehouseDir; | ||
private final MinIOContainer minIOContainer; | ||
|
||
private final AtomicBoolean isStarted = new AtomicBoolean(false); | ||
private final AutoCloseableCloser closer = AutoCloseableCloser.create(); | ||
|
||
public IcebergMinIODataLake(String bucketName, String warehouseDir) | ||
{ | ||
this.bucketName = requireNonNull(bucketName, "bucketName is null"); | ||
this.warehouseDir = requireNonNull(warehouseDir, "warehouseDir is null"); | ||
Network network = closer.register(newNetwork()); | ||
this.minIOContainer = closer.register( | ||
MinIOContainer.builder() | ||
.withNetwork(network) | ||
.withEnvVars(ImmutableMap.<String, String>builder() | ||
.put("MINIO_ACCESS_KEY", ACCESS_KEY) | ||
.put("MINIO_SECRET_KEY", SECRET_KEY) | ||
.build()) | ||
.build()); | ||
} | ||
|
||
public void start() | ||
{ | ||
if (isStarted()) { | ||
return; | ||
} | ||
try { | ||
this.minIOContainer.start(); | ||
AmazonS3 s3Client = AmazonS3ClientBuilder | ||
.standard() | ||
.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration( | ||
"http://localhost:" + minIOContainer.getMinioApiEndpoint().getPort(), | ||
"us-east-1")) | ||
.withPathStyleAccessEnabled(true) | ||
.withCredentials(new AWSStaticCredentialsProvider( | ||
new BasicAWSCredentials(ACCESS_KEY, SECRET_KEY))) | ||
.build(); | ||
s3Client.createBucket(this.bucketName); | ||
s3Client.putObject(this.bucketName, this.warehouseDir, ""); | ||
} | ||
finally { | ||
isStarted.set(true); | ||
} | ||
} | ||
|
||
public boolean isStarted() | ||
{ | ||
return isStarted.get(); | ||
} | ||
|
||
public void stop() | ||
{ | ||
if (!isStarted()) { | ||
return; | ||
} | ||
try { | ||
closer.close(); | ||
} | ||
catch (Exception e) { | ||
throw new RuntimeException("Failed to stop IcebergMinioDataLake", e); | ||
} | ||
finally { | ||
isStarted.set(false); | ||
} | ||
} | ||
|
||
public MinIOContainer getMinio() | ||
{ | ||
return minIOContainer; | ||
} | ||
|
||
@Override | ||
public void close() | ||
throws IOException | ||
{ | ||
stop(); | ||
} | ||
} |
Oops, something went wrong.