Oracle® ZFS Storage Appliance 管理指南,发行版 2013.1.5.0

退出打印视图

更新时间: 2016 年 2 月
 
 

工作流输入验证

工作流可以选择通过添加 validate 成员来验证其输入,该成员将包含工作流参数作为成员的对象作为参数。validate 函数应返回一个对象,该对象的每个成员都使用未通过验证的参数命名,每个成员的值都是要向用户显示的验证错误消息。

示例 17  工作流输入验证

要将我们的示例扩展为在用户尝试创建已有共享资源时给出明确的错误:

var workflow = {
	name: 'Create share',
	description: 'Creates a new share in a business unit',
	parameters: {
		name: {
			label: 'Name of new share',
			type: 'String'
		},
		unit: {
			label: 'Business unit',
			type: 'ChooseOne',
			options: [ 'development', 'finance', 'qa', 'sales' ],
			optionlabels: [ 'Development', 'Finance',
			    'Quality Assurance', 'Sales/Administrative' ],
		}
	},
	validate: function (params) {
		try {
			run('shares select ' + params.unit);
			run('select ' + params.name);
		} catch (err) {
			if (err.code == EAKSH_ENTITY_BADSELECT)
				return;
		}

		return ({ name: 'share already exists' });
	},
	execute: function (params) {
		try {
			run('shares select ' + params.unit);
		} catch (err) {
			if (err.code != EAKSH_ENTITY_BADSELECT)
				throw (err);

			/*
			 * We haven't yet created a project that corresponds to
			 * this business unit; create it now.
			 */
			run('shares project ' + params.unit);
			set('mountpoint', '/export/' + params.unit);
			run('commit');
			run('shares select ' + params.unit);
		}

		run('filesystem ' + params.name);
		run('commit');
		return ('Created new share "' + params.name + '"');
	}
};