private List<OwnerAndPermission> replicateAncestorsOwnerAndPermission(FileSystem originFs, Path originPath, FileSystem targetFs, Path destinationPath) throws IOException { List<OwnerAndPermission> ancestorOwnerAndPermissions = Lists.newArrayList(); Path currentOriginPath = originPath.getParent(); Path currentTargetPath = destinationPath.getParent(); while (currentOriginPath != null && currentTargetPath != null && currentOriginPath.getName().equals(currentTargetPath.getName())) { Optional<FileStatus> targetFileStatus = this.configuration.getCopyContext().getFileStatus(targetFs, currentTargetPath); if (targetFileStatus.isPresent()) { return ancestorOwnerAndPermissions; } ancestorOwnerAndPermissions .add(resolveReplicatedOwnerAndPermission(originFs, currentOriginPath, this.configuration)); currentOriginPath = currentOriginPath.getParent(); currentTargetPath = currentTargetPath.getParent(); } return ancestorOwnerAndPermissions; }
/** * Computes the correct {@link OwnerAndPermission} obtained from replicating source owner and permissions and applying * the {@link PreserveAttributes} rules in copyConfiguration. * @throws IOException */ public static OwnerAndPermission resolveReplicatedOwnerAndPermission(FileSystem fs, Path path, CopyConfiguration copyConfiguration) throws IOException { PreserveAttributes preserve = copyConfiguration.getPreserve(); Optional<FileStatus> originFileStatus = copyConfiguration.getCopyContext().getFileStatus(fs, path); if (!originFileStatus.isPresent()) { throw new IOException(String.format("Origin path %s does not exist.", path)); } String group = null; if (copyConfiguration.getTargetGroup().isPresent()) { group = copyConfiguration.getTargetGroup().get(); } else if (preserve.preserve(Option.GROUP)) { group = originFileStatus.get().getGroup(); } return new OwnerAndPermission(preserve.preserve(Option.OWNER) ? originFileStatus.get().getOwner() : null, group, preserve.preserve(Option.PERMISSION) ? originFileStatus.get().getPermission() : null); }
input.getExistingTargetPartition().get().getParameters().get(HiveDataset.REGISTRATION_GENERATION_TIME_MILLIS)); Optional<FileStatus> sourceFileStatus = this.helper.getConfiguration().getCopyContext(). getFileStatus(this.helper.getDataset().getFs(), input.getPartition().getDataLocation());
this.helper.getConfiguration().getCopyContext().getFileStatus(this.helper.getTargetFs(), targetPath); Optional<FileStatus> sourceFileStatus = this.helper.getConfiguration().getCopyContext() .getFileStatus(this.helper.getDataset().getFs(), input.getPartition().getDataLocation());
helper.getDataset().getFs(), helper.getDataset().getProperties()); Optional<FileStatus> sourceFileStatus = helper.getConfiguration().getCopyContext(). getFileStatus(helper.getDataset().getFs(), sourceHiveDescriptor.getLocation());
copyConfiguration.getCopyContext().logCacheStatistics();
Mockito.doReturn(copyContext).when(copyConfiguration).getCopyContext(); HiveDataset dataset = Mockito.mock(HiveDataset.class); FileSystem fs = Mockito.spy(FileSystem.getLocal(new Configuration()));
private List<OwnerAndPermission> replicateAncestorsOwnerAndPermission(FileSystem originFs, Path originPath, FileSystem targetFs, Path destinationPath) throws IOException { List<OwnerAndPermission> ancestorOwnerAndPermissions = Lists.newArrayList(); Path currentOriginPath = originPath.getParent(); Path currentTargetPath = destinationPath.getParent(); while (currentOriginPath != null && currentTargetPath != null && currentOriginPath.getName().equals(currentTargetPath.getName())) { Optional<FileStatus> targetFileStatus = this.configuration.getCopyContext().getFileStatus(targetFs, currentTargetPath); if (targetFileStatus.isPresent()) { return ancestorOwnerAndPermissions; } ancestorOwnerAndPermissions .add(resolveReplicatedOwnerAndPermission(originFs, currentOriginPath, this.configuration)); currentOriginPath = currentOriginPath.getParent(); currentTargetPath = currentTargetPath.getParent(); } return ancestorOwnerAndPermissions; }
/** * Computes the correct {@link OwnerAndPermission} obtained from replicating source owner and permissions and applying * the {@link PreserveAttributes} rules in copyConfiguration. * @throws IOException */ public static OwnerAndPermission resolveReplicatedOwnerAndPermission(FileSystem fs, Path path, CopyConfiguration copyConfiguration) throws IOException { PreserveAttributes preserve = copyConfiguration.getPreserve(); Optional<FileStatus> originFileStatus = copyConfiguration.getCopyContext().getFileStatus(fs, path); if (!originFileStatus.isPresent()) { throw new IOException(String.format("Origin path %s does not exist.", path)); } String group = null; if (copyConfiguration.getTargetGroup().isPresent()) { group = copyConfiguration.getTargetGroup().get(); } else if (preserve.preserve(Option.GROUP)) { group = originFileStatus.get().getGroup(); } return new OwnerAndPermission(preserve.preserve(Option.OWNER) ? originFileStatus.get().getOwner() : null, group, preserve.preserve(Option.PERMISSION) ? originFileStatus.get().getPermission() : null); }
input.getExistingTargetPartition().get().getParameters().get(HiveDataset.REGISTRATION_GENERATION_TIME_MILLIS)); Optional<FileStatus> sourceFileStatus = this.helper.getConfiguration().getCopyContext(). getFileStatus(this.helper.getDataset().getFs(), input.getPartition().getDataLocation());
this.helper.getConfiguration().getCopyContext().getFileStatus(this.helper.getTargetFs(), targetPath); Optional<FileStatus> sourceFileStatus = this.helper.getConfiguration().getCopyContext() .getFileStatus(this.helper.getDataset().getFs(), input.getPartition().getDataLocation());
helper.getDataset().getFs(), helper.getDataset().getProperties()); Optional<FileStatus> sourceFileStatus = helper.getConfiguration().getCopyContext(). getFileStatus(helper.getDataset().getFs(), sourceHiveDescriptor.getLocation());
copyConfiguration.getCopyContext().logCacheStatistics();