Developer Reference
pfdl_scheduler
api
observer_api
This class contains classes to enable the Observer pattern.
The NotificationTye
class is an enum class which is used for setting the
type of the notification.
The abstract Observer
class represents the observers in the pattern and requires
an update
method which is called by a Subject
object. Here, the type of the notification
and the corresponding data is required.
The abstract Subject
class represents the subjects in the observer pattern.
It provides methods to attach or detach observers and to notify them.
NotificationType
Observer
Bases: ABC
The Observer interface declares the update method, used by subjects.
update(notification_type, data)
abstractmethod
Receive update from subject.
Source code in pfdl_scheduler/api/observer_api.py
36 37 38 39 |
|
Subject
Bases: ABC
The Subject interface declares a set of methods for managing subscribers.
attach(observer)
abstractmethod
Attach an observer to the subject.
Source code in pfdl_scheduler/api/observer_api.py
45 46 47 48 |
|
detach(observer)
abstractmethod
Detach an observer from the subject.
Source code in pfdl_scheduler/api/observer_api.py
50 51 52 53 |
|
notify(notification_type, data)
abstractmethod
Notify all observers about an event.
Source code in pfdl_scheduler/api/observer_api.py
55 56 57 58 |
|
service_api
Contains the ServiceAPI class.
ServiceAPI(service, task_context, uuid='', in_loop=False)
dataclass
Represents a called Service. Represents a Service or Service Call in the langauge which can be mapped to a real service that can be executed. Attributes: service: A description of the called Service. task_context: A TaskAPI representaiton of the Task from which the service was called. uuid: A UUID4 which is generated at object creation and is used in the scheduling. in_loop: A boolean indicating whether the Service was called within a loop.
Initialize the object. Args: service: A description of the called Service. task_context: A TaskAPI representaiton of the Task from which the service was called. uuid: A UUID4 which is generated at object creation and is used in the scheduling. in_loop: A boolean indicating whether the Service was called within a loop.
Source code in pfdl_scheduler/api/service_api.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
|
task_api
Contains the TaskAPI class.
TaskAPI(task, task_context, uuid='', task_call=None, in_loop=False)
dataclass
Represents a called Task.
Represents a specific entity of a called Task. It combines the information of the Task itself and the parameters of the call. A TaskAPI object is used in the task started and finished callback which are called by the scheduler.
Attributes:
Name | Type | Description |
---|---|---|
task |
Task
|
A description of the called Task. |
task_context |
TaskAPI
|
A TaskAPI representaiton of the Task from which the called task was invoked. |
uuid |
str
|
A UUID4 which is generated at object creation and is used in the scheduling. |
task_call |
TaskCall
|
Information about the input and output parameters of the called Task. |
in_loop |
bool
|
A boolean indicating whether the Task was called within a loop. |
Initialize the object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
task |
Task
|
A description of the called Task. |
required |
task_context |
TaskAPI
|
A TaskAPI representaiton of the Task from which the called task was invoked. |
required |
uuid |
str
|
A UUID4 which is generated at object creation and is used in the scheduling. |
''
|
task_call |
TaskCall
|
Information about the input and output parameters of the called Task. |
None
|
in_loop |
bool
|
A boolean indicating whether the Task was called within a loop. |
False
|
Source code in pfdl_scheduler/api/task_api.py
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 |
|
extension
Contains the start up script used in the VSCode extension.
A program that shall be executed in the VS Code extension which has a string containing a PFDL program as input as well as the name of the corresponding file.
model
array
Contains the Array class.
Array(type_of_elements='', values=None, context=None)
Represents an Array in the PFDL.
Used as as an array definition or a returned array with elements in it.
Attributes:
Name | Type | Description |
---|---|---|
type_of_elements |
str
|
A string representing the type of the elements inside the array. |
values |
List[Any]
|
A list of elements of the Array (empty if it is a array definition). |
length |
int
|
An integer for the length of the Array. If it is not defined it gets the value -1. |
context |
ParserRuleContext
|
ANTLR context object of this class. |
Initialize the object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
type_of_elements |
str
|
A string representing the type of the elements inside the array. |
''
|
values |
List[Any]
|
A list of elements of the Array (empty if it is a array definition). |
None
|
context |
ParserRuleContext
|
ANTLR context object of this class. |
None
|
Source code in pfdl_scheduler/model/array.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
|
append_value(value)
Adds an element to the array and increase the length.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value |
Any
|
The value that should be added to the array. |
required |
Source code in pfdl_scheduler/model/array.py
86 87 88 89 90 91 92 93 94 95 |
|
length_defined()
Returns whether the lenght of the array is defined.
Returns:
Type | Description |
---|---|
bool
|
True if the length of the array is defined. |
Source code in pfdl_scheduler/model/array.py
97 98 99 100 101 102 103 |
|
condition
Contains the Condition class.
Condition(expression=None, passed_stmts=None, failed_stmts=None, context=None)
dataclass
Represents a conditional statement in the PFDL.
A Condition consists of a boolean expression which has to be satisfied in order to execute the statements in the Passed block. Otherwise the statements in the Failed block will be executed.
Attributes:
Name | Type | Description |
---|---|---|
expression |
Dict
|
Boolean expression in form of a dict (see Visitor for the dict structure). |
passed_stmts |
List[Union[Service, TaskCall, Loop, Condition]]
|
List of statements which are executed when the expression is satisfied. |
failed_stmts |
List[Union[Service, TaskCall, Loop, Condition]]
|
List of statements which are executed when the expression is not satisfied. |
context |
ParserRuleContext
|
ANTLR context object of this class. |
context_dict |
Dict
|
Maps other attributes with ANTLR context objects. |
Initialize the object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
expression |
Dict
|
Boolean expression in form of a dict (see Visitor for the dict structure). |
None
|
passed_stmts |
List[Union[Service, TaskCall, Loop, Condition]]
|
List of statements which are executed when the expression is satisfied. |
None
|
failed_stmts |
List[Union[Service, TaskCall, Loop, Condition]]
|
List of statements which are executed when the expression is not satisfied. |
None
|
context |
ParserRuleContext
|
ANTLR context object of this class. |
None
|
Source code in pfdl_scheduler/model/condition.py
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 |
|
counting_loop
Contains the CountingLoop class.
CountingLoop(statements=None, counting_variable='', limit='', parallel=False, context=None)
dataclass
Bases: Loop
Represents a Counting Loop in the PFDL.
Counting loops count a variable from an initial value to a given upper limit. If the parallel keyword was used, this loop executes the statements in the loop body in parallel as many times as the loop would iterate.
Attributes:
Name | Type | Description |
---|---|---|
statements |
List of statements inside the loop body. |
|
context |
ANTLR context object of this class. |
|
context_dict |
Maps other attributes with ANTLR context objects. |
|
counting_variable |
str
|
Name of the variable which is counted in the loop. |
limit |
str
|
Integer for the upper limit. |
parallel |
bool
|
A boolean indicating if the loop is a parallel loop or not. |
Initialize the object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
statements |
List[Union[Service, TaskCall, Loop, Condition]]
|
List of statements inside the loop body. |
None
|
counting_variable |
str
|
Name of the variable which is counted in the loop. |
''
|
limit |
str
|
Integer for the upper limit. |
''
|
parallel |
bool
|
A boolean indicating if the loop is a parallel loop or not. |
False
|
context |
ParserRuleContext
|
ANTLR context object of this class. |
None
|
Source code in pfdl_scheduler/model/counting_loop.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
|
loop
Contains the Loop class.
Loop(statements=None, context=None)
dataclass
The base class for the PFDL loops.
Attributes:
Name | Type | Description |
---|---|---|
statements |
List[Union[Service, TaskCall, Loop, Condition]]
|
List of statements inside the loop body. |
context |
ParserRuleContext
|
ANTLR context object of this class. |
context_dict |
Dict
|
Maps other attributes with ANTLR context objects. |
Initialize the object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
statements |
List[Union[Service, TaskCall, Loop, Condition]]
|
List of statements inside the loop body. |
None
|
context |
ParserRuleContext
|
ANTLR context object of this class. |
None
|
Source code in pfdl_scheduler/model/loop.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
|
parallel
Contains the Parallel class.
Parallel(task_calls=None, context=None)
dataclass
Represents a Parallel statement in the PFDL.
Each task within this instruction is executed in parallel with the calling task. When all parallel tasks are finished, the calling task continues its execution.
Attributes:
Name | Type | Description |
---|---|---|
task_calls |
List[TaskCall]
|
List of Task Calls in the Parallel statement. |
context |
ParserRuleContext
|
ANTLR context object of this class. |
context_dict |
Dict
|
Maps other attributes with ANTLR context objects. |
Initialize the object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
task_calls |
List[TaskCall]
|
List of Task Calls in the Parallel statement. |
None
|
context |
ParserRuleContext
|
ANTLR context object of this class. |
None
|
Source code in pfdl_scheduler/model/parallel.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
|
process
Contains the Process class.
Process(structs=None, tasks=None)
dataclass
Represents a production process described in a PFDL file.
A Process consists of multiple Structs and Tasks. A Process object gets created after the visitor traverses the syntax tree.
Attributes:
Name | Type | Description |
---|---|---|
structs |
Dict[str, Struct]
|
A dict for mapping the Struct names to the Struct objects. |
task |
Dict[str, Struct]
|
A dict for mapping the Task names to the Task objects. |
Initialize the object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
structs |
Dict[str, Struct]
|
A dict for mapping the Struct names to the Struct objects. |
None
|
tasks |
Dict[str, Task]
|
A dict for mapping the Task names to the Task objects. |
None
|
Source code in pfdl_scheduler/model/process.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
|
service
Contains the Service class.
Service(name='', input_parameters=None, output_parameters=None, context=None)
dataclass
Represents a Service or Service Call in the PFDL.
Represents a Service or Service Call in the langauge which can be mapped to a real service that can be executed.
Attributes:
Name | Type | Description |
---|---|---|
name |
str
|
A string representing the name of the Service. |
input_parameters |
List[Union[str, List[str], Struct]]
|
List of input parameters of the Service. |
output_parameters |
OrderedDict[str, Union[str, Array]]
|
List of output parameters of the Service. |
context |
ParserRuleContext
|
ANTLR context object of this class. |
context_dict |
Dict
|
Maps other attributes with ANTLR context objects. |
Initialize the object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
A string representing the name of the Service. |
''
|
input_parameters |
List[Union[str, List[str], Struct]]
|
List of input parameters of the Service. |
None
|
output_parameters |
Dict[str, Union[str, Array]]
|
List of output parameters of the Service. |
None
|
context |
ParserRuleContext
|
ANTLR context object of this class. |
None
|
Source code in pfdl_scheduler/model/service.py
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 |
|
struct
Contains the Struct class.
Struct(name='', attributes=None, context=None)
dataclass
Represents a Struct in the PFDL.
Data container for Services and Taskcalls. Used both for Struct definitons and instantiated Structs.
Attributes:
Name | Type | Description |
---|---|---|
name |
str
|
A string representing the name of the Struct. |
attributes |
Dict[str, Union[str, Array, Struct]]
|
A dict which maps the attribute names to the defined type or a value (if its a instantiated struct). |
context |
ParserRuleContext
|
ANTLR context object of this class. |
context_dict |
Dict
|
Maps other attributes with ANTLR context objects. |
Initialize the object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
A string representing the name of the Struct. |
''
|
attributes |
Dict[str, Union[str, Array, Struct]]
|
A dict which maps the attribute names to the defined type or a value (if its a instantiated struct). |
None
|
context |
ParserRuleContext
|
ANTLR context object of this class. |
None
|
Source code in pfdl_scheduler/model/struct.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
|
from_json(json_string, error_handler, struct_context)
classmethod
Creates a Struct instance out of the given JSON string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
json_string |
str
|
A JSON string desribing the Struct. |
required |
error_handler |
ErrorHandler
|
An ErrorHandler instance used for printing errors. |
required |
Returns:
Type | Description |
---|---|
Struct
|
The Struct which was created from the JSON string. |
Source code in pfdl_scheduler/model/struct.py
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
|
parse_json(json_object, error_handler, struct_context)
Parses the JSON Struct initialization.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
json_object |
Dict
|
A JSON object describing the Struct. |
required |
error_handler |
ErrorHandler
|
An ErrorHandler instance used for printing errors. |
required |
struct_context |
ParserRuleContext
|
The ANTLR struct context the struct corresponds to. |
required |
Returns:
Type | Description |
---|---|
Struct
|
A Struct object representing the initialized Struct. |
Source code in pfdl_scheduler/model/struct.py
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 |
|
task
Contains the Task class.
Task(name='', statements=None, variables=None, input_parameters=None, output_parameters=None, context=None)
dataclass
Represents a Task in the PFDL.
A Task contains statements which are executed sequentially. It is possible to define input and output parameters of a Task.
Attributes:
Name | Type | Description |
---|---|---|
name |
str
|
A string representing the name of the Task. |
statements |
List[Union[Service, TaskCall, Loop, Condition]]
|
List of statements which are executed sequentially. |
variables |
Dict[str, Union[str, Array]]
|
Dict for mapping variable names with their values. |
input_parameters |
OrderedDict[str, Union[str, Array]]
|
OrderedDict for mapping input parameter names with their values. |
output_parameters |
List[str]
|
List of variable names as output parameters. |
context |
ParserRuleContext
|
ANTLR context object of this class. |
context_dict |
Dict
|
Maps other attributes with ANTLR context objects. |
Initialize the object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
A string representing the name of the Task. |
''
|
statements |
List[Union[Service, TaskCall, Loop, Condition]]
|
List of statements which are executed sequentially. |
None
|
variables |
Dict[str, Union[str, Array]]
|
Dict for mapping variable names with their values. |
None
|
input_parameters |
OrderedDict[str, Union[str, Array]]
|
OrderedDict for mapping input parameter names with their values. |
None
|
output_parameters |
List[str]
|
List of variable names as output parameters. |
None
|
context |
ParserRuleContext
|
ANTLR context object of this class. |
None
|
Source code in pfdl_scheduler/model/task.py
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 |
|
task_call
Contains the TaskCall class.
TaskCall(name='', input_parameters=None, output_parameters=None, context=None)
dataclass
Represents a TaskCall in the PFDL.
Provides information about the name and call parameters of a Task which is called within another Task.
Attributes:
Name | Type | Description |
---|---|---|
name |
str
|
A string representing the name of the TaskCall. |
input_parameters |
List[Union[str, List[str], Struct]]
|
List of input parameters of the TaskCall. |
output_parameters |
Dict[str, Union[str, Array]]
|
List of output parameters of the TaskCall. |
context |
ParserRuleContext
|
ANTLR context object of this class. |
context_dict |
Dict
|
Maps other attributes with ANTLR context objects. |
Initialize the object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
A string representing the name of the TaskCall. |
''
|
input_parameters |
List[Union[str, List[str], Struct]]
|
List of input parameters of the TaskCall. |
None
|
output_parameters |
Dict[str, Union[str, Array]]
|
List of output parameters of the TaskCall. |
None
|
context |
ParserRuleContext
|
ANTLR context object of this class. |
None
|
Source code in pfdl_scheduler/model/task_call.py
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 |
|
while_loop
Contains the WhileLoop class.
WhileLoop(statements=None, expression=None, context=None)
dataclass
Bases: Loop
Represents a While Loop in the PFDL.
Loops until conditional statement (expression) is satisfied.
Attributes:
Name | Type | Description |
---|---|---|
statements |
List of statements inside the loop body. |
|
expression |
Dict
|
Boolean expression in form of a dict. |
context |
Dict
|
ANTLR context object of this class. |
context_dict |
Dict
|
Maps other attributes with ANTLR context objects. |
Initialize the object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
statements |
List[Union[Service, TaskCall, Loop, Condition]]
|
List of statements inside the loop body. |
None
|
expression |
Dict
|
Boolean expression in form of a dict. |
None
|
context |
ParserRuleContext
|
ANTLR context object of this class. |
None
|
Source code in pfdl_scheduler/model/while_loop.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
|
parser
pfdl_tree_visitor
Contains PFDLTreeVisitor class.
PFDLTreeVisitor(error_handler)
Bases: PFDLParserVisitor
Traverses the given parse tree and store program information in a Process object.
This class overrides the generated visitor methods from the ANTLR generated PFDLParserVisitor. A Process object is created and gets filled while traversing the syntax tree.
Attributes:
Name | Type | Description |
---|---|---|
error_handler |
ErrorHandler
|
ErrorHandler instance for printing errors while visiting. |
current_task |
Task
|
Reference to the currently visited Task. Every visitor method can access it. |
Initialize the object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
error_handler |
ErrorHandler
|
ErrorHandler instance for printing errors while visiting. |
required |
Source code in pfdl_scheduler/parser/pfdl_tree_visitor.py
49 50 51 52 53 54 55 56 |
|
visitProgram(ctx)
Starts the visiting of the syntax tree of the given PFDL program.
Source code in pfdl_scheduler/parser/pfdl_tree_visitor.py
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 |
|
petri_net
callbacks
Contains the PetriNetCallbacks class.
PetriNetCallbacks(task_started=None, service_started=None, service_finished=None, condition_started=None, while_loop_started=None, counting_loop_started=None, parallel_loop_started=None, task_finished=None)
dataclass
Internal callback functions that can be registered in the petri net.
Attributes:
Name | Type | Description |
---|---|---|
task_started |
Callable[[TaskAPI], Any]
|
Callback function which gets called when a task is started. |
service_started |
Callable[[ServiceAPI], Any]
|
Callback function which gets called when a service is started. |
service_finished |
Callable[[ServiceAPI], Any]
|
Callback function which gets called when a task is started. |
condition_started |
Callable[[Condition, str, str, TaskAPI], Any]
|
Callback function which gets called when a task is started. |
while_loop_started |
Callable[[WhileLoop, str, str, TaskAPI], Any]
|
Callback function which gets called when a while loop is started. |
counting_loop_started |
Callable[[CountingLoop, str, str, TaskAPI], Any]
|
Callback function which gets called when a counting loop is started. |
parallel_loop_started |
Callable[[CountingLoop, TaskAPI, List, str, str], Any]
|
Callback function which gets called when a parallel loop is started. |
task_finished |
Callable[[TaskAPI], Any]
|
Callback function which gets called when a task is finished. |
drawer
Functions defined here set attributes for drawing the petri net.
draw_arcs(arc, attr)
Set attributes for drawing arcs.
Source code in pfdl_scheduler/petri_net/drawer.py
81 82 83 84 85 |
|
draw_graph(graph, attr)
Set attributes for drawing the net.
Source code in pfdl_scheduler/petri_net/drawer.py
48 49 50 51 |
|
draw_petri_net(net, file_path, file_ending='.png')
Calls the draw method form the Snakes module on the given PetriNet.
Source code in pfdl_scheduler/petri_net/drawer.py
92 93 94 95 96 97 98 99 100 101 102 103 |
|
draw_place(place, attr)
Set attributes for drawing places.
Source code in pfdl_scheduler/petri_net/drawer.py
54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
|
draw_transition(trans, attr)
Set attributes for drawing transitions.
Source code in pfdl_scheduler/petri_net/drawer.py
70 71 72 73 74 75 76 77 78 |
|
generator
Contains the PetriNetGenerator class.
PetriNetGenerator(path_for_image='', used_in_extension=False, generate_test_ids=False, draw_net=True, file_name='petri_net')
Generates a Petri Net from a given Process object which corresponds to a PFDL file.
Attributes:
Name | Type | Description |
---|---|---|
path_for_image |
str
|
The path where the image of the generated Petri Net is saved. |
net |
PetriNet
|
The snakes Petri Net instance. |
tasks |
Dict[str, Task]
|
A dict representing the Tasks of the given Process object. |
transition_dict |
OrderedDict
|
A dict for mapping the UUIDs of the Transitions to their behavior. |
place_dict |
Dict
|
A dict for mapping the service id to the place name. |
task_started_id |
str
|
The id of the 'Task started' place. |
callbacks |
PetriNetCallbacks
|
A PetriNetCallbacks instance representing functions called while execution. |
generate_test_ids |
bool
|
A boolean indicating if test ids (counting from 0) should be generated. |
used_in_extension |
bool
|
A boolean indicating if the Generator is used within the extension. |
Initialize the object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path_for_image |
str
|
The path where the image of the generated Petri Net is saved. |
''
|
used_in_extension |
bool
|
A boolean indicating if the Generator is used within the extension. |
False
|
generate_test_ids |
bool
|
A boolean indicating if test ids (counting from 0) should be generated. |
False
|
draw_net |
bool
|
A boolean indicating if the petri net should be drawn. |
True
|
Source code in pfdl_scheduler/petri_net/generator.py
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 |
|
add_callback(transition_id, callback_function, *args)
Registers the given callback function in the transition_dict.
If the transition the transition_id refers to is fired, the callback function will be called with the given arguments inside the PetriNetLogic class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
transition_id |
str
|
The UUID of the transition where the callback is called if fired. |
required |
callback_function |
Callable
|
The callback function which should be called. |
required |
*args |
Any
|
Arguments with which the callback function is called. |
()
|
Source code in pfdl_scheduler/petri_net/generator.py
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
|
generate_condition(condition, task_context, first_transition_id, second_transition_id, node, in_loop=False)
Generate Petri Net components for the Condition statement.
Returns:
Type | Description |
---|---|
List[str]
|
The ids of the last transitions of the Condition petri net component. |
Source code in pfdl_scheduler/petri_net/generator.py
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 |
|
generate_counting_loop(loop, task_context, first_transition_id, second_transition_id, node, in_loop=False)
Generates the Petri Net components for a Couting Loop.
Returns:
Type | Description |
---|---|
str
|
The id of the last transition of the CountingLoop petri net component. |
Source code in pfdl_scheduler/petri_net/generator.py
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 |
|
generate_parallel(parallel, task_context, first_transition_id, second_transition_id, node, in_loop=False)
Generate the Petri Net components for a Parallel statement.
Returns:
Type | Description |
---|---|
str
|
The id of the last transition of the Parallel petri net component. |
Source code in pfdl_scheduler/petri_net/generator.py
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 |
|
generate_parallel_loop(loop, task_context, first_transition_id, second_transition_id, node)
Generates the static petri net components for a ParallelLoop.
This method will generate a placeholder for the ParallelLoop. The real amount of parallel startet Tasks is only known at runtime.
Returns:
Type | Description |
---|---|
str
|
The id of the last transition of the ParallelLoop petri net component. |
Source code in pfdl_scheduler/petri_net/generator.py
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 |
|
generate_petri_net(process)
Generates a Petri Net from the given Process object.
Starts from the 'productionTask' and iterates over his statements. For each statement type like Condition or TaskCall a Petri Net component is generated. All components get connected at the end.
Returns:
Type | Description |
---|---|
PetriNet
|
A PetriNet instance representing the generated net. |
Source code in pfdl_scheduler/petri_net/generator.py
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 |
|
generate_service(service, task_context, first_transition_id, second_transition_id, node, in_loop=False)
Generate the Petri Net components for a Service Call.
Returns:
Type | Description |
---|---|
str
|
The id of the last transition of the Service petri net component. |
Source code in pfdl_scheduler/petri_net/generator.py
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 |
|
generate_statements(task_context, statements, first_connection_id, last_connection_id, node, in_loop=False)
Generate Petri Net components for each statement in the given Task
Iterate over the statements of the given Tasks and generate the corresponding Petri Net components. Connect the individual components with each other via a transition.
Returns:
Type | Description |
---|---|
List[str]
|
The ids of the last connections (transitions). |
Source code in pfdl_scheduler/petri_net/generator.py
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 |
|
generate_task_call(task_call, task_context, first_transition_id, second_transition_id, node, in_loop=False)
Generate the Petri Net components for a Task Call.
Returns:
Type | Description |
---|---|
List[str]
|
The ids of the last transitions of the TaskCall petri net component. |
Source code in pfdl_scheduler/petri_net/generator.py
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 |
|
generate_while_loop(loop, task_context, first_transition_id, second_transition_id, node, in_loop=False)
Generate the Petri Net components for a While Loop.
Returns:
Type | Description |
---|---|
str
|
The id of the last transition of the WhileLoop petri net component. |
Source code in pfdl_scheduler/petri_net/generator.py
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 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 |
|
parse_expression(expression)
Parses the given expression to a printable format.
Returns:
Type | Description |
---|---|
str
|
The content of the expression as a formatted string. |
Source code in pfdl_scheduler/petri_net/generator.py
681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 |
|
remove_place_on_runtime(place_id)
Removes a place from the petri net at runtime.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
place_id |
str
|
The id as string of the task which should be removed from the net. |
required |
Source code in pfdl_scheduler/petri_net/generator.py
588 589 590 591 592 593 594 595 596 597 598 599 600 |
|
create_place(name, net, group_id, cluster=[])
Utility function for creating a place with the snakes module.
This function is used to add a place with the given name and to add labels for scheduling (for example if the place represents an event or if its initialized).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
A string representing the displayed name of the place. |
required |
net |
PetriNet
|
The petri net instance this place should be added to. |
required |
group_id |
str
|
|
required |
Returns:
Type | Description |
---|---|
str
|
A UUID as string for the added place. |
Source code in pfdl_scheduler/petri_net/generator.py
709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 |
|
create_transition(transition_name, transition_type, net, group_id)
Utility function for creating a transition with the snakes module.
This function is used to add a transition with the given name and to add labels for scheduling (currently only the type of the transition).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
transition_name |
str
|
A string representing the displayed name of the transition. |
required |
net |
PetriNet
|
The petri net instance this transition should be added to. |
required |
group_id |
str
|
|
required |
Returns:
Type | Description |
---|---|
str
|
A UUID as string for the added transition. |
Source code in pfdl_scheduler/petri_net/generator.py
729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 |
|
logic
Contains the PetriNetLogic class.
PetriNetLogic(petri_net_generator, draw_net=True, file_name='')
Provides methods for interacting with the generated petri nets for scheduling.
Scheduling of the production process with the help of the generated petri nets is done in this class.
Attributes:
Name | Type | Description |
---|---|---|
petri_net_generator |
PetriNetGenerator
|
A reference to the PetriNetGenerator. |
petri_net |
PetriNet
|
A reference to the generated petri net. |
draw_net |
bool
|
Indiciating whether the net should be drawn. |
transition_dict |
Dict
|
A reference to the dict in the generator which maps the ids to callbacks. |
Initialize the object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
petri_net_generator |
PetriNetGenerator
|
A reference to the PetriNetGenerator. |
required |
draw_net |
bool
|
Indiciating whether the net should be drawn. |
True
|
Source code in pfdl_scheduler/petri_net/logic.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
|
draw_petri_net()
Saves the given petri net as an image in the current working directory.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
The name of the image. |
required | |
petri_net |
The petri net instance that should be drawn. |
required |
Source code in pfdl_scheduler/petri_net/logic.py
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
|
evaluate_petri_net()
Tries to fire every transition as long as all transitions were tried and nothing can be done anymore.
Source code in pfdl_scheduler/petri_net/logic.py
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 |
|
fire_event(event)
Adds a token to the corresponding place of the event in the petri net.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
event |
Event
|
The Event object that is fired. |
required |
Source code in pfdl_scheduler/petri_net/logic.py
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
|
scheduler
Contains the Scheduler class.
ParallelLoopCounter()
Represents an intermediate object which indicates that the counter is from a parallel loop.
Source code in pfdl_scheduler/scheduler.py
44 45 |
|
Scheduler(pfdl_file_path, generate_test_ids=False, draw_petri_net=True, scheduler_id='', dashboard_host_address='')
Bases: Subject
Schedules Tasks of a given PFDL file.
The scheduler comprises almost the complete execution of a production order including the parsing of the PFDL description, model creation and validation and execution of the petri net. It interacts with the execution engines and informs them about services or tasks which started or finished.
This class implements the Observer pattern and serves as subject. Observers can be registered in the scheduler and receive updates (e.g. log entries, info about a new petri net img,..)
Attributes:
Name | Type | Description |
---|---|---|
running |
bool
|
A boolean that indicates whether the scheduler is running. |
pfdl_file_valid |
bool
|
A boolean indicating whether the given PFDL file was valid. |
process |
Process
|
The corresponding Process instance from the PFDL file. |
petri_net_generator |
PetriNetGenerator
|
A PetriNetGenerator instance for generating the petri net. |
petri_net_logic |
PetriNetLogic
|
A PetriNetLogic instance for execution of the petri net. |
task_callbacks |
TaskCallbacks
|
TaskCallbacks instance which holds the registered callbacks. |
variable_access_function |
Callable[[str], str]
|
The function which will be called when the scheduler needs a variable. |
loop_counters |
Dict[str, Dict[str, int]]
|
A dict for mapping task ids to the current loop counter (counting loops). |
awaited_events |
List[Event]
|
A list of awaited |
generate_test_ids |
bool
|
Indicates whether test ids should be generated. |
test_id_counters |
List[int]
|
A List consisting of counters for the test ids of tasks and services. |
observers |
List[Observer]
|
List of |
Initialize the object.
If the given path leads to a valid PFDL file the parsing will be started. If no errors
occur the model of the PFDL File will be transformed into a petri net and be drawn if
the draw_petri_net
flag is set. If generate_test_ids
is set the ids of the called
tasks and services will be an enumeration starting at 0.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pfdl_file_path |
str
|
The path to the PFDL file. |
required |
generate_test_ids |
bool
|
A boolean indicating whether test ids should be generated. |
False
|
draw_petri_net |
bool
|
A boolean indicating whether the petri net should be drawn. |
True
|
scheduler_id |
str
|
A unique ID to identify the Scheduer / Production Order |
''
|
dashboard_host_address |
str
|
The address of the Dashboard (if existing) |
''
|
Source code in pfdl_scheduler/scheduler.py
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 |
|
attach(observer)
Attach (add) an observer object to the observers list.
Source code in pfdl_scheduler/scheduler.py
136 137 138 |
|
check_expression(expression, task_context)
Check the boolean value of the given PFDL expression as a Python expression.
This method only gets executed if the semantic error check is passed. This means that no additional semantic checks has to be performed.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
expression |
Dict
|
A dict representing the expression. |
required |
task_context |
TaskAPI
|
The context in which the expression should be evaluated. |
required |
Returns:
Type | Description |
---|---|
bool
|
The value of the successfully executed expression in Python as a bool. |
Source code in pfdl_scheduler/scheduler.py
472 473 474 475 476 477 478 479 480 481 482 483 484 485 |
|
detach(observer)
Detach (remove) an observer object from the observers list.
Source code in pfdl_scheduler/scheduler.py
140 141 142 |
|
execute_expression(expression, task_context)
Executes the given PFDL expression as a Python expression.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
expression |
Dict
|
A dict representing the expression. |
required |
task_context |
TaskAPI
|
The context in which the expression should be evaluated. |
required |
Returns:
Type | Description |
---|---|
Any
|
The value of the expression executed in Python (type depends on specific expression). |
Source code in pfdl_scheduler/scheduler.py
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 |
|
fire_event(event)
Forwards the given Event to the PetriNetLogic instance.
The given Event
object will be passed to the petri net if it is an awaited
event.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
event |
Event
|
An |
required |
Returns:
Type | Description |
---|---|
bool
|
True if the event could be fired to the petri net (is an awaited event). |
Source code in pfdl_scheduler/scheduler.py
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
|
notify(notification_type, data)
Trigger an update in each subscriber.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
notification_type |
NotificationType
|
A |
required |
data |
Any
|
The data which the observers will receive. |
required |
Source code in pfdl_scheduler/scheduler.py
144 145 146 147 148 149 150 151 152 153 |
|
on_condition_started(condition, then_uuid, else_uuid, task_context)
Executes Scheduling logic when a Condition statement is started.
Source code in pfdl_scheduler/scheduler.py
340 341 342 343 344 345 346 347 348 349 350 351 |
|
on_counting_loop_started(loop, then_uuid, else_uuid, task_context)
Executes Scheduling logic when a Counting Loop is started.
Source code in pfdl_scheduler/scheduler.py
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 |
|
on_parallel_loop_started(loop, task_context, parallelTask, parallel_loop_started, first_transition_id, second_transition_id, node)
Executes Scheduling logic when a Parallel Loop is started.
Source code in pfdl_scheduler/scheduler.py
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 |
|
on_service_finished(service_api)
Executes Scheduling logic when a Service is finished.
Source code in pfdl_scheduler/scheduler.py
326 327 328 329 330 331 332 333 334 335 336 337 338 |
|
on_service_started(service_api)
Executes Scheduling logic when a Service is started.
Source code in pfdl_scheduler/scheduler.py
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 |
|
on_task_finished(task_api)
Executes Scheduling logic when a Task is finished.
Source code in pfdl_scheduler/scheduler.py
445 446 447 448 449 450 451 452 453 454 455 456 457 458 |
|
on_task_started(task_api)
Executes Scheduling logic when a Task is started.
Source code in pfdl_scheduler/scheduler.py
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 |
|
on_while_loop_started(loop, then_uuid, else_uuid, task_context)
Executes Scheduling logic when a While Loop is started.
Source code in pfdl_scheduler/scheduler.py
353 354 355 356 357 358 359 360 361 362 363 364 |
|
register_callback_service_finished(callback)
Registers the given callback in the service_finished list.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
callback |
Callable[[ServiceAPI], Any]
|
Function which will be invoked when a Service is finished. |
required |
Returns:
Type | Description |
---|---|
bool
|
True if the callback was successfully registered. |
Source code in pfdl_scheduler/scheduler.py
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 |
|
register_callback_service_started(callback)
Registers the given callback in the service_started list.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
callback |
Callable[[ServiceAPI], Any]
|
Function which will be invoked when a Service is started. |
required |
Returns:
Type | Description |
---|---|
bool
|
True if the callback was successfully registered. |
Source code in pfdl_scheduler/scheduler.py
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 |
|
register_callback_task_finished(callback)
Registers the given callback in the task_finished list.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
callback |
Callable[[TaskAPI], Any]
|
Function which will be invoked when a Task is finished. |
required |
Returns:
Type | Description |
---|---|
bool
|
True if the callback was successfully registered. |
Source code in pfdl_scheduler/scheduler.py
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 |
|
register_callback_task_started(callback)
Registers the given callback in the task_started list.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
callback |
Callable[[TaskAPI], Any]
|
Function which will be invoked when a Task is started. |
required |
Returns:
Type | Description |
---|---|
bool
|
True if the callback was successfully registered. |
Source code in pfdl_scheduler/scheduler.py
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
|
register_for_petrinet_callbacks()
Register scheduler callback functions in the petri net.
Source code in pfdl_scheduler/scheduler.py
460 461 462 463 464 465 466 467 468 469 470 |
|
register_variable_access_function(var_access_func)
Registers the given callback as the variable acces function of the Scheduler.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
var_access_func |
Callable[[str], str]
|
The function which will be called when the scheduler needs a variable. |
required |
Source code in pfdl_scheduler/scheduler.py
251 252 253 254 255 256 257 |
|
start()
Starts the scheduling process for the given PFDL file from the path.
Returns:
Type | Description |
---|---|
bool
|
True if the corresponding PFDL file was valid and the Scheduler could be started. |
Source code in pfdl_scheduler/scheduler.py
155 156 157 158 159 160 161 162 163 164 165 |
|
substitute_loop_indexes(call_api)
Substitutes loop indexes in service or task call input parameters if present.
Source code in pfdl_scheduler/scheduler.py
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 |
|
scheduling
event
Contains the Event class.
Event(event_type='', data=None)
Data class for controlling the PetriNet instance.
Currently avaiable Events
- Event(event_type="service_finished", data={"service_id":
})
Attributes:
Name | Type | Description |
---|---|---|
event_type |
str
|
A string representing the type of the event. |
data |
Dict
|
A dict containing the corresponding data of the event type. |
Source code in pfdl_scheduler/scheduling/event.py
32 33 34 |
|
from_json(json_string)
classmethod
Creates an Event instance out of the given JSON string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
json_string |
str
|
A JSON string desribing the Event. |
required |
Returns:
Type | Description |
---|---|
Union[None, Event]
|
The Event which was created from the JSON string. None if the conversion failed. |
Source code in pfdl_scheduler/scheduling/event.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
|
task_callbacks
Contains the TaskCallbacks class.
TaskCallbacks()
dataclass
Contains lists of callback functions that where registered in the scheduler.
Attributes:
Name | Type | Description |
---|---|---|
task_started |
List[Callable[[TaskAPI], Any]]
|
A list of callback functions which get called when a task is started. |
service_started |
List[Callable[[ServiceAPI], Any]]
|
A list of callback functions which get called when a service is started. |
service_finished |
List[Callable[[ServiceAPI], Any]]
|
A list of callback functions which get called when a service is finished. |
task_finished |
List[Callable[[TaskAPI], Any]]
|
A list of callback functions which get called when a task is finished. |
Initialize the object.
Source code in pfdl_scheduler/scheduling/task_callbacks.py
29 30 31 32 33 34 |
|
utils
dashboard_observer
Contains the start up script for the dashboard.
A program executed in the VS Code extension which has a string containing a PFDL program as input.
DashboardObserver(host, scheduler_id, pfdl_string)
Bases: Observer
DashboardObserver for receiving infos about changes of the PetriNet or Scheduling.
The Observer will send a post request to the dashboard with the data.
Source code in pfdl_scheduler/utils/dashboard_observer.py
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
|
helpers
Helper functions used in the project (especially in the SemanticErrorChecker).
check_type_of_value(value, value_type)
Checks if the given value is the given type in the DSL.
Returns:
Type | Description |
---|---|
bool
|
True if the value is from the given value type. |
Source code in pfdl_scheduler/utils/helpers.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
|
get_type_of_variable_list(var_list, task, struct_definitions)
Iterates over the given variable list and gets the type of the last element.
Returns:
Type | Description |
---|---|
str
|
Type of the last element in the variable list as string. |
Source code in pfdl_scheduler/utils/helpers.py
39 40 41 42 43 44 45 46 47 48 49 50 51 |
|
is_boolean(string)
Checks if the given string can be casted to a boolean.
Returns:
Type | Description |
---|---|
bool
|
True if the given string can be casted to a boolean. |
Source code in pfdl_scheduler/utils/helpers.py
76 77 78 79 80 81 82 83 84 |
|
is_con(string)
Checks if the given string is a condition element in the PFDL.
A condition element can be a PFDL string, boolean or number
Returns:
Type | Description |
---|---|
bool
|
True if the given string is a condition element in the PFDL. |
Source code in pfdl_scheduler/utils/helpers.py
54 55 56 57 58 59 60 61 62 |
|
is_float(string)
Checks if the given string can be casted to a float.
Returns:
Type | Description |
---|---|
bool
|
True if the given string can be casted to a float. |
Source code in pfdl_scheduler/utils/helpers.py
98 99 100 101 102 103 104 105 106 107 108 109 |
|
is_int(string)
Checks if the given string can be casted to an integer.
Returns:
Type | Description |
---|---|
bool
|
True if the given string can be casted to an integer. |
Source code in pfdl_scheduler/utils/helpers.py
112 113 114 115 116 117 118 119 120 121 122 123 |
|
is_number(string)
Checks if the given string can be casted to a number (int or float).
Returns:
Type | Description |
---|---|
bool
|
True if the given string can be casted to a number. |
Source code in pfdl_scheduler/utils/helpers.py
87 88 89 90 91 92 93 94 95 |
|
is_string(string)
Check if the given parameter is a string in the DSL: It should start and end with '"'.
Returns:
Type | Description |
---|---|
bool
|
True if the given string is a string in the DSL. |
Source code in pfdl_scheduler/utils/helpers.py
65 66 67 68 69 70 71 72 73 |
|
parse_operator(op)
Parses a PFDL operator in form of a string into a Python executable operator func.
Source code in pfdl_scheduler/utils/helpers.py
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
|
log_entry_observer
This module provides the LogEntryObserver which implements the Observer pattern.
The scheduler notifies about log entries, so this class is used to catch these updates and log them into a file
LogEntryObserver(scheduler_id)
Bases: Observer
LogEntryObserver for receiving logging information from the Scheduler.
LogLevels are based of https://docs.python.org/3/library/logging.html#logging-levels
Source code in pfdl_scheduler/utils/log_entry_observer.py
39 40 41 42 43 44 45 |
|
parsing_utils
Contains functions which are used to load and parse PFDL files.
load_file(file_path)
Loads the content of the file from the given path.
Returns:
Type | Description |
---|---|
str
|
The content of the file as a string. |
Source code in pfdl_scheduler/utils/parsing_utils.py
96 97 98 99 100 101 102 103 104 105 |
|
parse_file(file_path)
Loads the content of the file from the given path and calls the parse_string function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_path |
str
|
The path to the PFDL file. |
required |
Returns:
Type | Description |
---|---|
bool
|
A boolan indicating validity of the PFDL file, the content of the file, and the |
Union[None, Process]
|
process object if so, otherwise None. |
Source code in pfdl_scheduler/utils/parsing_utils.py
70 71 72 73 74 75 76 77 78 79 80 81 |
|
parse_string(pfdl_string, file_path='', used_in_extension=False)
Instantiate the ANTLR lexer and parser and parses the given PFDL string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pfdl_string |
str
|
A string containing the content of a PFDL file. |
required |
file_path |
str
|
The path of the PFDL file (used for error messages). |
''
|
used_in_extension |
bool
|
A boolean indicating if the function is called from the extension. |
False
|
Returns:
Type | Description |
---|---|
Tuple[bool, Union[None, Process]]
|
A boolan indicating validity of the PFDL file and the process object if so, otherwise None. |
Source code in pfdl_scheduler/utils/parsing_utils.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 |
|
write_tokens_to_file(token_stream)
Writes the given ANTLR CommonTokenStream into a file named 'token.txt'.
Source code in pfdl_scheduler/utils/parsing_utils.py
84 85 86 87 88 89 90 91 92 93 |
|
validation
error_handler
Contains the ErrorHandler class.
ErrorHandler(file_path, used_in_extension)
Keeps track of the total error amount in an PFDL file.
Provides a method for printing an erro which counts the errors.
Attributes:
Name | Type | Description |
---|---|---|
total_error_count |
int
|
Total number of errors. |
syntax_error_count |
int
|
Number of syntax errors. |
semantic_error_count |
int
|
Number of static semantic errors. |
file_path |
str
|
The file path to the PFDL file. |
used_in_extension |
bool
|
A boolean indicating if the Generator is used within the extension. |
Initialize the object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_path |
str
|
The file path to the PFDL file. |
required |
used_in_extension |
bool
|
A boolean indicating if the Generator is used within the extension. |
required |
Source code in pfdl_scheduler/validation/error_handler.py
26 27 28 29 30 31 32 33 34 35 36 37 |
|
has_error()
Returns true if the total error_count is greater than zero.
Source code in pfdl_scheduler/validation/error_handler.py
78 79 80 |
|
print_error(error_msg, line=0, column=0, off_symbol_length=0, context=None, syntax_error=False)
Prints an error into the standard output.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
error_msg |
str
|
A string containing the error message |
required |
line |
int
|
The line in which the error occured |
0
|
column |
int
|
The column in which the error occured |
0
|
off_symbol_length |
int
|
Length of the offending symbol |
0
|
context |
ParserRuleContext
|
ANTLR Context object (lines and column will be used from this if not None) |
None
|
syntax_error |
bool
|
A boolean indicating whether the error is a syntax error or not. |
False
|
Source code in pfdl_scheduler/validation/error_handler.py
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 |
|
semantic_error_checker
Contains the SemanticErrorChecker class.
SemanticErrorChecker(error_handler, process)
Checks for static semantic errors in a given Process object.
Each of the methods in this class checks for a specific semantic error. After calling the validate_process method the entire given process object and all the model objects it contains are tested for errors.
Attributes:
Name | Type | Description |
---|---|---|
error_handler |
ErrorHandler
|
ErrorHandler instance for printing errors. |
process |
Process
|
The Process object which has to be validated. |
tasks |
Dict[str, Task]
|
A Dict that contains all Task objects of the given process object. |
structs |
Dict[str, Struct]
|
A Dict that contains all Struct objects of the given process object. |
Initialize the object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
error_handler |
ErrorHandler
|
ErrorHandler instance for printing errors. |
required |
process |
Process
|
The Process object which has to be validated. |
required |
Source code in pfdl_scheduler/validation/semantic_error_checker.py
49 50 51 52 53 54 55 56 57 58 59 |
|
check_array(instantiated_array, array_definition)
Calls check methods to validate the instantiated array.
Returns:
Type | Description |
---|---|
bool
|
True if the given array is valid. |
Source code in pfdl_scheduler/validation/semantic_error_checker.py
644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 |
|
check_attribute_access(variable_list, context, task)
Checks if the attribute access via a variable list (for example x.y.z) is valid.
Returns:
Type | Description |
---|---|
bool
|
True if the attribute access is valid. |
Source code in pfdl_scheduler/validation/semantic_error_checker.py
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 |
|
check_binary_operation(expression, context, task)
Checks if a binary expression is a valid expression.
Returns:
Type | Description |
---|---|
bool
|
True if the given binary expression is a valid expression. |
Source code in pfdl_scheduler/validation/semantic_error_checker.py
793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 |
|
check_call_input_parameters(called_entity, task)
Checks if the input parameters of a Service or Task Call are valid.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
called_entity |
Union[Service, TaskCall]
|
The evoked call (service or task call). |
required |
Returns:
Type | Description |
---|---|
bool
|
True if the input parameters of a Service or Task Call are valid. |
Source code in pfdl_scheduler/validation/semantic_error_checker.py
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 |
|
check_call_output_parameters(called_entity)
Checks if the output parameters of a Service or Task Call are valid.
The output parameter of a call only consists of the visible variable name and
the type of the variable. So all there is to check is the variable definition.
This methods just calls the check_if_variable_definition_is_valid
method for all
output parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
called_entity |
Union[Service, TaskCall]
|
The evoked call (service or task call). |
required |
Returns:
Type | Description |
---|---|
bool
|
True if the output parameters of a Service or Task Call are valid. |
Source code in pfdl_scheduler/validation/semantic_error_checker.py
492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 |
|
check_call_parameters(called_entity, task)
Checks if the parameters of a Service or Task call are valid (input and output).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
called_entity |
Union[Service, TaskCall]
|
The evoked call (service or task call). |
required |
Returns:
Type | Description |
---|---|
bool
|
True if the parameters of a Service or Task call are valid. |
Source code in pfdl_scheduler/validation/semantic_error_checker.py
404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 |
|
check_conditional_statement(condition, task)
Calls check methods for the conditional statement.
Calls check_statement for the Passed and Failed statements and checks if the boolean expression is valid.
Returns:
Type | Description |
---|---|
bool
|
True if the conditional statement is valid. |
Source code in pfdl_scheduler/validation/semantic_error_checker.py
720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 |
|
check_counting_loop(counting_loop, task)
Calls check methods for the Counting Loop statement.
Returns:
Type | Description |
---|---|
bool
|
True if the Counting Loop statement is valid. |
Source code in pfdl_scheduler/validation/semantic_error_checker.py
707 708 709 710 711 712 713 714 715 716 717 718 |
|
check_expression(expression, context, task)
Executes checks to test given expression.
Returns:
Type | Description |
---|---|
bool
|
True if the given expression is valid. |
Source code in pfdl_scheduler/validation/semantic_error_checker.py
742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 |
|
check_for_missing_attribute_in_struct(struct, struct_definition)
Checks if an instantiated Struct is missing an attribute from the Struct definition.
Returns:
Type | Description |
---|---|
bool
|
True if no attributes are missing. |
Source code in pfdl_scheduler/validation/semantic_error_checker.py
674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 |
|
check_for_unknown_attribute_in_struct(struct_instance, identifier, struct_definition)
Checks if the given identifier in the instantiated struct exists in the struct definition.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
struct_instance |
Struct
|
The instantiated struct that is checked. |
required |
identifier |
str
|
The identifier in the struct instance which should be checked. |
required |
struct_definition |
Struct
|
The corresponding struct definition. |
required |
Returns:
Type | Description |
---|---|
bool
|
True if the given identifier exists in the struct definition. |
Source code in pfdl_scheduler/validation/semantic_error_checker.py
563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 |
|
check_for_unknown_datatypes_in_struct_definition(struct)
Checks for each attribute definition in the struct if the defined type exists.
Returns:
Type | Description |
---|---|
bool
|
True if all datatypes in the given struct are known. |
Source code in pfdl_scheduler/validation/semantic_error_checker.py
83 84 85 86 87 88 89 90 91 92 93 94 95 |
|
check_for_wrong_attribute_type_in_struct(struct_instance, identifier, struct_definition)
Calls check methods for the attribute assignments in an instantiated Struct.
This methods assumes that the given identifier is not unknown. Args: struct_instance: The instantiated struct that is checked. identifier: The identifier in the struct instance which should be checked. struct_definition: The corresponding struct definition.
Returns:
Type | Description |
---|---|
bool
|
True if the given identifier in the struct instance matches with the struct definition. |
Source code in pfdl_scheduler/validation/semantic_error_checker.py
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 |
|
check_if_input_parameter_matches(input_parameter, identifier, defined_type, task_call, called_task, task_context)
Checks if the input parameters of a Taskcall matches with the called Task.
This method assumes that the validity of the input parameter itself was already checked.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_parameter |
Union[str, List[str], Struct]
|
The input parameter of the TaskCall. |
required |
identifier |
str
|
Parameter name of the input in the called task (only for error message). |
required |
defined_type |
Union[str, Array]
|
Type of the input in the called task. |
required |
task_call |
TaskCall
|
The TaskCall the input parameter is from. |
required |
called_task |
Task
|
The Task the TaskCall is refering to (the called task). |
required |
task_context |
Task
|
The Task in which the TaskCall was evoked. |
required |
Returns: True if the input parameters of a Taskcall matches with the called Task.
Source code in pfdl_scheduler/validation/semantic_error_checker.py
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 |
|
check_if_struct_exists(struct)
Checks if the given Struct instance refers to a existing Struct definition.
Returns:
Type | Description |
---|---|
bool
|
True if the given Struct instance refers to a existing Struct definition. |
Source code in pfdl_scheduler/validation/semantic_error_checker.py
551 552 553 554 555 556 557 558 559 560 561 |
|
check_if_task_call_matches_with_called_task(task_call, task)
Checks if the parameters of the Taskcall matches with the parameters of the Task.
This method assumes that the validity of the input parameter itself was already checked.
Multiple Checks are done
(1) Checks if length of parameters of Taskcall and Task match. (2) Checks if types of input parameters match. (3) Checks if types of output parameters match.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
task_call |
TaskCall
|
The task call to be checked. |
required |
task_context |
The task in which the task call is defined. |
required |
Returns:
Type | Description |
---|---|
bool
|
True if the parameters matches. |
Source code in pfdl_scheduler/validation/semantic_error_checker.py
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 |
|
check_if_task_call_parameter_length_match(task_call)
Checks if the length of the Task call parameters match with the called Task.
Returns:
Type | Description |
---|---|
bool
|
True if the parameter lengths matches. |
Source code in pfdl_scheduler/validation/semantic_error_checker.py
387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 |
|
check_if_task_in_taskcall_exists(task_name, context)
Checks if the Task name in the Taskcall belongs to a Task.
Returns:
Type | Description |
---|---|
bool
|
True if the given name belongs to a Task. |
Source code in pfdl_scheduler/validation/semantic_error_checker.py
886 887 888 889 890 891 892 893 894 895 896 |
|
check_if_variable_definition_is_valid(identifier, variable_type, context)
Checks if the variable has the correct type.
Returns:
Type | Description |
---|---|
bool
|
True if variable definition is valid. |
Source code in pfdl_scheduler/validation/semantic_error_checker.py
860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 |
|
check_instantiated_struct_attributes(struct_instance)
Calls multiple check methods to validate an instantiated Struct.
Multiple Checks are done
(1) Check if the name of the struct instance exists in the struct definitions. (2) Check if attributes from the struct definition are missing. (3) Check if there are attributes in the instance that do not exist in the definition. (4) Check if attributes in the instance do not match with attributes in the definition.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
struct_instance |
Struct
|
The instantiated struct that is checked. |
required |
Returns:
Type | Description |
---|---|
bool
|
True if the instantiated Struct is valid. |
Source code in pfdl_scheduler/validation/semantic_error_checker.py
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 |
|
check_parallel(parallel, task)
Calls check methods for the Parallel statement.
Returns:
Type | Description |
---|---|
bool
|
True if the given Parallel statement is valid. |
Source code in pfdl_scheduler/validation/semantic_error_checker.py
160 161 162 163 164 165 166 167 168 169 170 171 |
|
check_service(service, task)
Calls check methods for the Service or Service Call statement.
Returns:
Type | Description |
---|---|
bool
|
True if the given Service statement is valid. |
Source code in pfdl_scheduler/validation/semantic_error_checker.py
208 209 210 211 212 213 214 215 216 |
|
check_single_expression(expression, context, task)
Checks if a single expression is a valid expression.
Returns:
Type | Description |
---|---|
bool
|
True if the given single expression is a valid expression. |
Source code in pfdl_scheduler/validation/semantic_error_checker.py
762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 |
|
check_statement(statement, task)
Calls check methods depending on the type of the statement.
Returns:
Type | Description |
---|---|
bool
|
True if the given statement is valid. |
Source code in pfdl_scheduler/validation/semantic_error_checker.py
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
|
check_statements(task)
Executes semantic checks for all statements in a Task.
Returns:
Type | Description |
---|---|
bool
|
True if all Statements are valid. |
Source code in pfdl_scheduler/validation/semantic_error_checker.py
126 127 128 129 130 131 132 133 134 135 136 |
|
check_structs()
Executes semantic checks for each Struct.
Returns:
Type | Description |
---|---|
bool
|
True if all Struct definitions are valid. |
Source code in pfdl_scheduler/validation/semantic_error_checker.py
71 72 73 74 75 76 77 78 79 80 81 |
|
check_task_call(task_call, task_context)
Calls check methods for the TaskCall statement.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
task_call |
TaskCall
|
The task call to be checked. |
required |
task_context |
Task
|
The task in which the task call is defined. |
required |
Returns:
Type | Description |
---|---|
bool
|
True if the given TaskCall statement is valid. |
Source code in pfdl_scheduler/validation/semantic_error_checker.py
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 |
|
check_task_input_parameters(task)
Checks if the input parameters are valid.
Returns:
Type | Description |
---|---|
bool
|
True if the input parameters of the given Task are valid. |
Source code in pfdl_scheduler/validation/semantic_error_checker.py
173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
|
check_task_output_parameters(task)
Checks if the output parameters are valid.
Checks if the variable names used as parameters are variables defined in the Task.
Returns:
Type | Description |
---|---|
bool
|
True if the output parameters of the given Task are valid. |
Source code in pfdl_scheduler/validation/semantic_error_checker.py
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
|
check_tasks()
Executes semantic checks for each Task.
Returns:
Type | Description |
---|---|
bool
|
True if all Task definitions are valid. |
Source code in pfdl_scheduler/validation/semantic_error_checker.py
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 |
|
check_unary_operation(expression, context, task)
Checks if a unary expression is a valid expression.
Returns:
Type | Description |
---|---|
bool
|
True if the given unary expression is a valid expression. |
Source code in pfdl_scheduler/validation/semantic_error_checker.py
785 786 787 788 789 790 791 |
|
check_while_loop(while_loop, task)
Calls check methods for the While Loop statement.
Returns:
Type | Description |
---|---|
bool
|
True if the While Loop statement is valid. |
Source code in pfdl_scheduler/validation/semantic_error_checker.py
692 693 694 695 696 697 698 699 700 701 702 703 704 705 |
|
expression_is_number(expression, task)
Checks if the given expression is a number (int or float).
Returns:
Type | Description |
---|---|
bool
|
True if the given expression is a number. |
Source code in pfdl_scheduler/validation/semantic_error_checker.py
826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 |
|
expression_is_string(expression, task)
Checks if the given expression is a PFDL string.
Returns:
Type | Description |
---|---|
bool
|
True if the given expression is a PFDL string. |
Source code in pfdl_scheduler/validation/semantic_error_checker.py
847 848 849 850 851 852 853 854 855 856 857 858 |
|
instantiated_array_length_correct(instantiated_array, array_definition)
Checks if the length of the instantiated array matches with the array definition.
Returns:
Type | Description |
---|---|
bool
|
True if both lengths are equal. |
Source code in pfdl_scheduler/validation/semantic_error_checker.py
914 915 916 917 918 919 920 921 922 923 924 925 |
|
validate_process()
Starts static semantic checks.
Returns:
Type | Description |
---|---|
bool
|
True, if the process has no errors, otherwise False. |
Source code in pfdl_scheduler/validation/semantic_error_checker.py
61 62 63 64 65 66 67 68 |
|
variable_type_exists(variable_type)
Checks if the given variable type exists in the PFDL file.
A variable type can be a primitive (number, string or boolean) or an identifier of a defined Struct.
Returns:
Type | Description |
---|---|
bool
|
True if the variable type exists within the PFDL file. |
Source code in pfdl_scheduler/validation/semantic_error_checker.py
898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 |
|
syntax_error_listener
Contains SyntaxErrorListener class.
SyntaxErrorListener(token_stream, error_handler)
Bases: ErrorListener
Custom ErrorListener for the PFDL.
Overrides Antlr ErrorListener class so we can use our ErrorHandler class for syntax errors.
Attributes:
Name | Type | Description |
---|---|---|
token_stream |
CommonTokenStream
|
ANTLR token stream. |
error_handler |
ErrorHandler
|
ErrorHandler instance for printing errors. |
Initialize the object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
token_stream |
CommonTokenStream
|
ANTLR token stream. |
required |
error_handler |
ErrorHandler
|
ErrorHandler instance for printing errors. |
required |
Source code in pfdl_scheduler/validation/syntax_error_listener.py
31 32 33 34 35 36 37 38 39 40 |
|
syntaxError(recognizer, offendingSymbol, line, column, msg, e)
Overwrites the ANTLR ErrorListener method to use the error handler.
Source code in pfdl_scheduler/validation/syntax_error_listener.py
42 43 44 45 46 47 48 49 50 51 52 |
|