action.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. ###############################################################################
  2. # #
  3. # L3q - Light, light, lightweight queue #
  4. # Copyright (C) 2023 Marcus Pedersén marcus.pedersen@slu.se #
  5. # #
  6. # This program is free software: you can redistribute it and/or modify #
  7. # it under the terms of the GNU General Public License as published by #
  8. # the Free Software Foundation, either version 3 of the License, or #
  9. # (at your option) any later version. #
  10. # #
  11. # This program is distributed in the hope that it will be useful, #
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of #
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
  14. # GNU General Public License for more details. #
  15. # #
  16. # You should have received a copy of the GNU General Public License #
  17. # along with this program. If not, see <http://www.gnu.org/licenses/>. #
  18. # #
  19. ###############################################################################
  20. '''
  21. Module contains action classes
  22. and functions for l3q,
  23. required by both daemon, node and client programs.
  24. Action classes are sent as json strings
  25. over https between different l3q programs.
  26. '''
  27. class Action():
  28. '''
  29. Base class for actions.
  30. Subclasses should specify
  31. needed required slots.
  32. '''
  33. __slots__ = ['validate']
  34. def __init__(self) -> None:
  35. self.validate: str = ""
  36. '''
  37. Client Action classes.
  38. To be sent as json
  39. to l3q darmon.
  40. '''
  41. class CAValidateKey(Action):
  42. '''
  43. Client action: Validate Key
  44. '''
  45. __slots__: list[str] = ['password', 'hostname']
  46. def __init__(self) -> None:
  47. self.password: str = ""
  48. self.hostname: str = ""
  49. class CAGetQueue(Action):
  50. '''
  51. Client action: Get Queue
  52. '''
  53. __slots__: list[str] = []
  54. def __init__(self) -> None:
  55. pass
  56. class CAGetHistory(Action):
  57. '''
  58. Client action: Get History
  59. '''
  60. __slots__: list[str] = []
  61. def __init__(self) -> None:
  62. pass
  63. class CAGetNodeStatus(Action):
  64. '''
  65. Client action: Get Node Status
  66. '''
  67. __slots__: list[str] = []
  68. def __init__(self) -> None:
  69. pass
  70. class CAGetJobInfo(Action):
  71. '''
  72. Client action: Get Job Info
  73. '''
  74. __slots__ = ['jobid']
  75. def __init__(self) -> None:
  76. self.jobid: int = 0
  77. class CAGetTaskInfo(Action):
  78. '''
  79. Client action: Get Task Info
  80. '''
  81. __slots__ = ['taskid']
  82. def __init__(self) -> None:
  83. self.taskid: int = 0
  84. class CAGetTaskList(Action):
  85. '''
  86. Client action: Get Task List
  87. '''
  88. __slots__ = ['jobid']
  89. def __init__(self) -> None:
  90. self.jobid: int = 0
  91. class CASetNodeOnline(Action):
  92. '''
  93. Client action: Set Node Online
  94. '''
  95. __slots__ = ['node_name']
  96. def __init__(self) -> None:
  97. self.node_name: str = ""
  98. class CASetNodeOffline(Action):
  99. '''
  100. Client action: Set Node Offline
  101. '''
  102. __slots__ = ['node_name']
  103. def __init__(self) -> None:
  104. self.node_name: str = ""
  105. class CAAddParallel(Action):
  106. '''
  107. Client action: Add Parallel Job
  108. '''
  109. __slots__ = ['user', 'name','tasks', 'nodes', 'cores', 'memory', 'depend']
  110. def __init__(self) -> None:
  111. self.user: str = ""
  112. self.name: str = ""
  113. self.tasks: list[str] = []
  114. self.nodes: int = 0
  115. self.cores: int = 0
  116. self.memory: int = 0
  117. self.depend: list[int]
  118. class CAAddSequence(Action):
  119. '''
  120. Client action: Add Sequence Job
  121. '''
  122. __slots__ = ['user', 'name','tasks', 'cores', 'memory', 'depend']
  123. def __init__(self) -> None:
  124. self.user: str = ""
  125. self.name: str = ""
  126. self.tasks: list[str] = []
  127. self.cores: int = 1
  128. self.memory: int = 0
  129. self.depend: list[int]
  130. class CACancelJob(Action):
  131. '''
  132. Client action: Cancel Job
  133. '''
  134. __slots__ = ['jobid', 'user']
  135. def __init__(self) -> None:
  136. self.jobid: int = 0
  137. self.user: str = ""