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

Introduce model changes for v2v #16787

Merged
merged 1 commit into from Feb 9, 2018
Merged

Conversation

bzwei
Copy link
Contributor

@bzwei bzwei commented Jan 10, 2018

Initial work for modeling v2v tables introduced in ManageIQ/manageiq-schema#149

Deletion of the mapping with items is automatically supported. Update with single request is to be done in a future PR.

@bzwei
Copy link
Contributor Author

bzwei commented Jan 10, 2018

@miq-bot add_label wip

@miq-bot miq-bot added the wip label Jan 10, 2018
@bzwei
Copy link
Contributor Author

bzwei commented Jan 10, 2018

@miq-bot assign @gmcculloug


def self.select_mappings_by_sources(sources)
all.select do |m|
true if m.mapping_items.where(:source => sources).count == sources.count
Copy link
Member

Choose a reason for hiding this comment

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

nitpick: you can drop the if, simply:

all.select do |m|
  m.mapping_items.where(:source => sources).count == sources.count
end


def self.select_mappings(vms)
resources = vms.each_with_object([]) do |vm, array|
array << vm.ems_cluster
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure I know the schemea for vms, but can't we simply do something like

Cluster.where(vm_ids: vms)

Your code will go over every vm and fetch its cluster and strorage, this can be very slow on a very large number of vms

@bzwei
Copy link
Contributor Author

bzwei commented Feb 5, 2018

@miq-bot add_label v2v

@bzwei
Copy link
Contributor Author

bzwei commented Feb 5, 2018

@jntullo please review

item_map['sources'].each do |source_id|
transformation_mapping_items << TransformationMappingItem.new(
:source_id => source_id,
:source_type => dst_type.camelize,
Copy link

@jntullo jntullo Feb 5, 2018

Choose a reason for hiding this comment

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

Instead of camelizing, I think that the API should likely deconstruct the type from the api collection to the actual source_type (class). I suggest this because not all of the source types will align perfectly. I am not sure all of the types a transformation item will allow, but just as an example, providers aligns to ExtManagementSystem. I think it would be best for the API to transform providers to ExtManagementSystem. Then you will not have to do anything with the source_type that you get. Thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am perfectly fine with what you proposed.

@bzwei bzwei force-pushed the v2v_models branch 2 times, most recently from 6436393 to 7e9b2da Compare February 6, 2018 00:34
@bzwei bzwei changed the title [WIP] Introduce model changes for v2v Introduce model changes for v2v Feb 6, 2018
@bzwei
Copy link
Contributor Author

bzwei commented Feb 6, 2018

@lfu please review

item_map['sources'].each do |source_id|
transformation_mapping_items << TransformationMappingItem.new(
:source_id => source_id,
:source_type => dst_type,
Copy link

Choose a reason for hiding this comment

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

Just had an idea. Instead of using the dst_type, how do you feel about the API sending you a source_type? Something along the lines of:

{"name": "new transformation mapping",
 "mappings": { 
    "clusters": [{"source_type": "EmsCluster", "destination": ":id", "sources": [":id"]}
  ]}}

We would add this in on the create (instead of just changing cluster to EmsCluster), and would also mean that we would not need to do the reverse on a GET (EmsCluster to cluster)

@miq-bot
Copy link
Member

miq-bot commented Feb 7, 2018

Checked commit bzwei@f60db73 with ruby 2.3.3, rubocop 0.52.0, haml-lint 0.20.0, and yamllint 1.10.0
5 files checked, 3 offenses detected

app/models/transformation_mapping_item.rb

@lfu
Copy link
Member

lfu commented Feb 8, 2018

LGTM 👍

Copy link

@jntullo jntullo left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@@ -0,0 +1,3 @@
FactoryGirl.define do
factory :transformation_mapping_item
Copy link
Member

Choose a reason for hiding this comment

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

@bzwei You are using TransformationMappingItem.new in the spec, is this factory needed at this point?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

spec/models/factory_girl_spec.rb requires all models to have a factory defined.

@gmcculloug gmcculloug merged commit a6a868c into ManageIQ:master Feb 9, 2018
@gmcculloug gmcculloug added this to the Sprint 79 Ending Feb 12, 2018 milestone Feb 9, 2018
@bzwei
Copy link
Contributor Author

bzwei commented Feb 13, 2018

@miq-bot add_label enhancement

@himdel
Copy link
Contributor

himdel commented May 20, 2018

@miq-bot add_label gaprindashvili/yes

Needed by ManageIQ/manageiq-api#313 for gaprindashvili v2v support

simaishi pushed a commit that referenced this pull request May 29, 2018
Introduce model changes for v2v
(cherry picked from commit a6a868c)
@simaishi
Copy link
Contributor

Gaprindashvili backport details:

$ git log -1
commit 02fe57dc8f62bbab06266e8c5bccfa48c9a36c9c
Author: Greg McCullough <gmccullo@redhat.com>
Date:   Fri Feb 9 16:55:35 2018 -0500

    Merge pull request #16787 from bzwei/v2v_models
    
    Introduce model changes for v2v
    (cherry picked from commit a6a868cb5dca144e366a85258976be2b06bf3bd3)

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.

None yet

8 participants