6
6
import React , { useEffect , useState } from 'react' ;
7
7
import { getIn , useFormikContext } from 'formik' ;
8
8
import { isEmpty , isEqual } from 'lodash' ;
9
+ import semver from 'semver' ;
9
10
import {
10
11
EuiSmallButton ,
11
12
EuiSmallButtonEmpty ,
@@ -23,6 +24,7 @@ import {
23
24
import {
24
25
CONFIG_STEP ,
25
26
CachedFormikState ,
27
+ MINIMUM_FULL_SUPPORTED_VERSION ,
26
28
SimulateIngestPipelineResponseVerbose ,
27
29
TemplateNode ,
28
30
WORKFLOW_STEP_TYPE ,
@@ -56,6 +58,8 @@ import {
56
58
getDataSourceId ,
57
59
prepareDocsForSimulate ,
58
60
getIngestPipelineErrors ,
61
+ getEffectiveVersion ,
62
+ sleep ,
59
63
} from '../../../utils' ;
60
64
import { BooleanField } from './input_fields' ;
61
65
import '../workspace/workspace-styles.scss' ;
@@ -97,6 +101,21 @@ export function WorkflowInputs(props: WorkflowInputsProps) {
97
101
} = useFormikContext < WorkflowFormValues > ( ) ;
98
102
const dispatch = useAppDispatch ( ) ;
99
103
const dataSourceId = getDataSourceId ( ) ;
104
+ const [ dataSourceVersion , setDataSourceVersion ] = useState <
105
+ string | undefined
106
+ > ( undefined ) ;
107
+ useEffect ( ( ) => {
108
+ async function getVersion ( ) {
109
+ if ( dataSourceId !== undefined ) {
110
+ setDataSourceVersion ( await getEffectiveVersion ( dataSourceId ) ) ;
111
+ }
112
+ }
113
+ getVersion ( ) ;
114
+ } , [ dataSourceId ] ) ;
115
+ const isPreV219 =
116
+ dataSourceVersion !== undefined
117
+ ? semver . lt ( dataSourceVersion , MINIMUM_FULL_SUPPORTED_VERSION )
118
+ : false ;
100
119
101
120
// transient running states
102
121
const [ isUpdatingSearchPipeline , setIsUpdatingSearchPipeline ] = useState <
@@ -390,10 +409,16 @@ export function WorkflowInputs(props: WorkflowInputsProps) {
390
409
reprovision : true ,
391
410
} ,
392
411
dataSourceId,
412
+ dataSourceVersion,
393
413
} )
394
414
)
395
415
. unwrap ( )
396
416
. then ( async ( result ) => {
417
+ // if the datasource < 2.19, only async provisioning/reprovisioning is supported.
418
+ // so, we manually wait some time before trying to fetch the updated workflow
419
+ if ( isPreV219 ) {
420
+ await sleep ( 1000 ) ;
421
+ }
397
422
props . setUnsavedIngestProcessors ( false ) ;
398
423
props . setUnsavedSearchProcessors ( false ) ;
399
424
success = true ;
@@ -426,6 +451,7 @@ export function WorkflowInputs(props: WorkflowInputsProps) {
426
451
)
427
452
. unwrap ( )
428
453
. then ( async ( result ) => {
454
+ await sleep ( 100 ) ;
429
455
await dispatch (
430
456
updateWorkflow ( {
431
457
apiBody : {
@@ -438,16 +464,24 @@ export function WorkflowInputs(props: WorkflowInputsProps) {
438
464
)
439
465
. unwrap ( )
440
466
. then ( async ( result ) => {
467
+ await sleep ( 100 ) ;
441
468
props . setUnsavedIngestProcessors ( false ) ;
442
469
props . setUnsavedSearchProcessors ( false ) ;
443
470
await dispatch (
444
471
provisionWorkflow ( {
445
472
workflowId : updatedWorkflow . id as string ,
446
473
dataSourceId,
474
+ dataSourceVersion,
447
475
} )
448
476
)
449
477
. unwrap ( )
450
478
. then ( async ( result ) => {
479
+ await sleep ( 100 ) ;
480
+ // if the datasource < 2.19, only async provisioning/reprovisioning is supported.
481
+ // so, we manually wait some time before trying to fetch the updated workflow
482
+ if ( isPreV219 ) {
483
+ await sleep ( 1000 ) ;
484
+ }
451
485
await dispatch (
452
486
getWorkflow ( {
453
487
workflowId : updatedWorkflow . id as string ,
0 commit comments