Skip to content

Commit 2275a78

Browse files
committed
GDC draft II
1 parent ec854e8 commit 2275a78

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

src/connection.js

+59
Original file line numberDiff line numberDiff line change
@@ -804,6 +804,62 @@ class Connection {
804804
return await pg.describeUserProcess();
805805
}
806806

807+
isOgcProcess(process) {
808+
let nodes = Object.values(process.process_graph);
809+
return Boolean(nodes.find(node => {
810+
let process = this.processes.get(node.process_id);
811+
return Utils.isObject(process) && Boolean(process.ogcapi);
812+
}));
813+
}
814+
815+
async executeOgcProcess(process, abortController = null) {
816+
if (Utils.size(process.process_graph) !== 1) {
817+
throw new Error('Synchronous execution with OGC API - Processes only supports one process at at time.');
818+
}
819+
let requestBody = this._normalizeUserProcess(
820+
process,
821+
{
822+
plan: plan,
823+
budget: budget
824+
}
825+
);
826+
let response = await this._post('/result', requestBody, Environment.getResponseType(), abortController);
827+
let syncResult = {
828+
data: response.data,
829+
costs: null,
830+
type: null,
831+
logs: []
832+
};
833+
834+
if (typeof response.headers['openeo-costs'] === 'number') {
835+
syncResult.costs = response.headers['openeo-costs'];
836+
}
837+
838+
if (typeof response.headers['content-type'] === 'string') {
839+
syncResult.type = response.headers['content-type'];
840+
}
841+
842+
let links = Array.isArray(response.headers.link) ? response.headers.link : [response.headers.link];
843+
for(let link of links) {
844+
if (typeof link !== 'string') {
845+
continue;
846+
}
847+
let logs = link.match(/^<([^>]+)>;\s?rel="monitor"/i);
848+
if (Array.isArray(logs) && logs.length > 1) {
849+
try {
850+
let logsResponse = await this._get(logs[1]);
851+
if (Utils.isObject(logsResponse.data) && Array.isArray(logsResponse.data.logs)) {
852+
syncResult.logs = logsResponse.data.logs;
853+
}
854+
} catch(error) {
855+
console.warn(error);
856+
}
857+
}
858+
}
859+
860+
return syncResult;
861+
}
862+
807863
/**
808864
* Executes a process synchronously and returns the result as the response.
809865
*
@@ -824,6 +880,9 @@ class Connection {
824880
budget: budget
825881
}
826882
);
883+
if (isOgcProcess(requestBody.process)) {
884+
return this.executeOgcProcess(process, abortController);
885+
}
827886
let response = await this._post('/result', requestBody, Environment.getResponseType(), abortController);
828887
let syncResult = {
829888
data: response.data,

src/gdc.js

+12
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class GdcCapabilities extends Capabilities {
1212
describeCoverageRangetype: 'get /collections/{collection_id}/coverage/rangetype',
1313
describeCoverageRangeset: 'get /collections/{collection_id}/coverage/rangeset',
1414
describeCoverageMetadata: 'get /collections/{collection_id}/coverage/metadata',
15+
executeOgcProcess: 'post /processes/{processId}/execution',
1516
});
1617
this.checkConformance();
1718
}
@@ -66,6 +67,14 @@ class GdcCapabilities extends Capabilities {
6667
"path": "/processes",
6768
"methods": ["GET"]
6869
});
70+
this.data.endpoints.push({
71+
"path": "/processes/{processId}",
72+
"methods": ["GET"]
73+
});
74+
this.data.endpoints.push({
75+
"path": "/processes/{processId}/execution",
76+
"methods": ["POST"]
77+
});
6978
this.data.endpoints.push({
7079
"path": "/jobs",
7180
"methods": ["GET"]
@@ -189,6 +198,7 @@ const Migrate = {
189198

190199
// Make sure the required properties are present
191200
collection = StacMigrate.collection(collection);
201+
collection.ogcapi = true;
192202
// Make links absolute
193203
if (Array.isArray(collection.links)) {
194204
collection.links = this.connection.makeLinksAbsolute(collection.links, response);
@@ -202,6 +212,7 @@ const Migrate = {
202212
return process;
203213
}
204214

215+
process.ogcapi = true;
205216
process.summary = process.title;
206217

207218
process.parameters = [];
@@ -247,6 +258,7 @@ const Migrate = {
247258
return job;
248259
}
249260

261+
job.ogcapi = true;
250262
job.id = job.jobID;
251263
job.process = {
252264
process_graph: {

0 commit comments

Comments
 (0)