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

Refactor service_type to use constants #17681

Merged
merged 1 commit into from
Jul 27, 2018

Conversation

bzwei
Copy link
Contributor

@bzwei bzwei commented Jul 9, 2018

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.

@miq-bot miq-bot added the wip label Jul 9, 2018
@bzwei bzwei force-pushed the v2v_internal_type branch 3 times, most recently from a0563de to d4c432a Compare July 10, 2018 15:35
@bzwei
Copy link
Contributor Author

bzwei commented Jul 10, 2018

@miq-bot assign @gmcculloug

@@ -206,19 +206,22 @@ def create_service(service_task, parent_svc = nil)
svc
end

def self.public_service_templates
where.not(:service_type => 'internal')
Copy link
Member

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' .

@@ -206,19 +206,22 @@ def create_service(service_task, parent_svc = nil)
svc
end

def self.public_service_templates
Copy link
Member

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?

h-kataria added a commit to h-kataria/manageiq-ui-classic that referenced this pull request Jul 10, 2018
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 bzwei force-pushed the v2v_internal_type branch 3 times, most recently from 68cfb06 to b693848 Compare July 10, 2018 19:02
@@ -207,36 +213,35 @@ def create_service(service_task, parent_svc = nil)
end

def set_service_type
Copy link
Member

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:

  1. This should be a private method
  2. 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.)
  3. Potentially rename method to avoid using "set" prefix which robocop usually warns about.

h-kataria added a commit to h-kataria/manageiq-ui-classic that referenced this pull request Jul 11, 2018
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 bzwei changed the title [WIP] set internal service_type for transformation plan Set internal service_type for transformation plan Jul 11, 2018
@miq-bot miq-bot removed the wip label Jul 11, 2018
@gmcculloug gmcculloug requested a review from Fryguy July 11, 2018 20:34
@@ -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,
Copy link
Member

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?

Copy link
Member

@bdunne bdunne left a 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 ¯\_(ツ)_/¯

@@ -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') }
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

Choose a reason for hiding this comment

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

👍

svc_type = self.class.SERVICE_TYPE_UNKNOWN
else
svc_type = self.class::SERVICE_TYPE_ATOMIC
service_resources.each do |sr|
Copy link
Member

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

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 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.

end
end

self.service_type = svc_type
Copy link
Member

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?

Copy link
Contributor Author

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.

@gmcculloug
Copy link
Member

@bdunne I thought about subclassing as well. I think we would need to establish a new base class model (for example service_template_base) and then derive ServiceTemplate and ServiceTemplateInternal models to build off of. Is that kind of what you were thinking?

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?

@bdunne
Copy link
Member

bdunne commented Jul 17, 2018

I didn't realize this was being backported 😞 Yes, that's what I was thinking with the subclassing, inject an internal class

@bzwei
Copy link
Contributor Author

bzwei commented Jul 18, 2018

cc @hsong-rh

@bzwei bzwei changed the title Set internal service_type for transformation plan [WIP] Set internal service_type for transformation plan Jul 19, 2018
@miq-bot miq-bot added the wip label Jul 19, 2018
Copy link
Member

@gmcculloug gmcculloug left a comment

Choose a reason for hiding this comment

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

@bzwei Can you turn this into a refactoring that introduces the SERVICE_TYPE constants and remove the "internal" additions as we will be implementing that different in #17748

@bzwei bzwei changed the title [WIP] Set internal service_type for transformation plan [WIP] Refactor service_type to use constants Jul 24, 2018
Remove "unknown" as one of the allowed values for service_type
@bzwei bzwei changed the title [WIP] Refactor service_type to use constants Refactor service_type to use constants Jul 26, 2018
@miq-bot miq-bot removed the wip label Jul 26, 2018
@miq-bot
Copy link
Member

miq-bot commented Jul 26, 2018

Checked commit bzwei@cb706b8 with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0
6 files checked, 0 offenses detected
Everything looks fine. 🏆

@@ -240,13 +251,19 @@
end

it "with service_type of unknown" do
Copy link
Member

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?

Copy link
Contributor Author

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
Copy link
Member

Choose a reason for hiding this comment

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

Same here.

@bzwei
Copy link
Contributor Author

bzwei commented Jul 26, 2018

@miq-bot remove_label gaprindashvili/yes, bug, transformation
@miq-bot add_label technical_debt

@miq-bot
Copy link
Member

miq-bot commented Jul 26, 2018

@bzwei Cannot apply the following label because they are not recognized: technical_debt

@gmcculloug gmcculloug merged commit 1893e95 into ManageIQ:master Jul 27, 2018
@gmcculloug gmcculloug added this to the Sprint 91 Ending Jul 30, 2018 milestone Jul 27, 2018
@bzwei bzwei deleted the v2v_internal_type branch July 27, 2018 13:35
h-kataria added a commit to h-kataria/manageiq-ui-classic that referenced this pull request Jul 27, 2018
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
@h-kataria
Copy link
Contributor

@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.

@gmcculloug
Copy link
Member

@h-kataria Thanks for pointing that out. The public_service_templates approach has not changed but the code moved to PR #17748.

h-kataria added a commit to h-kataria/manageiq-ui-classic that referenced this pull request Jul 30, 2018
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
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