You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ozone.apache.org by GitBox <gi...@apache.org> on 2019/12/22 10:42:44 UTC

[GitHub] [hadoop-ozone] nandakumar131 commented on issue #385: HDDS-2779. Fix list volume for --start parameter

nandakumar131 commented on issue #385: HDDS-2779. Fix list volume for --start parameter
URL: https://github.com/apache/hadoop-ozone/pull/385#issuecomment-568250705
 
 
   Thanks @cxorm for working on this.
   
   Suggestion:
   You can simplify `listVolumes` code with the below one
   
   ```
   public List<OmVolumeArgs> listVolumes(String userName,
         String prefix, String startKey, int maxKeys) throws IOException {
   
       if (StringUtil.isBlank(userName)) {
         throw new OMException("User name is required to list Volumes.",
             ResultCodes.USER_NOT_FOUND);
       }
   
       final List<OmVolumeArgs> result = Lists.newArrayList();
       final List<String> volumes = getVolumesByUser(userName)
           .getVolumeNamesList();
   
       int index = 0;
       if (!Strings.isNullOrEmpty(startKey)) {
         index = volumes.indexOf(startKey.startsWith(OzoneConsts.OM_KEY_PREFIX) ?
             startKey.substring(1) : startKey);
       }
       final String startChar = prefix == null ? "" : prefix;
   
       while (index != -1 && index < volumes.size() && result.size() < maxKeys) {
         final String volumeName = volumes.get(index);
         if (volumeName.startsWith(startChar)) {
           final OmVolumeArgs volumeArgs = getVolumeTable()
               .get(getVolumeKey(volumeName));
           if (volumeArgs == null) {
             // Could not get volume info by given volume name,
             // since the volume name is loaded from db,
             // this probably means om db is corrupted or some entries are
             // accidentally removed.
             throw new OMException("Volume info not found for " + volumeName,
                 ResultCodes.VOLUME_NOT_FOUND);
           }
           result.add(volumeArgs);
         }
         index++;
       }
       return result;
     }
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: ozone-issues-unsubscribe@hadoop.apache.org
For additional commands, e-mail: ozone-issues-help@hadoop.apache.org