From: Grégoire Aubert Date: Mon, 15 Jan 2018 07:56:18 +0000 (+0100) Subject: SONAR-10120 Add server id and date in the system info json name X-Git-Tag: 7.0-RC1~11 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=ec5f54c943df55d53fa6fae8632fcaede060ae19;p=sonarqube.git SONAR-10120 Add server id and date in the system info json name --- diff --git a/server/sonar-web/src/main/js/api/system.ts b/server/sonar-web/src/main/js/api/system.ts index 0d5a58856d2..794000c0389 100644 --- a/server/sonar-web/src/main/js/api/system.ts +++ b/server/sonar-web/src/main/js/api/system.ts @@ -50,6 +50,7 @@ export interface SysInfo extends SysValueObject { System: { 'High Availability': boolean; 'Logs Level': string; + 'Server ID': string; }; } 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 4ca3983b019..7c3c01adf5c 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 @@ -26,7 +26,14 @@ import StandaloneSysInfos from './StandaloneSysInfos'; import SystemUpgradeNotif from './system-upgrade/SystemUpgradeNotif'; import { translate } from '../../../helpers/l10n'; import { ClusterSysInfo, getSystemInfo, SysInfo } from '../../../api/system'; -import { getSystemLogsLevel, isCluster, parseQuery, Query, serializeQuery } from '../utils'; +import { + getServerId, + getSystemLogsLevel, + isCluster, + parseQuery, + Query, + serializeQuery +} from '../utils'; import { RawQuery } from '../../../helpers/query'; import '../styles.css'; @@ -124,11 +131,12 @@ export default class App extends React.PureComponent { {this.renderSysInfo()} diff --git a/server/sonar-web/src/main/js/apps/system/components/PageActions.tsx b/server/sonar-web/src/main/js/apps/system/components/PageActions.tsx index 1499dfde562..dfda4b9e904 100644 --- a/server/sonar-web/src/main/js/apps/system/components/PageActions.tsx +++ b/server/sonar-web/src/main/js/apps/system/components/PageActions.tsx @@ -20,6 +20,7 @@ import * as React from 'react'; import ChangeLogLevelForm from './ChangeLogLevelForm'; import RestartForm from '../../../components/common/RestartForm'; +import { getFileNameSuffix } from '../utils'; import { EditButton } from '../../../components/ui/buttons'; import { getBaseUrl } from '../../../helpers/urls'; import { translate } from '../../../helpers/l10n'; @@ -30,6 +31,7 @@ interface Props { cluster: boolean; logLevel: string; onLogLevelChange: () => void; + serverId?: string; } interface State { @@ -139,7 +141,7 @@ export default class PageActions extends React.PureComponent { id="download-link" className="button spacer-left" onClick={this.removeElementFocus} - download="sonarqube_system_info.json" + download={`sonarqube-support-info-${getFileNameSuffix(this.props.serverId)}.json`} target="_blank"> {translate('system.download_system_info')} diff --git a/server/sonar-web/src/main/js/apps/system/components/PageHeader.tsx b/server/sonar-web/src/main/js/apps/system/components/PageHeader.tsx index 3828cc2cd72..653a3841154 100644 --- a/server/sonar-web/src/main/js/apps/system/components/PageHeader.tsx +++ b/server/sonar-web/src/main/js/apps/system/components/PageHeader.tsx @@ -25,8 +25,9 @@ interface Props { isCluster: boolean; loading: boolean; logLevel: string; - showActions: boolean; onLogLevelChange: () => void; + serverId?: string; + showActions: boolean; } export default function PageHeader(props: Props) { @@ -39,6 +40,7 @@ export default function PageHeader(props: Props) { canRestart={!props.isCluster} cluster={props.isCluster} logLevel={props.logLevel} + serverId={props.serverId} onLogLevelChange={props.onLogLevelChange} /> )} 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 643e09c5a28..ad20d28f61f 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 @@ -45,7 +45,8 @@ const sysInfoData: ClusterSysInfo = { ], System: { 'High Availability': true, - 'Logs Level': 'INFO' + 'Logs Level': 'INFO', + 'Server ID': 'MyServerId' } }; diff --git a/server/sonar-web/src/main/js/apps/system/components/__tests__/PageActions-test.tsx b/server/sonar-web/src/main/js/apps/system/components/__tests__/PageActions-test.tsx index 1aa058f3238..5bf79f1de3d 100644 --- a/server/sonar-web/src/main/js/apps/system/components/__tests__/PageActions-test.tsx +++ b/server/sonar-web/src/main/js/apps/system/components/__tests__/PageActions-test.tsx @@ -22,58 +22,41 @@ import { shallow } from 'enzyme'; import PageActions from '../PageActions'; import { click } from '../../../../helpers/testUtils'; +jest.mock('../../utils', () => ({ + getFileNameSuffix: (suffix?: string) => `filesuffix(${suffix || ''})` +})); + it('should render correctly', () => { - expect( - shallow( - {}} - /> - ) - ).toMatchSnapshot(); + expect(getWrapper({ serverId: 'MyServerId' })).toMatchSnapshot(); }); it('should render without restart and log download', () => { expect( - shallow( - {}} - /> - ) + getWrapper({ canDownloadLogs: false, canRestart: false, cluster: true }) ).toMatchSnapshot(); }); it('should open restart modal', () => { - const wrapper = shallow( - {}} - /> - ); + const wrapper = getWrapper(); click(wrapper.find('#restart-server-button')); expect(wrapper.find('RestartForm')).toHaveLength(1); }); it('should open change log level modal', () => { - const wrapper = shallow( + const wrapper = getWrapper(); + click(wrapper.find('#edit-logs-level-button')); + expect(wrapper.find('ChangeLogLevelForm')).toHaveLength(1); +}); + +function getWrapper(props = {}) { + return shallow( {}} + {...props} /> ); - click(wrapper.find('#edit-logs-level-button')); - expect(wrapper.find('ChangeLogLevelForm')).toHaveLength(1); -}); +} 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 f3a45b2883f..121a57d0941 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 @@ -30,7 +30,8 @@ const sysInfoData: SysInfo = { Search: { 'Number of Nodes': 1 }, System: { 'High Availability': true, - 'Logs Level': 'DEBUG' + 'Logs Level': 'DEBUG', + 'Server ID': 'MyServerId' } }; 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 4cee8e00890..ca216f72e04 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 @@ -17,6 +17,7 @@ exports[`should support more than two nodes 1`] = ` Object { "High Availability": true, "Logs Level": "INFO", + "Server ID": "MyServerId", } } /> diff --git a/server/sonar-web/src/main/js/apps/system/components/__tests__/__snapshots__/PageActions-test.tsx.snap b/server/sonar-web/src/main/js/apps/system/components/__tests__/__snapshots__/PageActions-test.tsx.snap index 3556043a83b..dd7d6f39b36 100644 --- a/server/sonar-web/src/main/js/apps/system/components/__tests__/__snapshots__/PageActions-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/system/components/__tests__/__snapshots__/PageActions-test.tsx.snap @@ -80,7 +80,7 @@ exports[`should render correctly 1`] = ` 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 503084200e4..e24f796cd60 100644 --- a/server/sonar-web/src/main/js/apps/system/utils.ts +++ b/server/sonar-web/src/main/js/apps/system/utils.ts @@ -98,6 +98,10 @@ export function isCluster(sysInfoData?: SysInfo): boolean { ); } +export function getServerId(sysInfoData?: SysInfo): string | undefined { + return sysInfoData && sysInfoData['System']['Server ID']; +} + export function getSystemLogsLevel(sysInfoData?: SysInfo): string { const defaultLevel = LOGS_LEVELS[0]; if (!sysInfoData) { @@ -166,6 +170,15 @@ export function getStandaloneSecondarySections(sysInfoData: SysInfo): SysInfoSec }; } +export function getFileNameSuffix(suffix?: string) { + const now = new Date(); + return ( + `${suffix ? suffix + '-' : ''}` + + `${now.getFullYear()}-${now.getMonth() + 1}-` + + `${now.getDate()}-${now.getHours()}-${now.getMinutes()}` + ); +} + export function groupSections(sysInfoData: SysValueObject) { const mainSection: SysValueObject = {}; const sections: SysInfoSection = {};