maxImages limit, expose odmVersion

pull/51/head
Piero Toffanin 2018-11-09 11:09:19 -05:00
rodzic 1dab8eebcb
commit b75e86183f
8 zmienionych plików z 62 dodań i 19 usunięć

Wyświetl plik

@ -16,5 +16,6 @@
"test": false, "test": false,
"testSkipOrthophotos": false, "testSkipOrthophotos": false,
"testSkipDems": false, "testSkipDems": false,
"token": "" "token": "",
"maxImages": -1
} }

Wyświetl plik

@ -37,7 +37,8 @@ Options:
--test_skip_orthophotos If test mode is enabled, skip orthophoto results when generating assets. (default: false) --test_skip_orthophotos If test mode is enabled, skip orthophoto results when generating assets. (default: false)
--test_skip_dems If test mode is enabled, skip dems results when generating assets. (default: false) --test_skip_dems If test mode is enabled, skip dems results when generating assets. (default: false)
--powercycle When set, the application exits immediately after powering up. Useful for testing launch and compilation issues. --powercycle When set, the application exits immediately after powering up. Useful for testing launch and compilation issues.
--token <token> Sets a token that needs to be passed for every request. This can be used to limit access to the node only to token holders. (default: none) --token <token> Sets a token that needs to be passed for every request. This can be used to limit access to the node only to token holders. (default: none)
--max_images <number> Specify the maximum number of images that this processing node supports. (default: unlimited)
Log Levels: Log Levels:
error | debug | info | verbose | debug | silly error | debug | info | verbose | debug | silly
`); `);
@ -86,5 +87,7 @@ config.testSkipOrthophotos = argv.test_skip_orthophotos || fromConfigFile("testS
config.testSkipDems = argv.test_skip_dems || fromConfigFile("testSkipDems", false); config.testSkipDems = argv.test_skip_dems || fromConfigFile("testSkipDems", false);
config.powercycle = argv.powercycle || fromConfigFile("powercycle", false); config.powercycle = argv.powercycle || fromConfigFile("powercycle", false);
config.token = argv.token || fromConfigFile("token", ""); config.token = argv.token || fromConfigFile("token", "");
config.maxImages = argv.max_images || fromConfigFile("maxImages", "");
module.exports = config; module.exports = config;

Wyświetl plik

@ -8,7 +8,7 @@ REST API to access OpenDroneMap
=== Version information === Version information
[%hardbreaks] [%hardbreaks]
_Version_ : 1.1.1 _Version_ : 1.2.0
=== Contact information === Contact information
@ -68,12 +68,16 @@ Retrieves information about this node
_optional_|Amount of RAM available in bytes|integer _optional_|Amount of RAM available in bytes|integer
|*cpuCores* + |*cpuCores* +
_optional_|Number of CPU cores (virtual)|integer _optional_|Number of CPU cores (virtual)|integer
|*maxImages* +
_optional_|Maximum number of images allowed for new tasks|integer
|*odmVersion* +
_optional_|Current version of ODM|string
|*taskQueueCount* + |*taskQueueCount* +
_required_|Number of tasks currently being processed or waiting to be processed|integer _required_|Number of tasks currently being processed or waiting to be processed|integer
|*totalMemory* + |*totalMemory* +
_optional_|Amount of total RAM in the system in bytes|integer _optional_|Amount of total RAM in the system in bytes|integer
|*version* + |*version* +
_required_|Current version|string _required_|Current API version|string
|=== |===

File diff suppressed because one or more lines are too long

Wyświetl plik

@ -36,7 +36,7 @@ let morgan = require('morgan');
let TaskManager = require('./libs/TaskManager'); let TaskManager = require('./libs/TaskManager');
let Task = require('./libs/Task'); let Task = require('./libs/Task');
let odmOptions = require('./libs/odmOptions'); let odmInfo = require('./libs/odmInfo');
let Directories = require('./libs/Directories'); let Directories = require('./libs/Directories');
let unzip = require('node-unzip-2'); let unzip = require('node-unzip-2');
let si = require('systeminformation'); let si = require('systeminformation');
@ -148,6 +148,7 @@ let server;
app.post('/task/new', authCheck, addRequestId, upload.array('images'), (req, res) => { app.post('/task/new', authCheck, addRequestId, upload.array('images'), (req, res) => {
if ((!req.files || req.files.length === 0) && !req.body.zipurl) res.json({ error: "Need at least 1 file or a zip file url." }); if ((!req.files || req.files.length === 0) && !req.body.zipurl) res.json({ error: "Need at least 1 file or a zip file url." });
if (config.maxImages > 0 && req.files && req.files.length > config.maxImages) res.json({error: `${req.files.length} images uploaded, but this node can only process up to ${config.maxImages}.`})
else { else {
let srcPath = path.join("tmp", req.id); let srcPath = path.join("tmp", req.id);
@ -157,7 +158,7 @@ app.post('/task/new', authCheck, addRequestId, upload.array('images'), (req, res
async.series([ async.series([
cb => { cb => {
odmOptions.filterOptions(req.body.options, (err, options) => { odmInfo.filterOptions(req.body.options, (err, options) => {
if (err) cb(err); if (err) cb(err);
else { else {
req.body.options = options; req.body.options = options;
@ -208,18 +209,22 @@ app.post('/task/new', authCheck, addRequestId, upload.array('images'), (req, res
else { else {
async.eachSeries(entries, (entry, cb) => { async.eachSeries(entries, (entry, cb) => {
if (/\.zip$/gi.test(entry)) { if (/\.zip$/gi.test(entry)) {
let filesCount = 0;
fs.createReadStream(path.join(destImagesPath, entry)).pipe(unzip.Parse()) fs.createReadStream(path.join(destImagesPath, entry)).pipe(unzip.Parse())
.on('entry', function(entry) { .on('entry', function(entry) {
if (entry.type === 'File') { if (entry.type === 'File') {
filesCount++;
entry.pipe(fs.createWriteStream(path.join(destImagesPath, path.basename(entry.path)))); entry.pipe(fs.createWriteStream(path.join(destImagesPath, path.basename(entry.path))));
} else { } else {
entry.autodrain(); entry.autodrain();
} }
}) })
.on('close', cb) .on('close', () => {
// Verify max images limit
if (config.maxImages > 0 && filesCount > config.maxImages) cb(`${filesCount} images uploaded, but this node can only process up to ${config.maxImages}.`);
else cb();
})
.on('error', cb); .on('error', cb);
} else cb(); } else cb();
}, cb); }, cb);
} }
@ -559,7 +564,7 @@ app.post('/task/remove', authCheck, uuidCheck, (req, res) => {
*/ */
app.post('/task/restart', authCheck, uuidCheck, (req, res, next) => { app.post('/task/restart', authCheck, uuidCheck, (req, res, next) => {
if (req.body.options){ if (req.body.options){
odmOptions.filterOptions(req.body.options, (err, options) => { odmInfo.filterOptions(req.body.options, (err, options) => {
if (err) res.json({ error: err.message }); if (err) res.json({ error: err.message });
else { else {
req.body.options = options; req.body.options = options;
@ -608,7 +613,7 @@ app.post('/task/restart', authCheck, uuidCheck, (req, res, next) => {
* description: Description of what this option does * description: Description of what this option does
*/ */
app.get('/options', (req, res) => { app.get('/options', (req, res) => {
odmOptions.getOptions((err, options) => { odmInfo.getOptions((err, options) => {
if (err) res.json({ error: err.message }); if (err) res.json({ error: err.message });
else res.json(options); else res.json(options);
}); });
@ -628,7 +633,7 @@ app.get('/options', (req, res) => {
* properties: * properties:
* version: * version:
* type: string * type: string
* description: Current version * description: Current API version
* taskQueueCount: * taskQueueCount:
* type: integer * type: integer
* description: Number of tasks currently being processed or waiting to be processed * description: Number of tasks currently being processed or waiting to be processed
@ -640,21 +645,30 @@ app.get('/options', (req, res) => {
* description: Amount of total RAM in the system in bytes * description: Amount of total RAM in the system in bytes
* cpuCores: * cpuCores:
* type: integer * type: integer
* description: Number of CPU cores (virtual) * description: Number of CPU cores (virtual)
* maxImages:
* type: integer
* description: Maximum number of images allowed for new tasks
* odmVersion:
* type: string
* description: Current version of ODM
*/ */
app.get('/info', (req, res) => { app.get('/info', (req, res) => {
async.parallel({ async.parallel({
cpu: cb => si.cpu(data => cb(null, data)), cpu: cb => si.cpu(data => cb(null, data)),
mem: cb => si.mem(data => cb(null, data)), mem: cb => si.mem(data => cb(null, data)),
odmVersion: odmInfo.getVersion
}, (_, data) => { }, (_, data) => {
const { cpu, mem } = data; const { cpu, mem, odmVersion } = data;
res.json({ res.json({
version: packageJson.version, version: packageJson.version,
taskQueueCount: taskManager.getQueueCount(), taskQueueCount: taskManager.getQueueCount(),
totalMemory: mem.total, totalMemory: mem.total,
availableMemory: mem.available, availableMemory: mem.available,
cpuCores: cpu.cores cpuCores: cpu.cores,
maxImages: config.maxImages,
odmVersion: odmVersion
}); });
}); });
}); });
@ -682,7 +696,7 @@ process.on('SIGINT', gracefulShutdown);
if (config.test) logger.info("Running in test mode"); if (config.test) logger.info("Running in test mode");
let commands = [ let commands = [
cb => odmOptions.initialize(cb), cb => odmInfo.initialize(cb),
cb => auth.initialize(cb), cb => auth.initialize(cb),
cb => { taskManager = new TaskManager(cb); }, cb => { taskManager = new TaskManager(cb); },
cb => { cb => {

Wyświetl plik

@ -17,14 +17,28 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
"use strict"; "use strict";
let odmRunner = require('./odmRunner'); let odmRunner = require('./odmRunner');
let async = require('async');
let assert = require('assert'); let assert = require('assert');
let logger = require('./logger'); let logger = require('./logger');
let odmOptions = null; let odmOptions = null;
let odmVersion = null;
module.exports = { module.exports = {
initialize: function(done){ initialize: function(done){
this.getOptions(done); async.parallel([
this.getOptions,
this.getVersion
], done);
},
getVersion: function(done){
if (odmVersion){
done(null, odmVersion);
return;
}
odmRunner.getVersion(done);
}, },
getOptions: function(done){ getOptions: function(done){

Wyświetl plik

@ -81,6 +81,13 @@ module.exports = {
return childProcess; return childProcess;
}, },
getVersion: function(done){
fs.readFile(path.join(config.odm_path, 'VERSION'), {encoding: 'utf8'}, (err, content) => {
if (err) done(null, "?");
else done(null, content.split("\n").map(l => l.trim())[0]);
});
},
getJsonOptions: function(done){ getJsonOptions: function(done){
// In test mode, we don't call ODM, // In test mode, we don't call ODM,

Wyświetl plik

@ -1,6 +1,6 @@
{ {
"name": "node-opendronemap", "name": "node-opendronemap",
"version": "1.1.1", "version": "1.2.0",
"description": "REST API to access OpenDroneMap", "description": "REST API to access OpenDroneMap",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {