cloudcms-server 0.9.261 → 0.9.264
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/framework/controllers.js +4 -4
- package/launchpad/index.js +13 -0
- package/launchpad/launchers/cluster.js +23 -5
- package/launchpad/launchers/redis.js +47 -16
- package/launchpad/launchers/single.js +6 -0
- package/locks/locks.js +49 -4
- package/locks/providers/memory.js +9 -6
- package/locks/providers/redis.js +1 -1
- package/middleware/authentication/adapters/session.js +20 -8
- package/middleware/authentication/authentication.js +28 -16
- package/middleware/authentication/authenticators/default.js +5 -2
- package/middleware/authentication/authenticators/session.js +5 -2
- package/middleware/authentication/providers/saml.js +0 -1
- package/middleware/authorization/authorization.js +11 -8
- package/middleware/awareness/awareness.js +39 -27
- package/middleware/awareness/providers/abstract-async.js +130 -84
- package/middleware/awareness/providers/abstract.js +1 -1
- package/middleware/awareness/providers/memory.js +0 -14
- package/middleware/awareness/providers/redis.js +113 -232
- package/middleware/cloudcms/cloudcms.js +17 -15
- package/package.json +2 -2
- package/server/index.js +415 -407
- package/temp/clusterlock/index.js +3 -5
- package/temp/clusterlock/package.json +1 -1
- package/util/cloudcms.js +65 -86
- package/web/socket.io/socket.io.js +0 -4240
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
var path = require("path");
|
|
6
6
|
var cluster = require("cluster");
|
|
7
7
|
|
|
8
|
-
var
|
|
8
|
+
var AsyncLock = require('async-lock');
|
|
9
9
|
|
|
10
10
|
var releaseFunctions = {};
|
|
11
11
|
|
|
@@ -18,7 +18,7 @@ var _setup = function() {
|
|
|
18
18
|
|
|
19
19
|
if (cluster.isMaster)
|
|
20
20
|
{
|
|
21
|
-
var lock = new
|
|
21
|
+
var lock = new AsyncLock();
|
|
22
22
|
|
|
23
23
|
var _claim = function(message)
|
|
24
24
|
{
|
|
@@ -26,7 +26,7 @@ var _setup = function() {
|
|
|
26
26
|
|
|
27
27
|
var ticket = "ticket-" + message.id;
|
|
28
28
|
|
|
29
|
-
lock.
|
|
29
|
+
lock.acquire(key, function(releaseFn) {
|
|
30
30
|
|
|
31
31
|
releaseFunctions[ticket] = releaseFn;
|
|
32
32
|
|
|
@@ -158,7 +158,6 @@ process.on('message', _workerIncomingMessagesHandler);
|
|
|
158
158
|
|
|
159
159
|
var _lock = function(key, fn) {
|
|
160
160
|
|
|
161
|
-
console.log("z1: " + key);
|
|
162
161
|
// notify master that we have something waiting to run for this lock
|
|
163
162
|
_sendMessageToMaster({
|
|
164
163
|
"type": "claim",
|
|
@@ -166,7 +165,6 @@ var _lock = function(key, fn) {
|
|
|
166
165
|
"key": key
|
|
167
166
|
},
|
|
168
167
|
"callback": function(ticket) {
|
|
169
|
-
console.log("z2: " + ticket);
|
|
170
168
|
|
|
171
169
|
fn.call(null, function(afterReleaseCallback) {
|
|
172
170
|
|
package/util/cloudcms.js
CHANGED
|
@@ -68,26 +68,23 @@ exports = module.exports = function()
|
|
|
68
68
|
{
|
|
69
69
|
if (!repositoryId)
|
|
70
70
|
{
|
|
71
|
-
callback({
|
|
71
|
+
return callback({
|
|
72
72
|
"message": "Missing repositoryId in ensureContentDirectory()"
|
|
73
73
|
});
|
|
74
|
-
return;
|
|
75
74
|
}
|
|
76
75
|
|
|
77
76
|
if (!branchId)
|
|
78
77
|
{
|
|
79
|
-
callback({
|
|
78
|
+
return callback({
|
|
80
79
|
"message": "Missing branchId in ensureContentDirectory()"
|
|
81
80
|
});
|
|
82
|
-
return;
|
|
83
81
|
}
|
|
84
82
|
|
|
85
83
|
if (!locale)
|
|
86
84
|
{
|
|
87
|
-
callback({
|
|
85
|
+
return callback({
|
|
88
86
|
"message": "Missing locale in ensureContentDirectory()"
|
|
89
87
|
});
|
|
90
|
-
return;
|
|
91
88
|
}
|
|
92
89
|
|
|
93
90
|
var contentDirectoryPath = path.join(repositoryId, branchId, nodeId, locale);
|
|
@@ -148,21 +145,17 @@ exports = module.exports = function()
|
|
|
148
145
|
if (err)
|
|
149
146
|
{
|
|
150
147
|
// nothing found
|
|
151
|
-
callback({
|
|
148
|
+
return callback({
|
|
152
149
|
"message": "Nothing cached on disk"
|
|
153
150
|
});
|
|
154
|
-
|
|
155
|
-
return;
|
|
156
151
|
}
|
|
157
152
|
|
|
158
153
|
if (!cacheInfoString)
|
|
159
154
|
{
|
|
160
155
|
// nothing found
|
|
161
|
-
callback({
|
|
156
|
+
return callback({
|
|
162
157
|
"message": "Nothing cached on disk"
|
|
163
158
|
});
|
|
164
|
-
|
|
165
|
-
return;
|
|
166
159
|
}
|
|
167
160
|
|
|
168
161
|
var invalidate = function () {
|
|
@@ -346,25 +339,40 @@ exports = module.exports = function()
|
|
|
346
339
|
{
|
|
347
340
|
if (attemptCount === maxAttemptsAllowed)
|
|
348
341
|
{
|
|
349
|
-
cb({
|
|
342
|
+
return cb({
|
|
350
343
|
"message": "Maximum number of connection attempts exceeded(" + maxAttemptsAllowed + ")",
|
|
351
344
|
"err": previousError
|
|
352
345
|
});
|
|
353
|
-
|
|
354
|
-
return;
|
|
355
346
|
}
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
347
|
+
|
|
348
|
+
var failFast = function(contentStore, filePath, cb) {
|
|
349
|
+
var triggered = false;
|
|
350
|
+
|
|
351
|
+
return function(tempStream, err)
|
|
360
352
|
{
|
|
353
|
+
// don't allow this to be called twice
|
|
354
|
+
if (triggered) {
|
|
355
|
+
return;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
triggered = true;
|
|
359
|
+
|
|
361
360
|
// ensure stream is closed
|
|
362
|
-
|
|
363
|
-
|
|
361
|
+
if (tempStream) {
|
|
362
|
+
closeWriteStream(tempStream);
|
|
363
|
+
}
|
|
364
|
+
|
|
364
365
|
// ensure cleanup
|
|
365
366
|
return safeRemove(contentStore, filePath, function () {
|
|
366
367
|
cb(err);
|
|
367
368
|
});
|
|
369
|
+
};
|
|
370
|
+
}(contentStore, filePath, cb);
|
|
371
|
+
|
|
372
|
+
contentStore.writeStream(filePath, function(err, tempStream) {
|
|
373
|
+
|
|
374
|
+
if (err) {
|
|
375
|
+
return failFast(tempStream, err);
|
|
368
376
|
}
|
|
369
377
|
|
|
370
378
|
var cacheFilePath = toCacheFilePath(filePath);
|
|
@@ -398,18 +406,10 @@ exports = module.exports = function()
|
|
|
398
406
|
{
|
|
399
407
|
response.pipe(tempStream).on("close", function (err) {
|
|
400
408
|
|
|
401
|
-
// TODO: not needed here?
|
|
402
|
-
// ensure stream is closed
|
|
403
|
-
// closeWriteStream(tempStream);
|
|
404
|
-
|
|
405
409
|
if (err)
|
|
406
410
|
{
|
|
407
411
|
// some went wrong at disk io level?
|
|
408
|
-
return
|
|
409
|
-
cb({
|
|
410
|
-
"message": "Failed to download: " + JSON.stringify(err)
|
|
411
|
-
});
|
|
412
|
-
});
|
|
412
|
+
return failFast(tempStream, err);
|
|
413
413
|
}
|
|
414
414
|
|
|
415
415
|
contentStore.existsFile(filePath, function (exists) {
|
|
@@ -418,55 +418,39 @@ exports = module.exports = function()
|
|
|
418
418
|
|
|
419
419
|
// write cache file
|
|
420
420
|
var cacheInfo = buildCacheInfo(response);
|
|
421
|
-
if (cacheInfo)
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
});
|
|
421
|
+
if (!cacheInfo) {
|
|
422
|
+
return cb(null, filePath, null);
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
contentStore.writeFile(cacheFilePath, JSON.stringify(cacheInfo, null, " "), function (err) {
|
|
426
|
+
|
|
427
|
+
if (err)
|
|
428
|
+
{
|
|
429
|
+
// failed to write cache file, thus the whole thing is invalid
|
|
430
|
+
return safeRemove(contentStore, cacheFilePath, function () {
|
|
431
|
+
failFast(tempStream, {
|
|
432
|
+
"message": "Failed to write cache file: " + cacheFilePath + ", err: " + JSON.stringify(err)
|
|
434
433
|
});
|
|
435
|
-
}
|
|
436
|
-
|
|
437
|
-
{
|
|
438
|
-
cb(null, filePath, cacheInfo);
|
|
439
|
-
}
|
|
434
|
+
});
|
|
435
|
+
}
|
|
440
436
|
|
|
441
|
-
});
|
|
442
|
-
}
|
|
443
|
-
else
|
|
444
|
-
{
|
|
445
437
|
cb(null, filePath, cacheInfo);
|
|
446
|
-
}
|
|
438
|
+
});
|
|
447
439
|
}
|
|
448
440
|
else
|
|
449
441
|
{
|
|
450
|
-
//process.log("WARN: exists false, " + filePath);
|
|
451
|
-
|
|
452
442
|
// for some reason, file wasn't found
|
|
453
443
|
// roll back the whole thing
|
|
454
444
|
safeRemove(contentStore, cacheFilePath, function () {
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
"message": "Failed to verify written cached file: " + filePath
|
|
458
|
-
});
|
|
445
|
+
failFast(tempStream, {
|
|
446
|
+
"message": "Failed to verify written cached file: " + filePath
|
|
459
447
|
});
|
|
460
448
|
});
|
|
461
449
|
}
|
|
462
450
|
});
|
|
463
451
|
|
|
464
452
|
}).on("error", function (err) {
|
|
465
|
-
|
|
466
|
-
// ensure stream is closed
|
|
467
|
-
closeWriteStream(tempStream);
|
|
468
|
-
|
|
469
|
-
process.log("Pipe error: " + err);
|
|
453
|
+
failFast(tempStream, err);
|
|
470
454
|
});
|
|
471
455
|
}
|
|
472
456
|
else
|
|
@@ -480,10 +464,7 @@ exports = module.exports = function()
|
|
|
480
464
|
});
|
|
481
465
|
|
|
482
466
|
response.on('end', function () {
|
|
483
|
-
|
|
484
|
-
// ensure stream is closed
|
|
485
|
-
closeWriteStream(tempStream);
|
|
486
|
-
|
|
467
|
+
|
|
487
468
|
var afterCleanup = function () {
|
|
488
469
|
|
|
489
470
|
// see if it is "invalid_token"
|
|
@@ -518,9 +499,11 @@ exports = module.exports = function()
|
|
|
518
499
|
"code": response.statusCode,
|
|
519
500
|
"body": body
|
|
520
501
|
});
|
|
521
|
-
|
|
522
502
|
};
|
|
523
|
-
|
|
503
|
+
|
|
504
|
+
// ensure stream is closed
|
|
505
|
+
closeWriteStream(tempStream);
|
|
506
|
+
|
|
524
507
|
// clean things up
|
|
525
508
|
safeRemove(contentStore, cacheFilePath, function () {
|
|
526
509
|
safeRemove(contentStore, filePath, function () {
|
|
@@ -532,12 +515,8 @@ exports = module.exports = function()
|
|
|
532
515
|
}
|
|
533
516
|
|
|
534
517
|
}).on('error', function (e) {
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
closeWriteStream(tempStream);
|
|
538
|
-
|
|
539
|
-
//process.log("_writeToDisk request timed out");
|
|
540
|
-
//process.log(e)
|
|
518
|
+
failFast(tempStream, e);
|
|
519
|
+
|
|
541
520
|
}).on('end', function (e) {
|
|
542
521
|
|
|
543
522
|
// ensure stream is closed
|
|
@@ -548,9 +527,11 @@ exports = module.exports = function()
|
|
|
548
527
|
tempStream.on("error", function (e) {
|
|
549
528
|
process.log("Temp stream errored out");
|
|
550
529
|
process.log(e);
|
|
530
|
+
|
|
531
|
+
failFast(tempStream, e);
|
|
551
532
|
|
|
552
533
|
// ensure stream is closed
|
|
553
|
-
closeWriteStream(tempStream);
|
|
534
|
+
//closeWriteStream(tempStream);
|
|
554
535
|
|
|
555
536
|
});
|
|
556
537
|
});
|
|
@@ -608,8 +589,7 @@ exports = module.exports = function()
|
|
|
608
589
|
readFromDisk(contentStore, filePath, function (err, cacheInfo) {
|
|
609
590
|
|
|
610
591
|
if (!err && cacheInfo) {
|
|
611
|
-
callback(err, filePath, cacheInfo);
|
|
612
|
-
return;
|
|
592
|
+
return callback(err, filePath, cacheInfo);
|
|
613
593
|
}
|
|
614
594
|
|
|
615
595
|
// either there was an error (in which case things were cleaned up)
|
|
@@ -631,13 +611,12 @@ exports = module.exports = function()
|
|
|
631
611
|
|
|
632
612
|
if (err) {
|
|
633
613
|
process.log("writeToDisk error, err: " + err.message + ", body: " + err.body);
|
|
634
|
-
callback(err);
|
|
635
|
-
}
|
|
636
|
-
else {
|
|
637
|
-
//process.log("Fetched: " + assetPath);
|
|
638
|
-
//process.log("Retrieved from server: " + filePath);
|
|
639
|
-
callback(null, filePath, cacheInfo);
|
|
614
|
+
return callback(err);
|
|
640
615
|
}
|
|
616
|
+
|
|
617
|
+
//process.log("Fetched: " + assetPath);
|
|
618
|
+
//process.log("Retrieved from server: " + filePath);
|
|
619
|
+
callback(null, filePath, cacheInfo);
|
|
641
620
|
});
|
|
642
621
|
});
|
|
643
622
|
};
|
|
@@ -749,6 +728,7 @@ exports = module.exports = function()
|
|
|
749
728
|
writeToDisk(contentStore, gitana, uri, filePath, function (err, filePath, responseHeaders) {
|
|
750
729
|
|
|
751
730
|
if (err) {
|
|
731
|
+
|
|
752
732
|
if (err.code === 404) {
|
|
753
733
|
return callback();
|
|
754
734
|
}
|
|
@@ -1101,7 +1081,6 @@ exports = module.exports = function()
|
|
|
1101
1081
|
_LOCK(contentStore, _lock_identifier(repositoryId, branchId, nodeId), function(err, releaseLockFn) {
|
|
1102
1082
|
|
|
1103
1083
|
invalidateNode(contentStore, repositoryId, branchId, nodeId, function () {
|
|
1104
|
-
|
|
1105
1084
|
invalidateNodePaths(contentStore, repositoryId, branchId, paths, function() {
|
|
1106
1085
|
|
|
1107
1086
|
// release lock
|