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

For middleware UI, only allow operations on mutable servers. #636

Merged
merged 2 commits into from
Mar 23, 2017
Merged

For middleware UI, only allow operations on mutable servers. #636

merged 2 commits into from
Mar 23, 2017

Conversation

mtho11
Copy link
Contributor

@mtho11 mtho11 commented Mar 8, 2017

The Hawkular agent now reads the properties from managed servers. These properties can be used to indicate the immutability of the environment (such as an EAP server running in OpenShift). The property being set here is: -Dhawkular.agent.immutable=true

An Immutable server:
immutable_toolbar

A mutable server:
mutable_toolbar

Testing

  1. Start a hawkular server (requires Hawkular Services >= 0.32)
  2. Add a Hawkular Provider
  3. Add manger EAP 7.0 server (with Hawkular Agent) to Hawkular Provider with parameter: -Dhawkular.agent.immutable=true where machineA can be any string. For example:
bin/standalone.sh -Djboss.socket.binding.port-offset=100 -Dhawkular.agent.in-container=true -Dhawkular.agent.immutable=true 

Links

@mtho11
Copy link
Contributor Author

mtho11 commented Mar 9, 2017

@miq-bot add_label middleware, enhancement, ui

@miq-bot
Copy link
Member

miq-bot commented Mar 9, 2017

@mtho11 unrecognized command 'middleware', ignoring...

Accepted commands are: add_label, assign, close_issue, move_issue, remove_label, rm_label, set_milestone

@mtho11
Copy link
Contributor Author

mtho11 commented Mar 9, 2017

@miq-bot add_label middleware, enhancement, ui

@mtho11 mtho11 changed the title For middleware UI, only allow operations on mutable servers. [WIP]For middleware UI, only allow operations on mutable servers. Mar 9, 2017
@miq-bot miq-bot added the wip label Mar 9, 2017
@chessbyte chessbyte changed the title [WIP]For middleware UI, only allow operations on mutable servers. [WIP] For middleware UI, only allow operations on mutable servers. Mar 9, 2017
@dclarizio dclarizio removed the ui label Mar 13, 2017
@mtho11 mtho11 closed this Mar 15, 2017
@mtho11 mtho11 reopened this Mar 15, 2017
@abonas
Copy link
Member

abonas commented Mar 15, 2017

Does the hawkular server ("the provider") also have this flag?

@mtho11
Copy link
Contributor Author

mtho11 commented Mar 15, 2017

@abonas yes,
Jira link here

[email protected]? ||
(@record.try(:product) != 'Hawkular' && @record.try(:middleware_server).try(:product) != 'Hawkular')
if @record.present?
hawkular_product? ? false : !immutable?
Copy link
Member

Choose a reason for hiding this comment

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

Can this part be simplified?
perhaps something like "return record.present? && hawkular_product? && immutable?"

Copy link
Contributor Author

@mtho11 mtho11 Mar 16, 2017

Choose a reason for hiding this comment

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

ok thank for the tip, this works: @record.present? && !hawkular_product? && !immutable?

Copy link

@cfcosta cfcosta left a comment

Choose a reason for hiding this comment

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

The case for when the record is a hawkular instance should be tested accordingly. The other changes I suggested are more code-quality related, so while they are completely optional in my view, they would increase the code quality by making stuff more encapsulated.

@@ -1,7 +1,18 @@
class ApplicationHelper::Button::MiddlewareServerAction < ApplicationHelper::Button::Basic

def visible?
[email protected]? ||
(@record.try(:product) != 'Hawkular' && @record.try(:middleware_server).try(:product) != 'Hawkular')
@record.present? && !hawkular_product? && !immutable?
Copy link

Choose a reason for hiding this comment

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

I think this class would be better written as:

class ApplicationHelper::Button::MiddlewareServerAction < ApplicationHelper::Button::Basic
  def NullableRecord
    delegate :present?, to: :@record

    def initialize(record)
      @record = record
    end

    def properties
      @record.try(:properties)
    end

    def product
      @record.try(:product).presence ||
        @record.try(:middleware_server).try(:product)
    end
  end


  def visible?
    nullable_record = NullableRecord.new(@record)

    @record.present?
      && !nullable_record.properties['Immutable']
      && nullable_record.product != 'Hawkular'
  end
