Skip to content

Commit

Permalink
check pipeline size on change and before save / deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
GnsP committed Feb 28, 2025
1 parent 1123ad4 commit 45e6fd3
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
11 changes: 11 additions & 0 deletions app/hydrator/controllers/create/toppanel-ctrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,7 @@ class HydratorPlusPlusTopPanelCtrl {
this.checkNameError();
}
onPublishV2(isEdit = false) {
if (!this.HydratorPlusPlusConfigStore.checkPipelineJsonSize()) return;
this.HydratorPlusPlusConfigActions.publishPipeline(isEdit);
this.checkNameError();
}
Expand Down Expand Up @@ -1456,6 +1457,16 @@ class HydratorPlusPlusTopPanelCtrl {
}

let uploadedFile = files[0];

const MB = 1024 * 1024; // Bytes
if (files[0].size > 2 * MB) {
const fileSizeInMB = ((files[0].size || 1) / MB).toFixed(2);
this.myAlertOnValium.show({
type: "danger",
content: `File size is ${fileSizeInMB}MB. Pipelines larger than 2MB are not supported.`,
});
return;
}
this.HydratorUpgradeService.validateAndUpgradeConfigFile(uploadedFile, this.getParentVersion());
}

Expand Down
26 changes: 25 additions & 1 deletion app/hydrator/services/create/stores/config-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

class HydratorPlusPlusConfigStore {
constructor(HydratorPlusPlusConfigDispatcher, HydratorPlusPlusCanvasFactory, GLOBALS, mySettings, HydratorPlusPlusConsoleActions, $stateParams, NonStorePipelineErrorFactory, HydratorPlusPlusHydratorService, $q, HydratorPlusPlusPluginConfigFactory, uuid, $state, HYDRATOR_DEFAULT_VALUES, myHelpers, MY_CONFIG, EventPipe, myPipelineApi, myAppsApi, HydratorPlusPlusNodeService) {
constructor(HydratorPlusPlusConfigDispatcher, HydratorPlusPlusCanvasFactory, GLOBALS, mySettings, HydratorPlusPlusConsoleActions, $stateParams, NonStorePipelineErrorFactory, HydratorPlusPlusHydratorService, $q, HydratorPlusPlusPluginConfigFactory, uuid, $state, HYDRATOR_DEFAULT_VALUES, myHelpers, MY_CONFIG, EventPipe, myPipelineApi, myAppsApi, HydratorPlusPlusNodeService, myAlertOnValium) {
'ngInject';
this.state = {};
this.mySettings = mySettings;
Expand All @@ -36,6 +36,7 @@ class HydratorPlusPlusConfigStore {
this.myPipelineApi = myPipelineApi;
this.myAppsApi = myAppsApi;
this.isDistributed = MY_CONFIG.isEnterprise ? true : false;
this.myAlertOnValium = myAlertOnValium;

this.changeListeners = [];
this.setDefaults();
Expand Down Expand Up @@ -70,7 +71,28 @@ class HydratorPlusPlusConfigStore {
this.changeListeners.splice(index, 1);
};
}
checkPipelineJsonSize() {
const MB = 1024 * 1024; // Bytes
try {
const pipelineJson = this.getConfigForExport();
delete pipelineJson.__ui__;
const jsonBlob = new Blob([JSON.stringify(pipelineJson, null, 4)], { type: 'application/json' });
const blobSize = jsonBlob.size || 1;
const blobSizeInMBRounded = (blobSize / MB).toFixed(2);
if (jsonBlob.size > 2 * MB) {
this.myAlertOnValium.show({
type: "danger",
content: `Pipeline size is ${blobSizeInMBRounded}MB. Pipelines larger than 2MB are not supported.`,
});
return false;
}
} catch (e) {
// pass
}
return true;
}
emitChange() {
this.checkPipelineJsonSize();
this.changeListeners.forEach( callback => callback() );
}
setDefaults(config) {
Expand Down Expand Up @@ -1208,6 +1230,8 @@ class HydratorPlusPlusConfigStore {
return;
}

if (!this.HydratorPlusPlusConfigStore.checkPipelineJsonSize()) return;

let config = this.getConfigForExport({ shouldPruneProperties: false });
const draftId = this.getDraftId() || this.uuid.v4();
const params = {
Expand Down

0 comments on commit 45e6fd3

Please sign in to comment.