You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by GitBox <gi...@apache.org> on 2021/08/12 09:01:17 UTC

[GitHub] [cloudstack] davidjumani opened a new pull request #5307: Filter disk / service offerings by domain at DB level

davidjumani opened a new pull request #5307:
URL: https://github.com/apache/cloudstack/pull/5307


   ### Description
   
   Fixes https://github.com/apache/cloudstack/issues/5290
   Fixes incorrect count returned in listServiceOfferings and listDiskOfferings caused by filtering records in the manager rather than directly in the database
   
   ### Types of changes
   
   - [ ] Breaking change (fix or feature that would cause existing functionality to change)
   - [ ] New feature (non-breaking change which adds functionality)
   - [x] Bug fix (non-breaking change which fixes an issue)
   - [ ] Enhancement (improves an existing feature and functionality)
   - [ ] Cleanup (Code refactoring and cleanup, that may add test cases)
   
   #### Bug Severity
   
   - [ ] BLOCKER
   - [ ] Critical
   - [ ] Major
   - [x] Minor
   - [ ] Trivial
   
   ### How Has This Been Tested?
   TODO


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] ravening commented on a change in pull request #5307: Filter disk / service offerings by domain at DB level

Posted by GitBox <gi...@apache.org>.
ravening commented on a change in pull request #5307:
URL: https://github.com/apache/cloudstack/pull/5307#discussion_r697536310



##########
File path: server/src/main/java/com/cloud/api/query/QueryManagerImpl.java
##########
@@ -2824,75 +2826,42 @@
             sc.addAnd("zoneId", SearchCriteria.Op.SC, zoneSC);
         }
 
-        // FIXME: disk offerings should search back up the hierarchy for
-        // available disk offerings...
-        /*
-         * sb.addAnd("domainId", sb.entity().getDomainId(),
-         * SearchCriteria.Op.EQ); if (domainId != null) {
-         * SearchBuilder<DomainVO> domainSearch =
-         * _domainDao.createSearchBuilder(); domainSearch.addAnd("path",
-         * domainSearch.entity().getPath(), SearchCriteria.Op.LIKE);
-         * sb.join("domainSearch", domainSearch, sb.entity().getDomainId(),
-         * domainSearch.entity().getId()); }
-         */
-
-        // FIXME: disk offerings should search back up the hierarchy for
-        // available disk offerings...
-        /*
-         * if (domainId != null) { sc.setParameters("domainId", domainId); //
-         * //DomainVO domain = _domainDao.findById((Long)domainId); // // I want
-         * to join on user_vm.domain_id = domain.id where domain.path like
-         * 'foo%' //sc.setJoinParameters("domainSearch", "path",
-         * domain.getPath() + "%"); // }
-         */
-
-        Pair<List<DiskOfferingJoinVO>, Integer> result = _diskOfferingJoinDao.searchAndCount(sc, searchFilter);
-        // Remove offerings that are not associated with caller's domain
-        if (account.getType() != Account.ACCOUNT_TYPE_ADMIN && CollectionUtils.isNotEmpty(result.first())) {
-            ListIterator<DiskOfferingJoinVO> it = result.first().listIterator();
-            while (it.hasNext()) {
-                DiskOfferingJoinVO offering = it.next();
-                if(!Strings.isNullOrEmpty(offering.getDomainId())) {
-                    boolean toRemove = true;
-                    String[] domainIdsArray = offering.getDomainId().split(",");
-                    for (String domainIdString : domainIdsArray) {
-                        Long dId = Long.valueOf(domainIdString.trim());
-                        if (isRecursive) {
-                            if (_domainDao.isChildDomain(account.getDomainId(), dId)) {
-                                toRemove = false;
-                                break;
-                            }
-                        } else {
-                            if (_domainDao.isChildDomain(dId, account.getDomainId())) {
-                                toRemove = false;
-                                break;
-                            }
-                        }
-                    }
-                    if (toRemove) {
-                        it.remove();
-                    }
-                }
+        // Filter offerings that are not associated with caller's domain
+        // Fetch the offering ids from the details table since theres no smart way to filter them in the join ... yet!
+        Account caller = CallContext.current().getCallingAccount();
+        if (caller.getType() != Account.ACCOUNT_TYPE_ADMIN) {
+            Domain callerDomain = _domainDao.findById(caller.getDomainId());
+            List<Long> domainIds = _domainDao.getDomainParentIds(callerDomain.getId())
+                .stream().collect(Collectors.toList());
+            if (isRecursive) {
+                List<Long> childrenIds = _domainDao.getDomainChildrenIds(callerDomain.getPath());
+                if (childrenIds != null && !childrenIds.isEmpty())
+                domainIds.addAll(childrenIds);
             }
-        }
-        return new Pair<>(result.first(), result.second());
-    }
 
-    private List<ServiceOfferingJoinVO> filterOfferingsOnCurrentTags(List<ServiceOfferingJoinVO> offerings, ServiceOfferingVO currentVmOffering) {
-        if (currentVmOffering == null) {
-            return offerings;
-        }
-        List<String> currentTagsList = StringUtils.csvTagsToList(currentVmOffering.getTags());
+            List<Long> ids = _diskOfferingDetailsDao.findOfferingIdsByDomainIds(domainIds);
+
+            if (ids == null || ids.isEmpty()) {

Review comment:
       if else part can be refactored as follows as most of it contains common code
   
   ```
   SearchBuilder<DiskOfferingJoinVO> sb = _diskOfferingJoinDao.createSearchBuilder();
   sb.or("domainId", sb.entity().getDomainId(), Op.NULL);
   
   SearchCriteria<DiskOfferingJoinVO> scc = sb.create();
   sc.addAnd("domainId", SearchCriteria.Op.SC, scc);
   
   if (ids != null &&  !ids.isEmpty()) {
       sb.and("id", sb.entity().getId(), Op.IN);
       scc.setParameters("id", ids.toArray());
   }
   
   sb.done();
   ```




-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] blueorangutan commented on pull request #5307: Filter disk / service offerings by domain at DB level

Posted by GitBox <gi...@apache.org>.
blueorangutan commented on pull request #5307:
URL: https://github.com/apache/cloudstack/pull/5307#issuecomment-902519653


   @shwstppr a Jenkins job has been kicked to build packages. I'll keep you posted as I make progress.


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] davidjumani commented on pull request #5307: Filter disk / service offerings by domain at DB level

Posted by GitBox <gi...@apache.org>.
davidjumani commented on pull request #5307:
URL: https://github.com/apache/cloudstack/pull/5307#issuecomment-901643077


   @nvazquez @shwstppr Will it be a good idea to filter the tags in the DB as well ? Might lead to a longer query but I think it'll be fine since I doubt there will be dozens of tags
   
   ```
           if (currentVmOffering != null) {
               List<String> tags = StringUtils.csvTagsToList(currentVmOffering.getTags());
               SearchBuilder<ServiceOfferingJoinVO> sb = _srvOfferingJoinDao.createSearchBuilder();
               for(String tag: tags) {
                   sb.and(tag, sb.entity().getTags(), Op.FIND_IN_SET);
               }
               sb.done();
   
               SearchCriteria<ServiceOfferingJoinVO> scc = sb.create();
               for(String tag: tags) {
                   scc.setParameters(tag, tag);
               }
               sc.addAnd("tags", SearchCriteria.Op.SC, scc);
           }
   
   ```


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] blueorangutan commented on pull request #5307: Filter disk / service offerings by domain at DB level

Posted by GitBox <gi...@apache.org>.
blueorangutan commented on pull request #5307:
URL: https://github.com/apache/cloudstack/pull/5307#issuecomment-911243731


   Packaging result: :heavy_check_mark: el7 :heavy_check_mark: el8 :heavy_check_mark: debian. SL-JID 1093


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] blueorangutan commented on pull request #5307: Filter disk / service offerings by domain at DB level

Posted by GitBox <gi...@apache.org>.
blueorangutan commented on pull request #5307:
URL: https://github.com/apache/cloudstack/pull/5307#issuecomment-911491920


   Packaging result: :heavy_check_mark: el7 :heavy_check_mark: el8 :heavy_check_mark: debian. SL-JID 1100


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] davidjumani commented on pull request #5307: Filter disk / service offerings by domain at DB level

Posted by GitBox <gi...@apache.org>.
davidjumani commented on pull request #5307:
URL: https://github.com/apache/cloudstack/pull/5307#issuecomment-911564125


   @blueorangutan test


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] blueorangutan commented on pull request #5307: Filter disk / service offerings by domain at DB level

Posted by GitBox <gi...@apache.org>.
blueorangutan commented on pull request #5307:
URL: https://github.com/apache/cloudstack/pull/5307#issuecomment-911514316


   <b>Trillian Build Failed (tid-1932)<b/>


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] blueorangutan removed a comment on pull request #5307: Filter disk / service offerings by domain at DB level

Posted by GitBox <gi...@apache.org>.
blueorangutan removed a comment on pull request #5307:
URL: https://github.com/apache/cloudstack/pull/5307#issuecomment-909973317


   @rhtyd a Trillian-Jenkins test job (centos7 mgmt + kvm-centos7) has been kicked to run smoke tests


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] blueorangutan commented on pull request #5307: Filter disk / service offerings by domain at DB level

Posted by GitBox <gi...@apache.org>.
blueorangutan commented on pull request #5307:
URL: https://github.com/apache/cloudstack/pull/5307#issuecomment-902568675


   Packaging result: :heavy_check_mark: el7 :heavy_check_mark: el8 :heavy_multiplication_x: debian. SL-JID 951


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] nvazquez commented on pull request #5307: Filter disk / service offerings by domain at DB level

Posted by GitBox <gi...@apache.org>.
nvazquez commented on pull request #5307:
URL: https://github.com/apache/cloudstack/pull/5307#issuecomment-909404070


   @blueorangutan test


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] blueorangutan commented on pull request #5307: Filter disk / service offerings by domain at DB level

Posted by GitBox <gi...@apache.org>.
blueorangutan commented on pull request #5307:
URL: https://github.com/apache/cloudstack/pull/5307#issuecomment-911555341


   Packaging result: :heavy_check_mark: el7 :heavy_check_mark: el8 :heavy_check_mark: debian. SL-JID 1103


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] davidjumani removed a comment on pull request #5307: Filter disk / service offerings by domain at DB level

Posted by GitBox <gi...@apache.org>.
davidjumani removed a comment on pull request #5307:
URL: https://github.com/apache/cloudstack/pull/5307#issuecomment-911422718


   @blueorangutan package


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] davidjumani commented on a change in pull request #5307: Filter disk / service offerings by domain at DB level

Posted by GitBox <gi...@apache.org>.
davidjumani commented on a change in pull request #5307:
URL: https://github.com/apache/cloudstack/pull/5307#discussion_r700893129



##########
File path: engine/schema/src/main/java/com/cloud/service/dao/ServiceOfferingDetailsDaoImpl.java
##########
@@ -67,4 +71,23 @@ public String getDetail(Long serviceOfferingId, String key) {
         }
         return detailValue;
     }
+
+    @Override
+    public List<Long> findOfferingIdsByDomainIds(List<Long> domainIds) {
+        Object[] dIds = domainIds.stream().map(s -> String.valueOf(s)).collect(Collectors.toList()).toArray();

Review comment:
       Refactored and updated

##########
File path: engine/schema/src/main/java/org/apache/cloudstack/resourcedetail/dao/DiskOfferingDetailsDaoImpl.java
##########
@@ -66,4 +71,25 @@ public String getDetail(Long diskOfferingId, String key) {
         }
         return detailValue;
     }
-}
\ No newline at end of file
+
+    @Override
+    public List<Long> findOfferingIdsByDomainIds(List<Long> domainIds) {

Review comment:
       Refactored and updated




-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] blueorangutan commented on pull request #5307: Filter disk / service offerings by domain at DB level

Posted by GitBox <gi...@apache.org>.
blueorangutan commented on pull request #5307:
URL: https://github.com/apache/cloudstack/pull/5307#issuecomment-909404528


   @nvazquez a Trillian-Jenkins test job (centos7 mgmt + kvm-centos7) has been kicked to run smoke tests


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] rhtyd commented on pull request #5307: Filter disk / service offerings by domain at DB level

Posted by GitBox <gi...@apache.org>.
rhtyd commented on pull request #5307:
URL: https://github.com/apache/cloudstack/pull/5307#issuecomment-911500994


   @blueorangutan test


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] davidjumani commented on pull request #5307: Filter disk / service offerings by domain at DB level

Posted by GitBox <gi...@apache.org>.
davidjumani commented on pull request #5307:
URL: https://github.com/apache/cloudstack/pull/5307#issuecomment-901645589


   @blueorangutan package


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] blueorangutan commented on pull request #5307: Filter disk / service offerings by domain at DB level

Posted by GitBox <gi...@apache.org>.
blueorangutan commented on pull request #5307:
URL: https://github.com/apache/cloudstack/pull/5307#issuecomment-902534944


   Packaging result: :heavy_check_mark: el7 :heavy_check_mark: el8 :heavy_check_mark: debian. SL-JID 948


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] blueorangutan commented on pull request #5307: Filter disk / service offerings by domain at DB level

Posted by GitBox <gi...@apache.org>.
blueorangutan commented on pull request #5307:
URL: https://github.com/apache/cloudstack/pull/5307#issuecomment-901656048


   Packaging result: :heavy_check_mark: el7 :heavy_check_mark: el8 :heavy_check_mark: debian. SL-JID 928


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] rhtyd commented on pull request #5307: Filter disk / service offerings by domain at DB level

Posted by GitBox <gi...@apache.org>.
rhtyd commented on pull request #5307:
URL: https://github.com/apache/cloudstack/pull/5307#issuecomment-909044492


   @blueorangutan package


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] blueorangutan removed a comment on pull request #5307: Filter disk / service offerings by domain at DB level

Posted by GitBox <gi...@apache.org>.
blueorangutan removed a comment on pull request #5307:
URL: https://github.com/apache/cloudstack/pull/5307#issuecomment-911424187


   @davidjumani a Jenkins job has been kicked to build packages. I'll keep you posted as I make progress.


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] rhtyd commented on pull request #5307: Filter disk / service offerings by domain at DB level

Posted by GitBox <gi...@apache.org>.
rhtyd commented on pull request #5307:
URL: https://github.com/apache/cloudstack/pull/5307#issuecomment-909044492






-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] nvazquez commented on pull request #5307: Filter disk / service offerings by domain at DB level

Posted by GitBox <gi...@apache.org>.
nvazquez commented on pull request #5307:
URL: https://github.com/apache/cloudstack/pull/5307#issuecomment-912214489


   Merging based on approvals and test results (failure not related to the PR)


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] blueorangutan commented on pull request #5307: Filter disk / service offerings by domain at DB level

