Search in sources :

Example 66 with InvalidPathException

use of alluxio.exception.InvalidPathException in project alluxio by Alluxio.

the class UfsStatusCacheTest method testFetchExecutionException.

@Test
public void testFetchExecutionException() throws Exception {
    spyUfs();
    // Now test execution exception
    AtomicReference<Error> ref = new AtomicReference<>(null);
    doThrow(new RuntimeException("Purposefully thrown exception.")).when(mUfs).listStatus(any(String.class));
    mCache.prefetchChildren(new AlluxioURI("/"), mMountTable);
    Thread t = new Thread(() -> {
        try {
            try {
                assertNull("Should return null when fetching children", mCache.fetchChildrenIfAbsent(null, new AlluxioURI("/"), mMountTable, false));
            } catch (InterruptedException | InvalidPathException e) {
                // Thread should not be interrupted if interrupt not called
                assertFalse(Thread.currentThread().isInterrupted());
                assertTrue(e instanceof InterruptedException);
            }
        } catch (AssertionError err) {
            ref.set(err);
        }
    });
    t.start();
    t.join();
    assertNull(ref.get());
}
Also used : AtomicReference(java.util.concurrent.atomic.AtomicReference) InvalidPathException(alluxio.exception.InvalidPathException) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test)

Example 67 with InvalidPathException

use of alluxio.exception.InvalidPathException in project alluxio by Alluxio.

the class CpCommand method run.

@Override
public int run(CommandLine cl) throws AlluxioException, IOException {
    String[] args = cl.getArgs();
    AlluxioURI srcPath = new AlluxioURI(args[0]);
    AlluxioURI dstPath = new AlluxioURI(args[1]);
    if ((dstPath.getScheme() == null || isAlluxio(dstPath.getScheme())) && isFile(srcPath.getScheme())) {
        List<AlluxioURI> srcPaths = new ArrayList<>();
        if (srcPath.containsWildcard()) {
            List<File> srcFiles = FileSystemShellUtils.getFiles(srcPath.getPath());
            if (srcFiles.size() == 0) {
                throw new IOException(ExceptionMessage.PATH_DOES_NOT_EXIST.getMessage(srcPath));
            }
            for (File srcFile : srcFiles) {
                srcPaths.add(new AlluxioURI(srcPath.getScheme(), srcPath.getAuthority(), srcFile.getPath()));
            }
        } else {
            File src = new File(srcPath.getPath());
            if (src.isDirectory()) {
                File[] files = src.listFiles();
                if (files == null) {
                    throw new IOException(String.format("Failed to list files for directory %s", src));
                }
                for (File f : files) {
                    srcPaths.add(new AlluxioURI(srcPath.getScheme(), srcPath.getAuthority(), f.getPath()));
                }
            } else {
                srcPaths.add(srcPath);
            }
        }
        if (srcPaths.size() == 1 && !(new File(srcPaths.get(0).getPath())).isDirectory()) {
            copyFromLocalFile(srcPaths.get(0), dstPath);
        } else {
            CopyThreadPoolExecutor pool = new CopyThreadPoolExecutor(mThread, System.out, System.err, mFileSystem, mFileSystem.exists(dstPath) ? null : dstPath);
            try {
                createDstDir(dstPath);
                for (AlluxioURI src : srcPaths) {
                    AlluxioURI dst = new AlluxioURI(dstPath, new AlluxioURI(src.getName()));
                    asyncCopyLocalPath(pool, src, dst);
                }
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
                throw new RuntimeException(e);
            } finally {
                pool.shutdown();
            }
        }
        System.out.println(String.format(COPY_SUCCEED_MESSAGE, srcPath, dstPath));
    } else if ((srcPath.getScheme() == null || isAlluxio(srcPath.getScheme())) && isFile(dstPath.getScheme())) {
        List<AlluxioURI> srcPaths = FileSystemShellUtils.getAlluxioURIs(mFileSystem, srcPath);
        if (srcPaths.size() == 0) {
            throw new IOException(ExceptionMessage.PATH_DOES_NOT_EXIST.getMessage(srcPath));
        }
        if (srcPath.containsWildcard()) {
            copyWildcardToLocal(srcPaths, dstPath);
        } else {
            copyToLocal(srcPath, dstPath);
        }
    } else if ((srcPath.getScheme() == null || isAlluxio(srcPath.getScheme())) && (dstPath.getScheme() == null || isAlluxio(dstPath.getScheme()))) {
        List<AlluxioURI> srcPaths = FileSystemShellUtils.getAlluxioURIs(mFileSystem, srcPath);
        if (srcPaths.size() == 0) {
            throw new FileDoesNotExistException(ExceptionMessage.PATH_DOES_NOT_EXIST.getMessage(srcPath.getPath()));
        }
        boolean recursive = cl.hasOption(RECURSIVE_OPTION.getOpt()) || cl.hasOption(RECURSIVE_ALIAS_OPTION.getOpt());
        if (srcPath.containsWildcard()) {
            copyWildcard(srcPaths, dstPath, recursive);
        } else {
            copy(srcPath, dstPath, recursive);
        }
    } else {
        throw new InvalidPathException("Schemes must be either file or alluxio, and at most one file scheme is allowed.");
    }
    return 0;
}
Also used : FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) ArrayList(java.util.ArrayList) IOException(java.io.IOException) InvalidPathException(alluxio.exception.InvalidPathException) List(java.util.List) ArrayList(java.util.ArrayList) File(java.io.File) AlluxioURI(alluxio.AlluxioURI)

