diff --git a/x-pack/plugins/ml/common/types/saved_objects.ts b/x-pack/plugins/ml/common/types/saved_objects.ts index d6c9ad758e8c6..aa3220747e849 100644 --- a/x-pack/plugins/ml/common/types/saved_objects.ts +++ b/x-pack/plugins/ml/common/types/saved_objects.ts @@ -11,7 +11,7 @@ export interface SavedObjectResult { [jobId: string]: { success: boolean; error?: any }; } -export interface RepairSavedObjectResponse { +export interface SyncSavedObjectResponse { savedObjectsCreated: SavedObjectResult; savedObjectsDeleted: SavedObjectResult; datafeedsAdded: SavedObjectResult; diff --git a/x-pack/plugins/ml/public/application/components/job_spaces_repair/index.ts b/x-pack/plugins/ml/public/application/components/job_spaces_sync/index.ts similarity index 78% rename from x-pack/plugins/ml/public/application/components/job_spaces_repair/index.ts rename to x-pack/plugins/ml/public/application/components/job_spaces_sync/index.ts index 3a9c22c1f3688..314071d5be1d8 100644 --- a/x-pack/plugins/ml/public/application/components/job_spaces_repair/index.ts +++ b/x-pack/plugins/ml/public/application/components/job_spaces_sync/index.ts @@ -4,4 +4,4 @@ * you may not use this file except in compliance with the Elastic License. */ -export { JobSpacesRepairFlyout } from './job_spaces_repair_flyout'; +export { JobSpacesSyncFlyout } from './job_spaces_sync_flyout'; diff --git a/x-pack/plugins/ml/public/application/components/job_spaces_repair/job_spaces_repair_flyout.tsx b/x-pack/plugins/ml/public/application/components/job_spaces_sync/job_spaces_sync_flyout.tsx similarity index 59% rename from x-pack/plugins/ml/public/application/components/job_spaces_repair/job_spaces_repair_flyout.tsx rename to x-pack/plugins/ml/public/application/components/job_spaces_sync/job_spaces_sync_flyout.tsx index 47d3fe065dd66..db80d0aa330f8 100644 --- a/x-pack/plugins/ml/public/application/components/job_spaces_repair/job_spaces_repair_flyout.tsx +++ b/x-pack/plugins/ml/public/application/components/job_spaces_sync/job_spaces_sync_flyout.tsx @@ -23,34 +23,31 @@ import { } from '@elastic/eui'; import { ml } from '../../services/ml_api_service'; -import { - RepairSavedObjectResponse, - SavedObjectResult, -} from '../../../../common/types/saved_objects'; -import { RepairList } from './repair_list'; +import { SyncSavedObjectResponse, SavedObjectResult } from '../../../../common/types/saved_objects'; +import { SyncList } from './sync_list'; import { useToastNotificationService } from '../../services/toast_notification_service'; interface Props { onClose: () => void; } -export const JobSpacesRepairFlyout: FC = ({ onClose }) => { +export const JobSpacesSyncFlyout: FC = ({ onClose }) => { const { displayErrorToast, displaySuccessToast } = useToastNotificationService(); const [loading, setLoading] = useState(false); - const [repairable, setRepairable] = useState(false); - const [repairResp, setRepairResp] = useState(null); + const [canSync, setCanSync] = useState(false); + const [syncResp, setSyncResp] = useState(null); - async function loadRepairList(simulate: boolean = true) { + async function loadSyncList(simulate: boolean = true) { setLoading(true); try { - const resp = await ml.savedObjects.repairSavedObjects(simulate); - setRepairResp(resp); + const resp = await ml.savedObjects.syncSavedObjects(simulate); + setSyncResp(resp); const count = Object.values(resp).reduce((acc, cur) => acc + Object.keys(cur).length, 0); - setRepairable(count > 0); + setCanSync(count > 0); setLoading(false); return resp; } catch (error) { - // this shouldn't be hit as errors are returned per-repair task + // this shouldn't be hit as errors are returned per-sync task // as part of the response displayErrorToast(error); setLoading(false); @@ -59,32 +56,33 @@ export const JobSpacesRepairFlyout: FC = ({ onClose }) => { } useEffect(() => { - loadRepairList(); + loadSyncList(); }, []); - async function repair() { - if (repairable) { - // perform the repair - const resp = await loadRepairList(false); - // check simulate the repair again to check that all - // items have been repaired. - await loadRepairList(true); + async function sync() { + if (canSync) { + // perform the sync + const resp = await loadSyncList(false); + // check simulate the sync again to check that all + // items have been synchronized. + await loadSyncList(true); if (resp === null) { return; } const { successCount, errorCount } = getResponseCounts(resp); if (errorCount > 0) { - const title = i18n.translate('xpack.ml.management.repairSavedObjectsFlyout.repair.error', { - defaultMessage: 'Some jobs cannot be repaired.', + const title = i18n.translate('xpack.ml.management.syncSavedObjectsFlyout.sync.error', { + defaultMessage: 'Some jobs cannot be synchronized.', }); displayErrorToast(resp as any, title); return; } displaySuccessToast( - i18n.translate('xpack.ml.management.repairSavedObjectsFlyout.repair.success', { - defaultMessage: '{successCount} {successCount, plural, one {job} other {jobs}} repaired', + i18n.translate('xpack.ml.management.syncSavedObjectsFlyout.sync.success', { + defaultMessage: + '{successCount} {successCount, plural, one {job} other {jobs}} synchronized', values: { successCount }, }) ); @@ -98,8 +96,8 @@ export const JobSpacesRepairFlyout: FC = ({ onClose }) => {

@@ -108,33 +106,29 @@ export const JobSpacesRepairFlyout: FC = ({ onClose }) => { - + - + @@ -145,7 +139,7 @@ export const JobSpacesRepairFlyout: FC = ({ onClose }) => { ); }; -function getResponseCounts(resp: RepairSavedObjectResponse) { +function getResponseCounts(resp: SyncSavedObjectResponse) { let successCount = 0; let errorCount = 0; Object.values(resp).forEach((result: SavedObjectResult) => { diff --git a/x-pack/plugins/ml/public/application/components/job_spaces_repair/repair_list.tsx b/x-pack/plugins/ml/public/application/components/job_spaces_sync/sync_list.tsx similarity index 60% rename from x-pack/plugins/ml/public/application/components/job_spaces_repair/repair_list.tsx rename to x-pack/plugins/ml/public/application/components/job_spaces_sync/sync_list.tsx index 3eab255ba34e6..573842c2f35e7 100644 --- a/x-pack/plugins/ml/public/application/components/job_spaces_repair/repair_list.tsx +++ b/x-pack/plugins/ml/public/application/components/job_spaces_sync/sync_list.tsx @@ -9,38 +9,36 @@ import { FormattedMessage } from '@kbn/i18n/react'; import { EuiText, EuiTitle, EuiAccordion, EuiTextColor, EuiHorizontalRule } from '@elastic/eui'; -import { RepairSavedObjectResponse } from '../../../../common/types/saved_objects'; +import { SyncSavedObjectResponse } from '../../../../common/types/saved_objects'; -export const RepairList: FC<{ repairItems: RepairSavedObjectResponse | null }> = ({ - repairItems, -}) => { - if (repairItems === null) { +export const SyncList: FC<{ syncItems: SyncSavedObjectResponse | null }> = ({ syncItems }) => { + if (syncItems === null) { return null; } return ( <> - + - + - + - + ); }; -const SavedObjectsCreated: FC<{ repairItems: RepairSavedObjectResponse }> = ({ repairItems }) => { - const items = Object.keys(repairItems.savedObjectsCreated); +const SavedObjectsCreated: FC<{ syncItems: SyncSavedObjectResponse }> = ({ syncItems }) => { + const items = Object.keys(syncItems.savedObjectsCreated); const title = ( <> @@ -48,7 +46,7 @@ const SavedObjectsCreated: FC<{ repairItems: RepairSavedObjectResponse }> = ({ r

@@ -59,7 +57,7 @@ const SavedObjectsCreated: FC<{ repairItems: RepairSavedObjectResponse }> = ({ r

@@ -67,11 +65,11 @@ const SavedObjectsCreated: FC<{ repairItems: RepairSavedObjectResponse }> = ({ r ); - return ; + return ; }; -const SavedObjectsDeleted: FC<{ repairItems: RepairSavedObjectResponse }> = ({ repairItems }) => { - const items = Object.keys(repairItems.savedObjectsDeleted); +const SavedObjectsDeleted: FC<{ syncItems: SyncSavedObjectResponse }> = ({ syncItems }) => { + const items = Object.keys(syncItems.savedObjectsDeleted); const title = ( <> @@ -79,7 +77,7 @@ const SavedObjectsDeleted: FC<{ repairItems: RepairSavedObjectResponse }> = ({ r

@@ -90,7 +88,7 @@ const SavedObjectsDeleted: FC<{ repairItems: RepairSavedObjectResponse }> = ({ r

@@ -98,11 +96,11 @@ const SavedObjectsDeleted: FC<{ repairItems: RepairSavedObjectResponse }> = ({ r ); - return ; + return ; }; -const DatafeedsAdded: FC<{ repairItems: RepairSavedObjectResponse }> = ({ repairItems }) => { - const items = Object.keys(repairItems.datafeedsAdded); +const DatafeedsAdded: FC<{ syncItems: SyncSavedObjectResponse }> = ({ syncItems }) => { + const items = Object.keys(syncItems.datafeedsAdded); const title = ( <> @@ -110,7 +108,7 @@ const DatafeedsAdded: FC<{ repairItems: RepairSavedObjectResponse }> = ({ repair

@@ -121,7 +119,7 @@ const DatafeedsAdded: FC<{ repairItems: RepairSavedObjectResponse }> = ({ repair

@@ -129,11 +127,11 @@ const DatafeedsAdded: FC<{ repairItems: RepairSavedObjectResponse }> = ({ repair ); - return ; + return ; }; -const DatafeedsRemoved: FC<{ repairItems: RepairSavedObjectResponse }> = ({ repairItems }) => { - const items = Object.keys(repairItems.datafeedsRemoved); +const DatafeedsRemoved: FC<{ syncItems: SyncSavedObjectResponse }> = ({ syncItems }) => { + const items = Object.keys(syncItems.datafeedsRemoved); const title = ( <> @@ -141,7 +139,7 @@ const DatafeedsRemoved: FC<{ repairItems: RepairSavedObjectResponse }> = ({ repa

@@ -152,7 +150,7 @@ const DatafeedsRemoved: FC<{ repairItems: RepairSavedObjectResponse }> = ({ repa

@@ -160,23 +158,21 @@ const DatafeedsRemoved: FC<{ repairItems: RepairSavedObjectResponse }> = ({ repa ); - return ; + return ; }; -const RepairItem: FC<{ id: string; title: JSX.Element; items: string[] }> = ({ +const SyncItem: FC<{ id: string; title: JSX.Element; items: string[] }> = ({ id, title, items, }) => ( - {items.length && ( -

    - {items.map((item) => ( -
  • {item}
  • - ))} -
- )} +
    + {items.map((item) => ( +
  • {item}
  • + ))} +
); diff --git a/x-pack/plugins/ml/public/application/management/jobs_list/components/jobs_list_page/jobs_list_page.tsx b/x-pack/plugins/ml/public/application/management/jobs_list/components/jobs_list_page/jobs_list_page.tsx index 8ad18e2b821b6..18d45c02a3c95 100644 --- a/x-pack/plugins/ml/public/application/management/jobs_list/components/jobs_list_page/jobs_list_page.tsx +++ b/x-pack/plugins/ml/public/application/management/jobs_list/components/jobs_list_page/jobs_list_page.tsx @@ -39,7 +39,7 @@ import { DataFrameAnalyticsList } from '../../../../data_frame_analytics/pages/a import { AccessDeniedPage } from '../access_denied_page'; import { SharePluginStart } from '../../../../../../../../../src/plugins/share/public'; import { SpacesPluginStart } from '../../../../../../../spaces/public'; -import { JobSpacesRepairFlyout } from '../../../../components/job_spaces_repair'; +import { JobSpacesSyncFlyout } from '../../../../components/job_spaces_sync'; import { getDefaultAnomalyDetectionJobsListState } from '../../../../jobs/jobs_list/jobs'; import { getMlGlobalServices } from '../../../../app'; import { ListingPageUrlState } from '../../../../../../common/types/common'; @@ -125,7 +125,7 @@ export const JobsListPage: FC<{ const spacesEnabled = spaces !== undefined; const [initialized, setInitialized] = useState(false); const [accessDenied, setAccessDenied] = useState(false); - const [showRepairFlyout, setShowRepairFlyout] = useState(false); + const [showSyncFlyout, setShowSyncFlyout] = useState(false); const [isMlEnabledInSpace, setIsMlEnabledInSpace] = useState(false); const tabs = useTabs(isMlEnabledInSpace, spacesEnabled); const [currentTabId, setCurrentTabId] = useState(tabs[0].id); @@ -184,8 +184,8 @@ export const JobsListPage: FC<{ ); } - function onCloseRepairFlyout() { - setShowRepairFlyout(false); + function onCloseSyncFlyout() { + setShowSyncFlyout(false); } if (accessDenied) { @@ -244,12 +244,12 @@ export const JobsListPage: FC<{ {spacesEnabled && ( <> - setShowRepairFlyout(true)}> - {i18n.translate('xpack.ml.management.jobsList.repairFlyoutButton', { - defaultMessage: 'Repair saved objects', + setShowSyncFlyout(true)}> + {i18n.translate('xpack.ml.management.jobsList.syncFlyoutButton', { + defaultMessage: 'Synchronize saved objects', })} - {showRepairFlyout && } + {showSyncFlyout && } )} diff --git a/x-pack/plugins/ml/public/application/services/ml_api_service/saved_objects.ts b/x-pack/plugins/ml/public/application/services/ml_api_service/saved_objects.ts index b47cf3f62871c..e821fa3da4d66 100644 --- a/x-pack/plugins/ml/public/application/services/ml_api_service/saved_objects.ts +++ b/x-pack/plugins/ml/public/application/services/ml_api_service/saved_objects.ts @@ -11,7 +11,7 @@ import { HttpService } from '../http_service'; import { basePath } from './index'; import { JobType, - RepairSavedObjectResponse, + SyncSavedObjectResponse, SavedObjectResult, JobsSpacesResponse, } from '../../../../common/types/saved_objects'; @@ -40,9 +40,9 @@ export const savedObjectsApiProvider = (httpService: HttpService) => ({ }); }, - repairSavedObjects(simulate: boolean = false) { - return httpService.http({ - path: `${basePath()}/saved_objects/repair`, + syncSavedObjects(simulate: boolean = false) { + return httpService.http({ + path: `${basePath()}/saved_objects/sync`, method: 'GET', query: { simulate }, }); diff --git a/x-pack/plugins/ml/server/routes/apidoc.json b/x-pack/plugins/ml/server/routes/apidoc.json index 5672824f3d040..85df7228fe929 100644 --- a/x-pack/plugins/ml/server/routes/apidoc.json +++ b/x-pack/plugins/ml/server/routes/apidoc.json @@ -145,7 +145,7 @@ "JobSavedObjects", "SavedObjectsStatus", - "RepairJobSavedObjects", + "SyncJobSavedObjects", "InitializeJobSavedObjects", "AssignJobsToSpaces", "RemoveJobsFromSpaces", diff --git a/x-pack/plugins/ml/server/routes/saved_objects.ts b/x-pack/plugins/ml/server/routes/saved_objects.ts index 3ba69b0d6b505..57c6084d9971b 100644 --- a/x-pack/plugins/ml/server/routes/saved_objects.ts +++ b/x-pack/plugins/ml/server/routes/saved_objects.ts @@ -6,8 +6,8 @@ import { wrapError } from '../client/error_wrapper'; import { RouteInitialization, SavedObjectsRouteDeps } from '../types'; -import { checksFactory, repairFactory } from '../saved_objects'; -import { jobsAndSpaces, repairJobObjects, jobTypeSchema } from './schemas/saved_objects'; +import { checksFactory, syncSavedObjectsFactory } from '../saved_objects'; +import { jobsAndSpaces, syncJobObjects, jobTypeSchema } from './schemas/saved_objects'; import { jobIdsSchema } from './schemas/job_service_schema'; /** @@ -50,8 +50,8 @@ export function savedObjectsRoutes( /** * @apiGroup JobSavedObjects * - * @api {get} /api/ml/saved_objects/repair Repair job saved objects - * @apiName RepairJobSavedObjects + * @api {get} /api/ml/saved_objects/sync Sync job saved objects + * @apiName SyncJobSavedObjects * @apiDescription Create saved objects for jobs which are missing them. * Delete saved objects for jobs which no longer exist. * Update missing datafeed ids in saved objects for datafeeds which exist. @@ -60,9 +60,9 @@ export function savedObjectsRoutes( */ router.get( { - path: '/api/ml/saved_objects/repair', + path: '/api/ml/saved_objects/sync', validate: { - query: repairJobObjects, + query: syncJobObjects, }, options: { tags: ['access:ml:canCreateJob', 'access:ml:canCreateDataFrameAnalytics'], @@ -71,8 +71,8 @@ export function savedObjectsRoutes( routeGuard.fullLicenseAPIGuard(async ({ client, request, response, jobSavedObjectService }) => { try { const { simulate } = request.query; - const { repairJobs } = repairFactory(client, jobSavedObjectService); - const savedObjects = await repairJobs(simulate); + const { syncSavedObjects } = syncSavedObjectsFactory(client, jobSavedObjectService); + const savedObjects = await syncSavedObjects(simulate); return response.ok({ body: savedObjects, @@ -95,7 +95,7 @@ export function savedObjectsRoutes( { path: '/api/ml/saved_objects/initialize', validate: { - query: repairJobObjects, + query: syncJobObjects, }, options: { tags: ['access:ml:canCreateJob', 'access:ml:canCreateDataFrameAnalytics'], @@ -104,7 +104,7 @@ export function savedObjectsRoutes( routeGuard.fullLicenseAPIGuard(async ({ client, request, response, jobSavedObjectService }) => { try { const { simulate } = request.query; - const { initSavedObjects } = repairFactory(client, jobSavedObjectService); + const { initSavedObjects } = syncSavedObjectsFactory(client, jobSavedObjectService); const savedObjects = await initSavedObjects(simulate); return response.ok({ diff --git a/x-pack/plugins/ml/server/routes/schemas/saved_objects.ts b/x-pack/plugins/ml/server/routes/schemas/saved_objects.ts index 6b8c64714a82c..c2d091bd16052 100644 --- a/x-pack/plugins/ml/server/routes/schemas/saved_objects.ts +++ b/x-pack/plugins/ml/server/routes/schemas/saved_objects.ts @@ -12,7 +12,7 @@ export const jobsAndSpaces = schema.object({ spaces: schema.arrayOf(schema.string()), }); -export const repairJobObjects = schema.object({ simulate: schema.maybe(schema.boolean()) }); +export const syncJobObjects = schema.object({ simulate: schema.maybe(schema.boolean()) }); export const jobTypeSchema = schema.object({ jobType: schema.string(), diff --git a/x-pack/plugins/ml/server/saved_objects/index.ts b/x-pack/plugins/ml/server/saved_objects/index.ts index fdd675f40d083..a082f3c3ec54a 100644 --- a/x-pack/plugins/ml/server/saved_objects/index.ts +++ b/x-pack/plugins/ml/server/saved_objects/index.ts @@ -7,6 +7,6 @@ export { setupSavedObjects } from './saved_objects'; export { JobObject, JobSavedObjectService, jobSavedObjectServiceFactory } from './service'; export { checksFactory } from './checks'; -export { repairFactory } from './repair'; +export { syncSavedObjectsFactory } from './sync'; export { jobSavedObjectsInitializationFactory } from './initialization'; export { savedObjectClientsFactory } from './util'; diff --git a/x-pack/plugins/ml/server/saved_objects/initialization/initialization.ts b/x-pack/plugins/ml/server/saved_objects/initialization/initialization.ts index 5edf35c033177..a81fc925b824b 100644 --- a/x-pack/plugins/ml/server/saved_objects/initialization/initialization.ts +++ b/x-pack/plugins/ml/server/saved_objects/initialization/initialization.ts @@ -6,7 +6,7 @@ import { IScopedClusterClient, CoreStart, SavedObjectsClientContract } from 'kibana/server'; import { savedObjectClientsFactory } from '../util'; -import { repairFactory } from '../repair'; +import { syncSavedObjectsFactory } from '../sync'; import { jobSavedObjectServiceFactory, JobObject } from '../service'; import { mlLog } from '../../lib/log'; import { ML_SAVED_OBJECT_TYPE } from '../../../common/types/saved_objects'; @@ -58,7 +58,7 @@ export function jobSavedObjectsInitializationFactory( // create space overrides for specific jobs const jobSpaceOverrides = await createJobSpaceOverrides(client); // initialize jobs - const { initSavedObjects } = repairFactory(client, jobSavedObjectService); + const { initSavedObjects } = syncSavedObjectsFactory(client, jobSavedObjectService); const { jobs } = await initSavedObjects(false, jobSpaceOverrides); mlLog.info(`${jobs.length} job saved objects initialized`); } catch (error) { diff --git a/x-pack/plugins/ml/server/saved_objects/initialization/space_overrides/space_overrides.ts b/x-pack/plugins/ml/server/saved_objects/initialization/space_overrides/space_overrides.ts index d8c713888051f..969024ee58b51 100644 --- a/x-pack/plugins/ml/server/saved_objects/initialization/space_overrides/space_overrides.ts +++ b/x-pack/plugins/ml/server/saved_objects/initialization/space_overrides/space_overrides.ts @@ -5,7 +5,7 @@ */ import { IScopedClusterClient } from 'kibana/server'; -import type { JobSpaceOverrides } from '../../repair'; +import type { JobSpaceOverrides } from '../../sync'; import { logJobsSpaces } from './logs'; import { metricsJobsSpaces } from './metrics'; diff --git a/x-pack/plugins/ml/server/saved_objects/repair.ts b/x-pack/plugins/ml/server/saved_objects/sync.ts similarity index 97% rename from x-pack/plugins/ml/server/saved_objects/repair.ts rename to x-pack/plugins/ml/server/saved_objects/sync.ts index 692217e5fac36..16e0520567056 100644 --- a/x-pack/plugins/ml/server/saved_objects/repair.ts +++ b/x-pack/plugins/ml/server/saved_objects/sync.ts @@ -9,7 +9,7 @@ import { IScopedClusterClient } from 'kibana/server'; import type { JobObject, JobSavedObjectService } from './service'; import { JobType, - RepairSavedObjectResponse, + SyncSavedObjectResponse, InitializeSavedObjectResponse, } from '../../common/types/saved_objects'; import { checksFactory } from './checks'; @@ -23,14 +23,14 @@ export interface JobSpaceOverrides { }; } -export function repairFactory( +export function syncSavedObjectsFactory( client: IScopedClusterClient, jobSavedObjectService: JobSavedObjectService ) { const { checkStatus } = checksFactory(client, jobSavedObjectService); - async function repairJobs(simulate: boolean = false) { - const results: RepairSavedObjectResponse = { + async function syncSavedObjects(simulate: boolean = false) { + const results: SyncSavedObjectResponse = { savedObjectsCreated: {}, savedObjectsDeleted: {}, datafeedsAdded: {}, @@ -232,5 +232,5 @@ export function repairFactory( return results; } - return { checkStatus, repairJobs, initSavedObjects }; + return { checkStatus, syncSavedObjects, initSavedObjects }; }