Posted by GitBox <gi...@apache.org>.
blueorangutan commented on pull request #5307:
URL: https://github.com/apache/cloudstack/pull/5307#issuecomment-909044859






-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] nvazquez commented on pull request #5307: Filter disk / service offerings by domain at DB level

Posted by GitBox <gi...@apache.org>.
nvazquez commented on pull request #5307:
URL: https://github.com/apache/cloudstack/pull/5307#issuecomment-901990137


   @davidjumani I see your point, thanks. +1 from me unless @shwstppr has any concern


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] blueorangutan commented on pull request #5307: Filter disk / service offerings by domain at DB level

Posted by GitBox <gi...@apache.org>.
blueorangutan commented on pull request #5307:
URL: https://github.com/apache/cloudstack/pull/5307#issuecomment-901631382


   @davidjumani a Jenkins job has been kicked to build packages. I'll keep you posted as I make progress.


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] blueorangutan commented on pull request #5307: Filter disk / service offerings by domain at DB level

Posted by GitBox <gi...@apache.org>.
blueorangutan commented on pull request #5307:
URL: https://github.com/apache/cloudstack/pull/5307#issuecomment-909065144


   Packaging result: :heavy_check_mark: el7 :heavy_check_mark: el8 :heavy_check_mark: debian. SL-JID 1074


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] blueorangutan commented on pull request #5307: Filter disk / service offerings by domain at DB level

Posted by GitBox <gi...@apache.org>.
blueorangutan commented on pull request #5307:
URL: https://github.com/apache/cloudstack/pull/5307#issuecomment-901643023


   Packaging result: :heavy_check_mark: el7 :heavy_check_mark: el8 :heavy_check_mark: debian. SL-JID 927


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] ravening commented on a change in pull request #5307: Filter disk / service offerings by domain at DB level

Posted by GitBox <gi...@apache.org>.
ravening commented on a change in pull request #5307:
URL: https://github.com/apache/cloudstack/pull/5307#discussion_r697529920



##########
File path: engine/schema/src/main/java/com/cloud/service/dao/ServiceOfferingDetailsDaoImpl.java
##########
@@ -67,4 +71,23 @@ public String getDetail(Long serviceOfferingId, String key) {
         }
         return detailValue;
     }
+
+    @Override
+    public List<Long> findOfferingIdsByDomainIds(List<Long> domainIds) {
+        Object[] dIds = domainIds.stream().map(s -> String.valueOf(s)).collect(Collectors.toList()).toArray();

Review comment:
       better to mention String[] rather than Object[] since you are explicitly getting string value?

##########
File path: server/src/main/java/com/cloud/api/query/QueryManagerImpl.java
##########
@@ -2824,75 +2826,42 @@
             sc.addAnd("zoneId", SearchCriteria.Op.SC, zoneSC);
         }
 
