/** * Heuristically checks if exception was caused by invalid HDFS version and returns appropriate exception. * * @param e Exception to check. * @param msg Detailed error message. * @return Appropriate exception. */ private IgfsException handleSecondaryFsError(IOException e, String msg) { if (e instanceof FileNotFoundException) return new IgfsPathNotFoundException(e); else return new IgfsException(msg, e); }
/** * Returns an array of File object. Under the specific path. * * @param path IGFS path. * @return Array of File objects. */ @Nullable private File[] listFiles0(IgfsPath path) { File f = fileForPath(path); if (!f.exists()) throw new IgfsPathNotFoundException("Failed to list files (path not found): " + path); else return f.listFiles(); }
/** * Update path properties if needed. * * @param path IGFS path * @param props Properties map. */ private void updatePropertiesIfNeeded(IgfsPath path, Map<String, String> props) { if (props == null || props.isEmpty()) return; File file = fileForPath(path); if (!file.exists()) throw new IgfsPathNotFoundException("Failed to update properties for path: " + path); LocalFileSystemUtils.updateProperties(file, props.get(IgfsUtils.PROP_GROUP_NAME), props.get(IgfsUtils.PROP_PERMISSION)); } }
@Override public IgfsSecondaryInputStreamDescriptor onSuccess( Map<IgfsPath, IgfsEntryInfo> infos) throws Exception { IgfsEntryInfo info = infos.get(path); if (info == null) throw fsException(new IgfsPathNotFoundException("File not found: " + path)); if (!info.isFile()) throw fsException(new IgfsPathIsDirectoryException("Failed to open file " + "(not a file): " + path)); return new IgfsSecondaryInputStreamDescriptor(infos.get(path), lazySecondaryReader(fs, path, bufSize)); }
/** {@inheritDoc} */ @Override public Collection<IgfsPath> listPaths(IgfsPath path) { try { FileStatus[] statuses = fileSystemForUser().listStatus(convert(path)); if (statuses == null) throw new IgfsPathNotFoundException("Failed to list files (path not found): " + path); Collection<IgfsPath> res = new ArrayList<>(statuses.length); for (FileStatus status : statuses) res.add(new IgfsPath(path, status.getPath().getName())); return res; } catch (FileNotFoundException ignored) { throw new IgfsPathNotFoundException("Failed to list files (path not found): " + path); } catch (IOException e) { throw handleSecondaryFsError(e, "Failed to list statuses due to secondary file system exception: " + path); } }
/** {@inheritDoc} */ @Override public void rename(IgfsPath src, IgfsPath dest) { File srcFile = fileForPath(src); File destFile = fileForPath(dest); if (!srcFile.exists()) throw new IgfsPathNotFoundException("Failed to perform rename because source path not found: " + src); if (srcFile.isDirectory() && destFile.isFile()) throw new IgfsPathIsNotDirectoryException("Failed to perform rename because destination path is " + "directory and source path is file [src=" + src + ", dest=" + dest + ']'); try { if (destFile.isDirectory()) Files.move(srcFile.toPath(), destFile.toPath().resolve(srcFile.getName())); else if(!srcFile.renameTo(destFile)) throw new IgfsException("Failed to perform rename (underlying file system returned false) " + "[src=" + src + ", dest=" + dest + ']'); } catch (IOException e) { throw handleSecondaryFsError(e, "Failed to rename [src=" + src + ", dest=" + dest + ']'); } }
return create(path, bufSize, false, 0, 0, props); else throw new IgfsPathNotFoundException("Failed to append to file because it doesn't exist: " + path);
/** * Get summary for path. * * @param path Path. * @return Summary. * @throws IgniteCheckedException If failed. */ private IgfsPathSummary summary0(IgfsPath path) throws IgniteCheckedException { IgfsFile info = info(path); if (info == null) throw new IgfsPathNotFoundException("Failed to get path summary (path not found): " + path); IgfsPathSummary sum = new IgfsPathSummary(path); summaryRecursive(info, sum); return sum; }
/** {@inheritDoc} */ @Override public void setTimes(IgfsPath path, long modificationTime, long accessTime) throws IgniteException { Path p = fileForPath(path).toPath(); if (!Files.exists(p)) throw new IgfsPathNotFoundException("Failed to set times (path not found): " + path); try { Files.getFileAttributeView(p, BasicFileAttributeView.class) .setTimes( (modificationTime >= 0) ? FileTime.from(modificationTime, TimeUnit.MILLISECONDS) : null, (accessTime >= 0) ? FileTime.from(accessTime, TimeUnit.MILLISECONDS) : null, null); } catch (IOException e) { throw new IgniteException("Failed to set times for path: " + path, e); } }
@Override public Collection<IgfsPath> call() throws Exception { if (log.isDebugEnabled()) log.debug("List directory: " + path); IgfsMode mode = resolveMode(path); Collection<IgfsPath> files = new HashSet<>(); if (mode != PRIMARY) { assert secondaryFs != null; try { Collection<IgfsPath> children = secondaryFs.listPaths(path); files.addAll(children); if (mode == PROXY || !modeRslvr.hasPrimaryChild(path)) return files; } catch (Exception e) { U.error(log, "List paths in DUAL mode failed [path=" + path + ']', e); throw e; } } IgfsEntryInfo info = primaryInfoForListing(path); if (info != null) { // Perform the listing. for (String child : info.listing().keySet()) files.add(new IgfsPath(path, child)); } else if (mode == PRIMARY) throw new IgfsPathNotFoundException("Failed to list paths (path not found): " + path); return files; } });
/** * Cast IO exception to IGFS exception. * * @param msg Error message. * @param e IO exception. * @return IGFS exception. */ public static IgfsException cast(String msg, IOException e) { if (e instanceof FileNotFoundException) return new IgfsPathNotFoundException(e); else if (e instanceof ParentNotDirectoryException) return new IgfsParentNotDirectoryException(msg, e); else if (e instanceof PathIsNotEmptyDirectoryException) return new IgfsDirectoryNotEmptyException(e); else if (e instanceof PathExistsException) return new IgfsPathAlreadyExistsException(msg, e); else return new IgfsException(msg, e); }
throw new IgfsPathNotFoundException("Failed to list files (path not found): " + path);
@Override public Void applyx() throws IgniteCheckedException { validTxState(true); // Lock file ID for this transaction. IgfsEntryInfo oldInfo = info(fileId); if (oldInfo == null) throw fsException(new IgfsPathNotFoundException("Failed to unlock file (file not " + "found): " + fileId)); if (!F.eq(lockId, oldInfo.lockId())) throw new IgniteCheckedException("Failed to unlock file (inconsistent file lock ID) " + "[fileId=" + fileId + ", lockId=" + lockId + ", actualLockId=" + oldInfo.lockId() + ']'); id2InfoPrj.invoke(fileId, new IgfsMetaFileUnlockProcessor(modificationTime, updateSpace, space, affRange)); return null; } });
throw fsException(new IgfsPathNotFoundException("Failed to rename " + "(source path not found): " + src)); throw fsException(new IgfsPathNotFoundException("Failed to rename " + "(destination path not found): " + dest));
/** * @param errCode Error code. * @param err Error. * @throws IgniteCheckedException Based on error code. */ public static void throwError(Integer errCode, String err) throws IgniteCheckedException { assert err != null; assert errCode != -1; if (errCode == ERR_FILE_NOT_FOUND) throw new IgfsPathNotFoundException(err); else if (errCode == ERR_PATH_ALREADY_EXISTS) throw new IgfsPathAlreadyExistsException(err); else if (errCode == ERR_DIRECTORY_NOT_EMPTY) throw new IgfsDirectoryNotEmptyException(err); else if (errCode == ERR_PARENT_NOT_DIRECTORY) throw new IgfsParentNotDirectoryException(err); else if (errCode == ERR_INVALID_HDFS_VERSION) throw new IgfsInvalidHdfsVersionException(err); else if (errCode == ERR_CORRUPTED_FILE) throw new IgfsCorruptedFileException(err); else if (errCode == ERR_IGFS_GENERIC) throw new IgfsException(err); throw new IgniteCheckedException(err); }
throw new IgfsPathNotFoundException("Failed to list paths (path not found): " + path);
/** * Add file into file system structure. Do not create new transaction expecting that the one already exists. * * @param parentId Parent file ID. * @param fileName File name in the parent's listing. * @param newFileInfo File info to store in the parent's listing. * @return File id already stored in meta cache or {@code null} if passed file info was stored. * @throws IgniteCheckedException If failed. */ private IgniteUuid putIfAbsentNonTx(IgniteUuid parentId, String fileName, IgfsEntryInfo newFileInfo) throws IgniteCheckedException { if (log.isDebugEnabled()) log.debug("Locking parent id [parentId=" + parentId + ", fileName=" + fileName + ", newFileInfo=" + newFileInfo + ']'); validTxState(true); // Lock only parent file ID. IgfsEntryInfo parentInfo = info(parentId); if (parentInfo == null) throw fsException(new IgfsPathNotFoundException("Failed to lock parent directory (not found): " + parentId)); if (!parentInfo.isDirectory()) throw fsException(new IgfsPathIsNotDirectoryException("Parent file is not a directory: " + parentInfo)); IgfsListingEntry childEntry = parentInfo.listing().get(fileName); if (childEntry != null) return childEntry.fileId(); createNewEntry(newFileInfo, parentId, fileName); return null; }
@Override public Collection<IgfsBlockLocation> call() throws Exception { if (log.isDebugEnabled()) log.debug("Get affinity for file block [path=" + path + ", start=" + start + ", len=" + len + ']'); IgfsMode mode = resolveMode(path); if (mode == PROXY) return secondaryFs.affinity(path, start, len, maxLen); // Check memory first. IgfsEntryInfo info = meta.infoForPath(path); if (info == null && mode != PRIMARY) { assert IgfsUtils.isDualMode(mode); assert secondaryFs != null; // Synchronize info = meta.synchronizeFileDual(secondaryFs, path); } if (info == null) throw new IgfsPathNotFoundException("File not found: " + path); if (!info.isFile()) throw new IgfsPathIsDirectoryException("Failed to get affinity for path because it is not " + "a file: " + path); return data.affinity(info, start, len, maxLen); } });
/** * @param gridIdx Grid index. * @param path Path to await. * @throws Exception If failed. */ protected void awaitFileFragmenting(int gridIdx, IgfsPath path) throws Exception { IgfsEx igfs = (IgfsEx)grid(gridIdx).fileSystem("igfs"); IgfsMetaManager meta = igfs.context().meta(); IgniteUuid fileId = meta.fileId(path); if (fileId == null) throw new IgfsPathNotFoundException("File not found: " + path); IgfsEntryInfo fileInfo = meta.info(fileId); do { if (fileInfo == null) throw new IgfsPathNotFoundException("File not found: " + path); if (fileInfo.fileMap().ranges().isEmpty()) return; U.sleep(100); fileInfo = meta.info(fileId); } while (true); }
throw new IgfsPathNotFoundException("File not found: " + path);