Search in sources :

Example 1 with CreateOptions

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();
}
Also used : IOException(java.io.IOException) CreateOptions(alluxio.underfs.options.CreateOptions)

Example 2 with CreateOptions

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));
}
Also used : MetricKey(alluxio.metrics.MetricKey) UfsManager(alluxio.underfs.UfsManager) Mode(alluxio.security.authorization.Mode) Protocol(alluxio.proto.dataserver.Protocol) UnderFileSystem(alluxio.underfs.UnderFileSystem) CreateOptions(alluxio.underfs.options.CreateOptions)

Aggregations

CreateOptions (alluxio.underfs.options.CreateOptions)2 MetricKey (alluxio.metrics.MetricKey)1 Protocol (alluxio.proto.dataserver.Protocol)1 Mode (alluxio.security.authorization.Mode)1 UfsManager (alluxio.underfs.UfsManager)1 UnderFileSystem (alluxio.underfs.UnderFileSystem)1 IOException (java.io.IOException)1