-
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.
[ML] Transforms: Adds
_schedule_now
action to transform list. (#153545
) - Adds `_schedule_now` action to transform list. - Fixes bulk actions to be correctly disabled when not available.
- Loading branch information
Showing
24 changed files
with
604 additions
and
16 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
x-pack/plugins/transform/common/api_schemas/schedule_now_transforms.ts
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 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { TypeOf } from '@kbn/config-schema'; | ||
|
||
import { transformIdsSchema, CommonResponseStatusSchema } from './common'; | ||
|
||
export const scheduleNowTransformsRequestSchema = transformIdsSchema; | ||
export type ScheduleNowTransformsRequestSchema = TypeOf<typeof scheduleNowTransformsRequestSchema>; | ||
export type ScheduleNowTransformsResponseSchema = CommonResponseStatusSchema; |
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
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
84 changes: 84 additions & 0 deletions
84
x-pack/plugins/transform/public/app/hooks/use_schedule_now_transform.tsx
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,84 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import React from 'react'; | ||
|
||
import { i18n } from '@kbn/i18n'; | ||
|
||
import { toMountPoint } from '@kbn/kibana-react-plugin/public'; | ||
|
||
import type { ScheduleNowTransformsRequestSchema } from '../../../common/api_schemas/schedule_now_transforms'; | ||
import { isScheduleNowTransformsResponseSchema } from '../../../common/api_schemas/type_guards'; | ||
|
||
import { getErrorMessage } from '../../../common/utils/errors'; | ||
|
||
import { useAppDependencies, useToastNotifications } from '../app_dependencies'; | ||
import { refreshTransformList$, REFRESH_TRANSFORM_LIST_STATE } from '../common'; | ||
import { ToastNotificationText } from '../components'; | ||
|
||
import { useApi } from './use_api'; | ||
|
||
export const useScheduleNowTransforms = () => { | ||
const { overlays, theme } = useAppDependencies(); | ||
const toastNotifications = useToastNotifications(); | ||
const api = useApi(); | ||
|
||
return async (transformsInfo: ScheduleNowTransformsRequestSchema) => { | ||
const results = await api.scheduleNowTransforms(transformsInfo); | ||
|
||
if (!isScheduleNowTransformsResponseSchema(results)) { | ||
toastNotifications.addDanger({ | ||
title: i18n.translate( | ||
'xpack.transform.stepCreateForm.scheduleNowTransformResponseSchemaErrorMessage', | ||
{ | ||
defaultMessage: | ||
'An error occurred calling the request to schedule the transform to process data instantly.', | ||
} | ||
), | ||
text: toMountPoint( | ||
<ToastNotificationText | ||
overlays={overlays} | ||
theme={theme} | ||
text={getErrorMessage(results)} | ||
/>, | ||
{ theme$: theme.theme$ } | ||
), | ||
}); | ||
return; | ||
} | ||
|
||
for (const transformId in results) { | ||
// hasOwnProperty check to ensure only properties on object itself, and not its prototypes | ||
if (results.hasOwnProperty(transformId)) { | ||
const result = results[transformId]; | ||
if (result.success === true) { | ||
toastNotifications.addSuccess( | ||
i18n.translate('xpack.transform.transformList.scheduleNowTransformSuccessMessage', { | ||
defaultMessage: | ||
'Request to schedule transform {transformId} to process data instantly acknowledged.', | ||
values: { transformId }, | ||
}) | ||
); | ||
} else { | ||
toastNotifications.addError(new Error(JSON.stringify(result.error!.caused_by, null, 2)), { | ||
title: i18n.translate( | ||
'xpack.transform.transformList.scheduleNowTransformErrorMessage', | ||
{ | ||
defaultMessage: | ||
'An error occurred scheduling transform {transformId} to process data instantly.', | ||
values: { transformId }, | ||
} | ||
), | ||
toastMessage: result.error!.reason, | ||
}); | ||
} | ||
} | ||
} | ||
|
||
refreshTransformList$.next(REFRESH_TRANSFORM_LIST_STATE.REFRESH); | ||
}; | ||
}; |
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
9 changes: 9 additions & 0 deletions
9
...ransform/public/app/sections/transform_management/components/action_schedule_now/index.ts
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,9 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
export { useScheduleNowAction } from './use_schedule_now_action'; | ||
export { isScheduleNowActionDisabled, ScheduleNowActionName } from './schedule_now_action_name'; |
102 changes: 102 additions & 0 deletions
102
...sections/transform_management/components/action_schedule_now/schedule_now_action_name.tsx
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,102 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import React, { FC, useContext } from 'react'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { EuiToolTip } from '@elastic/eui'; | ||
|
||
import { | ||
createCapabilityFailureMessage, | ||
AuthorizationContext, | ||
} from '../../../../lib/authorization'; | ||
import { TransformListRow, isCompletedBatchTransform } from '../../../../common'; | ||
|
||
export const scheduleNowActionNameText = i18n.translate( | ||
'xpack.transform.transformList.scheduleNowActionNameText', | ||
{ | ||
defaultMessage: 'Schedule now', | ||
} | ||
); | ||
|
||
export const isScheduleNowActionDisabled = ( | ||
items: TransformListRow[], | ||
canScheduleNowTransform: boolean, | ||
transformNodes: number | ||
) => { | ||
// Disable schedule-now for batch transforms which have completed. | ||
const completedBatchTransform = items.some((i: TransformListRow) => isCompletedBatchTransform(i)); | ||
|
||
return ( | ||
!canScheduleNowTransform || | ||
completedBatchTransform || | ||
items.length === 0 || | ||
transformNodes === 0 | ||
); | ||
}; | ||
|
||
export interface ScheduleNowActionNameProps { | ||
items: TransformListRow[]; | ||
forceDisable?: boolean; | ||
transformNodes: number; | ||
} | ||
export const ScheduleNowActionName: FC<ScheduleNowActionNameProps> = ({ | ||
items, | ||
forceDisable, | ||
transformNodes, | ||
}) => { | ||
const { canScheduleNowTransform } = useContext(AuthorizationContext).capabilities; | ||
const isBulkAction = items.length > 1; | ||
|
||
// Disable schedule-now for batch transforms which have completed. | ||
const completedBatchTransform = items.some((i: TransformListRow) => isCompletedBatchTransform(i)); | ||
|
||
let completedBatchTransformMessage; | ||
|
||
if (isBulkAction === true) { | ||
completedBatchTransformMessage = i18n.translate( | ||
'xpack.transform.transformList.cannotScheduleNowCompleteBatchTransformBulkActionToolTip', | ||
{ | ||
defaultMessage: | ||
'One or more transforms are completed batch transforms and cannot be scheduled to process data instantly.', | ||
} | ||
); | ||
} else { | ||
completedBatchTransformMessage = i18n.translate( | ||
'xpack.transform.transformList.cannotScheduleNowCompleteBatchTransformToolTip', | ||
{ | ||
defaultMessage: | ||
'{transformId} is a completed batch transform and cannot be scheduled to process data instantly.', | ||
values: { transformId: items[0] && items[0].config.id }, | ||
} | ||
); | ||
} | ||
|
||
const actionIsDisabled = isScheduleNowActionDisabled( | ||
items, | ||
canScheduleNowTransform, | ||
transformNodes | ||
); | ||
|
||
let content: string = i18n.translate('xpack.transform.transformList.scheduleNowToolTip', { | ||
defaultMessage: | ||
'Schedule the transform to instantly process data without waiting for the configured interval between checks for changes in the source indices.', | ||
}); | ||
|
||
if (actionIsDisabled && items.length > 0) { | ||
if (!canScheduleNowTransform) { | ||
content = createCapabilityFailureMessage('canScheduleNowTransform'); | ||
} else if (completedBatchTransform) { | ||
content = completedBatchTransformMessage; | ||
} | ||
} | ||
|
||
return ( | ||
<EuiToolTip position="top" content={content}> | ||
<>{scheduleNowActionNameText}</> | ||
</EuiToolTip> | ||
); | ||
}; |
53 changes: 53 additions & 0 deletions
53
.../sections/transform_management/components/action_schedule_now/use_schedule_now_action.tsx
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,53 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import React, { useContext, useMemo } from 'react'; | ||
|
||
import { TRANSFORM_STATE } from '../../../../../../common/constants'; | ||
|
||
import { AuthorizationContext } from '../../../../lib/authorization'; | ||
import { TransformListAction, TransformListRow } from '../../../../common'; | ||
import { useScheduleNowTransforms } from '../../../../hooks'; | ||
|
||
import { | ||
isScheduleNowActionDisabled, | ||
scheduleNowActionNameText, | ||
ScheduleNowActionName, | ||
} from './schedule_now_action_name'; | ||
|
||
export type ScheduleNowAction = ReturnType<typeof useScheduleNowAction>; | ||
export const useScheduleNowAction = (forceDisable: boolean, transformNodes: number) => { | ||
const { canScheduleNowTransform } = useContext(AuthorizationContext).capabilities; | ||
|
||
const scheduleNowTransforms = useScheduleNowTransforms(); | ||
|
||
const action: TransformListAction = useMemo( | ||
() => ({ | ||
name: (item: TransformListRow) => ( | ||
<ScheduleNowActionName | ||
items={[item]} | ||
forceDisable={forceDisable} | ||
transformNodes={transformNodes} | ||
/> | ||
), | ||
available: (item: TransformListRow) => item.stats.state === TRANSFORM_STATE.STARTED, | ||
enabled: (item: TransformListRow) => | ||
!isScheduleNowActionDisabled([item], canScheduleNowTransform, transformNodes), | ||
description: scheduleNowActionNameText, | ||
icon: 'play', | ||
type: 'icon', | ||
onClick: (item: TransformListRow) => scheduleNowTransforms([{ id: item.id }]), | ||
'data-test-subj': 'transformActionScheduleNow', | ||
}), | ||
[canScheduleNowTransform, forceDisable, scheduleNowTransforms, transformNodes] | ||
); | ||
|
||
return { | ||
action, | ||
scheduleNowTransforms, | ||
}; | ||
}; |
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
Oops, something went wrong.