cloudstack-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jburwell <...@git.apache.org>
Subject [GitHub] cloudstack pull request #1615: CLOUDSTACK-9438: Fix for CLOUDSTACK-9252 - Ma...
Date Fri, 05 Aug 2016 22:08:47 GMT
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/1615#discussion_r73766528
  
    --- Diff: server/src/com/cloud/storage/ImageStoreDetailsUtil.java ---
    @@ -20,48 +20,68 @@
     
     import javax.inject.Inject;
     
    +import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
    +import org.apache.cloudstack.framework.config.impl.ConfigurationVO;
     import org.apache.cloudstack.storage.datastore.db.ImageStoreDao;
     import org.apache.cloudstack.storage.datastore.db.ImageStoreDetailsDao;
     import org.apache.cloudstack.storage.datastore.db.ImageStoreVO;
     
    +import com.cloud.capacity.CapacityManager;
    +
     public class ImageStoreDetailsUtil {
     
         @Inject
         protected ImageStoreDao imageStoreDao;
         @Inject
         protected ImageStoreDetailsDao imageStoreDetailsDao;
    +    @Inject
    +    protected ConfigurationDao configurationDao;
     
         /**
    -     * Obtain NFS protocol version (if provided) for a store id.<br/>
    -     * It can be set by adding an entry in {@code image_store_details} table, providing
{@code name=nfs.version} and {@code value=X} (e.g. 3)
    +     * Retrieve global secondary storage NFS version default value
    +     * @return global default value
    +     */
    +    protected Integer getGlobalDefaultNfsVersion(){
    +        ConfigurationVO globalNfsVersion = configurationDao.findByName(CapacityManager.ImageStoreNFSVersion.key());
    +        String value = globalNfsVersion.getValue();
    +        return (value != null ? Integer.valueOf(value) : null);
    +    }
    +    /**
    +     * Obtain NFS protocol version (if provided) for a store id, if not use default config
value<br/>
          * @param storeId image store id
    -     * @return {@code null} if {@code nfs.version} is not found for storeId <br/>
    -     * {@code X} if {@code nfs.version} is found found for storeId
    +     * @return {@code null} if {@code secstorage.nfs.version} is not found for storeId
<br/>
    +     * {@code X} if {@code secstorage.nfs.version} is found found for storeId
          */
         public Integer getNfsVersion(long storeId) throws NumberFormatException {
    -        String nfsVersion = null;
    +        Integer nfsVersion;
             if (imageStoreDetailsDao.getDetails(storeId) != null){
                 Map<String, String> storeDetails = imageStoreDetailsDao.getDetails(storeId);
    --- End diff --
    
    I recognize that this code predates this patch, but it is a double API call.  Consider
the following refactoring:
    
    ```
    public Integer getNfsVersion(long storeId) throws NumberFormatException {
    
        final Map<String, String> storeDetails = imageStoreDetailsDao.getDetails(storeId);
        if (storeDetails != null && storeDetails.containsKey(CapacityManager.ImageStoreNFSVersion.key()))
{
            final String version = storeDetails.get(CapacityManager.ImageStoreNFSVersion.key());
            return (val != null ? Integer.valueOf(val) : null);
        }
    
        return getGlobalDefaultNfsVersion();
    
    }
    ```


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message