-
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
b7352bf
commit c84c830
Showing
11 changed files
with
217 additions
and
28 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
36 changes: 36 additions & 0 deletions
36
...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,36 @@ | ||
/* | ||
* 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; | ||
|
||
import org.apache.hadoop.fs.FileSystem; | ||
import org.apache.hadoop.fs.azurebfs.AzureBlobFileSystem; | ||
|
||
/** Abfs azureFs implementation. */ | ||
public class ABFSAzureFSFactory extends AbstractAzureFSFactory { | ||
|
||
@Override | ||
public String getScheme() { | ||
return "abfs"; | ||
} | ||
|
||
@Override | ||
FileSystem createAzureFS() { | ||
return new AzureBlobFileSystem(); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -24,7 +24,6 @@ | |
import org.apache.flink.runtime.fs.hdfs.HadoopFileSystem; | ||
import org.apache.flink.runtime.util.HadoopConfigLoader; | ||
|
||
import org.apache.hadoop.fs.azure.NativeAzureFileSystem; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
|
@@ -36,8 +35,8 @@ | |
import static org.apache.flink.util.Preconditions.checkNotNull; | ||
|
||
/** | ||
* Abstract factory for AzureFS. Subclasses override to specify the correct scheme (wasb / wasbs). | ||
* Based on Azure HDFS support in the <a | ||
* 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. | ||
*/ | ||
public abstract class AbstractAzureFSFactory implements FileSystemFactory { | ||
|
@@ -53,8 +52,6 @@ public abstract class AbstractAzureFSFactory implements FileSystemFactory { | |
|
||
private final HadoopConfigLoader configLoader; | ||
|
||
private Configuration flinkConfig; | ||
|
||
public AbstractAzureFSFactory() { | ||
this.configLoader = | ||
new HadoopConfigLoader( | ||
|
@@ -68,25 +65,18 @@ public AbstractAzureFSFactory() { | |
|
||
@Override | ||
public void configure(Configuration config) { | ||
flinkConfig = config; | ||
configLoader.setFlinkConfig(config); | ||
} | ||
|
||
abstract org.apache.hadoop.fs.FileSystem createAzureFS(); | ||
|
||
@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"); | ||
return new HadoopFileSystem(createInitializedAzureFS(fsUri, flinkConfig)); | ||
} | ||
|
||
// uri is of the form: wasb(s)://[email protected]/testDir | ||
private org.apache.hadoop.fs.FileSystem createInitializedAzureFS( | ||
URI fsUri, Configuration flinkConfig) throws IOException { | ||
LOG.info("Trying to load and instantiate Azure File System for {}", fsUri); | ||
org.apache.hadoop.conf.Configuration hadoopConfig = configLoader.getOrLoadHadoopConfig(); | ||
|
||
org.apache.hadoop.fs.FileSystem azureFS = new NativeAzureFileSystem(); | ||
azureFS.initialize(fsUri, hadoopConfig); | ||
|
||
return azureFS; | ||
org.apache.hadoop.fs.FileSystem fs = createAzureFS(); | ||
fs.initialize(fsUri, hadoopConfig); | ||
return new HadoopFileSystem(fs); | ||
} | ||
} |
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
36 changes: 36 additions & 0 deletions
36
...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,36 @@ | ||
/* | ||
* 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; | ||
|
||
import org.apache.hadoop.fs.FileSystem; | ||
import org.apache.hadoop.fs.azurebfs.AzureBlobFileSystem; | ||
|
||
/** Secure ABFS AzureFS implementation. */ | ||
public class SecureABFSAzureFSFactory extends AbstractAzureFSFactory { | ||
|
||
@Override | ||
public String getScheme() { | ||
return "abfss"; | ||
} | ||
|
||
@Override | ||
FileSystem createAzureFS() { | ||
return new AzureBlobFileSystem(); | ||
} | ||
} |
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
72 changes: 72 additions & 0 deletions
72
...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,72 @@ | ||
/* | ||
* 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; | ||
|
||
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