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

Graph refresh - target vm #35

Merged
merged 4 commits into from
Jul 5, 2017
Merged

Conversation

pkliczewski
Copy link
Contributor

@pkliczewski pkliczewski commented May 12, 2017

Collector and parser implementations

RFE link: https://bugzilla.redhat.com/1466172

end

def clusters
if target.kind_of? VmOrTemplate
Copy link
Contributor

@Ladas Ladas May 16, 2017

Choose a reason for hiding this comment

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

right, seems like you still count with only 1 target being here.

If should be that the target is a TargetCollection, then target.targets could contain VmOrTemplate object. Then if the cluster would be needed for Vms, you should first parse all VmOrTemplate cluster references then fetch only referenced clusters.

If you don't fetch the cluster, the reference will be filled from the DB.


def clusters
collector.clusters.each do |cluster|
persister.resource_pools.find_or_build(r_id).assign_attributes(
Copy link
Contributor

Choose a reason for hiding this comment

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

the r_id does not seem to be defined?

persister.clusters.find_or_build(cluster.id).assign_attributes(
:ems_ref => ems_ref,
:ems_ref_obj => ems_ref,
:uid_ems => cluster.id,
Copy link
Contributor

Choose a reason for hiding this comment

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

in the persistor, you have the default unique uuid (manager_ref attribute) as ems_ref, which is default. The unique uuid attribute should be what you use in persister.clusters.find_or_build(unique_uuid/manager_ref)

logical_unit && logical_unit.id
end

free = storagedomain.try(:available).to_i
Copy link
Contributor

Choose a reason for hiding this comment

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

you can probably put these one liners directly to the hash below, to spare some LOC

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will move only those which are used in one place

host_os_version = host.dig(:os, :version)
ems_ref = ManageIQ::Providers::Redhat::InfraManager.make_ems_ref(host_inv.href)

clusters = persister.clusters.lazy_find(host.dig(:cluster, :id))
Copy link
Contributor

@Ladas Ladas May 16, 2017

Choose a reason for hiding this comment

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

if you want to access the clusters directly do:

cluster = persister.clusters.find(host.dig(:cluster, :id)) # should return just 1, since we are using unique index here

storage_ids = []
dcs.each do |dc|
if dc_ids.include? dc.id
storage_ids << collector.collect_dc_domains(dc).to_miq_a.collect { |s| s[:id] }
Copy link
Contributor

Choose a reason for hiding this comment

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

would be nice to have a TODO if we could solve this lazily, maybe we can't


host_operating_systems(persister_host, host, hostname)
networks = collector.collect_networks
switchs(persister_host, host, nics, networks)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: plural of switch should be switches

nics.to_miq_a.each do |nic|
network = network_from_nic(nic, host, networks)

if network
Copy link
Contributor

Choose a reason for hiding this comment

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

switch_uid = network.try(:id) || network_name

should result in the same thing

def network_for_nic(nic, host, networks)
network_id = nic.dig(:network, :id)
if network_id
network = networks.detect { |n| n.id == network_id }
Copy link
Contributor

Choose a reason for hiding this comment

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

if you cycle this through a lot of hosts&nics, might be better to avoid .detect which is O(n)

so somewhere above you could do indexed_networks = networks.index_by(:id)
and here just do indexed_networks[:network_id], which is O(1)

although I don't see the network_for_nic called anywhere?

Copy link
Contributor

Choose a reason for hiding this comment

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

btw. this would be in general, I've seen that Ovirt has ineffective parser, which is most likely caused by these O(n) lookups, which result easily in O(n^2) when called in another cycle.

So would be nice to also fix parser performance for the graph refresh. :-) I've seen that parsing took the same time as saving to the DB for the old refresh, it should take like 1% of the time we need to save to the DB

cluster_id = host.dig(:cluster, :id)
cluster = persister.clusters.lazy_find(cluster_id)
datacenter_id = cluster.dig(:data_center, :id)
network = networks.detect { |n| n.name == network_name && n.dig(:data_center, :id) == datacenter_id }
Copy link
Contributor

Choose a reason for hiding this comment

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

a crusade to kill all .detect :-)

storages = []
collector.attached_disks(vm).to_miq_a.each do |disk|
disk.storage_domains.to_miq_a.each do |sd|
storages << persister.storages.lazy_find(:ems_ref => sd.id)
Copy link
Contributor

Choose a reason for hiding this comment

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

lazy find knows only strings now and can take only the unique uuid (if needed we could extend it to teach it multiple indexes)

so persister.storages.lazy_find(sd.id)

name = description = snapshot.description
name = "Active Image" if name[0, 13] == '_ActiveImage_'

