Skip to content
This repository has been archived by the owner on Jun 6, 2024. It is now read-only.

[Web Portal] Replace the suffix if a cloned job is resubmited #2451

Merged
merged 3 commits into from
Apr 1, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/webportal/config/webpack.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ const config = (env, argv) => ({
fs: 'empty',
process: true,
module: false,
Buffer: true,
},
});

Expand Down
24 changes: 21 additions & 3 deletions src/webportal/src/app/job/job-submit/job-submit.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const userAuth = require('../../user/user-auth/user-auth.component');
const jobSchema = require('./job-submit.schema.js');
const querystring = require('querystring');
const stripJsonComments = require('strip-json-comments');
const uuid = require('uuid');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have not seen the uuid included in package.json, and I don't think uuid is required here. In browser side, uuid just uses crypto level random number instead of Math.random() to avoid more collisions, since we have a directly response when user is submitting with the same job name, so I don't think avoid more collisions here is important.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed


const jobSubmitHtml = jobSubmitComponent({
breadcrumb: breadcrumbComponent,
Expand All @@ -37,6 +38,15 @@ const jobSubmitHtml = jobSubmitComponent({
let editor;
let jobDefaultConfig;

const getChecksum = (str) => {
const buffer = Buffer.from(str);
let res = 0;
buffer.forEach((x) => {
res = res ^ x;
});
return res.toString(16);
};

const isValidJson = (str) => {
let valid = true;
let errors = null;
Expand Down Expand Up @@ -173,9 +183,17 @@ $(document).ready(() => {
url: url,
type: 'GET',
success: (data) => {
let jobConfigObj = JSON.parse(data);
let timestamp = Date.now();
jobConfigObj.jobName += `_${timestamp}`;
let jobConfigObj = data;
if (typeof(jobConfigObj) === 'string') {
jobConfigObj = JSON.parse(data);
}
let name = jobConfigObj.jobName;
if (/_\w{8}$/.test(name) && getChecksum(name.slice(0, -2)) === name.slice(-2)) {
name = name.slice(0, -9);
}
name = `${name}_${uuid().substr(0, 6)}`;
name = name + getChecksum(name);
jobConfigObj.jobName = name;
editor.setValue(Object.assign({}, jobDefaultConfig, jobConfigObj));
},
error: (xhr, textStatus, error) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,11 @@ $(document).ready(() => {
if (type != null && username != null && jobname != null) {
const url = `${webportalConfig.restServerUri}/api/v1/user/${username}/jobs/${jobname}/config`;
$.get(url, (data) => {
userTemplate.updatePageFromYaml(data);
if (typeof data === 'string') {
userTemplate.updatePageFromYaml(data);
} else {
userTemplate.updatePageFromJson(data);
}
$('#submitJob').attr('disabled', false);
});
}
Expand Down