Skip to content

Commit cc381ad

Browse files
committed
Get core APIs working
Signed-off-by: Tyler Ohlsen <ohltyler@amazon.com>
1 parent 988d19a commit cc381ad

File tree

4 files changed

+20
-25
lines changed

4 files changed

+20
-25
lines changed

public/pages/workflow_detail/workflow_detail.tsx

+1-13
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { EuiPage, EuiPageBody } from '@elastic/eui';
1212
import { BREADCRUMBS } from '../../utils';
1313
import { getCore } from '../../services';
1414
import { WorkflowDetailHeader } from './components';
15-
import { AppState, fetchIndices } from '../../store';
15+
import { AppState } from '../../store';
1616
import { ResizableWorkspace } from './workspace';
1717
import { Launches } from './launches';
1818
import { Prototype } from './prototype';
@@ -48,13 +48,6 @@ function replaceActiveTab(activeTab: string, props: WorkflowDetailProps) {
4848
*/
4949
export function WorkflowDetail(props: WorkflowDetailProps) {
5050
const { workflows } = useSelector((state: AppState) => state.workflows);
51-
const { indices, loading } = useSelector(
52-
(state: AppState) => state.opensearch
53-
);
54-
55-
console.log('indices fetched: ', indices);
56-
console.log('workflows fetched: ', workflows);
57-
console.log('loading: ', loading);
5851

5952
const workflow = workflows.find(
6053
(wf) => wf.id === props.match?.params?.workflowId
@@ -79,11 +72,6 @@ export function WorkflowDetail(props: WorkflowDetailProps) {
7972
}
8073
}, []);
8174

82-
useEffect(() => {
83-
console.log('fetching indices...');
84-
fetchIndices('opensearch_dashboards_*');
85-
}, []);
86-
8775
useEffect(() => {
8876
getCore().chrome.setBreadcrumbs([
8977
BREADCRUMBS.FLOW_FRAMEWORK,

public/route_service.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export function configureRoutes(core: CoreStart): RouteService {
1515
return {
1616
searchIndex: async (indexName: string, body: {}) => {
1717
try {
18-
const response = await core.http.post<{ respString: string }>(
18+
const response = await core.http.get<{ respString: string }>(
1919
`${SEARCH_INDICES_PATH}/${indexName}`,
2020
{
2121
body: JSON.stringify(body),
@@ -28,7 +28,7 @@ export function configureRoutes(core: CoreStart): RouteService {
2828
},
2929
fetchIndices: async (pattern: string) => {
3030
try {
31-
const response = await core.http.post<{ respString: string }>(
31+
const response = await core.http.get<{ respString: string }>(
3232
`${FETCH_INDICES_PATH}/${pattern}`
3333
);
3434
return response;

public/store/reducers/opensearch_reducer.ts

+12-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import { createAsyncThunk, createSlice } from '@reduxjs/toolkit';
77
import { getRouteService } from '../../services';
88
import { Index } from '../../../common';
9+
import { HttpFetchError } from '../../../../../src/core/public';
910

1011
const initialState = {
1112
loading: false,
@@ -18,11 +19,19 @@ const FETCH_INDICES_ACTION = `${OPENSEARCH_PREFIX}/fetchIndices`;
1819

1920
export const fetchIndices = createAsyncThunk(
2021
FETCH_INDICES_ACTION,
21-
async (pattern?: string) => {
22+
async (pattern: string, { rejectWithValue }) => {
2223
// defaulting to fetch everything except system indices (starting with '.')
2324
const patternString = pattern || '*,-.*';
24-
const response = getRouteService().fetchIndices(patternString);
25-
return response;
25+
const response: any | HttpFetchError = await getRouteService().fetchIndices(
26+
patternString
27+
);
28+
if (response instanceof HttpFetchError) {
29+
return rejectWithValue(
30+
'Error fetching indices: ' + response.body.message
31+
);
32+
} else {
33+
return response;
34+
}
2635
}
2736
);
2837

server/routes/opensearch_routes_service.ts

+5-7
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export function registerOpenSearchRoutes(
1919
router: IRouter,
2020
opensearchRoutesService: OpenSearchRoutesService
2121
): void {
22-
router.post(
22+
router.get(
2323
{
2424
path: `${SEARCH_INDICES_PATH}/{index_name}`,
2525
validate: {
@@ -32,7 +32,7 @@ export function registerOpenSearchRoutes(
3232
opensearchRoutesService.searchIndex
3333
);
3434

35-
router.post(
35+
router.get(
3636
{
3737
path: `${FETCH_INDICES_PATH}/{pattern}`,
3838
validate: {
@@ -69,7 +69,7 @@ export class OpenSearchRoutesService {
6969
try {
7070
const response = await this.client
7171
.asScoped(req)
72-
.callAsCurrentUser.search(params);
72+
.callAsCurrentUser('search', params);
7373
return res.ok({ body: response });
7474
} catch (err: any) {
7575
return generateCustomError(res, err);
@@ -82,19 +82,17 @@ export class OpenSearchRoutesService {
8282
res: OpenSearchDashboardsResponseFactory
8383
): Promise<IOpenSearchDashboardsResponse<any>> => {
8484
const { pattern } = req.params;
85-
console.log('in fetchIndices()');
86-
console.log('pattern: ', pattern);
8785
try {
8886
const response = await this.client
8987
.asScoped(req)
90-
.callAsCurrentUser.cat.indices({
88+
.callAsCurrentUser('cat.indices', {
9189
index: pattern,
9290
format: 'json',
9391
h: 'health,index',
9492
});
9593

9694
// re-formatting the index results to match Index
97-
const cleanedIndices = response.body.map((index) => ({
95+
const cleanedIndices = response.map((index: any) => ({
9896
name: index.index,
9997
health: index.health,
10098
})) as Index[];

0 commit comments

Comments
 (0)