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

Add hana scale up scenario as selection in checks catalog #3210

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 28 additions & 7 deletions assets/js/lib/model/clusters.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,28 @@ export const ASCS_ERS = 'ascs_ers';
export const COST_OPT_SCENARIO = 'cost_optimized';
export const PERFORMANCE_SCENARIO = 'performance_optimized';

export const clusterTypes = [HANA_SCALE_UP, HANA_SCALE_OUT, ASCS_ERS];
export const hanaClusterScenarioTypes = [
COST_OPT_SCENARIO,
PERFORMANCE_SCENARIO,
];
// Hana scale up with scenarios
export const HANA_SCALE_UP_PERF_OPT = `${HANA_SCALE_UP}-${PERFORMANCE_SCENARIO}`;
export const HANA_SCALE_UP_COST_OPT = `${HANA_SCALE_UP}-${COST_OPT_SCENARIO}`;

export const isValidClusterType = (clusterType) =>
clusterTypes.includes(clusterType);
export const clusterTypes = [HANA_SCALE_UP, HANA_SCALE_OUT, ASCS_ERS];

const clusterTypeLabels = {
[HANA_SCALE_UP]: 'HANA Scale Up',
[HANA_SCALE_OUT]: 'HANA Scale Out',
[ASCS_ERS]: 'ASCS/ERS',
};
export const isValidClusterType = (clusterType) =>
clusterTypes.includes(clusterType);

export const getClusterTypeLabel = (type) =>
clusterTypeLabels[type] || 'Unknown';

export const hanaClusterScenarioTypes = [
COST_OPT_SCENARIO,
PERFORMANCE_SCENARIO,
];

const clusterScenarioLabels = {
[PERFORMANCE_SCENARIO]: 'Perf. Opt.',
[COST_OPT_SCENARIO]: 'Cost Opt.',
Expand All @@ -33,6 +37,23 @@ const clusterScenarioLabels = {
export const getClusterScenarioLabel = (type) =>
clusterScenarioLabels[type] || '';

export const clusterTypesCatalog = [
HANA_SCALE_UP_PERF_OPT,
HANA_SCALE_UP_COST_OPT,
HANA_SCALE_OUT,
ASCS_ERS,
];

export const clusterTypeLabelsChecksCatalog = {
[HANA_SCALE_UP_PERF_OPT]: 'HANA Scale Up Perf. Opt.',
[HANA_SCALE_UP_COST_OPT]: 'HANA Scale Up Cost Opt.',
[HANA_SCALE_OUT]: 'HANA Scale Out',
[ASCS_ERS]: 'ASCS/ERS',
};

export const getClusterTypeLabelChecksCatalog = (type) =>
clusterTypeLabelsChecksCatalog[type] || 'Unknown';

export const ANGI_ARCHITECTURE = 'angi';
export const CLASSIC_ARCHITECTURE = 'classic';

Expand Down
59 changes: 53 additions & 6 deletions assets/js/pages/ChecksCatalog/ChecksCatalog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,15 @@ import {
TARGET_HOST,
TARGET_CLUSTER,
} from '@lib/model';
import { clusterTypes, getClusterTypeLabel } from '@lib/model/clusters';
import {
clusterTypesCatalog,
getClusterTypeLabelChecksCatalog,
COST_OPT_SCENARIO,
HANA_SCALE_UP,
PERFORMANCE_SCENARIO,
HANA_SCALE_UP_PERF_OPT,
HANA_SCALE_UP_COST_OPT,
} from '@lib/model/clusters';
import { hasChecksForClusterType, hasChecksForTarget } from '@lib/model/checks';
import Accordion from '@common/Accordion';
import PageHeader from '@common/PageHeader';
Expand All @@ -24,11 +32,21 @@ const providerOptionRenderer = createOptionRenderer(
(provider) => <ProviderLabel provider={provider} />
);

const mapClusterType = (type) => {
switch (type) {
case HANA_SCALE_UP_PERF_OPT:
case HANA_SCALE_UP_COST_OPT:
return HANA_SCALE_UP;
default:
return type;
}
};

const clusterTypeRenderer = createOptionRenderer(
'All cluster types',
(clusterType, disabled) => (
<>
{getClusterTypeLabel(clusterType)}
{getClusterTypeLabelChecksCatalog(clusterType)}
{disabled && (
<Pill
size="xs"
Expand Down Expand Up @@ -74,11 +92,30 @@ function ChecksCatalog({
const [selectedProvider, setProviderSelected] = useState(OPTION_ALL);
const [selectedTargetType, setSelectedTargetType] = useState(OPTION_ALL);
const [selectedClusterType, setSelectedClusterType] = useState(OPTION_ALL);
const [selectedHanaScaleUpScenario, setSelectedHanaScaleUpScenario] =
useState(OPTION_ALL);

const onClusterTypeChange = (type) => {
switch (type) {
case HANA_SCALE_UP_PERF_OPT:
setSelectedHanaScaleUpScenario(PERFORMANCE_SCENARIO);
break;
case HANA_SCALE_UP_COST_OPT:
setSelectedHanaScaleUpScenario(COST_OPT_SCENARIO);
break;
default:
setSelectedHanaScaleUpScenario(OPTION_ALL);
}

setSelectedClusterType(type);
};

const onTargetTypeChange = (targetType) => {
if (targetType !== TARGET_CLUSTER) {
setSelectedClusterType(OPTION_ALL);
setSelectedHanaScaleUpScenario(OPTION_ALL);
}
setSelectedHanaScaleUpScenario(OPTION_ALL);
setSelectedTargetType(targetType);
};

Expand All @@ -95,13 +132,16 @@ function ChecksCatalog({
},
{
optionsName: 'cluster-types',
options: clusterTypes.map((clusterType) => ({
options: clusterTypesCatalog.map((clusterType) => ({
value: clusterType,
disabled: !hasChecksForClusterType(completeCatalog, clusterType),
disabled: !hasChecksForClusterType(
completeCatalog,
mapClusterType(clusterType)
),
})),
renderOption: clusterTypeRenderer,
value: selectedClusterType,
onChange: setSelectedClusterType,
onChange: onClusterTypeChange,
disabled: selectedTargetType !== TARGET_CLUSTER,
},
{
Expand All @@ -118,13 +158,20 @@ function ChecksCatalog({
selectedProvider,
selectedTargetType,
selectedClusterType,
selectedHanaScaleUpScenario,
});
}, [selectedProvider, selectedTargetType, selectedClusterType]);
}, [
selectedProvider,
selectedTargetType,
selectedClusterType,
selectedHanaScaleUpScenario,
]);

const clearFilters = () => {
setProviderSelected(OPTION_ALL);
setSelectedTargetType(OPTION_ALL);
setSelectedClusterType(OPTION_ALL);
setSelectedHanaScaleUpScenario(OPTION_ALL);
};

return (
Expand Down
31 changes: 28 additions & 3 deletions assets/js/pages/ChecksCatalog/ChecksCatalog.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ describe('ChecksCatalog ChecksCatalog component', () => {
selectedClusterType: 'all',
selectedProvider: 'all',
selectedTargetType: 'all',
selectedHanaScaleUpScenario: 'all',
});
});

Expand Down Expand Up @@ -72,6 +73,16 @@ describe('ChecksCatalog ChecksCatalog component', () => {
metadata: {
target_type: 'cluster',
cluster_type: 'hana_scale_up',
hana_scenario: 'performance_optimized',
architecture_type: 'classic',
},
}),
catalogCheckFactory.build({
metadata: {
target_type: 'cluster',
cluster_type: 'hana_scale_up',
hana_scenario: 'cost_optimized',
architecture_type: 'classic',
},
}),
catalogCheckFactory.build({
Expand All @@ -89,7 +100,11 @@ describe('ChecksCatalog ChecksCatalog component', () => {
initialTargetType: 'Clusters',
filter: 'All cluster types',
expectDisabled: 'HANA Scale Out',
expectAllEnabled: ['HANA Scale Up', 'ASCS/ERS'],
expectAllEnabled: [
'HANA Scale Up Perf. Opt.',
'HANA Scale Up Cost Opt.',
'ASCS/ERS',
],
},
];

Expand Down Expand Up @@ -120,11 +135,9 @@ describe('ChecksCatalog ChecksCatalog component', () => {
}

await user.click(screen.getByText(filter));

expect(
screen.getByText(expectDisabled, { exact: false }).closest('div')
).toHaveAttribute('aria-disabled', 'true');

const expectItemEnabled = (itemExpectedEnabled) =>
expect(
screen.getByText(itemExpectedEnabled).closest('div')
Expand All @@ -151,6 +164,14 @@ describe('ChecksCatalog ChecksCatalog component', () => {
metadata: {
target_type: 'cluster',
cluster_type: 'hana_scale_up',
hana_scenario: 'performance_optimized',
},
}),
catalogCheckFactory.build({
metadata: {
target_type: 'cluster',
cluster_type: 'hana_scale_up',
hana_scenario: 'cost_optimized',
},
}),
catalogCheckFactory.build({
Expand Down Expand Up @@ -179,21 +200,25 @@ describe('ChecksCatalog ChecksCatalog component', () => {
selectedClusterType: 'all',
selectedProvider: 'all',
selectedTargetType: 'all',
selectedHanaScaleUpScenario: 'all',
});
expect(mockUpdateCatalog).toHaveBeenNthCalledWith(2, {
selectedClusterType: 'all',
selectedProvider: 'aws',
selectedTargetType: 'all',
selectedHanaScaleUpScenario: 'all',
});
expect(mockUpdateCatalog).toHaveBeenNthCalledWith(3, {
selectedClusterType: 'all',
selectedProvider: 'aws',
selectedTargetType: 'cluster',
selectedHanaScaleUpScenario: 'all',
});
expect(mockUpdateCatalog).toHaveBeenNthCalledWith(4, {
selectedClusterType: 'ascs_ers',
selectedProvider: 'aws',
selectedTargetType: 'cluster',
selectedHanaScaleUpScenario: 'all',
});
});
});
25 changes: 23 additions & 2 deletions assets/js/pages/ChecksCatalog/ChecksCatalogPage.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import React from 'react';
import { useSelector, useDispatch } from 'react-redux';
import {
HANA_SCALE_UP,
HANA_SCALE_UP_PERF_OPT,
HANA_SCALE_UP_COST_OPT,
} from '@lib/model/clusters';

import { pickBy, values } from 'lodash';

import { getCatalog } from '@state/selectors/catalog';
import { updateCatalog } from '@state/catalog';
import { OPTION_ALL } from '@common/Select';
Expand All @@ -11,10 +15,25 @@ import ChecksCatalog from './ChecksCatalog';

const isSomeFilter = (value) => value !== OPTION_ALL;

const modifyHanaScaleUpClusterType = (clusterType) => {
switch (clusterType) {
case HANA_SCALE_UP_PERF_OPT:
case HANA_SCALE_UP_COST_OPT:
return HANA_SCALE_UP;
default:
return clusterType;
}
};

const buildUpdateCatalogAction = (selectedFilters) => {
const hasFilters = values(selectedFilters).some(isSomeFilter);
const modifiedSelectedFilters = {
...selectedFilters,
cluster_type: modifyHanaScaleUpClusterType(selectedFilters.cluster_type),
};

const payload = {
...pickBy(selectedFilters, isSomeFilter),
...pickBy(modifiedSelectedFilters, isSomeFilter),
...(hasFilters ? { filteredCatalog: true } : {}),
};
return updateCatalog(payload);
Expand All @@ -40,12 +59,14 @@ function ChecksCatalogPage() {
selectedProvider,
selectedTargetType,
selectedClusterType,
selectedHanaScaleUpScenario,
}) =>
dispatch(
buildUpdateCatalogAction({
provider: selectedProvider,
target_type: selectedTargetType,
cluster_type: selectedClusterType,
hana_scenario: selectedHanaScaleUpScenario,
})
)
}
Expand Down
Loading