'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = getClusterPayload;
function tradClusterPayload(id) {
if (!id) {
throw Error('missing id in traditional cluster payload');
}
return {
_id: id
};
}
function ec2ClusterPayload(name, machine) {
var clusterSize = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
var profileId = arguments[3];
var clusterNames = arguments[4];
if (typeof name === 'undefined') {
throw Error('Missing required field: "name"');
} else if (typeof machine === 'undefined') {
throw Error('Missing required field: "machine"');
} else if (typeof profileId === 'undefined') {
throw Error('Missing required field: "profileId"');
} else if (clusterNames.indexOf(name.trim()) !== -1) {
throw Error('An EC2 instance with this name already exists');
}
var _clusterSize = Number(clusterSize);
if (Number.isNaN(_clusterSize)) {
_clusterSize = 1;
} else if (clusterSize <= 0) {
throw Error('Cluster must be greater than zero');
}
return {
serverType: 'ec2',
machine: machine,
name: name.trim(),
clusterSize: _clusterSize,
profileId: profileId
};
}
function getClusterPayload(type, options, clusterNames) {
if (type === 'EC2') {
var name = options.name,
machine = options.machine,
clusterSize = options.clusterSize,
profile = options.profile,
cluster = options.cluster;
if (cluster) {
return { _id: cluster };
}
return ec2ClusterPayload(name, machine, clusterSize, profile, clusterNames);
}
if (type === 'Traditional') {
var _profile = options.profile;
return tradClusterPayload(_profile);
}
return null;
}
|