-
Notifications
You must be signed in to change notification settings - Fork 898
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
Moving Inventory::Builder's functions to Inventory class #17907
Conversation
What do you think about this, @agrare, @Ladas? I'm not sure, how to write specs for this PR, should I choose some provider and write specs for it? |
|
||
collector_type = "#{collector_class}::#{manager_type}Manager".safe_constantize | ||
persister_type = "#{persister_class}::#{manager_type}Manager".safe_constantize | ||
parser_type = "#{parser_class}::#{manager_type}Manager".safe_constantize |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this will not fit the current TargetCollection, that uses more parsers
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah I see, I'll try to extend it, maybe build_inventory
can be generic only for some providers, but at least inventory
method is repeated every time with the same code.
My question was, if there is some hidden reason why Builder doesn't have class in core (when all other refresh classes have one)
3cfecc2
to
fbabe32
Compare
def parser_class | ||
"#{inventory_class}::Parser".constantize | ||
rescue | ||
ManageIQ::Providers::Inventory::Collector |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this look like there should be ManageIQ::Providers::Inventory::Parser, and below is the same
but I think it is invalid class anyway? So we should not return it and rather let it fail?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
of course, there should be Parser
, thanks :)
it's not invalid class, it replaced ManagerRefresh::Inventory::Parser
.
I think it's better that it raises NotImplementedError
from this class, than nil error from some random place
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, ok, if it will raise NotImplementedError, then it should be ok
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
..I'll find this error when writing spec, but I've question about it, please look at 2nd comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hm ,we should still log.error here, so this place is not hidden
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
btw. I meant invalid that ManageIQ::Providers::Inventory::Collector base class it not valid for using.
Not sure about specs, we could use mock classes or dummy provider, @agrare ?
# Example: | ||
# %w(Cloud Network Infra) | ||
def allowed_manager_types | ||
raise NotImplementedError |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lets provide a message to the exception
@slemrmartin why have this in a different Builder class? This looks like it could easily be just in |
@agrare because there is many Also Builders instantiates subclasses of |
I agree that the providers should inherit from a common base but I don't see the benefit of a different sub-class when it could just be the top level class
Honestly it is more confusing that a sub class instantiates the top level class. When Something like |
|
I don't understand what you mean. Provider specific classes cannot be fully removed. For example Amazon with [Parser,Collector,Persister]::StorageManager::[Ebs, S3]'s classes cannot be generalized. In case of Amazon, Storage Parser for TargetCollection cannot be determined automatically.
What do you mean by that? Provider specific builder instantiates provider specific inventory, parser,collector,persister, not the top level class (top level classes are instantiated only in case of non-existing classes - which then causes NotImplementedError on non-random place (at least Parser, as I see))
The same question, what do you mean by returning instance of a parent class there? Do you suggest to completely remove all Builders from providers and move method It's definitely possible, but complexity remains the same, not everything can be generalized to top-level class |
That's not what I'm talking about, I'm saying instead of adding a new top-level class
Of course not everything can be generalized but the complexity will be less in the sense of someone wanting to create an instance of |
Thanks @agrare, that makes sense to me, working on it :) |
72a03bc
to
25447e0
Compare
begin | ||
inventory = builder_class_for(ems.class).build_inventory(ems, target) | ||
rescue NameError | ||
inventory = inventory_class_for(ems.class).build(ems, target) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey what if we add an alias for build_inventory -> build so we can call this one way while we refactor the providers?
25447e0
to
8eaf563
Compare
begin | ||
inventory = builder_class_for(ems.class).build_inventory(ems, target) | ||
rescue NameError | ||
inventory = inventory_class_for(ems.class).build(ems, target) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like the comment got overwritten but I think we should just alias build_inventory build
and save the rescue here, we can remove it once we move all the providers over
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh just noticed the builder_class_for
part, at first I thought the whole line was the same except for build
/ build_inventory
2050a30
to
340565c
Compare
@miq-bot add_label refactoring |
# | ||
# @param klass class of the Provider/Manager | ||
# @return [Class] Correct class name of the persister | ||
def self.persister_class_for(klass) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@agrare I only changed order of these methods in file, no change there
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm good with this for now, I think these should all be private and then all of the yardoc comments are unnecessary
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually where is persister_class_for used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah okay 👍
This pull request is not mergeable. Please rebase and repush. |
340565c
to
3620846
Compare
def self.build(ems, target) | ||
new( | ||
class_for(ems, target, 'Persister').new(ems, target), | ||
class_for(ems, target, 'Collector').new(ems, target), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of the general class_for
here how about we call collector_class_for
and persister_class_for
here to give providers a change to override them?
Checked commits slemrmartin/manageiq@a54b241~...f3fd91d with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0 |
@slemrmartin looks good overall, I'm going to merge this so we can finish cleaning up the provider plugins and then we can come back and revisit this |
Before this PR all providers with graph refresh repeats the same code for their inventory builders.
They didn't inherit from any common class (except Object, of course :).
This PR makes common methods in
ManageIQ::Providers::Inventory
, then all provider-specific builders can be removed.