Skip to content

Conversation

@weizhouapache
Copy link
Member

Description

This PR fixes an issue in #4399

Steps to reproduce the issue
(1) create service offering with multiple host tags (2 or more)
(2) create a vm with the service offering

expected result
vm is started or
get error message "No suitable host found for follow compute offering tags: tag1,tag2"

actual result:
Got exception

com.cloud.utils.exception.CloudRuntimeException: DB Exception on: select distinct cluster_id from host join host_tags on host.id = host_tags.host_id and host_tags.tag = ?

Types of changes

  • Breaking change (fix or feature that would cause existing functionality to change)
  • New feature (non-breaking change which adds functionality)
  • 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)

Feature/Enhancement Scale or Bug Severity

Feature/Enhancement Scale

  • Major
  • Minor

Bug Severity

  • BLOCKER
  • Critical
  • Major
  • Minor
  • Trivial

Screenshots (if appropriate):

How Has This Been Tested?

@weizhouapache weizhouapache added this to the 4.16.0.0 milestone Sep 28, 2021
@nvazquez
Copy link
Contributor

@blueorangutan package

@blueorangutan
Copy link

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

@blueorangutan
Copy link

Packaging result: ✔️ el7 ✔️ el8 ✔️ debian ✔️ suse15. SL-JID 1426

@nvazquez
Copy link
Contributor

@blueorangutan test

@blueorangutan
Copy link

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

Copy link
Contributor

@nvazquez nvazquez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - Manually verified

@nvazquez
Copy link
Contributor

Ping for review @sureshanaparti @davidjumani @rhtyd

@blueorangutan
Copy link

Trillian test result (tid-2229)
Environment: kvm-centos7 (x2), Advanced Networking with Mgmt server 7
Total time taken: 31149 seconds
Marvin logs: https://github.com/blueorangutan/acs-prs/releases/download/trillian/pr5521-t2229-kvm-centos7.zip
Smoke tests completed. 89 look OK, 0 have errors
Only failed tests results shown below:

Test Result Time (s) Test File

+ "HAVING tag_count = %s ";
private static final String SEPARATOR = ",";
private static final String LIST_CLUSTERID_FOR_HOST_TAG = "select distinct cluster_id from host join host_tags on host.id = host_tags.host_id and host_tags.tag = ?";
private static final String LIST_CLUSTERID_FOR_HOST_TAG = "select distinct cluster_id from host join ( %s ) AS selected_hosts ON host.id = selected_hosts.host_id";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should %s be replaced with ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rhtyd It seems, all the tags are part of the sub-query stmt "LIST_HOST_IDS_BY_COMPUTETAGS" and the returned hosts from that sub-query were considered from further filtering.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should %s be replaced with ?

@rhtyd
see suresh's comment above.

String sql = this.LIST_CLUSTERID_FOR_HOST_TAG;
PreparedStatement pstmt = null;
List<Long> result = new ArrayList();
List<String> tags = Arrays.asList(computeOfferingTags.split(this.SEPARATOR));
String subselect = getHostIdsByComputeTags(tags);
sql = String.format(sql, subselect);

an example of final sql is (if there are 3 tags)

select distinct cluster_id from host join 
( SELECT filtered.host_id, COUNT(filtered.tag) AS tag_count FROM (SELECT host_id, tag FROM host_tags GROUP BY host_id,tag) AS filtered WHERE tag IN(?,?,?) GROUP BY host_id HAVING tag_count = 3  ) AS selected_hosts 
ON host.id = selected_hosts.host_id;

Copy link
Contributor

@sureshanaparti sureshanaparti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@rohityadavcloud rohityadavcloud merged commit ea643a6 into apache:main Sep 29, 2021
@weizhouapache weizhouapache deleted the 4.16-fix-multi-tags branch December 9, 2022 08:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants