[ 
https://issues.apache.org/jira/browse/HDFS-11968?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16173678#comment-16173678
 ] 

Surendra Singh Lilhore commented on HDFS-11968:
-----------------------------------------------

Thanks [~msingh] patch. {{getStoragePolicy}} command is depend on 
{{HdfsFileStatus}} and {{BlockStoragePolicy}} to get the policy Id, which is 
specific to the HDFS. Lets not change any public 
interface({{BlockStoragePolicySpi}}) to get the policy ID. 
Try this code for {{getStoragePolicy}} command.
{code}
      try {
        FileStatus status;
        try {
          status = fs.getFileStatus(new Path(path));
        } catch (FileNotFoundException e) {
          System.err.println("File/Directory does not exist: " + path);
          return 2;
        }
        if (status instanceof HdfsFileStatus) {
          byte storagePolicyId = ((HdfsFileStatus) status).getStoragePolicy();
          if (storagePolicyId == 
HdfsConstants.BLOCK_STORAGE_POLICY_ID_UNSPECIFIED) {
            System.out.println("The storage policy of " + path
                + " is unspecified");
            return 0;
          }
          Collection<? extends BlockStoragePolicySpi> policies = fs
              .getAllStoragePolicies();
          for (BlockStoragePolicySpi policy : policies) {
            if (policy instanceof BlockStoragePolicy) {
              if (((BlockStoragePolicy) policy).getId() == storagePolicyId) {
                System.out.println("The storage policy of " + path + ":\n"
                    + policy);
                return 0;
              }
            }
          }
        }
        System.out.println(getName() + " is not supported for filesystem "
            + fs.getScheme() + " on path " + path);
        return 2;
      } catch (Exception e) {
        System.err.println(AdminHelper.prettifyException(e));
        return 2;
      }
{code}

> ViewFS: StoragePolicies commands fail with HDFS federation
> ----------------------------------------------------------
>
>                 Key: HDFS-11968
>                 URL: https://issues.apache.org/jira/browse/HDFS-11968
>             Project: Hadoop HDFS
>          Issue Type: Bug
>          Components: hdfs
>    Affects Versions: 2.7.1
>            Reporter: Mukul Kumar Singh
>            Assignee: Mukul Kumar Singh
>         Attachments: HDFS-11968.001.patch, HDFS-11968.002.patch, 
> HDFS-11968.003.patch, HDFS-11968.004.patch, HDFS-11968.005.patch, 
> HDFS-11968.006.patch, HDFS-11968.007.patch
>
>
> hdfs storagepolicies command fails with HDFS federation.
> For storage policies commands, a given user path should be resolved to a HDFS 
> path and
> storage policy command should be applied onto the resolved HDFS path.
> {code}
>   static DistributedFileSystem getDFS(Configuration conf)
>       throws IOException {
>     FileSystem fs = FileSystem.get(conf);
>     if (!(fs instanceof DistributedFileSystem)) {
>       throw new IllegalArgumentException("FileSystem " + fs.getUri() +
>           " is not an HDFS file system");
>     }
>     return (DistributedFileSystem)fs;
>   }
> {code}



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to