Skip to content

Commit d5d0275

Browse files
author
Drew Meyers
committed
feat: New initiator action - OGC process execution
1 parent c263d60 commit d5d0275

File tree

3 files changed

+77
-1
lines changed

3 files changed

+77
-1
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import httpx
2+
3+
from ..utils.logger import logger
4+
from .base import Action
5+
6+
__all__ = ["SubmitOgcProcessExecution"]
7+
8+
9+
class SubmitOgcProcessExecution(Action):
10+
def __init__(self, payload, payload_info, params):
11+
super().__init__(payload, payload_info, params)
12+
logger.info("instantiated %s", __class__.__name__)
13+
14+
def execute(self):
15+
logger.debug("executing execute in %s", __class__.__name__)
16+
url = f"{self._params['ogc_processes_base_api_endpoint']}/processes/{self._params['process_id']}/execution"
17+
logger.info("url: %s", url)
18+
headers = {"Content-Type": "application/json", "Accept": "application/json"}
19+
# body = {
20+
# "inputs": self._params["execution_inputs"],
21+
# "outputs": self._params["execution_outputs"],
22+
# "subscriber": self._params["execution_subscriber"],
23+
# }
24+
body = {
25+
"inputs": {
26+
"payload": self._payload,
27+
"payload_info": self._payload_info,
28+
"on_success": self._params["on_success"],
29+
},
30+
"outputs": None,
31+
"subscriber": None,
32+
}
33+
response = httpx.post(url, headers=headers, json=body)
34+
if response.status_code in (200, 201):
35+
success = True
36+
resp = response.json()
37+
logger.info(
38+
"Successfully triggered the execution of the OGC Process %s: %s",
39+
self._params["process_id"],
40+
resp,
41+
)
42+
else:
43+
success = False
44+
resp = response.text
45+
logger.info(
46+
"Failed to trigger the execution of the OGC Process %s: %s",
47+
self._params["process_id"],
48+
resp,
49+
)
50+
return {"success": success, "response": resp}

src/unity_initiator/resources/routers_schema.yaml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ evaluator_config:
3636
# Currently only 2 types of actions are supported:
3737
# 1. submit payload to an SNS topic
3838
# 2. submit payload to an airflow DAG
39-
action_config: any(include("submit_dag_by_id_action"), include("submit_to_sns_topic_action"))
39+
action_config: any(include("submit_dag_by_id_action"), include("submit_to_sns_topic_action"), include("submit_ogc_process_execution_action"))
4040

4141
# Configuration for submitting a payload to an airflow DAG.
4242
submit_dag_by_id_action:
@@ -58,6 +58,17 @@ submit_to_sns_topic_action:
5858
topic_arn: str(required=False)
5959
on_success: include("on_success_actions", required=False)
6060

61+
# Configuration for submitting a OGC process execution.
62+
submit_ogc_process_execution_action:
63+
name: str(equals="submit_ogc_process_execution")
64+
params:
65+
process_id: str()
66+
ogc_processes_base_api_endpoint: str(required=False)
67+
execution_inputs: map(required=False)
68+
execution_outputs: map(required=False)
69+
execution_subscriber: map(required=False)
70+
on_success: include("on_success_actions", required=False)
71+
6172
# Configuration to pass onto the evaluator to use when evaluation is a success.
6273
on_success_actions:
6374
actions: list(include("action_config"), required=True, min=1, max=1)

tests/resources/test_router.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,3 +129,18 @@ initiator_config:
129129
#airflow_base_api_endpoint: xxx
130130
#airflow_username: <ARN to username entry in AWS Secrets Manager>
131131
#airflow_password: <ARN to password entry in Secrets Manager>
132+
133+
- regexes:
134+
- '(?<=/)(?P<filename>hello_world\.txt)$'
135+
evaluators:
136+
- name: eval_hello_world_readiness
137+
actions:
138+
- name: submit_ogc_process_execution
139+
params:
140+
process_id: eval_hello_world_readiness
141+
ogc_processes_base_api_endpoint: ${ogc_processes_base_api_endpoint}
142+
on_success:
143+
actions:
144+
- name: submit_ogc_process_execution
145+
params:
146+
process_id: hello_world

0 commit comments

Comments
 (0)