Skip to content

Commit

Permalink
Get core APIs working
Browse files Browse the repository at this point in the history
Signed-off-by: Tyler Ohlsen <[email protected]>
  • Loading branch information
ohltyler committed Feb 26, 2024
1 parent 988d19a commit cc381ad
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 25 deletions.
14 changes: 1 addition & 13 deletions public/pages/workflow_detail/workflow_detail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { EuiPage, EuiPageBody } from '@elastic/eui';
import { BREADCRUMBS } from '../../utils';
import { getCore } from '../../services';
import { WorkflowDetailHeader } from './components';
import { AppState, fetchIndices } from '../../store';
import { AppState } from '../../store';
import { ResizableWorkspace } from './workspace';
import { Launches } from './launches';
import { Prototype } from './prototype';
Expand Down Expand Up @@ -48,13 +48,6 @@ function replaceActiveTab(activeTab: string, props: WorkflowDetailProps) {
*/
export function WorkflowDetail(props: WorkflowDetailProps) {
const { workflows } = useSelector((state: AppState) => state.workflows);
const { indices, loading } = useSelector(
(state: AppState) => state.opensearch
);

console.log('indices fetched: ', indices);
console.log('workflows fetched: ', workflows);
console.log('loading: ', loading);

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

useEffect(() => {
console.log('fetching indices...');
fetchIndices('opensearch_dashboards_*');
}, []);

useEffect(() => {
getCore().chrome.setBreadcrumbs([
BREADCRUMBS.FLOW_FRAMEWORK,
Expand Down
4 changes: 2 additions & 2 deletions public/route_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export function configureRoutes(core: CoreStart): RouteService {
return {
searchIndex: async (indexName: string, body: {}) => {
try {
const response = await core.http.post<{ respString: string }>(
const response = await core.http.get<{ respString: string }>(
`${SEARCH_INDICES_PATH}/${indexName}`,
{
body: JSON.stringify(body),
Expand All @@ -28,7 +28,7 @@ export function configureRoutes(core: CoreStart): RouteService {
},
fetchIndices: async (pattern: string) => {
try {
const response = await core.http.post<{ respString: string }>(
const response = await core.http.get<{ respString: string }>(
`${FETCH_INDICES_PATH}/${pattern}`
);
return response;
Expand Down
15 changes: 12 additions & 3 deletions public/store/reducers/opensearch_reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import { createAsyncThunk, createSlice } from '@reduxjs/toolkit';
import { getRouteService } from '../../services';
import { Index } from '../../../common';
import { HttpFetchError } from '../../../../../src/core/public';

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

export const fetchIndices = createAsyncThunk(
FETCH_INDICES_ACTION,
async (pattern?: string) => {
async (pattern: string, { rejectWithValue }) => {
// defaulting to fetch everything except system indices (starting with '.')
const patternString = pattern || '*,-.*';
const response = getRouteService().fetchIndices(patternString);
return response;
const response: any | HttpFetchError = await getRouteService().fetchIndices(
patternString
);
if (response instanceof HttpFetchError) {
return rejectWithValue(
'Error fetching indices: ' + response.body.message
);
} else {
return response;
}
}
);

Expand Down
12 changes: 5 additions & 7 deletions server/routes/opensearch_routes_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function registerOpenSearchRoutes(
router: IRouter,
opensearchRoutesService: OpenSearchRoutesService
): void {
router.post(
router.get(
{
path: `${SEARCH_INDICES_PATH}/{index_name}`,
validate: {
Expand All @@ -32,7 +32,7 @@ export function registerOpenSearchRoutes(
opensearchRoutesService.searchIndex
);

router.post(
router.get(
{
path: `${FETCH_INDICES_PATH}/{pattern}`,
validate: {
Expand Down Expand Up @@ -69,7 +69,7 @@ export class OpenSearchRoutesService {
try {
const response = await this.client
.asScoped(req)
.callAsCurrentUser.search(params);
.callAsCurrentUser('search', params);
return res.ok({ body: response });
} catch (err: any) {
return generateCustomError(res, err);
Expand All @@ -82,19 +82,17 @@ export class OpenSearchRoutesService {
res: OpenSearchDashboardsResponseFactory
): Promise<IOpenSearchDashboardsResponse<any>> => {
const { pattern } = req.params;
console.log('in fetchIndices()');
console.log('pattern: ', pattern);
try {
const response = await this.client
.asScoped(req)
.callAsCurrentUser.cat.indices({
.callAsCurrentUser('cat.indices', {
index: pattern,
format: 'json',
h: 'health,index',
});

// re-formatting the index results to match Index
const cleanedIndices = response.body.map((index) => ({
const cleanedIndices = response.map((index: any) => ({
name: index.index,
health: index.health,
})) as Index[];
Expand Down

0 comments on commit cc381ad

Please sign in to comment.