Job.js

  1. const Resource = require('./Resource');
  2. /** @namespace jobs */
  3. class Job extends Resource {
  4. constructor(httpClient) {
  5. super(httpClient);
  6. this.baseURL = '/jobs';
  7. this.operations = ['list', 'get', 'create', 'delete', 'terminate'];
  8. }
  9. /** List jobs<br>
  10. * see: {@link https://qarnot.com/documentation/api/#api-Jobs-List_Jobs}
  11. * @function
  12. * @name list
  13. * @memberof jobs
  14. * @example <caption>Usage</caption>
  15. * const jobs = await Qarnot.jobs.list();
  16. * console.log(jobs);
  17. * @example <caption>Output</caption>
  18. * [
  19. * {
  20. * "name": "my job",
  21. * "creationDate": "2014-12-24T15:10:54.8659210Z",
  22. * "lastModified": "2014-12-24T15:10:54.8659210Z",
  23. * "uuid": "52c10b2d-0687-41e1-985e-7279f6dd543a",
  24. * "state": 'Active',
  25. * "poolUuid": "6307bccd-a886-4b6d-8223-66c9024dd94c",
  26. * "useDependencies": true,
  27. * "maxWallTime": "1.03:16:50.5000000"
  28. * }
  29. * ]
  30. * @returns {Promise<Object[]>}
  31. */
  32. /** Get information of the specified job<br>
  33. * see: {@link https://qarnot.com/documentation/api/#api-Jobs-Job_Information}
  34. * @function
  35. * @name get
  36. * @memberof jobs
  37. * @param uuid {String} uuid of the job
  38. * @example <caption>Usage</caption>
  39. * const job = await Qarnot.jobs.get('52c10b2d-0687-41e1-985e-7279f6dd543a');
  40. * console.log(job);
  41. * @example <caption>Output</caption>
  42. * {
  43. * "name": "my job",
  44. * "creationDate": "2014-12-24T15:10:54.8659210Z",
  45. * "lastModified": "2014-12-24T15:10:54.8659210Z",
  46. * "uuid": "52c10b2d-0687-41e1-985e-7279f6dd543a",
  47. * "state": 'Active',
  48. * "poolUuid": "6307bccd-a886-4b6d-8223-66c9024dd94c",
  49. * "useDependencies": true,
  50. * "maxWallTime": "1.03:16:50.5000000"
  51. * }
  52. * @returns {Promise<Object>}
  53. */
  54. /** List tasks in the specified job<br>
  55. * see: {@link https://qarnot.com/documentation/api/#api-Jobs-List_job_s_Tasks}
  56. * @function
  57. * @name get
  58. * @memberof jobs
  59. * @param uuid {String} uuid of the job
  60. * @example <caption>Usage</caption>
  61. * const tasks = await Qarnot.jobs.getTasks('52c10b2d-0687-41e1-985e-7279f6dd543a');
  62. * console.log(tasks);
  63. * @example <caption>Output</caption>
  64. * [
  65. * {
  66. * "name": "my blend",
  67. * "profile": "blender",
  68. * "instanceCount": 4,
  69. * "snapshotWhitelist": "white.*",
  70. * "snapshotBlacklist": "black.*",
  71. * "resourceBuckets": [
  72. * "my-input-bucket"
  73. * ],
  74. * "resultBucket": "my-output-bucket",
  75. * "state": "Success",
  76. * "status": {
  77. * "downloadProgress": 100.0,
  78. * "executionProgress": 0.0,
  79. * "uploadProgress": 0.0,
  80. * "instanceCount": 6,
  81. * "downloadTime": "00:00:00",
  82. * "downloadTimeSec": 0.0,
  83. * "environmentTime": "00:00:00",
  84. * "environmentTimeSec": 0.0,
  85. * "executionTime": "00:00:00",
  86. * "executionTimeSec": 0,
  87. * "uploadTime": "00:00:00",
  88. * "uploadTimeSec" : 0.0,
  89. * "succeededRange": "",
  90. * "executedRange": "",
  91. * "failedRange": "",
  92. * "runningInstancesInfo": {
  93. * "perRunningInstanceInfo": [
  94. * {
  95. * "phase": "environment",
  96. * "instanceId": 2467,
  97. * "maxFrequencyGHz": 0.0,
  98. * "currentFrequencyGHz": 0.0,
  99. * "cpuUsage": 0.0,
  100. * "MaxMemoryMB": 0,
  101. * "CurrentMemoryMB": 0,
  102. * "networkInKbps": 0.0,
  103. * "networkOutKbps": 0.0,
  104. * "progress": 0.0,
  105. * "executionTimeSec": 0,
  106. * "executionTimeGHz": 0.0,
  107. * "cpuModel": "",
  108. * "activeForwards": [],
  109. * "memoryUsage": 0.0
  110. * }
  111. * ],
  112. * "timestamp": "0001-01-01T00:00:00",
  113. * "averageFrequencyGHz": 0.0,
  114. * "maxFrequencyGHz": 0.0,
  115. * "minFrequencyGHz": 0.0,
  116. * "averageMaxFrequencyGHz": 0.0,
  117. * "averageCpuUsage": 0.0,
  118. * "clusterPowerIndicator": 1.0,
  119. * "averageMemoryOccupation": 0.0,
  120. * "averageNetworkInKbps": 0.0,
  121. * "averageNetworkOutKbps": 0.0,
  122. * "totalNetworkInKbps": 0.0,
  123. * "totalNetworkOutKbps": 0.0
  124. * }
  125. * },
  126. * "snapshotInterval": 0,
  127. * "resultsCount":1,
  128. * "constants": [
  129. * {
  130. * "key": "BLEND_FILE",
  131. * "value": "final2.blend"
  132. * }
  133. * ],
  134. * "creationDate": "2014-12-24T15:10:54.8659210Z",
  135. * "uuid": "52c10b2d-0687-41e1-985e-7279f6dd543a"
  136. * }
  137. * ]
  138. * @returns {Promise<Object>}
  139. */
  140. getTasks(uuid) {
  141. return this.httpClient.executeHttp('GET', `${this.baseURL}/${uuid}/tasks`, null);
  142. }
  143. /** Create a new job<br>
  144. * see: {@link https://qarnot.com/documentation/api/#api-Jobs-Create_job}
  145. * @function
  146. * @name create
  147. * @memberof jobs
  148. * @example <caption>Usage</caption>
  149. * const job = await Qarnot.jobs.create({
  150. * "name": "my job",
  151. * "poolUuid": "6307bccd-a886-4b6d-8223-66c9024dd94c",
  152. * "useDependencies": true,
  153. * "maxWallTime": "1.03:16:50.5000000"
  154. * });
  155. * console.log(job)
  156. * @example <caption>Output</caption>
  157. * { uuid: 'bb43b1cb-c03f-4417-9210-a265de8995e9' }
  158. * @returns {Promise<Object>}
  159. */
  160. /** Delete a job<br>
  161. * see: {@link https://qarnot.com/documentation/api/#api-Jobs-Delete_Job}
  162. * @function
  163. * @name delete
  164. * @memberof jobs
  165. * @example <caption>Usage</caption>
  166. * await Qarnot.jobs.delete('bb43b1cb-c03f-4417-9210-a265de8995e9');
  167. * @returns {Promise}
  168. */
  169. /** Terminate a job<br>
  170. * see: {@link https://qarnot.com/documentation/api/#api-Jobs-Terminate_Job}
  171. * @function
  172. * @name terminate
  173. * @memberof jobs
  174. * @example <caption>Usage</caption>
  175. * await Qarnot.jobs.terminate('bb43b1cb-c03f-4417-9210-a265de8995e9');
  176. * @returns {Promise}
  177. */
  178. terminate(uuid) {
  179. return this.httpClient.executeHttp('POST', `${this.baseURL}/${uuid}/terminate`, null);
  180. }
  181. /** Get a paginate number of user's jobs list<br>
  182. * see: {@link https://qarnot.com/documentation/api/#api-Jobs-Paginate_Jobs_List}
  183. * @function
  184. * @name paginate
  185. * @memberof jobs
  186. * @example <caption>Usage</caption>
  187. * const pagination = await Qarnot.jobs.paginate();
  188. * console.log(pagination);
  189. * @example <caption>Output</caption>
  190. * [
  191. * {
  192. * data:
  193. * [
  194. * {
  195. * "Connection": null,
  196. * "Uuid": "8c97b929-cb3b-4b5e-b630-2a94a1c6b77a",
  197. * "Name": "job_0",
  198. * "Shortname": "shortname",
  199. * "PoolUuid": "00000000-0000-0000-0000-000000000000",
  200. * "State": "Completed",
  201. * "PreviousState": "Terminating",
  202. * "StateTransitionTime": "2020-07-07T16:17:49Z",
  203. * "PreviousStateTransitionTime": "2020-07-07T16:17:49Z",
  204. * "CreationDate": "2020-07-07T16:15:05Z",
  205. * "LastModified": "2020-07-07T16:17:49Z",
  206. * "UseDependencies": false,
  207. * "MaximumWallTime": "00:00:00",
  208. * "Pool": null
  209. * }
  210. * ],
  211. * count: 1,
  212. * isTruncated: true,
  213. * nextToken: '5ed67ba6d1f1b90d3aff497b'
  214. * }
  215. * ]
  216. * @returns {Promise<Object[]>}
  217. */
  218. paginate(maximumResults = 20, nextToken = null, filter = null, orderBy = null, orderType = null) {
  219. const pageBody = {
  220. Token: nextToken,
  221. Filter: filter,
  222. MaximumResults: maximumResults,
  223. OrderBy: orderBy,
  224. OrderType: orderType,
  225. };
  226. return this.httpClient.executeHttp('POST', `${this.baseURL}/paginate`, pageBody);
  227. }
  228. }
  229. module.exports = Job;