From 20755f4ca03f36a4211455153a6c38d62b64419b Mon Sep 17 00:00:00 2001 From: Qi Shu Date: Mon, 29 Apr 2019 10:15:10 -0700 Subject: [PATCH] Add supervisor card in home view (#7551) * Add supervisor card in home view * hide the text under conditions --- web-console/src/views/home-view.tsx | 48 +++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/web-console/src/views/home-view.tsx b/web-console/src/views/home-view.tsx index 33eb6e3c522..5e2f3693565 100644 --- a/web-console/src/views/home-view.tsx +++ b/web-console/src/views/home-view.tsx @@ -51,6 +51,11 @@ export interface HomeViewState { segmentCount: number; segmentCountError: string | null; + supervisorCountLoading: boolean; + runningSupervisorCount: number; + suspendedSupervisorCount: number; + supervisorCountError: string | null; + taskCountLoading: boolean; runningTaskCount: number; pendingTaskCount: number; @@ -72,6 +77,7 @@ export class HomeView extends React.Component { private statusQueryManager: QueryManager; private datasourceQueryManager: QueryManager; private segmentQueryManager: QueryManager; + private supervisorQueryManager: QueryManager; private taskQueryManager: QueryManager; private dataServerQueryManager: QueryManager; private middleManagerQueryManager: QueryManager; @@ -91,6 +97,11 @@ export class HomeView extends React.Component { segmentCount: 0, segmentCountError: null, + supervisorCountLoading: false, + runningSupervisorCount: 0, + suspendedSupervisorCount: 0, + supervisorCountError: null, + taskCountLoading: false, runningTaskCount: 0, pendingTaskCount: 0, @@ -188,6 +199,30 @@ export class HomeView extends React.Component { 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({ @@ -332,6 +367,19 @@ GROUP BY 1`); error: state.datasourceCountError })} + {this.renderCard({ + href: '#tasks', + icon: IconNames.LIST_COLUMNS, + title: 'Supervisors', + loading: state.supervisorCountLoading, + content: <> + {!Boolean(state.runningSupervisorCount + state.suspendedSupervisorCount) &&

0 supervisors

} + {Boolean(state.runningSupervisorCount) &&

{pluralIfNeeded(state.runningSupervisorCount, 'running supervisor')}

} + {Boolean(state.suspendedSupervisorCount) &&

{pluralIfNeeded(state.suspendedSupervisorCount, 'suspended supervisor')}

} + , + error: state.supervisorCountError + })} + {this.renderCard({ href: '#tasks', icon: IconNames.GANTT_CHART,