Skip to content

Commit

Permalink
Merge pull request #1071 from cdapio/bugfix-ui/CDAP-20738
Browse files Browse the repository at this point in the history
[CDAP-20738] Fix pushdown not exported
  • Loading branch information
sumengwang authored Jul 24, 2023
2 parents 65f06e3 + a64bbae commit d9cb454
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,10 @@ export const ConfigModelessActionButtons = ({ ...props }: IConfigModelessActionB

const saveAndAction = (actionFn) => {
setSaveLoading(true);
let observable;
if (lifecycleManagementEditEnabled) {
observable = updatePreferences();
} else {
observable = Observable.forkJoin(updatePipeline(), updatePreferences());
}
const observable = Observable.forkJoin(
updatePipeline(lifecycleManagementEditEnabled),
updatePreferences()
);
observable.subscribe(
() => {
actionFn();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,35 +26,17 @@ import {
convertKeyValuePairsToMap,
convertMapToKeyValuePairs,
flattenObj,
unflatternStringToObj,
getPushdownObjectFromRuntimeArgs,
isPushdownEnabled,
} from 'services/helpers';
import { useFeatureFlagDefaultFalse } from 'services/react/customHooks/useFeatureFlag';

const getPushdownEnabledValue = (state) => {
const pushdownEnabledKeyValuePair = state.runtimeArgs.pairs.find(
(pair) => pair.key === GENERATED_RUNTIMEARGS.PIPELINE_PUSHDOWN_ENABLED
);
return pushdownEnabledKeyValuePair
? pushdownEnabledKeyValuePair.value === 'true'
: state.pushdownEnabled;
return isPushdownEnabled(state.runtimeArgs) || state.pushdownEnabled;
};

const getTransformationPushdownValue = (state) => {
if (state.transformationPushdown) {
return state.transformationPushdown;
}
const transformationPushdownKeyValuePair = state.runtimeArgs.pairs.filter((pair) =>
pair.key.startsWith(GENERATED_RUNTIMEARGS.PIPELINE_TRANSFORMATION_PUSHDOWN_PREFIX)
);
const pushdownObject = {};
transformationPushdownKeyValuePair.forEach((pair) => {
// unflattern the runtimeargs key and put it in pushdown object
const trimmedKey = pair.key.substring(
GENERATED_RUNTIMEARGS.PIPELINE_TRANSFORMATION_PUSHDOWN_PREFIX.length
);
unflatternStringToObj(pushdownObject, trimmedKey, pair.value);
});
return pushdownObject;
return getPushdownObjectFromRuntimeArgs(state.runtimeArgs) || state.transformationPushdown;
};

export default function PushdownTabContent({}) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import uniqBy from 'lodash/uniqBy';
import cloneDeep from 'lodash/cloneDeep';
import { CLOUD } from 'services/global-constants';
import { Observable } from 'rxjs/Observable';
import { of } from 'rxjs/observable/of';
import { map } from 'rxjs/operators';

// Filter certain preferences from being shown in the run time arguments
Expand Down Expand Up @@ -150,7 +151,7 @@ const updatePreferences = () => {
);
};

const updatePipeline = () => {
const updatePipeline = (lifecycleManagementEditEnabled = true) => {
let detailStoreState = PipelineDetailStore.getState();
let { name, description, artifact, principal } = detailStoreState;
let { stages, connections, comments } = detailStoreState.config;
Expand Down Expand Up @@ -225,6 +226,14 @@ const updatePipeline = () => {
config = { ...commonConfig, ...sqlOnlyConfig };
}

if (lifecycleManagementEditEnabled) {
PipelineDetailStore.dispatch({
type: PipelineDetailActions.SET_CONFIG,
payload: { config },
});
return of({});
}

let publishObservable = MyPipelineApi.publish(
{
namespace: getCurrentNamespace(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ import classnames from 'classnames';
import { duplicatePipeline, editPipeline } from 'services/PipelineUtils';
import cloneDeep from 'lodash/cloneDeep';
import downloadFile from 'services/download-file';
import { santizeStringForHTMLID } from 'services/helpers';
import {
getPushdownObjectFromRuntimeArgs,
isPushdownEnabled,
santizeStringForHTMLID,
} from 'services/helpers';
import { deleteEditDraft } from 'components/PipelineList/DeployedPipelineView/store/ActionCreator';
import { DiscardDraftModal } from 'components/shared/DiscardDraftModal';
import { CommitModal } from 'components/SourceControlManagement/LocalPipelineListView/CommitModal';
Expand All @@ -40,6 +44,7 @@ import {
setPullStatus,
setSourceControlMeta,
} from 'components/PipelineDetails/store/ActionCreator';
import PipelineConfigurationsStore from 'components/PipelineConfigurations/Store';
require('./PipelineDetailsActionsButton.scss');

const PREFIX = 'features.PipelineDetails.TopPanel';
Expand Down Expand Up @@ -123,16 +128,24 @@ class PipelineDetailsActionsButton extends Component<IPipelineDetailsActionsButt
};
}

public pipelineConfig = {
name: this.props.pipelineName,
description: this.props.description,
artifact: this.props.artifact,
config: cloneDeep(this.props.config), // currently doing a cloneDeep because angular is mutating this state...
version: this.props.version,
public getPipelineConfig = () => {
const pipelineConfig = {
name: this.props.pipelineName,
description: this.props.description,
artifact: this.props.artifact,
config: cloneDeep(this.props.config), // currently doing a cloneDeep because angular is mutating this state...
version: this.props.version,
};
const { runtimeArgs } = PipelineConfigurationsStore.getState();
pipelineConfig.config.pushdownEnabled = isPushdownEnabled(runtimeArgs);
pipelineConfig.config.transformationPushdown = getPushdownObjectFromRuntimeArgs(runtimeArgs);
return pipelineConfig;
};

public pipelineConfig = this.getPipelineConfig();

public duplicateConfigAndNavigate = () => {
duplicatePipeline(this.props.pipelineName, sanitizeConfig(this.pipelineConfig));
duplicatePipeline(this.props.pipelineName, sanitizeConfig(this.getPipelineConfig()));
};

public toggleDiscardConfirmation = () => {
Expand All @@ -151,7 +164,7 @@ class PipelineDetailsActionsButton extends Component<IPipelineDetailsActionsButt
return;
}
if (!this.props.editDraftId) {
editPipeline(this.props.pipelineName, sanitizeConfig(this.pipelineConfig));
editPipeline(this.props.pipelineName, sanitizeConfig(this.getPipelineConfig()));
return;
}
this.setState({
Expand Down Expand Up @@ -211,7 +224,7 @@ class PipelineDetailsActionsButton extends Component<IPipelineDetailsActionsButt
const closePopoverCb = () => {
this.setState({ showPopover: false });
};
downloadFile(this.pipelineConfig, closePopoverCb);
downloadFile(this.getPipelineConfig(), closePopoverCb);
};

public toggleExportModal = () => {
Expand Down Expand Up @@ -241,7 +254,7 @@ class PipelineDetailsActionsButton extends Component<IPipelineDetailsActionsButt
<PipelineExportModal
isOpen={this.state.showExportModal}
onClose={this.toggleExportModal}
pipelineConfig={sanitizeConfig(this.pipelineConfig)}
pipelineConfig={sanitizeConfig(this.getPipelineConfig())}
onExport={this.handlePipelineExport}
/>
);
Expand Down
37 changes: 36 additions & 1 deletion app/cdap/services/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import isArray from 'lodash/isArray';
// We don't use webpack alias here because this is used in Footer which is used in login app
// And for login 'components/Lab/..' aliases to components folder inside login app.
import experimentsList from '../components/Lab/experiment-list.tsx';
import { GENERATED_RUNTIMEARGS } from './global-constants.js';
/*
Purpose: Query a json object or an array of json objects
Return: Returns undefined if property is not defined(never set) and
Expand Down Expand Up @@ -897,6 +898,38 @@ const PIPELINE_ARTIFACTS = [
'cdap-data-streams',
];

/**
*
* @param {object} runtimeArgs
* @returns a pushdown config object generated from runtimeArgs
*/
const getPushdownObjectFromRuntimeArgs = (runtimeArgs) => {
const transformationPushdownKeyValuePair = runtimeArgs.pairs.filter((pair) =>
pair.key.startsWith(GENERATED_RUNTIMEARGS.PIPELINE_TRANSFORMATION_PUSHDOWN_PREFIX)
);
const pushdownObject = {};
transformationPushdownKeyValuePair.forEach((pair) => {
// unflattern the runtimeargs key and put it in pushdown object
const trimmedKey = pair.key.substring(
GENERATED_RUNTIMEARGS.PIPELINE_TRANSFORMATION_PUSHDOWN_PREFIX.length
);
unflatternStringToObj(pushdownObject, trimmedKey, pair.value);
});
return pushdownObject
}

/**
*
* @param {object} runtimeArgs
* @returns a boolean value if pushdown enabled
*/
const isPushdownEnabled = (runtimeArgs) => {
const pushdownEnabledKeyValuePair = runtimeArgs.pairs.find(
(pair) => pair.key === GENERATED_RUNTIMEARGS.PIPELINE_PUSHDOWN_ENABLED
);
return pushdownEnabledKeyValuePair ? pushdownEnabledKeyValuePair.value === 'true' : false
}

export {
openLinkInNewTab,
objectQuery,
Expand Down Expand Up @@ -959,5 +992,7 @@ export {
unflatternStringToObj,
arrayOfStringsMatchTargetPrefix,
PIPELINE_ARTIFACTS,
BATCH_PIPELINE_TYPE
BATCH_PIPELINE_TYPE,
getPushdownObjectFromRuntimeArgs,
isPushdownEnabled
};

0 comments on commit d9cb454

Please sign in to comment.