From 1d3475d3cfc61ab3779adcb9bb8db40abee44a33 Mon Sep 17 00:00:00 2001 From: Joram Wilander Date: Sun, 4 Jun 2017 11:44:28 -0400 Subject: [PATCH] Add action to get cluster status (#132) --- .../src/action_types/admin.js | 7 +++++- .../mattermost-redux/src/actions/admin.js | 9 +++++++ .../mattermost-redux/src/client/client4.js | 7 ++++++ .../src/reducers/entities/admin.js | 18 +++++++++++++- .../src/reducers/requests/admin.js | 13 +++++++++- .../src/selectors/entities/admin.js | 3 +++ .../test/actions/admin.test.js | 24 +++++++++++++++++++ 7 files changed, 78 insertions(+), 3 deletions(-) diff --git a/packages/mattermost-redux/src/action_types/admin.js b/packages/mattermost-redux/src/action_types/admin.js index 0b9b83c569ef..b2e645812dc1 100644 --- a/packages/mattermost-redux/src/action_types/admin.js +++ b/packages/mattermost-redux/src/action_types/admin.js @@ -48,10 +48,15 @@ export default keyMirror({ UPLOAD_BRAND_IMAGE_SUCCESS: null, UPLOAD_BRAND_IMAGE_FAILURE: null, + GET_CLUSTER_STATUS_REQUEST: null, + GET_CLUSTER_STATUS_SUCCESS: null, + GET_CLUSTER_STATUS_FAILURE: null, + RECEIVED_LOGS: null, RECEIVED_AUDITS: null, RECEIVED_CONFIG: null, RECEIVED_COMPLIANCE_REPORT: null, - RECEIVED_COMPLIANCE_REPORTS: null + RECEIVED_COMPLIANCE_REPORTS: null, + RECEIVED_CLUSTER_STATUS: null }); diff --git a/packages/mattermost-redux/src/actions/admin.js b/packages/mattermost-redux/src/actions/admin.js index 020d690e8e0e..625cf716070d 100644 --- a/packages/mattermost-redux/src/actions/admin.js +++ b/packages/mattermost-redux/src/actions/admin.js @@ -126,3 +126,12 @@ export function uploadBrandImage(imageData) { imageData ); } + +export function getClusterStatus() { + return bindClientFunc( + Client4.getClusterStatus, + AdminTypes.GET_CLUSTER_STATUS_REQUEST, + [AdminTypes.RECEIVED_CLUSTER_STATUS, AdminTypes.GET_CLUSTER_STATUS_SUCCESS], + AdminTypes.GET_CLUSTER_STATUS_FAILURE + ); +} diff --git a/packages/mattermost-redux/src/client/client4.js b/packages/mattermost-redux/src/client/client4.js index 6a0209997831..026ce10123df 100644 --- a/packages/mattermost-redux/src/client/client4.js +++ b/packages/mattermost-redux/src/client/client4.js @@ -1142,6 +1142,13 @@ export default class Client4 { ); }; + getClusterStatus = async () => { + return this.doFetch( + `${this.getBaseRoute()}/cluster/status`, + {method: 'get'} + ); + }; + // Client Helpers doFetch = async (url, options) => { diff --git a/packages/mattermost-redux/src/reducers/entities/admin.js b/packages/mattermost-redux/src/reducers/entities/admin.js index e5255d64711f..8678cdb1e8c8 100644 --- a/packages/mattermost-redux/src/reducers/entities/admin.js +++ b/packages/mattermost-redux/src/reducers/entities/admin.js @@ -70,6 +70,19 @@ function complianceReports(state = {}, action) { } } +function clusterInfo(state = [], action) { + switch (action.type) { + case AdminTypes.RECEIVED_CLUSTER_STATUS: { + return action.data; + } + case UserTypes.LOGOUT_SUCCESS: + return []; + + default: + return state; + } +} + export default combineReducers({ // array of strings each representing a log entry @@ -82,7 +95,10 @@ export default combineReducers({ config, // object where every key is a report id and has an object with report details - complianceReports + complianceReports, + + // array of cluster status data + clusterInfo }); diff --git a/packages/mattermost-redux/src/reducers/requests/admin.js b/packages/mattermost-redux/src/reducers/requests/admin.js index 4c11a96aca0f..947a9899faf2 100644 --- a/packages/mattermost-redux/src/reducers/requests/admin.js +++ b/packages/mattermost-redux/src/reducers/requests/admin.js @@ -116,6 +116,16 @@ function uploadBrandImage(state = initialRequestState(), action) { ); } +function getClusterStatus(state = initialRequestState(), action) { + return handleRequest( + AdminTypes.GET_CLUSTER_STATUS_REQUEST, + AdminTypes.GET_CLUSTER_STATUS_SUCCESS, + AdminTypes.GET_CLUSTER_STATUS_FAILURE, + state, + action + ); +} + export default combineReducers({ getLogs, getAudits, @@ -127,6 +137,7 @@ export default combineReducers({ recycleDatabase, createCompliance, getCompliance, - uploadBrandImage + uploadBrandImage, + getClusterStatus }); diff --git a/packages/mattermost-redux/src/selectors/entities/admin.js b/packages/mattermost-redux/src/selectors/entities/admin.js index ec328a85b922..6e11fbce39e0 100644 --- a/packages/mattermost-redux/src/selectors/entities/admin.js +++ b/packages/mattermost-redux/src/selectors/entities/admin.js @@ -17,3 +17,6 @@ export function getComplianceReports(state) { return state.entities.admin.complianceReports; } +export function getClusterInfo(state) { + return state.entities.admin.clusterInfo; +} diff --git a/packages/mattermost-redux/test/actions/admin.test.js b/packages/mattermost-redux/test/actions/admin.test.js index 550661a99d35..b657c0a7772b 100644 --- a/packages/mattermost-redux/test/actions/admin.test.js +++ b/packages/mattermost-redux/test/actions/admin.test.js @@ -305,4 +305,28 @@ describe('Actions.Admin', () => { throw new Error('uploadBrandImage request failed'); } }); + + it('getClusterStatus', async () => { + nock(Client4.getBaseRoute()). + get('/cluster/status'). + reply(200, [ + { + id: 'someid', + version: 'someversion' + } + ]); + + await Actions.getClusterStatus()(store.dispatch, store.getState); + + const state = store.getState(); + const request = state.requests.admin.getClusterStatus; + if (request.status === RequestStatus.FAILURE) { + throw new Error('getClusterStatus request failed'); + } + + const clusterInfo = state.entities.admin.clusterInfo; + assert.ok(clusterInfo); + assert.ok(clusterInfo.length === 1); + assert.ok(clusterInfo[0].id === 'someid'); + }); });