Skip to content

Commit

Permalink
Automated Workflows for POC implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffibm committed Apr 27, 2023
1 parent a0b233d commit 2d1924c
Show file tree
Hide file tree
Showing 31 changed files with 908 additions and 54 deletions.
21 changes: 21 additions & 0 deletions app/controllers/catalog_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,18 @@ def atomic_form_field_changed
if params[:display]
page << "miq_tabs_show_hide('#details_tab', '#{(params[:display] == "1")}')"
end
if params[:provisioning_entry_point_type]
@edit[:new][:fqname] = ""
page.replace_html("provision_entry_point", :partial => "provision_entry_points")
end
if params[:reconfigure_entry_point_type]
@edit[:new][:reconfigure_fqname] = ""
page.replace_html("reconfigure_entry_point", :partial => "reconfigure_entry_points")
end
if params[:retirement_entry_point_type]
@edit[:new][:retire_fqname] = ""
page.replace_html("retirement_entry_point", :partial => "retirement_entry_points")
end
%w[fqname reconfigure_fqname retire_fqname].each do |name|
if params[name.to_sym] && @edit[:new][name.to_sym].present?
page << "$('##{name}_remove').attr('disabled', false);"
Expand Down Expand Up @@ -652,6 +664,15 @@ def ae_tree_select_toggle
session[:edit] = @edit
end

def embededded_workflows_modal
render :update do |page|
page << javascript_prologue
page << javascript_show(params[:type])
page << javascript_show("#{params[:type]}_modal")
page << "$('##{params[:type]}_modal').addClass('modal fade in');"
end
end

def ae_tree_select_discard
assert_new_or_edit_by_service_type

Expand Down
38 changes: 38 additions & 0 deletions app/controllers/workflow_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
class WorkflowController < ApplicationController
before_action :check_privileges
before_action :get_session_data

after_action :cleanup_action
after_action :set_session_data

include Mixins::GenericListMixin
include Mixins::GenericSessionMixin
include Mixins::GenericShowMixin
include Mixins::BreadcrumbsMixin

def self.model
ManageIQ::Providers::EmbeddedAnsible::AutomationManager::Playbook
#ManageIQ::Providers::Workflows::AutomationManager::Workflow
end

def show_list
assert_privileges('embedded_workflow_view')
super
end

def show
assert_privileges('embedded_workflow_view')
end

def breadcrumbs_options
{
:breadcrumbs => [
{:title => _("Automation")},
{:title => _("Embedded Workflow")},
{:title => _("Workflows"), :url => controller_url},
],
}
end

menu_section :embedded_workflow
end
37 changes: 37 additions & 0 deletions app/controllers/workflow_credential_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
class WorkflowCredentialController < ApplicationController
before_action :check_privileges
before_action :get_session_data

after_action :cleanup_action
after_action :set_session_data

include Mixins::GenericListMixin
include Mixins::GenericSessionMixin
include Mixins::GenericShowMixin
include Mixins::BreadcrumbsMixin

def self.model
ManageIQ::Providers::EmbeddedAnsible::AutomationManager::Playbook
end

def show_list
assert_privileges('embedded_workflow_credential_view')
super
end

def show
assert_privileges('embedded_workflow_credential_view')
end

def breadcrumbs_options
{
:breadcrumbs => [
{:title => _("Automation")},
{:title => _("Embedded Workflow")},
{:title => _("Credentials"), :url => controller_url},
],
}
end

menu_section :embedded_workflow
end
37 changes: 37 additions & 0 deletions app/controllers/workflow_repository_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
class WorkflowRepositoryController < ApplicationController
before_action :check_privileges
before_action :get_session_data

after_action :cleanup_action
after_action :set_session_data

include Mixins::GenericListMixin
include Mixins::GenericSessionMixin
include Mixins::GenericShowMixin
include Mixins::BreadcrumbsMixin

def self.model
ManageIQ::Providers::EmbeddedAnsible::AutomationManager::Playbook
end

