use of alluxio.exception.InvalidPathException in project alluxio by Alluxio.
the class CpCommand method copyWildcardToLocal.
/**
* Copies a list of files or directories specified by srcPaths from the Alluxio filesystem to
* dstPath in the local filesystem. This method is used when the input path contains wildcards.
*
* @param srcPaths the list of files in the Alluxio filesystem
* @param dstPath the {@link AlluxioURI} of the destination directory in the local filesystem
*/
private void copyWildcardToLocal(List<AlluxioURI> srcPaths, AlluxioURI dstPath) throws AlluxioException, IOException {
File dstFile = new File(dstPath.getPath());
if (dstFile.exists() && !dstFile.isDirectory()) {
throw new InvalidPathException(ExceptionMessage.DESTINATION_CANNOT_BE_FILE.getMessage());
}
if (!dstFile.exists()) {
if (!dstFile.mkdirs()) {
throw new IOException("Fail to create directory: " + dstPath);
} else {
System.out.println("Create directory: " + dstPath);
}
}
List<String> errorMessages = new ArrayList<>();
for (AlluxioURI srcPath : srcPaths) {
try {
File dstSubFile = new File(dstFile.getAbsoluteFile(), srcPath.getName());
copyToLocal(srcPath, new AlluxioURI(dstPath.getScheme(), dstPath.getAuthority(), dstSubFile.getPath()));
} catch (IOException e) {
errorMessages.add(e.getMessage());
}
}
if (errorMessages.size() != 0) {
throw new IOException(Joiner.on('\n').join(errorMessages));
}
}
use of alluxio.exception.InvalidPathException in project alluxio by Alluxio.
the class CpCommand method copyWildcard.
/**
* Copies a list of files or directories specified by srcPaths to the destination specified by
* dstPath. This method is used when the original source path contains wildcards.
*
* @param srcPaths a list of files or directories in the Alluxio filesystem
* @param dstPath the destination in the Alluxio filesystem
* @param recursive indicates whether directories should be copied recursively
*/
private void copyWildcard(List<AlluxioURI> srcPaths, AlluxioURI dstPath, boolean recursive) throws AlluxioException, IOException {
URIStatus dstStatus = null;
try {
dstStatus = mFileSystem.getStatus(dstPath);
} catch (FileDoesNotExistException e) {
// if the destination does not exist, it will be created
}
if (dstStatus != null && !dstStatus.isFolder()) {
throw new InvalidPathException(ExceptionMessage.DESTINATION_CANNOT_BE_FILE.getMessage());
}
if (dstStatus == null) {
mFileSystem.createDirectory(dstPath);
System.out.println("Created directory: " + dstPath);
}
List<String> errorMessages = new ArrayList<>();
for (AlluxioURI srcPath : srcPaths) {
try {
copy(srcPath, new AlluxioURI(dstPath.getScheme(), dstPath.getAuthority(), PathUtils.concatPath(dstPath.getPath(), srcPath.getName())), recursive);
} catch (AlluxioException | IOException e) {
errorMessages.add(e.getMessage());
}
}
if (errorMessages.size() != 0) {
throw new IOException(Joiner.on('\n').join(errorMessages));
}
}
use of alluxio.exception.InvalidPathException in project alluxio by Alluxio.
the class PathTranslator method toAlluxioPath.
/**
* Returns the corresponding alluxio path, for the specified ufs path.
*
* @param ufsPath the ufs path to translate
* @return the corresponding alluxio path
* @throws IOException if the ufs path is not mounted
*/
public String toAlluxioPath(String ufsPath) throws IOException {
String suffix = ufsPath.endsWith("/") ? "/" : "";
AlluxioURI ufsUri = new AlluxioURI(ufsPath);
// first look for an exact match
if (mPathMap.inverse().containsKey(ufsUri)) {
AlluxioURI match = mPathMap.inverse().get(ufsUri);
if (match.equals(ufsUri)) {
// bypassed UFS path, return as is
return ufsPath;
}
return checkAndAddSchemeAuthority(mPathMap.inverse().get(ufsUri)) + suffix;
}
// otherwise match by longest prefix
BiMap.Entry<AlluxioURI, AlluxioURI> longestPrefix = null;
int longestPrefixDepth = -1;
for (BiMap.Entry<AlluxioURI, AlluxioURI> entry : mPathMap.entrySet()) {
try {
AlluxioURI valueUri = entry.getValue();
if (valueUri.isAncestorOf(ufsUri) && valueUri.getDepth() > longestPrefixDepth) {
longestPrefix = entry;
longestPrefixDepth = valueUri.getDepth();
}
} catch (InvalidPathException e) {
throw new IOException(e);
}
}
if (longestPrefix == null) {
// TODO(yuzhu): instead of throwing an exception, mount the path?
throw new IOException(String.format("Failed to translate ufs path (%s). Mapping missing from translator", ufsPath));
}
if (longestPrefix.getKey().equals(longestPrefix.getValue())) {
// return ufsPath if set the key and value to be same when bypass path.
return ufsPath;
}
try {
String difference = PathUtils.subtractPaths(ufsUri.getPath(), longestPrefix.getValue().getPath());
AlluxioURI mappedUri = longestPrefix.getKey().join(difference);
return checkAndAddSchemeAuthority(mappedUri) + suffix;
} catch (InvalidPathException e) {
throw new IOException(e);
}
}
use of alluxio.exception.InvalidPathException in project alluxio by Alluxio.
the class CephFSUnderFileSystem method createDirect.
@Override
public OutputStream createDirect(String path, CreateOptions options) throws IOException {
path = stripPath(path);
String parentPath;
try {
parentPath = PathUtils.getParent(path);
} catch (InvalidPathException e) {
throw new IOException("Invalid path " + path, e);
}
IOException te = null;
RetryPolicy retryPolicy = new CountingRetry(MAX_TRY);
while (retryPolicy.attempt()) {
try {
// support creating CephFS files with specified block size and replication.
if (options.getCreateParent()) {
if (mkdirs(parentPath, MkdirsOptions.defaults(mUfsConf)) && !isDirectory(parentPath)) {
throw new IOException(ExceptionMessage.PARENT_CREATION_FAILED.getMessage(path));
}
}
int flags = CephMount.O_WRONLY | CephMount.O_CREAT | CephMount.O_TRUNC;
short mode = options.getMode().toShort();
int fd = openInternal(path, flags, mode);
return new CephOutputStream(mMount, fd);
} catch (IOException e) {
LOG.warn("Retry count {} : {}", retryPolicy.getAttemptCount(), e.toString());
te = e;
}
}
throw te;
}
use of alluxio.exception.InvalidPathException in project alluxio by Alluxio.
the class CpCommand method copyWildcardToLocal.
/**
* Copies a list of files or directories specified by srcPaths from the Alluxio filesystem to
* dstPath in the local filesystem. This method is used when the input path contains wildcards.
*
* @param srcPaths the list of files in the Alluxio filesystem
* @param dstPath the {@link AlluxioURI} of the destination directory in the local filesystem
* @throws AlluxioException when Alluxio exception occurs
* @throws IOException when non-Alluxio exception occurs
*/
private void copyWildcardToLocal(List<AlluxioURI> srcPaths, AlluxioURI dstPath) throws AlluxioException, IOException {
File dstFile = new File(dstPath.getPath());
if (dstFile.exists() && !dstFile.isDirectory()) {
throw new InvalidPathException(ExceptionMessage.DESTINATION_CANNOT_BE_FILE.getMessage());
}
if (!dstFile.exists()) {
if (!dstFile.mkdirs()) {
throw new IOException("Fail to create directory: " + dstPath);
} else {
System.out.println("Create directory: " + dstPath);
}
}
List<String> errorMessages = new ArrayList<>();
for (AlluxioURI srcPath : srcPaths) {
try {
File dstSubFile = new File(dstFile.getAbsoluteFile(), srcPath.getName());
copyToLocal(srcPath, new AlluxioURI(dstPath.getScheme(), dstPath.getAuthority(), dstSubFile.getPath()));
} catch (IOException e) {
errorMessages.add(e.getMessage());
}
}
if (errorMessages.size() != 0) {
throw new IOException(Joiner.on('\n').join(errorMessages));
}
}
Aggregations