Skip to content

Commit

Permalink
C and U collection form coversion
Browse files Browse the repository at this point in the history
staging changes

reordered

form added

lint error coorection

lint error correction
  • Loading branch information
anu-jose-ibm committed Sep 4, 2023
1 parent e37dec7 commit 8d0069e
Show file tree
Hide file tree
Showing 8 changed files with 175 additions and 77 deletions.
6 changes: 3 additions & 3 deletions app/controllers/miq_ae_customization_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def x_show

# Dialog show selected from catalog explorer
def show
assert_privileges('dialog_accord') # feature like miq_ae_customization_service_dialog_show is missing
assert_privileges('dialog_accord') # feature like miq_ae_customization_service_dialog_show is missing
nodes = params[:id].split("-")
record = Dialog.find_by(:id =>nodes.last)
self.x_active_accord = "dialogs"
Expand Down Expand Up @@ -330,8 +330,8 @@ def no_items_selected?(field_name)
end

def rebuild_toolbars(presenter)
unless @in_a_form
c_tb = build_toolbar(center_toolbar_filename) if center_toolbar_filename
if !@in_a_form && center_toolbar_filename
c_tb = build_toolbar(center_toolbar_filename)
end

presenter.set_visibility(c_tb.present?, :toolbar)
Expand Down
82 changes: 49 additions & 33 deletions app/controllers/ops_controller/diagnostics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ def diagnostics_tree_select
@record = MiqServer.find(id)
when "role"
@record = ServerRole.find(id)
@rec_status = @record.assigned_server_roles.find_by(:active => true) ? "active" : "stopped" if @record.class == ServerRole
@rec_status = @record.assigned_server_roles.find_by(:active => true) ? "active" : "stopped" if @record.instance_of?(ServerRole)
when "asr"
@record = AssignedServerRole.find(id)
@rec_status = @record.assigned_server_roles.find_by(:active => true) ? "active" : "stopped" if @record.class == ServerRole
@rec_status = @record.assigned_server_roles.find_by(:active => true) ? "active" : "stopped" if @record.instance_of?(ServerRole)
end
@sb[:diag_selected_model] = @record.class.to_s
@sb[:diag_selected_id] = @record.id
Expand Down Expand Up @@ -100,7 +100,7 @@ def log_depot_edit

build_supported_depots_for_select
log_protocol = params[:log_protocol]
protocols = FileDepot.supported_depots.map { |k, _v| [k, k.constantize] }.to_h
protocols = FileDepot.supported_depots.transform_values { |v| some_value }
raise _('Invalid or unsupported file depot type.') unless protocols.key?(log_protocol)

depot = @record.log_file_depot.instance_of?(protocols[log_protocol]) ? @record.log_file_depot : @record.build_log_file_depot(:type => log_protocol)
Expand Down Expand Up @@ -132,7 +132,7 @@ def log_depot_edit

begin
log_protocol = params[:log_protocol]
protocols = FileDepot.supported_depots.map { |k, _v| [k, k.constantize] }.to_h
protocols = FileDepot.supported_depots.to_h { |k, _v| [k, k.constantize] }
raise _("Unsupported log depot protocol: %{protocol}") % {:protocol => log_protocol} unless protocols.key?(log_protocol)

protocols[log_protocol].validate_settings(settings)
Expand Down Expand Up @@ -239,6 +239,27 @@ def cu_repair_field_changed
def cu_repair
assert_privileges("ops_diagnostics")

if params[:end_date].to_time < params[:start_date].to_time
render :json => {:status => :error, :message => _("End Date cannot be earlier than Start Date")}
else
# converting string to time, and then converting into user selected timezone
from = "#{params[:start_date]} #{params[:start_hour]}:#{params[:start_min]}:00".to_time.in_time_zone(params[:timezone])
to = "#{params[:end_date]} #{params[:end_hour]}:#{params[:end_min]}:00".to_time.in_time_zone(params[:timezone])
selected_zone = Zone.find(x_node.split('-').last)
begin
Metric::Capture.perf_capture_gap_queue(from, to, selected_zone)
rescue => bang
# Push msg and error flag
render :json => {:status => :error, :message => _("Error during 'C & U Gap Collection': %{message}") % {:message => bang.message}}
else
render :json => {:status => :success, :message => _("C & U Gap Collection successfully initiated")}
end
end
end

def cu_repair_old
assert_privileges("ops_diagnostics")

return unless load_edit("curepair_edit__new", "replace_cell__explorer")

if @edit[:new][:end_date].to_time < @edit[:new][:start_date].to_time
Expand Down Expand Up @@ -285,22 +306,20 @@ def build_log_depot_json(log_depot)
prefix, uri = log_depot[:uri].to_s.split('://')
klass = @record.log_file_depot.try(:class)

