List of usage examples for org.apache.hadoop.fs RawLocalFileSystem setPermission
@Override public void setPermission(Path p, FsPermission permission) throws IOException
From source file:com.datatorrent.stram.util.FSUtil.java
License:Apache License
/** * Download the file from dfs to local file. * * @param fs// w w w .j a v a 2 s. c o m * @param destinationFile * @param dfsFile * @param conf * @return * @throws IOException */ public static File copyToLocalFileSystem(FileSystem fs, String destinationPath, String destinationFile, String dfsFile, Configuration conf) throws IOException { File destinationDir = new File(destinationPath); if (!destinationDir.exists() && !destinationDir.mkdirs()) { throw new RuntimeException("Unable to create local directory"); } RawLocalFileSystem localFileSystem = new RawLocalFileSystem(); try { // allow app user to access local dir FsPermission permissions = new FsPermission(FsAction.ALL, FsAction.NONE, FsAction.NONE); localFileSystem.setPermission(new Path(destinationDir.getAbsolutePath()), permissions); Path dfsFilePath = new Path(dfsFile); File localFile = new File(destinationDir, destinationFile); FileUtil.copy(fs, dfsFilePath, localFile, false, conf); // set permissions on actual file to be read-only for user permissions = new FsPermission(FsAction.READ, FsAction.NONE, FsAction.NONE); localFileSystem.setPermission(new Path(localFile.getAbsolutePath()), permissions); return localFile; } finally { localFileSystem.close(); } }
From source file:org.apache.slider.server.services.security.SecurityUtils.java
License:Apache License
public static void initializeSecurityParameters(MapOperations configMap, boolean persistPassword) { String keyStoreLocation = configMap.getOption(SliderXmlConfKeys.KEY_KEYSTORE_LOCATION, getDefaultKeystoreLocation()); File secDirFile = new File(keyStoreLocation).getParentFile(); if (!secDirFile.exists()) { // create entire required directory structure File dbDir = new File(secDirFile, "db"); File newCertsDir = new File(dbDir, "newcerts"); newCertsDir.mkdirs();//w ww . j ava 2s . c o m try { RawLocalFileSystem fileSystem = new RawLocalFileSystem(); FsPermission permissions = new FsPermission(FsAction.ALL, FsAction.NONE, FsAction.NONE); fileSystem.setPermission(new Path(dbDir.getAbsolutePath()), permissions); fileSystem.setPermission(new Path(dbDir.getAbsolutePath()), permissions); fileSystem.setPermission(new Path(newCertsDir.getAbsolutePath()), permissions); File indexFile = new File(dbDir, "index.txt"); indexFile.createNewFile(); SecurityUtils.writeCaConfigFile(secDirFile.getAbsolutePath().replace('\\', '/')); } catch (IOException e) { LOG.error("Unable to create SSL configuration directories/files", e); } // need to create the password } keystorePass = getKeystorePassword(secDirFile, persistPassword); securityDir = secDirFile.getAbsolutePath(); }