Search in sources :

Example 1 with IgfsFileImpl

use of org.apache.ignite.internal.processors.igfs.IgfsFileImpl in project ignite by apache.

the class IgfsControlResponse method readExternal.

/**
 * Reads object from data input.
 *
 * @param in Data input.
 * @throws IOException If read failed.
 * @throws ClassNotFoundException If could not find class.
 */
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
    byte[] hdr = new byte[RES_HEADER_SIZE];
    in.readFully(hdr);
    resType = U.bytesToInt(hdr, 0);
    boolean hasErr = hdr[4] != 0;
    if (hasErr) {
        err = in.readUTF();
        errCode = in.readInt();
        if (resType == RES_TYPE_ERR_STREAM_ID)
            res = in.readLong();
        return;
    }
    switch(resType) {
        case RES_TYPE_BOOLEAN:
            res = in.readBoolean();
            break;
        case RES_TYPE_LONG:
            res = in.readLong();
            break;
        case RES_TYPE_IGFS_PATH:
            {
                boolean hasVal = in.readBoolean();
                if (hasVal)
                    res = IgfsUtils.readPath(in);
                break;
            }
        case RES_TYPE_IGFS_PATH_SUMMARY:
            {
                boolean hasVal = in.readBoolean();
                if (hasVal) {
                    IgfsPathSummary sum = new IgfsPathSummary();
                    sum.readExternal(in);
                    res = sum;
                }
                break;
            }
        case RES_TYPE_IGFS_FILE:
            {
                boolean hasVal = in.readBoolean();
                if (hasVal) {
                    IgfsFileImpl file = new IgfsFileImpl();
                    file.readExternal(in);
                    res = file;
                }
                break;
            }
        case RES_TYPE_IGFS_STREAM_DESCRIPTOR:
            {
                boolean hasVal = in.readBoolean();
                if (hasVal) {
                    IgfsInputStreamDescriptor desc = new IgfsInputStreamDescriptor();
                    desc.readExternal(in);
                    res = desc;
                }
                break;
            }
        case RES_TYPE_HANDSHAKE:
            {
                boolean hasVal = in.readBoolean();
                if (hasVal) {
                    IgfsHandshakeResponse msg = new IgfsHandshakeResponse();
                    msg.readExternal(in);
                    res = msg;
                }
                break;
            }
        case RES_TYPE_STATUS:
            {
                boolean hasVal = in.readBoolean();
                if (hasVal) {
                    IgfsStatus msg = new IgfsStatus();
                    msg.readExternal(in);
                    res = msg;
                }
                break;
            }
        case RES_TYPE_COL_IGFS_FILE:
            {
                Collection<IgfsFile> files = null;
                int size = in.readInt();
                if (size >= 0) {
                    files = new ArrayList<>(size);
                    for (int i = 0; i < size; i++) {
                        IgfsFileImpl file = new IgfsFileImpl();
                        file.readExternal(in);
                        files.add(file);
                    }
                }
                res = files;
                break;
            }
        case RES_TYPE_COL_IGFS_PATH:
            {
                Collection<IgfsPath> paths = null;
                int size = in.readInt();
                if (size >= 0) {
                    paths = new ArrayList<>(size);
                    for (int i = 0; i < size; i++) paths.add(IgfsUtils.readPath(in));
                }
                res = paths;
                break;
            }
        case RES_TYPE_COL_IGFS_BLOCK_LOCATION:
            {
                Collection<IgfsBlockLocation> locations = null;
                int size = in.readInt();
                if (size >= 0) {
                    locations = new ArrayList<>(size);
                    for (int i = 0; i < size; i++) {
                        IgfsBlockLocationImpl location = new IgfsBlockLocationImpl();
                        location.readExternal(in);
                        locations.add(location);
                    }
                }
                res = locations;
                break;
            }
        case RES_TYPE_MODE_RESOLVER:
            {
                boolean hasVal = in.readBoolean();
                if (hasVal) {
                    IgfsModeResolver msg = new IgfsModeResolver();
                    msg.readExternal(in);
                    res = msg;
                }
                break;
            }
        case RES_TYPE_BYTE_ARRAY:
            assert false : "Response type of byte array should never be processed by marshaller.";
    }
}
Also used : IgfsPathSummary(org.apache.ignite.igfs.IgfsPathSummary) IgfsModeResolver(org.apache.ignite.internal.processors.igfs.IgfsModeResolver) IgfsHandshakeResponse(org.apache.ignite.internal.processors.igfs.IgfsHandshakeResponse) IgfsBlockLocationImpl(org.apache.ignite.internal.processors.igfs.IgfsBlockLocationImpl) ArrayList(java.util.ArrayList) IgfsInputStreamDescriptor(org.apache.ignite.internal.processors.igfs.IgfsInputStreamDescriptor) Collection(java.util.Collection) IgfsFileImpl(org.apache.ignite.internal.processors.igfs.IgfsFileImpl) IgfsStatus(org.apache.ignite.internal.processors.igfs.IgfsStatus)

