Skip to content

Commit 474a8a7

Browse files
authored
Support 2.17 BWC with latest backend integrations (#612)
Signed-off-by: Tyler Ohlsen <ohltyler@amazon.com>
1 parent c77a2be commit 474a8a7

13 files changed

+241
-60
lines changed

public/pages/workflow_detail/tools/query/query.tsx

+13
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import {
3636
containsEmptyValues,
3737
containsSameValues,
3838
getDataSourceId,
39+
getEffectiveVersion,
3940
getPlaceholdersFromQuery,
4041
getSearchPipelineErrors,
4142
injectParameters,
@@ -64,6 +65,17 @@ const SEARCH_OPTIONS = [
6465
export function Query(props: QueryProps) {
6566
const dispatch = useAppDispatch();
6667
const dataSourceId = getDataSourceId();
68+
const [dataSourceVersion, setDataSourceVersion] = useState<
69+
string | undefined
70+
>(undefined);
71+
useEffect(() => {
72+
async function getVersion() {
73+
if (dataSourceId !== undefined) {
74+
setDataSourceVersion(await getEffectiveVersion(dataSourceId));
75+
}
76+
}
77+
getVersion();
78+
}, [dataSourceId]);
6779

6880
const { loading } = useSelector((state: AppState) => state.opensearch);
6981

@@ -204,6 +216,7 @@ export function Query(props: QueryProps) {
204216
: '_none',
205217
},
206218
dataSourceId,
219+
dataSourceVersion,
207220
verbose: includePipeline,
208221
})
209222
)

public/pages/workflow_detail/workflow_inputs/processors_list.tsx

+5-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,11 @@ import {
2929
WorkflowConfig,
3030
WorkflowFormValues,
3131
} from '../../../../common';
32-
import { formikToUiConfig, getDataSourceFromURL } from '../../../utils';
33-
import { getEffectiveVersion } from '../../../pages/workflows/new_workflow/new_workflow';
32+
import {
33+
formikToUiConfig,
34+
getDataSourceFromURL,
35+
getEffectiveVersion,
36+
} from '../../../utils';
3437
import {
3538
CollapseProcessor,
3639
CopyIngestProcessor,

public/pages/workflow_detail/workflow_inputs/search_inputs/search_inputs.tsx

+5-4
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ import {
1515
WorkflowConfig,
1616
} from '../../../../../common';
1717
import { catIndices, useAppDispatch } from '../../../../store';
18-
import { getDataSourceId } from '../../../../utils';
19-
import { getEffectiveVersion } from '../../../workflows/new_workflow/new_workflow';
18+
import { getDataSourceId, getEffectiveVersion } from '../../../../utils';
2019

2120
interface SearchInputsProps {
2221
uiConfig: WorkflowConfig;
@@ -42,8 +41,10 @@ export function SearchInputs(props: SearchInputsProps) {
4241
useEffect(() => {
4342
const checkVersion = async () => {
4443
try {
45-
const version = await getEffectiveVersion(dataSourceId);
46-
setShowTransformQuery(semver.gte(version, '2.19.0'));
44+
if (dataSourceId !== undefined) {
45+
const version = await getEffectiveVersion(dataSourceId);
46+
setShowTransformQuery(semver.gte(version, '2.19.0'));
47+
}
4748
} catch (error) {
4849
console.error('Error checking version:', error);
4950
setShowTransformQuery(true);

public/pages/workflow_detail/workflow_inputs/workflow_inputs.tsx

+34
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import React, { useEffect, useState } from 'react';
77
import { getIn, useFormikContext } from 'formik';
88
import { isEmpty, isEqual } from 'lodash';
9+
import semver from 'semver';
910
import {
1011
EuiSmallButton,
1112
EuiSmallButtonEmpty,
@@ -23,6 +24,7 @@ import {
2324
import {
2425
CONFIG_STEP,
2526
CachedFormikState,
27+
MINIMUM_FULL_SUPPORTED_VERSION,
2628
SimulateIngestPipelineResponseVerbose,
2729
TemplateNode,
2830
WORKFLOW_STEP_TYPE,
@@ -56,6 +58,8 @@ import {
5658
getDataSourceId,
5759
prepareDocsForSimulate,
5860
getIngestPipelineErrors,
61+
getEffectiveVersion,
62+
sleep,
5963
} from '../../../utils';
6064
import { BooleanField } from './input_fields';
6165
import '../workspace/workspace-styles.scss';
@@ -97,6 +101,21 @@ export function WorkflowInputs(props: WorkflowInputsProps) {
97101
} = useFormikContext<WorkflowFormValues>();
98102
const dispatch = useAppDispatch();
99103
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;
100119

101120
// transient running states
102121
const [isUpdatingSearchPipeline, setIsUpdatingSearchPipeline] = useState<
@@ -390,10 +409,16 @@ export function WorkflowInputs(props: WorkflowInputsProps) {
390409
reprovision: true,
391410
},
392411
dataSourceId,
412+
dataSourceVersion,
393413
})
394414
)
395415
.unwrap()
396416
.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+
}
397422
props.setUnsavedIngestProcessors(false);
398423
props.setUnsavedSearchProcessors(false);
399424
success = true;
@@ -426,6 +451,7 @@ export function WorkflowInputs(props: WorkflowInputsProps) {
426451
)
427452
.unwrap()
428453
.then(async (result) => {
454+
await sleep(100);
429455
await dispatch(
430456
updateWorkflow({
431457
apiBody: {
@@ -438,16 +464,24 @@ export function WorkflowInputs(props: WorkflowInputsProps) {
438464
)
439465
.unwrap()
440466
.then(async (result) => {
467+
await sleep(100);
441468
props.setUnsavedIngestProcessors(false);
442469
props.setUnsavedSearchProcessors(false);
443470
await dispatch(
444471
provisionWorkflow({
445472
workflowId: updatedWorkflow.id as string,
446473
dataSourceId,
474+
dataSourceVersion,
447475
})
448476
)
449477
.unwrap()
450478
.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+
}
451485
await dispatch(
452486
getWorkflow({
453487
workflowId: updatedWorkflow.id as string,

public/pages/workflows/new_workflow/new_workflow.tsx

+5-24
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,13 @@ import {
2727
searchConnectors,
2828
} from '../../../store';
2929
import { enrichPresetWorkflowWithUiMetadata } from './utils';
30-
import { getDataSourceId, isDataSourceReady } from '../../../utils';
30+
import {
31+
getDataSourceId,
32+
isDataSourceReady,
33+
getEffectiveVersion,
34+
} from '../../../utils';
3135
import { getDataSourceEnabled } from '../../../services';
3236
import semver from 'semver';
33-
import { DataSourceAttributes } from '../../../../../../src/plugins/data_source/common/data_sources';
34-
import { getSavedObjectsClient } from '../../../../public/services';
3537
import {
3638
WORKFLOW_TYPE,
3739
MIN_SUPPORTED_VERSION,
@@ -40,27 +42,6 @@ import {
4042

4143
interface NewWorkflowProps {}
4244

43-
export const getEffectiveVersion = async (
44-
dataSourceId: string | undefined
45-
): Promise<string> => {
46-
try {
47-
if (dataSourceId === undefined) {
48-
throw new Error('Data source is required');
49-
}
50-
51-
const dataSource = await getSavedObjectsClient().get<DataSourceAttributes>(
52-
'data-source',
53-
dataSourceId
54-
);
55-
const version =
56-
dataSource?.attributes?.dataSourceVersion || MIN_SUPPORTED_VERSION;
57-
return version;
58-
} catch (error) {
59-
console.error('Error getting version:', error);
60-
return MIN_SUPPORTED_VERSION;
61-
}
62-
};
63-
6445
const filterPresetsByVersion = async (
6546
workflows: WorkflowTemplate[],
6647
dataSourceId: string | undefined

public/route_service.ts

+25-5
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,13 @@ export interface RouteService {
6060
workflowTemplate: WorkflowTemplate,
6161
updateFields: boolean,
6262
reprovision: boolean,
63-
dataSourceId?: string
63+
dataSourceId?: string,
64+
dataSourceVersion?: string
6465
) => Promise<any | HttpFetchError>;
6566
provisionWorkflow: (
6667
workflowId: string,
67-
dataSourceId?: string
68+
dataSourceId?: string,
69+
dataSourceVersion?: string
6870
) => Promise<any | HttpFetchError>;
6971
deprovisionWorkflow: ({
7072
workflowId,
@@ -96,12 +98,14 @@ export interface RouteService {
9698
index,
9799
body,
98100
dataSourceId,
101+
dataSourceVersion,
99102
searchPipeline,
100103
verbose,
101104
}: {
102105
index: string;
103106
body: {};
104107
dataSourceId?: string;
108+
dataSourceVersion?: string;
105109
searchPipeline?: string;
106110
verbose?: boolean;
107111
}) => Promise<any | HttpFetchError>;
@@ -205,7 +209,8 @@ export function configureRoutes(core: CoreStart): RouteService {
205209
workflowTemplate: WorkflowTemplate,
206210
updateFields: boolean,
207211
reprovision: boolean,
208-
dataSourceId?: string
212+
dataSourceId?: string,
213+
dataSourceVersion?: string
209214
) => {
210215
try {
211216
const url = dataSourceId
@@ -215,20 +220,32 @@ export function configureRoutes(core: CoreStart): RouteService {
215220
`${url}/${workflowId}/${updateFields}/${reprovision}`,
216221
{
217222
body: JSON.stringify(workflowTemplate),
223+
query: {
224+
data_source_version: dataSourceVersion,
225+
},
218226
}
219227
);
220228
return response;
221229
} catch (e: any) {
222230
return e as HttpFetchError;
223231
}
224232
},
225-
provisionWorkflow: async (workflowId: string, dataSourceId?: string) => {
233+
provisionWorkflow: async (
234+
workflowId: string,
235+
dataSourceId?: string,
236+
dataSourceVersion?: string
237+
) => {
226238
try {
227239
const url = dataSourceId
228240
? `${BASE_NODE_API_PATH}/${dataSourceId}/workflow/provision`
229241
: PROVISION_WORKFLOW_NODE_API_PATH;
230242
const response = await core.http.post<{ respString: string }>(
231-
`${url}/${workflowId}`
243+
`${url}/${workflowId}`,
244+
{
245+
query: {
246+
data_source_version: dataSourceVersion,
247+
},
248+
}
232249
);
233250
return response;
234251
} catch (e: any) {
@@ -323,12 +340,14 @@ export function configureRoutes(core: CoreStart): RouteService {
323340
index,
324341
body,
325342
dataSourceId,
343+
dataSourceVersion,
326344
searchPipeline,
327345
verbose,
328346
}: {
329347
index: string;
330348
body: {};
331349
dataSourceId?: string;
350+
dataSourceVersion?: string;
332351
searchPipeline?: string;
333352
verbose?: boolean;
334353
}) => {
@@ -344,6 +363,7 @@ export function configureRoutes(core: CoreStart): RouteService {
344363
body: JSON.stringify(body),
345364
query: {
346365
verbose: verbose ?? false,
366+
data_source_version: dataSourceVersion,
347367
},
348368
});
349369
return response;

public/store/reducers/opensearch_reducer.ts

+3
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,12 @@ export const searchIndex = createAsyncThunk(
110110
{
111111
apiBody,
112112
dataSourceId,
113+
dataSourceVersion,
113114
verbose,
114115
}: {
115116
apiBody: { index: string; body: {}; searchPipeline?: string };
116117
dataSourceId?: string;
118+
dataSourceVersion?: string;
117119
verbose?: boolean;
118120
},
119121
{ rejectWithValue }
@@ -123,6 +125,7 @@ export const searchIndex = createAsyncThunk(
123125
index,
124126
body,
125127
dataSourceId,
128+
dataSourceVersion,
126129
searchPipeline,
127130
verbose,
128131
});

public/store/reducers/workflows_reducer.ts

+15-3
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ export const updateWorkflow = createAsyncThunk(
116116
{
117117
apiBody,
118118
dataSourceId,
119+
dataSourceVersion,
119120
}: {
120121
apiBody: {
121122
workflowId: string;
@@ -124,6 +125,7 @@ export const updateWorkflow = createAsyncThunk(
124125
reprovision?: boolean;
125126
};
126127
dataSourceId?: string;
128+
dataSourceVersion?: string;
127129
},
128130
{ rejectWithValue }
129131
) => {
@@ -135,7 +137,8 @@ export const updateWorkflow = createAsyncThunk(
135137
workflowTemplate,
136138
updateFields || false,
137139
reprovision || false,
138-
dataSourceId
140+
dataSourceId,
141+
dataSourceVersion
139142
);
140143
if (response instanceof HttpFetchError) {
141144
return rejectWithValue(
@@ -150,14 +153,23 @@ export const updateWorkflow = createAsyncThunk(
150153
export const provisionWorkflow = createAsyncThunk(
151154
PROVISION_WORKFLOW_ACTION,
152155
async (
153-
{ workflowId, dataSourceId }: { workflowId: string; dataSourceId?: string },
156+
{
157+
workflowId,
158+
dataSourceId,
159+
dataSourceVersion,
160+
}: {
161+
workflowId: string;
162+
dataSourceId?: string;
163+
dataSourceVersion?: string;
164+
},
154165
{ rejectWithValue }
155166
) => {
156167
const response:
157168
| any
158169
| HttpFetchError = await getRouteService().provisionWorkflow(
159170
workflowId,
160-
dataSourceId
171+
dataSourceId,
172+
dataSourceVersion
161173
);
162174
if (response instanceof HttpFetchError) {
163175
return rejectWithValue(

0 commit comments

Comments
 (0)