cloudcms-server 3.3.1-beta.1 → 3.3.1-beta.10

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.
Files changed (38) hide show
  1. package/.last_command +7 -0
  2. package/broadcast/providers/redis.js +32 -57
  3. package/clients/nrp.js +117 -0
  4. package/clients/redis.js +48 -0
  5. package/duster/helpers/sample/nyt.js +5 -7
  6. package/framework/controllers.js +0 -1
  7. package/index.js +23 -13
  8. package/insight/insight.js +6 -9
  9. package/locks/providers/redis.js +29 -58
  10. package/middleware/admin/admin.js +4 -4
  11. package/middleware/awareness/awareness.js +4 -1
  12. package/middleware/awareness/plugins/editorial.js +41 -66
  13. package/middleware/awareness/plugins/resources.js +74 -0
  14. package/middleware/awareness/providers/redis.js +263 -237
  15. package/middleware/cache/providers/redis.js +134 -92
  16. package/middleware/config/config.js +41 -2
  17. package/middleware/deployment/deployment.js +19 -22
  18. package/middleware/form/form.js +18 -33
  19. package/middleware/modules/modules.js +64 -11
  20. package/middleware/proxy/proxy.js +1 -2
  21. package/middleware/stores/engines/s3.js +0 -2
  22. package/middleware/stores/stores.js +50 -6
  23. package/middleware/themes/themes.js +49 -0
  24. package/middleware/virtual-config/virtual-config.js +35 -39
  25. package/notifications/notifications.js +75 -2
  26. package/package.json +18 -19
  27. package/server/index.js +105 -24
  28. package/server/standalone.js +2 -0
  29. package/util/auth.js +2 -7
  30. package/util/cloudcms.js +19 -34
  31. package/util/proxy-factory.js +17 -7
  32. package/util/redis.js +113 -0
  33. package/util/renditions.js +6 -12
  34. package/util/request.js +117 -0
  35. package/util/util.js +23 -36
  36. package/web/socket.io/socket.io.js +4240 -2
  37. package/web/cms/ice.js +0 -109
  38. package/web/cms/preview.js +0 -106
@@ -1,7 +1,11 @@
1
- var path = require("path");
1
+ //var path = require("path");
2
2
 
3
- var redis = require("redis");
3
+ //var redis = require("redis");
4
4
  var logFactory = require("../../../util/logger");
5
+ //const redisHelper = require("../../../util/redis");
6
+
7
+ var redisClientFactory = require("../../../clients/redis");
8
+ const redisHelper = require("../../../util/redis");
5
9
 