Example 2 with IgfsFileImpl

use of org.apache.ignite.internal.processors.igfs.IgfsFileImpl 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 3 with IgfsFileImpl

use of org.apache.ignite.internal.processors.igfs.IgfsFileImpl in project ignite by apache.

the class HadoopIgfsSecondaryFileSystemDelegateImpl method listFiles.

/**
 * {@inheritDoc}
 */
@Override
public Collection<IgfsFile> listFiles(IgfsPath path) {
    try {
        FileStatus[] statuses = fileSystemForUser().listStatus(convert(path));
        if (statuses == null)
            throw new IgfsPathNotFoundException("Failed to list files (path not found): " + path);
        Collection<IgfsFile> res = new ArrayList<>(statuses.length);
        for (FileStatus s : statuses) {
            IgfsEntryInfo fsInfo = s.isDirectory() ? IgfsUtils.createDirectory(IgniteUuid.randomUuid(), null, properties(s), s.getAccessTime(), s.getModificationTime()) : IgfsUtils.createFile(IgniteUuid.randomUuid(), (int) s.getBlockSize(), s.getLen(), null, null, false, properties(s), s.getAccessTime(), s.getModificationTime());
            res.add(new IgfsFileImpl(new IgfsPath(path, s.getPath().getName()), fsInfo, 1));
        }
        return res;
    } catch (FileNotFoundException ignored) {
        throw new IgfsPathNotFoundException("Failed to list files (path not found): " + path);
    } catch (IOException e) {
        throw handleSecondaryFsError(e, "Failed to list statuses due to secondary file system exception: " + path);
    }
}
Also used : IgfsPath(org.apache.ignite.igfs.IgfsPath) FileStatus(org.apache.hadoop.fs.FileStatus) ArrayList(java.util.ArrayList) IgfsEntryInfo(org.apache.ignite.internal.processors.igfs.IgfsEntryInfo) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) IgfsPathNotFoundException(org.apache.ignite.igfs.IgfsPathNotFoundException) IgfsFile(org.apache.ignite.igfs.IgfsFile) IgfsFileImpl(org.apache.ignite.internal.processors.igfs.IgfsFileImpl)

Aggregations

IgfsFileImpl (org.apache.ignite.internal.processors.igfs.IgfsFileImpl)3 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 FileStatus (org.apache.hadoop.fs.FileStatus)2 IgfsFile (org.apache.ignite.igfs.IgfsFile)2 IgfsPath (org.apache.ignite.igfs.IgfsPath)2 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 IgfsPathNotFoundException (org.apache.ignite.igfs.IgfsPathNotFoundException)1 IgfsPathSummary (org.apache.ignite.igfs.IgfsPathSummary)1 IgfsBlockLocationImpl (org.apache.ignite.internal.processors.igfs.IgfsBlockLocationImpl)1 IgfsEntryInfo (org.apache.ignite.internal.processors.igfs.IgfsEntryInfo)1 IgfsHandshakeResponse (org.apache.ignite.internal.processors.igfs.IgfsHandshakeResponse)1 IgfsInputStreamDescriptor (org.apache.ignite.internal.processors.igfs.IgfsInputStreamDescriptor)1 IgfsModeResolver (org.apache.ignite.internal.processors.igfs.IgfsModeResolver)1 IgfsStatus (org.apache.ignite.internal.processors.igfs.IgfsStatus)1 Nullable (org.jetbrains.annotations.Nullable)1