def show_list
assert_privileges('embedded_workflow_repository_view')
super
end

def show
assert_privileges('embedded_workflow_repository_view')
end

def breadcrumbs_options
{
:breadcrumbs => [
{:title => _("Automation")},
{:title => _("Embedded Workflow")},
{:title => _("Repositories"), :url => controller_url},
],
}
end

menu_section :embedded_workflow
end
3 changes: 3 additions & 0 deletions app/javascript/components/code-editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ const CodeEditor = (props) => {
{ modes.map((mode) => <RadioButton value={mode} labelText={mode} key={mode} />) }
</RadioButtonGroup>
)}
{
console.log(codeMode)
}
<CodeMirror
className={`miq-codemirror ${error ? 'has-error' : ''}`}
options={{
Expand Down
85 changes: 85 additions & 0 deletions app/javascript/components/workflows/dummy-data.asl
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
{
"Comment": "An example of the Amazon States Language using a choice state.",
"StartAt": "FirstState",
"States": {
"FirstState": {
"Type": "Task",
"Resource": "docker://agrare/hello-world:latest",
"Retry": [
{
"ErrorEquals": [ "States.Timeout" ],
"IntervalSeconds": 3,
"MaxAttempts": 2,
"BackoffRate": 1.5
}
],
"Catch": [
{
"ErrorEquals": [ "States.ALL" ],
"Next": "FailState"
}
],
"Next": "ChoiceState"
},

"ChoiceState": {
"Type" : "Choice",
"Choices": [
{
"Variable": "$.foo",
"NumericEquals": 1,
"Next": "FirstMatchState"
},
{
"Variable": "$.foo",
"NumericEquals": 2,
"Next": "SecondMatchState"
},
{
"Variable": "$.foo",
"NumericEquals": 3,
"Next": "SuccessState"
}
],
"Default": "FailState"
},

"FirstMatchState": {
"Type" : "Task",
"Resource": "docker://agrare/hello-world:latest",
"Next": "PassState"
},

"SecondMatchState": {
"Type" : "Task",
"Resource": "docker://agrare/hello-world:latest",
"Next": "NextState"
},

"PassState": {
"Type": "Pass",
"Result": {
"foo": "bar",
"bar": "baz"
},
"ResultPath": "$.result",
"Next": "NextState"
},

"FailState": {
"Type": "Fail",
"Error": "FailStateError",
"Cause": "No Matches!"
},

"SuccessState": {
"Type": "Succeed"
},

"NextState": {
"Type": "Task",
"Resource": "docker://agrare/hello-world:latest",
"End": true
}
}
}
46 changes: 46 additions & 0 deletions app/javascript/components/workflows/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import React, { useState, useEffect } from 'react';
import { Loading } from 'carbon-components-react';
import MiqDataTable from '../miq-data-table';
import { workflowsList } from './workflows-dummy-data';

const WorkflowList = () => {
const [data, setData] = useState({ isLoading: true, list: {} });

// TODO: Change the url when the GET automated worflow list api is available.
useEffect(() => {
API.get('/api/workflows/?expand=resources')
.then((response) => {
setData({
isLoading: false,
list: workflowsList(response),
});
});
}, []);

/** Function to handle a row's click event. */
const onSelect = (selectedItemId) => {
miqSparkleOn();
window.location.href = `/workflow/show/${selectedItemId}`;
};
if (data.isLoading) {
return (
<div className="loadingSpinner">
<Loading active small withOverlay={false} className="loading" />
</div>
);
}

return (
<MiqDataTable
headers={data.list.headers}
rows={data.list.rows}
onCellClick={(selectedRow) => onSelect(selectedRow.id)}
showPagination={false}
truncateText={false}
mode="automated-workflow-list"
gridChecks={[]}
/>
);
};

export default WorkflowList;
Loading

0 comments on commit 2d1924c

Please sign in to comment.