Search in sources :

Example 6 with IgfsFile

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

the class IgniteHadoopFileSystem method getFileStatus.

/**
 * {@inheritDoc}
 */
@Override
public FileStatus getFileStatus(Path f) throws IOException {
    A.notNull(f, "f");
    enterBusy();
    try {
        IgfsFile info = rmtClient.info(convert(f));
        if (info == null)
            throw new FileNotFoundException("File not found: " + f);
        return convert(info);
    } finally {
        leaveBusy();
    }
}
Also used : FileNotFoundException(java.io.FileNotFoundException) IgfsFile(org.apache.ignite.igfs.IgfsFile)

Example 7 with IgfsFile

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

the class HadoopIgfsSecondaryFileSystemDelegateImpl method info.

/**
 * {@inheritDoc}
 */
@Override
public IgfsFile info(final IgfsPath path) {
    try {
        final FileStatus status = fileSystemForUser().getFileStatus(convert(path));
        if (status == null)
            return null;
        final Map<String, String> props = properties(status);
        return new IgfsFileImpl(new IgfsFile() {

            @Override
            public IgfsPath path() {
                return path;
            }

            @Override
            public boolean isFile() {
                return status.isFile();
            }

            @Override
            public boolean isDirectory() {
                return status.isDirectory();
            }

            @Override
            public int blockSize() {
                // By convention directory has blockSize == 0, while file has blockSize > 0:
                return isDirectory() ? 0 : (int) status.getBlockSize();
            }

            @Override
            public long groupBlockSize() {
                return status.getBlockSize();
            }

            @Override
            public long accessTime() {
                return status.getAccessTime();
            }

            @Override
            public long modificationTime() {
                return status.getModificationTime();
            }

            @Override
            public String property(String name) throws IllegalArgumentException {
                String val = props.get(name);
                if (val == null)
                    throw new IllegalArgumentException("File property not found [path=" + path + ", name=" + name + ']');
                return val;
            }

            @Nullable
            @Override
            public String property(String name, @Nullable String dfltVal) {
                String val = props.get(name);
                return val == null ? dfltVal : val;
            }

            @Override
            public long length() {
                return status.getLen();
            }

            /**
             * {@inheritDoc}
             */
            @Override
            public Map<String, String> properties() {
                return props;
            }
        }, 0);
    } catch (FileNotFoundException ignore) {
        return null;
    } catch (IOException e) {
        throw handleSecondaryFsError(e, "Failed to get file status [path=" + path + "]");
    }
}
Also used : IgfsPath(org.apache.ignite.igfs.IgfsPath) FileStatus(org.apache.hadoop.fs.FileStatus) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) IgfsFileImpl(org.apache.ignite.internal.processors.igfs.IgfsFileImpl) IgfsFile(org.apache.ignite.igfs.IgfsFile) HashMap(java.util.HashMap) Map(java.util.Map) Nullable(org.jetbrains.annotations.Nullable)

Example 8 with IgfsFile

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

the class LocalIgfsSecondaryFileSystem method info.

/**
 * {@inheritDoc}
 */
@Override
public IgfsFile info(final IgfsPath path) {
    File file = fileForPath(path);
    if (!file.exists())
        return null;
    boolean isDir = file.isDirectory();
    PosixFileAttributes attrs = LocalFileSystemUtils.posixAttributes(file);
    Map<String, String> props = LocalFileSystemUtils.posixAttributesToMap(attrs);
    BasicFileAttributes basicAttrs = LocalFileSystemUtils.basicAttributes(file);
    if (isDir) {
        return new LocalFileSystemIgfsFile(path, false, true, 0, basicAttrs.lastAccessTime().toMillis(), basicAttrs.lastModifiedTime().toMillis(), 0, props);
    } else {
        return new LocalFileSystemIgfsFile(path, file.isFile(), false, 0, basicAttrs.lastAccessTime().toMillis(), basicAttrs.lastModifiedTime().toMillis(), file.length(), props);
    }
}
Also used : LocalFileSystemIgfsFile(org.apache.ignite.internal.processors.igfs.secondary.local.LocalFileSystemIgfsFile) PosixFileAttributes(java.nio.file.attribute.PosixFileAttributes) IgfsFile(org.apache.ignite.igfs.IgfsFile) LocalFileSystemIgfsFile(org.apache.ignite.internal.processors.igfs.secondary.local.LocalFileSystemIgfsFile) File(java.io.File) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes)

Example 9 with IgfsFile

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

the class LocalIgfsSecondaryFileSystem method update.

