本文整理汇总了Java中org.apache.hadoop.fs.FileUtil.canWrite方法的典型用法代码示例。如果您正苦于以下问题:Java FileUtil.canWrite方法的具体用法?Java FileUtil.canWrite怎么用?Java FileUtil.canWrite使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.hadoop.fs.FileUtil
的用法示例。
在下文中一共展示了FileUtil.canWrite方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkAccessByFileMethods
import org.apache.hadoop.fs.FileUtil; //导入方法依赖的package包/类
/**
* Checks that the current running process can read, write, and execute the
* given directory by using methods of the File object.
*
* @param dir File to check
* @throws DiskErrorException if dir is not readable, not writable, or not
* executable
*/
private static void checkAccessByFileMethods(File dir)
throws DiskErrorException {
if (!FileUtil.canRead(dir)) {
throw new DiskErrorException("Directory is not readable: "
+ dir.toString());
}
if (!FileUtil.canWrite(dir)) {
throw new DiskErrorException("Directory is not writable: "
+ dir.toString());
}
if (!FileUtil.canExecute(dir)) {
throw new DiskErrorException("Directory is not executable: "
+ dir.toString());
}
}
示例2: attemptRestoreRemovedStorage
import org.apache.hadoop.fs.FileUtil; //导入方法依赖的package包/类
/**
* See if any of removed storages is "writable" again, and can be returned
* into service.
*/
void attemptRestoreRemovedStorage() {
// if directory is "alive" - copy the images there...
if(!restoreFailedStorage || removedStorageDirs.size() == 0)
return; //nothing to restore
/* We don't want more than one thread trying to restore at a time */
synchronized (this.restorationLock) {
LOG.info("NNStorage.attemptRestoreRemovedStorage: check removed(failed) "+
"storarge. removedStorages size = " + removedStorageDirs.size());
for(Iterator<StorageDirectory> it
= this.removedStorageDirs.iterator(); it.hasNext();) {
StorageDirectory sd = it.next();
File root = sd.getRoot();
LOG.info("currently disabled dir " + root.getAbsolutePath() +
"; type="+sd.getStorageDirType()
+ ";canwrite="+FileUtil.canWrite(root));
if(root.exists() && FileUtil.canWrite(root)) {
LOG.info("restoring dir " + sd.getRoot().getAbsolutePath());
this.addStorageDir(sd); // restore
this.removedStorageDirs.remove(sd);
}
}
}
}
示例3: initializeControllerPathsFromMtab
import org.apache.hadoop.fs.FileUtil; //导入方法依赖的package包/类
private void initializeControllerPathsFromMtab()
throws ResourceHandlerException {
try {
Map<String, List<String>> parsedMtab = parseMtab();
//we want to do a bulk update without the paths changing concurrently
rwLock.writeLock().lock();
for (CGroupController controller : CGroupController.values()) {
String name = controller.getName();
String controllerPath = findControllerInMtab(name, parsedMtab);
if (controllerPath != null) {
File f = new File(controllerPath + "/" + this.cGroupPrefix);
if (FileUtil.canWrite(f)) {
controllerPaths.put(controller, controllerPath);
} else {
String error =
new StringBuffer("Mount point Based on mtab file: ")
.append(MTAB_FILE).append(
". Controller mount point not writable for: ")
.append(name).toString();
LOG.error(error);
throw new ResourceHandlerException(error);
}
} else {
LOG.warn("Controller not mounted but automount disabled: " + name);
}
}
} catch (IOException e) {
LOG.warn("Failed to initialize controller paths! Exception: " + e);
throw new ResourceHandlerException(
"Failed to initialize controller paths!");
} finally {
rwLock.writeLock().unlock();
}
}
示例4: initializeControllerPaths
import org.apache.hadoop.fs.FileUtil; //导入方法依赖的package包/类
private void initializeControllerPaths() throws IOException {
String controllerPath;
Boolean isCentos7 = conf.getBoolean("os.centos7",false);
if (isCentos7) {
// centos7
controllerPath = cgroupMountPath+"/"+CONTROLLER_CPU; // "/sys/fs/cgroup/cpu"
}else {
Map<String, List<String>> parsedMtab = parseMtab();
// CPU
controllerPath = findControllerInMtab(CONTROLLER_CPU, parsedMtab);
}
if (controllerPath != null) {
File f = new File(controllerPath + "/" + this.cgroupPrefix);
if (FileUtil.canWrite(f)) {
controllerPaths.put(CONTROLLER_CPU, controllerPath);
} else {
throw new IOException("Not able to enforce cpu weights; cannot write "
+ "to cgroup at: " + controllerPath);
}
} else {
throw new IOException("Not able to enforce cpu weights; cannot find "
+ "cgroup for cpu controller in " + getMtabFileName());
}
}