-        // FIXME: disk offerings should search back up the hierarchy for
-        // available disk offerings...
-        /*
-         * sb.addAnd("domainId", sb.entity().getDomainId(),
-         * SearchCriteria.Op.EQ); if (domainId != null) {
-         * SearchBuilder<DomainVO> domainSearch =
-         * _domainDao.createSearchBuilder(); domainSearch.addAnd("path",
-         * domainSearch.entity().getPath(), SearchCriteria.Op.LIKE);
-         * sb.join("domainSearch", domainSearch, sb.entity().getDomainId(),
-         * domainSearch.entity().getId()); }
-         */
-
-        // FIXME: disk offerings should search back up the hierarchy for
-        // available disk offerings...
-        /*
-         * if (domainId != null) { sc.setParameters("domainId", domainId); //
-         * //DomainVO domain = _domainDao.findById((Long)domainId); // // I want
-         * to join on user_vm.domain_id = domain.id where domain.path like
-         * 'foo%' //sc.setJoinParameters("domainSearch", "path",
-         * domain.getPath() + "%"); // }
-         */
-
-        Pair<List<DiskOfferingJoinVO>, Integer> result = _diskOfferingJoinDao.searchAndCount(sc, searchFilter);
-        // Remove offerings that are not associated with caller's domain
-        if (account.getType() != Account.ACCOUNT_TYPE_ADMIN && CollectionUtils.isNotEmpty(result.first())) {
-            ListIterator<DiskOfferingJoinVO> it = result.first().listIterator();
-            while (it.hasNext()) {
-                DiskOfferingJoinVO offering = it.next();
-                if(!Strings.isNullOrEmpty(offering.getDomainId())) {
-                    boolean toRemove = true;
-                    String[] domainIdsArray = offering.getDomainId().split(",");
-                    for (String domainIdString : domainIdsArray) {
-                        Long dId = Long.valueOf(domainIdString.trim());
-                        if (isRecursive) {
-                            if (_domainDao.isChildDomain(account.getDomainId(), dId)) {
-                                toRemove = false;
-                                break;
-                            }
-                        } else {
-                            if (_domainDao.isChildDomain(dId, account.getDomainId())) {
-                                toRemove = false;
-                                break;
-                            }
-                        }
-                    }
-                    if (toRemove) {
-                        it.remove();
-                    }
-                }
+        // Filter offerings that are not associated with caller's domain
+        // Fetch the offering ids from the details table since theres no smart way to filter them in the join ... yet!
+        Account caller = CallContext.current().getCallingAccount();
+        if (caller.getType() != Account.ACCOUNT_TYPE_ADMIN) {
+            Domain callerDomain = _domainDao.findById(caller.getDomainId());
+            List<Long> domainIds = _domainDao.getDomainParentIds(callerDomain.getId())
+                .stream().collect(Collectors.toList());
+            if (isRecursive) {
+                List<Long> childrenIds = _domainDao.getDomainChildrenIds(callerDomain.getPath());
+                if (childrenIds != null && !childrenIds.isEmpty())
+                domainIds.addAll(childrenIds);

Review comment:
       proper indentation here?

##########
File path: server/src/main/java/com/cloud/api/query/QueryManagerImpl.java
##########
@@ -2824,75 +2826,42 @@
             sc.addAnd("zoneId", SearchCriteria.Op.SC, zoneSC);
         }
 
-        // FIXME: disk offerings should search back up the hierarchy for
-        // available disk offerings...
-        /*
-         * sb.addAnd("domainId", sb.entity().getDomainId(),
-         * SearchCriteria.Op.EQ); if (domainId != null) {
-         * SearchBuilder<DomainVO> domainSearch =
-         * _domainDao.createSearchBuilder(); domainSearch.addAnd("path",
-         * domainSearch.entity().getPath(), SearchCriteria.Op.LIKE);
-         * sb.join("domainSearch", domainSearch, sb.entity().getDomainId(),
-         * domainSearch.entity().getId()); }
-         */
-
-        // FIXME: disk offerings should search back up the hierarchy for
-        // available disk offerings...
-        /*
-         * if (domainId != null) { sc.setParameters("domainId", domainId); //
-         * //DomainVO domain = _domainDao.findById((Long)domainId); // // I want
-         * to join on user_vm.domain_id = domain.id where domain.path like
-         * 'foo%' //sc.setJoinParameters("domainSearch", "path",
-         * domain.getPath() + "%"); // }
-         */
-
-        Pair<List<DiskOfferingJoinVO>, Integer> result = _diskOfferingJoinDao.searchAndCount(sc, searchFilter);
-        // Remove offerings that are not associated with caller's domain
-        if (account.getType() != Account.ACCOUNT_TYPE_ADMIN && CollectionUtils.isNotEmpty(result.first())) {
-            ListIterator<DiskOfferingJoinVO> it = result.first().listIterator();
-            while (it.hasNext()) {
-                DiskOfferingJoinVO offering = it.next();
-                if(!Strings.isNullOrEmpty(offering.getDomainId())) {
-                    boolean toRemove = true;
-                    String[] domainIdsArray = offering.getDomainId().split(",");
-                    for (String domainIdString : domainIdsArray) {
-                        Long dId = Long.valueOf(domainIdString.trim());
-                        if (isRecursive) {
-                            if (_domainDao.isChildDomain(account.getDomainId(), dId)) {
-                                toRemove = false;
-                                break;
-                            }
-                        } else {
-                            if (_domainDao.isChildDomain(dId, account.getDomainId())) {
-                                toRemove = false;
-                                break;
-                            }
-                        }
-                    }
-                    if (toRemove) {
-                        it.remove();
-                    }
-                }
+        // Filter offerings that are not associated with caller's domain
+        // Fetch the offering ids from the details table since theres no smart way to filter them in the join ... yet!
+        Account caller = CallContext.current().getCallingAccount();
+        if (caller.getType() != Account.ACCOUNT_TYPE_ADMIN) {
+            Domain callerDomain = _domainDao.findById(caller.getDomainId());
+            List<Long> domainIds = _domainDao.getDomainParentIds(callerDomain.getId())
+                .stream().collect(Collectors.toList());
+            if (isRecursive) {
+                List<Long> childrenIds = _domainDao.getDomainChildrenIds(callerDomain.getPath());
+                if (childrenIds != null && !childrenIds.isEmpty())
+                domainIds.addAll(childrenIds);
             }
-        }
-        return new Pair<>(result.first(), result.second());
-    }
 
-    private List<ServiceOfferingJoinVO> filterOfferingsOnCurrentTags(List<ServiceOfferingJoinVO> offerings, ServiceOfferingVO currentVmOffering) {
-        if (currentVmOffering == null) {
-            return offerings;
-        }
-        List<String> currentTagsList = StringUtils.csvTagsToList(currentVmOffering.getTags());
+            List<Long> ids = _diskOfferingDetailsDao.findOfferingIdsByDomainIds(domainIds);
+
+            if (ids == null || ids.isEmpty()) {

Review comment:
       if else part can be refactored as follows as most of it contains common code
   
   ```
   SearchBuilder<DiskOfferingJoinVO> sb = _diskOfferingJoinDao.createSearchBuilder();
   sb.or("domainId", sb.entity().getDomainId(), Op.NULL);
   
   SearchCriteria<DiskOfferingJoinVO> scc = sb.create();
   sc.addAnd("domainId", SearchCriteria.Op.SC, scc);
   
   if (ids != null &&  !ids.isEmpty()) {
       sb.and("id", sb.entity().getId(), Op.IN);
       scc.setParameters("id", ids.toArray());
   }
   
   sb.done();
   ```

##########
File path: engine/schema/src/main/java/org/apache/cloudstack/resourcedetail/dao/DiskOfferingDetailsDaoImpl.java
##########
@@ -66,4 +71,25 @@ public String getDetail(Long diskOfferingId, String key) {
         }
         return detailValue;
     }
-}
\ No newline at end of file
+
+    @Override
+    public List<Long> findOfferingIdsByDomainIds(List<Long> domainIds) {

Review comment:
       @davidjumani  This part is duplicated code right? this can be in a common place for both service and disk offering

##########
File path: server/src/main/java/com/cloud/api/query/QueryManagerImpl.java
##########
@@ -3064,39 +3033,72 @@
             sc.addAnd("cpuspeedconstraints", SearchCriteria.Op.SC, cpuSpeedSearchCriteria);
         }
 
-        Pair<List<ServiceOfferingJoinVO>, Integer> result = _srvOfferingJoinDao.searchAndCount(sc, searchFilter);
-
-        //Couldn't figure out a smart way to filter offerings based on tags in sql so doing it in Java.
-        List<ServiceOfferingJoinVO> filteredOfferings = filterOfferingsOnCurrentTags(result.first(), currentVmOffering);
-        // Remove offerings that are not associated with caller's domain
-        if (caller.getType() != Account.ACCOUNT_TYPE_ADMIN && CollectionUtils.isNotEmpty(filteredOfferings)) {
-            ListIterator<ServiceOfferingJoinVO> it = filteredOfferings.listIterator();
-            while (it.hasNext()) {
-                ServiceOfferingJoinVO offering = it.next();
-                if(!Strings.isNullOrEmpty(offering.getDomainId())) {
-                    boolean toRemove = true;
-                    String[] domainIdsArray = offering.getDomainId().split(",");
-                    for (String domainIdString : domainIdsArray) {
-                        Long dId = Long.valueOf(domainIdString.trim());
-                        if (isRecursive) {
-                            if (_domainDao.isChildDomain(caller.getDomainId(), dId)) {
-                                toRemove = false;
-                                break;
-                            }
-                        } else {
-                            if (_domainDao.isChildDomain(dId, caller.getDomainId())) {
-                                toRemove = false;
-                                break;
-                            }
-                        }
-                    }
-                    if (toRemove) {
-                        it.remove();
-                    }
+        // Filter offerings that are not associated with caller's domain
+        // Fetch the offering ids from the details table since theres no smart way to filter them in the join ... yet!
+        if (caller.getType() != Account.ACCOUNT_TYPE_ADMIN) {
+            Domain callerDomain = _domainDao.findById(caller.getDomainId());
+            List<Long> domainIds = _domainDao.getDomainParentIds(callerDomain.getId())
+                .stream().collect(Collectors.toList());
+            if (isRecursive) {
+                List<Long> childrenIds = _domainDao.getDomainChildrenIds(callerDomain.getPath());
+                if (childrenIds != null && !childrenIds.isEmpty())
+                domainIds.addAll(childrenIds);
+            }
+
+            List<Long> ids = _srvOfferingDetailsDao.findOfferingIdsByDomainIds(domainIds);

Review comment:
       Most of this is duplicated code. can be extracted to a single function.




-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] blueorangutan commented on pull request #5307: Filter disk / service offerings by domain at DB level

Posted by GitBox <gi...@apache.org>.
blueorangutan commented on pull request #5307:
URL: https://github.com/apache/cloudstack/pull/5307#issuecomment-909968130


   <b>Trillian Build Failed (tid-1890)<b/>


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] blueorangutan commented on pull request #5307: Filter disk / service offerings by domain at DB level

Posted by GitBox <gi...@apache.org>.
blueorangutan commented on pull request #5307:
URL: https://github.com/apache/cloudstack/pull/5307#issuecomment-911506391


   @ravening a Jenkins job has been kicked to build packages. I'll keep you posted as I make progress.


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] blueorangutan removed a comment on pull request #5307: Filter disk / service offerings by domain at DB level

Posted by GitBox <gi...@apache.org>.
blueorangutan removed a comment on pull request #5307:
URL: https://github.com/apache/cloudstack/pull/5307#issuecomment-910771558






-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] nvazquez commented on pull request #5307: Filter disk / service offerings by domain at DB level

Posted by GitBox <gi...@apache.org>.
nvazquez commented on pull request #5307:
URL: https://github.com/apache/cloudstack/pull/5307#issuecomment-909404070


   @blueorangutan test


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] blueorangutan commented on pull request #5307: Filter disk / service offerings by domain at DB level

Posted by GitBox <gi...@apache.org>.
blueorangutan commented on pull request #5307:
URL: https://github.com/apache/cloudstack/pull/5307#issuecomment-910771558


   <b>Trillian test result (tid-1892)</b>
   Environment: kvm-centos7 (x2), Advanced Networking with Mgmt server 7
   Total time taken: 49605 seconds
   Marvin logs: https://github.com/blueorangutan/acs-prs/releases/download/trillian/pr5307-t1892-kvm-centos7.zip
   Smoke tests completed. 88 look OK, 3 have errors
   Only failed tests results shown below:
   
   
   Test | Result | Time (s) | Test File
   --- | --- | --- | ---
   test_deploy_vm_start_failure | `Error` | 78.15 | test_deploy_vm.py
   test_deploy_vm_volume_creation_failure | `Error` | 61.73 | test_deploy_vm.py
   test_vm_ha | `Error` | 64.36 | test_vm_ha.py
   test_vm_sync | `Error` | 127.92 | test_vm_sync.py
   


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] blueorangutan commented on pull request #5307: Filter disk / service offerings by domain at DB level

Posted by GitBox <gi...@apache.org>.
blueorangutan commented on pull request #5307:
URL: https://github.com/apache/cloudstack/pull/5307#issuecomment-909973317


   @rhtyd a Trillian-Jenkins test job (centos7 mgmt + kvm-centos7) has been kicked to run smoke tests


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] blueorangutan commented on pull request #5307: Filter disk / service offerings by domain at DB level

Posted by GitBox <gi...@apache.org>.
blueorangutan commented on pull request #5307:
URL: https://github.com/apache/cloudstack/pull/5307#issuecomment-911444488


   @davidjumani a Jenkins job has been kicked to build packages. I'll keep you posted as I make progress.


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] DaanHoogland commented on a change in pull request #5307: Filter disk / service offerings by domain at DB level

