Skip to content

Commit

Permalink
FIX: Use the schema ref for service communication
Browse files Browse the repository at this point in the history
  • Loading branch information
thclark committed Jun 11, 2024
1 parent ce433ec commit dc6bf36
Showing 1 changed file with 2 additions and 292 deletions.
294 changes: 2 additions & 292 deletions octue/cloud/events/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,301 +10,11 @@
SERVICE_COMMUNICATION_SCHEMA_VERSION = "0.13.0"
SERVICE_COMMUNICATION_SCHEMA_INFO_URL = "https://strands.octue.com/octue/service-communication"

# SERVICE_COMMUNICATION_SCHEMA = {
# "$ref": f"https://jsonschema.registry.octue.com/octue/service-communication/{SERVICE_COMMUNICATION_SCHEMA_VERSION}.json"
# }

SERVICE_COMMUNICATION_SCHEMA = {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "Octue services communication",
"description": "A schema describing the events Octue services can emit and consume.",
"type": "object",
"properties": {
"attributes": {
"title": "Event attributes",
"description": "Metadata for routing the event, adding context, and guiding the receiver's behaviour.",
"type": "object",
"oneOf": [
{
"title": "Attributes for an event from a parent service",
"properties": {
"datetime": {
"type": "string",
"format": "date-time",
"description": "The UTC datetime the event was emitted at in ISO8601 format.",
},
"uuid": {
"type": "string",
"format": "uuid",
"description": "A universally unique identifier for this event.",
},
"question_uuid": {
"type": "string",
"description": "The UUID of the question the event is related to.",
},
"parent_question_uuid": {
"oneOf": [
{
"type": "string",
"description": "The UUID of the question that triggered this question.",
},
{"type": "null", "description": "If this is the originating question."},
]
},
"originator_question_uuid": {
"type": "string",
"description": "The UUID of the ultimate question that triggered this tree of questions.",
},
"forward_logs": {"type": "boolean"},
"save_diagnostics": {
"enum": ["SAVE_DIAGNOSTICS_OFF", "SAVE_DIAGNOSTICS_ON_CRASH", "SAVE_DIAGNOSTICS_ON"]
},
"parent": {
"type": "string",
"description": "The service revision unique identifier (SRUID) of the parent that asked the question this event is related to.",
"examples": ["octue:test-service:1.2.0"],
},
"originator": {
"type": "string",
"description": "The service revision unique identifier (SRUID) of the service revision that triggered the tree of questions this event is related to.",
"examples": ["octue:test-service:1.2.0"],
},
"sender": {
"type": "string",
"description": "The service revision unique identifier (SRUID) of the service revision emitting the event.",
"examples": ["octue:test-service:1.2.0"],
},
"sender_type": {
"type": "string",
"pattern": "^PARENT$",
"description": "An indicator that the sender is a parent.",
},
"sender_sdk_version": {
"type": "string",
"description": "The version of Octue SDK the sender is running.",
},
"recipient": {
"type": "string",
"description": "The service revision unique identifier (SRUID) of the service revision this event is meant for.",
"examples": ["octue:test-service:1.2.0"],
},
"retry_count": {
"type": "integer",
"description": "The retry count for the question. All events related to the retry of a given question will have the same retry count. A question that is being asked for the first time will have a retry count of 0.",
"minimum": 0,
},
},
"required": [
"datetime",
"uuid",
"question_uuid",
"parent_question_uuid",
"originator_question_uuid",
"forward_logs",
"save_diagnostics",
"parent",
"originator",
"sender",
"sender_type",
"sender_sdk_version",
"recipient",
"retry_count",
],
},
{
"title": "Attributes for an event from a child service",
"properties": {
"datetime": {
"type": "string",
"format": "date-time",
"description": "The UTC datetime the event was emitted at in ISO8601 format.",
},
"uuid": {
"type": "string",
"format": "uuid",
"description": "A universally unique identifier for this event.",
},
"order": {
"type": "integer",
"minimum": 0,
"description": "The position of this event in the stream of events it is part of.",
},
"question_uuid": {
"type": "string",
"description": "The UUID of the question the event is related to.",
},
"parent_question_uuid": {
"oneOf": [
{
"type": "string",
"description": "The UUID of the question that triggered this question.",
},
{"type": "null", "description": "If this is the originating question."},
]
},
"originator_question_uuid": {
"type": "string",
"description": "The UUID of the ultimate question that triggered this tree of questions.",
},
"parent": {
"type": "string",
"description": "The service revision unique identifier (SRUID) of the parent that asked the question this event is related to.",
"examples": ["octue:test-service:1.2.0"],
},
"originator": {
"type": "string",
"description": "The service revision unique identifier (SRUID) of the service revision that triggered the tree of questions this event is related to.",
"examples": ["octue:test-service:1.2.0"],
},
"sender": {
"type": "string",
"description": "The service revision unique identifier (SRUID) of the service revision emitting the event.",
"examples": ["octue:test-service:1.2.0"],
},
"sender_type": {
"type": "string",
"pattern": "^CHILD$",
"description": "An indicator that the sender is a child.",
},
"sender_sdk_version": {
"type": "string",
"description": "The version of Octue SDK the sender is running.",
},
"recipient": {
"type": "string",
"description": "The service revision unique identifier (SRUID) of the service revision this event is meant for.",
"examples": ["octue:test-service:1.2.0"],
},
"retry_count": {
"type": "integer",
"description": "The retry count for the question. All events related to the retry of a given question will have the same retry count. A question that is being asked for the first time will have a retry count of 0.",
"minimum": 0,
},
},
"required": [
"datetime",
"uuid",
"order",
"question_uuid",
"parent_question_uuid",
"originator_question_uuid",
"parent",
"originator",
"sender",
"sender_type",
"sender_sdk_version",
"recipient",
"retry_count",
],
},
],
},
"event": {
"title": "Event data",
"description": "An Octue service event/message (e.g. heartbeat, log record, result).",
"type": "object",
"oneOf": [
{
"title": "Delivery acknowledgement",
"description": "An acknowledgement of successful receipt of a question. This type of message can only be sent by a child to a parent as part of the child's response to a question.",
"type": "object",
"properties": {
"kind": {"type": "string", "pattern": "^delivery_acknowledgement$"},
"datetime": {
"type": "string",
"pattern": "^[1-9]\\d{3}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(?:.\\d+)?$",
},
},
"required": ["kind", "datetime"],
},
{
"title": "Heartbeat",
"type": "object",
"description": "A message sent at regular intervals to let the parent know the child is still processing its question and that it should keep waiting for further messages. This type of message can only be sent by a child to a parent as part of the child's response to a question.",
"properties": {
"kind": {"type": "string", "pattern": "^heartbeat$"},
"datetime": {
"type": "string",
"pattern": "^[1-9]\\d{3}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(?:.\\d+)?$",
},
},
"required": ["kind", "datetime"],
},
{
"title": "Monitor message",
"type": "object",
"description": "An interim result or update sent during the processing of a question. This type of message can only be sent by a child to a parent as part of the child's response to a question.",
"properties": {
"kind": {"type": "string", "pattern": "^monitor_message$"},
"data": {
"description": "This schema is set in the child's twine (see https://twined.readthedocs.io/en/latest/anatomy_monitors.html)."
},
},
"required": ["kind", "data"],
},
{
"title": "Log record",
"description": "A log record generated during the processing of a question. This type of message can only be sent by a child to a parent as part of the child's response to a question.",
"type": "object",
"properties": {
"kind": {"type": "string", "pattern": "^log_record$"},
"log_record": {"type": "object"},
},
"required": ["kind", "log_record"],
},
{
"title": "Exception",
"description": "An unhandled error raised during the processing of a question, marking its premature end. This type of message can only be sent by a child to a parent as part of the child's response to a question.",
"type": "object",
"properties": {
"kind": {"type": "string", "pattern": "^exception$"},
"exception_message": {"type": "string"},
"exception_type": {"type": "string"},
"exception_traceback": {"type": "array", "items": {"type": "string"}},
},
"required": ["kind", "exception_message", "exception_type", "exception_traceback"],
},
{
"title": "Result",
"description": "The final result of processing a question. This type of message can only and must be sent by a child to a parent to complete the child's response to a question.",
"type": "object",
"properties": {
"kind": {"type": "string", "pattern": "^result$"},
"output_values": {
"description": "This schema is set in the child's twine (see https://twined.readthedocs.io/en/latest/anatomy_values.html)."
},
"output_manifest": {
"description": "See schema information here: https://strands.octue.com/octue/manifest",
"$ref": "https://jsonschema.registry.octue.com/octue/manifest/0.1.0.json",
},
},
"required": ["kind"],
},
{
"title": "Question",
"description": "A question for a child to process. This type of message can only be sent by a parent to a child to trigger the child to process a question.",
"properties": {
"kind": {"type": "string", "pattern": "^question$"},
"input_values": {
"description": "This schema is set in the child's twine (see https://twined.readthedocs.io/en/latest/anatomy_values.html)."
},
"input_manifest": {
"description": "See schema information here: https://strands.octue.com/octue/manifest",
"$ref": "https://jsonschema.registry.octue.com/octue/manifest/0.1.0.json",
},
"children": {
"description": "See schema information here: https://strands.octue.com/octue/children",
"$ref": "https://jsonschema.registry.octue.com/octue/children/0.1.0.json",
},
},
"required": ["kind"],
},
],
},
},
"required": ["attributes", "event"],
"$ref": f"https://jsonschema.registry.octue.com/octue/service-communication/{SERVICE_COMMUNICATION_SCHEMA_VERSION}.json"
}


# Instantiate a JSON schema validator to cache the service communication schema. This avoids downloading it from the
# registry every time a message is validated against it.
jsonschema.Draft202012Validator.check_schema(SERVICE_COMMUNICATION_SCHEMA)
Expand Down

0 comments on commit dc6bf36

Please sign in to comment.