Skip to content

Commit

Permalink
Merge 0b2a6c4 into ad1ddaf
Browse files Browse the repository at this point in the history
  • Loading branch information
itayw committed Jun 8, 2014
2 parents ad1ddaf + 0b2a6c4 commit 87b35a9
Show file tree
Hide file tree
Showing 17 changed files with 135,018 additions and 2,779 deletions.
30 changes: 19 additions & 11 deletions benchmark/base.bench.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,37 @@
var common = require('../lib/common/index');
var benchrest = require('bench-rest');
var
util = require('util'),
benchrest = require('bench-rest'),

common = require('../lib/common/index');

var flows = [
'./flows/beacon.spec.js',
//'./flows/beacon.large.spec.js',
'./flows/metadata.spec.js'
];

global.JOOLA_ADDRESS = 'http://127.0.0.1:8080';
const VERSION = '0.0.1';

var results = {};
results.benchmarkID = common.uuid();
results.timestamp = new Date();
results.flows = {};
results.flows = [];
results.flowCount = flows.length;

var actual = 0;

var joolaio = require('joola.io.sdk');
joolaio.init({host: 'http://localhost:8080', APIToken: 'apitoken-root', ajax: true}, function (err) {
joolaio.init({host: JOOLA_ADDRESS, APIToken: 'apitoken-demo'}, function (err) {
if (err)
throw err;

joolaio.system.nodeDetails(function (err, details) {
if (err)
throw err;

results.nodeDetails = details;

results.version = VERSION;
flows.forEach(function (flow) {
console.log('Running Flow', flow);
var flowModule = require(flow);
Expand All @@ -36,12 +44,12 @@ joolaio.init({host: 'http://localhost:8080', APIToken: 'apitoken-root', ajax: tr
console.error('Failed in %s with err: ', ctxName, err);
})
.on('progress', function (stats, percent, concurrent, ips) {
console.log('Progress: %s complete', percent);
console.log('Progress: %s complete', percent, concurrent, ips);
})
.on('end', function (stats, errorCount) {
console.log(stats);
//console.log(stats);
stats.name = flowModule.name;
results.flows[flowModule.name] = stats;
results.flows.push(stats);

if (++actual === results.flowCount)
return alldone();
Expand All @@ -51,11 +59,11 @@ joolaio.init({host: 'http://localhost:8080', APIToken: 'apitoken-root', ajax: tr
});

function alldone() {
console.log(results);
joolaio.beacon.insert('benchmark', results, function (err) {
console.log(util.inspect(results, {depth: null, colors: true}));
joolaio.beacon.insert('benchmark', results, {}, function (err) {
if (err)
throw err;
process.exit(0);
});
}
});
});
6 changes: 3 additions & 3 deletions benchmark/flows/beacon.large.spec.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
module.exports = {
name: 'beacon.large',
name: 'beacon_large',
runOptions: {
limit: 1, // concurrent connections
iterations: 1, // number of iterations to perform
progress: 1000
progress: 5000
//prealloc: 10
},
flow: {
before: [], // operations to do before anything
beforeMain: [], // operations to do before each iteration
main: [ // the main flow for each iteration, #{INDEX} is unique iteration counter token
{ post: JOOLA_ADDRESS + '/api/beacon/insert?APIToken=apitoken-root', json: require('../../test/fixtures/benchmark.json')}
{ post: JOOLA_ADDRESS + '/beacon/demo/benchmark?APIToken=apitoken-demo', json: require('../../test/fixtures/benchmark.json')}
],
afterMain: [], // operations to do after each iteration
after: [] // operations to do after everything is done
Expand Down
10 changes: 5 additions & 5 deletions benchmark/flows/beacon.spec.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
module.exports = {
name: 'beacon',
runOptions: {
limit: 1, // concurrent connections
iterations: 10, // number of iterations to perform
progress: 1000
//prealloc: 10
limit: 100, // concurrent connections
iterations: 100, // number of iterations to perform
progress: 5000
//prealloc: 10
},
flow: {
before: [], // operations to do before anything
beforeMain: [], // operations to do before each iteration
main: [ // the main flow for each iteration, #{INDEX} is unique iteration counter token
{ post: JOOLA_ADDRESS + '/api/beacon/insert?APIToken=apitoken-root', json: require('../../test/fixtures/benchmark-single.json')}
{ post: JOOLA_ADDRESS + '/beacon/demo/benchmark?APIToken=apitoken-demo', json: require('../../test/fixtures/benchmark-single.json')}
],
afterMain: [], // operations to do after each iteration
after: [] // operations to do after everything is done
Expand Down
10 changes: 5 additions & 5 deletions benchmark/flows/metadata.spec.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
module.exports = {
name: 'metadata',
runOptions: {
limit: 1, // concurrent connections
iterations: 10, // number of iterations to perform
progress: 1000
//prealloc: 10
limit: 10, // concurrent connections
iterations: 100, // number of iterations to perform
progress: 5000
//prealloc: 10
},
flow: {
before: [], // operations to do before anything
beforeMain: [], // operations to do before each iteration
main: [ // the main flow for each iteration, #{INDEX} is unique iteration counter token
{ get: JOOLA_ADDRESS + '/api/system/nodeDetails?APIToken=apitoken-root' }
{ get: JOOLA_ADDRESS + '/system/nodeDetails?APIToken=apitoken-demo' }
],
afterMain: [], // operations to do after each iteration
after: [] // operations to do after everything is done
Expand Down
4 changes: 3 additions & 1 deletion config/default.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: 0.0.110
version: 0.0.200
interfaces:
webserver:
enabled: true
Expand Down Expand Up @@ -463,13 +463,15 @@ workspaces:
- "beacon:insert"
- "query:fetch"
- "query:stop"
- "system:version"
filter: []
reader:
key: "user"
permissions:
- "beacon:insert"
- "query:fetch"
- "query:stop"
- "system:version"
filter: []
users:
root:
Expand Down
15 changes: 9 additions & 6 deletions lib/webserver/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ webserver.start = function (options, callback) {
return next();
});

app.use(function (req, res, next) {
function stampHeaders(req, res, next) {
res.header("Server", joola.config.get('interfaces:webserver:host') || 'N/A');

var allowOrigin = joola.config.get('interfaces:webserver:alloworigin') || req.headers.origin;
Expand All @@ -105,10 +105,10 @@ webserver.start = function (options, callback) {
});

next();
});
}

app.use(stampHeaders);
app.use(express.static(path.join(__dirname, 'public')));
app.use(express.static(path.join(__dirname, '../../node_modules/joola.io.sdk/bin')));
app.use(express.static(path.join(__dirname, '../../node_modules/joola.io.sdk/build/release')));

app.use(meta());
Expand Down Expand Up @@ -299,7 +299,8 @@ webserver.start = function (options, callback) {
res.headers[header] = value;
};
res.json = function (json, headers) {
res.headers = headers || {};
if (!res.headers)
res.headers = {};
res.headers.StatusCode = res.statusCode;
res.headers.Status = res.statusCode + ' ' + http.STATUS_CODES[res.statusCode];

Expand Down Expand Up @@ -356,8 +357,10 @@ webserver.start = function (options, callback) {
action: path.split('/')[1]
};

return joola.auth.middleware(req, res, function () {
return router.router(req, res);
return stampHeaders(req, res, function () {
return joola.auth.middleware(req, res, function () {
return router.router(req, res);
});
});
});
};
Expand Down
134 changes: 134 additions & 0 deletions lib/webserver/public/3rd/flot/jquery.flot.axislabels.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
/*
Axis Labels Plugin for flot. :P
Released under the GPLv3 license by Xuan Luo, September 2010.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
(function ($) {
var options = { };

function init(plot) {
// This is kind of a hack. There are no hooks in Flot between
// the creation and measuring of the ticks (setTicks, measureTickLabels
// in setupGrid() ) and the drawing of the ticks and plot box
// (insertAxisLabels in setupGrid() ).
//
// Therefore, we use a trick where we run the draw routine twice:
// the first time to get the tick measurements, so that we can change
// them, and then have it draw it again.
var secondPass = false;
plot.hooks.draw.push(function (plot, ctx) {
if (!secondPass) {
// MEASURE AND SET OPTIONS
$.each(plot.getAxes(), function(axisName, axis) {
var opts = axis.options // Flot 0.7
|| plot.getOptions()[axisName]; // Flot 0.6
if (!opts || !opts.axisLabel)
return;

var w, h;
if (opts.axisLabelUseCanvas != false)
opts.axisLabelUseCanvas = true;

if (opts.axisLabelUseCanvas) {
// canvas text
if (!opts.axisLabelFontSizePixels)
opts.axisLabelFontSizePixels = 14;
if (!opts.axisLabelFontFamily)
opts.axisLabelFontFamily = 'sans-serif';
// since we currently always display x as horiz.
// and y as vertical, we only care about the height
w = opts.axisLabelFontSizePixels;
h = opts.axisLabelFontSizePixels;

} else {
// HTML text
var elem = $('<div class="axisLabels" style="position:absolute;">' + opts.axisLabel + '</div>');
plot.getPlaceholder().append(elem);
w = elem.outerWidth(true);
h = elem.outerHeight(true);
elem.remove();
}

if (axisName.charAt(0) == 'x')
axis.labelHeight += h;
else
axis.labelWidth += w;
opts.labelHeight = axis.labelHeight;
opts.labelWidth = axis.labelWidth;
});
// re-draw with new label widths and heights
secondPass = true;
plot.setupGrid();
plot.draw();


} else {
// DRAW
$.each(plot.getAxes(), function(axisName, axis) {
var opts = axis.options // Flot 0.7
|| plot.getOptions()[axisName]; // Flot 0.6
if (!opts || !opts.axisLabel)
return;

if (opts.axisLabelUseCanvas) {
// canvas text
var ctx = plot.getCanvas().getContext('2d');
ctx.save();
ctx.font = opts.axisLabelFontSizePixels + 'px ' +
opts.axisLabelFontFamily;
var width = ctx.measureText(opts.axisLabel).width;
var height = opts.axisLabelFontSizePixels;
var x, y;
if (axisName.charAt(0) == 'x') {
x = plot.getPlotOffset().left + plot.width()/2 - width/2;
y = plot.getCanvas().height;
} else {
x = height * 0.72;
y = plot.getPlotOffset().top + plot.height()/2 - width/2;
}
ctx.translate(x, y);
ctx.rotate((axisName.charAt(0) == 'x') ? 0 : -Math.PI/2);
ctx.fillText(opts.axisLabel, 0, 0);
ctx.restore();

} else {
// HTML text
plot.getPlaceholder().find('#' + axisName + 'Label').remove();
var elem = $('<div id="' + axisName + 'Label" " class="axisLabels" style="position:absolute;">' + opts.axisLabel + '</div>');
if (axisName.charAt(0) == 'x') {
elem.css('left', plot.getPlotOffset().left + plot.width()/2 - elem.outerWidth()/2 + 'px');
elem.css('bottom', '0px');
} else {
elem.css('top', plot.getPlotOffset().top + plot.height()/2 - elem.outerHeight()/2 + 'px');
elem.css('left', '0px');
}
plot.getPlaceholder().append(elem);
}
});
secondPass = false;
}
});
}



$.plot.plugins.push({
init: init,
options: options,
name: 'axisLabels',
version: '1.0'
});
})(jQuery);
Loading

0 comments on commit 87b35a9

Please sign in to comment.