Skip to content

Commit

Permalink
[ML] Disabling datafeed editing when job is running (#60751)
Browse files Browse the repository at this point in the history
* [ML] Disabling datafeed editing when job is running

* changing variable

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
  • Loading branch information
jgowdyelastic and elasticmachine authored Mar 23, 2020
1 parent 91e8e3e commit de7151e
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { withKibana } from '../../../../../../../../../src/plugins/kibana_react/
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';
import { collapseLiteralStrings } from '../../../../../../shared_imports';
import { DATAFEED_STATE } from '../../../../../../common/constants/states';

export class EditJobFlyoutUI extends Component {
_initialJobFormState = null;
Expand All @@ -41,6 +42,7 @@ export class EditJobFlyoutUI extends Component {
this.state = {
job: {},
hasDatafeed: false,
datafeedRunning: false,
isFlyoutVisible: false,
isConfirmationModalVisible: false,
jobDescription: '',
Expand Down Expand Up @@ -157,10 +159,12 @@ export class EditJobFlyoutUI extends Component {

extractJob(job, hasDatafeed) {
this.extractInitialJobFormState(job, hasDatafeed);
const datafeedRunning = hasDatafeed && job.datafeed_config.state !== DATAFEED_STATE.STOPPED;

this.setState({
job,
hasDatafeed,
datafeedRunning,
jobModelMemoryLimitValidationError: '',
jobGroupsValidationError: '',
...cloneDeep(this._initialJobFormState),
Expand Down Expand Up @@ -283,6 +287,7 @@ export class EditJobFlyoutUI extends Component {
jobModelMemoryLimitValidationError,
isValidJobDetails,
isValidJobCustomUrls,
datafeedRunning,
} = this.state;

const tabs = [
Expand All @@ -293,6 +298,7 @@ export class EditJobFlyoutUI extends Component {
}),
content: (
<JobDetails
datafeedRunning={datafeedRunning}
jobDescription={jobDescription}
jobGroups={jobGroups}
jobModelMemoryLimit={jobModelMemoryLimit}
Expand Down Expand Up @@ -328,6 +334,7 @@ export class EditJobFlyoutUI extends Component {
datafeedScrollSize={datafeedScrollSize}
jobBucketSpan={jobBucketSpan}
setDatafeed={this.setDatafeed}
datafeedRunning={datafeedRunning}
/>
),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@
import PropTypes from 'prop-types';
import React, { Component } from 'react';

import { EuiFieldText, EuiForm, EuiFormRow, EuiSpacer, EuiFieldNumber } from '@elastic/eui';
import {
EuiFieldText,
EuiForm,
EuiFormRow,
EuiSpacer,
EuiFieldNumber,
EuiCallOut,
} from '@elastic/eui';

import { calculateDatafeedFrequencyDefaultSeconds } from '../../../../../../../common/util/job_utils';
import { getNewJobDefaults } from '../../../../../services/ml_server_info';
Expand Down Expand Up @@ -72,9 +79,21 @@ export class Datafeed extends Component {

render() {
const { query, queryDelay, frequency, scrollSize, defaults } = this.state;
const { datafeedRunning } = this.props;
return (
<React.Fragment>
<EuiSpacer size="m" />
{datafeedRunning && (
<>
<EuiCallOut color="warning">
<FormattedMessage
id="xpack.ml.jobsList.editJobFlyout.datafeed.readOnlyCalloutText"
defaultMessage="Datafeed settings cannot be edited while the datafeed is running. Please stop the job if you wish to edit these settings."
/>
</EuiCallOut>
<EuiSpacer size="l" />
</>
)}
<EuiForm>
<EuiFormRow
label={
Expand All @@ -90,6 +109,7 @@ export class Datafeed extends Component {
value={query}
onChange={this.onQueryChange}
height="200px"
readOnly={datafeedRunning}
/>
</EuiFormRow>
<EuiFormRow
Expand All @@ -104,6 +124,7 @@ export class Datafeed extends Component {
value={queryDelay}
placeholder={defaults.queryDelay}
onChange={this.onQueryDelayChange}
disabled={datafeedRunning}
/>
</EuiFormRow>
<EuiFormRow
Expand All @@ -118,6 +139,7 @@ export class Datafeed extends Component {
value={frequency}
placeholder={defaults.frequency}
onChange={this.onFrequencyChange}
disabled={datafeedRunning}
/>
</EuiFormRow>
<EuiFormRow
Expand All @@ -132,6 +154,7 @@ export class Datafeed extends Component {
value={scrollSize}
placeholder={defaults.scrollSize}
onChange={this.onScrollSizeChange}
disabled={datafeedRunning}
/>
</EuiFormRow>
</EuiForm>
Expand All @@ -140,6 +163,7 @@ export class Datafeed extends Component {
}
}
Datafeed.propTypes = {
datafeedRunning: PropTypes.bool.isRequired,
datafeedQuery: PropTypes.string.isRequired,
datafeedQueryDelay: PropTypes.string.isRequired,
datafeedFrequency: PropTypes.string.isRequired,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ export class JobDetails extends Component {
mmlValidationError,
groupsValidationError,
} = this.state;
const { datafeedRunning } = this.props;
return (
<React.Fragment>
<EuiSpacer size="m" />
Expand Down Expand Up @@ -152,6 +153,14 @@ export class JobDetails extends Component {
defaultMessage="Model memory limit"
/>
}
helpText={
datafeedRunning ? (
<FormattedMessage
id="xpack.ml.jobsList.editJobFlyout.jobDetails.modelMemoryLimitLabelHelp"
defaultMessage="Model memory limit cannot be edited while the datafeed is running."
/>
) : null
}
isInvalid={mmlValidationError !== ''}
error={mmlValidationError}
>
Expand All @@ -160,6 +169,7 @@ export class JobDetails extends Component {
onChange={this.onMmlChange}
isInvalid={mmlValidationError !== ''}
error={mmlValidationError}
disabled={datafeedRunning}
/>
</EuiFormRow>
</EuiForm>
Expand All @@ -168,6 +178,7 @@ export class JobDetails extends Component {
}
}
JobDetails.propTypes = {
datafeedRunning: PropTypes.bool.isRequired,
jobDescription: PropTypes.string.isRequired,
jobGroups: PropTypes.array.isRequired,
jobModelMemoryLimit: PropTypes.string.isRequired,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const datafeedConfigSchema = schema.object({
})
),
frequency: schema.maybe(schema.string()),
indices: schema.arrayOf(schema.string()),
indices: schema.maybe(schema.arrayOf(schema.string())),
indexes: schema.maybe(schema.arrayOf(schema.string())),
job_id: schema.maybe(schema.string()),
query: schema.maybe(schema.any()),
Expand Down

0 comments on commit de7151e

Please sign in to comment.