diff options
Diffstat (limited to 'server/sonar-web/src/main/js/apps')
19 files changed, 188 insertions, 179 deletions
diff --git a/server/sonar-web/src/main/js/apps/system/__tests__/utils-test.ts b/server/sonar-web/src/main/js/apps/system/__tests__/utils-test.ts index 0c550fd943f..b1e915f0370 100644 --- a/server/sonar-web/src/main/js/apps/system/__tests__/utils-test.ts +++ b/server/sonar-web/src/main/js/apps/system/__tests__/utils-test.ts @@ -18,6 +18,7 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import * as u from '../utils'; +import { ClusterSysInfo, SysInfo } from '../../../api/system'; describe('parseQuery', () => { it('should correctly parse the expand array', () => { @@ -44,16 +45,26 @@ describe('groupSections', () => { describe('getSystemLogsLevel', () => { it('should correctly return log level for standalone mode', () => { - expect(u.getSystemLogsLevel({ 'Logs Level': 'FOO' } as u.StandaloneSysInfo)).toBe('FOO'); - expect(u.getSystemLogsLevel({} as u.StandaloneSysInfo)).toBe('INFO'); + expect(u.getSystemLogsLevel({ System: { 'Logs Level': 'FOO' } } as SysInfo)).toBe('FOO'); + expect(u.getSystemLogsLevel({} as SysInfo)).toBe('INFO'); expect(u.getSystemLogsLevel()).toBe('INFO'); }); + it('should return the worst log level for cluster mode', () => { expect( u.getSystemLogsLevel({ - Cluster: true, - 'Application Nodes': [{ 'Logs Level': 'INFO' }, { 'Logs Level': 'DEBUG' }] - } as u.ClusterSysInfo) + System: { 'High Availability': true }, + 'Application Nodes': [ + { + 'Compute Engine Logging': { 'Logs Level': 'DEBUG' }, + 'Web Logging': { 'Logs Level': 'INFO' } + }, + { + 'Compute Engine Logging': { 'Logs Level': 'INFO' }, + 'Web Logging': { 'Logs Level': 'INFO' } + } + ] + } as ClusterSysInfo) ).toBe('DEBUG'); }); }); diff --git a/server/sonar-web/src/main/js/apps/system/components/App.tsx b/server/sonar-web/src/main/js/apps/system/components/App.tsx index 1cd3752de88..38679882597 100644 --- a/server/sonar-web/src/main/js/apps/system/components/App.tsx +++ b/server/sonar-web/src/main/js/apps/system/components/App.tsx @@ -24,16 +24,8 @@ import ClusterSysInfos from './ClusterSysInfos'; import PageHeader from './PageHeader'; import StandaloneSysInfos from './StandaloneSysInfos'; import { translate } from '../../../helpers/l10n'; -import { getSystemInfo, SysInfo } from '../../../api/system'; -import { - ClusterSysInfo, - getSystemLogsLevel, - isCluster, - parseQuery, - Query, - serializeQuery, - StandaloneSysInfo -} from '../utils'; +import { ClusterSysInfo, getSystemInfo, SysInfo } from '../../../api/system'; +import { getSystemLogsLevel, isCluster, parseQuery, Query, serializeQuery } from '../utils'; import { RawQuery } from '../../../helpers/query'; import '../styles.css'; @@ -114,7 +106,7 @@ export default class App extends React.PureComponent<Props, State> { return ( <StandaloneSysInfos expandedCards={query.expandedCards} - sysInfoData={sysInfoData as StandaloneSysInfo} + sysInfoData={sysInfoData} toggleCard={this.toggleSysInfoCards} /> ); diff --git a/server/sonar-web/src/main/js/apps/system/components/ChangeLogLevelForm.tsx b/server/sonar-web/src/main/js/apps/system/components/ChangeLogLevelForm.tsx index 6118fe2d956..7de208bd4f6 100644 --- a/server/sonar-web/src/main/js/apps/system/components/ChangeLogLevelForm.tsx +++ b/server/sonar-web/src/main/js/apps/system/components/ChangeLogLevelForm.tsx @@ -49,7 +49,7 @@ export default class ChangeLogLevelForm extends React.PureComponent<Props, State handleFormSubmit = (event: React.SyntheticEvent<HTMLFormElement>) => { event.preventDefault(); const { newLevel } = this.state; - if (!this.state.updating && newLevel !== this.props.logLevel) { + if (!this.state.updating) { this.setState({ updating: true }); setLogLevel(newLevel).then( () => this.props.onChange(newLevel), @@ -64,7 +64,6 @@ export default class ChangeLogLevelForm extends React.PureComponent<Props, State render() { const { updating, newLevel } = this.state; const header = translate('system.set_log_level'); - const disableSubmit = updating || newLevel === this.props.logLevel; return ( <Modal isOpen={true} @@ -100,7 +99,7 @@ export default class ChangeLogLevelForm extends React.PureComponent<Props, State </div> <div className="modal-foot"> {updating && <i className="spinner spacer-right" />} - <button disabled={disableSubmit} id="set-log-level-submit"> + <button disabled={updating} id="set-log-level-submit"> {translate('save')} </button> <a href="#" id="set-log-level-cancel" onClick={this.handleCancelClick}> diff --git a/server/sonar-web/src/main/js/apps/system/components/ClusterSysInfos.tsx b/server/sonar-web/src/main/js/apps/system/components/ClusterSysInfos.tsx index cb3000dea32..54c70b1999c 100644 --- a/server/sonar-web/src/main/js/apps/system/components/ClusterSysInfos.tsx +++ b/server/sonar-web/src/main/js/apps/system/components/ClusterSysInfos.tsx @@ -21,8 +21,8 @@ import * as React from 'react'; import { sortBy } from 'lodash'; import HealthCard from './info-items/HealthCard'; import { translate } from '../../../helpers/l10n'; +import { ClusterSysInfo } from '../../../api/system'; import { - ClusterSysInfo, getAppNodes, getHealth, getHealthCauses, diff --git a/server/sonar-web/src/main/js/apps/system/components/StandaloneSysInfos.tsx b/server/sonar-web/src/main/js/apps/system/components/StandaloneSysInfos.tsx index 4ed444cc66d..69ddc3cbfab 100644 --- a/server/sonar-web/src/main/js/apps/system/components/StandaloneSysInfos.tsx +++ b/server/sonar-web/src/main/js/apps/system/components/StandaloneSysInfos.tsx @@ -20,18 +20,18 @@ import * as React from 'react'; import { map } from 'lodash'; import HealthCard from './info-items/HealthCard'; +import { SysInfo } from '../../../api/system'; import { getHealth, getHealthCauses, getStandaloneMainSections, getStandaloneSecondarySections, - ignoreInfoFields, - StandaloneSysInfo + ignoreInfoFields } from '../utils'; interface Props { expandedCards: string[]; - sysInfoData: StandaloneSysInfo; + sysInfoData: SysInfo; toggleCard: (toggledCard: string) => void; } diff --git a/server/sonar-web/src/main/js/apps/system/components/__tests__/ClusterSysInfos-test.tsx b/server/sonar-web/src/main/js/apps/system/components/__tests__/ClusterSysInfos-test.tsx index 21c60cbd6fc..c2e892abb5d 100644 --- a/server/sonar-web/src/main/js/apps/system/components/__tests__/ClusterSysInfos-test.tsx +++ b/server/sonar-web/src/main/js/apps/system/components/__tests__/ClusterSysInfos-test.tsx @@ -20,20 +20,33 @@ import * as React from 'react'; import { shallow } from 'enzyme'; import ClusterSysInfos from '../ClusterSysInfos'; -import { HealthType } from '../../../../api/system'; -import { ClusterSysInfo } from '../../utils'; +import { ClusterSysInfo, HealthType } from '../../../../api/system'; const sysInfoData: ClusterSysInfo = { - Cluster: true, Health: HealthType.RED, - Name: 'Foo', - 'Health Causes': [{ message: 'Database down' }], + 'Health Causes': ['Database down'], 'Application Nodes': [ - { Name: 'Bar', Health: HealthType.GREEN, 'Health Causes': [], 'Logs Level': 'INFO' } + { + Name: 'Bar', + Health: HealthType.GREEN, + 'Health Causes': [], + 'Compute Engine Logging': { 'Logs Level': 'INFO' }, + 'Web Logging': { 'Logs Level': 'INFO' } + } ], 'Search Nodes': [ - { Name: 'Baz', Health: HealthType.YELLOW, 'Health Causes': [], 'Logs Level': 'INFO' } - ] + { + Name: 'Baz', + Health: HealthType.YELLOW, + 'Health Causes': [], + 'Compute Engine Logging': { 'Logs Level': 'INFO' }, + 'Web Logging': { 'Logs Level': 'INFO' } + } + ], + System: { + 'High Availability': true, + 'Logs Level': 'INFO' + } }; it('should render correctly', () => { @@ -42,9 +55,27 @@ it('should render correctly', () => { sysInfoData: { ...sysInfoData, 'Application Nodes': [ - { Name: 'Foo', Health: HealthType.GREEN, 'Health Causes': [], 'Logs Level': 'INFO' }, - { Name: 'Bar', Health: HealthType.RED, 'Health Causes': [], 'Logs Level': 'DEBUG' }, - { Name: 'Baz', Health: HealthType.YELLOW, 'Health Causes': [], 'Logs Level': 'TRACE' } + { + Name: 'Foo', + Health: HealthType.GREEN, + 'Health Causes': [], + 'Compute Engine Logging': { 'Logs Level': 'INFO' }, + 'Web Logging': { 'Logs Level': 'INFO' } + }, + { + Name: 'Bar', + Health: HealthType.RED, + 'Health Causes': [], + 'Compute Engine Logging': { 'Logs Level': 'INFO' }, + 'Web Logging': { 'Logs Level': 'DEBUG' } + }, + { + Name: 'Baz', + Health: HealthType.YELLOW, + 'Health Causes': [], + 'Compute Engine Logging': { 'Logs Level': 'TRACE' }, + 'Web Logging': { 'Logs Level': 'DEBUG' } + } ] } }).find('HealthCard') diff --git a/server/sonar-web/src/main/js/apps/system/components/__tests__/StandaloneSysInfos-test.tsx b/server/sonar-web/src/main/js/apps/system/components/__tests__/StandaloneSysInfos-test.tsx index c70202e3219..220cdb85ef1 100644 --- a/server/sonar-web/src/main/js/apps/system/components/__tests__/StandaloneSysInfos-test.tsx +++ b/server/sonar-web/src/main/js/apps/system/components/__tests__/StandaloneSysInfos-test.tsx @@ -20,18 +20,18 @@ import * as React from 'react'; import { shallow } from 'enzyme'; import StandaloneSysInfos from '../StandaloneSysInfos'; -import { HealthType } from '../../../../api/system'; -import { StandaloneSysInfo } from '../../utils'; +import { HealthType, SysInfo } from '../../../../api/system'; -const sysInfoData: StandaloneSysInfo = { - Cluster: true, +const sysInfoData: SysInfo = { Health: HealthType.RED, - 'Logs Level': 'DEBUG', - Name: 'Foo', - 'Health Causes': [{ message: 'Database down' }], + 'Health Causes': ['Database down'], 'Web JVM': { 'Max Memory': '2Gb' }, 'Compute Engine': { Pending: 4 }, - Elasticsearch: { 'Number of Nodes': 1 } + Search: { 'Number of Nodes': 1 }, + System: { + 'High Availability': true, + 'Logs Level': 'DEBUG' + } }; it('should render correctly', () => { diff --git a/server/sonar-web/src/main/js/apps/system/components/__tests__/__snapshots__/ChangeLogLevelForm-test.tsx.snap b/server/sonar-web/src/main/js/apps/system/components/__tests__/__snapshots__/ChangeLogLevelForm-test.tsx.snap index eeaa775462d..4759423740e 100644 --- a/server/sonar-web/src/main/js/apps/system/components/__tests__/__snapshots__/ChangeLogLevelForm-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/system/components/__tests__/__snapshots__/ChangeLogLevelForm-test.tsx.snap @@ -97,7 +97,7 @@ exports[`should display some warning messages for non INFO levels 1`] = ` className="modal-foot" > <button - disabled={true} + disabled={false} id="set-log-level-submit" > save @@ -206,7 +206,7 @@ exports[`should render correctly 1`] = ` className="modal-foot" > <button - disabled={true} + disabled={false} id="set-log-level-submit" > save diff --git a/server/sonar-web/src/main/js/apps/system/components/__tests__/__snapshots__/ClusterSysInfos-test.tsx.snap b/server/sonar-web/src/main/js/apps/system/components/__tests__/__snapshots__/ClusterSysInfos-test.tsx.snap index abd7d3a63ac..6db92bdf46b 100644 --- a/server/sonar-web/src/main/js/apps/system/components/__tests__/__snapshots__/ClusterSysInfos-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/system/components/__tests__/__snapshots__/ClusterSysInfos-test.tsx.snap @@ -7,9 +7,7 @@ exports[`should support more than two nodes 1`] = ` health="RED" healthCauses={ Array [ - Object { - "message": "Database down", - }, + "Database down", ] } name="System" @@ -17,7 +15,8 @@ exports[`should support more than two nodes 1`] = ` open={true} sysInfoData={ Object { - "Name": "Foo", + "High Availability": true, + "Logs Level": "INFO", } } /> @@ -34,8 +33,12 @@ exports[`should support more than two nodes 1`] = ` open={false} sysInfoData={ Object { - "Logs Level": "INFO", - "Name": "Bar", + "Compute Engine Logging": Object { + "Logs Level": "INFO", + }, + "Web Logging": Object { + "Logs Level": "INFO", + }, } } /> @@ -52,8 +55,12 @@ exports[`should support more than two nodes 1`] = ` open={false} sysInfoData={ Object { - "Logs Level": "INFO", - "Name": "Baz", + "Compute Engine Logging": Object { + "Logs Level": "INFO", + }, + "Web Logging": Object { + "Logs Level": "INFO", + }, } } /> diff --git a/server/sonar-web/src/main/js/apps/system/components/__tests__/__snapshots__/StandaloneSysInfos-test.tsx.snap b/server/sonar-web/src/main/js/apps/system/components/__tests__/__snapshots__/StandaloneSysInfos-test.tsx.snap index f4961aeac1e..b7a2d4285c1 100644 --- a/server/sonar-web/src/main/js/apps/system/components/__tests__/__snapshots__/StandaloneSysInfos-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/system/components/__tests__/__snapshots__/StandaloneSysInfos-test.tsx.snap @@ -7,9 +7,7 @@ exports[`should render correctly 1`] = ` health="RED" healthCauses={ Array [ - Object { - "message": "Database down", - }, + "Database down", ] } name="System" @@ -17,8 +15,8 @@ exports[`should render correctly 1`] = ` open={false} sysInfoData={ Object { + "High Availability": true, "Logs Level": "DEBUG", - "Name": "Foo", } } /> @@ -28,11 +26,9 @@ exports[`should render correctly 1`] = ` open={false} sysInfoData={ Object { - "Web Database Connectivity": undefined, "Web JVM": Object { "Max Memory": "2Gb", }, - "Web JVM Properties": undefined, } } /> @@ -42,9 +38,9 @@ exports[`should render correctly 1`] = ` open={true} sysInfoData={ Object { - "Compute Engine JVM": undefined, - "Compute Engine JVM Properties": undefined, - "Pending": 4, + "Compute Engine": Object { + "Pending": 4, + }, } } /> @@ -54,11 +50,9 @@ exports[`should render correctly 1`] = ` open={false} sysInfoData={ Object { - "Elasticsearch": Object { + "Search": Object { "Number of Nodes": 1, }, - "Search JVM": undefined, - "Search JVM Properties": undefined, } } /> diff --git a/server/sonar-web/src/main/js/apps/system/components/info-items/HealthCard.tsx b/server/sonar-web/src/main/js/apps/system/components/info-items/HealthCard.tsx index 459f26ee721..ff49fc75a83 100644 --- a/server/sonar-web/src/main/js/apps/system/components/info-items/HealthCard.tsx +++ b/server/sonar-web/src/main/js/apps/system/components/info-items/HealthCard.tsx @@ -23,14 +23,14 @@ import { map } from 'lodash'; import HealthItem from './HealthItem'; import OpenCloseIcon from '../../../../components/icons-components/OpenCloseIcon'; import Section from './Section'; -import { HealthType, HealthCause, SysValueObject } from '../../../../api/system'; +import { HealthType, SysValueObject } from '../../../../api/system'; import { LOGS_LEVELS, groupSections, getLogsLevel } from '../../utils'; import { translate } from '../../../../helpers/l10n'; interface Props { biggerHealth?: boolean; health?: HealthType; - healthCauses?: HealthCause[]; + healthCauses?: string[]; onClick: (toggledCard: string) => void; open: boolean; name: string; diff --git a/server/sonar-web/src/main/js/apps/system/components/info-items/HealthCauseItem.tsx b/server/sonar-web/src/main/js/apps/system/components/info-items/HealthCauseItem.tsx index 49b22b717bb..7d34624a709 100644 --- a/server/sonar-web/src/main/js/apps/system/components/info-items/HealthCauseItem.tsx +++ b/server/sonar-web/src/main/js/apps/system/components/info-items/HealthCauseItem.tsx @@ -19,12 +19,12 @@ */ import * as React from 'react'; import * as classNames from 'classnames'; -import { HealthCause, HealthType } from '../../../../api/system'; +import { HealthType } from '../../../../api/system'; interface Props { className?: string; health: HealthType; - healthCause: HealthCause; + healthCause: string; } export default function HealthCauseItem({ className, health, healthCause }: Props) { @@ -35,7 +35,7 @@ export default function HealthCauseItem({ className, health, healthCause }: Prop health === HealthType.RED ? 'alert-danger' : 'alert-warning', className )}> - {healthCause.message} + {healthCause} </span> ); } diff --git a/server/sonar-web/src/main/js/apps/system/components/info-items/HealthItem.tsx b/server/sonar-web/src/main/js/apps/system/components/info-items/HealthItem.tsx index 86618c34c8a..2edc10805e0 100644 --- a/server/sonar-web/src/main/js/apps/system/components/info-items/HealthItem.tsx +++ b/server/sonar-web/src/main/js/apps/system/components/info-items/HealthItem.tsx @@ -21,13 +21,13 @@ import * as React from 'react'; import * as classNames from 'classnames'; import HealthCauseItem from './HealthCauseItem'; import StatusIndicator from '../../../../components/common/StatusIndicator'; -import { HealthType, HealthCause } from '../../../../api/system'; +import { HealthType } from '../../../../api/system'; interface Props { biggerHealth?: boolean; className?: string; health: HealthType; - healthCauses?: HealthCause[]; + healthCauses?: string[]; } export default function HealthItem({ biggerHealth, className, health, healthCauses }: Props) { diff --git a/server/sonar-web/src/main/js/apps/system/components/info-items/__tests__/HealthCard-test.tsx b/server/sonar-web/src/main/js/apps/system/components/info-items/__tests__/HealthCard-test.tsx index 98b33bd31ee..933510b929f 100644 --- a/server/sonar-web/src/main/js/apps/system/components/info-items/__tests__/HealthCard-test.tsx +++ b/server/sonar-web/src/main/js/apps/system/components/info-items/__tests__/HealthCard-test.tsx @@ -59,7 +59,7 @@ function getShallowWrapper(props = {}) { <HealthCard biggerHealth={false} health={HealthType.RED} - healthCauses={[{ message: 'foo' }]} + healthCauses={['foo']} name="Foobar" onClick={() => {}} open={false} diff --git a/server/sonar-web/src/main/js/apps/system/components/info-items/__tests__/HealthCauseItem-test.tsx b/server/sonar-web/src/main/js/apps/system/components/info-items/__tests__/HealthCauseItem-test.tsx index 24504f09a91..319d069cae5 100644 --- a/server/sonar-web/src/main/js/apps/system/components/info-items/__tests__/HealthCauseItem-test.tsx +++ b/server/sonar-web/src/main/js/apps/system/components/info-items/__tests__/HealthCauseItem-test.tsx @@ -23,10 +23,8 @@ import HealthCauseItem from '../HealthCauseItem'; import { HealthType } from '../../../../../api/system'; it('should render correctly', () => { + expect(shallow(<HealthCauseItem health={HealthType.RED} healthCause="foo" />)).toMatchSnapshot(); expect( - shallow(<HealthCauseItem health={HealthType.RED} healthCause={{ message: 'foo' }} />) - ).toMatchSnapshot(); - expect( - shallow(<HealthCauseItem health={HealthType.YELLOW} healthCause={{ message: 'foo' }} />) + shallow(<HealthCauseItem health={HealthType.YELLOW} healthCause="foo" />) ).toMatchSnapshot(); }); diff --git a/server/sonar-web/src/main/js/apps/system/components/info-items/__tests__/HealthItem-test.tsx b/server/sonar-web/src/main/js/apps/system/components/info-items/__tests__/HealthItem-test.tsx index 9f1bd198352..7f21d999a4e 100644 --- a/server/sonar-web/src/main/js/apps/system/components/info-items/__tests__/HealthItem-test.tsx +++ b/server/sonar-web/src/main/js/apps/system/components/info-items/__tests__/HealthItem-test.tsx @@ -24,26 +24,19 @@ import { HealthType } from '../../../../../api/system'; it('should render correctly', () => { expect( - shallow( - <HealthItem biggerHealth={true} health={HealthType.RED} healthCauses={[{ message: 'foo' }]} /> - ) + shallow(<HealthItem biggerHealth={true} health={HealthType.RED} healthCauses={['foo']} />) ).toMatchSnapshot(); }); it('should not render health causes', () => { expect( - shallow(<HealthItem health={HealthType.GREEN} healthCauses={[{ message: 'foo' }]} />) + shallow(<HealthItem health={HealthType.GREEN} healthCauses={['foo']} />) ).toMatchSnapshot(); expect(shallow(<HealthItem health={HealthType.YELLOW} healthCauses={[]} />)).toMatchSnapshot(); }); it('should render multiple health causes', () => { expect( - shallow( - <HealthItem - health={HealthType.YELLOW} - healthCauses={[{ message: 'foo' }, { message: 'bar' }]} - /> - ) + shallow(<HealthItem health={HealthType.YELLOW} healthCauses={['foo', 'bar']} />) ).toMatchSnapshot(); }); diff --git a/server/sonar-web/src/main/js/apps/system/components/info-items/__tests__/__snapshots__/HealthCard-test.tsx.snap b/server/sonar-web/src/main/js/apps/system/components/info-items/__tests__/__snapshots__/HealthCard-test.tsx.snap index 7390ef8020e..6c054721b70 100644 --- a/server/sonar-web/src/main/js/apps/system/components/info-items/__tests__/__snapshots__/HealthCard-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/system/components/info-items/__tests__/__snapshots__/HealthCard-test.tsx.snap @@ -31,9 +31,7 @@ exports[`should display the sysinfo detail 1`] = ` health="RED" healthCauses={ Array [ - Object { - "message": "foo", - }, + "foo", ] } /> @@ -69,9 +67,7 @@ exports[`should render correctly 1`] = ` health="RED" healthCauses={ Array [ - Object { - "message": "foo", - }, + "foo", ] } /> @@ -102,9 +98,7 @@ exports[`should show a main section and multiple sub sections 1`] = ` health="RED" healthCauses={ Array [ - Object { - "message": "foo", - }, + "foo", ] } /> diff --git a/server/sonar-web/src/main/js/apps/system/components/info-items/__tests__/__snapshots__/HealthItem-test.tsx.snap b/server/sonar-web/src/main/js/apps/system/components/info-items/__tests__/__snapshots__/HealthItem-test.tsx.snap index f962437404c..eafb250bdd1 100644 --- a/server/sonar-web/src/main/js/apps/system/components/info-items/__tests__/__snapshots__/HealthItem-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/system/components/info-items/__tests__/__snapshots__/HealthItem-test.tsx.snap @@ -27,11 +27,7 @@ exports[`should render correctly 1`] = ` <HealthCauseItem className="spacer-right" health="RED" - healthCause={ - Object { - "message": "foo", - } - } + healthCause="foo" /> <StatusIndicator color="red" @@ -47,20 +43,12 @@ exports[`should render multiple health causes 1`] = ` <HealthCauseItem className="spacer-right" health="YELLOW" - healthCause={ - Object { - "message": "foo", - } - } + healthCause="foo" /> <HealthCauseItem className="spacer-right" health="YELLOW" - healthCause={ - Object { - "message": "bar", - } - } + healthCause="bar" /> <StatusIndicator color="yellow" diff --git a/server/sonar-web/src/main/js/apps/system/utils.ts b/server/sonar-web/src/main/js/apps/system/utils.ts index ae8818edf9d..5d98c9e74f8 100644 --- a/server/sonar-web/src/main/js/apps/system/utils.ts +++ b/server/sonar-web/src/main/js/apps/system/utils.ts @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -import { each, omit, memoize, sortBy } from 'lodash'; +import { each, memoize, omit, omitBy, pickBy, sortBy } from 'lodash'; import { cleanQuery, parseAsArray, @@ -26,7 +26,7 @@ import { serializeStringArray } from '../../helpers/query'; import { - HealthCause, + ClusterSysInfo, HealthType, NodeInfo, SysInfo, @@ -38,45 +38,64 @@ export interface Query { expandedCards: string[]; } -export interface ClusterSysInfo extends SysInfo { - 'Application Nodes': NodeInfo[]; - 'Search Nodes': NodeInfo[]; -} - -export interface StandaloneSysInfo extends SysInfo { - 'Logs Level': string; -} - export const LOGS_LEVELS = ['INFO', 'DEBUG', 'TRACE']; +export const HA_FIELD = 'High Availability'; export const HEALTH_FIELD = 'Health'; export const HEALTHCAUSES_FIELD = 'Health Causes'; export function ignoreInfoFields(sysInfoObject: SysValueObject): SysValueObject { - return omit(sysInfoObject, ['Cluster', HEALTH_FIELD, HEALTHCAUSES_FIELD]); + return omit(sysInfoObject, [HEALTH_FIELD, HEALTHCAUSES_FIELD, 'Name', 'Settings']); } export function getHealth(sysInfoObject: SysValueObject): HealthType { return sysInfoObject[HEALTH_FIELD] as HealthType; } -export function getHealthCauses(sysInfoObject: SysValueObject): HealthCause[] { - return sysInfoObject[HEALTHCAUSES_FIELD] as HealthCause[]; +export function getHealthCauses(sysInfoObject: SysValueObject): string[] { + return sysInfoObject[HEALTHCAUSES_FIELD] as string[]; } export function getLogsLevel(sysInfoObject: SysValueObject): string { + if (sysInfoObject['Web Logging']) { + return sortBy( + [ + (sysInfoObject as NodeInfo)['Compute Engine Logging']['Logs Level'], + (sysInfoObject as NodeInfo)['Web Logging']['Logs Level'] + ], + logLevel => LOGS_LEVELS.indexOf(logLevel) + )[1]; + } + if (sysInfoObject['System']) { + return (sysInfoObject as SysInfo)['System']['Logs Level']; + } return (sysInfoObject['Logs Level'] || LOGS_LEVELS[0]) as string; } +export function getAppNodes(sysInfoData: ClusterSysInfo): NodeInfo[] { + return sysInfoData['Application Nodes']; +} + +export function getSearchNodes(sysInfoData: ClusterSysInfo): NodeInfo[] { + return sysInfoData['Search Nodes']; +} + +export function isCluster(sysInfoData?: SysInfo): boolean { + return ( + sysInfoData != undefined && sysInfoData['System'] && sysInfoData['System'][HA_FIELD] === true + ); +} + export function getSystemLogsLevel(sysInfoData?: SysInfo): string { const defaultLevel = LOGS_LEVELS[0]; if (!sysInfoData) { return defaultLevel; } if (isCluster(sysInfoData)) { - const nodes = sortBy(getAppNodes(sysInfoData as ClusterSysInfo), node => - LOGS_LEVELS.indexOf(getLogsLevel(node)) + const logLevels = sortBy( + getAppNodes(sysInfoData as ClusterSysInfo).map(getLogsLevel), + logLevel => LOGS_LEVELS.indexOf(logLevel) ); - return nodes.length > 0 ? getLogsLevel(nodes[nodes.length - 1]) : defaultLevel; + return logLevels.length > 0 ? logLevels[logLevels.length - 1] : defaultLevel; } else { return getLogsLevel(sysInfoData); } @@ -87,51 +106,40 @@ export function getNodeName(nodeInfo: NodeInfo): string { } export function getClusterMainCardSection(sysInfoData: ClusterSysInfo): SysValueObject { - return omit(sysInfoData, ['Application Nodes', 'Search Nodes', 'Settings', 'Statistics']); -} - -export function getStandaloneMainSections(sysInfoData: StandaloneSysInfo): SysValueObject { - return omit(sysInfoData, [ - 'Settings', - 'Statistics', - 'Compute Engine', - 'Compute Engine JVM', - 'Compute Engine JVM Properties', - 'Elasticsearch', - 'Search JVM', - 'Search JVM Properties', - 'Web Database Connectivity', - 'Web JVM', - 'Web JVM Properties' - ]); -} - -export function getStandaloneSecondarySections(sysInfoData: StandaloneSysInfo): SysInfoSection { return { - Web: { - 'Web Database Connectivity': sysInfoData['Web Database Connectivity'], - 'Web JVM': sysInfoData['Web JVM'], - 'Web JVM Properties': sysInfoData['Web JVM Properties'] - }, - 'Compute Engine': { - ...sysInfoData['Compute Engine'] as SysValueObject, - 'Compute Engine JVM': sysInfoData['Compute Engine JVM'], - 'Compute Engine JVM Properties': sysInfoData['Compute Engine JVM Properties'] - }, - Search: { - Elasticsearch: sysInfoData['Elasticsearch'] as SysValueObject, - 'Search JVM': sysInfoData['Search JVM'], - 'Search JVM Properties': sysInfoData['Search JVM Properties'] - } + ...sysInfoData['System'], + ...omit(sysInfoData, [ + 'Application Nodes', + 'Plugins', + 'Search Nodes', + 'Settings', + 'Statistics', + 'System' + ]) }; } -export function getAppNodes(sysInfoData: ClusterSysInfo): NodeInfo[] { - return sysInfoData['Application Nodes']; +export function getStandaloneMainSections(sysInfoData: SysInfo): SysValueObject { + return { + ...sysInfoData['System'], + ...omitBy( + sysInfoData, + (value, key) => + value == null || + ['Plugins', 'Settings', 'Statistics', 'System'].includes(key) || + key.startsWith('Compute Engine') || + key.startsWith('Search') || + key.startsWith('Web') + ) + }; } -export function getSearchNodes(sysInfoData: ClusterSysInfo): NodeInfo[] { - return sysInfoData['Search Nodes']; +export function getStandaloneSecondarySections(sysInfoData: SysInfo): SysInfoSection { + return { + Web: pickBy(sysInfoData, (_, key) => key.startsWith('Web')), + 'Compute Engine': pickBy(sysInfoData, (_, key) => key.startsWith('Compute Engine')), + Search: pickBy(sysInfoData, (_, key) => key.startsWith('Search')) + }; } export function groupSections(sysInfoData: SysValueObject) { @@ -147,18 +155,12 @@ export function groupSections(sysInfoData: SysValueObject) { return { mainSection, sections }; } -export function isCluster(sysInfoData?: SysInfo): boolean { - return sysInfoData != undefined && sysInfoData['Cluster'] === true; -} +export const parseQuery = memoize((urlQuery: RawQuery): Query => ({ + expandedCards: parseAsArray(urlQuery.expand, parseAsString) +})); -export const parseQuery = memoize((urlQuery: RawQuery): Query => { - return { - expandedCards: parseAsArray(urlQuery.expand, parseAsString) - }; -}); - -export const serializeQuery = memoize((query: Query): RawQuery => { - return cleanQuery({ +export const serializeQuery = memoize((query: Query): RawQuery => + cleanQuery({ expand: serializeStringArray(query.expandedCards) - }); -}); + }) +); |