Skip to content

Commit

Permalink
Added MDS for rollup
Browse files Browse the repository at this point in the history
  • Loading branch information
Prabhat Sharma committed Mar 28, 2024
1 parent 9d84ef8 commit 1d392b3
Show file tree
Hide file tree
Showing 9 changed files with 160 additions and 55 deletions.
16 changes: 12 additions & 4 deletions public/pages/CreateRollup/containers/CreateRollup/CreateRollup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

import React, { ChangeEvent, Component } from "react";
import React, { ChangeEvent, Component, useContext } from "react";
import { EuiSpacer, EuiTitle, EuiFlexGroup, EuiFlexItem, EuiComboBoxOptionOption } from "@elastic/eui";
import { RouteComponentProps } from "react-router-dom";
import { RollupService } from "../../../../services";
Expand All @@ -12,8 +12,10 @@ import RollupIndices from "../../components/RollupIndices";
import CreateRollupSteps from "../../components/CreateRollupSteps";
import IndexService from "../../../../services/IndexService";
import { IndexItem } from "../../../../../models/interfaces";
import { DataSourceMenuContext, DataSourceMenuProperties } from "../../../../services/DataSourceMenuContext";
import { useUpdateUrlWithDataSourceProperties } from "../../../../components/MDSEnabledComponent";