Posted by GitBox <gi...@apache.org>.
DaanHoogland commented on a change in pull request #5307:
URL: https://github.com/apache/cloudstack/pull/5307#discussion_r692863034



##########
File path: server/src/main/java/com/cloud/api/query/QueryManagerImpl.java
##########
@@ -346,14 +345,17 @@
     private DiskOfferingJoinDao _diskOfferingJoinDao;
 
     @Inject
-    private DiskOfferingDetailsDao diskOfferingDetailsDao;
+    private DiskOfferingDetailsDao _diskOfferingDetailsDao;

Review comment:
       don't see the use of this consistency. the underscore does not value in field names, does it?




-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] nvazquez commented on pull request #5307: Filter disk / service offerings by domain at DB level

Posted by GitBox <gi...@apache.org>.
nvazquez commented on pull request #5307:
URL: https://github.com/apache/cloudstack/pull/5307#issuecomment-901841188


   @davidjumani I think it looks good, can we simply set the list of tags as parameter and use the `Op.IN` operator instead?


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] nvazquez commented on pull request #5307: Filter disk / service offerings by domain at DB level

Posted by GitBox <gi...@apache.org>.
nvazquez commented on pull request #5307:
URL: https://github.com/apache/cloudstack/pull/5307#issuecomment-910814014


   @blueorangutan test


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] blueorangutan commented on pull request #5307: Filter disk / service offerings by domain at DB level

Posted by GitBox <gi...@apache.org>.
blueorangutan commented on pull request #5307:
URL: https://github.com/apache/cloudstack/pull/5307#issuecomment-910072070


   <b>Trillian test result (tid-1870)</b>
   Environment: kvm-centos7 (x2), Advanced Networking with Mgmt server 7
   Total time taken: 55032 seconds
   Marvin logs: https://github.com/blueorangutan/acs-prs/releases/download/trillian/pr5307-t1870-kvm-centos7.zip
   Smoke tests completed. 87 look OK, 4 have errors
   Only failed tests results shown below:
   
   
   Test | Result | Time (s) | Test File
   --- | --- | --- | ---
   test_deploy_vm_start_failure | `Error` | 67.94 | test_deploy_vm.py
   test_deploy_vm_volume_creation_failure | `Error` | 66.66 | test_deploy_vm.py
   test_vm_ha | `Error` | 60.30 | test_vm_ha.py
   test_vm_sync | `Error` | 129.76 | test_vm_sync.py
   ContextSuite context=TestKubernetesCluster>:teardown | `Error` | 87.85 | test_kubernetes_clusters.py
   


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] blueorangutan commented on pull request #5307: Filter disk / service offerings by domain at DB level

Posted by GitBox <gi...@apache.org>.
blueorangutan commented on pull request #5307:
URL: https://github.com/apache/cloudstack/pull/5307#issuecomment-911424187


   @davidjumani a Jenkins job has been kicked to build packages. I'll keep you posted as I make progress.


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] davidjumani edited a comment on pull request #5307: Filter disk / service offerings by domain at DB level

Posted by GitBox <gi...@apache.org>.
davidjumani edited a comment on pull request #5307:
URL: https://github.com/apache/cloudstack/pull/5307#issuecomment-901843583


   @nvazquez I did think of that but as there are multiple tags in both the VM's offering and the service offerings an IN will not work (eg: looking for a,b,c in b,a,c,d,e). It's pretty much checking if the VM's offering tags are a subset of another offering's tags


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] blueorangutan commented on pull request #5307: Filter disk / service offerings by domain at DB level

Posted by GitBox <gi...@apache.org>.
blueorangutan commented on pull request #5307:
URL: https://github.com/apache/cloudstack/pull/5307#issuecomment-909044859


   @rhtyd a Jenkins job has been kicked to build packages. I'll keep you posted as I make progress.


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] ravening commented on a change in pull request #5307: Filter disk / service offerings by domain at DB level

Posted by GitBox <gi...@apache.org>.
ravening commented on a change in pull request #5307:
URL: https://github.com/apache/cloudstack/pull/5307#discussion_r698392211



##########
File path: server/src/main/java/com/cloud/api/query/QueryManagerImpl.java
##########
@@ -2824,75 +2826,42 @@
             sc.addAnd("zoneId", SearchCriteria.Op.SC, zoneSC);
         }
 
