Package org.apache.hadoop.fs

Examples of org.apache.hadoop.fs.FileStatus


   * @return true if exists
   * @throws IOException
   */
  public static boolean isTableInfoExists(FileSystem fs, Path rootdir,
      String tableName) throws IOException {
    FileStatus status = getTableInfoPath(fs, rootdir, tableName);
    return status == null? false: fs.exists(status.getPath());
  }
View Full Code Here


   * @throws IOException
   */
  static long getTableInfoModtime(final FileSystem fs, final Path rootdir,
      final String tableName)
  throws IOException {
    FileStatus status = getTableInfoPath(fs, rootdir, tableName);
    return status == null? 0: status.getModificationTime();
  }
View Full Code Here

  }

  static TableDescriptorModtime getTableDescriptorModtime(FileSystem fs, Path tableDir)
  throws NullPointerException, IOException {
    if (tableDir == null) throw new NullPointerException();
    FileStatus status = getTableInfoPath(fs, tableDir);
    if (status == null) {
      throw new TableInfoMissingException("No .tableinfo file under "
          + tableDir.toUri());
    }
    FSDataInputStream fsDataInputStream = fs.open(status.getPath());
    HTableDescriptor hTableDescriptor = null;
    try {
      hTableDescriptor = new HTableDescriptor();
      hTableDescriptor.readFields(fsDataInputStream);
    } finally {
      fsDataInputStream.close();
    }
    return new TableDescriptorModtime(status.getModificationTime(), hTableDescriptor);
  }
View Full Code Here

   * tests.
   */
  public static void deleteTableDescriptorIfExists(String tableName,
      Configuration conf) throws IOException {
    FileSystem fs = FSUtils.getCurrentFileSystem(conf);
    FileStatus status = getTableInfoPath(fs, FSUtils.getRootDir(conf), tableName);
    // The below deleteDirectory works for either file or directory.
    if (status != null && fs.exists(status.getPath())) {
      FSUtils.deleteDirectory(fs, status.getPath());
    }
  }
View Full Code Here

   *         already exists and we weren't forcing the descriptor creation.
   * @throws IOException if a filesystem error occurs
   */
  public static boolean createTableDescriptorForTableDirectory(FileSystem fs, Path tabledir,
      HTableDescriptor htableDescriptor, boolean forceCreation) throws IOException {
    FileStatus status = getTableInfoPath(fs, tabledir);
    if (status != null) {
      LOG.info("Current tableInfoPath = " + status.getPath());
      if (!forceCreation) {
        if (fs.exists(status.getPath()) && status.getLen() > 0) {
          LOG.info("TableInfo already exists.. Skipping creation");
          return false;
        }
      }
    }
View Full Code Here

   * from the given directory.
   * @throws IOException
   */
  private List<StoreFile> loadStoreFiles() throws IOException {
    ArrayList<StoreFile> results = new ArrayList<StoreFile>();
    FileStatus files[] = getStoreFiles();

    if (files == null || files.length == 0) {
      return results;
    }
    // initialize the thread pool for opening store files in parallel..
View Full Code Here

  /**
   * compute HDFS block distribution, for reference file, it is an estimate
   */
  private void computeHDFSBlockDistribution() throws IOException {
    if (isReference()) {
      FileStatus status;
      if (this.link != null) {
        status = this.link.getFileStatus(fs);
      } else {
        status = fs.getFileStatus(this.referencePath);
      }
      this.hdfsBlocksDistribution = computeRefFileHDFSBlockDistribution(
        this.fs, this.reference, status);
    } else {
      FileStatus status;
      if (isLink()) {
        status = link.getFileStatus(fs);
      } else {
        status = this.fs.getFileStatus(path);
      }
      long length = status.getLen();
      this.hdfsBlocksDistribution = FSUtils.computeHDFSBlocksDistribution(
        this.fs, status, 0, length);
    }
  }
View Full Code Here

        return false;
      }

      try {
        // Verify if the input file exists
        FileStatus inputStat = getFileStatus(inputFs, inputPath);
        if (inputStat == null) return false;

        // Verify if the output file exists and is the same that we want to copy
        FileStatus outputStat = getFileStatus(outputFs, outputPath);
        if (outputStat != null && sameFile(inputStat, outputStat)) {
          LOG.info("Skip copy " + inputPath + " to " + outputPath + ", same file.");
          return true;
        }
View Full Code Here

    /**
     * Preserve the files attribute selected by the user copying them from the source file
     */
    private boolean preserveAttributes(final Path path, final FileStatus refStat) {
      FileStatus stat;
      try {
        stat = outputFs.getFileStatus(path);
      } catch (IOException e) {
        LOG.warn("Unable to get the status for file=" + path);
        return false;
      }

      try {
        if (filesMode > 0 && stat.getPermission().toShort() != filesMode) {
          outputFs.setPermission(path, new FsPermission(filesMode));
        } else if (!stat.getPermission().equals(refStat.getPermission())) {
          outputFs.setPermission(path, refStat.getPermission());
        }
      } catch (IOException e) {
        LOG.error("Unable to set the permission for file=" + path, e);
        return false;
      }

      try {
        String user = (filesUser != null) ? filesUser : refStat.getOwner();
        String group = (filesGroup != null) ? filesGroup : refStat.getGroup();
        if (!(user.equals(stat.getOwner()) && group.equals(stat.getGroup()))) {
          outputFs.setOwner(path, user, group);
        }
      } catch (IOException e) {
        LOG.error("Unable to set the owner/group for file=" + path, e);
        return false;
View Full Code Here

    return this.cache.contains(fileName);
  }

  private synchronized void refreshCache() throws IOException {
    // get the status of the snapshots directory
    FileStatus status;
    try {
      status = fs.getFileStatus(snapshotDir);
    } catch (FileNotFoundException e) {
      LOG.error("Snapshot directory: " + snapshotDir + " doesn't exist");
      return;
    }
    // if the snapshot directory wasn't modified since we last check, we are done
    if (status.getModificationTime() <= lastModifiedTime) return;

    // directory was modified, so we need to reload our cache
    // there could be a slight race here where we miss the cache, check the directory modification
    // time, then someone updates the directory, causing us to not scan the directory again.
    // However, snapshot directories are only created once, so this isn't an issue.

    // 1. update the modified time
    this.lastModifiedTime = status.getModificationTime();

    // 2.clear the cache
    this.cache.clear();
    Map<String, SnapshotDirectoryInfo> known = new HashMap<String, SnapshotDirectoryInfo>();
View Full Code Here

TOP

Related Classes of org.apache.hadoop.fs.FileStatus

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.