/
Inode.java
239 lines (201 loc) · 5.45 KB
/
Inode.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
/*
* The Alluxio Open Foundation licenses this work under the Apache License, version 2.0
* (the "License"). You may not use this work except in compliance with the License, which is
* available at www.apache.org/licenses/LICENSE-2.0
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied, as more fully set forth in the License.
*
* See the NOTICE file distributed with this work for information regarding copyright ownership.
*/
package alluxio.master.file.meta;
import alluxio.grpc.TtlAction;
import alluxio.proto.journal.Journal.JournalEntry;
import alluxio.proto.meta.InodeMeta;
import alluxio.security.authorization.AccessControlList;
import alluxio.security.authorization.AclAction;
import alluxio.security.authorization.AclActions;
import alluxio.security.authorization.DefaultAccessControlList;
import alluxio.wire.FileInfo;
import com.google.common.base.Preconditions;
import com.google.protobuf.ByteString;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.annotation.Nullable;
/**
* Base class for read only inodes.
*/
public abstract class Inode implements InodeView {
private final InodeView mDelegate;
protected Inode(InodeView delegate) {
mDelegate = delegate;
}
@Override
public long getCreationTimeMs() {
return mDelegate.getCreationTimeMs();
}
@Override
public String getGroup() {
return mDelegate.getGroup();
}
@Override
public long getId() {
return mDelegate.getId();
}
@Override
public long getTtl() {
return mDelegate.getTtl();
}
@Override
public TtlAction getTtlAction() {
return mDelegate.getTtlAction();
}
@Override
public long getLastModificationTimeMs() {
return mDelegate.getLastModificationTimeMs();
}
@Override
public String getName() {
return mDelegate.getName();
}
@Override
public short getMode() {
return mDelegate.getMode();
}
@Override
public PersistenceState getPersistenceState() {
return mDelegate.getPersistenceState();
}
@Override
public long getParentId() {
return mDelegate.getParentId();
}
@Override
public String getOwner() {
return mDelegate.getOwner();
}
@Override
@Nullable
public Map<String, ByteString> getXAttr() {
return mDelegate.getXAttr();
}
@Override
public boolean isDeleted() {
return mDelegate.isDeleted();
}
@Override
public boolean isDirectory() {
return mDelegate.isDirectory();
}
@Override
public boolean isFile() {
return mDelegate.isFile();
}
@Override
public boolean isPinned() {
return mDelegate.isPinned();
}
@Override
public boolean isPersisted() {
return mDelegate.isPersisted();
}
@Override
public String getUfsFingerprint() {
return mDelegate.getUfsFingerprint();
}
@Override
public AccessControlList getACL() {
return mDelegate.getACL();
}
@Override
public DefaultAccessControlList getDefaultACL() throws UnsupportedOperationException {
return mDelegate.getDefaultACL();
}
@Override
public Set<String> getMediumTypes() {
return mDelegate.getMediumTypes();
}
@Override
public FileInfo generateClientFileInfo(String path) {
return mDelegate.generateClientFileInfo(path);
}
@Override
public boolean checkPermission(String user, List<String> groups, AclAction action) {
return mDelegate.checkPermission(user, groups, action);
}
@Override
public AclActions getPermission(String user, List<String> groups) {
return mDelegate.getPermission(user, groups);
}
@Override
public InodeMeta.Inode toProto() {
return mDelegate.toProto();
}
@Override
public JournalEntry toJournalEntry() {
return mDelegate.toJournalEntry();
}
@Override
public boolean equals(Object other) {
if (!(other instanceof Inode)) {
return false;
}
Inode otherInode = (Inode) other;
return mDelegate.equals(otherInode.mDelegate);
}
@Override
public int hashCode() {
return mDelegate.hashCode();
}
/**
* Casts the inode as an {@link InodeDirectory} if it is one, otherwise throws an
* exception.
*
* This gives convenience in method chaining, e.g.
*
* inode.asDirectory().getChildren()
*
* instead of
*
* ((InodeDirectory) inode).getChildren()
*
* @return the inode as an inode directory
*/
public InodeDirectory asDirectory() {
if (!isDirectory()) {
throw new IllegalStateException(
String.format("Inode %s is not a directory", mDelegate.getName()));
}
return (InodeDirectory) this;
}
/**
* @return the inode as an inode file
*/
public InodeFile asFile() {
if (isDirectory()) {
throw new IllegalStateException(
String.format("Inode %s is not a file", mDelegate.getName()));
}
return (InodeFile) this;
}
/**
* Wraps an InodeView, providing read-only access. Modifications to the underlying inode will
* affect the created read-only inode.
*
* @param delegate the delegate to wrap
* @return the created read-only inode
*/
public static Inode wrap(InodeView delegate) {
if (delegate instanceof Inode) {
return (Inode) delegate;
}
if (delegate.isFile()) {
Preconditions.checkState(delegate instanceof InodeFileView);
return new InodeFile((InodeFileView) delegate);
} else {
Preconditions.checkState(delegate instanceof InodeDirectoryView);
return new InodeDirectory((InodeDirectoryView) delegate);
}
}
}