persister.snapshots.find_or_build_by(persister_vm).assign_attributes(
Copy link
Contributor

Choose a reason for hiding this comment

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

find_or_build

def operating_systems(persister_vm, vm)
guest_os = vm.dig(:os, :type)

persister.operating_systems.find_or_build_by(persister_vm).assign_attributes(
Copy link
Contributor

Choose a reason for hiding this comment

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

find_or_build

return result if custom_attrs.nil?

custom_attrs.each do |ca|
persister.custom_attributes.find_or_build_by(persister_vm).assign_attributes(
Copy link
Contributor

Choose a reason for hiding this comment

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

find_or_build

agrare pushed a commit to agrare/manageiq-providers-ovirt that referenced this pull request May 16, 2017
…_refresh

check if name is blank and use instance_id instead
return collect_emsclusters
def ems_clusters
clusters = []
if target.targets.any? { |t| t.kind_of? VmOrTemplate }
Copy link
Contributor

Choose a reason for hiding this comment

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

right, so for the saving to work properly, the Collector and Persistor should use the same: references(:ems_clusters)

references(:ems_clusters) => [:cluster_ems_ref_1, :cluster_ems_ref_2]
So what it will then say, is collect me only [:cluster_ems_ref_1, :cluster_ems_ref_2] from the API. And when saving, compare it to [:cluster_ems_ref_1, :cluster_ems_ref_2] in the MIQ DB.

so Collector and Persistor should be aligned like this

@pkliczewski pkliczewski force-pushed the graph_refresh branch 2 times, most recently from 9ff22f4 to 91ecd68 Compare June 8, 2017 10:07
@pkliczewski pkliczewski changed the title [WIP] Graph refresh Graph refresh - target vm Jun 8, 2017
@miq-bot miq-bot removed the wip label Jun 8, 2017
@pkliczewski
Copy link
Contributor Author

@borod108 @masayag @jhernand Please take a look

@pkliczewski
Copy link
Contributor Author

@matobet please take a look

@pkliczewski
Copy link
Contributor Author

The reason for failed test is missing default manager which is provided by dependent PR

@pkliczewski
Copy link
Contributor Author

Graph refresh

@pkliczewski
Copy link
Contributor Author

@miq-bot assign @oourfali

@pkliczewski
Copy link
Contributor Author

@borod108 @masayag please review

@@ -76,7 +76,7 @@ def self.provision_class(via)

def vm_reconfigure(vm, options = {})
ovirt_services_for_reconfigure = ManageIQ::Providers::Redhat::InfraManager::OvirtServices::Builder.new(self)
.build(:use_highest_supported_version => true).new(:ems => self)
.build(:use_highest_supported_version => true).new(:ems => self)
Copy link
Contributor

Choose a reason for hiding this comment

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

extra line?

return
end

persister.lans..find_or_build_by(
Copy link
Contributor

Choose a reason for hiding this comment

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

..

@miq-bot
Copy link
Member

miq-bot commented Jul 4, 2017

This pull request is not mergeable. Please rebase and repush.

When calling vm target refresh the db is updated properly using
graph refresh code base.
@miq-bot
Copy link
Member

miq-bot commented Jul 4, 2017

Some comments on commits pkliczewski/manageiq-providers-ovirt@0abcb77~...c743ab6

spec/models/manageiq/providers/redhat/infra_manager/refresh/refresher_target_vm_4_spec.rb

  • ⚠️ - 106 - Detected allow_any_instance_of. This RSpec method is highly discouraged, please only use when absolutely necessary.
  • ⚠️ - 110 - Detected allow_any_instance_of. This RSpec method is highly discouraged, please only use when absolutely necessary.
  • ⚠️ - 114 - Detected allow_any_instance_of. This RSpec method is highly discouraged, please only use when absolutely necessary.
  • ⚠️ - 117 - Detected allow_any_instance_of. This RSpec method is highly discouraged, please only use when absolutely necessary.
  • ⚠️ - 118 - Detected allow_any_instance_of. This RSpec method is highly discouraged, please only use when absolutely necessary.
  • ⚠️ - 119 - Detected allow_any_instance_of. This RSpec method is highly discouraged, please only use when absolutely necessary.
  • ⚠️ - 120 - Detected allow_any_instance_of. This RSpec method is highly discouraged, please only use when absolutely necessary.
  • ⚠️ - 122 - Detected allow_any_instance_of. This RSpec method is highly discouraged, please only use when absolutely necessary.
  • ⚠️ - 123 - Detected allow_any_instance_of. This RSpec method is highly discouraged, please only use when absolutely necessary.
  • ⚠️ - 27 - Detected allow_any_instance_of. This RSpec method is highly discouraged, please only use when absolutely necessary.
  • ⚠️ - 28 - Detected allow_any_instance_of. This RSpec method is highly discouraged, please only use when absolutely necessary.
  • ⚠️ - 81 - Detected allow_any_instance_of. This RSpec method is highly discouraged, please only use when absolutely necessary.
  • ⚠️ - 83 - Detected allow_any_instance_of. This RSpec method is highly discouraged, please only use when absolutely necessary.
  • ⚠️ - 85 - Detected allow_any_instance_of. This RSpec method is highly discouraged, please only use when absolutely necessary.
  • ⚠️ - 87 - Detected allow_any_instance_of. This RSpec method is highly discouraged, please only use when absolutely necessary.
  • ⚠️ - 89 - Detected allow_any_instance_of. This RSpec method is highly discouraged, please only use when absolutely necessary.

@miq-bot
Copy link
Member

miq-bot commented Jul 4, 2017

Checked commits pkliczewski/manageiq-providers-ovirt@0abcb77~...c743ab6 with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0
9 files checked, 1 offense detected

app/models/manageiq/providers/redhat/inventory/parser/infra_manager.rb

@oourfali oourfali merged commit 12639ef into ManageIQ:master Jul 5, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants