Search in sources :

Example 41 with InvalidPathException

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

the class DefaultStorageTier method initStorageTier.

private void initStorageTier(boolean isMultiTier) throws BlockAlreadyExistsException, IOException, WorkerOutOfSpaceException {
    String tmpDir = ServerConfiguration.getString(PropertyKey.WORKER_DATA_TMP_FOLDER);
    PropertyKey tierDirPathConf = PropertyKey.Template.WORKER_TIERED_STORE_LEVEL_DIRS_PATH.format(mTierOrdinal);
    String[] dirPaths = ServerConfiguration.getString(tierDirPathConf).split(",");
    for (int i = 0; i < dirPaths.length; i++) {
        dirPaths[i] = CommonUtils.getWorkerDataDirectory(dirPaths[i], ServerConfiguration.global());
    }
    PropertyKey tierDirCapacityConf = PropertyKey.Template.WORKER_TIERED_STORE_LEVEL_DIRS_QUOTA.format(mTierOrdinal);
    String rawDirQuota = ServerConfiguration.getString(tierDirCapacityConf);
    Preconditions.checkState(rawDirQuota.length() > 0, PreconditionMessage.ERR_TIER_QUOTA_BLANK);
    String[] dirQuotas = rawDirQuota.split(",");
    PropertyKey tierDirMediumConf = PropertyKey.Template.WORKER_TIERED_STORE_LEVEL_DIRS_MEDIUMTYPE.format(mTierOrdinal);
    String rawDirMedium = ServerConfiguration.getString(tierDirMediumConf);
    Preconditions.checkState(rawDirMedium.length() > 0, "Tier medium type configuration should not be blank");
    String[] dirMedium = rawDirMedium.split(",");
    // Set reserved bytes on directories if tier aligning is enabled.
    long reservedBytes = 0;
    if (isMultiTier && ServerConfiguration.getBoolean(PropertyKey.WORKER_MANAGEMENT_TIER_ALIGN_ENABLED)) {
        reservedBytes = ServerConfiguration.getBytes(PropertyKey.WORKER_MANAGEMENT_TIER_ALIGN_RESERVED_BYTES);
    }
    mDirs = new HashMap<>(dirPaths.length);
    mLostStorage = new ArrayList<>();
    long totalCapacity = 0;
    for (int i = 0; i < dirPaths.length; i++) {
        int index = i >= dirQuotas.length ? dirQuotas.length - 1 : i;
        int mediumTypeindex = i >= dirMedium.length ? dirMedium.length - 1 : i;
        long capacity = FormatUtils.parseSpaceSize(dirQuotas[index]);
        try {
            StorageDir dir = DefaultStorageDir.newStorageDir(this, i, capacity, reservedBytes, dirPaths[i], dirMedium[mediumTypeindex]);
            totalCapacity += capacity;
            mDirs.put(i, dir);
        } catch (IOException | InvalidPathException e) {
            LOG.error("Unable to initialize storage directory at {}", dirPaths[i], e);
            mLostStorage.add(dirPaths[i]);
            continue;
        }
        // Delete tmp directory.
        String tmpDirPath = PathUtils.concatPath(dirPaths[i], tmpDir);
        try {
            FileUtils.deletePathRecursively(tmpDirPath);
        } catch (IOException e) {
            if (FileUtils.exists(tmpDirPath)) {
                LOG.error("Failed to clean up temporary directory: {}.", tmpDirPath);
            }
        }
    }
    mCapacityBytes = totalCapacity;
    if (mTierAlias.equals(Constants.MEDIUM_MEM) && mDirs.size() == 1) {
        checkEnoughMemSpace(mDirs.values().iterator().next());
    }
}
Also used : IOException(java.io.IOException) PropertyKey(alluxio.conf.PropertyKey) InvalidPathException(alluxio.exception.InvalidPathException)

Example 42 with InvalidPathException

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

the class HdfsConfValidationTask method accessAndParseConf.

