Search in sources :

Example 16 with IgfsPath

use of org.apache.ignite.igfs.IgfsPath in project ignite by apache.

the class IgniteHadoopFileSystem method delete.

/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override
public boolean delete(Path f, boolean recursive) throws IOException {
    A.notNull(f, "f");
    enterBusy();
    try {
        IgfsPath path = convert(f);
        // Will throw exception if delete failed.
        boolean res = rmtClient.delete(path, recursive);
        if (clientLog.isLogEnabled())
            clientLog.logDelete(path, recursive);
        return res;
    } catch (IOException e) {
        // Intentionally ignore IGFS exceptions here to follow Hadoop contract.
        if (F.eq(IOException.class, e.getClass()) && (e.getCause() == null || !X.hasCause(e.getCause(), IgfsException.class)))
            throw e;
        else
            return false;
    } finally {
        leaveBusy();
    }
}
Also used : IgfsPath(org.apache.ignite.igfs.IgfsPath) IgfsException(org.apache.ignite.igfs.IgfsException) IOException(java.io.IOException)

Example 17 with IgfsPath

use of org.apache.ignite.igfs.IgfsPath in project ignite by apache.

the class IgniteHadoopFileSystem method append.

/** {@inheritDoc} */
@SuppressWarnings("deprecation")
@Override
public FSDataOutputStream append(Path f, int bufSize, Progressable progress) throws IOException {
    A.notNull(f, "f");
    enterBusy();
    try {
        IgfsPath path = convert(f);
        if (LOG.isDebugEnabled())
            LOG.debug("Opening output stream in append [thread=" + Thread.currentThread().getName() + ", path=" + path + ", bufSize=" + bufSize + ']');
        HadoopIgfsStreamDelegate stream = rmtClient.append(path, false, null);
        assert stream != null;
        long logId = -1;
        if (clientLog.isLogEnabled()) {
            logId = IgfsLogger.nextId();
            clientLog.logAppend(logId, path, bufSize);
        }
        if (LOG.isDebugEnabled())
            LOG.debug("Opened output stream in append [path=" + path + ", delegate=" + stream + ']');
        HadoopIgfsOutputStream igfsOut = new HadoopIgfsOutputStream(stream, LOG, clientLog, logId);
        bufSize = Math.max(64 * 1024, bufSize);
        BufferedOutputStream out = new BufferedOutputStream(igfsOut, bufSize);
        return new FSDataOutputStream(out, null, 0);
    } finally {
        leaveBusy();
    }
}
Also used : IgfsPath(org.apache.ignite.igfs.IgfsPath) HadoopIgfsStreamDelegate(org.apache.ignite.internal.processors.hadoop.impl.igfs.HadoopIgfsStreamDelegate) FSDataOutputStream(org.apache.hadoop.fs.FSDataOutputStream) HadoopIgfsOutputStream(org.apache.ignite.internal.processors.hadoop.impl.igfs.HadoopIgfsOutputStream) BufferedOutputStream(java.io.BufferedOutputStream)

Example 18 with IgfsPath

use of org.apache.ignite.igfs.IgfsPath in project ignite by apache.

the class IgniteHadoopFileSystem method listStatus.

/** {@inheritDoc} */
@Override
public FileStatus[] listStatus(Path f) throws IOException {
    A.notNull(f, "f");
    enterBusy();
    try {
        IgfsPath path = convert(f);
        Collection<IgfsFile> list = rmtClient.listFiles(path);
        if (list == null)
            throw new FileNotFoundException("File " + f + " does not exist.");
        List<IgfsFile> files = new ArrayList<>(list);
        FileStatus[] arr = new FileStatus[files.size()];
        for (int i = 0; i < arr.length; i++) arr[i] = convert(files.get(i));
        if (clientLog.isLogEnabled()) {
            String[] fileArr = new String[arr.length];
            for (int i = 0; i < arr.length; i++) fileArr[i] = arr[i].getPath().toString();
            clientLog.logListDirectory(path, fileArr);
        }
        return arr;
    } finally {
        leaveBusy();
    }
}
Also used : IgfsPath(org.apache.ignite.igfs.IgfsPath) FileStatus(org.apache.hadoop.fs.FileStatus) FileNotFoundException(java.io.FileNotFoundException) ArrayList(java.util.ArrayList) IgfsFile(org.apache.ignite.igfs.IgfsFile)

