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 2020/08/10 07:49:23 UTC

[GitHub] [cloudstack] Pearl1594 opened a new pull request #4213: Search vm snapshots using tags

Pearl1594 opened a new pull request #4213:
URL: https://github.com/apache/cloudstack/pull/4213


   ## Description
   Search VM snapshots using tags
   Currently, search of VM snapshots doesn't comply with tags passed as input
   
   ## Types of changes
   <!--- What types of changes does your code introduce? Put an `x` in all the boxes that apply: -->
   - [ ] 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)
   
   ## How Has This Been Tested?
    tested via CLI (cmk) and UI
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

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



[GitHub] [cloudstack] blueorangutan commented on pull request #4213: Search vm snapshots using tags

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


   Packaging result: ✔centos7 ✔debian. JID-1586


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

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



[GitHub] [cloudstack] blueorangutan commented on pull request #4213: Search vm snapshots using tags

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


   Packaging result: ✖centos7 ✔debian. JID-1656


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

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



[GitHub] [cloudstack] blueorangutan commented on pull request #4213: Search vm snapshots using tags

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


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

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



[GitHub] [cloudstack] blueorangutan commented on pull request #4213: Search vm snapshots using tags

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


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

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



[GitHub] [cloudstack] rhtyd commented on pull request #4213: Search vm snapshots using tags

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


   @Pearl1594 pl address code review comments, send another PR for refactoring as necessary


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

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



[GitHub] [cloudstack] RodrigoDLopez commented on a change in pull request #4213: Search vm snapshots using tags

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