@Nullable
private Map<String, String> accessAndParseConf(String configName, String path) {
    if (path == null || path.isEmpty()) {
        mMsg.append(String.format("%s is not configured in Alluxio property %s%n", configName, PropertyKey.UNDERFS_HDFS_CONFIGURATION));
        mState = ValidationUtils.State.SKIPPED;
        return null;
    }
    try {
        PathUtils.getPathComponents(path);
    } catch (InvalidPathException e) {
        mState = ValidationUtils.State.WARNING;
        mMsg.append(String.format("Invalid path %s in Alluxio property %s.%n", path, PropertyKey.UNDERFS_HDFS_CONFIGURATION));
        mMsg.append(ValidationUtils.getErrorInfo(e));
        mAdvice.append(String.format("Please correct the path for %s in %s%n", configName, PropertyKey.UNDERFS_HDFS_CONFIGURATION));
        return null;
    }
    Path confPath = Paths.get(path);
    if (!Files.exists(confPath)) {
        mState = ValidationUtils.State.WARNING;
        mMsg.append(String.format("File does not exist at %s in Alluxio property %s.%n", path, PropertyKey.UNDERFS_HDFS_CONFIGURATION));
        mAdvice.append(String.format("Could not file file at \"%s\". Correct the path in %s%n", configName, PropertyKey.UNDERFS_HDFS_CONFIGURATION));
        return null;
    }
    if (!Files.isReadable(Paths.get(path))) {
        mState = ValidationUtils.State.WARNING;
        mMsg.append(String.format("\"%s\" is not readable from Alluxio property %s.%n", path, PropertyKey.UNDERFS_HDFS_CONFIGURATION));
        mAdvice.append(String.format("Grant more accessible permissions on the file" + " %s from %s%n", configName, PropertyKey.UNDERFS_HDFS_CONFIGURATION));
        return null;
    }
    HadoopConfigurationFileParser parser = new HadoopConfigurationFileParser();
    Map<String, String> properties = null;
    try {
        properties = parser.parseXmlConfiguration(path);
        mMsg.append(String.format("Successfully loaded %s. %n", path));
    } catch (IOException e) {
        mState = ValidationUtils.State.FAILED;
        mMsg.append(String.format("Failed to read %s. %s.%n", path, e.getMessage()));
        mMsg.append(ValidationUtils.getErrorInfo(e));
        mAdvice.append(String.format("Please check your %s.%n", path));
    } catch (RuntimeException e) {
        mState = ValidationUtils.State.FAILED;
        mMsg.append(String.format("Failed to parse %s. %s.%n", path, e.getMessage()));
        mMsg.append(ValidationUtils.getErrorInfo(e));
        mAdvice.append(String.format("Failed to parse %s as valid XML. Please check that the file " + "path is correct and the content is valid XML.%n", path));
    }
    return properties;
}
Also used : Path(java.nio.file.Path) IOException(java.io.IOException) InvalidPathException(alluxio.exception.InvalidPathException) Nullable(javax.annotation.Nullable)

Example 43 with InvalidPathException

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

the class SupportedHdfsActiveSyncProvider method processEvent.

private boolean processEvent(Event event, List<AlluxioURI> syncPointList, long txId) {
    boolean fileMatch = false;
    String filePath = "";
    String renameFilePath = "";
    switch(event.getEventType()) {
        case CREATE:
            Event.CreateEvent createEvent = (Event.CreateEvent) event;
            filePath = createEvent.getPath();
            break;
        case UNLINK:
            Event.UnlinkEvent unlinkEvent = (Event.UnlinkEvent) event;
            filePath = unlinkEvent.getPath();
            break;
        case APPEND:
            Event.AppendEvent appendEvent = (Event.AppendEvent) event;
            filePath = appendEvent.getPath();
            break;
        case RENAME:
            Event.RenameEvent renameEvent = (Event.RenameEvent) event;
            filePath = renameEvent.getSrcPath();
            renameFilePath = renameEvent.getDstPath();
            break;
        case METADATA:
            Event.MetadataUpdateEvent metadataUpdateEvent = (Event.MetadataUpdateEvent) event;
            filePath = metadataUpdateEvent.getPath();
            break;
        default:
            break;
    }
    if (filePath.isEmpty()) {
        return false;
    }
    for (AlluxioURI syncPoint : syncPointList) {
        try {
            // find out if the changed file falls under one of the sync points
            if (PathUtils.hasPrefix(filePath, syncPoint.getPath())) {
                fileMatch = true;
                recordFileChanged(syncPoint.toString(), filePath, txId);
            }
        } catch (InvalidPathException e) {
            LOG.info("Invalid path encountered {} ", filePath);
        }
        try {
            // find out if the changed file falls under one of the sync points
            if ((!renameFilePath.isEmpty()) && PathUtils.hasPrefix(renameFilePath, syncPoint.getPath())) {
                fileMatch = true;
                recordFileChanged(syncPoint.toString(), renameFilePath, txId);
            }
        } catch (InvalidPathException e) {
            LOG.info("Invalid path encountered {} ", renameFilePath);
        }
    }
    try (LockResource r = new LockResource(mWriteLock)) {
        mCurrentTxId = txId;
    }
    return fileMatch;
}
Also used : InvalidPathException(alluxio.exception.InvalidPathException) LockResource(alluxio.resource.LockResource) Event(org.apache.hadoop.hdfs.inotify.Event) AlluxioURI(alluxio.AlluxioURI)

Example 44 with InvalidPathException

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

the class MountTableTest method path.

/**
 * Tests the different methods of the {@link MountTable} class with a path.
 */
