-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* [ML] Adding jobs stats bar to top of jobs list * unsetting update function * changing node variable name * small refactor * using props copy of `updateJobStats` * adding proptypes * adding fixed height
- Loading branch information
1 parent
b61d509
commit 42f2518
Showing
8 changed files
with
231 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
x-pack/plugins/ml/public/jobs/jobs_list_new/components/jobs_stats_bar/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
|
||
export { JobStatsBar } from './jobs_stats_bar'; |
121 changes: 121 additions & 0 deletions
121
x-pack/plugins/ml/public/jobs/jobs_list_new/components/jobs_stats_bar/jobs_stats_bar.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
|
||
import './styles/main.less'; | ||
import { JOB_STATE, DATAFEED_STATE } from 'plugins/ml/../common/constants/states'; | ||
|
||
import PropTypes from 'prop-types'; | ||
import React, { | ||
Component, | ||
} from 'react'; | ||
|
||
function createJobStats(jobsSummaryList) { | ||
|
||
const jobStats = { | ||
activeNodes: { label: 'Active ML Nodes', value: 0, show: true }, | ||
total: { label: 'Total jobs', value: 0, show: true }, | ||
open: { label: 'Open jobs', value: 0, show: true }, | ||
closed: { label: 'Closed jobs', value: 0, show: true }, | ||
failed: { label: 'Failed jobs', value: 0, show: false }, | ||
activeDatafeeds: { label: 'Active datafeeds', value: 0, show: true } | ||
}; | ||
|
||
if (jobsSummaryList === undefined) { | ||
return jobStats; | ||
} | ||
|
||
// object to keep track of nodes being used by jobs | ||
const mlNodes = {}; | ||
let failedJobs = 0; | ||
|
||
jobsSummaryList.forEach((job) => { | ||
if (job.jobState === JOB_STATE.OPENED) { | ||
jobStats.open.value++; | ||
} else if (job.jobState === JOB_STATE.CLOSED) { | ||
jobStats.closed.value++; | ||
} else if (job.jobState === JOB_STATE.FAILED) { | ||
failedJobs++; | ||
} | ||
|
||
if (job.hasDatafeed && job.datafeedState === DATAFEED_STATE.STARTED) { | ||
jobStats.activeDatafeeds.value++; | ||
} | ||
|
||
if (job.nodeName !== undefined) { | ||
mlNodes[job.nodeName] = {}; | ||
} | ||
}); | ||
|
||
jobStats.total.value = jobsSummaryList.length; | ||
|
||
// // Only show failed jobs if it is non-zero | ||
if (failedJobs) { | ||
jobStats.failed.value = failedJobs; | ||
jobStats.failed.show = true; | ||
} else { | ||
jobStats.failed.show = false; | ||
} | ||
|
||
jobStats.activeNodes.value = Object.keys(mlNodes).length; | ||
|
||
return jobStats; | ||
} | ||
|
||
function Stat({ stat }) { | ||
return ( | ||
<span className="stat"> | ||
<span className="stat-label">{stat.label}</span>: <span className="stat-value">{stat.value}</span> | ||
</span> | ||
); | ||
} | ||
Stat.propTypes = { | ||
stat: PropTypes.object.isRequired, | ||
}; | ||
|
||
export class JobStatsBar extends Component { | ||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
jobsSummaryList: [], | ||
jobStats: {}, | ||
}; | ||
} | ||
|
||
updateJobStats = (jobsSummaryList) => { | ||
const jobStats = createJobStats(jobsSummaryList); | ||
this.setState({ | ||
jobsSummaryList, | ||
jobStats, | ||
}); | ||
}; | ||
|
||
componentDidMount() { | ||
this.props.setUpdateJobStats(this.updateJobStats); | ||
} | ||
|
||
componentWillUnmount() { | ||
this.props.unsetUpdateJobStats(); | ||
} | ||
|
||
render() { | ||
const { jobStats } = this.state; | ||
const stats = Object.keys(jobStats).map(k => jobStats[k]); | ||
|
||
return ( | ||
<div className="jobs-stats-bar-new"> | ||
{ | ||
stats.filter(s => (s.show)).map(s => <Stat key={s.label} stat={s} />) | ||
} | ||
</div> | ||
); | ||
} | ||
} | ||
JobStatsBar.propTypes = { | ||
setUpdateJobStats: PropTypes.func.isRequired, | ||
unsetUpdateJobStats: PropTypes.func.isRequired, | ||
}; | ||
|
14 changes: 14 additions & 0 deletions
14
x-pack/plugins/ml/public/jobs/jobs_list_new/components/jobs_stats_bar/styles/main.less
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
.jobs-stats-bar-new { | ||
|
||
height: 42px; | ||
padding: 14px; | ||
background-color: #EFF0F1; | ||
|
||
.stat { | ||
margin-right: 10px; | ||
.stat-label {} | ||
.stat-value { | ||
font-weight: bold | ||
} | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
x-pack/plugins/ml/public/jobs/jobs_list_new/components/node_available_warning/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
|
||
export { NodeAvailableWarning } from './node_available_warning'; |
44 changes: 44 additions & 0 deletions
44
.../ml/public/jobs/jobs_list_new/components/node_available_warning/node_available_warning.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
|
||
import { mlNodesAvailable, permissionToViewMlNodeCount } from 'plugins/ml/ml_nodes_check/check_ml_nodes'; | ||
|
||
import React from 'react'; | ||
|
||
import { | ||
EuiCallOut, | ||
EuiLink, | ||
EuiSpacer, | ||
} from '@elastic/eui'; | ||
|
||
export function NodeAvailableWarning() { | ||
const isCloud = false; // placeholder for future specific cloud functionality | ||
if ((mlNodesAvailable() === true) || (permissionToViewMlNodeCount() === false)) { | ||
return (<span />); | ||
} else { | ||
return ( | ||
<React.Fragment> | ||
<EuiCallOut | ||
title="No ML nodes available" | ||
color="warning" | ||
iconType="alert" | ||
> | ||
<p> | ||
There are no ML nodes available.<br /> | ||
You will not be able to create or run jobs. | ||
{isCloud && | ||
<span ng-if="isCloud"> | ||
This can be configured in Cloud <EuiLink href="#">here</EuiLink>. | ||
</span> | ||
} | ||
</p> | ||
</EuiCallOut> | ||
<EuiSpacer size="m" /> | ||
</React.Fragment> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters