Java Code Examples for org.apache.hadoop.fs.FileUtil#list()

The following examples show how to use org.apache.hadoop.fs.FileUtil#list() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FsVolumeImpl.java    From hadoop with Apache License 2.0 6 votes vote down vote up
boolean isBPDirEmpty(String bpid) throws IOException {
  File volumeCurrentDir = this.getCurrentDir();
  File bpDir = new File(volumeCurrentDir, bpid);
  File bpCurrentDir = new File(bpDir, DataStorage.STORAGE_DIR_CURRENT);
  File finalizedDir = new File(bpCurrentDir,
      DataStorage.STORAGE_DIR_FINALIZED);
  File rbwDir = new File(bpCurrentDir, DataStorage.STORAGE_DIR_RBW);
  if (finalizedDir.exists() && !DatanodeUtil.dirNoFilesRecursive(
      finalizedDir)) {
    return false;
  }
  if (rbwDir.exists() && FileUtil.list(rbwDir).length != 0) {
    return false;
  }
  return true;
}
 
Example 2
Source File: BlockPoolSliceStorage.java    From hadoop with Apache License 2.0 6 votes vote down vote up
/**
 * Cleanup the detachDir.
 * 
 * If the directory is not empty report an error; Otherwise remove the
 * directory.
 * 
 * @param detachDir detach directory
 * @throws IOException if the directory is not empty or it can not be removed
 */
private void cleanupDetachDir(File detachDir) throws IOException {
  if (!DataNodeLayoutVersion.supports(
      LayoutVersion.Feature.APPEND_RBW_DIR, layoutVersion)
      && detachDir.exists() && detachDir.isDirectory()) {

    if (FileUtil.list(detachDir).length != 0) {
      throw new IOException("Detached directory " + detachDir
          + " is not empty. Please manually move each file under this "
          + "directory to the finalized directory if the finalized "
          + "directory tree does not have the file.");
    } else if (!detachDir.delete()) {
      throw new IOException("Cannot remove directory " + detachDir);
    }
  }
}
 
Example 3
Source File: DataStorage.java    From hadoop with Apache License 2.0 6 votes vote down vote up
/**
 * Cleanup the detachDir. 
 * 
 * If the directory is not empty report an error; 
 * Otherwise remove the directory.
 * 
 * @param detachDir detach directory
 * @throws IOException if the directory is not empty or it can not be removed
 */
private void cleanupDetachDir(File detachDir) throws IOException {
  if (!DataNodeLayoutVersion.supports(
      LayoutVersion.Feature.APPEND_RBW_DIR, layoutVersion) &&
      detachDir.exists() && detachDir.isDirectory() ) {
    
      if (FileUtil.list(detachDir).length != 0 ) {
        throw new IOException("Detached directory " + detachDir +
            " is not empty. Please manually move each file under this " +
            "directory to the finalized directory if the finalized " +
            "directory tree does not have the file.");
      } else if (!detachDir.delete()) {
        throw new IOException("Cannot remove directory " + detachDir);
      }
  }
}
 
Example 4
Source File: FsVolumeImpl.java    From big-c with Apache License 2.0 6 votes vote down vote up
boolean isBPDirEmpty(String bpid) throws IOException {
  File volumeCurrentDir = this.getCurrentDir();
  File bpDir = new File(volumeCurrentDir, bpid);
  File bpCurrentDir = new File(bpDir, DataStorage.STORAGE_DIR_CURRENT);
  File finalizedDir = new File(bpCurrentDir,
      DataStorage.STORAGE_DIR_FINALIZED);
  File rbwDir = new File(bpCurrentDir, DataStorage.STORAGE_DIR_RBW);
  if (finalizedDir.exists() && !DatanodeUtil.dirNoFilesRecursive(
      finalizedDir)) {
    return false;
  }
  if (rbwDir.exists() && FileUtil.list(rbwDir).length != 0) {
    return false;
  }
  return true;
}
 
Example 5
Source File: BlockPoolSliceStorage.java    From big-c with Apache License 2.0 6 votes vote down vote up
/**
 * Cleanup the detachDir.
 * 
 * If the directory is not empty report an error; Otherwise remove the
 * directory.
 * 
 * @param detachDir detach directory
 * @throws IOException if the directory is not empty or it can not be removed
 */
private void cleanupDetachDir(File detachDir) throws IOException {
  if (!DataNodeLayoutVersion.supports(
      LayoutVersion.Feature.APPEND_RBW_DIR, layoutVersion)
      && detachDir.exists() && detachDir.isDirectory()) {

    if (FileUtil.list(detachDir).length != 0) {
      throw new IOException("Detached directory " + detachDir
          + " is not empty. Please manually move each file under this "
          + "directory to the finalized directory if the finalized "
          + "directory tree does not have the file.");
    } else if (!detachDir.delete()) {
      throw new IOException("Cannot remove directory " + detachDir);
    }
  }
}
 
Example 6
Source File: DataStorage.java    From big-c with Apache License 2.0 6 votes vote down vote up
/**
 * Cleanup the detachDir. 
 * 
 * If the directory is not empty report an error; 
 * Otherwise remove the directory.
 * 
 * @param detachDir detach directory
 * @throws IOException if the directory is not empty or it can not be removed
 */
private void cleanupDetachDir(File detachDir) throws IOException {
  if (!DataNodeLayoutVersion.supports(
      LayoutVersion.Feature.APPEND_RBW_DIR, layoutVersion) &&
      detachDir.exists() && detachDir.isDirectory() ) {
    
      if (FileUtil.list(detachDir).length != 0 ) {
        throw new IOException("Detached directory " + detachDir +
            " is not empty. Please manually move each file under this " +
            "directory to the finalized directory if the finalized " +
            "directory tree does not have the file.");
      } else if (!detachDir.delete()) {
        throw new IOException("Cannot remove directory " + detachDir);
      }
  }
}
 
Example 7
Source File: DefaultSourceFSConfigurationProvider.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
public Configuration getConf(Configuration sinkConf, String replicationClusterId)
    throws IOException {
  if (sourceClustersConfs.get(replicationClusterId) == null) {
    synchronized (this.sourceClustersConfs) {
      if (sourceClustersConfs.get(replicationClusterId) == null) {
        LOG.info("Loading source cluster FS client conf for cluster " + replicationClusterId);
        // Load only user provided client configurations.
        Configuration sourceClusterConf = new Configuration(false);

        String replicationConfDir = sinkConf.get(HConstants.REPLICATION_CONF_DIR);
        if (replicationConfDir == null) {
          LOG.debug(HConstants.REPLICATION_CONF_DIR + " is not configured.");
          URL resource = HBaseConfiguration.class.getClassLoader().getResource("hbase-site.xml");
          if (resource != null) {
            String path = resource.getPath();
            replicationConfDir = path.substring(0, path.lastIndexOf("/"));
          } else {
            replicationConfDir = System.getenv("HBASE_CONF_DIR");
          }
        }

        File confDir = new File(replicationConfDir, replicationClusterId);
        LOG.info("Loading source cluster " + replicationClusterId
                + " file system configurations from xml "
                + "files under directory " + confDir);
        String[] listofConfFiles = FileUtil.list(confDir);
        for (String confFile : listofConfFiles) {
          if (new File(confDir, confFile).isFile() && confFile.endsWith(XML)) {
            // Add all the user provided client conf files
            sourceClusterConf.addResource(new Path(confDir.getPath(), confFile));
          }
        }
        this.sourceClustersConfs.put(replicationClusterId, sourceClusterConf);
      }
    }
  }
  return this.sourceClustersConfs.get(replicationClusterId);
}