@Test
public void path() throws Exception {
    // Test add()
    addMount("/mnt/foo", "/foo", 2);
    addMount("/mnt/bar", "/bar", 3);
    try {
        addMount("/mnt/foo", "/foo2", 4);
        Assert.fail("Should not be able to add a mount to an existing mount.");
    } catch (FileAlreadyExistsException e) {
        // Exception expected
        Assert.assertEquals(ExceptionMessage.MOUNT_POINT_ALREADY_EXISTS.getMessage("/mnt/foo"), e.getMessage());
    }
    try {
        addMount("/test1", "hdfs://localhost", 6);
        addMount("/test2", "hdfs://localhost", 7);
        Assert.fail("mount fails");
    } catch (InvalidPathException e) {
        // Exception expected
        Assert.assertEquals(ExceptionMessage.MOUNT_POINT_PREFIX_OF_ANOTHER.getMessage("hdfs://localhost", "hdfs://localhost"), e.getMessage());
    }
    // Test resolve()
    MountTable.Resolution res1 = mMountTable.resolve(new AlluxioURI("/mnt/foo"));
    Assert.assertEquals(new AlluxioURI("/foo"), res1.getUri());
    Assert.assertEquals(2L, res1.getMountId());
    MountTable.Resolution res2 = mMountTable.resolve(new AlluxioURI("/mnt/foo/x"));
    Assert.assertEquals(new AlluxioURI("/foo/x"), res2.getUri());
    Assert.assertEquals(2L, res2.getMountId());
    MountTable.Resolution res3 = mMountTable.resolve(new AlluxioURI("/mnt/bar"));
    Assert.assertEquals(new AlluxioURI("/bar"), res3.getUri());
    Assert.assertEquals(3L, res3.getMountId());
    MountTable.Resolution res4 = mMountTable.resolve(new AlluxioURI("/mnt/bar/y"));
    Assert.assertEquals(new AlluxioURI("/bar/y"), res4.getUri());
    Assert.assertEquals(3L, res4.getMountId());
    MountTable.Resolution res5 = mMountTable.resolve(new AlluxioURI("/mnt/bar/baz"));
    Assert.assertEquals(new AlluxioURI("/bar/baz"), res5.getUri());
    Assert.assertEquals(3L, res5.getMountId());
    MountTable.Resolution res6 = mMountTable.resolve(new AlluxioURI("/foobar"));
    Assert.assertEquals(new AlluxioURI(ROOT_UFS).join("foobar"), res6.getUri());
    Assert.assertEquals(IdUtils.ROOT_MOUNT_ID, res6.getMountId());
    MountTable.Resolution res7 = mMountTable.resolve(new AlluxioURI("/"));
    Assert.assertEquals(new AlluxioURI("s3a://bucket/"), res7.getUri());
    Assert.assertEquals(IdUtils.ROOT_MOUNT_ID, res7.getMountId());
    // Test reverseResolve()
    Assert.assertEquals(new AlluxioURI("/mnt/foo"), mMountTable.reverseResolve(new AlluxioURI("/foo")).getUri());
    Assert.assertEquals(new AlluxioURI("/mnt/foo/x"), mMountTable.reverseResolve(new AlluxioURI("/foo/x")).getUri());
    Assert.assertEquals(mMountTable.reverseResolve(new AlluxioURI("/bar")).getUri(), new AlluxioURI("/mnt/bar"));
    Assert.assertEquals(mMountTable.reverseResolve(new AlluxioURI("/bar/y")).getUri(), new AlluxioURI("/mnt/bar/y"));
    // Test reverseResolve(), ufs path is not mounted
    Assert.assertEquals(new AlluxioURI("/foobar"), mMountTable.reverseResolve(new AlluxioURI("s3a://bucket/foobar")).getUri());
    Assert.assertEquals(new AlluxioURI("/"), mMountTable.reverseResolve(new AlluxioURI("s3a://bucket/")).getUri());
    Assert.assertNull(mMountTable.reverseResolve(new AlluxioURI("/foobar")));
    // Test getMountPoint()
    Assert.assertEquals("/mnt/foo", mMountTable.getMountPoint(new AlluxioURI("/mnt/foo")));
    Assert.assertEquals("/mnt/foo", mMountTable.getMountPoint(new AlluxioURI("/mnt/foo/x")));
    Assert.assertEquals("/mnt/bar", mMountTable.getMountPoint(new AlluxioURI("/mnt/bar")));
    Assert.assertEquals("/mnt/bar", mMountTable.getMountPoint(new AlluxioURI("/mnt/bar/y")));
    Assert.assertEquals("/mnt/bar", mMountTable.getMountPoint(new AlluxioURI("/mnt/bar/baz")));
    Assert.assertEquals("/", mMountTable.getMountPoint(new AlluxioURI("/mnt")));
    Assert.assertEquals("/", mMountTable.getMountPoint(new AlluxioURI("/")));
    // Test isMountPoint()
    Assert.assertTrue(mMountTable.isMountPoint(new AlluxioURI("/")));
    Assert.assertTrue(mMountTable.isMountPoint(new AlluxioURI("/mnt/foo")));
    Assert.assertFalse(mMountTable.isMountPoint(new AlluxioURI("/mnt/foo/bar")));
    Assert.assertFalse(mMountTable.isMountPoint(new AlluxioURI("/mnt")));
    Assert.assertFalse(mMountTable.isMountPoint(new AlluxioURI("/mnt/foo3")));
    Assert.assertTrue(mMountTable.isMountPoint(new AlluxioURI("/mnt/bar")));
    Assert.assertFalse(mMountTable.isMountPoint(new AlluxioURI("/mnt/bar/baz")));
    // Test delete()
    Assert.assertTrue(deleteMount("/mnt/bar"));
    Assert.assertTrue(deleteMount("/mnt/foo"));
    Assert.assertFalse(deleteMount("/mnt/foo"));
    Assert.assertFalse(deleteMount("/"));
    try {
        addMount("alluxio://localhost/t1", "s3a://localhost", 5);
        addMount("alluxio://localhost/t2", "s3a://localhost", 5);
        Assert.fail("mount fails");
    } catch (InvalidPathException e) {
        // Exception expected
        Assert.assertEquals(ExceptionMessage.MOUNT_POINT_PREFIX_OF_ANOTHER.getMessage("s3a://localhost", "s3a://localhost"), e.getMessage());
    }
}
Also used : FileAlreadyExistsException(alluxio.exception.FileAlreadyExistsException) InvalidPathException(alluxio.exception.InvalidPathException) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test)