Example 68 with InvalidPathException

use of alluxio.exception.InvalidPathException in project alluxio by Alluxio.

the class InodeTree method syncPersistDirectory.

/**
 * Persists the directory to the UFS, returning the UFS status if the directory is found to
 * already exist in the UFS.
 *
 * @param dir the directory to persist
 * @return optional ufs status if the directory already existed
 */
private Optional<UfsStatus> syncPersistDirectory(InodeDirectoryView dir) throws FileDoesNotExistException, IOException, InvalidPathException {
    AlluxioURI uri = getPath(dir);
    MountTable.Resolution resolution = mMountTable.resolve(uri);
    String ufsUri = resolution.getUri().toString();
    try (CloseableResource<UnderFileSystem> ufsResource = resolution.acquireUfsResource()) {
        UnderFileSystem ufs = ufsResource.get();
        MkdirsOptions mkdirsOptions = MkdirsOptions.defaults(ServerConfiguration.global()).setCreateParent(false).setOwner(dir.getOwner()).setGroup(dir.getGroup()).setMode(new Mode(dir.getMode()));
        if (!ufs.mkdirs(ufsUri, mkdirsOptions)) {
            // Directory might already exist. Try loading the status from ufs.
            UfsStatus status;
            try {
                status = ufs.getStatus(ufsUri);
            } catch (Exception e) {
                throw new IOException(String.format("Cannot create or load UFS directory %s: %s.", ufsUri, e.toString()), e);
            }
            if (status.isFile()) {
                throw new InvalidPathException(String.format("Error persisting directory. A file exists at the UFS location %s.", ufsUri));
            }
            return Optional.of(status);
        }
    }
    return Optional.empty();
}
Also used : MkdirsOptions(alluxio.underfs.options.MkdirsOptions) UfsStatus(alluxio.underfs.UfsStatus) LockMode(alluxio.concurrent.LockMode) Mode(alluxio.security.authorization.Mode) IOException(java.io.IOException) UnderFileSystem(alluxio.underfs.UnderFileSystem) InvalidPathException(alluxio.exception.InvalidPathException) FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) UnavailableException(alluxio.exception.status.UnavailableException) BlockInfoException(alluxio.exception.BlockInfoException) FileAlreadyExistsException(alluxio.exception.FileAlreadyExistsException) IOException(java.io.IOException) InvalidPathException(alluxio.exception.InvalidPathException) AlluxioURI(alluxio.AlluxioURI)

Example 69 with InvalidPathException

use of alluxio.exception.InvalidPathException in project alluxio by Alluxio.

the class AsyncUfsAbsentPathCache method getNestedPaths.

/**
 * Returns a sequence of Alluxio paths for a specified path, starting from the path component at
 * a specific index, to the specified path.
 *
 * @param alluxioUri the Alluxio path to get the nested paths for
 * @param startComponentIndex the index to the starting path component,
 *        root directory has index 0
 * @return a list of nested paths from the starting component to the given path
 */
private List<AlluxioURI> getNestedPaths(AlluxioURI alluxioUri, int startComponentIndex) {
    try {
        String[] fullComponents = PathUtils.getPathComponents(alluxioUri.getPath());
        String[] baseComponents = Arrays.copyOfRange(fullComponents, 0, startComponentIndex);
        AlluxioURI uri = new AlluxioURI(PathUtils.concatPath(AlluxioURI.SEPARATOR, baseComponents));
        List<AlluxioURI> components = new ArrayList<>(fullComponents.length - startComponentIndex);
        for (int i = startComponentIndex; i < fullComponents.length; i++) {
            uri = uri.joinUnsafe(fullComponents[i]);
            components.add(uri);
        }
        return components;
    } catch (InvalidPathException e) {
        return Collections.emptyList();
    }
}
Also used : ArrayList(java.util.ArrayList) InvalidPathException(alluxio.exception.InvalidPathException) AlluxioURI(alluxio.AlluxioURI)

