Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add method for Vm to get 'My Company' tags #16607

Merged

Conversation

lpichler
Copy link
Contributor

@lpichler lpichler commented Dec 6, 2017

'My Company' tags - there is used name writable_classification_tags for this method - it is inherited from names of used relations and scopes but maybe there is better name

in UI:
(for example)
screen shot 2017-12-12 at 11 05 45
screen shot 2017-12-12 at 11 06 26

How it looks in DB ?

Vm (for example) -> Taggings -> Tags -> Classification -> parent of Classification is read_only

it was derived from code in UI screen

Usage:

irb(main):001:0> Vm.find(10000000000151).writable_classification_tags
PostgreSQLAdapter#log_after_checkout, connection_pool: size: 50, connections: 1, in use: 1, waiting_in_queue: 0
  Vm Load (1.5ms)  SELECT  "vms".* FROM "vms" WHERE "vms"."type" IN ('Vm', 'VmServer', 'ManageIQ::Providers::InfraManager::Vm', 'ManageIQ::Providers::CloudManager::Vm', 'VmXen', 'ManageIQ::Providers::Redhat::InfraManager::Vm', 'ManageIQ::Providers::Microsoft::InfraManager::Vm', 'ManageIQ::Providers::Vmware::InfraManager::Vm', 'ManageIQ::Providers::Amazon::CloudManager::Vm', 'ManageIQ::Providers::Azure::CloudManager::Vm', 'ManageIQ::Providers::Google::CloudManager::Vm', 'ManageIQ::Providers::Openstack::CloudManager::Vm', 'ManageIQ::Providers::Vmware::CloudManager::Vm') AND "vms"."template" = $1 AND "vms"."id" = $2 LIMIT $3  [["template", "f"], ["id", 10000000000151], ["LIMIT", 1]]
  Vm Inst Including Associations (709.8ms - 1rows)
   (1.5ms)  SELECT DISTINCT COUNT(DISTINCT "tags"."id") FROM "tags" LEFT OUTER JOIN "classifications" ON "classifications"."tag_id" = "tags"."id" LEFT OUTER JOIN "classifications" "parents_classifications" ON "parents_classifications"."id" = "classifications"."parent_id" INNER JOIN "taggings" ON "tags"."id" = "taggings"."tag_id" WHERE "taggings"."taggable_id" = $1 AND "taggings"."taggable_type" = $2 AND "parents_classifications"."read_only" = $3  [["taggable_id", 10000000000151], ["taggable_type", "VmOrTemplate"], ["read_only", "f"]]
  Query Trace > lib/extensions/ar_virtual.rb:741:in `calculate'
     from lib/extensions/ar_virtual.rb:741:in `calculate'
  SQL (1.1ms)  SELECT "tags"."id" AS t0_r0, "tags"."name" AS t0_r1, "classifications"."id" AS t1_r0, "classifications"."description" AS t1_r1, "classifications"."icon" AS t1_r2, "classifications"."read_only" AS t1_r3, "classifications"."syntax" AS t1_r4, "classifications"."single_value" AS t1_r5, "classifications"."example_text" AS t1_r6, "classifications"."tag_id" AS t1_r7, "classifications"."parent_id" AS t1_r8, "classifications"."show" AS t1_r9, "classifications"."default" AS t1_r10, "classifications"."perf_by_tag" AS t1_r11, "parents_classifications"."id" AS t2_r0, "parents_classifications"."description" AS t2_r1, "parents_classifications"."icon" AS t2_r2, "parents_classifications"."read_only" AS t2_r3, "parents_classifications"."syntax" AS t2_r4, "parents_classifications"."single_value" AS t2_r5, "parents_classifications"."example_text" AS t2_r6, "parents_classifications"."tag_id" AS t2_r7, "parents_classifications"."parent_id" AS t2_r8, "parents_classifications"."show" AS t2_r9, "parents_classifications"."default" AS t2_r10, "parents_classifications"."perf_by_tag" AS t2_r11 FROM "tags" LEFT OUTER JOIN "classifications" ON "classifications"."tag_id" = "tags"."id" LEFT OUTER JOIN "classifications" "parents_classifications" ON "parents_classifications"."id" = "classifications"."parent_id" INNER JOIN "taggings" ON "tags"."id" = "taggings"."tag_id" WHERE "taggings"."taggable_id" = $1 AND "taggings"."taggable_type" = $2 AND "parents_classifications"."read_only" = $3  [["taggable_id", 10000000000151], ["taggable_type", "VmOrTemplate"], ["read_only", "f"]]
  Query Trace > lib/extensions/ar_virtual.rb:704:in `find_with_associations'
  Tag Inst Including Associations (22.1ms - 1rows)
[
    [0] #<Tag:0x00007f9152d767f8> {
          :id => 10000000000167,
        :name => "/managed/turbonomic/candidate"
    }

🎁 for @skateman

Links

https://bugzilla.redhat.com/show_bug.cgi?id=1519457
https://bugzilla.redhat.com/show_bug.cgi?id=1467805

@miq-bot miq-bot added the wip label Dec 6, 2017
@lpichler lpichler force-pushed the get_writeable_clasification_tags branch 3 times, most recently from 794417f to bc98533 Compare December 12, 2017 08:44
@lpichler lpichler changed the title [WIP] Add scope for user tags Add method for Vm to get 'My Company' tags Dec 12, 2017
@miq-bot miq-bot removed the wip label Dec 12, 2017
@lpichler
Copy link
Contributor Author

@miq-bot assign @gtanzillo
@miq-bot add_label gaprindashvili/yes

expect(@vm1.tags.count).to eq(4)
expect(@vm1.writable_classification_tags.count).to eq(1)
expect(@vm1.writable_classification_tags.first.name).to eq('/managed/environment/prod')

Copy link
Member

@skateman skateman Dec 12, 2017

Choose a reason for hiding this comment

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

Could you add an expectation to check if the returned object is an actual tag?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@lpichler
Copy link
Contributor Author

lpichler commented Dec 12, 2017

@skateman still same count of queries for asking on parent of classification.

irb(main):003:0> Vm.find(10000000000151).writable_classification_tags.first.classification.parent
  Vm Load (0.8ms)  SELECT  "vms".* FROM "vms" WHERE "vms"."type" IN ('Vm', 'VmServer', 'ManageIQ::Providers::InfraManager::Vm', 'ManageIQ::Providers::CloudManager::Vm', 'VmXen', 'ManageIQ::Providers::Redhat::InfraManager::Vm', 'ManageIQ::Providers::Microsoft::InfraManager::Vm', 'ManageIQ::Providers::Vmware::InfraManager::Vm', 'ManageIQ::Providers::Amazon::CloudManager::Vm', 'ManageIQ::Providers::Azure::CloudManager::Vm', 'ManageIQ::Providers::Google::CloudManager::Vm', 'ManageIQ::Providers::Openstack::CloudManager::Vm', 'ManageIQ::Providers::Vmware::CloudManager::Vm') AND "vms"."template" = $1 AND "vms"."id" = $2 LIMIT $3  [["template", "f"], ["id", 10000000000151], ["LIMIT", 1]]
  Vm Inst Including Associations (0.4ms - 1rows)
  SQL (1.4ms)  SELECT  "tags"."id" AS t0_r0, "tags"."name" AS t0_r1, "classifications"."id" AS t1_r0, "classifications"."description" AS t1_r1, "classifications"."icon" AS t1_r2, "classifications"."read_only" AS t1_r3, "classifications"."syntax" AS t1_r4, "classifications"."single_value" AS t1_r5, "classifications"."example_text" AS t1_r6, "classifications"."tag_id" AS t1_r7, "classifications"."parent_id" AS t1_r8, "classifications"."show" AS t1_r9, "classifications"."default" AS t1_r10, "classifications"."perf_by_tag" AS t1_r11, "parents_classifications"."id" AS t2_r0, "parents_classifications"."description" AS t2_r1, "parents_classifications"."icon" AS t2_r2, "parents_classifications"."read_only" AS t2_r3, "parents_classifications"."syntax" AS t2_r4, "parents_classifications"."single_value" AS t2_r5, "parents_classifications"."example_text" AS t2_r6, "parents_classifications"."tag_id" AS t2_r7, "parents_classifications"."parent_id" AS t2_r8, "parents_classifications"."show" AS t2_r9, "parents_classifications"."default" AS t2_r10, "parents_classifications"."perf_by_tag" AS t2_r11 FROM "tags" LEFT OUTER JOIN "classifications" ON "classifications"."tag_id" = "tags"."id" LEFT OUTER JOIN "classifications" "parents_classifications" ON "parents_classifications"."id" = "classifications"."parent_id" INNER JOIN "taggings" ON "tags"."id" = "taggings"."tag_id" WHERE "taggings"."taggable_id" = $1 AND "taggings"."taggable_type" = $2 AND "parents_classifications"."read_only" = $3 ORDER BY "tags"."id" ASC LIMIT $4  [["taggable_id", 10000000000151], ["taggable_type", "VmOrTemplate"], ["read_only", "f"], ["LIMIT", 1]]
  Query Trace > lib/extensions/ar_virtual.rb:704:in `find_with_associations'
  Tag Inst Including Associations (0.4ms - 1rows)
