diff options
author | Stas Vilchik <stas.vilchik@sonarsource.com> | 2017-08-18 19:28:04 +0200 |
---|---|---|
committer | Stas Vilchik <stas.vilchik@sonarsource.com> | 2017-08-21 10:29:05 +0200 |
commit | b6f7557b705bee15f1b86d325b58dbc539a22245 (patch) | |
tree | 927f54e57d3a984240015da744ae760c7f49c08c /server/sonar-web/src/main/js/api/system.ts | |
parent | 7983068e4d2a45531ba0942688e659adf9ee61a2 (diff) | |
download | sonarqube-b6f7557b705bee15f1b86d325b58dbc539a22245.tar.gz sonarqube-b6f7557b705bee15f1b86d325b58dbc539a22245.zip |
translate api/ to ts
Diffstat (limited to 'server/sonar-web/src/main/js/api/system.ts')
-rw-r--r-- | server/sonar-web/src/main/js/api/system.ts | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/server/sonar-web/src/main/js/api/system.ts b/server/sonar-web/src/main/js/api/system.ts new file mode 100644 index 00000000000..93eeaaf5b77 --- /dev/null +++ b/server/sonar-web/src/main/js/api/system.ts @@ -0,0 +1,60 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +import { getJSON, post } from '../helpers/request'; + +export function setLogLevel(level: string): Promise<void> { + return post('/api/system/change_log_level', { level }); +} + +export function getSystemInfo(): Promise<any> { + return getJSON('/api/system/info'); +} + +export function getSystemStatus(): Promise<any> { + return getJSON('/api/system/status'); +} + +export function restart(): Promise<void> { + return post('/api/system/restart'); +} + +const POLLING_INTERVAL = 2000; + +function pollStatus(cb: Function): void { + setTimeout(() => { + getSystemStatus() + .then(r => { + if (r.status === 'UP') { + cb(); + } else { + pollStatus(cb); + } + }) + .catch(() => pollStatus(cb)); + }, POLLING_INTERVAL); +} + +function promiseStatus(): Promise<any> { + return new Promise(resolve => pollStatus(resolve)); +} + +export function restartAndWait(): Promise<any> { + return restart().then(promiseStatus); +} |