interface CreateRollupProps extends RouteComponentProps {
interface CreateRollupProps extends RouteComponentProps, DataSourceMenuProperties {
rollupService: RollupService;
indexService: IndexService;
rollupId: string;
Expand All @@ -34,7 +36,7 @@ interface CreateRollupProps extends RouteComponentProps {
hasAggregation: boolean;
}

export default class CreateRollup extends Component<CreateRollupProps> {
export class CreateRollup extends Component<CreateRollupProps> {
render() {
if (this.props.currentStep !== 1) {
return null;
Expand All @@ -53,11 +55,17 @@ export default class CreateRollup extends Component<CreateRollupProps> {
<EuiSpacer />
<ConfigureRollup isEdit={false} {...this.props} />
<EuiSpacer />
<RollupIndices {...this.props} />
<RollupIndices key={this.props.dataSourceId} {...this.props} />
</EuiFlexItem>
</EuiFlexGroup>
<EuiSpacer />
</div>
);
}
}

export default function (props: CreateRollupProps) {
const dataSourceMenuProperties = useContext(DataSourceMenuContext);
useUpdateUrlWithDataSourceProperties();
return <CreateRollup {...props} {...dataSourceMenuProperties} />;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

import React, { ChangeEvent, Component } from "react";
import React, { ChangeEvent, Component, useContext } from "react";
import { EuiButton, EuiButtonEmpty, EuiComboBoxOptionOption, EuiFlexGroup, EuiFlexItem } from "@elastic/eui";
import { RouteComponentProps } from "react-router-dom";
import moment from "moment";
Expand All @@ -21,8 +21,10 @@ import CreateRollupStep3 from "../CreateRollupStep3";
import CreateRollupStep4 from "../CreateRollupStep4";
import { compareFieldItem, parseFieldOptions } from "../../utils/helpers";
import { CoreServicesContext } from "../../../../components/core_services";
import { DataSourceMenuContext, DataSourceMenuProperties } from "../../../../services/DataSourceMenuContext";
import { useUpdateUrlWithDataSourceProperties } from "../../../../components/MDSEnabledComponent";

interface CreateRollupFormProps extends RouteComponentProps {
interface CreateRollupFormProps extends RouteComponentProps, DataSourceMenuProperties {
rollupService: RollupService;
indexService: IndexService;
}
Expand Down Expand Up @@ -75,7 +77,7 @@ interface CreateRollupFormState {
rollupJSON: any;
}

export default class CreateRollupForm extends Component<CreateRollupFormProps, CreateRollupFormState> {
export class CreateRollupForm extends Component<CreateRollupFormProps, CreateRollupFormState> {
static contextType = CoreServicesContext;
_isMount: boolean;

Expand Down Expand Up @@ -143,6 +145,59 @@ export default class CreateRollupForm extends Component<CreateRollupFormProps, C
this._isMount = false;
}

componentDidUpdate(prevProps: CreateRollupFormProps, prevState: Readonly<CreateRollupFormState>) {
if (prevProps.dataSourceId != this.props.dataSourceId) {
// reset the state, if dataSourceId changes, i.e., clear state
this.setState({
currentStep: 1,
rollupSeqNo: null,
rollupPrimaryTerm: null,
rollupId: "",
rollupIdError: "",
submitError: "",
isSubmitting: false,
hasSubmitted: false,
loadingIndices: true,
indices: [],
totalIndices: 0,

mappings: "",
allMappings: [],
fields: [],
selectedFields: [],
selectedTerms: [],
selectedDimensionField: [],
selectedMetrics: [],
metricError: "",

sourceIndex: [],
sourceIndexError: "",
targetIndex: [],
targetIndexError: "",

timestamp: [],
timestampError: "",
intervalType: "fixed",
intervalValue: 1,
intervalError: "",
timezone: "UTC",
timeunit: "h",

jobEnabledByDefault: true,
continuousJob: "no",
continuousDefinition: "fixed",
interval: 1,
intervalTimeunit: "MINUTES",
cronExpression: "",
cronTimezone: "UTC",
pageSize: 1000,
delayTime: undefined,
delayTimeunit: "MINUTES",
rollupJSON: JSON.parse(EMPTY_ROLLUP),
});
}
}

getMappings = async (srcIndex: string): Promise<void> => {
if (!srcIndex.length) return;
try {
Expand Down Expand Up @@ -680,3 +735,9 @@ export default class CreateRollupForm extends Component<CreateRollupFormProps, C
);
}
}

export default function (props: Omit<CreateRollupFormProps, keyof DataSourceMenuProperties>) {
const dataSourceMenuProperties = useContext(DataSourceMenuContext);
useUpdateUrlWithDataSourceProperties();
return <CreateRollupForm {...props} {...dataSourceMenuProperties} />;
}
5 changes: 5 additions & 0 deletions public/pages/Main/Main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ const dataSourceEnabledPaths: string[] = [
ROUTES.COMPOSABLE_TEMPLATES,
ROUTES.CREATE_COMPOSABLE_TEMPLATE,
ROUTES.REINDEX,
ROUTES.ROLLUPS,
ROUTES.CREATE_ROLLUP,
];

export default class Main extends Component<MainProps, MainState> {
Expand Down Expand Up @@ -212,6 +214,7 @@ export default class Main extends Component<MainProps, MainState> {
services.managedIndexService = new ManagedIndexService(http, this.state.dataSourceId, this.props.multiDataSourceEnabled);
services.policyService = new PolicyService(http, this.state.dataSourceId, this.props.multiDataSourceEnabled);
services.notificationService = new NotificationService(http, this.state.dataSourceId, this.props.multiDataSourceEnabled);
services.rollupService = new RollupService(http, this.state.dataSourceId, this.props.multiDataSourceEnabled);
}
return services;
}
Expand Down Expand Up @@ -390,6 +393,8 @@ export default class Main extends Component<MainProps, MainState> {
ROUTES.CREATE_POLICY,
ROUTES.CHANGE_POLICY,
ROUTES.TRANSFORMS,
ROUTES.ROLLUPS,
ROUTES.CREATE_ROLLUP,
]}
render={() => (
<DataSourceMenu
Expand Down
32 changes: 24 additions & 8 deletions public/pages/Rollups/containers/Rollups/Rollups.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

import React, { Component } from "react";
import React, { Component, useContext } from "react";
import _ from "lodash";
import { BREADCRUMBS, ROUTES } from "../../../../utils/constants";
import queryString from "query-string";
Expand Down Expand Up @@ -43,12 +43,15 @@ import DeleteModal from "../../components/DeleteModal";
import { renderStatus } from "../../../RollupDetails/utils/helpers";
import { DocumentRollup } from "../../../../../models/interfaces";
import { CoreServicesContext } from "../../../../components/core_services";
import { DataSourceMenuContext, DataSourceMenuProperties } from "../../../../services/DataSourceMenuContext";
import MDSEnabledComponent from "../../../../components/MDSEnabledComponent";
import { HttpFetchQuery } from "opensearch-dashboards/public";

interface RollupsProps extends RouteComponentProps {
interface RollupsProps extends RouteComponentProps, DataSourceMenuProperties {
rollupService: RollupService;
}

interface RollupsState {
interface RollupsState extends DataSourceMenuProperties {
totalRollups: number;
from: number;
size: number;
Expand All @@ -63,7 +66,7 @@ interface RollupsState {
isDeleteModalVisible: boolean;
}

export default class Rollups extends Component<RollupsProps, RollupsState> {
export class Rollups extends MDSEnabledComponent<RollupsProps, RollupsState> {
static contextType = CoreServicesContext;
constructor(props: RollupsProps) {
super(props);
Expand Down Expand Up @@ -101,18 +104,26 @@ export default class Rollups extends Component<RollupsProps, RollupsState> {
}
}

static getQueryObjectFromState({ from, size, search, sortField, sortDirection }: RollupsState): RollupQueryParams {
return { from, size, search, sortField, sortDirection };
static getQueryObjectFromState({
from,
size,
search,
sortField,
sortDirection,
dataSourceId,
multiDataSourceEnabled,
}: RollupsState): RollupQueryParams {
return { from, size, search, sortField, sortDirection, ...(multiDataSourceEnabled ? { dataSourceId } : {}) };
}

getRollups = async (): Promise<void> => {
this.setState({ loadingRollups: true });
try {
const { rollupService, history } = this.props;
const queryObject = Rollups.getQueryObjectFromState(this.state);
const queryParamsString = queryString.stringify(Rollups.getQueryObjectFromState(this.state));
const queryParamsString = queryString.stringify({ ...queryObject, dataSourceLabel: this.state.dataSourceLabel });
history.replace({ ...this.props.location, search: queryParamsString });
const rollupJobsResponse = await rollupService.getRollups(queryObject);
const rollupJobsResponse = await rollupService.getRollups(queryObject); // Add type assertion
if (rollupJobsResponse.ok) {
const { rollups, totalRollups, metadata } = rollupJobsResponse.response;
this.setState({ rollups, totalRollups, rollupExplain: metadata });
Expand Down Expand Up @@ -480,3 +491,8 @@ export default class Rollups extends Component<RollupsProps, RollupsState> {
);
}
}

export default function (props: Omit<RollupsProps, keyof DataSourceMenuProperties>) {
const dataSourceMenuProps = useContext(DataSourceMenuContext);
return <Rollups {...props} {...dataSourceMenuProps} />;
}
34 changes: 19 additions & 15 deletions public/services/RollupService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,17 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { HttpSetup } from "opensearch-dashboards/public";
import { HttpFetchQuery, HttpSetup } from "opensearch-dashboards/public";
import { PutRollupResponse, GetRollupsResponse, GetFieldsResponse } from "../../server/models/interfaces";
import { ServerResponse } from "../../server/models/types";
import { NODE_API } from "../../utils/constants";
import { DocumentRollup, Rollup } from "../../models/interfaces";
import { MDSEnabledClientService } from "./MDSEnabledClientService";

export default class RollupService {
httpClient: HttpSetup;

constructor(httpClient: HttpSetup) {
this.httpClient = httpClient;
}

getRollups = async (queryObject: object): Promise<ServerResponse<GetRollupsResponse>> => {
export default class RollupService extends MDSEnabledClientService {
getRollups = async (queryObject?: HttpFetchQuery): Promise<ServerResponse<GetRollupsResponse>> => {
let url = `..${NODE_API.ROLLUPS}`;
queryObject = this.patchQueryObjectWithDataSourceId(queryObject);
const response = (await this.httpClient.get(url, { query: queryObject })) as ServerResponse<GetRollupsResponse>;
return response;
};
Expand All @@ -29,41 +25,49 @@ export default class RollupService {
primaryTerm?: number
): Promise<ServerResponse<PutRollupResponse>> => {
let url = `..${NODE_API.ROLLUPS}/${rollupId}`;
const response = (await this.httpClient.put(url, { query: { seqNo, primaryTerm }, body: JSON.stringify(rollup) })) as ServerResponse<
let queryObject = this.patchQueryObjectWithDataSourceId({ seqNo, primaryTerm });
const response = (await this.httpClient.put(url, { query: queryObject, body: JSON.stringify(rollup) })) as ServerResponse<
PutRollupResponse
>;
return response;
};

getRollup = async (rollupId: string): Promise<ServerResponse<DocumentRollup>> => {
const url = `..${NODE_API.ROLLUPS}/${rollupId}`;
const response = (await this.httpClient.get(url)) as ServerResponse<DocumentRollup>;
const queryObject = this.patchQueryObjectWithDataSourceId();
const response = (await this.httpClient.get(url, { query: queryObject })) as ServerResponse<DocumentRollup>;
return response;
};

deleteRollup = async (rollupId: string): Promise<ServerResponse<boolean>> => {
const url = `..${NODE_API.ROLLUPS}/${rollupId}`;
const response = (await this.httpClient.delete(url)) as ServerResponse<boolean>;
const queryObject = this.patchQueryObjectWithDataSourceId();
const response = (await this.httpClient.delete(url, { query: queryObject })) as ServerResponse<boolean>;
return response;
};

startRollup = async (rollupId: string): Promise<ServerResponse<boolean>> => {
const url = `..${NODE_API.ROLLUPS}/${rollupId}/_start`;
const response = (await this.httpClient.post(url)) as ServerResponse<boolean>;
const queryObject = this.patchQueryObjectWithDataSourceId();
const response = (await this.httpClient.post(url, { query: queryObject })) as ServerResponse<boolean>;
return response;
};

stopRollup = async (rollupId: string): Promise<ServerResponse<boolean>> => {
const url = `..${NODE_API.ROLLUPS}/${rollupId}/_stop`;
const response = (await this.httpClient.post(url)) as ServerResponse<boolean>;
const queryObject = this.patchQueryObjectWithDataSourceId();
const response = (await this.httpClient.post(url, { query: queryObject })) as ServerResponse<boolean>;
return response;
};

//Function to search for fields from a source index using GET /${source_index}/_mapping
getMappings = async (index: string): Promise<ServerResponse<any>> => {
const url = `..${NODE_API._MAPPINGS}`;
const body = { index: index };
const response = (await this.httpClient.post(url, { body: JSON.stringify(body) })) as ServerResponse<GetFieldsResponse>;
const queryObject = this.patchQueryObjectWithDataSourceId();
const response = (await this.httpClient.post(url, { query: queryObject, body: JSON.stringify(body) })) as ServerResponse<
GetFieldsResponse
>;
return response;
};
}
4 changes: 2 additions & 2 deletions server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export class IndexPatternManagementPlugin implements Plugin<IndexManagementPlugi
const dataStreamService = new DataStreamService(osDriver, dataSourceEnabled);
const policyService = new PolicyService(osDriver, dataSourceEnabled);
const managedIndexService = new ManagedIndexService(osDriver, dataSourceEnabled);
const rollupService = new RollupService(osDriver);
const rollupService = new RollupService(osDriver, dataSourceEnabled);
const transformService = new TransformService(osDriver);
const notificationService = new NotificationService(osDriver, dataSourceEnabled);
const snapshotManagementService = new SnapshotManagementService(osDriver);
Expand Down Expand Up @@ -83,7 +83,7 @@ export class IndexPatternManagementPlugin implements Plugin<IndexManagementPlugi
dataStreams(services, router, dataSourceEnabled);
policies(services, router, dataSourceEnabled);
managedIndices(services, router, dataSourceEnabled);
rollups(services, router);
rollups(services, router, dataSourceEnabled);
transforms(services, router);
notifications(services, router, dataSourceEnabled);
snapshotManagement(services, router);
Expand Down
Loading

0 comments on commit 1d392b3

Please sign in to comment.