-
Notifications
You must be signed in to change notification settings - Fork 9.2k
HADOOP-14566. Add seek support for SFTP FileSystem. #1999
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
Changes from all commits
7f95e24
e0fa916
9fa1307
9896efd
46a2d51
fb098c7
6bad392
a9bc169
773284d
5bf201c
bd5f4df
5760937
86bdff3
4e823fd
3bc3e90
fb49a21
b874cdf
86bf896
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| /* | ||
| * 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.hadoop.fs.contract.sftp; | ||
|
|
||
| import java.io.IOException; | ||
| import java.io.UncheckedIOException; | ||
| import java.net.URI; | ||
| import java.util.ArrayList; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
|
|
||
| import org.apache.hadoop.conf.Configuration; | ||
| import org.apache.hadoop.fs.FileSystem; | ||
| import org.apache.hadoop.fs.FileSystemTestHelper; | ||
| import org.apache.hadoop.fs.Path; | ||
| import org.apache.hadoop.fs.contract.AbstractFSContract; | ||
| import org.apache.hadoop.fs.sftp.SFTPFileSystem; | ||
| import org.apache.sshd.common.NamedFactory; | ||
| import org.apache.sshd.server.SshServer; | ||
| import org.apache.sshd.server.auth.UserAuth; | ||
| import org.apache.sshd.server.auth.password.UserAuthPasswordFactory; | ||
| import org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider; | ||
| import org.apache.sshd.server.subsystem.sftp.SftpSubsystemFactory; | ||
|
|
||
| public class SFTPContract extends AbstractFSContract { | ||
|
|
||
| private static final String CONTRACT_XML = "contract/sftp.xml"; | ||
| private static final URI TEST_URI = | ||
| URI.create("sftp://user:password@localhost"); | ||
| private final String testDataDir = | ||
| new FileSystemTestHelper().getTestRootDir(); | ||
| private final Configuration conf; | ||
| private SshServer sshd; | ||
|
|
||
| public SFTPContract(Configuration conf) { | ||
| super(conf); | ||
| addConfResource(CONTRACT_XML); | ||
| this.conf = conf; | ||
| } | ||
|
|
||
| @Override | ||
| public void init() throws IOException { | ||
| sshd = SshServer.setUpDefaultServer(); | ||
| // ask OS to assign a port | ||
| sshd.setPort(0); | ||
| sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider()); | ||
|
|
||
| List<NamedFactory<UserAuth>> userAuthFactories = new ArrayList<>(); | ||
| userAuthFactories.add(new UserAuthPasswordFactory()); | ||
|
|
||
| sshd.setUserAuthFactories(userAuthFactories); | ||
| sshd.setPasswordAuthenticator((username, password, session) -> | ||
| username.equals("user") && password.equals("password") | ||
| ); | ||
|
|
||
| sshd.setSubsystemFactories( | ||
| Collections.singletonList(new SftpSubsystemFactory())); | ||
|
|
||
| sshd.start(); | ||
| int port = sshd.getPort(); | ||
|
|
||
| conf.setClass("fs.sftp.impl", SFTPFileSystem.class, FileSystem.class); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shouldn't this be set in core-default.xml already?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's not set in core-default.xml, and if not specified here sftp urls won't be resolved by sftp schema. Could you please clarify a bit what exactly you mean here? Thank you!
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. double checked, it's quite strange. Is it a candidate for an improvement issue? |
||
| conf.setInt("fs.sftp.host.port", port); | ||
| conf.setBoolean("fs.sftp.impl.disable.cache", true); | ||
| } | ||
|
|
||
| @Override | ||
| public void teardown() throws IOException { | ||
| if (sshd != null) { | ||
| sshd.stop(); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public FileSystem getTestFileSystem() throws IOException { | ||
| return FileSystem.get(TEST_URI, conf); | ||
| } | ||
|
|
||
| @Override | ||
| public String getScheme() { | ||
| return "sftp"; | ||
| } | ||
|
|
||
| @Override | ||
| public Path getTestPath() { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shame we didn't declare this as raising an ioe; probably too late now
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's not too late I suppose, would you like me to try to declare it as throwing IOE? I can issue a new Jira and fix it there. |
||
| try { | ||
| FileSystem fs = FileSystem.get( | ||
| URI.create("sftp://user:password@localhost"), conf | ||
| ); | ||
| return fs.makeQualified(new Path(testDataDir)); | ||
| } catch (IOException e) { | ||
| throw new UncheckedIOException(e); | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| /* | ||
| * 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.hadoop.fs.contract.sftp; | ||
|
|
||
| import org.apache.hadoop.conf.Configuration; | ||
| import org.apache.hadoop.fs.contract.AbstractContractSeekTest; | ||
| import org.apache.hadoop.fs.contract.AbstractFSContract; | ||
|
|
||
| public class TestSFTPContractSeek extends AbstractContractSeekTest { | ||
|
|
||
| @Override | ||
| protected AbstractFSContract createContract(Configuration conf) { | ||
| return new SFTPContract(conf); | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.