org.apache.hadoop.fs.FileUtil.symLink()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(11.3k)|赞(0)|评价(0)|浏览(180)

本文整理了Java中org.apache.hadoop.fs.FileUtil.symLink()方法的一些代码示例,展示了FileUtil.symLink()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FileUtil.symLink()方法的具体详情如下:
包路径:org.apache.hadoop.fs.FileUtil
类名称:FileUtil
方法名:symLink

FileUtil.symLink介绍

[英]Create a soft link between a src and destination only on a local disk. HDFS does not support this
[中]仅在本地磁盘上的src和目标之间创建软链接。HDFS不支持这一点

代码示例

代码示例来源:origin: org.apache.hadoop/hadoop-common

@SuppressWarnings("deprecation")
@Override
public void createSymlink(Path target, Path link, boolean createParent)
  throws IOException {
 if (!FileSystem.areSymlinksEnabled()) {
  throw new UnsupportedOperationException("Symlinks not supported");
 }
 final String targetScheme = target.toUri().getScheme();
 if (targetScheme != null && !"file".equals(targetScheme)) {
  throw new IOException("Unable to create symlink to non-local file "+
             "system: "+target.toString());
 }
 if (createParent) {
  mkdirs(link.getParent());
 }
 // NB: Use createSymbolicLink in java.nio.file.Path once available
 int result = FileUtil.symLink(target.toString(),
   makeAbsolute(link).toString());
 if (result != 0) {
  throw new IOException("Error " + result + " creating symlink " +
    link + " to " + target);
 }
}

代码示例来源:origin: apache/hive

