Java Code Examples for org.apache.hadoop.hdfs.protocol.BlockStoragePolicy#getId()
The following examples show how to use
org.apache.hadoop.hdfs.protocol.BlockStoragePolicy#getId() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestHFileOutputFormat2.java From hbase with Apache License 2.0 | 6 votes |
private String getStoragePolicyNameForOldHDFSVersion(FileSystem fs, Path path) { try { if (fs instanceof DistributedFileSystem) { DistributedFileSystem dfs = (DistributedFileSystem) fs; HdfsFileStatus status = dfs.getClient().getFileInfo(path.toUri().getPath()); if (null != status) { byte storagePolicyId = status.getStoragePolicy(); Field idUnspecified = BlockStoragePolicySuite.class.getField("ID_UNSPECIFIED"); if (storagePolicyId != idUnspecified.getByte(BlockStoragePolicySuite.class)) { BlockStoragePolicy[] policies = dfs.getStoragePolicies(); for (BlockStoragePolicy policy : policies) { if (policy.getId() == storagePolicyId) { return policy.getName(); } } } } } } catch (Throwable e) { LOG.warn("failed to get block storage policy of [" + path + "]", e); } return null; }
Example 2
Source File: StoragePolicyAdmin.java From hadoop with Apache License 2.0 | 5 votes |
@Override public int run(Configuration conf, List<String> args) throws IOException { final String path = StringUtils.popOptionWithArgument("-path", args); if (path == null) { System.err.println("Please specify the path with -path.\nUsage:" + getLongUsage()); return 1; } final DistributedFileSystem dfs = AdminHelper.getDFS(conf); try { HdfsFileStatus status = dfs.getClient().getFileInfo(path); if (status == null) { System.err.println("File/Directory does not exist: " + path); return 2; } byte storagePolicyId = status.getStoragePolicy(); if (storagePolicyId == BlockStoragePolicySuite.ID_UNSPECIFIED) { System.out.println("The storage policy of " + path + " is unspecified"); return 0; } BlockStoragePolicy[] policies = dfs.getStoragePolicies(); for (BlockStoragePolicy p : policies) { if (p.getId() == storagePolicyId) { System.out.println("The storage policy of " + path + ":\n" + p); return 0; } } } catch (Exception e) { System.err.println(AdminHelper.prettifyException(e)); return 2; } System.err.println("Cannot identify the storage policy for " + path); return 2; }
Example 3
Source File: StoragePolicyAdmin.java From big-c with Apache License 2.0 | 5 votes |
@Override public int run(Configuration conf, List<String> args) throws IOException { final String path = StringUtils.popOptionWithArgument("-path", args); if (path == null) { System.err.println("Please specify the path with -path.\nUsage:" + getLongUsage()); return 1; } final DistributedFileSystem dfs = AdminHelper.getDFS(conf); try { HdfsFileStatus status = dfs.getClient().getFileInfo(path); if (status == null) { System.err.println("File/Directory does not exist: " + path); return 2; } byte storagePolicyId = status.getStoragePolicy(); if (storagePolicyId == BlockStoragePolicySuite.ID_UNSPECIFIED) { System.out.println("The storage policy of " + path + " is unspecified"); return 0; } BlockStoragePolicy[] policies = dfs.getStoragePolicies(); for (BlockStoragePolicy p : policies) { if (p.getId() == storagePolicyId) { System.out.println("The storage policy of " + path + ":\n" + p); return 0; } } } catch (Exception e) { System.err.println(AdminHelper.prettifyException(e)); return 2; } System.err.println("Cannot identify the storage policy for " + path); return 2; }
Example 4
Source File: HFileSystem.java From hbase with Apache License 2.0 | 5 votes |
/** * Before Hadoop 2.8.0, there's no getStoragePolicy method for FileSystem interface, and we need * to keep compatible with it. See HADOOP-12161 for more details. * @param path Path to get storage policy against * @return the storage policy name */ private String getStoragePolicyForOldHDFSVersion(Path path) { try { if (this.fs instanceof DistributedFileSystem) { DistributedFileSystem dfs = (DistributedFileSystem) this.fs; HdfsFileStatus status = dfs.getClient().getFileInfo(path.toUri().getPath()); if (null != status) { if (unspecifiedStoragePolicyId < 0) { // Get the unspecified id field through reflection to avoid compilation error. // In later version BlockStoragePolicySuite#ID_UNSPECIFIED is moved to // HdfsConstants#BLOCK_STORAGE_POLICY_ID_UNSPECIFIED Field idUnspecified = BlockStoragePolicySuite.class.getField("ID_UNSPECIFIED"); unspecifiedStoragePolicyId = idUnspecified.getByte(BlockStoragePolicySuite.class); } byte storagePolicyId = status.getStoragePolicy(); if (storagePolicyId != unspecifiedStoragePolicyId) { BlockStoragePolicy[] policies = dfs.getStoragePolicies(); for (BlockStoragePolicy policy : policies) { if (policy.getId() == storagePolicyId) { return policy.getName(); } } } } } } catch (Throwable e) { LOG.warn("failed to get block storage policy of [" + path + "]", e); } return null; }
Example 5
Source File: DFSOutputStream.java From hadoop with Apache License 2.0 | 4 votes |
private static boolean isLazyPersist(HdfsFileStatus stat) { final BlockStoragePolicy p = blockStoragePolicySuite.getPolicy( HdfsConstants.MEMORY_STORAGE_POLICY_NAME); return p != null && stat.getStoragePolicy() == p.getId(); }
Example 6
Source File: DFSOutputStream.java From big-c with Apache License 2.0 | 4 votes |
private static boolean isLazyPersist(HdfsFileStatus stat) { final BlockStoragePolicy p = blockStoragePolicySuite.getPolicy( HdfsConstants.MEMORY_STORAGE_POLICY_NAME); return p != null && stat.getStoragePolicy() == p.getId(); }