Skip to content

Commit

Permalink
Add MDS support for policies, policy managed indices, transform and r…
Browse files Browse the repository at this point in the history
…ollup jobs

Signed-off-by: Prabhat Sharma <[email protected]>
  • Loading branch information
Prabhat Sharma committed Apr 3, 2024
1 parent b151b85 commit 18fe432
Show file tree
Hide file tree
Showing 49 changed files with 1,292 additions and 802 deletions.
2 changes: 1 addition & 1 deletion public/JobHandler/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export { listenEvent, destroyListener, EVENT_MAP } from "./utils";

export async function JobHandlerRegister(core: CoreSetup) {
const commonService = new CommonService(core.http);
const accountResult = await commonService.apiCaller<{
const accountResult = await commonService.accountInfo<{
user_name: string;
}>({
endpoint: "transport.request",
Expand Down
32 changes: 29 additions & 3 deletions public/pages/ChangePolicy/containers/ChangePolicy/ChangePolicy.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 { RouteComponentProps } from "react-router-dom";
import { EuiSpacer, EuiTitle, EuiButton, EuiFlexGroup, EuiFlexItem, EuiButtonEmpty } from "@elastic/eui";
import { IndexService, ManagedIndexService } from "../../../../services";
Expand All @@ -14,8 +14,10 @@ import { ManagedIndexItem } from "../../../../../models/interfaces";
import { getErrorMessage } from "../../../../utils/helpers";
import { PolicyOption } from "../../models/interfaces";
import { CoreServicesContext } from "../../../../components/core_services";
import { DataSourceMenuContext, DataSourceMenuProperties } from "../../../../services/DataSourceMenuContext";
import { useUpdateUrlWithDataSourceProperties } from "../../../../components/MDSEnabledComponent";

interface ChangePolicyProps extends RouteComponentProps {
interface ChangePolicyProps extends RouteComponentProps, DataSourceMenuProperties {
managedIndexService: ManagedIndexService;
indexService: IndexService;
}
Expand All @@ -36,7 +38,7 @@ export enum Radio {
State = "state",
}

export default class ChangePolicy extends Component<ChangePolicyProps, ChangePolicyState> {
export class ChangePolicy extends Component<ChangePolicyProps, ChangePolicyState> {
static contextType = CoreServicesContext;
state: ChangePolicyState = {
selectedPolicies: [],
Expand All @@ -53,6 +55,22 @@ export default class ChangePolicy extends Component<ChangePolicyProps, ChangePol
this.context.chrome.setBreadcrumbs([BREADCRUMBS.INDEX_MANAGEMENT, BREADCRUMBS.MANAGED_INDICES, BREADCRUMBS.CHANGE_POLICY]);
}

componentDidUpdate(prevProps: ChangePolicyProps, prevState: Readonly<ChangePolicyState>) {
if (prevProps.dataSourceId != this.props.dataSourceId) {
// reset the state, if dataSourceId changes, i.e., clear state
this.setState({
selectedPolicies: [],
selectedManagedIndices: [],
selectedStateFilters: [],
stateRadioIdSelected: Radio.Current,
stateSelected: "",
managedIndicesError: "",
selectedPoliciesError: "",
hasSubmitted: false,
});
}
}

onChangeSelectedPolicy = (selectedPolicies: PolicyOption[]): void => {
// reset the selected state and radio whenever we select a new policy
const selectedPoliciesError = selectedPolicies.length ? "" : "Required";
Expand Down Expand Up @@ -151,6 +169,7 @@ export default class ChangePolicy extends Component<ChangePolicyProps, ChangePol
<EuiSpacer />

<ChangeManagedIndices
key={`changeManagedIndices-${this.props.dataSourceId}`}
{...this.props}
managedIndexService={managedIndexService}
selectedManagedIndices={selectedManagedIndices}
Expand All @@ -163,6 +182,7 @@ export default class ChangePolicy extends Component<ChangePolicyProps, ChangePol
<EuiSpacer />

<NewPolicy
key={`newPolicy-${this.props.dataSourceId}`}
{...this.props}
indexService={indexService}
selectedPolicies={selectedPolicies}
Expand Down Expand Up @@ -192,3 +212,9 @@ export default class ChangePolicy extends Component<ChangePolicyProps, ChangePol
);
}
}

export default function (props: Omit<ChangePolicyProps, keyof DataSourceMenuProperties>) {
const dataSourceMenuProperties = useContext(DataSourceMenuContext);
useUpdateUrlWithDataSourceProperties();
return <ChangePolicy {...props} {...dataSourceMenuProperties} />;
}
30 changes: 27 additions & 3 deletions public/pages/CreatePolicy/containers/CreatePolicy/CreatePolicy.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, Fragment } from "react";
import React, { ChangeEvent, Component, Fragment, useContext } from "react";
import { EuiSpacer, EuiTitle, EuiFlexGroup, EuiFlexItem, EuiButton, EuiButtonEmpty, EuiCallOut, EuiLink, EuiIcon } from "@elastic/eui";
import queryString from "query-string";
import { RouteComponentProps } from "react-router-dom";
Expand All @@ -15,8 +15,10 @@ import { PolicyService } from "../../../../services";
import { BREADCRUMBS, DOCUMENTATION_URL, ROUTES } from "../../../../utils/constants";
import { getErrorMessage } from "../../../../utils/helpers";
import { CoreServicesContext } from "../../../../components/core_services";
import { DataSourceMenuContext, DataSourceMenuProperties } from "../../../../services/DataSourceMenuContext";
import { useUpdateUrlWithDataSourceProperties } from "../../../../components/MDSEnabledComponent";

interface CreatePolicyProps extends RouteComponentProps {
interface CreatePolicyProps extends RouteComponentProps, DataSourceMenuProperties {
isEdit: boolean;
policyService: PolicyService;
}
Expand All @@ -32,7 +34,7 @@ interface CreatePolicyState {
hasSubmitted: boolean;
}

export default class CreatePolicy extends Component<CreatePolicyProps, CreatePolicyState> {
export class CreatePolicy extends Component<CreatePolicyProps, CreatePolicyState> {
static contextType = CoreServicesContext;
_isMount: boolean;
constructor(props: CreatePolicyProps) {
Expand Down Expand Up @@ -78,6 +80,22 @@ export default class CreatePolicy extends Component<CreatePolicyProps, CreatePol
this._isMount = false;
}

componentDidUpdate(prevProps: CreatePolicyProps, prevState: Readonly<CreatePolicyState>) {
if (prevProps.dataSourceId != this.props.dataSourceId) {
// reset the state, if dataSourceId changes, i.e., clear state
this.setState({
policySeqNo: null,
policyPrimaryTerm: null,
policyId: "",
policyIdError: "",
submitError: "",
jsonString: DEFAULT_POLICY,
isSubmitting: false,
hasSubmitted: false,
});
}
}

getPolicyToEdit = async (policyId: string): Promise<void> => {
try {
const { policyService } = this.props;
Expand Down Expand Up @@ -250,3 +268,9 @@ export default class CreatePolicy extends Component<CreatePolicyProps, CreatePol
);
}
}

export default function (props: Omit<CreatePolicyProps, keyof DataSourceMenuProperties>) {
const dataSourceMenuProperties = useContext(DataSourceMenuContext);
useUpdateUrlWithDataSourceProperties();
return <CreatePolicy {...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 { 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 Down Expand Up @@ -53,7 +55,7 @@ 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 />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
* 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 { RouteComponentProps, useHistory } from "react-router-dom";
import moment from "moment";
import { RollupService } from "../../../../services";
import { BREADCRUMBS, ROUTES } from "../../../../utils/constants";
Expand All @@ -21,8 +21,15 @@ import CreateRollupStep3 from "../CreateRollupStep3";
import CreateRollupStep4 from "../CreateRollupStep4";
import { compareFieldItem, parseFieldOptions } from "../../utils/helpers";
import { CoreServicesContext } from "../../../../components/core_services";

interface CreateRollupFormProps extends RouteComponentProps {
import {
DataSourceMenuContext,
DataSourceMenuProperties,
DataSourceMenuReadOnlyContext,
DataSourceMenuReadOnlyProperties,
} from "../../../../services/DataSourceMenuContext";
import { useUpdateUrlWithDataSourceProperties } from "../../../../components/MDSEnabledComponent";

interface CreateRollupFormProps extends RouteComponentProps, DataSourceMenuProperties, DataSourceMenuReadOnlyProperties {
rollupService: RollupService;
indexService: IndexService;
}
Expand Down Expand Up @@ -75,7 +82,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 +150,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 @@ -171,6 +231,14 @@ export default class CreateRollupForm extends Component<CreateRollupFormProps, C
_next() {
let currentStep = this.state.currentStep;
let error = false;

const dataSourceReadOnly = this.props.dataSourceReadOnly;
const setDataSourceReadOnly = this.props.setDataSourceReadOnly;

if (!dataSourceReadOnly) {
setDataSourceReadOnly(true);
}

//Verification here
if (currentStep == 1) {
const { rollupId, sourceIndex, targetIndex } = this.state;
Expand Down Expand Up @@ -234,6 +302,14 @@ export default class CreateRollupForm extends Component<CreateRollupFormProps, C
let currentStep = this.state.currentStep;
// If the current step is 2 or 3, then subtract one on "previous" button click
currentStep = currentStep <= 1 ? 1 : currentStep - 1;
if (currentStep == 1) {
const dataSourceReadOnly = this.props.dataSourceReadOnly;
const setDataSourceReadOnly = this.props.setDataSourceReadOnly;

if (dataSourceReadOnly) {
setDataSourceReadOnly(false);
}
}
this.setState({
currentStep: currentStep,
});
Expand Down Expand Up @@ -680,3 +756,10 @@ export default class CreateRollupForm extends Component<CreateRollupFormProps, C
);
}
}

export default function (props: Omit<CreateRollupFormProps, keyof DataSourceMenuProperties>) {
const dataSourceReadOnlyProperties = useContext(DataSourceMenuReadOnlyContext);
const dataSourceMenuProperties = useContext(DataSourceMenuContext);
useUpdateUrlWithDataSourceProperties();
return <CreateRollupForm {...props} {...dataSourceMenuProperties} {...dataSourceReadOnlyProperties} />;
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export default function DefineTransforms({
const fetchData = useCallback(async () => {
setLoading(true);
try {
const response = await transformService.searchSampleData(sourceIndex, { from: 0, size: DefaultSampleDataSize }, sourceIndexFilter);
const response = await transformService.searchSampleData(sourceIndex, sourceIndexFilter, { from: 0, size: DefaultSampleDataSize });

if (response.ok) {
setData(response.response.data);
Expand Down Expand Up @@ -162,7 +162,7 @@ export default function DefineTransforms({
}
const val = data[rowIndex]._source[columnId];
return val !== undefined ? JSON.stringify(val) : "-";
}
};

//TODO: remove duplicate code here after extracting the first table as separate component
if (isReadOnly)
Expand Down
Loading

0 comments on commit 18fe432

Please sign in to comment.