OutputStream outputStream = ufs.create(dstPath, CreateOptions.defaults(ServerConfiguration.global()) .setOwner(fileInfo.getOwner()).setGroup(fileInfo.getGroup()) .setMode(new Mode((short) fileInfo.getMode()))); final WritableByteChannel outputChannel = Channels.newChannel(outputStream);
ufs.create(dstPath.toString(), CreateOptions.defaults(ServerConfiguration.global()).setOwner(uriStatus.getOwner()) .setGroup(uriStatus.getGroup()).setMode(new Mode((short) uriStatus.getMode())))); bytesWritten = IOUtils.copyLarge(in, out); incrementPersistedMetric(ufsClient.getUfsMountPointUri(), bytesWritten);
/** * Tests getting and setting fields. */ @Test public void fields() { Random random = new Random(); boolean createParent = random.nextBoolean(); boolean ensureAtomic = random.nextBoolean(); String owner = CommonUtils.randomAlphaNumString(10); String group = CommonUtils.randomAlphaNumString(10); Mode mode = new Mode((short) random.nextInt()); CreateOptions options = CreateOptions.defaults(mConfiguration); options.setCreateParent(createParent); options.setEnsureAtomic(ensureAtomic); options.setOwner(owner); options.setGroup(group); options.setMode(mode); assertEquals(createParent, options.getCreateParent()); assertEquals(ensureAtomic, options.isEnsureAtomic()); assertEquals(owner, options.getOwner()); assertEquals(group, options.getGroup()); assertEquals(mode, options.getMode()); }
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()) .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.create(request.getUfsPath(), createOptions)); context.setCreateOptions(createOptions); String ufsString = MetricsSystem.escape(ufsClient.getUfsMountPointUri()); String counterName = Metric.getMetricNameWithTags(WorkerMetrics.BYTES_WRITTEN_UFS, WorkerMetrics.TAG_UFS, ufsString); Counter counter = MetricsSystem.counter(counterName); context.setCounter(counter); String meterName = Metric.getMetricNameWithTags(WorkerMetrics.BYTES_WRITTEN_UFS_THROUGHPUT, WorkerMetrics.TAG_UFS, ufsString); context.setMeter(MetricsSystem.meter(meterName)); } }