-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding ABFS support to access ADLS Gen2 storage accounts
- Loading branch information
1 parent
c3088af
commit 263feb2
Showing
8 changed files
with
156 additions
and
12 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
28 changes: 28 additions & 0 deletions
28
...s/flink-azure-fs-hadoop/src/main/java/org/apache/flink/fs/azurefs/ABFSAzureFSFactory.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,28 @@ | ||
/* | ||
* 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.flink.fs.azurefs; | ||
|
||
/** Abfs azureFs implementation. */ | ||
public class ABFSAzureFSFactory extends AbstractAzureFSFactory { | ||
|
||
@Override | ||
public String getScheme() { | ||
return "abfs"; | ||
} | ||
} |
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 |
---|---|---|
|
@@ -25,6 +25,7 @@ | |
import org.apache.flink.runtime.util.HadoopConfigLoader; | ||
|
||
import org.apache.hadoop.fs.azure.NativeAzureFileSystem; | ||
import org.apache.hadoop.fs.azurebfs.AzureBlobFileSystem; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
|
@@ -36,7 +37,7 @@ | |
import static org.apache.flink.util.Preconditions.checkNotNull; | ||
|
||
/** | ||
* Abstract factory for AzureFS. Subclasses override to specify the correct scheme (wasb / wasbs). | ||
* Abstract factory for AzureFS. Subclasses override to specify the correct scheme (wasb / wasbs / abfs/ abfss). | ||
* Based on Azure HDFS support in the <a | ||
* href="https://hadoop.apache.org/docs/current/hadoop-azure/index.html">hadoop-azure</a> module. | ||
*/ | ||
|
@@ -75,18 +76,27 @@ public void configure(Configuration config) { | |
@Override | ||
public FileSystem create(URI fsUri) throws IOException { | ||
checkNotNull(fsUri, "passed file system URI object should not be null"); | ||
LOG.info("Trying to load and instantiate Azure File System"); | ||
LOG.info("Trying to load and instantiate Azure File System for {}", fsUri); | ||
return new HadoopFileSystem(createInitializedAzureFS(fsUri, flinkConfig)); | ||
} | ||
|
||
// uri is of the form: wasb(s)://[email protected]/testDir | ||
// uri is of the form: wasb(s)://[email protected]/testDir (or) | ||
// abfs(s):////[email protected]/testDir | ||
private org.apache.hadoop.fs.FileSystem createInitializedAzureFS( | ||
URI fsUri, Configuration flinkConfig) throws IOException { | ||
org.apache.hadoop.conf.Configuration hadoopConfig = configLoader.getOrLoadHadoopConfig(); | ||
|
||
org.apache.hadoop.fs.FileSystem azureFS = new NativeAzureFileSystem(); | ||
azureFS.initialize(fsUri, hadoopConfig); | ||
|
||
return azureFS; | ||
String scheme = fsUri.getScheme(); | ||
|
||
if (scheme.startsWith("wasb")) { | ||
LOG.info("Trying to initialize hadoop filesystem for {}.", scheme); | ||
org.apache.hadoop.fs.FileSystem azureFS = new NativeAzureFileSystem(); | ||
azureFS.initialize(fsUri, hadoopConfig); | ||
return azureFS; | ||
} else { | ||
LOG.info("Trying to initialize hadoop filesystem for {}.", scheme); | ||
org.apache.hadoop.fs.FileSystem azureFS = new AzureBlobFileSystem(); | ||
azureFS.initialize(fsUri, hadoopConfig); | ||
return azureFS; | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...k-azure-fs-hadoop/src/main/java/org/apache/flink/fs/azurefs/SecureABFSAzureFSFactory.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,28 @@ | ||
/* | ||
* 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.flink.fs.azurefs; | ||
|
||
/** Secure ABFS AzureFS implementation. */ | ||
public class SecureABFSAzureFSFactory extends AbstractAzureFSFactory { | ||
|
||
@Override | ||
public String getScheme() { | ||
return "abfss"; | ||
} | ||
} |
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
54 changes: 54 additions & 0 deletions
54
...ink-azure-fs-hadoop/src/test/java/org/apache/flink/fs/azurefs/ABFSAzureFSFactoryTest.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,54 @@ | ||
package org.apache.flink.fs.azurefs; | ||
|
||
import org.apache.flink.configuration.Configuration; | ||
|
||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.ExpectedException; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.Parameterized; | ||
|
||
import java.net.URI; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
/** Tests for the ABFSAzureFSFactory. */ | ||
@RunWith(Parameterized.class) | ||
public class ABFSAzureFSFactoryTest { | ||
@Parameterized.Parameter public String scheme; | ||
|
||
@Parameterized.Parameters(name = "Scheme = {0}") | ||
public static List<String> parameters() { | ||
return Arrays.asList("abfs", "abfss"); | ||
} | ||
|
||
@Rule public final ExpectedException exception = ExpectedException.none(); | ||
|
||
private AbstractAzureFSFactory getFactory(String scheme) { | ||
return scheme.equals("abfs") ? new ABFSAzureFSFactory() : new SecureABFSAzureFSFactory(); | ||
} | ||
|
||
@Test | ||
public void testNullFsURI() throws Exception { | ||
URI uri = null; | ||
AbstractAzureFSFactory factory = getFactory(scheme); | ||
|
||
exception.expect(NullPointerException.class); | ||
exception.expectMessage("passed file system URI object should not be null"); | ||
|
||
factory.create(uri); | ||
} | ||
|
||
@Test | ||
public void testCreateFsWithMissingAuthority() throws Exception { | ||
String uriString = String.format("%s:///my/path", scheme); | ||
final URI uri = URI.create(uriString); | ||
|
||
exception.expect(IllegalArgumentException.class); | ||
exception.expectMessage(String.format("%s has invalid authority.", uriString)); | ||
|
||
AbstractAzureFSFactory factory = getFactory(scheme); | ||
factory.configure(new Configuration()); | ||
factory.create(uri); | ||
} | ||
} |
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