Topology API
Creating, loading and running topologies
Construct a topology using this constructor
Topology
Bases: TopologyApi
Source code in hyrrokkin/api/topology.py
50 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 | |
__init__(topology_folder, package_list, temporary_folder=None, engine_launcher=None, read_only=False, set_engine_pid_callback=None, import_from_path=None)
Create a topology instance
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
topology_folder
|
str
|
the folder used to store the topology's definition and files |
required |
package_list
|
list[str]
|
a list of the paths to python packages containing hyrrokkin package schemas (a schema.json file) |
required |
temporary_folder
|
str | None
|
a folder used to store files temporarily during execution |
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
|
set_engine_pid_callback
|
Callable[[int], None]
|
function that is called with the process identifier (PID) of the engine process if the engine is launched in a sub-process |
None
|
import_from_path
|
str
|
import from this path to initialise the topology |
None
|
Source code in hyrrokkin/api/topology.py
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 | |
check_notclosed(func)
Decorator that prevents access to a method once the closed attribute is set to True :param func: the method to be decorated :return: wrapped method
Source code in hyrrokkin/api/topology.py
35 36 37 38 39 40 41 42 43 44 45 46 47 | |
A topology inherits the following methods:
TopologyApi
Bases: ABC
Source code in hyrrokkin/interfaces/topology_api.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 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 | |
add_link(link_id, from_node_id, from_port, to_node_id, to_port, ref=None)
abstractmethod
Add a link to the topology
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
link_id
|
str
|
a requested unique identifier for the link |
required |
from_node_id
|
str
|
node id of the source node |
required |
from_port
|
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
|
str | None
|
port name on the destination node, can be omitted if the "to" node has only one input port |
required |
ref
|
str | None
|
an optional reference that identifies this request |
None
|
Raises:
| Type | Description |
|---|---|
InvalidLinkError
|
if the link cannot be added |
Returns:
| Type | Description |
|---|---|
str
|
link_id of the added link |
Source code in hyrrokkin/interfaces/topology_api.py
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | |
add_node(node_id, node_type, metadata={}, properties={}, data={}, copy_from_node_id='', ref=None)
abstractmethod
Add a node to the topology
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_id
|
str | None
|
the node's requested unique identifier or None |
required |
node_type
|
str
|
the type of the node, a string of the form package_id:node_type_id |
required |
metadata
|
dict[str, JsonType]
|
a dictionary containing the new metadata |
{}
|
properties
|
dict[str, JsonType]
|
dictionary containing the node's property names and values, must be JSON serialisable |
{}
|
data
|
dict[str, bytes]
|
if set, initialise with the properties and data copied from this node |
{}
|
copy_from_node_id
|
str
|
if set, initialise with the properties and data copied from this node rather than supplied in the data and properties arguments |
''
|
ref
|
str | None
|
an optional reference that identifies this request |
None
|
Returns:
| Type | Description |
|---|---|
str
|
the id of the added node |
Source code in hyrrokkin/interfaces/topology_api.py
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | |
add_output_listener(node_id, output_port_name, listener)
abstractmethod
Listen for values output from a node in the topology. Replaces any existing listener on the node/port if present.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_id
|
str
|
the node id |
required |
output_port_name
|
str
|
the name of the node's output port |
required |
listener
|
Callable[[bytes], None]
|
a callback function which is invoked with the value on the output port when the node is run |
required |
Source code in hyrrokkin/interfaces/topology_api.py
261 262 263 264 265 266 267 268 269 270 | |
attach_configuration_client(package_id, session_id='', client_id='', client_options={})
abstractmethod
Attach a client instance to a package configuration
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
package_id
|
str
|
the package configuration to which the client is to be attached |
required |
session_id
|
str
|
the id of an opened interactive session |
''
|
client_id
|
str
|
the id of the client to attach |
''
|
client_options
|
dict
|
optional, a dictionary with extra parameters for the client |
{}
|
Returns:
| Type | Description |
|---|---|
ClientApi
|
an object which implements the Client API and provides methods to interact with the configuration |
Source code in hyrrokkin/interfaces/topology_api.py
335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 | |
attach_listener(listener)
abstractmethod
Attach a listener instance which implements the TopologyListenerAPI
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
listener
|
TopologyListenerAPI
|
the listener instance |
required |
Source code in hyrrokkin/interfaces/topology_api.py
469 470 471 472 473 474 475 476 | |
attach_node_client(node_id, session_id='', client_id='', client_options={})
abstractmethod
Attach a client instance to a node. Any client already attached to the node with the same client_id will be detached.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_id
|
str
|
the node to which the client is to be attached |
required |
session_id
|
str
|
the id of an opened interactive session |
''
|
client_id
|
str
|
the name of the client to attach, as defined in the node's schema |
''
|
client_options
|
dict
|
optional, a dictionary with extra parameters from the client |
{}
|
Returns:
| Type | Description |
|---|---|
ClientApi
|
an instance which implements the Client API and provides methods to interact with the node |
Source code in hyrrokkin/interfaces/topology_api.py
317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 | |
clear(ref=None)
abstractmethod
Remove all nodes and links from the topology
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ref
|
str | None
|
an optional reference that identifies this request |
None
|
Source code in hyrrokkin/interfaces/topology_api.py
118 119 120 121 122 123 124 125 126 | |
close_session(session_id)
abstractmethod
Close a session
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_id
|
str
|
the identifier of the session to close |
required |
Source code in hyrrokkin/interfaces/topology_api.py
308 309 310 311 312 313 314 315 | |
detach_listener(listener)
abstractmethod
Detach a listener
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
listener
|
TopologyListenerAPI
|
the listener instance |
required |
Source code in hyrrokkin/interfaces/topology_api.py
478 479 480 481 482 483 484 485 | |
export_to(to_path, include_data=True)
abstractmethod
save the topology to a zip file or yaml file
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
to_path
|
str
|
the path to the YAML file or ZIP file to export to |
required |
include_data
|
bool
|
whether or not to export data as well as properties |
True
|
Source code in hyrrokkin/interfaces/topology_api.py
413 414 415 416 417 418 419 420 421 | |
get_link_ids_for_node(node_id)
abstractmethod
Get the ids of all links in the topology that are connected to a node
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_id
|
str
|
the id of the node |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
list of link ids connected to the node |
Source code in hyrrokkin/interfaces/topology_api.py
444 445 446 447 448 449 450 451 452 453 454 | |
get_links()
abstractmethod
Get details of the link ids and link types in the topology
Returns:
| Type | Description |
|---|---|
dict[str, tuple[LinkTypeApi, str, str]]
|
dict containing a mapping from link id to a tuple of format (link_type, |
Source code in hyrrokkin/interfaces/topology_api.py
435 436 437 438 439 440 441 442 | |
get_node_data(node_id, key)
abstractmethod
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 |
|---|---|
bytes | None
|
data or None if no data is associated with the key |
Source code in hyrrokkin/interfaces/topology_api.py
233 234 235 236 237 238 239 240 241 242 243 244 | |
get_node_data_keys(node_id)
abstractmethod
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/interfaces/topology_api.py
246 247 248 249 250 251 252 253 254 255 256 | |
get_node_properties(node_id)
abstractmethod
Gets the properties of a node
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_id
|
str
|
the node's identifier |
required |
Returns:
| Type | Description |
|---|---|
dict[str, JsonType]
|
dictionary containing properties |
Source code in hyrrokkin/interfaces/topology_api.py
221 222 223 224 225 226 227 228 229 230 231 | |
get_nodes()
abstractmethod
Get details of the node ids and types in the topology
Returns:
| Type | Description |
|---|---|
dict[str, NodeTypeApi]
|
dict containing a mapping from node id to node type |
Source code in hyrrokkin/interfaces/topology_api.py
426 427 428 429 430 431 432 433 | |
get_schema()
Returns: an instance implementing the SchemaApi allowing the packahes, node types and link types in the schema to be examined
Source code in hyrrokkin/interfaces/topology_api.py
459 460 461 462 463 464 | |
import_from(from_path, include_data=True, ref=None)
abstractmethod
Merge the nodes and links topology from a YAML file or ZIP file into this topology. Node and link ids will be renamed to avoid clashes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
from_path
|
str
|
the path to a YAML or ZIP file describing the topology |
required |
include_data
|
bool
|
whether or not to include any data referenced in the YAML file |
True
|
ref
|
str | None
|
an optional reference that identifies this request |
None
|
Returns:
| Type | Description |
|---|---|
list[str]
|
a tuple containing the set of added node ids, the set of added link ids, and |
list[str]
|
a dictionary containing any node renamings performed to avoid id collisions with existing nodes |
Notes
configuration properties/data will not be loaded if this method is called after the topology is started topology metadata will not be loaded if topology metadata already exists
Source code in hyrrokkin/interfaces/topology_api.py
393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 | |
inject_input_value(node_id, input_port_name, value)
abstractmethod
Inject input values into a node in the topology, via an input port. The port must not be connected.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_id
|
str
|
the node id |
required |
input_port_name
|
str
|
the name of the node's input port |
required |
value
|
bytes | list[bytes]
|
the value to inject - encoded as bytes. For ports that accept multiple connections, a list of bytes may be provided. |
required |
Source code in hyrrokkin/interfaces/topology_api.py
282 283 284 285 286 287 288 289 290 291 | |
is_paused()
abstractmethod
Returns: True if the topology is paused
Source code in hyrrokkin/interfaces/topology_api.py
161 162 163 164 165 | |
is_started()
abstractmethod
Returns: True if the topology is executing
Source code in hyrrokkin/interfaces/topology_api.py
137 138 139 140 141 | |
load(from_file, include_data=True, ref=None)
abstractmethod
Merge the nodes and links topology from an opened ZIP file into this topology. Node and link ids will be renamed to avoid clashes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
from_file
|
BytesIO
|
a file opened in binary mode |
required |
include_data
|
bool
|
whether or not to include the data from the file |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
list[str]
|
a tuple containing the set of added node ids, the set of added link ids, and |
|
list[str]
|
a dictionary containing any node renamings performed to avoid id collisions with existing nodes |
|
ref |
dict[str, str]
|
an optional reference that identifies this request |
Notes
configuration properties/data will not be loaded if this method is called after the topology is started topology metadata will not be loaded if topology metadata already exists
Source code in hyrrokkin/interfaces/topology_api.py
354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 | |
open_session(session_id=None)
abstractmethod
Open a new interactive session
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_id
|
str | None
|
the identifier of the session or None to generate a new session identifier |
None
|
Returns:
| Type | Description |
|---|---|
str
|
the session identifier for the opened session |
Source code in hyrrokkin/interfaces/topology_api.py
296 297 298 299 300 301 302 303 304 305 306 | |
pause(ref=None)
abstractmethod
Pause execution of the topology. Until resume is called, no new nodes will start running.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ref
|
str | None
|
an optional reference that identifies this request |
None
|
Source code in hyrrokkin/interfaces/topology_api.py
143 144 145 146 147 148 149 150 | |
reload_node(node_id, properties, data, ref=None)
abstractmethod
Reload a node with new properties and data, triggering re-execution of the node and all downstream nodes if the topology execution has already started
Reloading creates a new instance of the node with the new properties and data
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_id
|
str
|
the id of the node to reload |
required |
properties
|
JsonType
|
the properties to reload |
required |
data
|
dict[str, bytes]
|
the data to reload |
required |
ref
|
str | None
|
an optional reference that identifies this request |
None
|
Source code in hyrrokkin/interfaces/topology_api.py
203 204 205 206 207 208 209 210 211 212 213 214 215 216 | |
remove_link(link_id, ref=None)
Remove a link from the topology
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
link_id
|
str
|
the link's unique identifier |
required |
ref
|
str | None
|
an optional reference that identifies this request |
None
|
Source code in hyrrokkin/interfaces/topology_api.py
108 109 110 111 112 113 114 115 116 | |
remove_node(node_id, ref=None)
abstractmethod
Remove a node from the topology
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_id
|
str
|
the node's unique identifier |
required |
ref
|
str | None
|
an optional reference that identifies this request |
None
|
Source code in hyrrokkin/interfaces/topology_api.py
77 78 79 80 81 82 83 84 85 | |
remove_output_listener(node_id, output_port_name)
abstractmethod
Remove a listener from a node/port
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_id
|
str
|
the node id |
required |
output_port_name
|
str
|
the name of the node's output port |
required |
Source code in hyrrokkin/interfaces/topology_api.py
272 273 274 275 276 277 278 279 280 | |
restart(ref=None)
abstractmethod
Restart execution of the topology
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ref
|
str | None
|
an optional reference that identifies this request |
None
|
Source code in hyrrokkin/interfaces/topology_api.py
167 168 169 170 171 172 173 174 175 176 | |
resume(ref=None)
abstractmethod
Resume execution of the topology
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ref
|
str | None
|
an optional reference that identifies this request |
None
|
Source code in hyrrokkin/interfaces/topology_api.py
152 153 154 155 156 157 158 159 | |
run()
abstractmethod
Run the topology until all nodes have completed or failed
Returns: a dictionary containing the error messages returned from any failed nodes
Source code in hyrrokkin/interfaces/topology_api.py
178 179 180 181 182 183 184 185 | |
run_task(task_name, input_port_values, output_ports, ref=None)
abstractmethod
Run a topology task
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task_name
|
str
|
a descriptive name of the task |
required |
input_port_values
|
dict[str, bytes | list[bytes]]
|
map from port identifier (node_id:input_port_name) to a binary-encoded input value or list of values |
required |
output_ports
|
list[str]
|
a list of port identifiers (node_id:output_port_name) specifying output ports to return values from |
required |
ref
|
str | None
|
an optional reference that identifies this request |
None
|
Returns:
| Type | Description |
|---|---|
tuple[dict[str, bytes], dict[str, str]]
|
return a tuple of (dict mapping from output port name to value, dict mapping from node id to error string) |
Source code in hyrrokkin/interfaces/topology_api.py
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 | |
save(to_file=None, include_data=True)
abstractmethod
save the topology to a zip file
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
to_file
|
BufferedWriter
|
a file opened in binary mode for writing |
None
|
include_data
|
bool
|
whether or not to include the data in the file |
True
|
Source code in hyrrokkin/interfaces/topology_api.py
374 375 376 377 378 379 380 381 382 | |
serialise()
abstractmethod
Serialise the topology structure to JSON
Returns: JSON-serialisable dictionary
Source code in hyrrokkin/interfaces/topology_api.py
384 385 386 387 388 389 390 391 | |
set_metadata(metadata, ref=None)
abstractmethod
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 |
ref
|
str | None
|
an optional reference that identifies this request |
None
|
Notes
the following keys will be understood by hyrrokkin based tools - version, description, authors
Source code in hyrrokkin/interfaces/topology_api.py
32 33 34 35 36 37 38 39 40 41 42 43 | |
start(ref=None)
abstractmethod
Start execution of the topology
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ref
|
str | None
|
an optional reference that identifies this request |
None
|
Source code in hyrrokkin/interfaces/topology_api.py
128 129 130 131 132 133 134 135 | |
update_node_metadata(node_id, metadata={}, ref=None)
abstractmethod
Update a node's metadata
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_id
|
str | None
|
the node's requested unique identifier or None |
required |
metadata
|
dict[str, JsonType]
|
a dictionary containing the new metadata |
{}
|
ref
|
str | None
|
an optional reference that identifies this request |
None
|
Source code in hyrrokkin/interfaces/topology_api.py
65 66 67 68 69 70 71 72 73 74 75 | |