end

That way you gain a more testable interface and make the visible? method clearer about its implementation.

Copy link

Choose a reason for hiding this comment

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

Also, wouldn't EAP non-immutable servers have the Hawkular product if they are registered into miq by Hawkular? Also, what happens if the created provider for Hawkular is not called Hawkular, but something else? Does this field is unrelated to the created name?

Copy link
Contributor Author

@mtho11 mtho11 Mar 17, 2017

Choose a reason for hiding this comment

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

@cfcosta I agree with all of your changes, just not sure it should be part of this PR. I'm just adding an immutable field to existing infrastructure. And we need to get this merged quickly as this is a blocker issue for this release that the window is closing rapidly. Changing more lines of code will subject the PR to more scrutiny which could cause it to miss the release window. You or I can add these changes to a follow-on refactoring PR immediately after this is merged. Besides the fact that, these changes need to be applied consistently to all of the middleware application helper classes and tests.

end

context 'when server.properties.immutable? == true' do
let(:immutable_server) { FactoryGirl.create(:middleware_server, :properties => create_immutable(true)) }
Copy link

Choose a reason for hiding this comment

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

For those tests you can do something like this:

let(:record) { double(:properties => create_immutable(true)) } 

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'll have to read more about double, I'm not familiar.

end

context 'when server.properties.immutable? == false' do
let(:mutable_server) { FactoryGirl.create(:middleware_server, :properties => create_immutable(false)) }
Copy link

Choose a reason for hiding this comment

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

let(:record) { double(:properties => create_immutable(false) } 

subject { described_class.new(setup_view_context_with_sandbox({}), {}, {'record' => record}, {}) }
it { expect(subject).not_to be_visible }
end
end
Copy link

Choose a reason for hiding this comment

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

These test cases are not testing if the product is hawkular.

Copy link
Contributor Author

@mtho11 mtho11 Mar 17, 2017

Choose a reason for hiding this comment

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

thanks @cfcosta, I'm done for the night, will address tomorrow.

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 did think about the not testing 'Hawkular' product but it was already not part of the test suite and I didn't want to add permutation explosion. Not sure how we should handle this?

@cfcosta
Copy link

cfcosta commented Mar 17, 2017 via email

@miq-bot
Copy link
Member

miq-bot commented Mar 18, 2017

Checked commits https://github.com/mtho11/manageiq-ui-classic/compare/768982921884e69ad47a8ac324f89f9ab3597db6~...2e48b198305e19f602d11c1de0c1f9551a26b603 with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0
2 files checked, 0 offenses detected
Everything looks good. 🍰

@mtho11 mtho11 changed the title [WIP] For middleware UI, only allow operations on mutable servers. For middleware UI, only allow operations on mutable servers. Mar 18, 2017
@miq-bot miq-bot removed the wip label Mar 18, 2017
@mtho11
Copy link
Contributor Author

mtho11 commented Mar 20, 2017

@abonas is this good to go?

@abonas
Copy link
Member

abonas commented Mar 20, 2017

LGTM
@miq-bot assign @bronaghs

@bronaghs
Copy link

@miq-bot assign @martinpovolny

@miq-bot miq-bot assigned bronaghs and martinpovolny and unassigned bronaghs Mar 20, 2017
@abonas
Copy link
Member

abonas commented Mar 23, 2017

@martinpovolny @bronaghs @chessbyte can someone please merge it ? thank you

@h-kataria h-kataria added this to the Sprint 57 Ending Mar 27, 2017 milestone Mar 23, 2017
@h-kataria h-kataria merged commit 064885c into ManageIQ:master Mar 23, 2017
@mtho11 mtho11 deleted the mw-os-disable-cmds2 branch March 23, 2017 14:37

def hawkular?
@record.try(:product) == 'Hawkular' ||
@record.try(:middleware_server).try(:product) == 'Hawkular'
Copy link
Member

Choose a reason for hiding this comment

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

It has been already merged, but it may be handy to have those methods also on the server entity itself

@cfcosta
Copy link

cfcosta commented Mar 29, 2017

@Jiri-Kremser check ManageIQ/manageiq#14565 and #839

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.

9 participants