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

Support for expression methods #49

Merged
merged 6 commits into from
Jul 27, 2017

Conversation

mkanoor
Copy link
Contributor

@mkanoor mkanoor commented Jul 10, 2017

Expression Methods
https://www.pivotaltracker.com/n/projects/1613499/stories/148625717

Expression Methods allow you to use Advance Search Filters as Automate Methods, substituting the user_input from Automate Objects. The advantages of this approach is that the methods run directly in the worker and don't have the overhead of forking a DRb process to run the Automate Methods.

Related PR #50

Steps

  1. Create a new Automate Method and set the Location to expression

  2. Select the Expression object to use for the expression builder from the drop down list

  3. Create an expression using the expression editor controls and any values that need to be set at runtime from automate, mark then as user input. These are positional arguments.

  4. In the input parameters section create arg1,arg2,arg3... for each of the user input fields from Step 3. When specifying the default value for arg1,arg2,... you can use substitution. e.g. ${/#vm_suffix}

  5. Create a field called attributes with the list of attributes that you would like to collect from the search objects. e.g (name, id)

Input Parameters

  • arg1 The first argument in the expression
  • arg2 The second argument in the expression
  • argn The nth argument in the expression

Optional Input Parameters

  • attributes A comma delimited list of attributes to select from the resultant objects
    or
  • distinct A comma delimited list of attributes which are distinct in the resultant objects

This should me marked as an Array Type in the Input Parameters field.

If attributes and distinct are not specified we try to store the result in a variable called
values with a hash consisting of id and name. This makes it compatible with our existing dynamic dialog result set.

  • result_obj The object where the result data should be stored (default: current object)

  • result_attr The name of the attribute which stores the result (default: values)

  • result_type The result type hash or array (default: dialog_hash which matches to our dynamic dialog hash. Valid values are 'hash', 'dialog_hash', 'array', 'simple'

  • on_empty The method behavior when the search returns an empty list
    warn | error | abort (default: error)

  • default The default value in case the result is empty and you select warn

  • UI PR Expression method ui changes manageiq-ui-classic#1668

  • ManageIQ PR: Added support for expression methods manageiq#15537

The Expression Method in Edit Mode

screen shot 2017-07-11 at 2 55 32 pm

The Expression Method in Display Mode

screen shot 2017-07-11 at 2 54 58 pm

Dynamic Dialog Instance

The instance below shows how to setup for Dynamic Dialogs, the default properties can be set in the instance and the method will fill in the values field. In the examples below the AvailableVMsInternal is an expression method.

screen shot 2017-07-11 at 2 51 21 pm

If trying to get data into a text box e.g ID of a VMDB object the arguments would look like

  • "result_attr" = "value"
  • "result_type" ="simple"
  • "attributes" = "id" type = array

@mkanoor
Copy link
Contributor Author

mkanoor commented Jul 10, 2017

@gmcculloug Travis failure is pending for this PR ManageIQ/manageiq#15537 to get merged.

:ae_class => 'ASTERIX', :instance_name => 'DOGMATIX',
:method_name => 'OBELIX', :method_params => m_params,
:method_loc => 'expression',
:method_script => vm_search)
Copy link
Member

Choose a reason for hiding this comment

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

This same create_ae_model_with_method method and parameters are repeated for all but 2 tests. Please move into either a let block or method so it can be shared.

allow(User).to receive(:server_timezone).and_return("UTC")
end

it "expression_method" do
Copy link
Member

Choose a reason for hiding this comment

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

Suggest moving these tests into something like a describe "expression_method" do block to better group and reduce the duplication in each test title.

@@ -0,0 +1,169 @@
module MiqAeExpressionMethodSpec
include MiqAeEngine
describe MiqAeExpressionMethod do
Copy link
Member

Choose a reason for hiding this comment

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

Can we come up with a way to test this class without having to build an automate model and instantiate it each time? Seems very expensive to run each test and it would be better to focus the tests on the class. Thoughts?

@gmcculloug
Copy link
Member

@mkanoor The PR description has great documentation for the feature but I think it could use a few updates/enhancements that would be really useful.

  1. There are no longer any Required Input Parameters. Should rename section to Input Parameters.
  2. For Optional Input Parameters the key distinct is a tough one to wrap my head around. An example in the description would be helpful.
  3. result_type lists the default as hash but the code is showing dialog_hash
  4. result_type should list the available options.

@mkanoor mkanoor force-pushed the epxression_method_engine_changes branch from 58e9c0b to 23d3509 Compare July 26, 2017 18:01
@miq-bot
Copy link
Member

miq-bot commented Jul 26, 2017

Checked commits mkanoor/manageiq-automation_engine@49575af~...23d3509 with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0
5 files checked, 5 offenses detected

lib/miq_automation_engine/engine/miq_ae_engine/miq_ae_expression_method.rb

lib/miq_automation_engine/engine/miq_ae_engine/miq_ae_object.rb

@gmcculloug gmcculloug merged commit 6480698 into ManageIQ:master Jul 27, 2017
@gmcculloug gmcculloug added this to the Sprint 66 Ending Aug 7, 2017 milestone Jul 27, 2017
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.

3 participants