Package org.apache.flink.core.fs

Examples of org.apache.flink.core.fs.FileSystem


   
    // get the file info and check whether the cached statistics are still valid.
    for(org.apache.hadoop.fs.Path hadoopPath : hadoopFilePaths) {
     
      final Path filePath = new Path(hadoopPath.toUri());
      final FileSystem fs = FileSystem.get(filePath.toUri());
     
      final FileStatus file = fs.getFileStatus(filePath);
      latestModTime = Math.max(latestModTime, file.getModificationTime());
     
      // enumerate all files and check their modification time stamp.
      if (file.isDir()) {
        FileStatus[] fss = fs.listStatus(filePath);
        files.ensureCapacity(files.size() + fss.length);
       
        for (FileStatus s : fss) {
          if (!s.isDir()) {
            files.add(s);
View Full Code Here


      }
    }
  }

  public static void copy(Path sourcePath, Path targetPath, boolean executable) throws IOException {
    FileSystem sFS = sourcePath.getFileSystem();
    FileSystem tFS = targetPath.getFileSystem();
    if (!tFS.exists(targetPath)) {
      if (sFS.getFileStatus(sourcePath).isDir()) {
        tFS.mkdirs(targetPath);
        FileStatus[] contents = sFS.listStatus(sourcePath);
        for (FileStatus content : contents) {
          String distPath = content.getPath().toString();
          if (content.isDir()) {
            if (distPath.endsWith("/")) {
              distPath = distPath.substring(0, distPath.length() - 1);
            }
          }
          String localPath = targetPath.toString() + distPath.substring(distPath.lastIndexOf("/"));
          copy(content.getPath(), new Path(localPath), executable);
        }
      } else {
        try {
          FSDataOutputStream lfsOutput = tFS.create(targetPath, false);
          FSDataInputStream fsInput = sFS.open(sourcePath);
          IOUtils.copyBytes(fsInput, lfsOutput);
          new File(targetPath.toString()).setExecutable(executable);
        } catch (IOException ioe) {
          LOG.error("could not copy file to local file cache.", ioe);
View Full Code Here

    Path p = this.outputFilePath;
    if (p == null) {
      throw new IOException("The file path is null.");
    }
   
    final FileSystem fs = p.getFileSystem();

    // if this is a local file system, we need to initialize the local output directory here
    if (!fs.isDistributedFS()) {
     
      if (numTasks == 1 && outputDirectoryMode == OutputDirectoryMode.PARONLY) {
        // output should go to a single file
       
        // prepare local output path. checks for write mode and removes existing files in case of OVERWRITE mode
        if(!fs.initOutPathLocalFS(p, writeMode, false)) {
          // output preparation failed! Cancel task.
          throw new IOException("Output path '" + p.toString() + "' could not be initialized. Canceling task...");
        }
      }
      else {
        // numTasks > 1 || outDirMode == OutputDirectoryMode.ALWAYS
       
        if(!fs.initOutPathLocalFS(p, writeMode, true)) {
          // output preparation failed! Cancel task.
          throw new IOException("Output directory '" + p.toString() + "' could not be created. Canceling task...");
        }
      }
    }
     
     
    // Suffix the path with the parallel instance index, if needed
    this.actualFilePath = (numTasks > 1 || outputDirectoryMode == OutputDirectoryMode.ALWAYS) ? p.suffix("/" + (taskNumber+1)) : p;

    // create output file
    this.stream = fs.create(this.actualFilePath, writeMode == WriteMode.OVERWRITE);
   
    // at this point, the file creation must have succeeded, or an exception has been thrown
    this.fileCreated = true;
  }
View Full Code Here

   * @param parallelism The task parallelism.
   */
  @Override
  public void initializeGlobal(int parallelism) throws IOException {
    final Path path = getOutputFilePath();
    final FileSystem fs = path.getFileSystem();
   
    // only distributed file systems can be initialized at start-up time.
    if (fs.isDistributedFS()) {
     
      final WriteMode writeMode = getWriteMode();
      final OutputDirectoryMode outDirMode = getOutputDirectoryMode();

      if (parallelism == 1 && outDirMode == OutputDirectoryMode.PARONLY) {
        // output is not written in parallel and should be written to a single file.
        // prepare distributed output path
        if(!fs.initOutPathDistFS(path, writeMode, false)) {
          // output preparation failed! Cancel task.
          throw new IOException("Output path could not be initialized.");
        }

      } else {
        // output should be written to a directory

        // only distributed file systems can be initialized at start-up time.
        if(!fs.initOutPathDistFS(path, writeMode, true)) {
          throw new IOException("Output directory could not be created.");
        }
      }
    }
  }
View Full Code Here

    final int oldLineLengthLimit = this.lineLengthLimit;
    try {
      final Path filePath = this.filePath;
   
      // get the filesystem
      final FileSystem fs = FileSystem.get(filePath.toUri());
      final ArrayList<FileStatus> allFiles = new ArrayList<FileStatus>(1);
     
      // let the file input format deal with the up-to-date check and the basic size
      final FileBaseStatistics stats = getFileStats(cachedFileStats, filePath, fs, allFiles);
      if (stats == null) {
View Full Code Here

      bc = new BlobClient(serverAddress);

      for (final Iterator<Path> it = this.userJars.iterator(); it.hasNext();) {

        final Path jar = it.next();
        final FileSystem fs = jar.getFileSystem();
        FSDataInputStream is = null;
        try {
          is = fs.open(jar);
          final BlobKey key = bc.put(is);
          this.userJarBlobKeys.add(key);
        } finally {
          if (is != null) {
            is.close();
View Full Code Here

      try {
        URI u = new URI(entry.filePath);
        if (!u.getPath().startsWith("/")) {
          u = new File(entry.filePath).toURI();
        }
        FileSystem fs = FileSystem.get(u);
        if (fs.exists(new Path(u.getPath()))) {
          this.cacheFile.put(name, new DistributedCacheEntry(u.toString(), entry.isExecutable));
        } else {
          throw new IOException("File " + u.toString() + " doesn't exist.");
        }
      } catch (URISyntaxException ex) {
View Full Code Here

  @Override
  public FileInputSplit[] createInputSplits(int minNumSplits) throws IOException {
    List<FileStatus> files = this.getFiles();

    final FileSystem fs = this.filePath.getFileSystem();
    final long blockSize = this.blockSize == NATIVE_BLOCK_SIZE ? fs.getDefaultBlockSize() : this.blockSize;

    final List<FileInputSplit> inputSplits = new ArrayList<FileInputSplit>(minNumSplits);
    for (FileStatus file : files) {
      long splitSize = blockSize;
      for (long pos = 0, length = file.getLen(); pos < length; pos += splitSize) {
        long remainingLength = Math.min(pos + splitSize, length) - pos;

        // get the block locations and make sure they are in order with respect to their offset
        final BlockLocation[] blocks = fs.getFileBlockLocations(file, pos, remainingLength);
        Arrays.sort(blocks);

        inputSplits.add(new FileInputSplit(inputSplits.size(), file.getPath(), pos, remainingLength,
          blocks[0].getHosts()));
      }
    }

    if (inputSplits.size() < minNumSplits) {
      LOG.warn(String.format(
        "With the given block size %d, the file %s cannot be split into %d blocks. Filling up with empty splits...",
        blockSize, this.filePath, minNumSplits));
      FileStatus last = files.get(files.size() - 1);
      final BlockLocation[] blocks = fs.getFileBlockLocations(last, 0, last.getLen());
      for (int index = files.size(); index < minNumSplits; index++) {
        inputSplits.add(new FileInputSplit(index, last.getPath(), last.getLen(), 0, blocks[0].getHosts()));
      }
    }
View Full Code Here

  protected List<FileStatus> getFiles() throws IOException {
    // get all the files that are involved in the splits
    List<FileStatus> files = new ArrayList<FileStatus>();

    final FileSystem fs = this.filePath.getFileSystem();
    final FileStatus pathFile = fs.getFileStatus(this.filePath);

    if (pathFile.isDir()) {
      // input is directory. list all contained files
      final FileStatus[] partials = fs.listStatus(this.filePath);
      for (int i = 0; i < partials.length; i++) {
        if (!partials[i].isDir()) {
          files.add(partials[i]);
        }
      }
View Full Code Here

    try {
      final Path filePath = this.filePath;

      // get the filesystem
      final FileSystem fs = FileSystem.get(filePath.toUri());
      final ArrayList<FileStatus> allFiles = new ArrayList<FileStatus>(1);

      // let the file input format deal with the up-to-date check and the basic size
      final FileBaseStatistics stats = getFileStats(cachedFileStats, filePath, fs, allFiles);
      if (stats == null) {
View Full Code Here

TOP

Related Classes of org.apache.flink.core.fs.FileSystem

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.