1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 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 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 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 680 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 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 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 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 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 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313
|
Master-Worker connection with MessagePack over WebSocket protocol
=================================================================
.. note::
This is experimental protocol.
Messages between master and worker are sent using WebSocket protocol in both directions.
Data to be sent conceptually is a dictionary and is encoded using MessagePack.
One such encoded dictionary corresponds to one WebSocket message.
Authentication happens during opening WebSocket handshake using standard HTTP Basic authentication.
Worker credentials are sent in the value of the HTTP "Authorization" header.
Master checks if the credentials match and if not - the connection is terminated.
A WebSocket message can be either a request or a response.
Request message is sent when one side wants another one to perform an action.
Once the action is performed, the other side sends the response message back.
A response message is mandatory for every request message.
Message key-value pairs
-----------------------
This section describes a general structure of messages.
It applies for both master and worker.
.. _MsgPack_Request_Message:
Request message
~~~~~~~~~~~~~~~
A request message must contain at least these keys: ``seq_number``, ``op``.
Additional key-value pairs may be supplied depending on the request type.
``seq_number``
Value is an integer.
``seq_number`` must be unique for every request message coming from a particular side.
The purpose of ``seq_number`` value is to link the request message with response message.
Response message will carry the same ``seq_number`` value as in corresponding request message.
``op``
Value is a string.
It must not be ``response``.
Each side has a predefined set of commands that another side may invoke.
``op`` specifies the command to be invoked by requesting side.
.. _MsgPack_Response_Message:
Response message
~~~~~~~~~~~~~~~~
A response message must contain at least these keys: ``seq_number``, ``op``, ``result``.
``seq_number``
Value is an integer.
It represents a number which was specified in the corresponding request message.
``op``
Value is a string, always a ``response``.
``result``
Value is ``None`` when success.
Otherwise – message of exception.
``is_exception``
This key-value pair is optional.
If request succeeded this key-value pair is absent.
Otherwise, its value is a boolean ``True`` and the message of exception is specified in the
value of ``result``.
Messages from master to worker
------------------------------
print
~~~~~
Request
+++++++
This message requests worker to print a message to its log.
``seq_number``
Described in section on :ref:`MsgPack_Request_Message` structure.
``op``
Value is a string ``print``.
``message``
Value is a string.
It represents the string to be printed in worker’s log.
Response
++++++++
Worker prints a message from master to its log.
``seq_number``
Described in section on :ref:`MsgPack_Response_Message` structure.
``op``
Value is a string ``response``.
``result``
Value is ``None`` if log was printed successfully.
Otherwise – message of exception.
``is_exception``
This key-value pair is optional.
If request succeeded this key-value pair is absent.
Otherwise, its value is a boolean ``True`` and the message of exception is specified in the
value of ``result``.
keep-alive
~~~~~~~~~~
Request
+++++++
Master sends this message to check if the connection is still working.
``seq_number``
Described in section on :ref:`MsgPack_Request_Message` structure.
``op``
Value is a string ``keepalive``.
Response
++++++++
Response indicates that connection is still working.
``seq_number``
Described in section on :ref:`MsgPack_Response_Message` structure.
``op``
Value is a string ``response``.
``result``
Value is ``None``.
get_worker_info
~~~~~~~~~~~~~~~
Request
+++++++
This message requests worker to collect and send the information about itself back to the master.
Only ``op`` and ``seq_number`` values are sent, because worker does not need any additional
arguments for this action.
``op``
Value is a string ``get_worker_info``.
``seq_number``
Described in section on :ref:`MsgPack_Request_Message` structure.
Response
++++++++
``op``
Value is a string ``response``.
``seq_number``
Described in section on :ref:`MsgPack_Response_Message` structure.
``result``
Value is a dictionary that contains data about worker.
Otherwise – message of exception.
``is_exception``
This key-value pair is optional.
If request succeeded this key-value pair is absent.
Otherwise, its value is a boolean ``True`` and the message of exception is specified in the
value of ``result``.
Key-value pairs in ``result`` dictionary represent:
``environ``
Value is a dict.
It represents environment variables of the worker.
``system``
Value is a string.
It represents a name of the operating system dependent module imported.
``basedir``
Value is a string.
It represents a path to build directory.
``numcpus``
Value is an integer.
It represents a number of CPUs in the system.
If CPUs number for the worker is not detected, number 1 is set.
``version``
Value is a string.
It represents worker version.
``worker_commands``
Value is a dictionary.
Keys of this dictionary represent the commands that worker is able to perform.
Values represent the command version.
Additionally, files in Worker 'basedir/info' directory are read as key-value pairs.
Key is a name of a file and value is the content of a file.
As a convention, there are files named 'admin' and 'host':
``admin``
Value is a string.
It specifies information about administrator responsible for this worker.
``host``
Value is a string.
It specifies the name of the host.
set_worker_settings
~~~~~~~~~~~~~~~~~~~
Request
+++++++
Master sends this message to set worker settings.
The settings must be sent from master before first command.
``seq_number``
Described in section on :ref:`MsgPack_Request_Message` structure.
``op``
Value is a string ``set_worker_settings``.
``args``
Value is a dictionary.
It represents the settings needed for worker to format command output and buffer messages.
The following settings are mandatory:
* "buffer_size" - the maximum size of buffer in bytes to fill before sending an update message.
* "buffer_timeout" - the maximum time in seconds that data can wait in buffer before update
message is sent.
* "newline_re" - the pattern in output string, which will be replaced with newline symbol.
* "max_line_length" - the maximum size of command output line in bytes.
Response
++++++++
``seq_number``
Described in section on :ref:`MsgPack_Response_Message` structure.
``op``
Value is a string ``response``.
``result``
Value is ``None`` if success.
Otherwise – message of exception.
start_command
~~~~~~~~~~~~~
Request
+++++++
This message requests worker to start a specific command. Master does not have to wait for
completion of previous commands before starting a new one, so many different commands may be
running in worker simultaneously.
Each start command request message has a unique ``command_id`` value.
Worker may be sending request ``update`` messages to master which update master about status of
started command. When worker sends a request ``update`` message about command, the message takes a
``command_id`` value from corresponding start command request message. Accordingly master can match
update messages to the commands they correspond to. When command execution in worker is completed,
worker sends a request ``complete`` message to master with the ``command_id`` value of the
completed command. It allows master to track which command exactly was completed.
``op``
Value is a string ``start_command``.
``seq_number``
Described in section :ref:`MsgPack_Request_Message` structure.
``command_id``
Value is a string value that is unique per worker connection.
``command_name``
Value is a string.
It represents a name of the command to be called.
``args``
Value is a dictionary.
It represents arguments needed to run the command and any additional information about a command.
Arguments of all different commands are explained in section :ref:`MsgPack_Request_Types_Message`.
Response
++++++++
``op``
Value is a string ``response``.
``seq_number``
Described in section :ref:`MsgPack_Response_Message` structure.
``result``
Value is ``None`` when success.
Otherwise – message of exception.
``is_exception``
This key-value pair is optional.
If request succeeded this key-value pair is absent.
Otherwise, its value is a boolean ``True`` and the message of exception is specified in the
value of ``result``.
interrupt_command
~~~~~~~~~~~~~~~~~
Request
+++++++
This message requests worker to halt the specified command.
``seq_number``
Described in section :ref:`MsgPack_Request_Message`
``op``
Value is a string ``interrupt_command``.
``command_id``
Value is a string which identifies the command to interrupt.
``why``
Value is a string.
It represents the reason of interrupting command.
Response
++++++++
During this command worker may also send back additional update messages to the master.
Update messages are explained in section :ref:`MsgPack_Update_Message`.
``op``
Value is a string ``response``.
``seq_number``
Described in section :ref:`MsgPack_Response_Message`
``result``
Value is ``None`` if success.
Otherwise – message of exception.
``is_exception``
This key-value pair is optional.
If request succeeded this key-value pair is absent.
Otherwise, its value is a boolean ``True`` and the message of exception is specified in the
value of ``result``.
shutdown
~~~~~~~~
Request
+++++++
This message requests worker to shutdown itself.
Action does not require arguments, so only ``op`` and ``seq_number`` values are sent.
``seq_number``
Described in section :ref:`MsgPack_Request_Message`
``op``
The value is a string ``shutdown``.
Response
++++++++
Worker returns ``result``: ``None`` without waiting for completion of shutdown.
``op``
Value is a string ``response``.
``seq_number``
Described in section :ref:`MsgPack_Response_Message`.
``result``
Value is ``None`` if success.
Otherwise – message of exception.
``is_exception``
This key-value pair is optional.
If request succeeded this key-value pair is absent.
Otherwise, its value is a boolean ``True`` and the message of exception is specified in the
value of ``result``.
Messages from worker to master
------------------------------
.. _MsgPack_Update_Message:
update
~~~~~~
From the start of a command till its completion, worker may be updating master about the processes
of commands it requested to start. These updates are sent in an ``update`` messages.
Request
+++++++
``seq_number``
Described in section :ref:`MsgPack_Request_Message`.
``op``
Value is a string ``update``.
``args``
Value is a list of two-element lists.
These two elements in sub-lists represent name-value pairs: first element is the name of
update and second is its value.
The names and values are further explained in section :ref:`MsgPack_Keys_And_Values_Message`.
``command_id``
Value is a string which identifies command the update refers to.
Response
++++++++
``op``
Value is a string ``response``.
``seq_number``
Described in section :ref:`MsgPack_Response_Message`.
``result``
Value is ``None`` when master successfully acknowledges the update.
Otherwise – message of exception.
``is_exception``
This key-value pair is optional.
If request succeeded this key-value pair is absent.
Otherwise, its value is a boolean ``True`` and the message of exception is specified in the
value of ``result``.
update_upload_file_write
~~~~~~~~~~~~~~~~~~~~~~~~
Request
+++++++
``op``
Value is a string ``update_upload_file_write``.
``args``
Contents of the chunk from the file that worker read.
``command_id``
Value is a string which identifies command the update refers to.
Response
++++++++
``op``
Value is a string ``response``.
``seq_number``
Described in section :ref:`MsgPack_Response_Message`.
``result``
Value is ``None`` when master successfully acknowledges the update.
Otherwise – message of exception.
``is_exception``
This key-value pair is optional.
If request succeeded this key-value pair is absent.
Otherwise, its value is a boolean ``True`` and the message of exception is specified in the
value of ``result``.
update_upload_file_close
~~~~~~~~~~~~~~~~~~~~~~~~
By this command worker states that no more data will be transferred.
Request
+++++++
``op``
Value is a string ``update_upload_file_close``.
``command_id``
Value is a string which identifies command the update refers to.
Response
++++++++
``op``
Value is a string ``response``.
``seq_number``
Described in section :ref:`MsgPack_Response_Message`.
``result``
Value is ``None`` when master successfully acknowledges the update.
Otherwise – message of exception.
``is_exception``
This key-value pair is optional.
If request succeeded this key-value pair is absent.
Otherwise, its value is a boolean ``True`` and the message of exception is specified in the
value of ``result``.
update_upload_file_utime
~~~~~~~~~~~~~~~~~~~~~~~~
Request
+++++++
``op``
Value is a string ``update_upload_file_utime``.
``access_time``
Value is a floating point number.
It is a number of seconds that passed from the start of the Unix epoch
(January 1, 1970, 00:00:00 (UTC)) and last access of path.
``modified_time``
Value is a floating point number.
It is a number of seconds that passed from the start of the Unix epoch
(January 1, 1970, 00:00:00 (UTC)) and last modification of path.
``command_id``
Value is a string which identifies command the update refers to.
Response
++++++++
``op``
Value is a string ``response``.
``seq_number``
Described in section :ref:`MsgPack_Response_Message`.
``result``
Value is ``None`` when master successfully acknowledges the update.
Otherwise – message of exception.
``is_exception``
This key-value pair is optional.
If request succeeded this key-value pair is absent.
Otherwise, its value is a boolean ``True`` and the message of exception is specified in the
value of ``result``.
update_read_file
~~~~~~~~~~~~~~~~
Request
+++++++
``op``
Value is a string ``update_read_file``.
``length``
Maximum number of bytes of data to read.
``command_id``
Value is a string which identifies command the update refers to.
Response
++++++++
``op``
Value is a string ``response``.
``seq_number``
Described in section :ref:`MsgPack_Response_Message`.
``result``
Value is data of length ``length`` that master read from its file.
Otherwise – message of exception.
``is_exception``
This key-value pair is optional.
If request succeeded this key-value pair is absent.
Otherwise, its value is a boolean ``True`` and the message of exception is specified in the
value of ``result``.
update_read_file_close
~~~~~~~~~~~~~~~~~~~~~~
By this command worker states that no more data will be transferred.
Request
+++++++
``op``
Value is a string ``update_read_file_close``.
``command_id``
Value is a string which identifies command the update refers to.
Response
++++++++
``op``
Value is a string ``response``.
``seq_number``
Described in section :ref:`MsgPack_Response_Message`.
``result``
Value is ``None`` when master successfully acknowledges the update.
Otherwise – message of exception.
``is_exception``
This key-value pair is optional.
If request succeeded this key-value pair is absent.
Otherwise, its value is a boolean ``True`` and the message of exception is specified in the
value of ``result``.
update_upload_directory_write
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Request
+++++++
``op``
Value is a string ``update_upload_directory_write``.
``args``
Contents of the chunk from the directory that worker read.
``command_id``
Value is a string which identifies command the update refers to.
Response
++++++++
``op``
Value is a string ``response``.
``seq_number``
Described in section :ref:`MsgPack_Response_Message`.
``result``
Value is ``None`` when master successfully acknowledges the update.
Otherwise – message of exception.
``is_exception``
This key-value pair is optional.
If request succeeded this key-value pair is absent.
Otherwise, its value is a boolean ``True`` and the message of exception is specified in the
value of ``result``.
update_upload_directory_unpack
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
By this command worker states that no more data will be transferred.
Request
+++++++
``op``
Value is a string ``update_upload_directory_unpack``.
``command_id``
Value is a string which identifies command the update refers to.
Response
++++++++
``op``
Value is a string ``response``.
``seq_number``
Described in section :ref:`MsgPack_Response_Message`.
``result``
Value is ``None`` when master successfully acknowledges the update.
Otherwise – message of exception.
``is_exception``
This key-value pair is optional.
If request succeeded this key-value pair is absent.
Otherwise, its value is a boolean ``True`` and the message of exception is specified in the
value of ``result``.
complete
~~~~~~~~
Notifies master that the remote command has finished.
Request
+++++++
``seq_number``
Described in section :ref:`MsgPack_Request_Message`
``op``
Value is a string ``complete``.
``args``
``None`` if a command succeeded.
A message of error as a string if command failed.
``command_id``
Value is a string which identifies command to complete.
Response
++++++++
``op``
Value is a string ``response``.
``seq_number``
Described in section :ref:`MsgPack_Response_Message`.
``result``
Value is ``None`` when master successfully acknowledges the completion.
Otherwise – message of exception.
``is_exception``
This key-value pair is optional.
If request succeeded this key-value pair is absent.
Otherwise, its value is a boolean ``True`` and the message of exception is specified in the
value of ``result``.
.. _MsgPack_Request_Types_Message:
``start_command`` request types
-------------------------------
Request causes worker to start performing an action.
There are multiple types of the request each supporting a particular type of worker action.
The basic structure of request is the same as explained in section :ref:`MsgPack_Request_Message`.
Values of ``command_name`` and ``args`` keys depend on the specific command within the request
message dictionary. ``command_name`` is a string which defines command type. ``args`` is a
dictionary which defines the arguments and other variables worker needs to perform the command
successfully. Worker starts a program specified in the key ``command_name`` and sends updates to
the master about ongoing command.
Command names and their arguments dictionary key-value pairs are explained below.
Command_name: ``shell``
~~~~~~~~~~~~~~~~~~~~~~~
Runs a ``shell`` command on the worker.
``workdir``
Value is a string.
``workdir`` is an absolute path and overrides the builder directory.
The resulting path represents the worker directory to run the command in.
``env``
Value is a dictionary and is optional.
It contains key-value pairs that specify environment variables for the environment in which a
new command is started.
If the value is of type list, its elements are concatenated to a single string using a platform
specific path separator between the elements.
If this dictionary contains "PYTHONPATH" key, path separator and "$PYTHONPATH" is appended to
that value.
Resulting environment dictionary sent to the command is created following these rules:
1) If ``env`` has value for specific key and it is ``None``, resulting dictionary does not have
this key.
2) If ``env`` has value for specific key and it is not ``None``, resulting dictionary contains
this value with substitutions applied.
Any matches of a pattern ``${name}`` in this value, where name is any number of alphanumeric
characters, are substituted with the value of the same key from worker environment.
3) If a specific key from worker environment is not present in ``env``, resulting dictionary
contains that key-value pair from worker environment.
``want_stdout``
Value is a bool and is optional.
If value is not specified, the default is ``True``.
If value is ``True``, worker sends ``update`` log messages to master from the process
``stdout`` output.
``want_stderr``
Value is a bool and is optional.
If value is not specified, the default is True.
If value is ``True``, worker sends ``update`` log messages to the master from the process
``stderr`` output.
``logfiles``
Value is a dictionary and is optional.
If the value is not specified, the default is an empty dictionary.
This dictionary specifies logfiles other than stdio.
Keys are the logfile names.
Worker reads this logfile and sends the data with the ``update`` message, where logfile name as
a key identifies data of different logfiles.
Value is a dictionary. It contains the following keys:
``filename``
Value is a string. It represents the filename of the logfile, relative to worker directory
where the command is run.
``follow``
Value is a boolean.
If ``True`` - only follow the file from its current end-of-file, rather than starting from
the beginning. The default is ``False``.
``timeout``
Value is an integer and is optional.
If value is not specified, the default is ``None``.
It represents, how many seconds a worker should wait before killing a process after it gives no output.
``maxTime``
Value is an integer and is optional.
If value is not specified, the default is ``None``. It represents, how many seconds a worker
should wait before killing a process. Even if command is still running and giving the output,
``maxTime`` variable sets the maximum time the command is allowed to be performing. If
``maxTime`` is set to ``None``, command runs for as long as it needs unless ``timeout``
specifies otherwise.
``max_lines``
Value is an integer and is optional.
If value is not specified, the default is ``None``.
It represents, how many produced lines a worker should wait before killing a process.
If ``max_lines`` is set to ``None``, command runs for as long as it needs unless ``timeout``
or ``maxTime`` specifies otherwise.
``sigtermTime``
Value is an integer and is optional.
If value is not specified, the default is ``None``.
It specifies how to abort the process.
If ``sigtermTime`` is not ``None`` when aborting the process, worker sends a signal SIGTERM.
After sending this signal, worker waits for ``sigtermTime`` seconds of time and if the process
is still alive, sends the signal SIGKILL.
If ``sigtermTime`` is ``None``, worker does not wait and sends signal SIGKILL to the process
immediately.
``usePTY``
Value is a bool and is optional.
If value is not specified, the default is ``False``.
``True`` to use a PTY, ``False`` to not use a PTY.
``logEnviron``
Value is a bool and is optional.
If value is not specified, the default is ``True``.
If ``True``, worker sends to master an ``update`` message with process environment key-value
pairs at the beginning of a process.
``initial_stdin``
Value is a string or ``None``.
If not ``None``, the value is sent to the process as an initial stdin after process is started.
If value is ``None``, no initial stdin is sent.
``command``
Value is a list of strings or a string.
It represents the name of a program to be started and its arguments.
If this is a string, it will be invoked via ``/bin/sh`` shell by calling it as ``/bin/sh -c <command>``.
Otherwise, it must be a list, which will be executed directly.
If command succeeded, worker sends ``rc`` value 0 as an ``update`` message ``args`` key-value
pair. It can also send many other ``update`` messages with keys such as ``header``, ``stdout``
or ``stderr`` to inform about command execution. If command failed, it sends ``rc`` value with
the error number. If command timed out, it sends ``failure_reason`` key. The value of the
``failure_reason`` key can be one of the following:
- ``timeout`` if the command timed out due to time specified by the ``maxTime`` parameter being
exceeded.
- ``timeout_without_output`` if the command timed out due to time specified by the ``timeout``
parameter being exceeded.
- ``max_lines_failure`` if the command is killed due to the number of lines specified by the
``max_lines`` parameter being exceeded.
The basic structure of worker ``update`` message is explained in section
:ref:`MsgPack_Keys_And_Values_Message`.
Command_name: ``upload_file``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Worker reads the contents of its file and sends them in chunks to write into the file on masters’s side.
``path``
Value is a string.
It specifies the path of the worker file to read from.
``maxsize``
Value is an integer.
Maximum number of bytes to transfer from the worker.
The operation will fail if the file exceeds this size.
Worker will send messages with data to master until it notices it exceeded ``maxsize``.
``blocksize``
Value is an integer.
Maximum size for each data block to be sent to master.
``keepstamp``
Value is a bool.
It represents whether to preserve "file modified" and "accessed" times.
``True`` is for preserving.
Workers sends data to master with one or more ``update_upload_file_write`` messages.
After reading the file is over, worker sends ``update_upload_file_close`` message.
If ``keepstamp`` was ``True``, workers sends ``update_upload_file_utime`` message.
If command succeeded, worker sends ``rc`` value 0 as an ``update`` message ``args`` key-value pair.
It can also send ``update`` messages with key ``header`` or ``stderr`` to inform about command
execution.
If command failed, worker sends ``update_upload_file_close`` message and the ``update`` message
with dictionary ``args`` key ``rc`` with the error number.
The basic structure of worker ``update`` message is explained in section :ref:`MsgPack_Keys_And_Values_Message`.
Command_name: ``upload_directory``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Similar to ``upload_file``.
This command will upload an entire directory to the master, in the form of a tarball.
``path``
Value is a string.
It specifies the path of the worker directory to upload.
``maxsize``
Value is an integer.
Maximum number of bytes to transfer from the worker.
The operation will fail if the tarball file exceeds this size.
Worker will send messages with data to master until it notices it exceeded ``maxsize``.
``blocksize``
Value is an integer.
Maximum size for each data block to be sent to master.
``compress``
Compression algorithm to use – one of ``None``, 'bz2', or 'gz'.
Worker sends data to the master with one or more ``update_upload_directory_write`` messages.
After reading the directory, worker sends ``update_upload_directory_unpack`` with no arguments
to extract the tarball and ``rc`` value 0 as an ``update`` message ``args`` key-value pair if
the command succeeded.
Otherwise, worker sends ``update`` message with dictionary ``args`` key ``header`` with
information about the error that occurred and another ``update`` message with dictionary
``args`` key ``rc`` with the error number.
The basic structure of worker ``update`` message is explained in section
:ref:`MsgPack_Keys_And_Values_Message`.
Command_name: ``download_file``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Downloads a file from master to worker.
``path``
Value is a string.
It specifies the path of the worker file to create.
``maxsize``
Value is an integer.
Maximum number of bytes to transfer from the master.
The operation will fail if the file exceeds this size.
Worker will request data from master until it notices it exceeded ``maxsize``.
``blocksize``
Value is an integer.
It represents maximum size for each data block to be sent from master to worker.
``mode``
Value is ``None`` or an integer which represents an access mode for the new file.
256 - owner has read permission.
128 - owner has write permission.
64 - owner has execute permission.
32 - group has read permission.
16 - group has write permission.
8 - group has execute permission.
4 - others have read permission.
2 - others have write permission.
1 - others have execute permission.
If ``None``, file has default permissions.
If command succeeded, worker will send ``rc`` value 0 as an ``update`` message ``args``
key-value pair.
Otherwise, worker sends ``update`` message with dictionary ``args`` key ``header`` with
information about the error that occurred and another ``update`` message with dictionary
``args`` key ``rc`` with the error number.
The basic structure of worker ``update`` message is explained in section
:ref:`MsgPack_Keys_And_Values_Message`.
Command_name: ``listdir``
~~~~~~~~~~~~~~~~~~~~~~~~~
This command reads the directory and returns the list with directory contents.
``path``
Value is a string.
It specifies the path of a directory to list.
If command succeeded, the list containing the names of the entries in the directory given by
that path is sent via ``update`` message in ``args`` key ``files``. Worker will also send
``rc`` value 0 as an ``update`` message ``args`` key-value pair. If command failed, worker
sends ``update`` message with dictionary ``args`` key ``header`` with information about the
error that occurred and another ``update`` message with dictionary ``args`` key ``rc`` with the
error number.
The basic structure of worker ``update`` message is explained in section
:ref:`MsgPack_Keys_And_Values_Message`.
Command_name: ``mkdir``
~~~~~~~~~~~~~~~~~~~~~~~
This command will create a directory on the worker.
It will also create any intervening directories required.
``paths``
Value is a list of strings.
It specifies absolute paths of directories to create.
If command succeeded, worker will send ``rc`` value 0 as an ``update`` message ``args``
key-value pair.
Otherwise, worker sends ``update`` message with dictionary ``args`` key ``header`` with
information about the error that occurred and another ``update`` message with dictionary
``args`` key ``rc`` with the error number.
The basic structure of worker ``update`` message is explained in section
:ref:`MsgPack_Keys_And_Values_Message`.
Command_name ``rmdir``
~~~~~~~~~~~~~~~~~~~~~~
This command will remove directories or files on the worker.
``paths``
Value is a list of strings.
It specifies absolute paths of directories or files to remove.
``logEnviron``
Value is a bool and is optional.
If value is not specified, the default is ``True``.
If ``True``, worker sends to master an ``update`` message with process environment key-value
pairs at the beginning of a process.
``timeout``
Value is an integer and is optional.
If value is not specified, the default is 120s.
It represents how many seconds a worker should wait before killing a process when it gives no output.
``maxTime``
Value is an integer and is optional.
If value is not specified, the default is ``None``. It represents, how many seconds a worker
should wait before killing a process. Even if command is still running and giving the output,
``maxTime`` variable sets the maximum time the command is allowed to be performing. If
``maxTime`` is set to ``None``, command runs for as long as it needs unless ``timeout``
specifies otherwise.
If command succeeded, worker sends ``rc`` value 0 as an ``update`` message ``args`` key-value
pair. It can also send many ``update`` messages with key ``header``, ``stdout`` or ``stderr``
to inform about command execution. If command failed, worker changes the permissions of a
directory and tries the removal once again. If that does not help, worker sends ``rc`` value
with the error number.
The basic structure of worker ``update`` message is explained in section
:ref:`MsgPack_Keys_And_Values_Message`.
Command_name: ``cpdir``
~~~~~~~~~~~~~~~~~~~~~~~
This command copies a directory from one place in the worker to another.
``from_path``
Value is a string.
It specifies the absolute path to the source directory for the copy operation.
``to_path``
Value is a string.
It specifies the absolute path to the destination directory for the copy operation.
``logEnviron``
Value is a bool.
If ``True``, worker sends to master an ``update`` message with process environment key-value
pairs at the beginning of a process.
``timeout``
Value is an integer.
If value is not specified, the default is 120s.
It represents, how many seconds a worker should wait before killing a process if it gives no output.
``maxTime``
Value is an integer and is optional.
If value is not specified, the default is ``None``. It represents, how many seconds a worker
should wait before killing a process. Even if command is still running and giving the output,
``maxTime`` variable sets the maximum time the command is allowed to be performing. If
``maxTime`` is set to ``None``, command runs for as long as it needs unless ``timeout``
specifies otherwise.
If command succeeded, worker sends ``rc`` value 0 as an ``update`` message ``args`` key-value
pair. It can also send many ``update`` messages with key ``header``, ``stdout`` or ```stderr`
to inform about command execution. If command failed, it sends ``rc`` value with the error
number.
The basic structure of worker ``update`` message is explained in section
:ref:`MsgPack_Keys_And_Values_Message`.
Command_name: ``stat``
~~~~~~~~~~~~~~~~~~~~~~
This command returns status information about workers file or directory.
``path``
Value is a string.
It specifies the path of a file or directory to get the status of.
If command succeeded, status information is sent to the master in an ``update`` message, where
``args`` has a key ``stat`` with a value of a tuple of these 10 elements:
0 - File mode: file type and file mode bits (permissions) in Unix convention.
1 - Platform dependent, but if non-zero, uniquely identifies the file for a specific device.
2 - Unique ID of disc device where this file resides.
3 - Number of hard links.
4 - ID of the file owner.
5 - Group ID of the file owner.
6 - If the file is a regular file or a symbolic link, size of the file in bytes, otherwise unspecified.
Timestamps depend on the platform:
Unix time or the time of Windows creation, expressed in seconds.
7 - time of last access in seconds.
8 - time of last data modification in seconds.
9 - time of last status change in seconds.
If command succeeded, worker also sends ``rc`` value 0 as an ``update`` message ``args``
key-value pair.
Otherwise, worker sends ``update`` message with dictionary ``args`` key ``header`` with
information about the error that occurred and another ``update`` message with dictionary
``args`` key ``rc`` with the error number.
The basic structure of worker ``update`` message is explained in section
:ref:`MsgPack_Keys_And_Values_Message`.
Command_name: ``glob``
~~~~~~~~~~~~~~~~~~~~~~
Worker sends to the master a possibly-empty list of path names that match shell-style path
specification.
``path``
Value is a string.
It specifies a shell-style path pattern.
Path pattern can contain shell-style wildcards and must represent an absolute path.
If command succeeded, the result is sent to the master in an ``update`` message, where ``args``
has a key ``file`` with the value of that possibly-empty path list. This path list may contain
broken symlinks as in the shell. It is not specified whether path list is sorted.
Worker also sends ``rc`` value 0 as an ``update`` message ``args`` key-value pair.
Otherwise, worker sends ``update`` message with dictionary ``args`` key ``header`` with
information about the error that occurred and another ``update`` message with dictionary
``args`` key ``rc`` with the error number.
The basic structure of worker ``update`` message is explained in section
:ref:`MsgPack_Keys_And_Values_Message`.
Command_name: ``rmfile``
~~~~~~~~~~~~~~~~~~~~~~~~
This command removes the specified file.
``path``
Value is a string.
It specifies a path of a file to delete.
If command succeeded, worker sends ``rc`` value 0 as an ``update`` message ``args`` key-value pair.
Otherwise, worker sends ``update`` message with dictionary ``args`` key ``header`` with
information about the error that occurred and another ``update`` message with dictionary
``args`` key ``rc`` with the error number.
The basic structure of worker ``update`` message is explained in section
:ref:`MsgPack_Keys_And_Values_Message`.
.. _MsgPack_Keys_And_Values_Message:
Contents of the value corresponding to ``args`` key in the dictionary of ``update`` request message
---------------------------------------------------------------------------------------------------
The ``args`` key-value pair describes information that the request message sends to master. The
value is a list of lists. Each sub-list contains a name-value pair and represents a single update.
First element in a list represents the name of update (see below) and second element represents its
value. Commands may have their own update names so only common ones are described here.
``stdout``
Value is a standard output of a process as a string.
Some of the commands that master requests worker to start, may initiate processes which output
a result as a standard output and this result is saved in the value of ``stdout``.
The value satisfies the requirements described in a section below.
``rc``
Value is an integer.
It represents an exit code of a process.
0 if the process exit was successful.
Any other number represents a failure.
``failure_reason``
Value is a string and describes additional scenarios when a process failed.
The value of the ``failure_reason`` key can be one of the following:
- ``timeout`` if the command timed out due to time specified by the ``maxTime`` parameter being
exceeded.
- ``timeout_without_output`` if the command timed out due to time specified by the ``timeout``
parameter being exceeded.
- ``max_lines_failure`` if the command is killed due to the number of lines specified by the
``max_lines`` parameter being exceeded.
``header``
Value is a string of a header.
It represents additional information about how the command worked.
For example, information may include the command name and arguments, working directory and
environment or various errors or warnings of a process or other information that may be useful
for debugging.
The value satisfies the requirements described in a section below.
``files``
Value is a list of strings.
1) If the ``update`` message was a response to master request message ``start_command`` with
a key value pair ``command_name`` and ``glob``, then strings in this list represent path names
that matched pathname given by the master.
2) If the ``update`` message was a response to master request message ``start_command`` with a
key value pair ``command_name`` and ``listdir``, then strings in this list represent the names
of the entries in the directory given by path, which master sent as an argument.
``stderr``
Value is a standard error of a process as a string.
Some of the commands that master requests worker to start may initiate processes which can
output a result as a standard error and this result is saved in the value of ``stderr``.
The value satisfies the requirements described in a section below.
``log``
Value is a list where the first element represents the name of the log and the second element
is a list, representing the contents of the file.
The composition of this second element is described in the section below.
This message is used to transfer the contents of the file that master requested worker to read.
This file is identified by the name of the log.
The same value is sent by master as the key of dictionary represented by ``logfile`` key within
``args`` dictionary of ``StartCommand`` command.
``elapsed``
Value is an integer.
It represents how much time has passed between the start of a command and the completion in
seconds.
Requirements for content lists of ``stdout``, ``stderr``, ``header`` and ``log``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The lists that represents the contents of the output or a file consist of three elements.
First element is a string with the content, which must be processed using the following algorithm:
* Each value may contain one or more lines (characters with a terminating ``\n`` character).
Each line is not longer than internal ``maxsize`` value on worker side.
Longer lines are split into multiple lines where each except the last line contains exactly
``maxsize`` characters and the last line may contain less.
* The lines are run through an internal worker cleanup regex.
Second element is a list of indexes, representing the positions of newline characters in the string
of first tuple element.
Third element is a list of numbers, representing at what time each line was received as an output
while processing the command.
The number of elements in both lists is always the same.
|