Example 70 with InvalidPathException

use of alluxio.exception.InvalidPathException in project alluxio by Alluxio.

the class ManagerProcessContext method applyMount.

/**
 * Apply mount hdfs command.
 *
 * @param req validated request
 * @return response
 */
public ApplyMountPointResponse.Payload applyMount(ApplyMountPointRequest req) {
    ApplyMountPointRequest.Payload p = req.getPayload();
    ApplyMountPointResponse.Payload.Builder resultBuilder = ApplyMountPointResponse.Payload.newBuilder();
    alluxio.hub.proto.MountPointInfo mountPointInfo = p.getNew();
    Map<String, String> properties = constructProp(mountPointInfo, false);
    MountPOptions.Builder optionBuilder = MountPOptions.newBuilder().setReadOnly(mountPointInfo.getReadOnly()).setShared(mountPointInfo.getShared()).putAllProperties(properties);
    boolean needToRemount = false;
    try {
        boolean needToMount = true;
        if (p.hasBefore()) {
            AlluxioURI originalMount = new AlluxioURI(p.getBefore().getAlluxioPath());
            if (originalMount.isRoot() && (!(p.getBefore().getAlluxioPath().equals(p.getNew().getAlluxioPath()) && p.getBefore().getUfsUri().equals(p.getNew().getUfsUri())))) {
                throw new IOException("Cannot change the mount location or ufs location of a root mount");
            }
            // if both mount uri and ufs uri has not changed
            if (originalMount.isRoot() || (p.getBefore().getAlluxioPath().equals(p.getNew().getAlluxioPath()) && p.getBefore().getUfsUri().equals(p.getNew().getUfsUri()))) {
                getFileSystem().updateMount(originalMount, optionBuilder.build());
                needToMount = false;
            } else {
                getFileSystem().unmount(originalMount);
                needToRemount = true;
            }
        }
        if (needToMount) {
            getFileSystem().mount(new AlluxioURI(mountPointInfo.getAlluxioPath()), new AlluxioURI(mountPointInfo.getUfsUri()), optionBuilder.build());
            needToRemount = false;
        }
        if (mountPointInfo.hasHdfsInfo() && mountPointInfo.getHdfsInfo().getEnableSync()) {
            getFileSystem().startSync(new AlluxioURI(mountPointInfo.getAlluxioPath()));
        }
        resultBuilder.setSuccess(true);
    } catch (Exception e) {
        if (needToRemount) {
            alluxio.hub.proto.MountPointInfo oldMountPoint = p.getBefore();
            MountPOptions.Builder oldOptionBuilder = MountPOptions.newBuilder().setReadOnly(oldMountPoint.getReadOnly()).setShared(oldMountPoint.getShared()).putAllProperties(constructProp(oldMountPoint, false));
            try {
                getFileSystem().mount(new AlluxioURI(oldMountPoint.getAlluxioPath()), new AlluxioURI(oldMountPoint.getUfsUri()), oldOptionBuilder.build());
            } catch (Exception ex) {
                LOG.warn("Failed to restore the mount point " + oldMountPoint.getAlluxioPath() + " to previous state");
                resultBuilder.addError(ValidationUtils.getErrorInfo(ex));
            }
        }
        LOG.warn("Failed applying mount settings due to " + ValidationUtils.getErrorInfo(e));
        resultBuilder.setSuccess(false);
        resultBuilder.addError(ValidationUtils.getErrorInfo(e));
        // =====================
        if (e instanceof InvalidPathException) {
            if (exceptionMatchesPattern(e, "mount point.*already exists.*")) {
                resultBuilder.setAdvice("Another file, directory, or mount point already exists at this" + " path. Check the Alluxio path you are mounting to again to make sure it" + " doesn't conflict with paths that already exist.");
            } else if (exceptionMatchesPattern(e, "mount point.*is a prefix of.*")) {
                resultBuilder.setAdvice("A mount point with a similar UFS URI is already mounted to" + " Alluxio. Make sure that your UFS URI doesn't have a namespace overlap with" + " another existing mount point");
            } else if (exceptionMatchesPattern(e, ".*path.*is invalid.*")) {
                resultBuilder.setAdvice("We couldn't parse your Alluxio path. Make sure to provide the" + " absolute path to where the new mount point should exist.");
            }
        } else if (e instanceof FileDoesNotExistException) {
            if (exceptionMatchesPattern(e, "file.*creation failed. component.*does not exist")) {
                resultBuilder.setAdvice("One of components in the path you are trying to mount to does" + " not exist. Make sure that all path components in the Alluxio namespace you" + " are trying to mount at exists, except for the last one.");
            }
        } else if (e instanceof AlluxioException) {
            if (exceptionMatchesPattern(e, ".*no underfilesystem factory found for.*")) {
                resultBuilder.setAdvice(String.format("Alluxio couldn't find a matching library with the" + " URI (%s) and version (%s) provided. This means that you're trying to mount a" + " URI with an unsupported scheme (<scheme>://) or, that Alluxio doesn't have" + " an available version of the UFS type you're trying to mount.", mountPointInfo.getUfsUri(), p.getNew().hasHdfsInfo() ? p.getNew().getHdfsInfo().getHdfsVersion() : "N/A"));
            } else if (exceptionMatchesPattern(e, ".*ufs path.*does not exist.*")) {
                resultBuilder.setAdvice("The UFS path you are trying to mount does not exist in the UFS." + " Please make sure the UFS path specified exists.");
            } else if (exceptionMatchesPattern(e, ".*java.net.unknownhostexception:.*")) {
                resultBuilder.setAdvice(String.format("We weren't able to resolve the hostname in your" + " HDFS uri %s. Please double check that you've typed the hostname correctly and" + " that the system DNS can resolve the hostname.", mountPointInfo.getUfsUri()));
            } else if (exceptionMatchesPattern(e, "call from.*to.*failed on connection exception.*")) {
                resultBuilder.setAdvice("We were able to resolve the hostname of your URI, but failed to" + " connect. Double check that the hostname and port are correct. Then, if it" + " still fails verify that there is no firewall blocking connections between" + " this machine and the UFS URI specified.");
            }
        }
    // END Advice handling
    // ===================
    }
    return resultBuilder.build();
}
Also used : FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) MountPOptions(alluxio.grpc.MountPOptions) ConfigMapBuilder(io.fabric8.kubernetes.api.model.ConfigMapBuilder) ConfigBuilder(io.fabric8.kubernetes.client.ConfigBuilder) ByteString(com.google.protobuf.ByteString) IOException(java.io.IOException) AlluxioException(alluxio.exception.AlluxioException) IOException(java.io.IOException) InvalidPathException(alluxio.exception.InvalidPathException) FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) AlluxioStatusException(alluxio.exception.status.AlluxioStatusException) InvalidPathException(alluxio.exception.InvalidPathException) MountPointInfo(alluxio.wire.MountPointInfo) HDFSMountPointInfo(alluxio.hub.proto.HDFSMountPointInfo) ApplyMountPointRequest(alluxio.hub.proto.ApplyMountPointRequest) AlluxioURI(alluxio.AlluxioURI) AlluxioException(alluxio.exception.AlluxioException)

Aggregations

InvalidPathException (alluxio.exception.InvalidPathException)82 AlluxioURI (alluxio.AlluxioURI)51 FileDoesNotExistException (alluxio.exception.FileDoesNotExistException)44 IOException (java.io.IOException)40 ArrayList (java.util.ArrayList)25 FileAlreadyExistsException (alluxio.exception.FileAlreadyExistsException)19 AccessControlException (alluxio.exception.AccessControlException)17 AlluxioException (alluxio.exception.AlluxioException)17 LockedInodePath (alluxio.master.file.meta.LockedInodePath)17 MountTable (alluxio.master.file.meta.MountTable)14 UnderFileSystem (alluxio.underfs.UnderFileSystem)14 Inode (alluxio.master.file.meta.Inode)12 MountInfo (alluxio.master.file.meta.options.MountInfo)11 BlockInfoException (alluxio.exception.BlockInfoException)10 UnavailableException (alluxio.exception.status.UnavailableException)9 LockResource (alluxio.resource.LockResource)9 DirectoryNotEmptyException (alluxio.exception.DirectoryNotEmptyException)8 InodeDirectory (alluxio.master.file.meta.InodeDirectory)8 Test (org.junit.Test)8 URIStatus (alluxio.client.file.URIStatus)7