]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-10120 Add server id and date in the system info json name
authorGrégoire Aubert <gregoire.aubert@sonarsource.com>
Mon, 15 Jan 2018 07:56:18 +0000 (08:56 +0100)
committerGrégoire Aubert <gregoire.aubert@sonarsource.com>
Mon, 15 Jan 2018 10:40:43 +0000 (11:40 +0100)
server/sonar-web/src/main/js/api/system.ts
server/sonar-web/src/main/js/apps/system/components/App.tsx
server/sonar-web/src/main/js/apps/system/components/PageActions.tsx
server/sonar-web/src/main/js/apps/system/components/PageHeader.tsx
server/sonar-web/src/main/js/apps/system/components/__tests__/ClusterSysInfos-test.tsx
server/sonar-web/src/main/js/apps/system/components/__tests__/PageActions-test.tsx
server/sonar-web/src/main/js/apps/system/components/__tests__/StandaloneSysInfos-test.tsx
server/sonar-web/src/main/js/apps/system/components/__tests__/__snapshots__/ClusterSysInfos-test.tsx.snap
server/sonar-web/src/main/js/apps/system/components/__tests__/__snapshots__/PageActions-test.tsx.snap
server/sonar-web/src/main/js/apps/system/components/__tests__/__snapshots__/StandaloneSysInfos-test.tsx.snap
server/sonar-web/src/main/js/apps/system/utils.ts

index 0d5a58856d253670cf75c23433316ca6cf8e7bce..794000c0389ae23bd87ac77b3d03ddcfd6290733 100644 (file)
@@ -50,6 +50,7 @@ export interface SysInfo extends SysValueObject {
   System: {
     'High Availability': boolean;
     'Logs Level': string;
+    'Server ID': string;
   };
 }
 
index 4ca3983b019109ef2ea630bcb275f548ae85a14b..7c3c01adf5c1efac959fb5ba21092ca97146b6af 100644 (file)
@@ -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<Props, State> {
         <Helmet title={translate('system_info.page')} />
         <SystemUpgradeNotif />
         <PageHeader
-          loading={loading}
           isCluster={isCluster(sysInfoData)}
+          loading={loading}
           logLevel={getSystemLogsLevel(sysInfoData)}
-          showActions={sysInfoData !== undefined}
           onLogLevelChange={this.fetchSysInfo}
+          serverId={getServerId(sysInfoData)}
+          showActions={sysInfoData !== undefined}
         />
         {this.renderSysInfo()}
       </div>
index 1499dfde562bd396ef820f3ca896cba572485dac..dfda4b9e904fbc0119da653c97b1c5e91d7c7890 100644 (file)
@@ -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<Props, State> {
           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')}
         </a>
index 3828cc2cd72a0f549c7c084c97d1a0b8ec20b62f..653a3841154f62348b847ef2e107d71ca1dcf1e1 100644 (file)
@@ -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}
         />
       )}
index 643e09c5a286eaeab119060833a3cc4cc6d061c7..ad20d28f61fa7940cad6d406432cf90f2617002f 100644 (file)
@@ -45,7 +45,8 @@ const sysInfoData: ClusterSysInfo = {
   ],
   System: {
     'High Availability': true,
-    'Logs Level': 'INFO'
+    'Logs Level': 'INFO',
+    'Server ID': 'MyServerId'
   }
 };
 
index 1aa058f323845824da73b02d44b0b1ed5d48247b..5bf79f1de3da749e8b533a9660dcf09728ee02bd 100644 (file)
@@ -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(
-      <PageActions
-        canDownloadLogs={true}
-        canRestart={true}
-        cluster={false}
-        logLevel="INFO"
-        onLogLevelChange={() => {}}
-      />
-    )
-  ).toMatchSnapshot();
+  expect(getWrapper({ serverId: 'MyServerId' })).toMatchSnapshot();
 });
 
 it('should render without restart and log download', () => {
   expect(
-    shallow(
-      <PageActions
-        canDownloadLogs={false}
-        canRestart={false}
-        cluster={true}
-        logLevel="INFO"
-        onLogLevelChange={() => {}}
-      />
-    )
+    getWrapper({ canDownloadLogs: false, canRestart: false, cluster: true })
   ).toMatchSnapshot();
 });
 
 it('should open restart modal', () => {
-  const wrapper = shallow(
-    <PageActions
-      canDownloadLogs={true}
-      canRestart={true}
-      cluster={false}
-      logLevel="INFO"
-      onLogLevelChange={() => {}}
-    />
-  );
+  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(
     <PageActions
       canDownloadLogs={true}
       canRestart={true}
       cluster={false}
       logLevel="INFO"
       onLogLevelChange={() => {}}
+      {...props}
     />
   );
-  click(wrapper.find('#edit-logs-level-button'));
-  expect(wrapper.find('ChangeLogLevelForm')).toHaveLength(1);
-});
+}
index f3a45b2883ff99e31f14eb71fe194a344d4df2f8..121a57d0941f64d2de3b46c5a56c119e008f04de 100644 (file)
@@ -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'
   }
 };
 
index 4cee8e008900c88a5ce3e0fb0ab1d023084b4735..ca216f72e048f093642b821c6003ddb7f4bfae18 100644 (file)
@@ -17,6 +17,7 @@ exports[`should support more than two nodes 1`] = `
       Object {
         "High Availability": true,
         "Logs Level": "INFO",
+        "Server ID": "MyServerId",
       }
     }
   />
index 3556043a83b0c35d2a8edee2a94389127dea498f..dd7d6f39b3623958d4c9a83d34dfe915c63a2944 100644 (file)
@@ -80,7 +80,7 @@ exports[`should render correctly 1`] = `
   </div>
   <a
     className="button spacer-left"
-    download="sonarqube_system_info.json"
+    download="sonarqube-support-info-filesuffix(MyServerId).json"
     href="/api/system/info"
     id="download-link"
     onClick={[Function]}
@@ -122,7 +122,7 @@ exports[`should render without restart and log download 1`] = `
   </span>
   <a
     className="button spacer-left"
-    download="sonarqube_system_info.json"
+    download="sonarqube-support-info-filesuffix().json"
     href="/api/system/info"
     id="download-link"
     onClick={[Function]}
index 13877f72b8620635be233fe939dd38d3531e2e16..e5832de513c4d3ca8e959529c6c40ae99a2e77b3 100644 (file)
@@ -17,6 +17,7 @@ exports[`should render correctly 1`] = `
       Object {
         "High Availability": true,
         "Logs Level": "DEBUG",
+        "Server ID": "MyServerId",
       }
     }
   />
index 503084200e423f5b0292e0b8f23190288a425ab4..e24f796cd60291afe2ba9795fa89d0fd3f07d9b0 100644 (file)
@@ -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 = {};