List of usage examples for java.io File getTotalSpace
public long getTotalSpace()
From source file:com.glaf.core.util.FileUtils.java
/** * ??//from www . ja va 2s . co m */ public static double getDiskPartitionSpaceUsedPercent(final String path) { if (null == path || path.isEmpty()) return -1; try { File file = new File(path); if (!file.exists()) { boolean result = file.mkdirs(); if (!result) { } } long totalSpace = file.getTotalSpace(); long freeSpace = file.getFreeSpace(); long usedSpace = totalSpace - freeSpace; if (totalSpace > 0) { return usedSpace / (double) totalSpace; } } catch (Exception e) { return -1; } return -1; }
From source file:com.aliyun.odps.mapred.unittest.MRUnitTest.java
/** * ?.// w ww.j a v a 2 s. c o m * * <p> * ????__schema__??? * schema?[<proj>.<table_name>,]<col_name>:<col_type * >(,<col_name>:<col_type>)*<br /> * * <ul> * <li>proj.tablename,a:string,b:bigint,c:double * <li>a:string,b:bigint,c:double * </ul> * * @param dir * * @return {@link List} * @throws IOException * * @see {@link #writeRecords(File, List, String)} */ public static List<Record> readRecords(File dir) throws IOException { List<Record> records = new ArrayList<Record>(); TableMeta meta = SchemaUtils.readSchema(dir); File dataFile = new File(dir, "data"); if (!dataFile.exists()) { return records; } Counter emptyCounter = counters.findCounter(JobCounter.__EMPTY_WILL_NOT_SHOW); RecordReader reader = new CSVRecordReader( new FileSplit(dataFile, meta.getCols(), 0, dataFile.getTotalSpace()), meta, emptyCounter, emptyCounter, counters, WareHouse.getInstance().getInputColumnSeperator()); Record r = reader.read(); while (r != null) { records.add(r.clone()); r = reader.read(); } reader.close(); return records; }
From source file:org.apache.bookkeeper.util.TestDiskChecker.java
/** * Check the disk full/*from ww w .j av a2 s. c o m*/ */ @Test(expected = DiskOutOfSpaceException.class) public void testCheckDiskFull() throws IOException { File file = createTempDir("DiskCheck", "test"); long usableSpace = file.getUsableSpace(); long totalSpace = file.getTotalSpace(); float threshold = (1f - ((float) usableSpace / (float) totalSpace)) * 0.5f; diskChecker.setDiskSpaceThreshold(threshold, threshold); diskChecker.checkDiskFull(file); }
From source file:org.apache.bookkeeper.util.TestDiskChecker.java
@Test(expected = DiskWarnThresholdException.class) public void testDiskWarnThresholdException() throws IOException { File file = createTempDir("DiskCheck", "test"); long usableSpace = file.getUsableSpace(); long totalSpace = file.getTotalSpace(); float diskSpaceThreshold = (1f - ((float) usableSpace / (float) totalSpace)); float diskWarnThreshold = (1f - ((float) usableSpace / (float) totalSpace)) * 0.5f; diskChecker.setDiskSpaceThreshold(diskSpaceThreshold, diskWarnThreshold); diskChecker.checkDiskFull(file);//from www . j ava 2s . c o m }
From source file:org.apache.bookkeeper.util.TestDiskChecker.java
/** * Check disk full on non exist file. in this case it should check for * parent file/*from w w w.j a v a 2 s . co m*/ */ @Test(timeout = 30000, expected = DiskOutOfSpaceException.class) public void testCheckDiskFullOnNonExistFile() throws IOException { File file = createTempDir("DiskCheck", "test"); long usableSpace = file.getUsableSpace(); long totalSpace = file.getTotalSpace(); float threshold = (1f - ((float) usableSpace / (float) totalSpace)) * 0.5f; diskChecker.setDiskSpaceThreshold(threshold, threshold); assertTrue(file.delete()); diskChecker.checkDiskFull(file); }
From source file:org.apache.hadoop.yarn.server.nodemanager.TestLocalDirsHandlerService.java
@Test public void testGetFullDirs() throws Exception { Configuration conf = new YarnConfiguration(); conf.set(CommonConfigurationKeys.FS_PERMISSIONS_UMASK_KEY, "077"); FileContext localFs = FileContext.getLocalFSFileContext(conf); String localDir1 = new File(testDir, "localDir1").getPath(); String localDir2 = new File(testDir, "localDir2").getPath(); String logDir1 = new File(testDir, "logDir1").getPath(); String logDir2 = new File(testDir, "logDir2").getPath(); Path localDir1Path = new Path(localDir1); Path logDir1Path = new Path(logDir1); FsPermission dirPermissions = new FsPermission((short) 0410); localFs.mkdir(localDir1Path, dirPermissions, true); localFs.mkdir(logDir1Path, dirPermissions, true); conf.set(YarnConfiguration.NM_LOCAL_DIRS, localDir1 + "," + localDir2); conf.set(YarnConfiguration.NM_LOG_DIRS, logDir1 + "," + logDir2); conf.setFloat(YarnConfiguration.NM_MAX_PER_DISK_UTILIZATION_PERCENTAGE, 0.0f); NodeManagerMetrics nm = NodeManagerMetrics.create(); LocalDirsHandlerService dirSvc = new LocalDirsHandlerService(nm); dirSvc.init(conf);/* w ww. j av a 2 s .c o m*/ Assert.assertEquals(0, dirSvc.getLocalDirs().size()); Assert.assertEquals(0, dirSvc.getLogDirs().size()); Assert.assertEquals(1, dirSvc.getDiskFullLocalDirs().size()); Assert.assertEquals(1, dirSvc.getDiskFullLogDirs().size()); // check the metrics Assert.assertEquals(2, nm.getBadLocalDirs()); Assert.assertEquals(2, nm.getBadLogDirs()); Assert.assertEquals(0, nm.getGoodLocalDirsDiskUtilizationPerc()); Assert.assertEquals(0, nm.getGoodLogDirsDiskUtilizationPerc()); Assert.assertEquals("", dirSvc.getConfig().get(LocalDirsHandlerService.NM_GOOD_LOCAL_DIRS)); Assert.assertEquals("", dirSvc.getConfig().get(LocalDirsHandlerService.NM_GOOD_LOG_DIRS)); Assert.assertEquals(localDir1 + "," + localDir2, dirSvc.getConfig().get(YarnConfiguration.NM_LOCAL_DIRS)); Assert.assertEquals(logDir1 + "," + logDir2, dirSvc.getConfig().get(YarnConfiguration.NM_LOG_DIRS)); conf.setFloat(YarnConfiguration.NM_MAX_PER_DISK_UTILIZATION_PERCENTAGE, 100.0f); nm = NodeManagerMetrics.create(); dirSvc = new LocalDirsHandlerService(nm); dirSvc.init(conf); Assert.assertEquals(1, dirSvc.getLocalDirs().size()); Assert.assertEquals(1, dirSvc.getLogDirs().size()); Assert.assertEquals(0, dirSvc.getDiskFullLocalDirs().size()); Assert.assertEquals(0, dirSvc.getDiskFullLogDirs().size()); // check the metrics File dir = new File(localDir1); int utilizationPerc = (int) ((dir.getTotalSpace() - dir.getUsableSpace()) * 100 / dir.getTotalSpace()); Assert.assertEquals(1, nm.getBadLocalDirs()); Assert.assertEquals(1, nm.getBadLogDirs()); Assert.assertEquals(utilizationPerc, nm.getGoodLocalDirsDiskUtilizationPerc()); Assert.assertEquals(utilizationPerc, nm.getGoodLogDirsDiskUtilizationPerc()); Assert.assertEquals(localDir2, dirSvc.getConfig().get(LocalDirsHandlerService.NM_GOOD_LOCAL_DIRS)); Assert.assertEquals(logDir2, dirSvc.getConfig().get(LocalDirsHandlerService.NM_GOOD_LOG_DIRS)); Assert.assertEquals(localDir1 + "," + localDir2, dirSvc.getConfig().get(YarnConfiguration.NM_LOCAL_DIRS)); Assert.assertEquals(logDir1 + "," + logDir2, dirSvc.getConfig().get(YarnConfiguration.NM_LOG_DIRS)); FileUtils.deleteDirectory(new File(localDir1)); FileUtils.deleteDirectory(new File(localDir2)); FileUtils.deleteDirectory(new File(logDir1)); FileUtils.deleteDirectory(new File(logDir2)); dirSvc.close(); }
From source file:fr.gael.dhus.datastore.eviction.EvictionManager.java
/** * Computes the total space on disk where the eviction works. * * @return the total space in byte on disk partition. *//*from ww w . j a va2 s .com*/ public long getTotalSpace() { String path = getPath(); File fpath = new File(path); return fpath.getTotalSpace(); }
From source file:org.apache.activemq.usage.PercentDiskUsageLimitTest.java
protected int getFreePercentage() { File storeDir = StoreUtil.findParentDirectory(adapter.getDirectory()); return (int) (((double) storeDir.getUsableSpace() / storeDir.getTotalSpace()) * 100); }
From source file:org.apache.samza.monitor.TestLocalStoreMonitor.java
@Test public void shouldDeleteInActiveLocalStoresOfTheJob() throws Exception { File inActiveStoreDir = new File(jobDir, "inActiveStore"); FileUtils.forceMkdir(inActiveStoreDir); File inActiveTaskDir = new File(inActiveStoreDir, "test-task"); FileUtils.forceMkdir(inActiveTaskDir); long inActiveTaskDirSize = inActiveTaskDir.getTotalSpace(); localStoreMonitor.monitor();//from ww w . ja v a2 s. c o m assertTrue("Inactive task store directory should not exist.", !inActiveTaskDir.exists()); assertEquals(taskStoreSize + inActiveTaskDirSize, localStoreMonitorMetrics.diskSpaceFreedInBytes.getCount()); assertEquals(2, localStoreMonitorMetrics.noOfDeletedTaskPartitionStores.getCount()); FileUtils.deleteDirectory(inActiveStoreDir); }
From source file:cprasmu.rascam.camera.FileSystemModel.java
public long calculateUsage() { File f = new File(initialPath); return (long) (((double) (f.getTotalSpace() - f.getFreeSpace()) / (double) f.getTotalSpace()) * 100d); }