-
Notifications
You must be signed in to change notification settings - Fork 380
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[#5173] feat(hadoop-catlog): Support OSS fileset for Gravitino. #5174
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* 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. | ||
*/ | ||
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar | ||
|
||
plugins { | ||
`maven-publish` | ||
id("java") | ||
alias(libs.plugins.shadow) | ||
} | ||
|
||
dependencies { | ||
compileOnly(project(":catalogs:catalog-hadoop")) | ||
compileOnly(libs.hadoop3.common) | ||
implementation(libs.hadoop3.oss) | ||
|
||
// oss needs StringUtils from commons-lang or the following error will occur in 3.1.0 | ||
// java.lang.NoClassDefFoundError: org/apache/commons/lang/StringUtils | ||
// org.apache.hadoop.fs.aliyun.oss.AliyunOSSFileSystemStore.initialize(AliyunOSSFileSystemStore.java:111) | ||
// org.apache.hadoop.fs.aliyun.oss.AliyunOSSFileSystem.initialize(AliyunOSSFileSystem.java:323) | ||
// org.apache.hadoop.fs.FileSystem.createFileSystem(FileSystem.java:3611) | ||
|
||
implementation(libs.commons.lang) | ||
} | ||
|
||
tasks.withType(ShadowJar::class.java) { | ||
isZip64 = true | ||
configurations = listOf(project.configurations.runtimeClasspath.get()) | ||
archiveClassifier.set("") | ||
mergeServiceFiles() | ||
} | ||
|
||
tasks.jar { | ||
dependsOn(tasks.named("shadowJar")) | ||
archiveClassifier.set("empty") | ||
} | ||
|
||
tasks.compileJava { | ||
dependsOn(":catalogs:catalog-hadoop:runtimeJars") | ||
} |
50 changes: 50 additions & 0 deletions
50
bundles/aliyun-bundle/src/main/java/org/apache/gravitino/oss/fs/OSSFileSystemProvider.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,50 @@ | ||
/* | ||
* 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.gravitino.oss.fs; | ||
|
||
import java.io.IOException; | ||
import java.util.Map; | ||
import org.apache.gravitino.catalog.hadoop.fs.FileSystemProvider; | ||
import org.apache.hadoop.conf.Configuration; | ||
import org.apache.hadoop.fs.FileSystem; | ||
import org.apache.hadoop.fs.Path; | ||
import org.apache.hadoop.fs.aliyun.oss.AliyunOSSFileSystem; | ||
|
||
public class OSSFileSystemProvider implements FileSystemProvider { | ||
@Override | ||
public FileSystem getFileSystem(Path path, Map<String, String> config) throws IOException { | ||
Configuration configuration = new Configuration(); | ||
config.forEach( | ||
(k, v) -> { | ||
configuration.set(k.replace("gravitino.bypass.", ""), v); | ||
}); | ||
|
||
return AliyunOSSFileSystem.newInstance(path.toUri(), configuration); | ||
} | ||
|
||
@Override | ||
public String scheme() { | ||
return "oss"; | ||
} | ||
|
||
@Override | ||
public String name() { | ||
return "oss"; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...ain/resources/META-INF/services/org.apache.gravitino.catalog.hadoop.fs.FileSystemProvider
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,20 @@ | ||
# | ||
# 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. | ||
# | ||
|
||
org.apache.gravitino.oss.fs.OSSFileSystemProvider |
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
168 changes: 168 additions & 0 deletions
168
...rc/test/java/org/apache/gravitino/catalog/hadoop/integration/test/HadoopOSSCatalogIT.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,168 @@ | ||
/* | ||
* 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.gravitino.catalog.hadoop.integration.test; | ||
|
||
import static org.apache.gravitino.catalog.hadoop.HadoopCatalogPropertiesMetadata.FILESYSTEM_PROVIDERS; | ||
|
||
import com.google.common.annotations.VisibleForTesting; | ||
import com.google.common.collect.Maps; | ||
import java.io.IOException; | ||
import java.net.URI; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
import org.apache.gravitino.Catalog; | ||
import org.apache.gravitino.integration.test.util.DownloaderUtils; | ||
import org.apache.gravitino.integration.test.util.GravitinoITUtils; | ||
import org.apache.gravitino.integration.test.util.ITUtils; | ||
import org.apache.hadoop.conf.Configuration; | ||
import org.apache.hadoop.fs.FileSystem; | ||
import org.apache.hadoop.fs.Path; | ||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Disabled; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
@Disabled( | ||
"Disabled due to we don't have a real OSS account to test. If you have a GCP account," | ||
+ "please change the configuration(BUCKET_NAME, OSS_ACCESS_KEY, OSS_SECRET_KEY, OSS_ENDPOINT) and enable this test.") | ||
public class HadoopOSSCatalogIT extends HadoopCatalogIT { | ||
private static final Logger LOG = LoggerFactory.getLogger(HadoopOSSCatalogIT.class); | ||
public static final String BUCKET_NAME = "YOUR_BUCKET"; | ||
public static final String OSS_ACCESS_KEY = "YOUR_OSS_ACCESS_KEY"; | ||
public static final String OSS_SECRET_KEY = "YOUR_OSS_SECRET_KEY"; | ||
public static final String OSS_ENDPOINT = "YOUR_OSS_ENDPOINT"; | ||
|
||
@VisibleForTesting | ||
public void startIntegrationTest() throws Exception {} | ||
|
||
@BeforeAll | ||
public void setup() throws IOException { | ||
if (isDeploy()) { | ||
copyAliyunJars(); | ||
} | ||
|
||
try { | ||
super.startIntegrationTest(); | ||
} catch (Exception e) { | ||
throw new RuntimeException("Failed to start integration test", e); | ||
} | ||
|
||
metalakeName = GravitinoITUtils.genRandomName("CatalogFilesetIT_metalake"); | ||
catalogName = GravitinoITUtils.genRandomName("CatalogFilesetIT_catalog"); | ||
schemaName = GravitinoITUtils.genRandomName("CatalogFilesetIT_schema"); | ||
|
||
schemaName = GravitinoITUtils.genRandomName(SCHEMA_PREFIX); | ||
Configuration conf = new Configuration(); | ||
|
||
conf.set("fs.oss.accessKeyId", OSS_ACCESS_KEY); | ||
conf.set("fs.oss.accessKeySecret", OSS_SECRET_KEY); | ||
conf.set("fs.oss.endpoint", OSS_ENDPOINT); | ||
conf.set("fs.oss.impl", "org.apache.hadoop.fs.aliyun.oss.AliyunOSSFileSystem"); | ||
fileSystem = FileSystem.get(URI.create(String.format("oss://%s", BUCKET_NAME)), conf); | ||
|
||
createMetalake(); | ||
createCatalog(); | ||
createSchema(); | ||
} | ||
|
||
@AfterAll | ||
public void stop() throws IOException { | ||
Catalog catalog = metalake.loadCatalog(catalogName); | ||
catalog.asSchemas().dropSchema(schemaName, true); | ||
metalake.dropCatalog(catalogName); | ||
client.dropMetalake(metalakeName); | ||
|
||
try { | ||
closer.close(); | ||
} catch (Exception e) { | ||
LOG.error("Failed to close CloseableGroup", e); | ||
} | ||
} | ||
|
||
protected String defaultBaseLocation() { | ||
if (defaultBaseLocation == null) { | ||
try { | ||
Path bucket = | ||
new Path( | ||
String.format( | ||
"oss://%s/%s", | ||
BUCKET_NAME, GravitinoITUtils.genRandomName("CatalogFilesetIT"))); | ||
if (!fileSystem.exists(bucket)) { | ||
fileSystem.mkdirs(bucket); | ||
} | ||
|
||
defaultBaseLocation = bucket.toString(); | ||
} catch (IOException e) { | ||
throw new RuntimeException("Failed to create default base location", e); | ||
} | ||
} | ||
|
||
return defaultBaseLocation; | ||
} | ||
|
||
protected void createCatalog() { | ||
Map<String, String> map = Maps.newHashMap(); | ||
map.put("gravitino.bypass.fs.oss.accessKeyId", OSS_ACCESS_KEY); | ||
map.put("gravitino.bypass.fs.oss.accessKeySecret", OSS_SECRET_KEY); | ||
map.put("gravitino.bypass.fs.oss.endpoint", OSS_ENDPOINT); | ||
map.put("gravitino.bypass.fs.oss.impl", "org.apache.hadoop.fs.aliyun.oss.AliyunOSSFileSystem"); | ||
map.put(FILESYSTEM_PROVIDERS, "oss"); | ||
|
||
metalake.createCatalog(catalogName, Catalog.Type.FILESET, provider, "comment", map); | ||
|
||
catalog = metalake.loadCatalog(catalogName); | ||
} | ||
|
||
protected String generateLocation(String filesetName) { | ||
return String.format("%s/%s", defaultBaseLocation, filesetName); | ||
} | ||
|
||
private static boolean isDeploy() { | ||
String mode = | ||
System.getProperty(ITUtils.TEST_MODE) == null | ||
? ITUtils.EMBEDDED_TEST_MODE | ||
: System.getProperty(ITUtils.TEST_MODE); | ||
|
||
return Objects.equals(mode, ITUtils.DEPLOY_TEST_MODE); | ||
} | ||
|
||
private void copyAliyunJars() { | ||
if (!isDeploy()) { | ||
return; | ||
} | ||
|
||
String gravitinoHome = System.getenv("GRAVITINO_HOME"); | ||
String jarName = | ||
String.format("gravitino-aliyun-bundle-%s.jar", System.getenv("PROJECT_VERSION")); | ||
String gcsJars = | ||
ITUtils.joinPath( | ||
gravitinoHome, "..", "..", "bundles", "aliyun-bundle", "build", "libs", jarName); | ||
gcsJars = "file://" + gcsJars; | ||
try { | ||
if (!ITUtils.EMBEDDED_TEST_MODE.equals(testMode)) { | ||
String hadoopLibDirs = ITUtils.joinPath(gravitinoHome, "catalogs", "hadoop", "libs"); | ||
DownloaderUtils.downloadFile(gcsJars, hadoopLibDirs); | ||
} | ||
} catch (Exception e) { | ||
throw new RuntimeException( | ||
String.format("Failed to copy the aliyun dependency jars: %s", gcsJars), e); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to shade this jar?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think so, the package will be shaded in the jar
gravitino-aliyun-bundle
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is introduced by you, so you have to shade it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.