use of org.apache.ignite.igfs.IgfsPath in project ignite by apache.
the class IgniteHadoopFileSystem method delete.
/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override
public boolean delete(Path f, boolean recursive) throws IOException {
A.notNull(f, "f");
enterBusy();
try {
IgfsPath path = convert(f);
// Will throw exception if delete failed.
boolean res = rmtClient.delete(path, recursive);
if (clientLog.isLogEnabled())
clientLog.logDelete(path, recursive);
return res;
} catch (IOException e) {
// Intentionally ignore IGFS exceptions here to follow Hadoop contract.
if (F.eq(IOException.class, e.getClass()) && (e.getCause() == null || !X.hasCause(e.getCause(), IgfsException.class)))
throw e;
else
return false;
} finally {
leaveBusy();
}
}
use of org.apache.ignite.igfs.IgfsPath in project ignite by apache.
the class IgniteHadoopFileSystem method append.
/** {@inheritDoc} */
@SuppressWarnings("deprecation")
@Override
public FSDataOutputStream append(Path f, int bufSize, Progressable progress) throws IOException {
A.notNull(f, "f");
enterBusy();
try {
IgfsPath path = convert(f);
if (LOG.isDebugEnabled())
LOG.debug("Opening output stream in append [thread=" + Thread.currentThread().getName() + ", path=" + path + ", bufSize=" + bufSize + ']');
HadoopIgfsStreamDelegate stream = rmtClient.append(path, false, null);
assert stream != null;
long logId = -1;
if (clientLog.isLogEnabled()) {
logId = IgfsLogger.nextId();
clientLog.logAppend(logId, path, bufSize);
}
if (LOG.isDebugEnabled())
LOG.debug("Opened output stream in append [path=" + path + ", delegate=" + stream + ']');
HadoopIgfsOutputStream igfsOut = new HadoopIgfsOutputStream(stream, LOG, clientLog, logId);
bufSize = Math.max(64 * 1024, bufSize);
BufferedOutputStream out = new BufferedOutputStream(igfsOut, bufSize);
return new FSDataOutputStream(out, null, 0);
} finally {
leaveBusy();
}
}
use of org.apache.ignite.igfs.IgfsPath in project ignite by apache.
the class IgniteHadoopFileSystem method listStatus.
/** {@inheritDoc} */
@Override
public FileStatus[] listStatus(Path f) throws IOException {
A.notNull(f, "f");
enterBusy();
try {
IgfsPath path = convert(f);
Collection<IgfsFile> list = rmtClient.listFiles(path);
if (list == null)
throw new FileNotFoundException("File " + f + " does not exist.");
List<IgfsFile> files = new ArrayList<>(list);
FileStatus[] arr = new FileStatus[files.size()];
for (int i = 0; i < arr.length; i++) arr[i] = convert(files.get(i));
if (clientLog.isLogEnabled()) {
String[] fileArr = new String[arr.length];
for (int i = 0; i < arr.length; i++) fileArr[i] = arr[i].getPath().toString();
clientLog.logListDirectory(path, fileArr);
}
return arr;
} finally {
leaveBusy();
}
}
use of org.apache.ignite.igfs.IgfsPath in project ignite by apache.
the class IgniteHadoopFileSystemClientSelfTest method testOutputStreamDeferredException.
/**
* Test output stream deferred exception (GG-4440).
*
* @throws Exception If failed.
*/
@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
public void testOutputStreamDeferredException() throws Exception {
final byte[] data = "test".getBytes();
try {
switchHandlerErrorFlag(true);
HadoopIgfs client = new HadoopIgfsOutProc("127.0.0.1", 10500, "igfs", LOG, null);
client.handshake(null);
IgfsPath path = new IgfsPath("/test1.file");
HadoopIgfsStreamDelegate delegate = client.create(path, true, false, 1, 1024, null);
final HadoopIgfsOutputStream igfsOut = new HadoopIgfsOutputStream(delegate, LOG, IgfsLogger.disabledLogger(), 0);
// This call should return fine as exception is thrown for the first time.
igfsOut.write(data);
U.sleep(500);
// This call should throw an IO exception.
GridTestUtils.assertThrows(null, new Callable<Object>() {
@Override
public Object call() throws Exception {
igfsOut.write(data);
return null;
}
}, IOException.class, "Failed to write data to server (test).");
} finally {
switchHandlerErrorFlag(false);
}
}
use of org.apache.ignite.igfs.IgfsPath in project ignite by apache.
the class IgfsAbstractSelfTest method testMoveFileSourceParentRoot.
/**
* Test file move when source parent is the root.
*
* @throws Exception If failed.
*/
public void testMoveFileSourceParentRoot() throws Exception {
IgfsPath file = new IgfsPath("/" + FILE.name());
create(igfs, paths(DIR_NEW, SUBDIR_NEW), paths(file));
igfs.rename(file, SUBDIR_NEW);
checkExist(igfs, igfsSecondary, new IgfsPath(SUBDIR_NEW, FILE.name()));
checkNotExist(igfs, igfsSecondary, file);
}
Aggregations