Skip to content

Commit 97055d1

Browse files
committed
Merge branch 'master' into feature/sandbox-auto-scheduled
2 parents 127ef58 + 564170f commit 97055d1

File tree

7 files changed

+55
-21
lines changed

7 files changed

+55
-21
lines changed

bin/test-cli.sh

+18
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,24 @@ else
394394
exit 1
395395
fi
396396

397+
echo "Testing command ´sfcc-ci sandbox:create --realm <realm> --profile <INVALID_PROFILE>´ (expected to fail):"
398+
node ./cli.js sandbox:create --realm $ARG_SANDBOX_REALM --profile INVALID_PROFILE
399+
if [ $? -eq 1 ]; then
400+
echo -e "\t> OK"
401+
else
402+
echo -e "\t> FAILED"
403+
exit 1
404+
fi
405+
406+
echo "Testing command ´sfcc-ci sandbox:create --realm <realm> --profile large´ --ttl 3:"
407+
node ./cli.js sandbox:create --realm $ARG_SANDBOX_REALM --profile large --ttl 3
408+
if [ $? -eq 0 ]; then
409+
echo -e "\t> OK"
410+
else
411+
echo -e "\t> FAILED"
412+
exit 1
413+
fi
414+
397415
echo "Testing command ´sfcc-ci sandbox:create --realm <realm> --ttl 1 --sync´:"
398416
node ./cli.js sandbox:create --realm $ARG_SANDBOX_REALM --ttl 1 --sync
399417
if [ $? -eq 0 ]; then

cli.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ program
286286
.option('-r, --realm <realm>','Realm to create the sandbox for')
287287
.option('-t, --ttl <hours>','Number of hours the sandbox will live')
288288
.option('--auto-scheduled', 'Sets the sandbox as being auto scheduled')
289+
.option('-p, --profile <profile>','Resource profile used for the sandbox, "medium" is the default')
289290
.option('--ocapi-settings <json>','Additional OCAPI settings applied to the sandbox')
290291
.option('--webdav-settings <json>','Additional WebDAV permissions applied to the sandbox')
291292
.option('-j, --json','Formats the output in json')
@@ -297,14 +298,15 @@ program
297298
var realm = ( options.realm ? options.realm : null );
298299
var ttl = ( options.ttl ? parseInt(options.ttl) : null );
299300
var autoScheduled = ( options.autoScheduled ? options.autoScheduled : false );
301+
var profile = ( options.profile ? options.profile : null );
300302
var asJson = ( options.json ? options.json : false );
301303
var sync = ( options.sync ? options.sync : false );
302304
var setAsDefault = ( options.default ? options.default : false );
303305
var alias = ( options.setAlias ? options.setAlias : null );
304306
var ocapiSettings = ( options.ocapiSettings ? options.ocapiSettings : null );
305307
var webdavSettings = ( options.webdavSettings ? options.webdavSettings : null );
306-
require('./lib/sandbox').cli.create(realm, alias, ttl, autoScheduled, ocapiSettings, webdavSettings, asJson,
307-
sync, setAsDefault);
308+
require('./lib/sandbox').cli.create(realm, alias, ttl, profile, autoScheduled, ocapiSettings, webdavSettings,
309+
asJson, sync, setAsDefault);
308310
}).on('--help', function() {
309311
console.log('');
310312
console.log(' Details:');
@@ -319,6 +321,10 @@ program
319321
console.log(' schedule configured at sandbox realm level. By default or if omitted the sandbox is not auto');
320322
console.log(' scheduled.');
321323
console.log();
324+
console.log(' Use the optional --profile <profile> to set the resource allocation for the sandbox, "medium"');
325+
console.log(' is the default. Be careful, more powerful profiles consume more credits. Supported values');
326+
console.log(' are: medium, large, xlarge.');
327+
console.log();
322328
console.log(' You can force the command to wait until the creation of the sandbox has been finished and the');
323329
console.log(' sandbox is available to use (in "started" status) by using the --sync flag. By default the');
324330
console.log(' command will poll the status for 10 minutes. You can overwrite this by using the environment');
@@ -350,6 +356,7 @@ program
350356
console.log(' $ sfcc-ci sandbox:create -r my-realm -s -j');
351357
console.log(' $ sfcc-ci sandbox:create -r my-realm --ttl 6');
352358
console.log(' $ sfcc-ci sandbox:create -r my-realm --auto-scheduled');
359+
console.log(' $ sfcc-ci sandbox:create -r my-realm -p large');
353360
console.log();
354361
});
355362

lib/job.js

