本文整理汇总了Java中org.apache.hadoop.fs.FileSystem.setWorkingDirectory方法的典型用法代码示例。如果您正苦于以下问题:Java FileSystem.setWorkingDirectory方法的具体用法?Java FileSystem.setWorkingDirectory怎么用?Java FileSystem.setWorkingDirectory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.hadoop.fs.FileSystem
的用法示例。
在下文中一共展示了FileSystem.setWorkingDirectory方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testWorkingdirectory
import org.apache.hadoop.fs.FileSystem; //导入方法依赖的package包/类
private void testWorkingdirectory() throws Exception {
FileSystem fs = FileSystem.get(getProxiedFSConf());
Path workingDir = fs.getWorkingDirectory();
fs.close();
fs = getHttpFSFileSystem();
if (isLocalFS()) {
fs.setWorkingDirectory(workingDir);
}
Path httpFSWorkingDir = fs.getWorkingDirectory();
fs.close();
Assert.assertEquals(httpFSWorkingDir.toUri().getPath(),
workingDir.toUri().getPath());
fs = getHttpFSFileSystem();
fs.setWorkingDirectory(new Path("/tmp"));
workingDir = fs.getWorkingDirectory();
fs.close();
Assert.assertEquals(workingDir.toUri().getPath(), new Path("/tmp").toUri().getPath());
}
示例2: setupForViewFileSystem
import org.apache.hadoop.fs.FileSystem; //导入方法依赖的package包/类
/**
*
* @param fsTarget - the target fs of the view fs.
* @return return the ViewFS File context to be used for tests
* @throws Exception
*/
static public FileSystem setupForViewFileSystem(Configuration conf, FileSystemTestHelper fileSystemTestHelper, FileSystem fsTarget) throws Exception {
/**
* create the test root on local_fs - the mount table will point here
*/
Path targetOfTests = fileSystemTestHelper.getTestRootPath(fsTarget);
// In case previous test was killed before cleanup
fsTarget.delete(targetOfTests, true);
fsTarget.mkdirs(targetOfTests);
// Set up viewfs link for test dir as described above
String testDir = fileSystemTestHelper.getTestRootPath(fsTarget).toUri()
.getPath();
linkUpFirstComponents(conf, testDir, fsTarget, "test dir");
// Set up viewfs link for home dir as described above
setUpHomeDir(conf, fsTarget);
// the test path may be relative to working dir - we need to make that work:
// Set up viewfs link for wd as described above
String wdDir = fsTarget.getWorkingDirectory().toUri().getPath();
linkUpFirstComponents(conf, wdDir, fsTarget, "working dir");
FileSystem fsView = FileSystem.get(FsConstants.VIEWFS_URI, conf);
fsView.setWorkingDirectory(new Path(wdDir)); // in case testdir relative to wd.
Log.info("Working dir is: " + fsView.getWorkingDirectory());
return fsView;
}
示例3: configFs
import org.apache.hadoop.fs.FileSystem; //导入方法依赖的package包/类
private void configFs(Map<String, Object> customConfigs) throws IOException {
for (String uri : this.conf.getFsUris()) {
Configuration fsConfig = new Configuration();
customConfigs.entrySet().stream()
.filter(entry -> entry.getKey().startsWith(FsSourceTaskConfig.POLICY_PREFIX_FS))
.forEach(entry -> fsConfig.set(entry.getKey().replace(FsSourceTaskConfig.POLICY_PREFIX_FS, ""),
(String) entry.getValue()));
Path workingDir = new Path(convert(uri));
FileSystem fs = FileSystem.newInstance(workingDir.toUri(), fsConfig);
fs.setWorkingDirectory(workingDir);
this.fileSystems.add(fs);
}
}
示例4: testWorkingDirectory
import org.apache.hadoop.fs.FileSystem; //导入方法依赖的package包/类
/**
* Tests get/set working directory in DFS.
*/
@Test
public void testWorkingDirectory() throws IOException {
Configuration conf = new HdfsConfiguration();
MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).build();
FileSystem fileSys = cluster.getFileSystem();
try {
Path orig_path = fileSys.getWorkingDirectory();
assertTrue(orig_path.isAbsolute());
Path file1 = new Path("somewhat/random.txt");
writeFile(fileSys, file1);
assertTrue(fileSys.exists(new Path(orig_path, file1.toString())));
fileSys.delete(file1, true);
Path subdir1 = new Path("/somewhere");
fileSys.setWorkingDirectory(subdir1);
writeFile(fileSys, file1);
cleanupFile(fileSys, new Path(subdir1, file1.toString()));
Path subdir2 = new Path("else");
fileSys.setWorkingDirectory(subdir2);
writeFile(fileSys, file1);
readFile(fileSys, file1);
cleanupFile(fileSys, new Path(new Path(subdir1, subdir2.toString()),
file1.toString()));
// test home directory
Path home =
fileSys.makeQualified(
new Path(DFSConfigKeys.DFS_USER_HOME_DIR_PREFIX_DEFAULT
+ "/" + getUserName(fileSys)));
Path fsHome = fileSys.getHomeDirectory();
assertEquals(home, fsHome);
} finally {
fileSys.close();
cluster.shutdown();
}
}