6
10
  /**
7
11
  * Redis distributed cache.
@@ -11,123 +15,161 @@ var logFactory = require("../../../util/logger");
11
15
  exports = module.exports = function(cacheConfig)
12
16
  {
13
17
  var client = null;
14
-
15
- var logger = this.logger = logFactory("REDIS CACHE");
16
- logger.setLevel("error");
17
-
18
- // allow for global redis default
19
- // allow for redis broadcast specific
20
- // otherwise default to error
21
- if (typeof(process.env.CLOUDCMS_REDIS_DEBUG_LEVEL) !== "undefined") {
22
- logger.setLevel(("" + process.env.CLOUDCMS_REDIS_DEBUG_LEVEL).toLowerCase(), true);
23
- }
24
- else if (typeof(process.env.CLOUDCMS_CACHE_REDIS_DEBUG_LEVEL) !== "undefined") {
25
- logger.setLevel(("" + process.env.CLOUDCMS_CACHE_REDIS_DEBUG_LEVEL).toLowerCase(), true);
26
- }
27
-
18
+
19
+ var logger = redisHelper.redisLogger("REDIS_CACHE", "CLOUDCMS_CACHE_", "error")
20
+
28
21
  var r = {};
29
-
22
+
30
23
  r.init = function(callback)
31
24
  {
32
- var redisPort = cacheConfig.port;
33
- if (typeof(redisPort) === "undefined" || !redisPort)
34
- {
35
- redisPort = process.env.CLOUDCMS_CACHE_REDIS_PORT;
36
- }
37
- if (typeof(redisPort) === "undefined" || !redisPort)
38
- {
39
- redisPort = process.env.CLOUDCMS_REDIS_PORT;
40
- }
41
-
42
- var redisEndpoint = cacheConfig.endpoint;
43
- if (typeof(redisEndpoint) === "undefined" || !redisEndpoint)
44
- {
45
- redisEndpoint = process.env.CLOUDCMS_CACHE_REDIS_ENDPOINT;
46
- }
47
- if (typeof(redisEndpoint) === "undefined" || !redisEndpoint)
48
- {
49
- redisEndpoint = process.env.CLOUDCMS_REDIS_ENDPOINT;
50
- }
51
-
52
- var redisOptions = {};
53
-
54
- //redis.debug_mode = true;
55
-
56
- client = redis.createClient(redisPort, redisEndpoint, redisOptions);
57
-
58
- callback();
25
+ redisClientFactory.create(cacheConfig, function(err, _client) {
26
+
27
+ if (err) {
28
+ return callback(err);
29
+ }
30
+
31
+ client = _client;
32
+
33
+ return callback();
34
+
35
+ });
59
36
  };
60
-
37
+
61
38
  r.write = function(key, value, seconds, callback)
62
39
  {
63
- if (seconds <= -1)
64
- {
65
- client.set([key, JSON.stringify(value)], function(err, reply) {
66
- if (err) {
67
- logger.error("write error. key: " + key + " value: " + JSON.stringify(value) + ". error:" + err);
40
+ logger.info('write, key = ' + key + ', value = ' + value + '', seconds = ' + seconds');
41
+ (async function() {
42
+
43
+ var reply = null;
44
+ var err = null;
45
+
46
+ try
47
+ {
48
+ if (seconds <= -1)
49
+ {
50
+ reply = await client.set([key, JSON.stringify(value)]);
68
51
  }
69
- logger.info("write -> reply = " + reply);
70
- callback(err, reply);
71
- });
72
- }
73
- else
74
- {
75
- client.set([key, JSON.stringify(value), "EX", seconds], function(err, reply) {
76
- if (err) {
77
- logger.error("write.ex error. key: " + key + " value: " + JSON.stringify(value) + ". error:" + err);
52
+ else
53
+ {
54
+ reply = await client.set([key, JSON.stringify(value), "EX", seconds]);
78
55
  }
79
- logger.info("write.ex -> reply = " + reply);
80
- callback(err, reply);
81
- });
82
- }
56
+ }
57
+ catch (e)
58
+ {
59
+ err = e;
60
+ }
61
+
62
+ if (reply) {
63
+ logger.info("write -> reply = " + reply);
64
+ }
65
+
66
+ if (err) {
67
+ logger.error("write error. key: " + key + " value: " + JSON.stringify(value) + ". error:" + err);
68
+ }
69
+
70
+ callback(err, reply);
71
+
72
+ })();
83
73
  };
84
-
85
-     r.read = function(key, callback)
86
-     {
87
-         client.get([key], function(err, reply) {
88
-
74
+
75
+ r.read = function(key, callback)
76
+ {
77
+ logger.info('read, key = ' + key);
78
+
79
+ (async function() {
80
+
81
+ var err = null;
82
+ var reply = null;
83
+
84
+ try
85
+ {
86
+ reply = await client.get([key]);
87
+ }
88
+ catch (e)
89
+ {
90
+ err = e;
91
+ }
92
+
89
93
  if (err) {
90
94
  logger.error("read error. key: " + key + ". error:" + err);
91
95
  }
92
- logger.info("read. key: " + key + " -> reply = " + reply);
93
-             
96
+
97
+ if (reply) {
98
+ logger.info("read. key: " + key + " -> reply = " + reply);
99
+ }
100
+
94
101
  var result = null;
95
-             try
102
+ try
96
103
  {
97
-                 result = JSON.parse(reply);
98
-             }
104
+ result = JSON.parse(reply);
105
+ }
99
106
  catch (ex)
100
107
  {
101
-                 result = null;
102
-                 err = ex;
103
- if (err) {
108
+ result = null;
109
+ err = ex;
110
+
111
+ if (err)
112
+ {
104
113
  logger.error("error parsing reply. key: " + key + ". error:" + err);
105
114
  }
106
-             }
107
-
115
+ }
116
+
108
117
  callback(err, result);
109
-         });
110
-     };
111
-
118
+ })();
119
+ };
120
+
112
121
  r.remove = function(key, callback)
113
122
  {
114
- logger.info("remove. key: " + key);
115
- client.del([key], function(err) {
123
+ logger.info('remove, key = ' + key);
124
+
125
+ (async function() {
126
+
127
+ var err = null;
128
+
129
+ try
130
+ {
131
+ await client.del([key]);
132
+ logger.info("remove. key: " + key);
133
+ }
134
+ catch (e)
135
+ {
136
+ err = e;
137
+ }
138
+
116
139
  callback(err);
117
- });
140
+ })();
118
141
  };
119
142
 
120
143
  r.keys = function(prefix, callback)
121
-     {
122
- logger.info('keys. prefix = ' + prefix);
123
-         client.keys([prefix + '*'], function(err, reply) {
144
+ {
145
+ logger.info('keys, prefix = ' + prefix);
146
+
147
+ (async function() {
148
+
149
+ var err = null;
150
+ var reply = null;
151
+
152
+ try
153
+ {
154
+ reply = await client.keys([prefix + '*']);
155
+ }
156
+ catch (e)
157
+ {
158
+ err = e;
159
+ }
160
+
124
161
  if (err) {
125
162
  logger.error("error reading prefix: " + prefix + ". error:" + err);
126
163
  }
127
- logger.info("[keys -> reply = " + reply);
128
-             callback(err, reply);
129
-         });
130
-     };
131
-
164
+
165
+ if (reply) {
166
+ logger.info("[keys -> reply = " + reply);
167
+ }
168
+
169
+ callback(err, reply);
170
+
171
+ })();
172
+ };
173
+
132
174
  return r;
133
175
  };
@@ -21,8 +21,7 @@ exports = module.exports = function()
21
21
 
22
22
  if (err)
23
23
  {
24
- callback(err);
25
- return;
24
+ return callback(err);
26
25
  }
27
26
 
28
27
  ADAPTERS[configStore.id] = adapter;
@@ -842,6 +841,46 @@ exports = module.exports = function()
842
841
  });
843
842
  };
844
843
 
844
+ /**
845
+ * Invalidates cached adapter.
846
+ *
847
+ * @return {Function}
848
+ */
849
+ r.invalidateConfigHandler = function()
850
+ {
851
+ if (!process.configuration.config) {
852
+ process.configuration.config = {};
853
+ }
854
+
855
+ // config handler
856
+ return util.createHandler("invalidateConfig", "config", function(req, res, next, stores, cache, configuration) {
857
+
858
+ var configStore = stores.config;
859
+
860
+ var handled = false;
861
+
862
+ if (req.method.toLowerCase() === "post") {
863
+
864
+ if (req.url.indexOf("/_config/invalidate") === 0)
865
+ {
866
+ invalidateAdapter(configStore);
867
+
868
+ res.send({
869
+ "ok": true
870
+ });
871
+ res.end();
872
+
873
+ handled = true;
874
+ }
875
+ }
876
+
877
+ if (!handled)
878
+ {
879
+ next();
880
+ }
881
+ });
882
+ };
883
+
845
884
  var invalidateAdapter = r.invalidateAdapter = function(configStore)
