Package eu.stratosphere.core.fs

Examples of eu.stratosphere.core.fs.FileSystem


      throw new IllegalConfigurationException(this.getName() + " does not specify an input path");
    }

    // Check if the path is valid
    try {
      final FileSystem fs = this.path.getFileSystem();
      final FileStatus f = fs.getFileStatus(this.path);
      if (f == null) {
        throw new IOException(this.path.toString() + " led to a null object");
      }
    } catch (IOException e) {
      throw new IllegalConfigurationException("Cannot access file or directory: "
View Full Code Here


    if (this.path == null) {
      return -1;
    }

    try {
      final FileSystem fs = this.path.getFileSystem();
      final FileStatus f = fs.getFileStatus(this.path);
      numberOfBlocks = fs.getNumberOfBlocks(f);

    } catch (IOException e) {
      return -1;
    }
View Full Code Here

      return 0;
    }

    // Check if the path is valid
    try {
      final FileSystem fs = path.getFileSystem();

      try {
        final FileStatus f = fs.getFileStatus(path);

        if (f == null) {
          return 1;
        }

        // If the path points to a directory we allow an infinity number of subtasks
        if (f.isDir()) {
          return -1;
        }
      } catch (FileNotFoundException fnfex) {
        // The exception is thrown if the requested file/directory does not exist.
        // if the degree of parallelism is > 1, we create a directory for this path
        if (getNumberOfSubtasks() > 1) {
          fs.mkdirs(path);
          return -1;
        } else {
          // a none existing file and a degree of parallelism that is one
          return 1;
        }
View Full Code Here

   *         thrown if an error occurs while writing to the stream
   */
  private void writeRequiredJarFiles(final DataOutput out, final AbstractJobVertex[] jobVertices) throws IOException {

    // Now check if all the collected jar files really exist
    final FileSystem fs = FileSystem.getLocalFileSystem();

    for (int i = 0; i < this.userJars.size(); i++) {
      if (!fs.exists(this.userJars.get(i))) {
        throw new IOException("Cannot find jar file " + this.userJars.get(i));
      }
    }

    // How many jar files follow?
    out.writeInt(this.userJars.size());

    for (int i = 0; i < this.userJars.size(); i++) {

      final Path jar = this.userJars.get(i);

      // Write out the actual path
      jar.write(out);

      // Write out the length of the file
      final FileStatus file = fs.getFileStatus(jar);
      out.writeLong(file.getLen());

      // Now write the jar file
      final FSDataInputStream inStream = fs.open(this.userJars.get(i));
      final byte[] buf = new byte[BUFFERSIZE];
      int read = inStream.read(buf, 0, buf.length);
      while (read > 0) {
        out.write(buf, 0, read);
        read = inStream.read(buf, 0, buf.length);
View Full Code Here

      Path tmp = getTempDir(jobID, name);
      try {
        if (!lfs.exists(tmp)) {
          FSDataOutputStream lfsOutput = lfs.create(tmp, false);
          Path distributedPath = new Path(filePath);
          FileSystem fs = distributedPath.getFileSystem();
          FSDataInputStream fsInput = fs.open(distributedPath);
          IOUtils.copyBytes(fsInput, lfsOutput);
        }
      } catch (IOException e1) {
        throw new RuntimeException("Error copying a file from hdfs to the local fs", e1);
      }
View Full Code Here

    // Prepare output path and determine max DOP   
    try {
     
      int dop = getTaskConfiguration().getInteger(DEGREE_OF_PARALLELISM_KEY, -1);
      final FileSystem fs = path.getFileSystem();
     
      if(dop == 1 && outDirMode == OutputDirectoryMode.PARONLY) {
        // output is not written in parallel and should be written to a single file.
       
        if(fs.isDistributedFS()) {
          // prepare distributed output path
          if(!fs.initOutPathDistFS(path, writeMode, false)) {
            // output preparation failed! Cancel task.
            throw new IOException("Output path could not be initialized.");
          }
        }
       
        return 1;
       
      } else {
        // output should be written to a directory
       
        if(fs.isDistributedFS()) {
          // 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.");
          }
        }
       
        return -1;
View Full Code Here

    // get all the files that are involved in the splits
    final List<FileStatus> files = new ArrayList<FileStatus>();
    long totalLength = 0;

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

    if (pathFile.isDir()) {
      // input is directory. list all contained files
      final FileStatus[] dir = fs.listStatus(path);
      for (int i = 0; i < dir.length; i++) {
        if (!dir[i].isDir()) {
          files.add(dir[i]);
          totalLength += dir[i].getLen();
        }
      }

    } else {
      files.add(pathFile);
      totalLength += pathFile.getLen();
    }

    final long minSplitSize = 1;
    final long maxSplitSize = (minNumSplits < 1) ? Long.MAX_VALUE : (totalLength / minNumSplits +
          (totalLength % minNumSplits == 0 ? 0 : 1));

    // now that we have the files, generate the splits
    int splitNum = 0;
    for (final FileStatus file : files) {

      final long len = file.getLen();
      final long blockSize = file.getBlockSize();

      final long splitSize = Math.max(minSplitSize, Math.min(maxSplitSize, blockSize));
      final long halfSplit = splitSize >>> 1;

      final long maxBytesForLastSplit = (long) (splitSize * MAX_SPLIT_SIZE_DISCREPANCY);

      if (len > 0) {

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

        long bytesUnassigned = len;
        long position = 0;

        int blockIndex = 0;

        while (bytesUnassigned > maxBytesForLastSplit) {
          // get the block containing the majority of the data
          blockIndex = getBlockIndexForPosition(blocks, position, halfSplit, blockIndex);
          // create a new split
          final FileInputSplit fis = new FileInputSplit(splitNum++, file.getPath(), position, splitSize,
            blocks[blockIndex]
              .getHosts());
          inputSplits.add(fis);

          // adjust the positions
          position += splitSize;
          bytesUnassigned -= splitSize;
        }

        // assign the last split
        if (bytesUnassigned > 0) {
          blockIndex = getBlockIndexForPosition(blocks, position, halfSplit, blockIndex);
          final FileInputSplit fis = new FileInputSplit(splitNum++, file.getPath(), position,
            bytesUnassigned,
            blocks[blockIndex].getHosts());
          inputSplits.add(fis);
        }
      } else {
        // special case with a file of zero bytes size
        final BlockLocation[] blocks = fs.getFileBlockLocations(file, 0, 0);
        String[] hosts;
        if (blocks.length > 0) {
          hosts = blocks[0].getHosts();
        } else {
          hosts = new String[0];
View Full Code Here

  @Override
  public FileInputSplit[] createInputSplits(int minNumSplits) throws IOException {
    int numAvroFiles = 0;
    final Path path = this.filePath;
    // get all the files that are involved in the splits
    final FileSystem fs = path.getFileSystem();
    final FileStatus pathFile = fs.getFileStatus(path);

    if (!acceptFile(pathFile)) {
      throw new IOException("The given file does not pass the file-filter");
    }
    if (pathFile.isDir()) {
      // input is directory. list all contained files
      final FileStatus[] dir = fs.listStatus(path);
      for (int i = 0; i < dir.length; i++) {
        if (!dir[i].isDir() && acceptFile(dir[i])) {
          numAvroFiles++;
        }
      }
View Full Code Here

      final FileInputSplit split = splitIterator.next();

      long start = split.getStart();
      long length = split.getLength();

      final FileSystem fs = FileSystem.get(split.getPath().toUri());

      final FSDataInputStream fdis = fs.open(split.getPath());

      final LineReader lineReader = new LineReader(fdis, start, length, (1024 * 1024));

      byte[] line = lineReader.readLine();

View Full Code Here

  @Override
  public void invoke() throws Exception {

    Path outputPath = getFileOutputPath();

    FileSystem fs = FileSystem.get(outputPath.toUri());
    if (fs.exists(outputPath)) {
      FileStatus status = fs.getFileStatus(outputPath);

      if (status.isDir()) {
        outputPath = new Path(outputPath.toUri().toString() + "/file_" + getIndexInSubtaskGroup() + ".txt");
      }
    }

    final FSDataOutputStream outputStream = fs.create(outputPath, true);

    while (this.input.hasNext()) {

      StringRecord record = this.input.next();
      byte[] recordByte = (record.toString() + "\r\n").getBytes();
View Full Code Here

TOP

Related Classes of eu.stratosphere.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.