Search in sources :

Example 56 with URIStatus

use of alluxio.client.file.URIStatus in project alluxio by Alluxio.

the class CatCommand method runCommand.

@Override
protected void runCommand(AlluxioURI path, CommandLine cl) throws AlluxioException, IOException {
    URIStatus status = mFileSystem.getStatus(path);
    if (status.isFolder()) {
        throw new FileDoesNotExistException(ExceptionMessage.PATH_MUST_BE_FILE.getMessage(path));
    }
    OpenFileOptions options = OpenFileOptions.defaults().setReadType(ReadType.NO_CACHE);
    byte[] buf = new byte[512];
    try (FileInStream is = mFileSystem.openFile(path, options)) {
        int read = is.read(buf);
        while (read != -1) {
            System.out.write(buf, 0, read);
            read = is.read(buf);
        }
    }
}
Also used : FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) FileInStream(alluxio.client.file.FileInStream) OpenFileOptions(alluxio.client.file.options.OpenFileOptions) URIStatus(alluxio.client.file.URIStatus)

Example 57 with URIStatus

use of alluxio.client.file.URIStatus in project alluxio by Alluxio.

the class CheckConsistencyCommand method checkConsistency.

private void checkConsistency(AlluxioURI path, boolean repairConsistency) throws AlluxioException, IOException {
    CheckConsistencyOptions options = CheckConsistencyOptions.defaults();
    List<AlluxioURI> inconsistentUris = FileSystemUtils.checkConsistency(path, options);
    if (inconsistentUris.isEmpty()) {
        System.out.println(path + " is consistent with the under storage system.");
        return;
    }
    if (!repairConsistency) {
        Collections.sort(inconsistentUris);
        System.out.println("The following files are inconsistent:");
        for (AlluxioURI uri : inconsistentUris) {
            System.out.println(uri);
        }
    } else {
        Collections.sort(inconsistentUris);
        System.out.println(path + " has: " + inconsistentUris.size() + " inconsistent files.");
        List<AlluxioURI> inconsistentDirs = new ArrayList<AlluxioURI>();
        for (int i = 0; i < inconsistentUris.size(); i++) {
            AlluxioURI inconsistentUri = inconsistentUris.get(i);
            URIStatus status = mFileSystem.getStatus(inconsistentUri);
            if (status.isFolder()) {
                inconsistentDirs.add(inconsistentUri);
                continue;
            }
            System.out.println("repairing path: " + inconsistentUri);
            DeleteOptions deleteOptions = DeleteOptions.defaults().setAlluxioOnly(true);
            mFileSystem.delete(inconsistentUri, deleteOptions);
            mFileSystem.exists(inconsistentUri);
            System.out.println(inconsistentUri + " repaired");
            System.out.println();
        }
        for (AlluxioURI uri : inconsistentDirs) {
            DeleteOptions deleteOptions = DeleteOptions.defaults().setAlluxioOnly(true).setRecursive(true);
            System.out.println("repairing path: " + uri);
            mFileSystem.delete(uri, deleteOptions);
            mFileSystem.exists(uri);
            System.out.println(uri + "repaired");
            System.out.println();
        }
    }
}
Also used : DeleteOptions(alluxio.client.file.options.DeleteOptions) ArrayList(java.util.ArrayList) CheckConsistencyOptions(alluxio.client.file.options.CheckConsistencyOptions) URIStatus(alluxio.client.file.URIStatus) AlluxioURI(alluxio.AlluxioURI)

Example 58 with URIStatus

use of alluxio.client.file.URIStatus in project alluxio by Alluxio.

the class PersistCommand method persist.

/**
   * Persists a file or directory currently stored only in Alluxio to the UnderFileSystem.
   *
   * @param filePath the {@link AlluxioURI} path to persist to the UnderFileSystem
   * @throws AlluxioException when Alluxio exception occurs
   * @throws IOException when non-Alluxio exception occurs
   */
private void persist(AlluxioURI filePath) throws AlluxioException, IOException {
    URIStatus status = mFileSystem.getStatus(filePath);
    if (status.isFolder()) {
        List<URIStatus> statuses = mFileSystem.listStatus(filePath);
        List<String> errorMessages = new ArrayList<>();
        for (URIStatus uriStatus : statuses) {
            AlluxioURI newPath = new AlluxioURI(uriStatus.getPath());
            try {
                persist(newPath);
            } catch (IOException e) {
                errorMessages.add(e.getMessage());
            }
        }
        if (errorMessages.size() != 0) {
            throw new IOException(Joiner.on('\n').join(errorMessages));
        }
    } else if (status.isPersisted()) {
        System.out.println(filePath + " is already persisted");
    } else {
        FileSystemUtils.persistFile(mFileSystem, filePath);
        System.out.println("persisted file " + filePath + " with size " + status.getLength());
    }
}
Also used : ArrayList(java.util.ArrayList) IOException(java.io.IOException) URIStatus(alluxio.client.file.URIStatus) AlluxioURI(alluxio.AlluxioURI)

Example 59 with URIStatus

use of alluxio.client.file.URIStatus in project alluxio by Alluxio.

the class TailCommand method runCommand.

@Override
protected void runCommand(AlluxioURI path, CommandLine cl) throws AlluxioException, IOException {
    URIStatus status = mFileSystem.getStatus(path);
    int numOfBytes = Constants.KB;
    if (cl.hasOption('c')) {
        numOfBytes = Integer.parseInt(cl.getOptionValue('c'));
        Preconditions.checkArgument(numOfBytes > 0, "specified bytes must be > 0");
    }
    if (status.isFolder()) {
        throw new IOException(ExceptionMessage.PATH_MUST_BE_FILE.getMessage(path));
    }
    OpenFileOptions options = OpenFileOptions.defaults().setReadType(ReadType.NO_CACHE);
    try (FileInStream is = mFileSystem.openFile(path, options)) {
        byte[] buf = new byte[numOfBytes];
        long bytesToRead;
        if (status.getLength() > numOfBytes) {
            bytesToRead = numOfBytes;
        } else {
            bytesToRead = status.getLength();
        }
        is.skip(status.getLength() - bytesToRead);
        int read = is.read(buf);
        if (read != -1) {
            System.out.write(buf, 0, read);
        }
    }
}
Also used : FileInStream(alluxio.client.file.FileInStream) OpenFileOptions(alluxio.client.file.options.OpenFileOptions) IOException(java.io.IOException) URIStatus(alluxio.client.file.URIStatus)

Example 60 with URIStatus

use of alluxio.client.file.URIStatus in project alluxio by Alluxio.

the class IsolatedFileSystemIntegrationTest method unlockBlockTest2.

@Test
public void unlockBlockTest2() throws Exception {
    String uniqPath = PathUtils.uniqPath();
    FileInStream is;
    ByteBuffer buf;
    int numOfFiles = 5;
    int fileSize = WORKER_CAPACITY_BYTES / numOfFiles;
    List<AlluxioURI> files = new ArrayList<>();
    for (int k = 0; k < numOfFiles; k++) {
        FileSystemTestUtils.createByteFile(mFileSystem, uniqPath + k, fileSize, mWriteBoth);
        files.add(new AlluxioURI(uniqPath + k));
    }
    for (int k = 0; k < numOfFiles; k++) {
        URIStatus info = mFileSystem.getStatus(files.get(k));
        Assert.assertTrue(info.getInMemoryPercentage() == 100);
        is = mFileSystem.openFile(files.get(k), FileSystemTestUtils.toOpenFileOptions(mWriteBoth));
        buf = ByteBuffer.allocate((int) info.getBlockSizeBytes());
        Assert.assertTrue(is.read(buf.array()) != -1);
        is.seek(0);
        buf.clear();
        Assert.assertTrue(is.read(buf.array()) != -1);
        is.close();
    }
    FileSystemTestUtils.createByteFile(mFileSystem, uniqPath + numOfFiles, fileSize, mWriteBoth);
    files.add(new AlluxioURI(uniqPath + numOfFiles));
    for (int k = 1; k < numOfFiles; k++) {
        URIStatus info = mFileSystem.getStatus(files.get(k));
        Assert.assertTrue(info.getInMemoryPercentage() == 100);
    }
    HeartbeatScheduler.execute(HeartbeatContext.WORKER_BLOCK_SYNC);
    URIStatus info = mFileSystem.getStatus(files.get(numOfFiles));
    Assert.assertTrue(info.getInMemoryPercentage() == 100);
}
Also used : FileInStream(alluxio.client.file.FileInStream) ArrayList(java.util.ArrayList) URIStatus(alluxio.client.file.URIStatus) ByteBuffer(java.nio.ByteBuffer) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test)

Aggregations

URIStatus (alluxio.client.file.URIStatus)119 AlluxioURI (alluxio.AlluxioURI)111 Test (org.junit.Test)78 AbstractAlluxioShellTest (alluxio.shell.AbstractAlluxioShellTest)23 IOException (java.io.IOException)19 FileInStream (alluxio.client.file.FileInStream)17 ArrayList (java.util.ArrayList)15 AlluxioException (alluxio.exception.AlluxioException)13 FileDoesNotExistException (alluxio.exception.FileDoesNotExistException)13 AlluxioShellUtilsTest (alluxio.shell.AlluxioShellUtilsTest)12 FileInfo (alluxio.wire.FileInfo)12 File (java.io.File)10 FileOutStream (alluxio.client.file.FileOutStream)9 FileSystem (alluxio.client.file.FileSystem)7 InvalidPathException (alluxio.exception.InvalidPathException)7 ByteBuffer (java.nio.ByteBuffer)7 CreateFileOptions (alluxio.client.file.options.CreateFileOptions)6 OpenFileOptions (alluxio.client.file.options.OpenFileOptions)5 FileSystemMaster (alluxio.master.file.FileSystemMaster)5 UnderFileSystem (alluxio.underfs.UnderFileSystem)5