+5-7
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ function runJob(instance, job_id, request_doc, token, callback) {
3333
var options = ocapi.getOptions(instance, endpoint, token);
3434

3535
// the post body
36-
options['body'] = (request_doc ? request_doc : {});
36+
options['body'] = (request_doc ? request_doc : null);
3737

3838
// just do the request and pass the callback
3939
request.post(options, callback);
@@ -243,14 +243,12 @@ function status(instance, job_id, job_execution_id, verbose, streamLog, openLogF
243243
}
244244

245245
function buildParameters(job_params) {
246-
var params = {
247-
parameters: []
248-
};
246+
var params = [];
249247

250248
if (job_params) {
251249
job_params.forEach(function (param) {
252250
var split = param.split('=');
253-
params.parameters.push({
251+
params.push({
254252
name: split[0],
255253
value: (split.length > 1 ? split[1] : null)
256254
});
@@ -293,8 +291,8 @@ module.exports.api = {
293291
if (typeof(job_id) !== 'string') {
294292
throw new TypeError('Parameter job_id missing or not of type String');
295293
}
296-
if (!(typeof(job_params) === 'object' && Array.isArray(job_params))) {
297-
throw new TypeError('Parameter job_params must either be an array');
294+
if (typeof(job_params) !== 'object') {
295+
throw new TypeError('Parameter job_params must either be null or not of type Object');
298296
}
299297
if (typeof(token) !== 'string') {
300298
throw new TypeError('Parameter token missing or not of type String');

lib/sandbox.js

+17-3
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ const SANDBOX_STATUS_POLL_ERROR_THRESHOLD = 3;
4949
const SANDBOX_STATUS_UP_AND_RUNNING = 'started';
5050
const SANDBOX_STATUS_FAILED = 'failed';
5151
const BM_PATH = '/on/demandware.store/Sites-Site';
52+
const SANDBOX_RESOURCE_PROFILES = [ 'medium', 'large', 'xlarge' ];
5253

5354
// enable request debugging
5455
if ( process.env.DEBUG ) {
@@ -422,12 +423,13 @@ function getSandboxHost(sandbox) {
422423
*
423424
* @param {String} realm the realm to create the sandbox for
424425
* @param {String} ttl the ttl of the sandbox in hours
426+
* @param {String} profile the resource profile of the sandbox
425427
* @param {Boolean} autoScheduled sets the sandbox as auto scheduled
426428
* @param {String} additionalOcapiSettings JSON string holding additonal OCAPI settings to pass
427429
* @param {String} additionalWebdavSettings JSON string holding additonal WebDAV permissions to pass
428430
* @param {Function} callback the callback to execute, the error and the created sandbox are available as arguments to the callback function
429431
*/
430-
function createSandbox(realm, ttl, autoScheduled, additionalOcapiSettings, additionalWebdavSettings, callback) {
432+
function createSandbox(realm, ttl, profile, autoScheduled, additionalOcapiSettings, additionalWebdavSettings, callback) {
431433
if (!realm && dwjson['realm']) {
432434
realm = dwjson['realm'];
433435
console.debug('Using realm id %s from dw.json at %s', dwjson['realm'], process.cwd());
@@ -483,6 +485,16 @@ function createSandbox(realm, ttl, autoScheduled, additionalOcapiSettings, addit
483485
options['body']['autoScheduled'] = true;
484486
}
485487

488+
// the profile, if passed
489+
if (profile !== null) {
490+
if (SANDBOX_RESOURCE_PROFILES.indexOf(profile) === -1) {
491+
callback(new Error(`Invalid resource profile '${profile}', use one of:
492+
${SANDBOX_RESOURCE_PROFILES.join(', ')}`));
493+
return;
494+
}
495+
options['body']['resourceProfile'] = profile;
496+
}
497+
486498
ocapi.retryableCall('POST', options, function(err, res) {
487499
var errback = captureCommonErrors(err, res);
488500
if ( !errback ) {
@@ -937,19 +949,21 @@ module.exports.cli = {
937949
* @param {String} realm the realm to create the sandbox in
938950
* @param {String} alias the alias to use for the created sandbox
939951
* @param {Number} ttl number of hours, the sandbox will live (if absent the realm default ttl is used)
952+
* @param {String} profile resource profile used (if absent "medium" is used)
940953
* @param {Boolean} autoScheduled sets the sandbox as auto scheduled (false by default)
941954
* @param {String} ocapiSettings additional ocapi settings
942955
* @param {String} webdavPermissions additional webdav permissions
943956
* @param {Boolean} asJson optional flag to force output in json, false by default
944957
* @param {Boolean} sync whether to operate in synchronous mode, false by default
945958
* * @param {Boolean} setAsDefault optional flag to set as new default instance, false by default
946959
*/
947-
create : function(realm, alias, ttl, autoScheduled, ocapiSettings, webdavPermissions, asJson, sync, setAsDefault) {
960+
create : function(realm, alias, ttl, profile, autoScheduled, ocapiSettings, webdavPermissions, asJson, sync,
961+
setAsDefault) {
948962
// memorize the start time and duration
949963
var startTime = Date.now();
950964
var duration = 0;
951965

952-
createSandbox(realm, ttl, autoScheduled, ocapiSettings, webdavPermissions, function(err, newSandbox) {
966+
createSandbox(realm, ttl, profile, autoScheduled, ocapiSettings, webdavPermissions, function(err, newSandbox) {
953967
if (err) {
954968
if (asJson) {
955969
console.json({error: err.message});

package-lock.json

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"commander": "^2.18.0",
3030
"conf": "^4.0.2",
3131
"del": "^5.1.0",
32-
"dotenv": "^8.2.0",
32+
"dotenv": "^8.6.0",
3333
"globby": "^11.0.1",
3434
"inquirer": "^6.2.0",
3535
"jsondiffpatch": "^0.4.1",

test/unit/job.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,14 @@ describe('Tests for lib/job.js', function() {
1616

1717
it('should return empty array, if no argument passed', function() {
1818
var result = require('../../lib/job').buildParameters([]);
19-
expect(result).to.be.an('object');
20-
expect(result.parameters).to.be.an('array').that.is.empty;
19+
expect(result).to.be.an('array').that.is.empty;
2120
});
2221

2322
it('should properly split cli args', function() {
2423
var result = require('../../lib/job').buildParameters(['param1=value1','param2=value2']);
2524
var expected = [{name: 'param1', value: 'value1'},{name: 'param2', value: 'value2'}];
2625

27-
expect(result).to.be.an('object');
28-
expect(result.parameters).to.be.an('array').that.is.not.empty;
29-
expect(result.parameters).to.have.deep.members(expected);
26+
expect(result).to.have.deep.members(expected);
3027
});
3128
});
3229
});

0 commit comments

Comments
 (0)