Topology api
Creating, loading and running topologies
Topology
Source code in hyrrokkin/api/topology.py
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 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 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 |
|
__init__(execution_folder, package_list)
Create a topology
Parameters:
Name | Type | Description | Default |
---|---|---|---|
execution_folder
|
str
|
the folder used to store the topology definition and files |
required |
package_list
|
list[str]
|
a list of the paths to python packages containing schemas (a schema.json) |
required |
Source code in hyrrokkin/api/topology.py
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
|
add_link(link_id, from_node_id, from_port, to_node_id, to_port)
Add a link to the topology
Parameters:
Name | Type | Description | Default |
---|---|---|---|
link_id
|
str
|
a unique identifier for the link |
required |
from_node_id
|
str
|
node id of the source node |
required |
from_port
|
Union[str, None]
|
port name on the source node, can be omitted if the "from" node has only one output port |
required |
to_node_id
|
str
|
node id of the destination node |
required |
to_port
|
Union[str, None]
|
port name on the destination node, can be ommitted if the "to" node has only one input port |
required |
Raises:
Type | Description |
---|---|
InvalidLinkError
|
if the link cannot be added |
Source code in hyrrokkin/api/topology.py
369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 |
|
add_node(node_id, node_type, properties={}, metadata={}, x=0, y=0)
Add a node to the topology
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node_id
|
str
|
the node's unique identifier, must not already exist within the topology |
required |
node_type
|
str
|
the type of the node, a string of the form package_id:node_type_id |
required |
properties
|
dict[str, JsonType]
|
dictionary containing the node's property names and values, must be JSON serialisable |
{}
|
metadata
|
dict[str, JsonType]
|
a dictionary containing the new metadata |
{}
|
x
|
int
|
the new x-coordinate value |
0
|
y
|
int
|
the new y-coordinate value |
0
|
Source code in hyrrokkin/api/topology.py
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
|
clear()
Remove all nodes and links from the topology
Source code in hyrrokkin/api/topology.py
645 646 647 648 649 |
|
get_configuration_data(package_id, key)
Get binary or string data associated with a package configuration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
package_id
|
str
|
package identifier |
required |
key
|
str
|
a key to locate the data (can only contain alphanumeric characters and underscores) |
required |
Returns:
Type | Description |
---|---|
Union[bytes, str, None]
|
data or None if no data is associated with the key |
Source code in hyrrokkin/api/topology.py
326 327 328 329 330 331 332 333 334 335 336 337 338 339 |
|
get_configuration_data_keys(package_id)
Get the list of keys for which the package configuration stores binary data
Parameters:
Name | Type | Description | Default |
---|---|---|---|
package_id
|
str
|
package identifier |
required |
Returns:
Type | Description |
---|---|
list[str]
|
a set of data keys |
Source code in hyrrokkin/api/topology.py
355 356 357 358 359 360 361 362 363 364 365 366 367 |
|
get_configuration_properties(package_id)
Get the properties for the specified package configuration
Parameters:
Name | Type | Description | Default |
---|---|---|---|
package_id
|
str
|
the package identifier |
required |
Returns:
Type | Description |
---|---|
dict[str, JsonType]
|
A dictionary containing the properties defined for that package configuration |
Source code in hyrrokkin/api/topology.py
631 632 633 634 635 636 637 638 639 640 641 642 643 |
|
get_input_port_names(node_id)
Get the input port names for a given node
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node_id
|
str
|
the id of the node |
required |
Returns:
Type | Description |
---|---|
list[str]
|
list of input port names |
Source code in hyrrokkin/api/topology.py
594 595 596 597 598 599 600 601 602 603 604 605 606 |
|
get_link(link_id)
Get the link details for a given link
Parameters:
Name | Type | Description | Default |
---|---|---|---|
link_id
|
str
|
the id of the link to retrieve |
required |
Returns:
Type | Description |
---|---|
tuple[str, str, str, str]
|
tuple (from_node_id,from_port,to_node_id,to_port) |
Source code in hyrrokkin/api/topology.py
567 568 569 570 571 572 573 574 575 576 577 578 |
|
get_link_ids()
Get the ids of all links in the topology
Returns:
Type | Description |
---|---|
list[str]
|
list of link ids |
Source code in hyrrokkin/api/topology.py
558 559 560 561 562 563 564 565 |
|
get_metadata()
Get the metadata of the topology
Returns:
Type | Description |
---|---|
dict[str, JsonType]
|
A dictionary containing the metadata |
Source code in hyrrokkin/api/topology.py
608 609 610 611 612 613 614 615 |
|
get_node_data(node_id, key)
Get binary data associated with this node.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node_id
|
str
|
node identifier |
required |
key
|
str
|
a key to locate the data (can only contain alphanumeric characters and underscores) |
required |
Returns:
Type | Description |
---|---|
Union[bytes, None]
|
data or None if no data is associated with the key |
Source code in hyrrokkin/api/topology.py
244 245 246 247 248 249 250 251 252 253 254 255 256 257 |
|
get_node_data_keys(node_id)
Get the list of keys for which the node stores binary data
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node_id
|
str
|
node identifier |
required |
Returns:
Type | Description |
---|---|
list[str]
|
a set of data keys |
Source code in hyrrokkin/api/topology.py
272 273 274 275 276 277 278 279 280 281 282 283 284 |
|
get_node_ids()
Get the ids of all nodes in the topology
Returns:
Type | Description |
---|---|
list[str]
|
list of node ids |
Source code in hyrrokkin/api/topology.py
462 463 464 465 466 467 468 469 |
|
get_node_metadata(node_id)
Get the metadata of a node
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node_id
|
str
|
the id of the node |
required |
Returns:
Type | Description |
---|---|
dict[str, JsonType]
|
A dictionary containing the metadata |
Source code in hyrrokkin/api/topology.py
535 536 537 538 539 540 541 542 543 544 545 |
|
get_node_properties(node_id)
Get the properties for the specified node
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node_id
|
str
|
the node identifier |
required |
Returns:
Type | Description |
---|---|
dict[str, JsonType]
|
A dictionary containing the properties defined for that node |
Source code in hyrrokkin/api/topology.py
617 618 619 620 621 622 623 624 625 626 627 628 629 |
|
get_node_type(node_id)
Get the node package and type for a given node
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node_id
|
str
|
the id of the node to retrieve |
required |
Returns:
Type | Description |
---|---|
tuple[str, str]
|
tuple (package_id, node_type_id) |
Source code in hyrrokkin/api/topology.py
471 472 473 474 475 476 477 478 479 480 481 482 483 |
|
get_output_port_names(node_id)
Get the output port names for a given node
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node_id
|
str
|
the id of the node |
required |
Returns:
Type | Description |
---|---|
list[str]
|
list of output port names |
Source code in hyrrokkin/api/topology.py
580 581 582 583 584 585 586 587 588 589 590 591 592 |
|
get_package_ids()
Gets the ids of all packages
Returns:
Type | Description |
---|---|
list[str]
|
list of package ids |
Source code in hyrrokkin/api/topology.py
453 454 455 456 457 458 459 460 |
|
load_dir()
Load a topology from the execution folder
Source code in hyrrokkin/api/topology.py
99 100 101 102 103 104 |
|
load_zip(from_file)
Load a topology from a binary stream
Parameters:
Name | Type | Description | Default |
---|---|---|---|
from_file
|
BytesIO
|
a binary stream, opened for reading |
required |
Returns:
Type | Description |
---|---|
dict
|
a dictionary containing any node renamings performed to avoid id collisions with existing nodes |
Source code in hyrrokkin/api/topology.py
85 86 87 88 89 90 91 92 93 94 95 96 97 |
|
open_runner(status_event_handler=None, execution_event_handler=None, engine_launcher=None, read_only=False)
Create a runner to run the topology
Parameters:
Name | Type | Description | Default |
---|---|---|---|
status_event_handler
|
Callable[[str, str, str, str], None]
|
specify a function to call when a node/configuration sets its status passing parameters target_id, target_type, msg, status |
None
|
execution_event_handler
|
Callable[[Union[float, None], str, str, Union[Dict, Exception, None], bool], None]
|
specify a function to call when a node changes its execution status passing parameters timestamp, node_id, state, exception, is_manual |
None
|
engine_launcher
|
Union[EngineLauncher, None]
|
the engine_launcher to use to run the topology in a remote process. if not specified, select an appropriate one for the packages loaded |
None
|
read_only
|
bool
|
if true, do not allow nodes and configurations to persist data/properties changes to disk when running the topology |
False
|
Returns: a TopologyInteractor instance that allows the execution to be stopped and clients to be attached and detached
Source code in hyrrokkin/api/topology.py
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
|
remove_link(link_id)
Remove a link from the topology
Parameters:
Name | Type | Description | Default |
---|---|---|---|
link_id
|
str
|
the link's unique identifier |
required |
Source code in hyrrokkin/api/topology.py
441 442 443 444 445 446 447 448 449 450 451 |
|
remove_node(node_id)
Remove a node from the topology
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node_id
|
str
|
the node's unique identifier |
required |
Source code in hyrrokkin/api/topology.py
196 197 198 199 200 201 202 203 204 205 |
|
save_zip(to_file=None, include_data=True)
Save a topology to a binary stream
Parameters:
Name | Type | Description | Default |
---|---|---|---|
to_file
|
BufferedWriter
|
an opened binary file to which the topology will be saved, if provided |
None
|
include_data
|
bool
|
whether to include node/configuration data in the saved zip |
True
|
Returns:
Type | Description |
---|---|
Union[None, bytes]
|
if to_file is not provided, returns a bytes object containing the saved topology |
Source code in hyrrokkin/api/topology.py
106 107 108 109 110 111 112 113 114 115 116 117 |
|
serialise()
Serialise the topology to a dictionary without data/properties
Returns:
Type | Description |
---|---|
dict[str, JsonType]
|
a dictionary describing the topoology |
Source code in hyrrokkin/api/topology.py
525 526 527 528 529 530 531 532 533 |
|
serialise_link(link_id)
Serialise a link to a dictionary with self-explanatory keys
Parameters:
Name | Type | Description | Default |
---|---|---|---|
link_id
|
str
|
the id of the link to serialise |
required |
Returns:
Type | Description |
---|---|
dict[str, JsonType]
|
a dictionary describing the link |
Source code in hyrrokkin/api/topology.py
505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 |
|
serialise_node(node_id)
Serialise a node to a dictionary with self-explanatory keys
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node_id
|
str
|
the id of the node to serialise |
required |
Returns:
Type | Description |
---|---|
dict[str, JsonType]
|
a dictionary describing the node |
Source code in hyrrokkin/api/topology.py
485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 |
|
set_configuration_data(package_id, key, data)
Set binary or string data associated with this node.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
package_id
|
str
|
package identifier |
required |
key
|
str
|
a key to locate the data (can only contain alphanumeric characters and underscores) |
required |
data
|
Union[bytes, str, None]
|
data to be stored |
required |
Source code in hyrrokkin/api/topology.py
341 342 343 344 345 346 347 348 349 350 351 352 353 |
|
set_configuration_properties(package_id, properties)
Set the properties of a package's configuration
Parameters:
Name | Type | Description | Default |
---|---|---|---|
package_id
|
str
|
the id of the packahe |
required |
properties
|
dict
|
a dictionary containing the configuration properties, must be JSON serialisable. |
required |
Source code in hyrrokkin/api/topology.py
313 314 315 316 317 318 319 320 321 322 323 324 |
|
set_configuration_property(package_id, properties)
Update a property of a package configuration
Parameters:
Name | Type | Description | Default |
---|---|---|---|
package_id
|
str
|
the package's identifier |
required |
properties
|
dict[str, JsonType]
|
dictionary containing properties |
required |
Source code in hyrrokkin/api/topology.py
300 301 302 303 304 305 306 307 308 309 310 311 |
|
set_metadata(metadata)
Set metadata for this topology
Parameters:
Name | Type | Description | Default |
---|---|---|---|
metadata
|
dict[str, str]
|
a dictionary containing metadata, consisting of string keys and values. |
required |
Notes
the following keys will be understood by hyrrokkin based tools - version, description, authors
Source code in hyrrokkin/api/topology.py
161 162 163 164 165 166 167 168 169 170 171 |
|
set_node_data(node_id, key, data)
Set binary data associated with this node.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node_id
|
str
|
node identifier |
required |
key
|
str
|
a key to locate the data (can only contain alphanumeric characters and underscores) |
required |
data
|
Union[bytes, None]
|
data to be stored |
required |
Source code in hyrrokkin/api/topology.py
259 260 261 262 263 264 265 266 267 268 269 270 |
|
set_node_properties(node_id, properties)
Update the property of a node
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node_id
|
str
|
the node's identifier |
required |
properties
|
dict[str, JsonType]
|
dictionary containing properties |
required |
Source code in hyrrokkin/api/topology.py
232 233 234 235 236 237 238 239 240 241 242 |
|
update_node_metadata(node_id, metadata)
Updates the metadata of a node
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node_id
|
str
|
the id of the node |
required |
metadata
|
dict[str, JsonType]
|
a dictionary containing the new metadata |
required |
Source code in hyrrokkin/api/topology.py
547 548 549 550 551 552 553 554 555 556 |
|
update_node_position(node_id, x, y)
Update a node's position
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node_id
|
str
|
the id of the node to update |
required |
x
|
int
|
the new x-coordinate value |
required |
y
|
int
|
the new y-coordinate value |
required |
Source code in hyrrokkin/api/topology.py
207 208 209 210 211 212 213 214 215 216 |
|
check_not_running(func)
Decorator that prevents access to a method if any runners are running :param func: the method to be decorated :return: wrapped method
Source code in hyrrokkin/api/topology.py
39 40 41 42 43 44 45 46 47 48 49 |
|