-        // FIXME: disk offerings should search back up the hierarchy for
-        // available disk offerings...
-        /*
-         * sb.addAnd("domainId", sb.entity().getDomainId(),
-         * SearchCriteria.Op.EQ); if (domainId != null) {
-         * SearchBuilder<DomainVO> domainSearch =
-         * _domainDao.createSearchBuilder(); domainSearch.addAnd("path",
-         * domainSearch.entity().getPath(), SearchCriteria.Op.LIKE);
-         * sb.join("domainSearch", domainSearch, sb.entity().getDomainId(),
-         * domainSearch.entity().getId()); }
-         */
-
-        // FIXME: disk offerings should search back up the hierarchy for
-        // available disk offerings...
-        /*
-         * if (domainId != null) { sc.setParameters("domainId", domainId); //
-         * //DomainVO domain = _domainDao.findById((Long)domainId); // // I want
-         * to join on user_vm.domain_id = domain.id where domain.path like
-         * 'foo%' //sc.setJoinParameters("domainSearch", "path",
-         * domain.getPath() + "%"); // }
-         */
-
-        Pair<List<DiskOfferingJoinVO>, Integer> result = _diskOfferingJoinDao.searchAndCount(sc, searchFilter);
-        // Remove offerings that are not associated with caller's domain
-        if (account.getType() != Account.ACCOUNT_TYPE_ADMIN && CollectionUtils.isNotEmpty(result.first())) {
-            ListIterator<DiskOfferingJoinVO> it = result.first().listIterator();
-            while (it.hasNext()) {
-                DiskOfferingJoinVO offering = it.next();
-                if(!Strings.isNullOrEmpty(offering.getDomainId())) {
-                    boolean toRemove = true;
-                    String[] domainIdsArray = offering.getDomainId().split(",");
-                    for (String domainIdString : domainIdsArray) {
-                        Long dId = Long.valueOf(domainIdString.trim());
-                        if (isRecursive) {
-                            if (_domainDao.isChildDomain(account.getDomainId(), dId)) {
-                                toRemove = false;
-                                break;
-                            }
-                        } else {
-                            if (_domainDao.isChildDomain(dId, account.getDomainId())) {
-                                toRemove = false;
-                                break;
-                            }
-                        }
-                    }
-                    if (toRemove) {
-                        it.remove();
-                    }
-                }
+        // Filter offerings that are not associated with caller's domain
+        // Fetch the offering ids from the details table since theres no smart way to filter them in the join ... yet!
+        Account caller = CallContext.current().getCallingAccount();
+        if (caller.getType() != Account.ACCOUNT_TYPE_ADMIN) {
+            Domain callerDomain = _domainDao.findById(caller.getDomainId());
+            List<Long> domainIds = _domainDao.getDomainParentIds(callerDomain.getId())
+                .stream().collect(Collectors.toList());
+            if (isRecursive) {
+                List<Long> childrenIds = _domainDao.getDomainChildrenIds(callerDomain.getPath());
+                if (childrenIds != null && !childrenIds.isEmpty())
+                domainIds.addAll(childrenIds);
             }
-        }
-        return new Pair<>(result.first(), result.second());
-    }
 
-    private List<ServiceOfferingJoinVO> filterOfferingsOnCurrentTags(List<ServiceOfferingJoinVO> offerings, ServiceOfferingVO currentVmOffering) {
-        if (currentVmOffering == null) {
-            return offerings;
-        }
-        List<String> currentTagsList = StringUtils.csvTagsToList(currentVmOffering.getTags());
+            List<Long> ids = _diskOfferingDetailsDao.findOfferingIdsByDomainIds(domainIds);
+
+            if (ids == null || ids.isEmpty()) {

Review comment:
       This can be refactored as 
   
   ```
               SearchBuilder<DiskOfferingJoinVO> sb = _diskOfferingJoinDao.createSearchBuilder();
               if (ids != null && !ids.isEmpty()) {
                   sb.and("id", sb.entity().getId(), Op.IN);
               }
               sb.or("domainId", sb.entity().getDomainId(), Op.NULL);
               sb.done();
   
               SearchCriteria<DiskOfferingJoinVO> scc = sb.create();
               if (ids != null && !ids.isEmpty()) {
                   scc.setParameters("id", ids.toArray());
               }
               sc.addAnd("domainId", SearchCriteria.Op.SC, scc);
   ```




-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] blueorangutan commented on pull request #5307: Filter disk / service offerings by domain at DB level

Posted by GitBox <gi...@apache.org>.
blueorangutan commented on pull request #5307:
URL: https://github.com/apache/cloudstack/pull/5307#issuecomment-902537701


   @davidjumani a Jenkins job has been kicked to build packages. I'll keep you posted as I make progress.


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] davidjumani commented on pull request #5307: Filter disk / service offerings by domain at DB level

Posted by GitBox <gi...@apache.org>.
davidjumani commented on pull request #5307:
URL: https://github.com/apache/cloudstack/pull/5307#issuecomment-902537576


   @blueorangutan package


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] davidjumani commented on pull request #5307: Filter disk / service offerings by domain at DB level

Posted by GitBox <gi...@apache.org>.
davidjumani commented on pull request #5307:
URL: https://github.com/apache/cloudstack/pull/5307#issuecomment-911443605


   @blueorangutan package


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] blueorangutan removed a comment on pull request #5307: Filter disk / service offerings by domain at DB level

Posted by GitBox <gi...@apache.org>.
blueorangutan removed a comment on pull request #5307:
URL: https://github.com/apache/cloudstack/pull/5307#issuecomment-909404528


   @nvazquez a Trillian-Jenkins test job (centos7 mgmt + kvm-centos7) has been kicked to run smoke tests


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] rhtyd commented on pull request #5307: Filter disk / service offerings by domain at DB level

Posted by GitBox <gi...@apache.org>.
rhtyd commented on pull request #5307:
URL: https://github.com/apache/cloudstack/pull/5307#issuecomment-911206286


   @blueorangutan package
   
   @davidjumani @nvazquez do we need any additional/manual testing? 


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] blueorangutan commented on pull request #5307: Filter disk / service offerings by domain at DB level

Posted by GitBox <gi...@apache.org>.
blueorangutan commented on pull request #5307:
URL: https://github.com/apache/cloudstack/pull/5307#issuecomment-910814411


   @nvazquez a Trillian-Jenkins test job (centos7 mgmt + kvm-centos7) has been kicked to run smoke tests


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] davidjumani commented on pull request #5307: Filter disk / service offerings by domain at DB level

Posted by GitBox <gi...@apache.org>.
davidjumani commented on pull request #5307:
URL: https://github.com/apache/cloudstack/pull/5307#issuecomment-902539890


   @blueorangutan package


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] blueorangutan commented on pull request #5307: Filter disk / service offerings by domain at DB level

Posted by GitBox <gi...@apache.org>.
blueorangutan commented on pull request #5307:
URL: https://github.com/apache/cloudstack/pull/5307#issuecomment-902540025


   @davidjumani a Jenkins job has been kicked to build packages. I'll keep you posted as I make progress.


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] ravening commented on pull request #5307: Filter disk / service offerings by domain at DB level

Posted by GitBox <gi...@apache.org>.
ravening commented on pull request #5307:
URL: https://github.com/apache/cloudstack/pull/5307#issuecomment-907183544


   probably it might fix this issue as well
   
   https://github.com/apache/cloudstack/issues/4195


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] blueorangutan removed a comment on pull request #5307: Filter disk / service offerings by domain at DB level

Posted by GitBox <gi...@apache.org>.
blueorangutan removed a comment on pull request #5307:
URL: https://github.com/apache/cloudstack/pull/5307#issuecomment-909968130


   <b>Trillian Build Failed (tid-1890)<b/>


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] rhtyd commented on pull request #5307: Filter disk / service offerings by domain at DB level

Posted by GitBox <gi...@apache.org>.
rhtyd commented on pull request #5307:
URL: https://github.com/apache/cloudstack/pull/5307#issuecomment-909972363


   @blueorangutan test


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] blueorangutan commented on pull request #5307: Filter disk / service offerings by domain at DB level

Posted by GitBox <gi...@apache.org>.
blueorangutan commented on pull request #5307:
URL: https://github.com/apache/cloudstack/pull/5307#issuecomment-911207354


   @rhtyd a Jenkins job has been kicked to build packages. I'll keep you posted as I make progress.


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] blueorangutan commented on pull request #5307: Filter disk / service offerings by domain at DB level

Posted by GitBox <gi...@apache.org>.
blueorangutan commented on pull request #5307:
URL: https://github.com/apache/cloudstack/pull/5307#issuecomment-909044859






-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] davidjumani commented on pull request #5307: Filter disk / service offerings by domain at DB level