846
885
  {
847
886
  var adapter = ADAPTERS[configStore.id];
@@ -348,39 +348,36 @@ exports = module.exports = function()
348
348
  var rootStore = stores.root;
349
349
  rootStore.allocated(function(allocated) {
350
350
 
351
- console.log("H2: " + allocated);
352
351
  if (!allocated) {
353
- callback({
352
+ return callback({
354
353
  "message": "The application cannot be started because it is not deployed."
355
354
  });
356
355
  }
357
- else
358
- {
359
- rootStore.readFile("descriptor.json", function (err, data) {
360
356
 
361
- if (err) {
362
- return callback(err);
363
- }
357
+ rootStore.readFile("descriptor.json", function (err, data) {
364
358
 
365
- data = JSON.parse(data);
359
+ if (err) {
360
+ return callback(err);
361
+ }
366
362
 
367
- // is it already started?
368
- if (data.active) {
369
- return callback({
370
- "message": "The application is already started"
371
- });
372
- }
363
+ data = JSON.parse(data);
373
364
 
374
- data.active = true;
365
+ // is it already started?
366
+ if (data.active) {
367
+ return callback({
368
+ "message": "The application is already started"
369
+ });
370
+ }
375
371
 
376
- logFn("Starting application: " + data.application.id + " with host: " + host);
372
+ data.active = true;
377
373
 
378
- rootStore.writeFile("descriptor.json", JSON.stringify(data, null, " "), function (err) {
379
- console.log("Start error: "+ err);
380
- callback(err);
381
- });
374
+ logFn("Starting application: " + data.application.id + " with host: " + host);
375
+
376
+ rootStore.writeFile("descriptor.json", JSON.stringify(data, null, " "), function (err) {
377
+ console.log("Start error: "+ err);
378
+ callback(err);
382
379
  });
383
- }
380
+ });
384
381
  });
385
382
  });
386
383
  });
@@ -1,11 +1,10 @@
1
- var path = require("path");
2
- var fs = require("fs");
3
1
  var util = require("../../util/util");
4
- var request = require("request");
5
2
 
6
3
  var http = require("http");
7
4
  var https = require("https");
8
5
 
6
+ var request = require("../../util/request");
7
+
9
8
  /**
10
9
  * Form middleware.
11
10
  *
@@ -121,46 +120,37 @@ exports = module.exports = function()
121
120
  }
122
121
 
123
122
  // post form to Cloud CMS using public method
124
- var URL = util.asURL(process.env.GITANA_PROXY_SCHEME, process.env.GITANA_PROXY_HOST, process.env.GITANA_PROXY_PORT) + url;
123
+ var URL = util.asURL(process.env.GITANA_PROXY_SCHEME, process.env.GITANA_PROXY_HOST, process.env.GITANA_PROXY_PORT, process.env.GITANA_PROXY_PATH) + url;
125
124
 
126
125
  var headers = {};
127
126
  headers["Authorization"] = req.gitana.platform().getDriver().getHttpHeaders()["Authorization"];
128
127
 
129
- var agent = http.globalAgent;
130
- if (process.env.GITANA_PROXY_SCHEME === "https")
131
- {
132
- agent = https.globalAgent;
133
- }
134
-
135
128
  request({
136
129
  "method": "POST",
137
130
  "url": URL,
138
131
  "qs": {},
139
132
  "json": form,
140
133
  "headers": headers,
141
- "agent": agent,
142
134
  "timeout": process.defaultHttpTimeoutMs
143
- }, function(err, response, body) {
135
+ }, function(err, response, json) {
144
136
 
145
137
  console.log("Response error: " + JSON.stringify(err));
146
138
  console.log("Response: " + JSON.stringify(response,null,2));
147
- console.log("Body: " + JSON.stringify(body,null,2));
139
+ console.log("Body: " + JSON.stringify(json,null,2));
148
140
 
149
- if (err || (response && response.body && response.body.error))
141
+ if (err || (json && json.error))
150
142
  {
151
143
  if (failureUrl)
152
144
  {
153
145
  return res.redirect(failureUrl);
154
146
  }
155
- else
156
- {
157
- res.status(500);
158
- res.json({
159
- "ok": false,
160
- "err": err || response.body.message,
161
- "message": body
162
- });
163
- }
147
+
148
+ res.status(500);
149
+ res.json({
150
+ "ok": false,
151
+ "err": err || json.message,
152
+ "message": json
153
+ });
164
154
 
165
155
  return;
166
156
  }
@@ -193,27 +183,22 @@ exports = module.exports = function()
193
183
  req.branch(function(err, branch) {
194
184
 
195
185
  var url = branch.getUri() + "/alpaca/datasource";
196
-
197
- var URL = util.asURL(process.env.GITANA_PROXY_SCHEME, process.env.GITANA_PROXY_HOST, process.env.GITANA_PROXY_PORT) + url;
186
+
187
+ var URL = util.asURL(process.env.GITANA_PROXY_SCHEME, process.env.GITANA_PROXY_HOST, process.env.GITANA_PROXY_PORT, process.env.GITANA_PROXY_PATH) + url;
198
188
 
199
189
  var headers = {};
200
190
  headers["Authorization"] = req.gitana.platform().getDriver().getHttpHeaders()["Authorization"];
201
191
 
202
- var agent = http.globalAgent;
203
- if (process.env.GITANA_PROXY_SCHEME === "https")
204
- {
205
- agent = https.globalAgent;
206
- }
207
-
208
192
  request({
209
193
  "method": "POST",
210
194
  "url": URL,
211
195
  "qs": {},
212
196
  "json": form,
213
197
  "headers": headers,
214
- "agent": agent,
215
198
  "timeout": process.defaultHttpTimeoutMs
216
- }).pipe(res);
199
+ }, function(err, response, json) {
200
+ response.data.pipe(res);''
201
+ });
217
202
 
218
203
  });
219
204
  };
@@ -39,6 +39,13 @@ exports = module.exports = function()
39
39
 
40
40
  var doDeploy = function(host, moduleId, moduleConfig, callback)
41
41
  {
42
+ // broadcast: module_before_deploy
43
+ process.broadcast.publish("module_before_deploy", {
44
+ "host": host,
45
+ "moduleId": moduleId,
46
+ "moduleConfig": moduleConfig
47
+ });
48
+
42
49
  logFn("Start doDeploy, host: " + host + ", module ID: " + moduleId + ", module config: " + JSON.stringify(moduleConfig, null, 2));;
43
50
 
44
51
  if (!moduleConfig)
@@ -94,16 +101,26 @@ exports = module.exports = function()
94
101
 
95
102
  var targetStore = stores["modules"];
96
103
  var targetOffsetPath = moduleId;
97
-
104
+
105
+ //logFn("From: " + sourceType + ", " + sourceUrl + ", " + sourcePath + ", " + sourceBranch);
106
+ //logFn("To: " + targetStore + ", path: " + targetOffsetPath);
107
+
98
108
  util.gitCheckout(host, sourceType, sourceUrl, sourcePath, sourceBranch, targetStore, targetOffsetPath, false, logFn, function (err) {
99
109
 
100
- //logFn("After util.gitCheckout: " + JSON.stringify(err));
110
+ logFn("After util.gitCheckout: " + JSON.stringify(err));
101
111
 
102
112
  // invalidate any caching within the stores layer
103
113
  storeService.invalidate(host);
104
114
 
105
- //logFn("After store.invalidate");
106
-
115
+ logFn("After store.invalidate");
116
+
117
+ // broadcast: module_after_deploy
118
+ process.broadcast.publish("module_after_deploy", {
119
+ "host": host,
120
+ "moduleId": moduleId,
121
+ "moduleConfig": moduleConfig
122
+ });
123
+
107
124
  callback(err);
108
125
  });
109
126
  });
@@ -116,10 +133,17 @@ exports = module.exports = function()
116
133
 
117
134
  var doUndeploy = function(host, moduleId, moduleConfig, cacheOnly, callback)
118
135
  {
136
+ // broadcast: module_before_undeploy
137
+ process.broadcast.publish("module_before_undeploy", {
138
+ "host": host,
139
+ "moduleId": moduleId,
140
+ "moduleConfig": moduleConfig
141
+ });
142
+
119
143
  var logFn = function(text) {
120
144
  console.log(text);
121
145
  };
122
-
146
+
123
147
  logFn("Start doUndeploy, host: " + host + ", module ID: " + moduleId + ", module config: " + JSON.stringify(moduleConfig, null, 2));;
124
148
 
125
149
  storeService.produce(host, function(err, stores) {
@@ -156,12 +180,19 @@ exports = module.exports = function()
156
180
  var doRefresh = function(host, moduleId, moduleConfig, callback)
157
181
  {
158
182
  //logFn("Start doRefresh, host: " + host + ", module ID: " + moduleId + ", module config: " + JSON.stringify(moduleConfig, null, 2));;
159
-
183
+
184
+ // broadcast: module_before_refresh
185
+ process.broadcast.publish("module_before_refresh", {
186
+ "host": host,
187
+ "moduleId": moduleId,
188
+ "moduleConfig": moduleConfig
189
+ });
190
+
160
191
  storeService.produce(host, function(err, stores) {
161
192
 
162
193
  var options = {};
163
194
  options.host = host;
164
-
195
+
165
196
  var modulesStore = stores.modules;
166
197
  modulesStore.refresh(options, function(err) {
167
198
 
@@ -169,7 +200,20 @@ exports = module.exports = function()
169
200
  return callback(err);
170
201
  }
171
202
 
172
- doInvalidate(host, moduleId, moduleConfig, callback);
203
+ doInvalidate(host, moduleId, moduleConfig, function(err) {
204
+
205
+ if (!err)
206
+ {
207
+ // broadcast: module_after_refresh
208
+ process.broadcast.publish("module_after_refresh", {
209
+ "host": host,
210
+ "moduleId": moduleId,
211
+ "moduleConfig": moduleConfig
212
+ });
213
+ }
214
+
215
+ callback(err);
216
+ });
173
217
  });
174
218
  });
175
219
  };
@@ -210,7 +254,7 @@ exports = module.exports = function()
210
254
  var moduleId = message.moduleId;
211
255
  var moduleConfig = message.moduleConfig;
212
256
  var messageId = message.id;
213
-
257
+
214
258
  var identifier = acquireMessageConcurrencyLockIdentifier(messageId);
215
259
  util.executeFunction(identifier, function(exclusiveFirst, doneFn) {
216
260
 
@@ -236,6 +280,7 @@ exports = module.exports = function()
236
280
 
237
281
  // invalidate this server
238
282
  doInvalidate(host, moduleId, moduleConfig, function() {
283
+
239
284
  finished(err);
240
285
  });
241
286
 
@@ -255,7 +300,7 @@ exports = module.exports = function()
255
300
  var moduleId = message.moduleId;
256
301
  var moduleConfig = message.moduleConfig;
257
302
  var messageId = message.id;
258
-
303
+
259
304
  var identifier = acquireMessageConcurrencyLockIdentifier(messageId);
260
305
  util.executeFunction(identifier, function(exclusiveFirst, doneFn) {
261
306
 
@@ -278,6 +323,14 @@ exports = module.exports = function()
278
323
 
279
324
  // invalidate this server
280
325
  doInvalidate(host, moduleId, moduleConfig, function() {
326
+
327
+ // broadcast: module_after_undeploy
328
+ process.broadcast.publish("module_after_undeploy", {
329
+ "host": host,
330
+ "moduleId": moduleId,
331
+ "moduleConfig": moduleConfig
332
+ });
333
+
281
334
  finished(err);
282
335
  });
283
336
 
@@ -511,7 +564,7 @@ exports = module.exports = function()
511
564
 
512
565
  handled = true;
513
566
  }
514
- else if (req.url.indexOf("/oneteam") === 0 && req.url.indexOf("/modules") > -1 && req.url.indexOf("app/") !== 0)
567
+ else if (req.url.indexOf("/modules") > -1 && req.url.indexOf("app/") !== 0)
515
568
  {
516
569
  // this route handling is provided for support of local modules within OneTeam
517
570
  // the full url is /oneteam-XYZ/modules/{moduleId}/something.jpg
@@ -215,8 +215,7 @@ exports = module.exports = function()
215
215
  contentStore.writeFile(filePath + ".cache", JSON.stringify(cacheInfo), function() {
216
216
  _end.call(res, data, encoding);
217
217
  });
218
-
219
- };
218
+ `` };
220
219
 
221
220
  callback();
222
221
  });
@@ -279,9 +279,7 @@ exports = module.exports = function(engineConfig)
279
279
  for (var i = 0; i < data.Contents.length; i++)
280
280
  {
281
281
  var contentKey = data.Contents[i].Key;
282
- console.log("contentKey: " + contentKey);
283
282
  var cdr = contentKey.substring(params.Prefix.length);
284
- console.log("cdr.1: " + cdr);
285
283
 
286
284
  if (cdr.indexOf("/") === 0)
287
285
  {