##########
File path: server/src/main/java/com/cloud/vm/snapshot/VMSnapshotManagerImpl.java
##########
@@ -229,11 +238,32 @@ public boolean stop() {
         sb.and("idIN", sb.entity().getId(), SearchCriteria.Op.IN);
         sb.and("display_name", sb.entity().getDisplayName(), SearchCriteria.Op.EQ);
         sb.and("account_id", sb.entity().getAccountId(), SearchCriteria.Op.EQ);
-        sb.done();
+
+        if (MapUtils.isNotEmpty(tags)) {
+            SearchBuilder<ResourceTagVO> tagSearch = _resourceTagDao.createSearchBuilder();
+            for (int count = 0; count < tags.size(); count++) {
+                tagSearch.or().op(ApiConstants.KEY + String.valueOf(count), tagSearch.entity().getKey(), SearchCriteria.Op.EQ);
+                tagSearch.and(ApiConstants.VALUE + String.valueOf(count), tagSearch.entity().getValue(), SearchCriteria.Op.EQ);
+                tagSearch.cp();
+            }
+            tagSearch.and(ApiConstants.RESOURCE_TYPE, tagSearch.entity().getResourceType(), SearchCriteria.Op.EQ);
+            sb.groupBy(sb.entity().getId());
+            sb.join("tagSearch", tagSearch, sb.entity().getId(), tagSearch.entity().getResourceId(), JoinBuilder.JoinType.INNER);

Review comment:
       Could you please extract this to a method, add documentation to what this method do and why.
   Also can you please create unit tests to cover those method

##########
File path: server/src/main/java/com/cloud/vm/snapshot/VMSnapshotManagerImpl.java
##########
@@ -229,11 +238,32 @@ public boolean stop() {
         sb.and("idIN", sb.entity().getId(), SearchCriteria.Op.IN);
         sb.and("display_name", sb.entity().getDisplayName(), SearchCriteria.Op.EQ);
         sb.and("account_id", sb.entity().getAccountId(), SearchCriteria.Op.EQ);
-        sb.done();
+
+        if (MapUtils.isNotEmpty(tags)) {
+            SearchBuilder<ResourceTagVO> tagSearch = _resourceTagDao.createSearchBuilder();
+            for (int count = 0; count < tags.size(); count++) {
+                tagSearch.or().op(ApiConstants.KEY + String.valueOf(count), tagSearch.entity().getKey(), SearchCriteria.Op.EQ);
+                tagSearch.and(ApiConstants.VALUE + String.valueOf(count), tagSearch.entity().getValue(), SearchCriteria.Op.EQ);
+                tagSearch.cp();
+            }
+            tagSearch.and(ApiConstants.RESOURCE_TYPE, tagSearch.entity().getResourceType(), SearchCriteria.Op.EQ);
+            sb.groupBy(sb.entity().getId());
+            sb.join("tagSearch", tagSearch, sb.entity().getId(), tagSearch.entity().getResourceId(), JoinBuilder.JoinType.INNER);
+        }
 
         SearchCriteria<VMSnapshotVO> sc = sb.create();
         _accountMgr.buildACLSearchCriteria(sc, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
 
+        if (MapUtils.isNotEmpty(tags)) {
+            int count = 0;
+            sc.setJoinParameters("tagSearch", ApiConstants.RESOURCE_TYPE, ResourceTag.ResourceObjectType.VMSnapshot.toString());
+            for (String key : tags.keySet()) {
+                sc.setJoinParameters("tagSearch", ApiConstants.KEY + String.valueOf(count), key);
+                sc.setJoinParameters("tagSearch", ApiConstants.VALUE + String.valueOf(count), tags.get(key));
+                count++;
+            }

Review comment:
       cloud you do the same here please,
   extract to a new method, add documentation and unit 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.

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



[GitHub] [cloudstack] DaanHoogland commented on pull request #4213: Search vm snapshots using tags

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


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

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



[GitHub] [cloudstack] Pearl1594 commented on pull request #4213: Search vm snapshots using tags

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






----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

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



[GitHub] [cloudstack] rhtyd closed pull request #4213: Search vm snapshots using tags

Posted by GitBox <gi...@apache.org>.
rhtyd closed pull request #4213:
URL: https://github.com/apache/cloudstack/pull/4213


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

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



[GitHub] [cloudstack] rhtyd commented on pull request #4213: Search vm snapshots using tags

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


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

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



[GitHub] [cloudstack] blueorangutan commented on pull request #4213: Search vm snapshots using tags

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


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

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



[GitHub] [cloudstack] rhtyd merged pull request #4213: Search vm snapshots using tags

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


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

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



[GitHub] [cloudstack] blueorangutan commented on pull request #4213: Search vm snapshots using tags

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


   Packaging result: ✔centos7 ✔debian. JID-1705


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

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



[GitHub] [cloudstack] blueorangutan commented on pull request #4213: Search vm snapshots using tags

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


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

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



[GitHub] [cloudstack] blueorangutan commented on pull request #4213: Search vm snapshots using tags

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






----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

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



[GitHub] [cloudstack] Pearl1594 commented on pull request #4213: Search vm snapshots using tags

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


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

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



[GitHub] [cloudstack] blueorangutan commented on pull request #4213: Search vm snapshots using tags

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


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

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



[GitHub] [cloudstack] rhtyd commented on pull request #4213: Search vm snapshots using tags

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


   @Pearl1594 can you address review comments and kick packaging/tests - assuming this is for primate, if so - can you pl change the base branch to 4.14?


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

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



[GitHub] [cloudstack] blueorangutan commented on pull request #4213: Search vm snapshots using tags

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


   Packaging result: ✔centos7 ✔debian. JID-1662


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

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



[GitHub] [cloudstack] DaanHoogland commented on pull request #4213: Search vm snapshots using tags

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


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

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



[GitHub] [cloudstack] blueorangutan commented on pull request #4213: Search vm snapshots using tags

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


   <b>Trillian test result (tid-2380)</b>
   Environment: kvm-centos7 (x2), Advanced Networking with Mgmt server 7
   Total time taken: 43584 seconds
   Marvin logs: https://github.com/blueorangutan/acs-prs/releases/download/trillian/pr4213-t2380-kvm-centos7.zip
   Smoke tests completed. 83 look OK, 0 have error(s)
   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.

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



[GitHub] [cloudstack] GabrielBrascher commented on a change in pull request #4213: Search vm snapshots using tags

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



##########
File path: server/src/main/java/com/cloud/vm/snapshot/VMSnapshotManagerImpl.java
##########
@@ -229,11 +236,32 @@ public boolean stop() {
         sb.and("idIN", sb.entity().getId(), SearchCriteria.Op.IN);
         sb.and("display_name", sb.entity().getDisplayName(), SearchCriteria.Op.EQ);
         sb.and("account_id", sb.entity().getAccountId(), SearchCriteria.Op.EQ);
-        sb.done();
+
+        if (tags != null && !tags.isEmpty()) {
+            SearchBuilder<ResourceTagVO> tagSearch = _resourceTagDao.createSearchBuilder();
+            for (int count = 0; count < tags.size(); count++) {
+                tagSearch.or().op("key" + String.valueOf(count), tagSearch.entity().getKey(), SearchCriteria.Op.EQ);

Review comment:
       A few values can be extracted to constants, especially considering that they are being used more than once, for instance `"key"`.

##########
File path: server/src/main/java/com/cloud/vm/snapshot/VMSnapshotManagerImpl.java
##########
@@ -229,11 +236,32 @@ public boolean stop() {
         sb.and("idIN", sb.entity().getId(), SearchCriteria.Op.IN);
         sb.and("display_name", sb.entity().getDisplayName(), SearchCriteria.Op.EQ);
         sb.and("account_id", sb.entity().getAccountId(), SearchCriteria.Op.EQ);
-        sb.done();
+
+        if (tags != null && !tags.isEmpty()) {

Review comment:
       Can you please use [MapUtils.isNotEmpty(tags);](https://commons.apache.org/proper/commons-collections/javadocs/api-4.4/org/apache/commons/collections4/MapUtils.html#isNotEmpty-java.util.Map-)?
   
   `MapUtils.isNotEmpty` is a null-safe check that verifies if the specified map is not empty.

##########
File path: server/src/main/java/com/cloud/vm/snapshot/VMSnapshotManagerImpl.java
##########
@@ -229,11 +236,32 @@ public boolean stop() {
         sb.and("idIN", sb.entity().getId(), SearchCriteria.Op.IN);
         sb.and("display_name", sb.entity().getDisplayName(), SearchCriteria.Op.EQ);
         sb.and("account_id", sb.entity().getAccountId(), SearchCriteria.Op.EQ);
-        sb.done();
+
+        if (tags != null && !tags.isEmpty()) {
+            SearchBuilder<ResourceTagVO> tagSearch = _resourceTagDao.createSearchBuilder();
+            for (int count = 0; count < tags.size(); count++) {
+                tagSearch.or().op("key" + String.valueOf(count), tagSearch.entity().getKey(), SearchCriteria.Op.EQ);
+                tagSearch.and("value" + String.valueOf(count), tagSearch.entity().getValue(), SearchCriteria.Op.EQ);
+                tagSearch.cp();
+            }
+            tagSearch.and("resourceType", tagSearch.entity().getResourceType(), SearchCriteria.Op.EQ);
+            sb.groupBy(sb.entity().getId());
+            sb.join("tagSearch", tagSearch, sb.entity().getId(), tagSearch.entity().getResourceId(), JoinBuilder.JoinType.INNER);
+        }
 
         SearchCriteria<VMSnapshotVO> sc = sb.create();
         _accountMgr.buildACLSearchCriteria(sc, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
 
+        if (tags != null && !tags.isEmpty()) {

Review comment:
       `MapUtils.isNotEmpty` would fit nicely here




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

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



[GitHub] [cloudstack] rhtyd commented on pull request #4213: Search vm snapshots using tags

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


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

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



[GitHub] [cloudstack] blueorangutan commented on pull request #4213: Search vm snapshots using tags

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


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

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



[GitHub] [cloudstack] Pearl1594 commented on pull request #4213: Search vm snapshots using tags

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


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

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