Posted by GitBox <gi...@apache.org>.
davidjumani commented on pull request #5307:
URL: https://github.com/apache/cloudstack/pull/5307#issuecomment-911422718


   @blueorangutan package


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] blueorangutan commented on pull request #5307: Filter disk / service offerings by domain at DB level

Posted by GitBox <gi...@apache.org>.
blueorangutan commented on pull request #5307:
URL: https://github.com/apache/cloudstack/pull/5307#issuecomment-912112481


   <b>Trillian test result (tid-1935)</b>
   Environment: kvm-centos7 (x2), Advanced Networking with Mgmt server 7
   Total time taken: 39116 seconds
   Marvin logs: https://github.com/blueorangutan/acs-prs/releases/download/trillian/pr5307-t1935-kvm-centos7.zip
   Smoke tests completed. 86 look OK, 1 have errors
   Only failed tests results shown below:
   
   
   Test | Result | Time (s) | Test File
   --- | --- | --- | ---
   test_hostha_enable_ha_when_host_in_maintenance | `Error` | 300.52 | test_hostha_kvm.py
   


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] rhtyd commented on pull request #5307: Filter disk / service offerings by domain at DB level

Posted by GitBox <gi...@apache.org>.
rhtyd commented on pull request #5307:
URL: https://github.com/apache/cloudstack/pull/5307#issuecomment-909044492


   @blueorangutan package


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] ravening commented on pull request #5307: Filter disk / service offerings by domain at DB level

Posted by GitBox <gi...@apache.org>.
ravening commented on pull request #5307:
URL: https://github.com/apache/cloudstack/pull/5307#issuecomment-911505144


   > @blueorangutan package
   > 
   > @davidjumani @nvazquez do we need any additional/manual testing?
   
   @rhtyd we did manual testing and it looks good.


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] blueorangutan commented on pull request #5307: Filter disk / service offerings by domain at DB level

Posted by GitBox <gi...@apache.org>.
blueorangutan commented on pull request #5307:
URL: https://github.com/apache/cloudstack/pull/5307#issuecomment-911425827


   Packaging result: :heavy_multiplication_x: el7 :heavy_multiplication_x: el8 :heavy_multiplication_x: debian. SL-JID 1096


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] blueorangutan removed a comment on pull request #5307: Filter disk / service offerings by domain at DB level

Posted by GitBox <gi...@apache.org>.
blueorangutan removed a comment on pull request #5307:
URL: https://github.com/apache/cloudstack/pull/5307#issuecomment-911425827


   Packaging result: :heavy_multiplication_x: el7 :heavy_multiplication_x: el8 :heavy_multiplication_x: debian. SL-JID 1096


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] davidjumani commented on pull request #5307: Filter disk / service offerings by domain at DB level

Posted by GitBox <gi...@apache.org>.
davidjumani commented on pull request #5307:
URL: https://github.com/apache/cloudstack/pull/5307#issuecomment-901843583


   @nvazquez I did think of that but as there are multiple tags in both the VM's offering and the service offerings an IN will not work (eg: looking for a,b,c in b,a,c,d,e)


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] shwstppr commented on pull request #5307: Filter disk / service offerings by domain at DB level

Posted by GitBox <gi...@apache.org>.
shwstppr commented on pull request #5307:
URL: https://github.com/apache/cloudstack/pull/5307#issuecomment-902519244


   @blueorangutan package


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] ravening commented on a change in pull request #5307: Filter disk / service offerings by domain at DB level

Posted by GitBox <gi...@apache.org>.
ravening commented on a change in pull request #5307:
URL: https://github.com/apache/cloudstack/pull/5307#discussion_r700950663



##########
File path: engine/schema/src/main/java/com/cloud/service/dao/ServiceOfferingDetailsDaoImpl.java
##########
@@ -67,4 +71,23 @@ public String getDetail(Long serviceOfferingId, String key) {
         }
         return detailValue;
     }
+
+    @Override
+    public List<Long> findOfferingIdsByDomainIds(List<Long> domainIds) {
+        Object[] dIds = domainIds.stream().map(s -> String.valueOf(s)).collect(Collectors.toList()).toArray();

Review comment:
       @davidjumani this can be simplified to `domainIds.stream().map(String::valueOf).toArray();`




-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] blueorangutan commented on pull request #5307: Filter disk / service offerings by domain at DB level

Posted by GitBox <gi...@apache.org>.
blueorangutan commented on pull request #5307:
URL: https://github.com/apache/cloudstack/pull/5307#issuecomment-911347408


   <b>Trillian test result (tid-1918)</b>
   Environment: kvm-centos7 (x2), Advanced Networking with Mgmt server 7
   Total time taken: 34141 seconds
   Marvin logs: https://github.com/blueorangutan/acs-prs/releases/download/trillian/pr5307-t1918-kvm-centos7.zip
   Smoke tests completed. 87 look OK, 0 have errors
   Only failed tests results shown below:
   
   
   Test | Result | Time (s) | Test File
   --- | --- | --- | ---
   


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] nvazquez merged pull request #5307: Filter disk / service offerings by domain at DB level

Posted by GitBox <gi...@apache.org>.
nvazquez merged pull request #5307:
URL: https://github.com/apache/cloudstack/pull/5307


   


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] blueorangutan commented on pull request #5307: Filter disk / service offerings by domain at DB level

Posted by GitBox <gi...@apache.org>.
blueorangutan commented on pull request #5307:
URL: https://github.com/apache/cloudstack/pull/5307#issuecomment-911501988


   @rhtyd a Trillian-Jenkins test job (centos7 mgmt + kvm-centos7) has been kicked to run smoke tests


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] blueorangutan commented on pull request #5307: Filter disk / service offerings by domain at DB level

Posted by GitBox <gi...@apache.org>.
blueorangutan commented on pull request #5307:
URL: https://github.com/apache/cloudstack/pull/5307#issuecomment-911564606


   @davidjumani a Trillian-Jenkins test job (centos7 mgmt + kvm-centos7) has been kicked to run smoke tests


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] ravening commented on pull request #5307: Filter disk / service offerings by domain at DB level

Posted by GitBox <gi...@apache.org>.
ravening commented on pull request #5307:
URL: https://github.com/apache/cloudstack/pull/5307#issuecomment-907173999


   @davidjumani will this fix the issue in project view also?


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] davidjumani commented on pull request #5307: Filter disk / service offerings by domain at DB level

Posted by GitBox <gi...@apache.org>.
davidjumani commented on pull request #5307:
URL: https://github.com/apache/cloudstack/pull/5307#issuecomment-901630940


   @blueorangutan package


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] davidjumani commented on pull request #5307: Filter disk / service offerings by domain at DB level

Posted by GitBox <gi...@apache.org>.
davidjumani commented on pull request #5307:
URL: https://github.com/apache/cloudstack/pull/5307#issuecomment-902437293


   @nvazquez @shwstppr It appears that in searching for an offering when vmid is passed, it searches only based on the storage tags, not the host tags. Is that normal or a missing feature ?


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] davidjumani commented on a change in pull request #5307: Filter disk / service offerings by domain at DB level

Posted by GitBox <gi...@apache.org>.
davidjumani commented on a change in pull request #5307:
URL: https://github.com/apache/cloudstack/pull/5307#discussion_r695444233



##########
File path: server/src/main/java/com/cloud/api/query/QueryManagerImpl.java
##########
@@ -346,14 +345,17 @@
     private DiskOfferingJoinDao _diskOfferingJoinDao;
 
     @Inject
