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

Commit

Permalink
Binyli/commands (#3074)
Browse files Browse the repository at this point in the history
* auto remove empty lines in command

* fix import secret issue
  • Loading branch information
Binyang2014 authored Jul 5, 2019
1 parent 0af835f commit cfc67e8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 19 deletions.
25 changes: 22 additions & 3 deletions src/webportal/src/app/job-submission/models/job-protocol.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

import {jobProtocolSchema} from '../models/protocol-schema';

import {get, isEmpty} from 'lodash';
import {get, isEmpty, cloneDeep} from 'lodash';
import yaml from 'js-yaml';
import Joi from 'joi-browser';
import {removeEmptyProperties} from '../utils/utils';
Expand Down Expand Up @@ -68,8 +68,27 @@ export class JobProtocol {
}
}

static safePruneProtocol(protocol) {
const prunedProtocol= removeEmptyProperties(protocol);
const taskRoles = cloneDeep(prunedProtocol.taskRoles);
Object.keys(taskRoles).forEach((taskRoleName) => {
const taskRoleContent = taskRoles[taskRoleName];
if (isEmpty(taskRoleContent.commands)) {
return;
}
taskRoleContent.commands = taskRoleContent.commands.filter(
(line) => !isEmpty(line),
);
});
prunedProtocol.taskRoles = taskRoles;
return prunedProtocol;
}

static validateFromObject(protocol) {
const result = Joi.validate(removeEmptyProperties(protocol), jobProtocolSchema);
const result = Joi.validate(
JobProtocol.safePruneProtocol(protocol),
jobProtocolSchema,
);
return String(result.error || '');
}

Expand Down Expand Up @@ -122,7 +141,7 @@ export class JobProtocol {

toYaml() {
try {
return yaml.safeDump(removeEmptyProperties(this));
return yaml.safeDump(JobProtocol.safePruneProtocol(this));
} catch (e) {
alert(e.message);
}
Expand Down
24 changes: 8 additions & 16 deletions src/webportal/src/app/job-submission/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,23 +67,12 @@ export function addPathPrefix(path, prefix) {
return prefix.concat(path);
}

function pruneComponents(jobInformation, secrets, context) {
function populateComponents(jobInformation, context) {
const {vcNames} = context;
const virtualCluster = jobInformation.virtualCluster;
if (isEmpty(vcNames) || isNil(vcNames.find((vcName) => vcName === virtualCluster))) {
jobInformation.virtualCluster = '';
}

const removeValueIndex = secrets.map((secret, index) => {
if (secret.value === HIDE_SECRET) {
return index;
}
return -1;
}).filter((value) => value >= 0);

for (let i = removeValueIndex.length -1; i >= 0; i--) {
secrets.splice(removeValueIndex[i], 1);
}
}

export function getJobComponentsFromConfig(jobConfig, context) {
Expand All @@ -102,9 +91,12 @@ export function getJobComponentsFromConfig(jobConfig, context) {
const updatedParameters = Object.keys(parameters).map((key) => {
return {key: key, value: parameters[key]};
});
const updatedSecrets = Object.keys(secrets).map((key) => {
return {key: key, value: secrets[key]};
});
const updatedSecrets =
secrets === HIDE_SECRET
? []
: Object.keys(secrets).map((key) => {
return {key: key, value: secrets[key]};
});
const updatedTaskRoles = Object.keys(taskRoles).map((name) =>
JobTaskRole.fromProtocol(
name,
Expand All @@ -115,7 +107,7 @@ export function getJobComponentsFromConfig(jobConfig, context) {
),
);

pruneComponents(updatedJobInformation, updatedSecrets, context);
populateComponents(updatedJobInformation, context);
return [
updatedJobInformation,
updatedTaskRoles,
Expand Down

0 comments on commit cfc67e8

Please sign in to comment.