Example 45 with InvalidPathException

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

the class CpCommand method copy.

/**
 * Copies a file or a directory in the Alluxio filesystem.
 *
 * @param srcPath the source {@link AlluxioURI} (could be a file or a directory)
 * @param dstPath the {@link AlluxioURI} of the destination path in the Alluxio filesystem
 * @param recursive indicates whether directories should be copied recursively
 */
private void copy(AlluxioURI srcPath, AlluxioURI dstPath, boolean recursive) throws AlluxioException, IOException {
    URIStatus srcStatus = mFileSystem.getStatus(srcPath);
    URIStatus dstStatus = null;
    try {
        dstStatus = mFileSystem.getStatus(dstPath);
    } catch (FileDoesNotExistException e) {
    // if the destination does not exist, it will be created
    }
    if (!srcStatus.isFolder()) {
        if (dstStatus != null && dstStatus.isFolder()) {
            dstPath = new AlluxioURI(PathUtils.concatPath(dstPath.getPath(), srcPath.getName()));
        }
        copyFile(srcPath, dstPath);
    } else {
        if (!recursive) {
            throw new IOException(srcPath.getPath() + " is a directory," + " to copy it please use \"cp -R/-r/--recursive <src> <dst>\"");
        }
        List<URIStatus> statuses;
        statuses = mFileSystem.listStatus(srcPath);
        if (dstStatus != null) {
            if (!dstStatus.isFolder()) {
                throw new InvalidPathException(ExceptionMessage.DESTINATION_CANNOT_BE_FILE.getMessage());
            }
            // subdirectory of the destination
            if (srcStatus.isFolder()) {
                dstPath = new AlluxioURI(PathUtils.concatPath(dstPath.getPath(), srcPath.getName()));
                mFileSystem.createDirectory(dstPath);
                System.out.println("Created directory: " + dstPath);
            }
        }
        if (dstStatus == null) {
            mFileSystem.createDirectory(dstPath);
            System.out.println("Created directory: " + dstPath);
        }
        preserveAttributes(srcPath, dstPath);
        List<String> errorMessages = new ArrayList<>();
        for (URIStatus status : statuses) {
            try {
                copy(new AlluxioURI(srcPath.getScheme(), srcPath.getAuthority(), status.getPath()), new AlluxioURI(dstPath.getScheme(), dstPath.getAuthority(), PathUtils.concatPath(dstPath.getPath(), status.getName())), recursive);
            } catch (IOException e) {
                errorMessages.add(e.getMessage());
            }
        }
        if (errorMessages.size() != 0) {
            throw new IOException(Joiner.on('\n').join(errorMessages));
        }
    }
}
Also used : FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) ArrayList(java.util.ArrayList) IOException(java.io.IOException) URIStatus(alluxio.client.file.URIStatus) InvalidPathException(alluxio.exception.InvalidPathException) AlluxioURI(alluxio.AlluxioURI)

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