source: proiecte/HadoopJUnit/hadoop-0.20.1/src/core/org/apache/hadoop/fs/kfs/KFSImpl.java @ 120

Last change on this file since 120 was 120, checked in by (none), 14 years ago

Added the mail files for the Hadoop JUNit Project

  • Property svn:executable set to *
File size: 4.9 KB
Line 
1/**
2 *
3 * Licensed under the Apache License, Version 2.0
4 * (the "License"); you may not use this file except in compliance with
5 * the License. You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12 * implied. See the License for the specific language governing
13 * permissions and limitations under the License.
14 *
15 * @author: Sriram Rao (Kosmix Corp.)
16 *
17 * Provide the implementation of KFS which turn into calls to KfsAccess.
18 */
19
20package org.apache.hadoop.fs.kfs;
21
22import java.io.*;
23
24import org.apache.hadoop.fs.FSDataInputStream;
25import org.apache.hadoop.fs.FSDataOutputStream;
26import org.apache.hadoop.fs.FileSystem;
27import org.apache.hadoop.fs.FileStatus;
28import org.apache.hadoop.fs.Path;
29
30import org.kosmix.kosmosfs.access.KfsAccess;
31import org.kosmix.kosmosfs.access.KfsFileAttr;
32
33class KFSImpl implements IFSImpl {
34    private KfsAccess kfsAccess = null;
35    private FileSystem.Statistics statistics;
36
37    @Deprecated
38    public KFSImpl(String metaServerHost, int metaServerPort
39                   ) throws IOException {
40      this(metaServerHost, metaServerPort, null);
41    }
42
43    public KFSImpl(String metaServerHost, int metaServerPort, 
44                   FileSystem.Statistics stats) throws IOException {
45        kfsAccess = new KfsAccess(metaServerHost, metaServerPort);
46        statistics = stats;
47    }
48
49    public boolean exists(String path) throws IOException {
50        return kfsAccess.kfs_exists(path);
51    }
52
53    public boolean isDirectory(String path) throws IOException {
54        return kfsAccess.kfs_isDirectory(path);
55    }
56
57    public boolean isFile(String path) throws IOException {
58        return kfsAccess.kfs_isFile(path);
59    }
60
61    public String[] readdir(String path) throws IOException {
62        return kfsAccess.kfs_readdir(path);
63    }
64
65    public FileStatus[] readdirplus(Path path) throws IOException {
66        String srep = path.toUri().getPath();
67        KfsFileAttr[] fattr = kfsAccess.kfs_readdirplus(srep);
68        if (fattr == null)
69            return null;
70        int numEntries = 0;
71        for (int i = 0; i < fattr.length; i++) {
72            if ((fattr[i].filename.compareTo(".") == 0) || (fattr[i].filename.compareTo("..") == 0))
73                continue;
74            numEntries++;
75        }
76        FileStatus[] fstatus = new FileStatus[numEntries];
77        int j = 0;
78        for (int i = 0; i < fattr.length; i++) {
79            if ((fattr[i].filename.compareTo(".") == 0) || (fattr[i].filename.compareTo("..") == 0))
80                continue;
81            Path fn = new Path(path, fattr[i].filename);
82
83            if (fattr[i].isDirectory)
84                fstatus[j] = new FileStatus(0, true, 1, 0, fattr[i].modificationTime, fn);
85            else
86                fstatus[j] = new FileStatus(fattr[i].filesize, fattr[i].isDirectory,
87                                            fattr[i].replication,
88                                            (long)
89                                            (1 << 26),
90                                            fattr[i].modificationTime,
91                                            fn);
92
93            j++;
94        }
95        return fstatus;
96    }
97
98
99    public int mkdirs(String path) throws IOException {
100        return kfsAccess.kfs_mkdirs(path);
101    }
102
103    public int rename(String source, String dest) throws IOException {
104        return kfsAccess.kfs_rename(source, dest);
105    }
106
107    public int rmdir(String path) throws IOException {
108        return kfsAccess.kfs_rmdir(path);
109    }
110
111    public int remove(String path) throws IOException {
112        return kfsAccess.kfs_remove(path);
113    }
114
115    public long filesize(String path) throws IOException {
116        return kfsAccess.kfs_filesize(path);
117    }
118
119    public short getReplication(String path) throws IOException {
120        return kfsAccess.kfs_getReplication(path);
121    }
122
123    public short setReplication(String path, short replication) throws IOException {
124        return kfsAccess.kfs_setReplication(path, replication);
125    }
126
127    public String[][] getDataLocation(String path, long start, long len) throws IOException {
128        return kfsAccess.kfs_getDataLocation(path, start, len);
129    }
130
131    public long getModificationTime(String path) throws IOException {
132        return kfsAccess.kfs_getModificationTime(path);
133    }
134
135    public FSDataOutputStream create(String path, short replication, int bufferSize) throws IOException {
136        return new FSDataOutputStream(new KFSOutputStream(kfsAccess, path, replication), 
137                                      statistics);
138    }
139
140    public FSDataInputStream open(String path, int bufferSize) throws IOException {
141        return new FSDataInputStream(new KFSInputStream(kfsAccess, path, 
142                                                        statistics));
143    }
144}
Note: See TracBrowser for help on using the repository browser.