use of alluxio.exception.AlluxioException in project alluxio by Alluxio.
the class AbstractFileSystem method delete.
/**
* Attempts to delete the file or directory with the specified path.
*
* @param path path to delete
* @param recursive if true, will attempt to delete all children of the path
* @return true if one or more files/directories were deleted; false otherwise
* @throws IOException if the path failed to be deleted due to some constraint (ie. non empty
* directory with recursive flag disabled)
*/
@Override
public boolean delete(Path path, boolean recursive) throws IOException {
LOG.debug("delete({}, {})", path, recursive);
if (mStatistics != null) {
mStatistics.incrementWriteOps(1);
}
AlluxioURI uri = new AlluxioURI(HadoopUtils.getPathWithoutScheme(path));
DeleteOptions options = DeleteOptions.defaults().setRecursive(recursive);
try {
mFileSystem.delete(uri, options);
return true;
} catch (InvalidPathException | FileDoesNotExistException e) {
LOG.error("delete failed: {}", e.getMessage());
return false;
} catch (AlluxioException e) {
throw new IOException(e);
}
}
use of alluxio.exception.AlluxioException in project alluxio by Alluxio.
the class BlockInStream method createLocalBlockInStream.
/**
* Creates an instance of local {@link BlockInStream} that reads from local worker.
*
* @param blockId the block ID
* @param blockSize the block size
* @param workerNetAddress the worker network address
* @param context the file system context
* @param options the options
* @throws IOException if it fails to create an instance
* @return the {@link BlockInStream} created
*/
// TODO(peis): Use options idiom (ALLUXIO-2579).
public static BlockInStream createLocalBlockInStream(long blockId, long blockSize, WorkerNetAddress workerNetAddress, FileSystemContext context, InStreamOptions options) throws IOException {
Closer closer = Closer.create();
try {
BlockWorkerClient blockWorkerClient = closer.register(context.createBlockWorkerClient(workerNetAddress));
LockBlockResource lockBlockResource = closer.register(blockWorkerClient.lockBlock(blockId, LockBlockOptions.defaults()));
PacketInStream inStream = closer.register(PacketInStream.createLocalPacketInstream(lockBlockResource.getResult().getBlockPath(), blockId, blockSize));
blockWorkerClient.accessBlock(blockId);
return new BlockInStream(inStream, blockWorkerClient, closer, options);
} catch (AlluxioException | IOException e) {
CommonUtils.closeQuitely(closer);
throw CommonUtils.castToIOException(e);
}
}
use of alluxio.exception.AlluxioException in project alluxio by Alluxio.
the class FileSystemTestUtils method createByteFile.
/**
* Creates a simple file with {@code len} bytes.
*
* @param fs a {@link FileSystem} handler
* @param fileURI URI of the file
* @param options client options to create the file with
* @param len file size
* @throws IOException if {@code path} is invalid (e.g., illegal URI)
*/
public static void createByteFile(FileSystem fs, AlluxioURI fileURI, CreateFileOptions options, int len) throws IOException {
try (FileOutStream os = fs.createFile(fileURI, options)) {
byte[] arr = new byte[len];
for (int k = 0; k < len; k++) {
arr[k] = (byte) k;
}
os.write(arr);
} catch (AlluxioException e) {
throw new IOException(e.getMessage());
}
}
use of alluxio.exception.AlluxioException in project alluxio by Alluxio.
the class FileSystemTestUtils method listFiles.
/**
* Returns a list of files at a given {@code path}.
*
* @param fs a {@link FileSystem} handler
* @param path a path in alluxio file system
* @return a list of strings representing the file names under the given path
* @throws IOException if {@code path} does not exist or is invalid
*/
public static List<String> listFiles(FileSystem fs, String path) throws IOException {
try {
List<URIStatus> statuses = fs.listStatus(new AlluxioURI(path));
List<String> res = new ArrayList<>();
for (URIStatus status : statuses) {
res.add(status.getPath());
if (status.isFolder()) {
res.addAll(listFiles(fs, status.getPath()));
}
}
return res;
} catch (AlluxioException e) {
throw new IOException(e.getMessage());
}
}
use of alluxio.exception.AlluxioException in project alluxio by Alluxio.
the class AlluxioBlockStore method getOutStream.
/**
* Gets a stream to write data to a block based on the options. The stream can only be backed by
* Alluxio storage.
*
* @param blockId the block to write
* @param blockSize the standard block size to write, or -1 if the block already exists (and this
* stream is just storing the block in Alluxio again)
* @param options the output stream option
* @return an {@link OutputStream} which can be used to write data to the block in a
* streaming fashion
* @throws IOException if the block cannot be written
*/
public OutputStream getOutStream(long blockId, long blockSize, OutStreamOptions options) throws IOException {
WorkerNetAddress address;
FileWriteLocationPolicy locationPolicy = Preconditions.checkNotNull(options.getLocationPolicy(), PreconditionMessage.FILE_WRITE_LOCATION_POLICY_UNSPECIFIED);
try {
address = locationPolicy.getWorkerForNextBlock(getWorkerInfoList(), blockSize);
} catch (AlluxioException e) {
throw new IOException(e);
}
return getOutStream(blockId, blockSize, address, options);
}
Aggregations