Skip to content

Commit

Permalink
Fixed various issues surrounding loading payloads, fixed some json pa…
Browse files Browse the repository at this point in the history
…yloads being invalid/confusing, fixed various utility functions for posting jobs/udps etc.
  • Loading branch information
GeraldIr committed Feb 21, 2024
1 parent 454e860 commit 1f73f66
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 699 deletions.
17 changes: 9 additions & 8 deletions src/openeo_test_suite/lib/compliance_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ def _guess_root():

def get_examples_path():
return (
_guess_root().parents[2]
_guess_root().parents[1]
/ "src"
/ "openeo_test_suite"
/ "tests"
Expand All @@ -294,7 +294,7 @@ def load_payloads_from_directory(directory_path: str) -> Iterator[str]:
try:
# Load the JSON data from the file
data = json.load(file)
yield json.dumps(data)
yield data
except json.JSONDecodeError:
_log.error(f"Error decoding JSON in file: {filename}")
except Exception as e:
Expand All @@ -309,7 +309,7 @@ def set_uuid_in_job(json_data):
# Set the 'id' field to the generated UUID
json_data["process"]["id"] = new_id
# Return the modified JSON object
return new_id, json.dumps(json_data)
return new_id, json_data


def delete_id_resource(
Expand All @@ -336,18 +336,19 @@ def put_process_graphs(base_url: str, bearer_token: str): # TODO id and so fort

try:
for payload in payloads:
id = str(uuid.uuid4().hex)
id, payload = set_uuid_in_udp(payload)
created_udp_ids.append(id)
requests.put(
f"{base_url}/process_graphs/{id}",
response = requests.put(
f"{base_url}process_graphs/{id}",
data=payload,
headers={
"Content-Type": "application/json",
"Authorization": f"{bearer_token}",
},
)
print(response)
except Exception as e:
print(f"Failed to create process graph: {e}")
_log.error(f"Failed to create process graph: {e}")
return created_udp_ids


Expand Down Expand Up @@ -380,7 +381,7 @@ def post_jobs(base_url: str, bearer_token: str):

response = requests.post(
full_endpoint_url,
data=payload,
data=json.dumps(payload),
headers={
"Content-Type": "application/json",
"Authorization": f"{bearer_token}",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,292 +1,41 @@
{
"title": "NDVI based on Sentinel 2",
"description": "Deriving minimum NDVI measurements over pixel time series of Sentinel 2",
"process": {
"id": "ndvi",
"summary": "string",
"description": "string",
"parameters": [
{
"schema": {
"subtype": "string",
"deprecated": false,
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "http://example.com",
"type": "array",
"pattern": "/regex/",
"enum": [
null
],
"minimum": 0,
"maximum": 0,
"minItems": 0,
"maxItems": 0,
"items": [
{}
],
"property1": null,
"property2": null
},
"name": "string",
"description": "string",
"optional": false,
"deprecated": false,
"experimental": false,
"default": null
}
],
"returns": {
"description": "string",
"schema": {
"subtype": "string",
"deprecated": false,
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "http://example.com",
"type": "array",
"pattern": "/regex/",
"enum": [
null
],
"minimum": 0,
"maximum": 0,
"minItems": 0,
"maxItems": 0,
"items": [
{}
],
"property1": null,
"property2": null
}
},
"categories": [
"string"
],
"deprecated": false,
"experimental": false,
"exceptions": {
"Error Code1": {
"description": "string",
"message": "The value specified for the process argument '{argument}' in process '{process}' is invalid: {reason}",
"http": 400
},
"Error Code2": {
"description": "string",
"message": "The value specified for the process argument '{argument}' in process '{process}' is invalid: {reason}",
"http": 400
}
},
"examples": [
{
"title": "string",
"description": "string",
"arguments": {
"property1": {
"from_parameter": null,
"from_node": null,
"process_graph": null
},
"property2": {
"from_parameter": null,
"from_node": null,
"process_graph": null
}
},
"returns": null
}
],
"links": [
{
"rel": "related",
"href": "https://openeo.example",
"type": "text/html",
"title": "openEO"
}
],
"process_graph": {
"dc": {
"process_id": "load_collection",
"arguments": {
"id": "Sentinel-2",
"spatial_extent": {
"west": 16.1,
"east": 16.6,
"north": 48.6,
"south": 47.2
},
"temporal_extent": [
"2018-01-01",
"2018-02-01"
]
}
},
"bands": {
"process_id": "filter_bands",
"description": "Filter and order the bands. The order is important for the following reduce operation.",
"arguments": {
"data": {
"from_node": "dc"
},
"bands": [
"B08",
"B04",
"B02"
]
}
},
"evi": {
"process_id": "reduce",
"description": "Compute the EVI. Formula: 2.5 * (NIR - RED) / (1 + NIR + 6*RED + -7.5*BLUE)",
"arguments": {
"data": {
"from_node": "bands"
},
"dimension": "bands",
"reducer": {
"process_graph": {
"nir": {
"process_id": "array_element",
"arguments": {
"data": {
"from_parameter": "data"
},
"index": 0
}
},
"red": {
"process_id": "array_element",
"arguments": {
"data": {
"from_parameter": "data"
},
"index": 1
}
},
"blue": {
"process_id": "array_element",
"arguments": {
"data": {
"from_parameter": "data"
},
"index": 2
}
},
"sub": {
"process_id": "subtract",
"arguments": {
"data": [
{
"from_node": "nir"
},
{
"from_node": "red"
}
]
}
},
"p1": {
"process_id": "product",
"arguments": {
"data": [
6,
{
"from_node": "red"
}
]
}
},
"p2": {
"process_id": "product",
"arguments": {
"data": [
-7.5,
{
"from_node": "blue"
}
]
}
},
"sum": {
"process_id": "sum",
"arguments": {
"data": [
1,
{
"from_node": "nir"
},
{
"from_node": "p1"
},
{
"from_node": "p2"
}
]
}
},
"div": {
"process_id": "divide",
"arguments": {
"data": [
{
"from_node": "sub"
},
{
"from_node": "sum"
}
]
}
},
"p3": {
"process_id": "product",
"arguments": {
"data": [
2.5,
{
"from_node": "div"
}
]
},
"result": true
}
}
}
}
},
"mintime": {
"process_id": "reduce",
"description": "Compute a minimum time composite by reducing the temporal dimension",
"arguments": {
"data": {
"from_node": "evi"
},
"dimension": "temporal",
"reducer": {
"process_graph": {
"min": {
"process_id": "min",
"arguments": {
"data": {
"from_parameter": "data"
}
},
"result": true
}
}
}
}
},
"save": {
"process_id": "save_result",
"arguments": {
"data": {
"from_node": "mintime"
},
"format": "GTiff"
},
"result": true
}
}
},
"plan": "free",
"budget": 100,
"log_level": "warning"
}
"title": "Custom Test Process",
"description": "Loads and Saves austrian ground motion data",
"process": {
"process_graph": {
"load1": {
"process_id": "load_collection",
"arguments": {
"bands": [
"B01"
],
"properties": {},
"id": "CGLS_SSM_1KM",
"spatial_extent": {
"west": 16.186110851391813,
"east": 16.576456845030226,
"south": 48.08764096726651,
"north": 48.29291292355549
},
"temporal_extent": [
"2020-01-01T00:00:00Z",
"2020-12-13T00:00:00Z"
]
}
},
"save2": {
"process_id": "save_result",
"arguments": {
"data": {
"from_node": "load1"
},
"format": "NETCDF"
},
"result": true
}
},
"parameters": []
},
"plan": "free",
"budget": 100
}
Loading

0 comments on commit 1f73f66

Please sign in to comment.