-
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
Refactor service_type to use constants #17681
Conversation
a0563de
to
d4c432a
Compare
@miq-bot assign @gmcculloug |
app/models/service_template.rb
Outdated
@@ -206,19 +206,22 @@ def create_service(service_task, parent_svc = nil) | |||
svc | |||
end | |||
|
|||
def self.public_service_templates | |||
where.not(:service_type => 'internal') |
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.
Suggest we create constants for internal
, 'atomic' and 'composite' .
app/models/service_template.rb
Outdated
@@ -206,19 +206,22 @@ def create_service(service_task, parent_svc = nil) | |||
svc | |||
end | |||
|
|||
def self.public_service_templates |
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 should be a scope
and moved up with the other scopes here: https://github.com/ManageIQ/manageiq/blob/master/app/models/service_template.rb#L73-L76
Should this logic be incorporated into the existing displayed
scope?
This is to exclude Migration Plan Service Templates from Catalogs Explorer. Backend changes to support this are in ManageIQ/manageiq#17681 Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1594408
68cfb06
to
b693848
Compare
app/models/service_template.rb
Outdated
@@ -207,36 +213,35 @@ def create_service(service_task, parent_svc = nil) | |||
end | |||
|
|||
def set_service_type |
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.
@bzwei The logic of this method has been refactored and it would be good to add some tests around it.
Some additional thoughts:
- This should be a private method
- Change logic to return if immediately if the current service_type is
internal
and leave the previous logic in place. (Assuming that's why these changes were made.) - Potentially rename method to avoid using "set" prefix which robocop usually warns about.
This is to exclude Migration Plan Service Templates from Catalogs Explorer. Backend changes to support this are in ManageIQ/manageiq#17681 Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1594408
@@ -49,7 +51,7 @@ def self.create_catalog_item(options, _auth_user = nil) | |||
enhanced_config_info = validate_config_info(options) | |||
default_options = { | |||
:display => false, | |||
:service_type => 'atomic', | |||
:service_type => SERVICE_TYPE_INTERNAL, |
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.
Do we need to pass :service_type
here if default_value_for
is specified?
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.
It feels like there should be a ServiceTemplateInternal
subclass, but ¯\_(ツ)_/¯
app/models/service_template.rb
Outdated
@@ -74,6 +79,7 @@ class ServiceTemplate < ApplicationRecord | |||
scope :without_service_template_catalog_id, -> { where(:service_template_catalog_id => nil) } | |||
scope :with_existent_service_template_catalog_id, -> { where.not(:service_template_catalog_id => nil) } | |||
scope :displayed, -> { where(:display => true) } | |||
scope :public_service_templates, -> { where.not(:service_type => 'internal') } |
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.
Would just public
make more sense?
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.
public
is reserved keyword. I would rather not to cause confusion even if it is allowed here.
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.
👍
app/models/service_template.rb
Outdated
svc_type = self.class.SERVICE_TYPE_UNKNOWN | ||
else | ||
svc_type = self.class::SERVICE_TYPE_ATOMIC | ||
service_resources.each do |sr| |
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.
Wouldn't this be more efficient as:
service_resources.where(:resource_type => ["Service", "ServiceTemplate"]).any? ? self.class::SERVICE_TYPE_COMPOSITE : self.class::SERVICE_TYPE_ATOMIC
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 like your proposed way. However it does not pass the spec test. I realize this method is called after add_resource
which is not yet persisted in DB. This method is renamed from set_service_type
. Let's keep the old implementation which make no assumption that service_resources
have to be loaded from DB.
app/models/service_template.rb
Outdated
end | ||
end | ||
|
||
self.service_type = svc_type |
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.
Should this save the record?
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.
No. It is a private method. The caller is responsible for saving the record.
@bdunne I thought about subclassing as well. I think we would need to establish a new base class model (for example My concern is how disruptive this could be and I don't think the current change prevents us from doing the subclassing work in the future. Thoughts? |
I didn't realize this was being backported 😞 Yes, that's what I was thinking with the subclassing, inject an internal class |
cc @hsong-rh |
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.
Remove "unknown" as one of the allowed values for service_type
Checked commit bzwei@cb706b8 with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0 |
@@ -240,13 +251,19 @@ | |||
end | |||
|
|||
it "with service_type of unknown" do |
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.
@bzwei The service_type
"unknown" is no longer a concern here. Should this test be removed?
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.
The code still accept any string to service_type
. So the test here is ok although not important.
@@ -255,11 +272,17 @@ | |||
end | |||
|
|||
it "with service_type of unknown" do |
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.
Same here.
@bzwei Cannot apply the following label because they are not recognized: technical_debt |
This is to exclude Migration Plan Service Templates from Catalogs Explorer. Backend changes to support this are in ManageIQ/manageiq#17681 Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1594408
@bzwei @gmcculloug can you please let me know how does this PR affect changes in ManageIQ/manageiq-ui-classic#4274 , now that public_service_templates scope has been removed from the core PR, changes in UI PR no longer work. Please suggest. |
@h-kataria Thanks for pointing that out. The |
This is to exclude Migration Plan Service Templates from Catalogs Explorer. Backend changes to support this are in ManageIQ/manageiq#17681 Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1594408
Introduce new service type
internal
. This type of service template is intended to be used internally, not directly exposed through catalog.TransformationPlan
is the first template to have this type.Internal template is expected to be a single item, not bundled.
New method
ServiceTemplate.public_service_templates
excludes all internal templates.BZ https://bugzilla.redhat.com/show_bug.cgi?id=1594408
cc @h-kataria
[Edit]
It has been decided that we will make a schema change to introduce a new column to flag whether a template is internal.
This PR will remain open for refactoring purpose.