Overview¶
The brain of the Orbiter framework is in it's Rules
and the Rulesets
that contain them.
- A
Rule
is a python function that is evaluated and produces something (typically an Object) or nothing - A
Ruleset
is a collection ofRules
that are evaluated in priority order - A
TranslationRuleset
is a collection ofRulesets
, relating to an Origin andFileType
, with atranslate_fn
which determines how to apply the rulesets.
Different Rules
are applied in different scenarios, such as:
- converting input to an Airflow DAG (
@dag_rule
), - converting input to a specific Airflow Operator (
@task_rule
), - filtering entries from the input data
(
@dag_filter_rule
,@task_filter_rule
).
Tip
To map the following input
to an Airflow
BashOperator,
a Rule
could parse it as follows:
@task_rule
def my_rule(val):
if 'command' in val:
return OrbiterBashOperator(task_id=val['id'], bash_command=val['command'])
else:
return None
This returns a
OrbiterBashOperator
, which will become an Airflow
BashOperator
when the translation completes.
orbiter.rules.rulesets.translate ¶
translate(
translation_ruleset, input_dir: Path
) -> OrbiterProject
Orbiter expects a folder containing text files which may have a structure like:
The standard translation function performs the following steps:
- Find all files with the expected
TranslationRuleset.file_type
(.json
,.xml
,.yaml
, etc.) in the input folder.- Load each file and turn it into a Python Dictionary.
- For each file: Apply the
TranslationRuleset.dag_filter_ruleset
to filter down to entries that can translate to a DAG, in priority order. The file name is added under a__file
key to both input and output dictionaries for the DAG Filter rule.- For each dictionary: Apply the
TranslationRuleset.dag_ruleset
, to convert the object to anOrbiterDAG
, in priority-order, stopping when the first rule returns a match. If no rule returns a match, the entry is filtered.
- For each dictionary: Apply the
- Apply the
TranslationRuleset.task_filter_ruleset
to filter down to entries in the DAG that can translate to a Task, in priority-order.- For each: Apply the
TranslationRuleset.task_ruleset
, to convert the object to a specific Task, in priority-order, stopping when the first rule returns a match. If no rule returns a match, the entry is filtered.
- For each: Apply the
- After the DAG and Tasks are mapped, the
TranslationRuleset.task_dependency_ruleset
is applied in priority-order, stopping when the first rule returns a match, to create a list ofOrbiterTaskDependency
, which are then added to each task in theOrbiterDAG
- Apply the
TranslationRuleset.post_processing_ruleset
, against theOrbiterProject
, which can make modifications after all other rules have been applied. - After translation - the
OrbiterProject
is rendered to the output folder.
Source code in orbiter/rules/rulesets.py
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 |
|