Add supervisor card in home view (#7551)

* Add supervisor card in home view

* hide the text under conditions
This commit is contained in:
Qi Shu 2019-04-29 10:15:10 -07:00 committed by Fangjin Yang
parent ce7298b51e
commit 20755f4ca0
1 changed files with 48 additions and 0 deletions

View File

@ -51,6 +51,11 @@ export interface HomeViewState {
segmentCount: number; segmentCount: number;
segmentCountError: string | null; segmentCountError: string | null;
supervisorCountLoading: boolean;
runningSupervisorCount: number;
suspendedSupervisorCount: number;
supervisorCountError: string | null;
taskCountLoading: boolean; taskCountLoading: boolean;
runningTaskCount: number; runningTaskCount: number;
pendingTaskCount: number; pendingTaskCount: number;
@ -72,6 +77,7 @@ export class HomeView extends React.Component<HomeViewProps, HomeViewState> {
private statusQueryManager: QueryManager<string, any>; private statusQueryManager: QueryManager<string, any>;
private datasourceQueryManager: QueryManager<string, any>; private datasourceQueryManager: QueryManager<string, any>;
private segmentQueryManager: QueryManager<string, any>; private segmentQueryManager: QueryManager<string, any>;
private supervisorQueryManager: QueryManager<string, any>;
private taskQueryManager: QueryManager<string, any>; private taskQueryManager: QueryManager<string, any>;
private dataServerQueryManager: QueryManager<string, any>; private dataServerQueryManager: QueryManager<string, any>;
private middleManagerQueryManager: QueryManager<string, any>; private middleManagerQueryManager: QueryManager<string, any>;
@ -91,6 +97,11 @@ export class HomeView extends React.Component<HomeViewProps, HomeViewState> {
segmentCount: 0, segmentCount: 0,
segmentCountError: null, segmentCountError: null,
supervisorCountLoading: false,
runningSupervisorCount: 0,
suspendedSupervisorCount: 0,
supervisorCountError: null,
taskCountLoading: false, taskCountLoading: false,
runningTaskCount: 0, runningTaskCount: 0,
pendingTaskCount: 0, pendingTaskCount: 0,
@ -188,6 +199,30 @@ export class HomeView extends React.Component<HomeViewProps, HomeViewState> {
this.segmentQueryManager.runQuery(`SELECT COUNT(*) as "count" FROM sys.segments`); this.segmentQueryManager.runQuery(`SELECT COUNT(*) as "count" FROM sys.segments`);
// -------------------------
this.supervisorQueryManager = new QueryManager({
processQuery: async (query: string) => {
const resp = await axios.get('/druid/indexer/v1/supervisor?full');
const data = resp.data;
const runningSupervisorCount = data.filter((d: any) => d.spec.suspended === false).length;
const suspendedSupervisorCount = data.filter((d: any) => d.spec.suspended === true).length;
return {
runningSupervisorCount,
suspendedSupervisorCount
};
},
onStateChange: ({result, loading, error}) => {
this.setState({
runningSupervisorCount: result ? result.runningSupervisorCount : 0,
suspendedSupervisorCount: result ? result.suspendedSupervisorCount : 0,
supervisorCountLoading: loading,
supervisorCountError: error
});
}
});
this.supervisorQueryManager.runQuery('dummy');
// ------------------------- // -------------------------
this.taskQueryManager = new QueryManager({ this.taskQueryManager = new QueryManager({
@ -332,6 +367,19 @@ GROUP BY 1`);
error: state.datasourceCountError error: state.datasourceCountError
})} })}
{this.renderCard({
href: '#tasks',
icon: IconNames.LIST_COLUMNS,
title: 'Supervisors',
loading: state.supervisorCountLoading,
content: <>
{!Boolean(state.runningSupervisorCount + state.suspendedSupervisorCount) && <p>0 supervisors</p>}
{Boolean(state.runningSupervisorCount) && <p>{pluralIfNeeded(state.runningSupervisorCount, 'running supervisor')}</p>}
{Boolean(state.suspendedSupervisorCount) && <p>{pluralIfNeeded(state.suspendedSupervisorCount, 'suspended supervisor')}</p>}
</>,
error: state.supervisorCountError
})}
{this.renderCard({ {this.renderCard({
href: '#tasks', href: '#tasks',
icon: IconNames.GANTT_CHART, icon: IconNames.GANTT_CHART,