Skip to content

Commit

Permalink
Basic process namespace support and debug process
Browse files Browse the repository at this point in the history
  • Loading branch information
m-mohr committed Aug 11, 2021
1 parent 39b70c4 commit f1993eb
Show file tree
Hide file tree
Showing 19 changed files with 114 additions and 27 deletions.
2 changes: 1 addition & 1 deletion src/api/processes.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module.exports = class Processes {

getProcesses(req, res, next) {
res.json({
processes: this.registry.toJSON(),
processes: this.registry.namespace('backend'),
links: []
});
return next();
Expand Down
2 changes: 1 addition & 1 deletion src/models/logs.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ module.exports = class Logs {
this.add(message, 'error', data, trace, code, links, error.id);
}
else {
this.add(message, 'error', data, trace, code, links);
this.add(error, 'error', data, trace, code, links);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/processes/add_dimension.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module.exports = class add_dimension extends BaseProcess {

if (dc.hasDimension(name)) {
throw new Errors.DimensionExists({
process: this.spec.id,
process: this.id,
argument: 'name'
});
}
Expand Down
6 changes: 3 additions & 3 deletions src/processes/aggregate_temporal_frequency.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ module.exports = class aggregate_temporal_frequency extends BaseProcess {

if (!(callback instanceof ProcessGraph)) {
throw new Errors.ProcessArgumentInvalid({
process: this.spec.id,
process: this.id,
argument: 'reducer',
reason: 'No reducer specified.'
});
}
else if (callback.getNodeCount() !== 1) {
throw new Errors.ProcessArgumentInvalid({
process: this.spec.id,
process: this.id,
argument: 'reducer',
reason: "No complex reducer supported at the moment"
});
Expand All @@ -30,7 +30,7 @@ module.exports = class aggregate_temporal_frequency extends BaseProcess {
var process = callback.getProcess(childNode);
if (typeof process.geeReducer !== 'function') {
throw new Errors.ProcessArgumentInvalid({
process: this.spec.id,
process: this.id,
argument: 'reducer',
reason: 'The specified reducer is invalid.'
});
Expand Down
2 changes: 1 addition & 1 deletion src/processes/apply.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module.exports = class apply extends BaseProcess {
var callback = node.getArgument("process");
if (!(callback instanceof ProcessGraph)) {
throw new Errors.ProcessArgumentInvalid({
process: this.spec.id,
process: this.id,
argument: 'process',
reason: 'No process specified.'
});
Expand Down
2 changes: 1 addition & 1 deletion src/processes/array_element.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ module.exports = class array_element extends BaseProcess {
// ToDo: only bands is currently supported
if (dimension.type !== "bands") {
throw new Errors.ProcessArgumentInvalid({
process: this.spec.id,
process: this.id,
argument: 'dimension',
reason: 'Only dimension "bands" is currently supported.'
});
Expand Down
18 changes: 18 additions & 0 deletions src/processes/debug.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const { BaseProcess } = require('@openeo/js-processgraphs');
const Commons = require('../processgraph/commons');

module.exports = class debug extends BaseProcess {

async execute(node) {
var dc = node.getArgument('data');
var code = node.getArgument('data');
var level = node.getArgument('data', 'info');
var message = node.getArgument('data');

var logger = node.getLogger();
logger[level](message, data, code);

return dc;
}

};
57 changes: 57 additions & 0 deletions src/processes/debug.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"id": "debug",
"summary": "Publish debugging information",
"description": "Sends debugging information about the data to the log output. Passes the data through.",
"categories": [
"development"
],
"experimental": true,
"parameters": [
{
"name": "data",
"description": "Data to publish.",
"schema": {
"description": "Any data type is allowed."
}
},
{
"name": "code",
"description": "An identifier to help identify the log entry in a bunch of other log entries.",
"schema": {
"type": "string"
},
"default": "",
"optional": true
},
{
"name": "level",
"description": "The severity level of this message, defaults to `info`. Note that the level `error` forces the computation to be stopped!",
"schema": {
"type": "string",
"enum": [
"error",
"warning",
"info",
"debug"
]
},
"default": "info",
"optional": true
},
{
"name": "message",
"description": "A message to send in addition to the data.",
"schema": {
"type": "string"
},
"default": "",
"optional": true
}
],
"returns": {
"description": "The data as passed to the `data` parameter without any modification.",
"schema": {
"description": "Any data type is allowed."
}
}
}
4 changes: 2 additions & 2 deletions src/processes/drop_dimension.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module.exports = class drop_dimension extends BaseProcess {

if (dc.hasDimension(dimensionName) === false) {
throw new Errors.DimensionNotAvailable({
process: this.spec.id,
process: this.id,
argument: 'name'
});
}
Expand All @@ -19,7 +19,7 @@ module.exports = class drop_dimension extends BaseProcess {

if (dimension.values.length > 1) {
throw new Errors.DimensionLabelCountMismatch({
process: this.spec.id,
process: this.id,
argument: 'name'
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/processes/filter_bbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const Commons = require('../processgraph/commons');
module.exports = class filter_bbox extends BaseProcess {

async execute(node) {
return Commons.filterBbox(node.getDataCube("data"), node.getArgument("extent"), this.spec.id, 'extent');
return Commons.filterBbox(node.getDataCube("data"), node.getArgument("extent"), this.id, 'extent');
}

};
2 changes: 1 addition & 1 deletion src/processes/filter_spatial.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const Commons = require('../processgraph/commons');
module.exports = class filter_spatial extends BaseProcess {

async execute(node) {
return Commons.filterGeoJSON(node.getData("data"), node.getArgument("geometries"), this.spec.id, 'geometries');
return Commons.filterGeoJSON(node.getData("data"), node.getArgument("geometries"), this.id, 'geometries');
}

};
4 changes: 2 additions & 2 deletions src/processes/load_collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ module.exports = class load_collection extends BaseProcess {
var spatial_extent = node.getArgument("spatial_extent");
if (spatial_extent !== null) {
if (spatial_extent.type) { // GeoJSON - has been validated before so `type` should be a safe indicator for GeoJSON
dc = Commons.filterGeoJSON(dc, spatial_extent, this.spec.id, 'spatial_extent');
dc = Commons.filterGeoJSON(dc, spatial_extent, this.id, 'spatial_extent');
}
else { // Bounding box
dc = Commons.filterBbox(dc, spatial_extent, this.spec.id, 'spatial_extent');
dc = Commons.filterBbox(dc, spatial_extent, this.id, 'spatial_extent');
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/processes/reduce_dimension.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module.exports = class reduce_dimension extends BaseProcess {

async execute(node) {
var dc = node.getDataCube("data");
dc = await Commons.reduce(node, dc, this.spec.id);
dc = await Commons.reduce(node, dc, this.id);
// ToDo: We don't know at this point how the bands in the GEE images/imagecollections are called.
var dimensionName = node.getArgument("dimension");
dc.dropDimension(dimensionName);
Expand Down
4 changes: 2 additions & 2 deletions src/processes/rename_dimension.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ module.exports = class rename_dimension extends BaseProcess {

if (dc.hasDimension(srcName)) {
throw new Errors.DimensionNotAvailable({
process: this.spec.id,
process: this.id,
argument: 'source'
});
}
else if (dc.hasDimension(trgName)) {
throw new Errors.DimensionExists({
process: this.spec.id,
process: this.id,
argument: 'target'
});
}
Expand Down
4 changes: 2 additions & 2 deletions src/processes/rename_labels.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module.exports = class rename_labels extends BaseProcess {

if (!dc.hasDimension(dimensionName)) {
throw new Errors.ProcessArgumentInvalid({
process: this.spec.id,
process: this.id,
argument: 'dimension',
reason: 'Dimension "' + dimension + '" does not exist.'
});
Expand All @@ -28,7 +28,7 @@ module.exports = class rename_labels extends BaseProcess {
var dimension = dc.getDimension(dimensionName);
if (dimension.type !== "bands") {
throw new Errors.ProcessArgumentInvalid({
process: this.spec.id,
process: this.id,
argument: 'dimension',
reason: 'Only dimension "bands" is currently supported.'
});
Expand Down
5 changes: 5 additions & 0 deletions src/processgraph/processgraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ module.exports = class GeeProcessGraph extends ProcessGraph {
return pg;
}

createProcessInstance(process) {
var impl = require('../processes/' + process.id + '.js');
return new impl(process);
}

async validateNode(node) {
var process = this.getProcess(node);
return await process.validate(node, this.context);
Expand Down
5 changes: 2 additions & 3 deletions src/processgraph/registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,15 @@ module.exports = class GeeProcessRegistry extends ProcessRegistry {
this.addFromFile(id);
}
});
var num = Utils.size(this.processes);
var num = Utils.size(this.namespace('backend'));
console.info("Loaded " + num + " processes.");
return Promise.resolve(num);
}

addFromFile(id) {
var spec = require('../processes/' + id + '.json');
delete spec.process_graph;
var impl = require('../processes/' + id + '.js');
this.processes[id.toLowerCase()] = new impl(spec);
this.add(spec, 'backend');
}

getServerContext() {
Expand Down
8 changes: 8 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ var Utils = {
size(obj) {
return CommonUtils.size(obj);
},

omitFromObject(obj, omit) {
return CommonUtils.omitFromObject(obj, omit);
},

pickFromObject(obj, pick) {
return CommonUtils.pickFromObject(obj, pick);
},

loadDB(name, folder = './storage/database/') {
var db = new Datastore({ filename: folder + name + '.db', autoload: true });
Expand Down
10 changes: 5 additions & 5 deletions storage/errors/errors.json
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@
},
"ProcessGraphMissing": {
"description": null,
"message": "No valid process graph specified.",
"message": "No process graph specified",
"http": 400,
"tags": [
"Process Graph Management",
Expand All @@ -231,31 +231,31 @@
},
"ProcessUnsupported": {
"description": null,
"message": "Process '{process}' is not supported.",
"message": "Process '{process}' (namespace: {namespace}) is not supported.",
"http": 400,
"tags": [
"Processes"
]
},
"ProcessArgumentUnsupported": {
"description": null,
"message": "Process '{process}' does not support argument '{argument}'.",
"message": "Process '{process}' (namespace: {namespace}) does not support the following arguments: {arguments}",
"http": 400,
"tags": [
"Processes"
]
},
"ProcessArgumentInvalid": {
"description": null,
"message": "The argument '{argument}' in process '{process}' is invalid: {reason}",
"message": "The argument '{argument}' in process '{process}' (namespace: {namespace}) is invalid: {reason}",
"http": 400,
"tags": [
"Processes"
]
},
"ProcessArgumentRequired": {
"description": null,
"message": "Process '{process}' requires argument '{argument}'.",
"message": "Process '{process}' (namespace: {namespace}) requires argument '{argument}'.",
"http": 400,
"tags": [
"Processes"
Expand Down

0 comments on commit f1993eb

Please sign in to comment.