Skip to content

Commit b51e438

Browse files
committed
Block simulate on ingest if version not foundg
Signed-off-by: Tyler Ohlsen <ohltyler@amazon.com>
1 parent 372ea42 commit b51e438

File tree

2 files changed

+49
-21
lines changed

2 files changed

+49
-21
lines changed

public/pages/workflow_detail/workflow_inputs/workflow_inputs.tsx

+9-1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ import {
6060
getIngestPipelineErrors,
6161
getEffectiveVersion,
6262
sleep,
63+
useMissingDataSourceVersion,
6364
} from '../../../utils';
6465
import { BooleanField } from './input_fields';
6566
import '../workspace/workspace-styles.scss';
@@ -116,6 +117,10 @@ export function WorkflowInputs(props: WorkflowInputsProps) {
116117
dataSourceVersion !== undefined
117118
? semver.lt(dataSourceVersion, MINIMUM_FULL_SUPPORTED_VERSION)
118119
: false;
120+
const missingDataSourceVersion = useMissingDataSourceVersion(
121+
dataSourceId,
122+
dataSourceVersion
123+
);
119124

120125
// transient running states
121126
const [isUpdatingSearchPipeline, setIsUpdatingSearchPipeline] = useState<
@@ -617,7 +622,10 @@ export function WorkflowInputs(props: WorkflowInputsProps) {
617622
if (
618623
!isEmpty(values?.ingest?.enrich) &&
619624
values?.ingest?.pipelineName !== undefined &&
620-
values?.ingest?.pipelineName !== ''
625+
values?.ingest?.pipelineName !== '' &&
626+
// if the data source version is missing/undefined, we cannot
627+
// guarantee that the simulate API will be available
628+
!missingDataSourceVersion
621629
) {
622630
const curDocs = prepareDocsForSimulate(
623631
values?.ingest?.docs,

public/utils/utils.tsx

+40-20
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
import React, { ReactNode } from 'react';
6+
import React, { ReactNode, useEffect, useState } from 'react';
77
import yaml from 'js-yaml';
88
import jsonpath from 'jsonpath';
99
import { capitalize, escape, findKey, get, isEmpty, set, unset } from 'lodash';
@@ -159,27 +159,38 @@ export function isValidWorkflow(workflowObj: any): boolean {
159159

160160
// Determines if a file used for import workflow is compatible with the current data source version.
161161
export async function isCompatibleWorkflow(
162-
workflowObj: any,
162+
workflowObj: any,
163163
dataSourceId?: string | undefined
164164
): Promise<boolean> {
165165
const compatibility = workflowObj?.version?.compatibility;
166166

167167
// Default to true when compatibility cannot be assessed (empty/invalid compatibility array or MDS disabled.)
168-
if (!Array.isArray(compatibility) || compatibility.length === 0 || dataSourceId === undefined) {
168+
if (
169+
!Array.isArray(compatibility) ||
170+
compatibility.length === 0 ||
171+
dataSourceId === undefined
172+
) {
169173
return true;
170174
}
171175

172-
const dataSourceVersion = await getEffectiveVersion(dataSourceId);
173-
const [effectiveMajorVersion, effectiveMinorVersion] = dataSourceVersion.split('.').map(Number);
174-
176+
const dataSourceVersion = await getEffectiveVersion(dataSourceId);
177+
const [
178+
effectiveMajorVersion,
179+
effectiveMinorVersion,
180+
] = dataSourceVersion.split('.').map(Number);
181+
175182
// Checks if any version in compatibility array matches the current dataSourceVersion (major.minor)
176-
return compatibility.some(compatibleVersion => {
177-
const [compatibleMajor, compatibleMinor] = compatibleVersion.split('.').map(Number);
178-
return effectiveMajorVersion === compatibleMajor && effectiveMinorVersion === compatibleMinor;
183+
return compatibility.some((compatibleVersion) => {
184+
const [compatibleMajor, compatibleMinor] = compatibleVersion
185+
.split('.')
186+
.map(Number);
187+
return (
188+
effectiveMajorVersion === compatibleMajor &&
189+
effectiveMinorVersion === compatibleMinor
190+
);
179191
});
180192
}
181193

182-
183194
export function isValidUiWorkflow(workflowObj: any): boolean {
184195
return (
185196
isValidWorkflow(workflowObj) &&
@@ -909,13 +920,13 @@ export function getFieldValue(jsonObj: {}, fieldName: string): any | undefined {
909920
return undefined;
910921
}
911922

912-
// Get the version from the selected data source
923+
// Get the version from the selected data source, if found
913924
export const getEffectiveVersion = async (
914925
dataSourceId: string | undefined
915-
): Promise<string> => {
926+
): Promise<string | undefined> => {
916927
try {
917928
if (dataSourceId === undefined) {
918-
throw new Error('Data source is required');
929+
throw new Error();
919930
}
920931

921932
if (dataSourceId === '') {
@@ -927,16 +938,26 @@ export const getEffectiveVersion = async (
927938
'data-source',
928939
dataSourceId
929940
);
930-
const version =
931-
dataSource?.attributes?.dataSourceVersion || MIN_SUPPORTED_VERSION;
932-
return version;
941+
return dataSource?.attributes?.dataSourceVersion;
933942
} catch (error) {
934-
console.error('Error getting version:', error);
935-
return MIN_SUPPORTED_VERSION;
943+
console.error('Error getting version: ', error);
944+
return undefined;
936945
}
937946
};
938947

939-
948+
export function useMissingDataSourceVersion(
949+
dataSourceId: string | undefined,
950+
dataSourceVersion: string | undefined
951+
): boolean {
952+
const [missingVersion, setMissingVersion] = useState<boolean>(false);
953+
useEffect(() => {
954+
setMissingVersion(
955+
dataSourceId !== undefined && dataSourceVersion === undefined
956+
);
957+
}, [dataSourceId, dataSourceVersion]);
958+
return missingVersion;
959+
}
960+
940961
/**
941962
* Formats version string to show only major.minor numbers
942963
* Example: "3.0.0-alpha1" -> "3.0"
@@ -946,4 +967,3 @@ export function formatDisplayVersion(version: string): string {
946967
const [major, minor] = version.split('.');
947968
return `${major}.${minor}`;
948969
}
949-

0 commit comments

Comments
 (0)