import { http } from '../http_service' ; import { basePath } from './index' ; import { DataFrameAnalyticsStats } from '../../data_frame_analytics/pages/analytics_management/components/analytics_list/common' ; import { ValidateAnalyticsJobResponse } from '../../../../common/constants/validation' ; import { DataFrameAnalyticsConfig , UpdateDataFrameAnalyticsConfig , } from '../../data_frame_analytics/common' ; import { DeepPartial } from '../../../../common/types/common' ; import { NewJobCapsResponse } from '../../../../common/types/fields' ; import { DeleteDataFrameAnalyticsWithIndexStatus , AnalyticsMapReturnType , } from '../../../../common/types/data_frame_analytics' ; export interface GetDataFrameAnalyticsStatsResponseOk { node_failures ? : object ; count : number ; data_frame_analytics : DataFrameAnalyticsStats [ ] ; } export interface GetDataFrameAnalyticsStatsResponseError { statusCode : number ; error : string ; message : string ; } export type GetDataFrameAnalyticsStatsResponse = GetDataFrameAnalyticsStatsResponseOk | GetDataFrameAnalyticsStatsResponseError ; export interface GetDataFrameAnalyticsResponse { count : number ; data_frame_analytics : DataFrameAnalyticsConfig [ ] ; } export interface DeleteDataFrameAnalyticsWithIndexResponse { acknowledged : boolean ; analyticsJobDeleted : DeleteDataFrameAnalyticsWithIndexStatus ; destIndexDeleted : DeleteDataFrameAnalyticsWithIndexStatus ; destIndexPatternDeleted : DeleteDataFrameAnalyticsWithIndexStatus ; } export interface JobsExistsResponse { [ jobId ] : { exists : boolean ; } ; } export const dataFrameAnalytics = { getDataFrameAnalytics ( analyticsId ? , excludeGenerated ? ) { const analyticsIdString = analyticsId !== undefined ? `/${ analyticsId }` : '' ; return http < GetDataFrameAnalyticsResponse > ( { path : `${ basePath ( ) }/data_frame/analytics${ analyticsIdString }` , method : 'GET' , ... ( excludeGenerated ? { query : { excludeGenerated } } : { } ) , } ) ; } , getDataFrameAnalyticsStats ( analyticsId ? ) { if ( analyticsId !== undefined ) { return http < GetDataFrameAnalyticsStatsResponse > ( { path : `${ basePath ( ) }/data_frame/analytics/${ analyticsId }/_stats` , method : 'GET' , } ) ; } return http < GetDataFrameAnalyticsStatsResponse > ( { path : `${ basePath ( ) }/data_frame/analytics/_stats` , method : 'GET' , } ) ; } , createDataFrameAnalytics ( analyticsId , analyticsConfig ) { const body = JSON . stringify ( analyticsConfig ) ; return http < any > ( { path : `${ basePath ( ) }/data_frame/analytics/${ analyticsId }` , method : 'PUT' , body , } ) ; } , updateDataFrameAnalytics ( analyticsId , updateConfig ) { const body = JSON . stringify ( updateConfig ) ; return http < any > ( { path : `${ basePath ( ) }/data_frame/analytics/${ analyticsId }/_update` , method : 'POST' , body , } ) ; } , getDataFrameAnalyticsMap ( id , treatAsRoot , type ? ) { const idString = id !== undefined ? `/${ id }` : '' ; return http ( { path : `${ basePath ( ) }/data_frame/analytics/map${ idString }` , method : 'GET' , query : { treatAsRoot , type } , } ) ; } , jobsExist ( analyticsIds , allSpaces = false ) { const body = JSON . stringify ( { analyticsIds , allSpaces } ) ; return http < JobsExistsResponse > ( { path : `${ basePath ( ) }/data_frame/analytics/jobs_exist` , method : 'POST' , body , } ) ; } , evaluateDataFrameAnalytics ( evaluateConfig ) { const body = JSON . stringify ( evaluateConfig ) ; return http < any > ( { path : `${ basePath ( ) }/data_frame/_evaluate` , method : 'POST' , body , } ) ; } , explainDataFrameAnalytics ( jobConfig ) { const body = JSON . stringify ( jobConfig ) ; return http < any > ( { path : `${ basePath ( ) }/data_frame/analytics/_explain` , method : 'POST' , body , } ) ; } , deleteDataFrameAnalytics ( analyticsId ) { return http < any > ( { path : `${ basePath ( ) }/data_frame/analytics/${ analyticsId }` , method : 'DELETE' , } ) ; } , deleteDataFrameAnalyticsAndDestIndex ( analyticsId , deleteDestIndex , deleteDestIndexPattern ) { return http < DeleteDataFrameAnalyticsWithIndexResponse > ( { path : `${ basePath ( ) }/data_frame/analytics/${ analyticsId }` , query : { deleteDestIndex , deleteDestIndexPattern } , method : 'DELETE' , } ) ; } , startDataFrameAnalytics ( analyticsId ) { return http < any > ( { path : `${ basePath ( ) }/data_frame/analytics/${ analyticsId }/_start` , method : 'POST' , } ) ; } , stopDataFrameAnalytics ( analyticsId , force = false ) { return http < any > ( { path : `${ basePath ( ) }/data_frame/analytics/${ analyticsId }/_stop` , method : 'POST' , query : { force } , } ) ; } , getAnalyticsAuditMessages ( analyticsId ) { return http < any > ( { path : `${ basePath ( ) }/data_frame/analytics/${ analyticsId }/messages` , method : 'GET' , } ) ; } , validateDataFrameAnalytics ( analyticsConfig ) { const body = JSON . stringify ( analyticsConfig ) ; return http < ValidateAnalyticsJobResponse > ( { path : `${ basePath ( ) }/data_frame/analytics/validate` , method : 'POST' , body , } ) ; } , newJobCapsAnalytics ( indexPatternTitle , isRollup = false ) { const query = isRollup === true ? { rollup : true } : { } ; return http < NewJobCapsResponse > ( { path : `${ basePath ( ) }/data_frame/analytics/new_job_caps/${ indexPatternTitle }` , method : 'GET' , query , } ) ; } , } ;