log_depot_json = {:depot_name => log_depot[:name],
:uri => uri,
:uri_prefix => prefix,
:log_userid => log_depot.authentication_userid,
:log_protocol => klass.to_s}
log_depot_json
{:depot_name => log_depot[:name],
:uri => uri,
:uri_prefix => prefix,
:log_userid => log_depot.authentication_userid,
:log_protocol => klass.to_s}
end

def build_empty_log_depot_json
log_depot_json = {:depot_name => '',
:uri => '',
:uri_prefix => '',
:log_userid => '',
:log_password => '',
:log_protocol => ''}
log_depot_json
{:depot_name => '',
:uri => '',
:uri_prefix => '',
:log_userid => '',
:log_password => '',
:log_protocol => ''}
end

# to delete orphaned records for user that was delete from db
Expand Down Expand Up @@ -519,7 +538,7 @@ def delete_server
def process_server_deletion(server)
server.destroy
rescue => bang
add_flash(_("Server \"%{name}\": Error during 'destroy': ") % {:name => server.name} << bang.message,
add_flash((_("Server \"%{name}\": Error during 'destroy': ") % {:name => server.name}) << bang.message,
:error)
else
AuditEvent.success(
Expand Down Expand Up @@ -681,27 +700,28 @@ def diagnostics_set_form_vars
elsif active_node && active_node.split('-').first == "svr"
@selected_server ||= MiqServer.find(@sb[:selected_server_id]) # Reread the server record
if @sb[:selected_server_id] == my_server.id
if @sb[:active_tab] == "diagnostics_evm_log"
case @sb[:active_tab]
when "diagnostics_evm_log"
@log = fetch_local_log("evm")
add_flash(_("Logs for this %{product} Server are not available for viewing") % {:product => Vmdb::Appliance.PRODUCT_NAME}, :warning) if @log.blank?
@msg_title = _("ManageIQ")
@refresh_action = "refresh_log"
@download_action = "fetch_log"
elsif @sb[:active_tab] == "diagnostics_audit_log"
when "diagnostics_audit_log"
@log = fetch_local_log("audit")
add_flash(_("Logs for this %{product} Server are not available for viewing") % {:product => Vmdb::Appliance.PRODUCT_NAME}, :warning) if @log.blank?
@msg_title = _("Audit")
@refresh_action = "refresh_audit_log"
@download_action = "fetch_audit_log"
elsif @sb[:active_tab] == "diagnostics_production_log"
when "diagnostics_production_log"
@log = fetch_local_log(Rails.env)
add_flash(_("Logs for this %{product} Server are not available for viewing") % {:product => Vmdb::Appliance.PRODUCT_NAME}, :warning) if @log.blank?
@msg_title = @sb[:rails_log]
@refresh_action = "refresh_production_log"
@download_action = "fetch_production_log"
elsif @sb[:active_tab] == "diagnostics_summary"
when "diagnostics_summary"
@selected_server = MiqServer.find(@sb[:selected_server_id])
elsif @sb[:active_tab] == "diagnostics_workers"
when "diagnostics_workers"
pm_get_workers
@record = @selected_server
else
Expand Down Expand Up @@ -749,7 +769,7 @@ def build_server_tree(parent)
end
if @sb[:diag_selected_id]
@record = @sb[:diag_selected_model].constantize.find(@sb[:diag_selected_id]) # Set the current record
@rec_status = @record.assigned_server_roles.find_by(:active => true) ? "active" : "stopped" if @record.class == ServerRole
@rec_status = @record.assigned_server_roles.find_by(:active => true) ? "active" : "stopped" if @record.instance_of?(ServerRole)
end
end

Expand All @@ -758,25 +778,21 @@ def diagnostics_get_info
@in_a_form = false
node = x_node.downcase.split("-").first
case node
when "root"
@sb[:diag_tree_type] ||= "roles"
@sb[:diag_selected_id] = nil
diagnostics_set_form_vars
when "z"
when "root", "z"
@sb[:diag_tree_type] ||= "roles"
@sb[:diag_selected_id] = nil
diagnostics_set_form_vars
when "svr"
@record = @selected_server = MiqServer.find(x_node.downcase.split("-").last)
@sb[:selected_server_id] = @selected_server.id
diagnostics_set_form_vars
end

diagnostics_set_form_vars
end

def build_supported_depots_for_select
not_supported_depots = %w[FileDepotS3 FileDepotSwift]
supported_depots = FileDepot.supported_depots.reject { |model, _desc| not_supported_depots.include?(model) }
@uri_prefixes = supported_depots.keys.map { |model| [model, model.constantize.uri_prefix] }.to_h
supported_depots = FileDepot.supported_depots.except(*not_supported_depots)
@uri_prefixes = supported_depots.keys.index_with { |model| model.constantize.uri_prefix }
@supported_depots_for_select = {'' => _('<No Depot>')}.merge(supported_depots)
end

Expand Down
57 changes: 57 additions & 0 deletions app/javascript/components/c-and-u-collections-form/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import React, {useState} from 'react';
import MiqFormRenderer from '@@ddf';
import createSchema from './schema';
import NotificationMessage from '../notification-message';

// import handleFailure from '../../helpers/handle-failure';

const DiagnosticsCURepairForm = ({ timezones }) => {

const [data, setData] = useState({
response: undefined
});

/** Function to append 0 to beginning of a number if it is a single digit. */
const padStart = (number) => String(number).padStart(2, '0');

/** This function format the date. */
const formatDate = (date) => {
const newDate = new Date(date[0]);
return `${padStart(newDate.getMonth()+1)}/${padStart(newDate.getDate())}/${newDate.getFullYear()}`;
}

const onSubmit = (values) => {
const data = {
timezone: values.timezone,
start_date: formatDate(values.startDate),
end_date: formatDate(values.endDate),
}
console.log(data);
http.post(`/ops/cu_repair?button=submit`, data, { skipErrors: [400, 500] })
.then(({status, message}) => {
['startDate', 'endDate'].forEach((item) => document.getElementById(item).value = "");
setData({
...data,
response: { status, message }
});
});
};

const renderMessage = ({status, message}) => <NotificationMessage type={status} message={message} />

return (
<>
{ data.response && renderMessage(data.response) }
<MiqFormRenderer
schema={createSchema(timezones)}
onSubmit={onSubmit}
/>
{
`${__('Note')} : ${__('Gap Collection is only available for VMware vSphere Infrastructures')}`
}
</>
)
};


export default DiagnosticsCURepairForm;
39 changes: 39 additions & 0 deletions app/javascript/components/c-and-u-collections-form/schema.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { componentTypes, validatorTypes } from '@@ddf';

const createSchema = (timezones) => ({
title: __('Collection Options'),
fields: [
{
component: componentTypes.SELECT,
id: 'timezone',
name: 'timezone',
label: __('Timezone'),
initialValue: 'UTC',
validate: [{ type: validatorTypes.REQUIRED }],
isRequired: true,
includeEmpty: true,
options: timezones.map((timezone) => ({
label: timezone[0],
value: timezone[1],
})),
},
{
component: 'date-picker',
id: 'startDate',
name: 'startDate',
label: __('Start Date'),
validate: [{ type: validatorTypes.REQUIRED }],
isRequired: true,
},
{
component: 'date-picker',
id: 'endDate',
name: 'endDate',
label: __('End Date'),
validate: [{ type: validatorTypes.REQUIRED }],
isRequired: true,
}
],
});

export default createSchema;
2 changes: 2 additions & 0 deletions app/javascript/packs/component-definitions-common.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ import StorageServiceForm from '../components/storage-service-form';
import VolumeMappingForm from '../components/volume-mapping-form';
import ZoneForm from '../components/zone-form';
import AnsiblePlayBookEditCatalogForm from '../components/ansible-playbook-edit-catalog-form';
import DiagnosticsCURepairForm from '../components/c-and-u-collections-form';

/**
* Add component definitions to this file.
Expand Down Expand Up @@ -331,3 +332,4 @@ ManageIQ.component.addReact('VolumeMappingForm', VolumeMappingForm);
ManageIQ.component.addReact('VmCommonRenameForm', VmCommonRenameForm);
ManageIQ.component.addReact('ZoneForm', ZoneForm);
ManageIQ.component.addReact('AnsiblePlayBookEditCatalogForm', AnsiblePlayBookEditCatalogForm);
ManageIQ.component.addReact('DiagnosticsCURepairForm', DiagnosticsCURepairForm);
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import React from 'react';
import toJson from 'enzyme-to-json';
import fetchMock from 'fetch-mock';
import { act } from 'react-dom/test-utils';

import { mount } from '../helpers/mountForm';
import DiagnosticsCURepairForm from '../../components/c-and-u-collections-form';

describe('DiagnosticsCURepairForm Component', () => {
afterEach(() => {
fetchMock.reset();
fetchMock.restore();
});
it('Should render a new DiagnosticsCURepair form', async () => {
let wrapper;
await act(async () => {
wrapper = mount(<DiagnosticsCURepairForm />);
});
wrapper.update();
expect(toJson(wrapper)).toMatchSnapshot();
});

});
2 changes: 2 additions & 0 deletions app/views/ops/_diagnostics_cu_repair_tab.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<%= react('DiagnosticsCURepairForm', {:timezones => ViewHelper::ALL_TIMEZONES}) =%>

41 changes: 0 additions & 41 deletions app/views/ops/_diagnostics_cu_repair_tab.html.haml

This file was deleted.

0 comments on commit 8d0069e

Please sign in to comment.