String target = p.toUri().getPath();
String link = workDir + Path.SEPARATOR + p.getName();
if (FileUtil.symLink(target, link) != 0) {
 throw new IOException("Cannot link to added file: " + target + " from: " + link);

代码示例来源:origin: apache/drill

String target = p.toUri().getPath();
String link = workDir + Path.SEPARATOR + p.getName();
if (FileUtil.symLink(target, link) != 0) {
 throw new IOException("Cannot link to added file: " + target + " from: " + link);

代码示例来源:origin: apache/hive

String target = p.toUri().getPath();
String link = workDir + Path.SEPARATOR + p.getName();
if (FileUtil.symLink(target, link) != 0) {
 throw new IOException ("Cannot link to added file: " + target + " from: " + link);

代码示例来源:origin: apache/drill

String target = p.toUri().getPath();
String link = workDir + Path.SEPARATOR + p.getName();
if (FileUtil.symLink(target, link) != 0) {
 throw new IOException ("Cannot link to added file: " + target + " from: " + link);

代码示例来源:origin: org.apache.hadoop/hadoop-yarn-server-nodemanager

@Override
public void symLink(String target, String symlink) throws IOException {
 FileUtil.symLink(target, symlink);
}

代码示例来源:origin: org.apache.hadoop/hadoop-mapred

/**
 * Utility method for creating a symlink and warning on errors.
 * 
 * If link is null, does nothing.
 */
private static void symlink(File workDir, String target, String link)
  throws IOException {
 if (link != null) {
  link = workDir.toString() + Path.SEPARATOR + link;
  File flink = new File(link);
  if (!flink.exists()) {
   LOG.info(String.format("Creating symlink: %s <- %s", target, link));
   if (0 != FileUtil.symLink(target, link)) {
    LOG.warn(String.format("Failed to create symlink: %s <- %s", target, link));
   }
  }
 }
}

代码示例来源:origin: org.apache.hadoop/hadoop-mapred-test

/**
 * Creates 1 subdirectory and 1 file under dir2. Creates 1 subdir, 1 file,
 * 1 symlink to a dir and a symlink to a file under dir1.
 * Creates dir1/subDir, dir1/file, dir2/subDir, dir2/file,
 * dir1/symlinkSubDir->dir2/subDir, dir1/symlinkFile->dir2/file.
 */
static void createSubDirsAndSymLinks(JobConf jobConf, Path dir1, Path dir2)
   throws IOException {
 FileSystem fs = FileSystem.getLocal(jobConf);
 createSubDirAndFile(fs, dir1);
 createSubDirAndFile(fs, dir2);
 // now create symlinks under dir1 that point to file/dir under dir2
 FileUtil.symLink(dir2+"/subDir", dir1+"/symlinkSubDir");
 FileUtil.symLink(dir2+"/file", dir1+"/symlinkFile");
}

代码示例来源:origin: org.apache.hadoop/hadoop-mapreduce-client-common

/**
 * Utility method for creating a symlink and warning on errors.
 *
 * If link is null, does nothing.
 */
private void symlink(File workDir, String target, String link)
  throws IOException {
 if (link != null) {
  link = workDir.toString() + Path.SEPARATOR + link;
  File flink = new File(link);
  if (!flink.exists()) {
   LOG.info(String.format("Creating symlink: %s <- %s", target, link));
   if (0 != FileUtil.symLink(target, link)) {
    LOG.warn(String.format("Failed to create symlink: %s <- %s", target,
      link));
   } else {
    symlinksCreated.add(new File(link));
   }
  }
 }
}

代码示例来源:origin: com.github.jiayuhan-it/hadoop-mapreduce-client-common

/**
 * Utility method for creating a symlink and warning on errors.
 *
 * If link is null, does nothing.
 */
private void symlink(File workDir, String target, String link)
  throws IOException {
 if (link != null) {
  link = workDir.toString() + Path.SEPARATOR + link;
  File flink = new File(link);
  if (!flink.exists()) {
   LOG.info(String.format("Creating symlink: %s <- %s", target, link));
   if (0 != FileUtil.symLink(target, link)) {
    LOG.warn(String.format("Failed to create symlink: %s <- %s", target,
      link));
   } else {
    symlinksCreated.add(new File(link));
   }
  }
 }
}

代码示例来源:origin: com.facebook.hadoop/hadoop-core

private static void createSymlink(Configuration conf, URI cache,
  CacheStatus cacheStatus, boolean isArchive,
  Path currentWorkDir, boolean honorSymLinkConf) throws IOException {
 boolean doSymlink = honorSymLinkConf && DistributedCache.getSymlink(conf);
 if(cache.getFragment() == null) {
  doSymlink = false;
 }
 String link =
  currentWorkDir.toString() + Path.SEPARATOR + cache.getFragment();
 File flink = new File(link);
 if (doSymlink){
  if (!flink.exists()) {
   FileUtil.symLink(cacheStatus.localizedLoadPath.toString(), link);
  }
 }
}

代码示例来源:origin: org.apache.hadoop/hadoop-mapred

private void createSymlink(Configuration conf, URI cache,
  CacheStatus cacheStatus, boolean isArchive,
  Path currentWorkDir, boolean honorSymLinkConf) throws IOException {
 boolean doSymlink = honorSymLinkConf && DistributedCache.getSymlink(conf);
 if(cache.getFragment() == null) {
  doSymlink = false;
 }
 String link = 
  currentWorkDir.toString() + Path.SEPARATOR + cache.getFragment();
 File flink = new File(link);
 if (doSymlink){
  if (!flink.exists()) {
   FileUtil.symLink(cacheStatus.localizedLoadPath.toString(), link);
  }
 }
}

代码示例来源:origin: io.hops/hadoop-mapreduce-client-common

/**
 * Utility method for creating a symlink and warning on errors.
 *
 * If link is null, does nothing.
 */
private void symlink(File workDir, String target, String link)
  throws IOException {
 if (link != null) {
  link = workDir.toString() + Path.SEPARATOR + link;
  File flink = new File(link);
  if (!flink.exists()) {
   LOG.info(String.format("Creating symlink: %s <- %s", target, link));
   if (0 != FileUtil.symLink(target, link)) {
    LOG.warn(String.format("Failed to create symlink: %s <- %s", target,
      link));
   } else {
    symlinksCreated.add(new File(link));
   }
  }
 }
}

代码示例来源:origin: org.jvnet.hudson.hadoop/hadoop-core

/**
 * This method create symlinks for all files in a given dir in another directory
 * @param conf the configuration
 * @param jobCacheDir the target directory for creating symlinks
 * @param workDir the directory in which the symlinks are created
 * @throws IOException
 */
public static void createAllSymlink(Configuration conf, File jobCacheDir, File workDir)
 throws IOException{
 if ((jobCacheDir == null || !jobCacheDir.isDirectory()) ||
     workDir == null || (!workDir.isDirectory())) {
  return;
 }
 boolean createSymlink = getSymlink(conf);
 if (createSymlink){
  File[] list = jobCacheDir.listFiles();
  for (int i=0; i < list.length; i++){
   FileUtil.symLink(list[i].getAbsolutePath(),
            new File(workDir, list[i].getName()).toString());
  }
 }  
}

代码示例来源:origin: ch.cern.hadoop/hadoop-common

@SuppressWarnings("deprecation")
@Override
public void createSymlink(Path target, Path link, boolean createParent)
  throws IOException {
 if (!FileSystem.areSymlinksEnabled()) {
  throw new UnsupportedOperationException("Symlinks not supported");
 }
 final String targetScheme = target.toUri().getScheme();
 if (targetScheme != null && !"file".equals(targetScheme)) {
  throw new IOException("Unable to create symlink to non-local file "+
             "system: "+target.toString());
 }
 if (createParent) {
  mkdirs(link.getParent());
 }
 // NB: Use createSymbolicLink in java.nio.file.Path once available
 int result = FileUtil.symLink(target.toString(),
   makeAbsolute(link).toString());
 if (result != 0) {
  throw new IOException("Error " + result + " creating symlink " +
    link + " to " + target);
 }
}

代码示例来源:origin: io.hops/hadoop-common

@SuppressWarnings("deprecation")
@Override
public void createSymlink(Path target, Path link, boolean createParent)
  throws IOException {
 if (!FileSystem.areSymlinksEnabled()) {
  throw new UnsupportedOperationException("Symlinks not supported");
 }
 final String targetScheme = target.toUri().getScheme();
 if (targetScheme != null && !"file".equals(targetScheme)) {
  throw new IOException("Unable to create symlink to non-local file "+
             "system: "+target.toString());
 }
 if (createParent) {
  mkdirs(link.getParent());
 }
 // NB: Use createSymbolicLink in java.nio.file.Path once available
 int result = FileUtil.symLink(target.toString(),
   makeAbsolute(link).toString());
 if (result != 0) {
  throw new IOException("Error " + result + " creating symlink " +
    link + " to " + target);
 }
}

代码示例来源:origin: com.github.jiayuhan-it/hadoop-common

@SuppressWarnings("deprecation")
@Override
public void createSymlink(Path target, Path link, boolean createParent)
  throws IOException {
 if (!FileSystem.areSymlinksEnabled()) {
  throw new UnsupportedOperationException("Symlinks not supported");
 }
 final String targetScheme = target.toUri().getScheme();
 if (targetScheme != null && !"file".equals(targetScheme)) {
  throw new IOException("Unable to create symlink to non-local file "+
             "system: "+target.toString());
 }
 if (createParent) {
  mkdirs(link.getParent());
 }
 // NB: Use createSymbolicLink in java.nio.file.Path once available
 int result = FileUtil.symLink(target.toString(),
   makeAbsolute(link).toString());
 if (result != 0) {
  throw new IOException("Error " + result + " creating symlink " +
    link + " to " + target);
 }
}

代码示例来源:origin: io.prestosql.hadoop/hadoop-apache

@SuppressWarnings("deprecation")
@Override
public void createSymlink(Path target, Path link, boolean createParent)
  throws IOException {
 if (!FileSystem.areSymlinksEnabled()) {
  throw new UnsupportedOperationException("Symlinks not supported");
 }
 final String targetScheme = target.toUri().getScheme();
 if (targetScheme != null && !"file".equals(targetScheme)) {
  throw new IOException("Unable to create symlink to non-local file "+
             "system: "+target.toString());
 }
 if (createParent) {
  mkdirs(link.getParent());
 }
 // NB: Use createSymbolicLink in java.nio.file.Path once available
 int result = FileUtil.symLink(target.toString(),
   makeAbsolute(link).toString());
 if (result != 0) {
  throw new IOException("Error " + result + " creating symlink " +
    link + " to " + target);
 }
}

代码示例来源:origin: com.github.jiayuhan-it/hadoop-common

/**
 * Test that deletion of a symlink works as expected.
 */
@Test (timeout = 30000)
public void testSymlinkDelete() throws Exception {
 Assert.assertFalse(del.exists());
 del.mkdirs();
 File file = new File(del, FILE);
 file.createNewFile();
 File link = new File(del, "_link");
 // create the symlink
 FileUtil.symLink(file.getAbsolutePath(), link.getAbsolutePath());
 Assert.assertTrue(file.exists());
 Assert.assertTrue(link.exists());
 // make sure that deleting a symlink works properly
 Assert.assertTrue(link.delete());
 Assert.assertFalse(link.exists());
 Assert.assertTrue(file.exists());
}

代码示例来源:origin: ch.cern.hadoop/hadoop-common

/**
 * Test that deletion of a symlink works as expected.
 */
@Test (timeout = 30000)
public void testSymlinkDelete() throws Exception {
 Assert.assertFalse(del.exists());
 del.mkdirs();
 File file = new File(del, FILE);
 file.createNewFile();
 File link = new File(del, "_link");
 // create the symlink
 FileUtil.symLink(file.getAbsolutePath(), link.getAbsolutePath());
 Assert.assertTrue(file.exists());
 Assert.assertTrue(link.exists());
 // make sure that deleting a symlink works properly
 Assert.assertTrue(link.delete());
 Assert.assertFalse(link.exists());
 Assert.assertTrue(file.exists());
}

相关文章