/**
 * {@inheritDoc}
 */
@Nullable
@Override
public IgfsFile update(IgfsPath path, Map<String, String> props) {
    File f = fileForPath(path);
    if (!f.exists())
        return null;
    updatePropertiesIfNeeded(path, props);
    return info(path);
}
Also used : IgfsFile(org.apache.ignite.igfs.IgfsFile) LocalFileSystemIgfsFile(org.apache.ignite.internal.processors.igfs.secondary.local.LocalFileSystemIgfsFile) File(java.io.File) Nullable(org.jetbrains.annotations.Nullable)

Example 10 with IgfsFile

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

the class IgfsImpl method update.

/**
 * {@inheritDoc}
 */
@Override
public IgfsFile update(final IgfsPath path, final Map<String, String> props) {
    A.notNull(path, "path");
    A.notNull(props, "props");
    A.ensure(!props.isEmpty(), "!props.isEmpty()");
    if (meta.isClient())
        return meta.runClientTask(new IgfsClientUpdateCallable(cfg.getName(), IgfsUserContext.currentUser(), path, props));
    return safeOp(new Callable<IgfsFile>() {

        @Override
        public IgfsFile call() throws Exception {
            if (log.isDebugEnabled())
                log.debug("Set file properties [path=" + path + ", props=" + props + ']');
            IgfsMode mode = resolveMode(path);
            switch(mode) {
                case PRIMARY:
                    {
                        List<IgniteUuid> fileIds = meta.idsForPath(path);
                        IgniteUuid fileId = fileIds.get(fileIds.size() - 1);
                        if (fileId != null) {
                            IgfsEntryInfo info = meta.updateProperties(fileId, props);
                            if (info != null) {
                                if (evts.isRecordable(EVT_IGFS_META_UPDATED))
                                    evts.record(new IgfsEvent(path, igfsCtx.localNode(), EVT_IGFS_META_UPDATED, props));
                                return new IgfsFileImpl(path, info, data.groupBlockSize());
                            }
                        }
                        break;
                    }
                case DUAL_ASYNC:
                case DUAL_SYNC:
                    {
                        await(path);
                        IgfsEntryInfo info = meta.updateDual(secondaryFs, path, props);
                        if (info != null)
                            return new IgfsFileImpl(path, info, data.groupBlockSize());
                        break;
                    }
                default:
                    assert mode == PROXY : "Unknown mode: " + mode;
                    IgfsFile status = secondaryFs.update(path, props);
                    return status != null ? new IgfsFileImpl(status, data.groupBlockSize()) : null;
            }
            return null;
        }
    });
}
Also used : IgfsMode(org.apache.ignite.igfs.IgfsMode) IgfsClientUpdateCallable(org.apache.ignite.internal.processors.igfs.client.IgfsClientUpdateCallable) IgniteUuid(org.apache.ignite.lang.IgniteUuid) IgfsEvent(org.apache.ignite.events.IgfsEvent) IgfsFile(org.apache.ignite.igfs.IgfsFile) IgfsPathIsDirectoryException(org.apache.ignite.igfs.IgfsPathIsDirectoryException) IgfsInvalidPathException(org.apache.ignite.igfs.IgfsInvalidPathException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) IgfsException(org.apache.ignite.igfs.IgfsException) IgfsPathNotFoundException(org.apache.ignite.igfs.IgfsPathNotFoundException)

Aggregations

IgfsFile (org.apache.ignite.igfs.IgfsFile)30 IgfsPath (org.apache.ignite.igfs.IgfsPath)13 FileNotFoundException (java.io.FileNotFoundException)6 IgniteException (org.apache.ignite.IgniteException)6 IgfsBlockLocation (org.apache.ignite.igfs.IgfsBlockLocation)5 ArrayList (java.util.ArrayList)4 FileStatus (org.apache.hadoop.fs.FileStatus)4 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)4 IgfsPathNotFoundException (org.apache.ignite.igfs.IgfsPathNotFoundException)4 IgniteUuid (org.apache.ignite.lang.IgniteUuid)4 IOException (java.io.IOException)3 IgniteFileSystem (org.apache.ignite.IgniteFileSystem)3 IgfsException (org.apache.ignite.igfs.IgfsException)3 Nullable (org.jetbrains.annotations.Nullable)3 File (java.io.File)2 HashMap (java.util.HashMap)2 UUID (java.util.UUID)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 FSDataOutputStream (org.apache.hadoop.fs.FSDataOutputStream)2 Path (org.apache.hadoop.fs.Path)2