@Override public short getReplication() { return fileStatus.getReplication(); }
@Override public short getReplication() { return realStatus.getReplication(); }
@Override public short getReplication() { return myFs.getReplication(); }
/** * Get the replication factor. * * @deprecated Use {@link #getFileStatus(Path)} instead * @param src file name * @return file replication * @throws FileNotFoundException if the path does not resolve. * @throws IOException an IO failure */ @Deprecated public short getReplication(Path src) throws IOException { return getFileStatus(src).getReplication(); }
protected int getBlobReplication(String key) throws IOException { Path path = getKeyDir(key); Path dest = new Path(path, BLOBSTORE_DATA); return _fs.getFileStatus(dest).getReplication(); }
@Override public boolean apply(FileStatus input) { return input.getReplication() == replication && input.getBlockSize() == blockSize; } };
protected int updateBlobReplication(String key, int replication) throws IOException { Path path = getKeyDir(key); Path dest = new Path(path, BLOBSTORE_DATA); _fs.setReplication(dest, (short) replication); return _fs.getFileStatus(dest).getReplication(); }
/** * Returns a string representation of a Hadoop {@link FileStatus}. * * @param fs Hadoop {@link FileStatus} * @return its string representation */ public static String toStringHadoopFileStatus(FileStatus fs) { StringBuilder sb = new StringBuilder(); sb.append("HadoopFileStatus: Path: ").append(fs.getPath()); sb.append(" , Length: ").append(fs.getLen()); // Use isDir instead of isDirectory for compatibility with hadoop 1. sb.append(" , IsDir: ").append(fs.isDir()); sb.append(" , BlockReplication: ").append(fs.getReplication()); sb.append(" , BlockSize: ").append(fs.getBlockSize()); sb.append(" , ModificationTime: ").append(fs.getModificationTime()); sb.append(" , AccessTime: ").append(fs.getAccessTime()); sb.append(" , Permission: ").append(fs.getPermission()); sb.append(" , Owner: ").append(fs.getOwner()); sb.append(" , Group: ").append(fs.getGroup()); return sb.toString(); }
private FileStatus cloneStatus() throws IOException { return new FileStatus(status.getLen(), status.isDirectory(), status.getReplication(), status.getBlockSize(), status.getModificationTime(), status.getAccessTime(), null, null, null, status.isSymlink() ? status.getSymlink() : null, status.getPath()); } }
private Map<String, String> createAttributes(final FileStatus status) { final Map<String, String> attributes = new HashMap<>(); attributes.put(CoreAttributes.FILENAME.key(), status.getPath().getName()); attributes.put(CoreAttributes.PATH.key(), getAbsolutePath(status.getPath().getParent())); attributes.put("hdfs.owner", status.getOwner()); attributes.put("hdfs.group", status.getGroup()); attributes.put("hdfs.lastModified", String.valueOf(status.getModificationTime())); attributes.put("hdfs.length", String.valueOf(status.getLen())); attributes.put("hdfs.replication", String.valueOf(status.getReplication())); final FsPermission permission = status.getPermission(); final String perms = getPerms(permission.getUserAction()) + getPerms(permission.getGroupAction()) + getPerms(permission.getOtherAction()); attributes.put("hdfs.permissions", perms); return attributes; }
/** * Copy constructor. * * @param other FileStatus to copy */ public FileStatus(FileStatus other) throws IOException { // It's important to call the getters here instead of directly accessing the // members. Subclasses like ViewFsFileStatus can override the getters. this(other.getLen(), other.isDirectory(), other.getReplication(), other.getBlockSize(), other.getModificationTime(), other.getAccessTime(), other.getPermission(), other.getOwner(), other.getGroup(), (other.isSymlink() ? other.getSymlink() : null), other.getPath()); }
protected FileStatus swizzleFileStatus(FileStatus orig, boolean isParam) { FileStatus ret = new FileStatus(orig.getLen(), orig.isDir(), orig.getReplication(), orig.getBlockSize(), orig.getModificationTime(), orig.getAccessTime(), orig.getPermission(), orig.getOwner(), orig.getGroup(), isParam ? swizzleParamPath(orig.getPath()) : swizzleReturnPath(orig.getPath())); return ret; }
/** * @return desired replication for destination file. */ public short getReplication(FileSystem targetFs) { return getPreserve().preserve(PreserveAttributes.Option.REPLICATION) ? getOrigin().getReplication() : targetFs.getDefaultReplication(this.destination); }
/** * Replace the scheme of the input {@link FileStatus} if it matches the string to replace. */ public static FileStatus replaceScheme(FileStatus st, String replace, String replacement) { if (replace != null && replace.equals(replacement)) { return st; } try { return new FileStatus(st.getLen(), st.isDir(), st.getReplication(), st.getBlockSize(), st.getModificationTime(), st.getAccessTime(), st.getPermission(), st.getOwner(), st.getGroup(), st.isSymlink() ? st.getSymlink() : null, replaceScheme(st.getPath(), replace, replacement)); } catch (IOException ioe) { throw new RuntimeException(ioe); } }
public ChecksumFSInputChecker(ChecksumFileSystem fs, Path file, int bufferSize) throws IOException { super( file, fs.getFileStatus(file).getReplication() ); this.datas = fs.getRawFileSystem().open(file, bufferSize); this.fs = fs; Path sumFile = fs.getChecksumFile(file); try { int sumBufferSize = fs.getSumBufferSize(fs.getBytesPerSum(), bufferSize); sums = fs.getRawFileSystem().open(sumFile, sumBufferSize); byte[] version = new byte[CHECKSUM_VERSION.length]; sums.readFully(version); if (!Arrays.equals(version, CHECKSUM_VERSION)) throw new IOException("Not a checksum file: "+sumFile); this.bytesPerSum = sums.readInt(); set(fs.verifyChecksum, DataChecksum.newCrc32(), bytesPerSum, 4); } catch (IOException e) { // mincing the message is terrible, but java throws permission // exceptions as FNF because that's all the method signatures allow! if (!(e instanceof FileNotFoundException) || e.getMessage().endsWith(" (Permission denied)")) { LOG.warn("Problem opening checksum file: "+ file + ". Ignoring exception: " , e); } set(fs.verifyChecksum, null, 1, 0); } }
public void touch(MockFile file) { if (fileStatusMap.containsKey(file)) { FileStatus fileStatus = fileStatusMap.get(file); FileStatus fileStatusNew = new FileStatus(fileStatus.getLen(), fileStatus.isDirectory(), fileStatus.getReplication(), fileStatus.getBlockSize(), fileStatus.getModificationTime() + 1, fileStatus.getAccessTime(), fileStatus.getPermission(), fileStatus.getOwner(), fileStatus.getGroup(), fileStatus.getPath()); fileStatusMap.put(file, fileStatusNew); } }
public void touch(MockFile file) { if (fileStatusMap.containsKey(file)) { FileStatus fileStatus = fileStatusMap.get(file); FileStatus fileStatusNew = new FileStatus(fileStatus.getLen(), fileStatus.isDirectory(), fileStatus.getReplication(), fileStatus.getBlockSize(), fileStatus.getModificationTime() + 1, fileStatus.getAccessTime(), fileStatus.getPermission(), fileStatus.getOwner(), fileStatus.getGroup(), fileStatus.getPath()); fileStatusMap.put(file, fileStatusNew); } }
/** * Constructor * @param stat a file status * @param locations a file's block locations */ public LocatedFileStatus(FileStatus stat, BlockLocation[] locations) { this(stat.getLen(), stat.isDirectory(), stat.getReplication(), stat.getBlockSize(), stat.getModificationTime(), stat.getAccessTime(), stat.getPermission(), stat.getOwner(), stat.getGroup(), null, stat.getPath(), stat.hasAcl(), stat.isEncrypted(), stat.isErasureCoded(), locations); if (stat.isSymlink()) { try { setSymlink(stat.getSymlink()); } catch (IOException e) { throw new RuntimeException("Unexpected exception", e); } } }
/** * @return <expected, gotten, backup>, where each is sorted */ private static List<List<String>> getFileLists(FileStatus[] previous, FileStatus[] archived) { List<List<String>> files = new ArrayList<>(3); // copy over the original files List<String> originalFileNames = convertToString(previous); files.add(originalFileNames); List<String> currentFiles = new ArrayList<>(previous.length); List<FileStatus> backedupFiles = new ArrayList<>(previous.length); for (FileStatus f : archived) { String name = f.getPath().getName(); // if the file has been backed up if (name.contains(".")) { Path parent = f.getPath().getParent(); String shortName = name.split("[.]")[0]; Path modPath = new Path(parent, shortName); FileStatus file = new FileStatus(f.getLen(), f.isDirectory(), f.getReplication(), f.getBlockSize(), f.getModificationTime(), modPath); backedupFiles.add(file); } else { // otherwise, add it to the list to compare to the original store files currentFiles.add(name); } } files.add(currentFiles); files.add(convertToString(backedupFiles)); return files; }
public ChecksumFSInputChecker(ChecksumFs fs, Path file, int bufferSize) throws IOException, UnresolvedLinkException { super(file, fs.getFileStatus(file).getReplication()); this.datas = fs.getRawFs().open(file, bufferSize); this.fs = fs; Path sumFile = fs.getChecksumFile(file); try { int sumBufferSize = fs.getSumBufferSize(fs.getBytesPerSum(), bufferSize, file); sums = fs.getRawFs().open(sumFile, sumBufferSize); byte[] version = new byte[CHECKSUM_VERSION.length]; sums.readFully(version); if (!Arrays.equals(version, CHECKSUM_VERSION)) { throw new IOException("Not a checksum file: "+sumFile); } this.bytesPerSum = sums.readInt(); set(fs.verifyChecksum, DataChecksum.newCrc32(), bytesPerSum, 4); } catch (FileNotFoundException e) { // quietly ignore set(fs.verifyChecksum, null, 1, 0); } catch (IOException e) { // loudly ignore LOG.warn("Problem opening checksum file: "+ file + ". Ignoring exception: " , e); set(fs.verifyChecksum, null, 1, 0); } }