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:
[email protected]


With regards,
Apache Git Services

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

Reply via email to