-    private DiskOfferingDetailsDao diskOfferingDetailsDao;
+    private DiskOfferingDetailsDao _diskOfferingDetailsDao;

Review comment:
       I'm for changing all variables, not just one, which can be done in a separate PR




-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] DaanHoogland commented on a change in pull request #5307: Filter disk / service offerings by domain at DB level

Posted by GitBox <gi...@apache.org>.
DaanHoogland commented on a change in pull request #5307:
URL: https://github.com/apache/cloudstack/pull/5307#discussion_r692853931



##########
File path: server/src/main/java/com/cloud/api/query/QueryManagerImpl.java
##########
@@ -346,14 +345,17 @@
     private DiskOfferingJoinDao _diskOfferingJoinDao;
 
     @Inject
-    private DiskOfferingDetailsDao diskOfferingDetailsDao;
+    private DiskOfferingDetailsDao _diskOfferingDetailsDao;

Review comment:
       why add the '_'? we are trying to get away from that convention.

##########
File path: server/src/main/java/com/cloud/api/query/QueryManagerImpl.java
##########
@@ -3064,39 +3033,72 @@
             sc.addAnd("cpuspeedconstraints", SearchCriteria.Op.SC, cpuSpeedSearchCriteria);
         }
 
-        Pair<List<ServiceOfferingJoinVO>, Integer> result = _srvOfferingJoinDao.searchAndCount(sc, searchFilter);
-
-        //Couldn't figure out a smart way to filter offerings based on tags in sql so doing it in Java.
-        List<ServiceOfferingJoinVO> filteredOfferings = filterOfferingsOnCurrentTags(result.first(), currentVmOffering);
-        // Remove offerings that are not associated with caller's domain
-        if (caller.getType() != Account.ACCOUNT_TYPE_ADMIN && CollectionUtils.isNotEmpty(filteredOfferings)) {
-            ListIterator<ServiceOfferingJoinVO> it = filteredOfferings.listIterator();
-            while (it.hasNext()) {
-                ServiceOfferingJoinVO offering = it.next();
-                if(!Strings.isNullOrEmpty(offering.getDomainId())) {
-                    boolean toRemove = true;
-                    String[] domainIdsArray = offering.getDomainId().split(",");
-                    for (String domainIdString : domainIdsArray) {
-                        Long dId = Long.valueOf(domainIdString.trim());
-                        if (isRecursive) {
-                            if (_domainDao.isChildDomain(caller.getDomainId(), dId)) {
-                                toRemove = false;
-                                break;
-                            }
-                        } else {
-                            if (_domainDao.isChildDomain(dId, caller.getDomainId())) {
-                                toRemove = false;
-                                break;
-                            }
-                        }
-                    }
-                    if (toRemove) {
-                        it.remove();
-                    }
+        // Filter offerings that are not associated with caller's domain

Review comment:
       once again, a this comment is a good method name to extract the code below to.

##########
File path: server/src/main/java/com/cloud/api/query/QueryManagerImpl.java
##########
@@ -2824,75 +2826,42 @@
             sc.addAnd("zoneId", SearchCriteria.Op.SC, zoneSC);
         }
 
-        // FIXME: disk offerings should search back up the hierarchy for
-        // available disk offerings...
-        /*
-         * sb.addAnd("domainId", sb.entity().getDomainId(),
-         * SearchCriteria.Op.EQ); if (domainId != null) {
-         * SearchBuilder<DomainVO> domainSearch =
-         * _domainDao.createSearchBuilder(); domainSearch.addAnd("path",
-         * domainSearch.entity().getPath(), SearchCriteria.Op.LIKE);
-         * sb.join("domainSearch", domainSearch, sb.entity().getDomainId(),
-         * domainSearch.entity().getId()); }
-         */
-
-        // FIXME: disk offerings should search back up the hierarchy for
-        // available disk offerings...
-        /*
-         * if (domainId != null) { sc.setParameters("domainId", domainId); //
-         * //DomainVO domain = _domainDao.findById((Long)domainId); // // I want
-         * to join on user_vm.domain_id = domain.id where domain.path like
-         * 'foo%' //sc.setJoinParameters("domainSearch", "path",
-         * domain.getPath() + "%"); // }
-         */
-
-        Pair<List<DiskOfferingJoinVO>, Integer> result = _diskOfferingJoinDao.searchAndCount(sc, searchFilter);
-        // Remove offerings that are not associated with caller's domain
-        if (account.getType() != Account.ACCOUNT_TYPE_ADMIN && CollectionUtils.isNotEmpty(result.first())) {
-            ListIterator<DiskOfferingJoinVO> it = result.first().listIterator();
-            while (it.hasNext()) {
-                DiskOfferingJoinVO offering = it.next();
-                if(!Strings.isNullOrEmpty(offering.getDomainId())) {
-                    boolean toRemove = true;
-                    String[] domainIdsArray = offering.getDomainId().split(",");
-                    for (String domainIdString : domainIdsArray) {
-                        Long dId = Long.valueOf(domainIdString.trim());
-                        if (isRecursive) {
-                            if (_domainDao.isChildDomain(account.getDomainId(), dId)) {
-                                toRemove = false;
-                                break;
-                            }
-                        } else {
-                            if (_domainDao.isChildDomain(dId, account.getDomainId())) {
-                                toRemove = false;
-                                break;
-                            }
-                        }
-                    }
-                    if (toRemove) {
-                        it.remove();
-                    }
-                }
+        // Filter offerings that are not associated with caller's domain

Review comment:
       good method name ;) maybe factor out the below.

##########
File path: server/src/main/java/com/cloud/api/query/QueryManagerImpl.java
##########
@@ -346,14 +345,17 @@
     private DiskOfferingJoinDao _diskOfferingJoinDao;
 
     @Inject
-    private DiskOfferingDetailsDao diskOfferingDetailsDao;
+    private DiskOfferingDetailsDao _diskOfferingDetailsDao;
 
     @Inject
     private ServiceOfferingJoinDao _srvOfferingJoinDao;
 
     @Inject
     private ServiceOfferingDao _srvOfferingDao;
 
+    @Inject
+    private ServiceOfferingDetailsDao _srvOfferingDetailsDao;

Review comment:
       ```suggestion
       private ServiceOfferingDetailsDao serviceOfferingDetailsDao;
   ```




-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] davidjumani commented on a change in pull request #5307: Filter disk / service offerings by domain at DB level

Posted by GitBox <gi...@apache.org>.
davidjumani commented on a change in pull request #5307:
URL: https://github.com/apache/cloudstack/pull/5307#discussion_r692856802



##########
File path: server/src/main/java/com/cloud/api/query/QueryManagerImpl.java
##########
@@ -346,14 +345,17 @@
     private DiskOfferingJoinDao _diskOfferingJoinDao;
 
     @Inject
-    private DiskOfferingDetailsDao diskOfferingDetailsDao;
+    private DiskOfferingDetailsDao _diskOfferingDetailsDao;

Review comment:
       Consistency in the file, unless you'd like me to rename all the class variables ?




-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] blueorangutan commented on pull request #5307: Filter disk / service offerings by domain at DB level

Posted by GitBox <gi...@apache.org>.
blueorangutan commented on pull request #5307:
URL: https://github.com/apache/cloudstack/pull/5307#issuecomment-901645924


   @davidjumani a Jenkins job has been kicked to build packages. I'll keep you posted as I make progress.


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org