use of alluxio.underfs.options.CreateOptions in project alluxio by Alluxio.
the class UfsFileWriteHandler method completeRequest.
@Override
protected void completeRequest(UfsFileWriteRequestContext context) throws Exception {
if (context == null) {
return;
}
if (context.getOutputStream() == null) {
createUfsFile(context);
}
Preconditions.checkState(context.getOutputStream() != null);
context.getOutputStream().close();
CreateOptions createOptions = context.getCreateOptions();
if (createOptions != null) {
try {
// Set the owner/group of the file to the correct owner.
context.getUfsResource().get().setOwner(context.getRequest().getUfsPath(), createOptions.getOwner(), createOptions.getGroup());
} catch (IOException e) {
LOG.warn("Failed to update ownership for ufs path: {} owner: {} group: {} error: {}", context.getRequest().getUfsPath(), createOptions.getOwner(), createOptions.getGroup(), e.toString());
}
}
context.setOutputStream(null);
context.setCreateOptions(null);
context.getUfsResource().close();
}
use of alluxio.underfs.options.CreateOptions in project alluxio by Alluxio.
the class UfsFileWriteHandler method createUfsFile.
private void createUfsFile(UfsFileWriteRequestContext context) throws IOException {
UfsFileWriteRequest request = context.getRequest();
Preconditions.checkState(request != null);
Protocol.CreateUfsFileOptions createUfsFileOptions = request.getCreateUfsFileOptions();
UfsManager.UfsClient ufsClient = mUfsManager.get(createUfsFileOptions.getMountId());
CloseableResource<UnderFileSystem> ufsResource = ufsClient.acquireUfsResource();
context.setUfsResource(ufsResource);
UnderFileSystem ufs = ufsResource.get();
CreateOptions createOptions = CreateOptions.defaults(ServerConfiguration.global()).setCreateParent(true).setOwner(createUfsFileOptions.getOwner()).setGroup(createUfsFileOptions.getGroup()).setMode(new Mode((short) createUfsFileOptions.getMode()));
if (createUfsFileOptions.hasAcl()) {
// This acl information will be ignored by all but HDFS implementations
createOptions.setAcl(ProtoUtils.fromProto(createUfsFileOptions.getAcl()));
}
context.setOutputStream(ufs.createNonexistingFile(request.getUfsPath(), createOptions));
context.setCreateOptions(createOptions);
String ufsString = MetricsSystem.escape(ufsClient.getUfsMountPointUri());
MetricKey counterKey = MetricKey.WORKER_BYTES_WRITTEN_UFS;
MetricKey meterKey = MetricKey.WORKER_BYTES_WRITTEN_UFS_THROUGHPUT;
context.setCounter(MetricsSystem.counterWithTags(counterKey.getName(), counterKey.isClusterAggregated(), MetricInfo.TAG_UFS, ufsString));
context.setMeter(MetricsSystem.meterWithTags(meterKey.getName(), meterKey.isClusterAggregated(), MetricInfo.TAG_UFS, ufsString));
}
Aggregations