Skip to content

Commit 39ed7aa

Browse files
authored
fix error that local cluster cannot get version (#606)
Signed-off-by: Kama Huang <kamahuan@amazon.com>
1 parent c9aa3db commit 39ed7aa

File tree

7 files changed

+75
-13
lines changed

7 files changed

+75
-13
lines changed

public/pages/workflow_detail/workflow_inputs/processors_list.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ export function ProcessorsList(props: ProcessorsListProps) {
119119
return;
120120
}
121121

122-
if (dataSourceId) {
122+
if (dataSourceId !== undefined) {
123123
getEffectiveVersion(dataSourceId)
124124
.then((ver) => {
125125
setVersion(ver);

public/pages/workflows/new_workflow/new_workflow.test.tsx

+4
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ const initialState = {
4040
presetWorkflows: loadPresetWorkflowTemplates(),
4141
},
4242
workflows: INITIAL_WORKFLOWS_STATE,
43+
opensearch: {
44+
loading: false,
45+
localClusterVersion: null,
46+
},
4347
};
4448

4549
const mockDispatch = jest.fn();

public/pages/workflows/new_workflow/new_workflow.tsx

+16-11
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import {
3939
MIN_SUPPORTED_VERSION,
4040
MINIMUM_FULL_SUPPORTED_VERSION,
4141
} from '../../../../common/constants';
42+
import { getLocalClusterVersion } from '../../../store/reducers/opensearch_reducer';
4243

4344
interface NewWorkflowProps {}
4445

@@ -52,7 +53,7 @@ const filterPresetsByVersion = async (
5253
return workflows;
5354
}
5455

55-
if (!dataSourceId) {
56+
if (dataSourceId === undefined) {
5657
return [];
5758
}
5859

@@ -92,14 +93,18 @@ export function NewWorkflow(props: NewWorkflowProps) {
9293
const dataSourceId = getDataSourceId();
9394
const dataSourceEnabled = getDataSourceEnabled().enabled;
9495
// workflows state
95-
const { presetWorkflows, loading } = useSelector(
96+
const { presetWorkflows, loading: presetsLoading } = useSelector(
9697
(state: AppState) => state.presets
9798
);
99+
const { loading: opensearchLoading, localClusterVersion } = useSelector(
100+
(state: AppState) => state.opensearch
101+
);
102+
const isLoading = presetsLoading || opensearchLoading;
103+
98104
const [allWorkflows, setAllWorkflows] = useState<WorkflowTemplate[]>([]);
99105
const [filteredWorkflows, setFilteredWorkflows] = useState<
100106
WorkflowTemplate[]
101107
>([]);
102-
const [isVersionLoading, setIsVersionLoading] = useState(false);
103108

104109
// search bar state
105110
const [searchQuery, setSearchQuery] = useState<string>('');
@@ -111,6 +116,7 @@ export function NewWorkflow(props: NewWorkflowProps) {
111116
// 1. fetch the workflow presets persisted on server-side
112117
// 2. fetch the ML models and connectors. these may be used in quick-create views when selecting a preset,
113118
// so we optimize by fetching once at the top-level here.
119+
// 3. fetch local cluster version if applicable
114120
useEffect(() => {
115121
dispatch(getWorkflowPresets());
116122
if (isDataSourceReady(dataSourceId)) {
@@ -119,6 +125,10 @@ export function NewWorkflow(props: NewWorkflowProps) {
119125
searchConnectors({ apiBody: FETCH_ALL_QUERY_LARGE, dataSourceId })
120126
);
121127
}
128+
// if use local cluster
129+
if (dataSourceId === '') {
130+
dispatch(getLocalClusterVersion());
131+
}
122132
}, [dataSourceId, dataSourceEnabled]);
123133

124134
// initial hook to populate all workflows
@@ -140,19 +150,15 @@ export function NewWorkflow(props: NewWorkflowProps) {
140150
);
141151
setAllWorkflows(enrichedWorkflows);
142152
setFilteredWorkflows(enrichedWorkflows);
143-
setIsVersionLoading(false);
144153
return;
145154
}
146155

147-
if (!dataSourceId) {
156+
if (dataSourceId === undefined) {
148157
setAllWorkflows([]);
149158
setFilteredWorkflows([]);
150-
setIsVersionLoading(true);
151159
return;
152160
}
153161

154-
setIsVersionLoading(true);
155-
156162
const version = await getEffectiveVersion(dataSourceId);
157163

158164
const enrichedWorkflows = presetWorkflows.map((presetWorkflow) =>
@@ -166,11 +172,10 @@ export function NewWorkflow(props: NewWorkflowProps) {
166172

167173
setAllWorkflows(versionFilteredWorkflows);
168174
setFilteredWorkflows(versionFilteredWorkflows);
169-
setIsVersionLoading(false);
170175
};
171176

172177
loadWorkflows();
173-
}, [presetWorkflows, dataSourceId, dataSourceEnabled]);
178+
}, [presetWorkflows, dataSourceId, dataSourceEnabled, localClusterVersion]);
174179

175180
// When search query updated, re-filter preset list
176181
useEffect(() => {
@@ -191,7 +196,7 @@ export function NewWorkflow(props: NewWorkflowProps) {
191196
/>
192197
</EuiFlexItem>
193198
<EuiFlexItem>
194-
{loading || isVersionLoading ? (
199+
{isLoading ? (
195200
<EuiFlexGroup
196201
justifyContent="center"
197202
alignItems="center"

public/route_service.ts

+12
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ export interface RouteService {
148148
pipelineId: string,
149149
dataSourceId?: string
150150
) => Promise<any | HttpFetchError>;
151+
getLocalClusterVersion: () => Promise<any | HttpFetchError>;
151152
}
152153

153154
export function configureRoutes(core: CoreStart): RouteService {
@@ -323,6 +324,17 @@ export function configureRoutes(core: CoreStart): RouteService {
323324
return e as HttpFetchError;
324325
}
325326
},
327+
getLocalClusterVersion: async () => {
328+
try {
329+
const response = await core.http.post('/api/console/proxy', {
330+
query: { path: '/', method: 'GET', dataSourceId: '' },
331+
});
332+
return response.version.number;
333+
} catch (e: any) {
334+
return e as HttpFetchError;
335+
}
336+
},
337+
326338
getIndex: async (index: string, dataSourceId?: string) => {
327339
try {
328340
const url = dataSourceId

public/store/reducers/opensearch_reducer.ts

+35
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,12 @@ export const INITIAL_OPENSEARCH_STATE = {
2929
indexDetails: {} as { [key: string]: IndexConfiguration },
3030
ingestPipelineDetails: {} as { [key: string]: IngestPipelineConfig },
3131
searchPipelineDetails: {} as { [key: string]: SearchPipelineConfig },
32+
localClusterVersion: null as string | null,
3233
};
3334

3435
const OPENSEARCH_PREFIX = 'opensearch';
36+
const GET_LOCAL_CLUSTER_VERSION_ACTION = `${OPENSEARCH_PREFIX}/getLocalClusterVersion`;
37+
const SET_OPENSEARCH_ERROR = `${OPENSEARCH_PREFIX}/setError`;
3538
const CAT_INDICES_ACTION = `${OPENSEARCH_PREFIX}/catIndices`;
3639
const GET_MAPPINGS_ACTION = `${OPENSEARCH_PREFIX}/mappings`;
3740
const SEARCH_INDEX_ACTION = `${OPENSEARCH_PREFIX}/search`;
@@ -42,6 +45,25 @@ const GET_INGEST_PIPELINE_ACTION = `${OPENSEARCH_PREFIX}/getIngestPipeline`;
4245
const GET_SEARCH_PIPELINE_ACTION = `${OPENSEARCH_PREFIX}/getSearchPipeline`;
4346
const GET_INDEX_ACTION = `${OPENSEARCH_PREFIX}/getIndex`;
4447

48+
export const getLocalClusterVersion = createAsyncThunk(
49+
GET_LOCAL_CLUSTER_VERSION_ACTION,
50+
async (_, { rejectWithValue }) => {
51+
try {
52+
const version = await getRouteService().getLocalClusterVersion();
53+
return version;
54+
} catch (error) {
55+
return rejectWithValue('Error getting local cluster version: ' + error);
56+
}
57+
}
58+
);
59+
60+
export const setOpenSearchError = createAsyncThunk(
61+
SET_OPENSEARCH_ERROR,
62+
async ({ error }: { error: string }, { rejectWithValue }) => {
63+
return error;
64+
}
65+
);
66+
4567
export const catIndices = createAsyncThunk(
4668
CAT_INDICES_ACTION,
4769
async (
@@ -417,6 +439,19 @@ const opensearchSlice = createSlice({
417439
.addCase(bulk.rejected, (state, action) => {
418440
state.errorMessage = action.payload as string;
419441
state.loading = false;
442+
})
443+
.addCase(getLocalClusterVersion.pending, (state) => {
444+
state.loading = true;
445+
state.errorMessage = '';
446+
})
447+
.addCase(getLocalClusterVersion.fulfilled, (state, action) => {
448+
state.localClusterVersion = action.payload;
449+
state.loading = false;
450+
state.errorMessage = '';
451+
})
452+
.addCase(getLocalClusterVersion.rejected, (state, action) => {
453+
state.errorMessage = action.payload as string;
454+
state.loading = false;
420455
});
421456
},
422457
});

public/store/reducers/presets_reducer.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ const presetsSlice = createSlice({
5151
state.errorMessage = '';
5252
})
5353
.addCase(getWorkflowPresets.rejected, (state, action) => {
54-
state.errorMessage = action.payload as string;
5554
state.loading = false;
55+
state.errorMessage = action.payload as string;
5656
});
5757
},
5858
});

public/utils/utils.tsx

+6
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import {
4747
import {
4848
getCore,
4949
getDataSourceEnabled,
50+
getRouteService,
5051
getSavedObjectsClient,
5152
} from '../services';
5253
import {
@@ -893,6 +894,11 @@ export const getEffectiveVersion = async (
893894
throw new Error('Data source is required');
894895
}
895896

897+
if (dataSourceId === '') {
898+
// Use route service for local cluster case
899+
return await getRouteService().getLocalClusterVersion();
900+
}
901+
896902
const dataSource = await getSavedObjectsClient().get<DataSourceAttributes>(
897903
'data-source',
898904
dataSourceId

0 commit comments

Comments
 (0)