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();
}
}
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 + "]");
}
}
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);
}
}
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);
}
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;
}
});
}
Aggregations