Skip to content
This repository has been archived by the owner on Mar 13, 2024. It is now read-only.

Commit

Permalink
Add action to get cluster status (#132)
Browse files Browse the repository at this point in the history
  • Loading branch information
jwilander authored and hmhealey committed Aug 28, 2020
1 parent b57f1ad commit 1d3475d
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 3 deletions.
7 changes: 6 additions & 1 deletion packages/mattermost-redux/src/action_types/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
});

9 changes: 9 additions & 0 deletions packages/mattermost-redux/src/actions/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}
7 changes: 7 additions & 0 deletions packages/mattermost-redux/src/client/client4.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
18 changes: 17 additions & 1 deletion packages/mattermost-redux/src/reducers/entities/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

});

13 changes: 12 additions & 1 deletion packages/mattermost-redux/src/reducers/requests/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -127,6 +137,7 @@ export default combineReducers({
recycleDatabase,
createCompliance,
getCompliance,
uploadBrandImage
uploadBrandImage,
getClusterStatus
});

3 changes: 3 additions & 0 deletions packages/mattermost-redux/src/selectors/entities/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ export function getComplianceReports(state) {
return state.entities.admin.complianceReports;
}

export function getClusterInfo(state) {
return state.entities.admin.clusterInfo;
}
24 changes: 24 additions & 0 deletions packages/mattermost-redux/test/actions/admin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});

0 comments on commit 1d3475d

Please sign in to comment.