#<Classification:0x00007fde251559e0> {
              :id => 10000000000147,
     :description => "Turbonomic",
            :icon => nil,
       :read_only => false,
          :syntax => "string",
    :single_value => false,
    :example_text => "Turbonomic",
          :tag_id => 10000000000152,
       :parent_id => 0,
            :show => true,
         :default => nil,
     :perf_by_tag => false
}

Copy link
Member

@skateman skateman left a comment

Choose a reason for hiding this comment

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

The Seal of Approval

@skateman
Copy link
Member

Travis issue seems irrelevant...

@skateman
Copy link
Member

@lpichler please rebase to make the tests green.

@lpichler lpichler force-pushed the get_writeable_clasification_tags branch from d3af28d to 438abad Compare December 13, 2017 10:29
@miq-bot
Copy link
Member

miq-bot commented Dec 13, 2017

Checked commit lpichler@438abad with ruby 2.3.3, rubocop 0.47.1, haml-lint 0.20.0, and yamllint 1.10.0
3 files checked, 0 offenses detected
Everything looks fine. 🏆

@skateman
Copy link
Member

@gtanzillo can we get this in?

@gtanzillo gtanzillo added this to the Sprint 76 Ending Jan 1, 2018 milestone Dec 13, 2017
@gtanzillo gtanzillo merged commit dd073f4 into ManageIQ:master Dec 13, 2017
simaishi pushed a commit that referenced this pull request Dec 14, 2017
@simaishi
Copy link
Contributor

Gaprindashvili backport details:

$ git log -1
commit 2bdf92189b98cf23366334176bb4693f73902b9f
Author: Gregg Tanzillo <[email protected]>
Date:   Wed Dec 13 18:09:01 2017 -0500

    Merge pull request #16607 from lpichler/get_writeable_clasification_tags
    
    Add method for Vm to get 'My Company'  tags
    (cherry picked from commit dd073f43e717688faa671d62454cf7207edec8e7)
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1526049

@lpichler lpichler deleted the get_writeable_clasification_tags branch December 14, 2017 17:26
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