Example 19 with IgfsPath

use of org.apache.ignite.igfs.IgfsPath in project ignite by apache.

the class IgniteHadoopFileSystemClientSelfTest method testOutputStreamDeferredException.

/**
     * Test output stream deferred exception (GG-4440).
     *
     * @throws Exception If failed.
     */
@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
public void testOutputStreamDeferredException() throws Exception {
    final byte[] data = "test".getBytes();
    try {
        switchHandlerErrorFlag(true);
        HadoopIgfs client = new HadoopIgfsOutProc("127.0.0.1", 10500, "igfs", LOG, null);
        client.handshake(null);
        IgfsPath path = new IgfsPath("/test1.file");
        HadoopIgfsStreamDelegate delegate = client.create(path, true, false, 1, 1024, null);
        final HadoopIgfsOutputStream igfsOut = new HadoopIgfsOutputStream(delegate, LOG, IgfsLogger.disabledLogger(), 0);
        // This call should return fine as exception is thrown for the first time.
        igfsOut.write(data);
        U.sleep(500);
        // This call should throw an IO exception.
        GridTestUtils.assertThrows(null, new Callable<Object>() {

            @Override
            public Object call() throws Exception {
                igfsOut.write(data);
                return null;
            }
        }, IOException.class, "Failed to write data to server (test).");
    } finally {
        switchHandlerErrorFlag(false);
    }
}
Also used : IgfsPath(org.apache.ignite.igfs.IgfsPath) IOException(java.io.IOException)

Example 20 with IgfsPath

use of org.apache.ignite.igfs.IgfsPath in project ignite by apache.

the class IgfsAbstractSelfTest method testMoveFileSourceParentRoot.

/**
     * Test file move when source parent is the root.
     *
     * @throws Exception If failed.
     */
public void testMoveFileSourceParentRoot() throws Exception {
    IgfsPath file = new IgfsPath("/" + FILE.name());
    create(igfs, paths(DIR_NEW, SUBDIR_NEW), paths(file));
    igfs.rename(file, SUBDIR_NEW);
    checkExist(igfs, igfsSecondary, new IgfsPath(SUBDIR_NEW, FILE.name()));
    checkNotExist(igfs, igfsSecondary, file);
}
Also used : IgfsPath(org.apache.ignite.igfs.IgfsPath)

Aggregations

IgfsPath (org.apache.ignite.igfs.IgfsPath)161 IgfsOutputStream (org.apache.ignite.igfs.IgfsOutputStream)23 IOException (java.io.IOException)22 ArrayList (java.util.ArrayList)15 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)14 HashMap (java.util.HashMap)13 IgniteException (org.apache.ignite.IgniteException)13 IgniteFileSystem (org.apache.ignite.IgniteFileSystem)13 IgfsFile (org.apache.ignite.igfs.IgfsFile)13 IgfsException (org.apache.ignite.igfs.IgfsException)12 IgniteUuid (org.apache.ignite.lang.IgniteUuid)11 IgfsBlockLocation (org.apache.ignite.igfs.IgfsBlockLocation)10 IgfsInputStream (org.apache.ignite.igfs.IgfsInputStream)10 Map (java.util.Map)9 Path (org.apache.hadoop.fs.Path)9 IgfsPathNotFoundException (org.apache.ignite.igfs.IgfsPathNotFoundException)9 FileNotFoundException (java.io.FileNotFoundException)6 OutputStream (java.io.OutputStream)6 IgfsDirectoryNotEmptyException (org.apache.ignite.igfs.IgfsDirectoryNotEmptyException)6 IgfsParentNotDirectoryException (org.apache.ignite.igfs.IgfsParentNotDirectoryException)6