PageRenderTime 59ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/contribs/phpext/slurm_php/slurm_php.c

https://github.com/cfenoy/slurm
C | 902 lines | 630 code | 151 blank | 121 comment | 132 complexity | 4d91c5a7bac93e6842a51990e429136e MD5 | raw file
Possible License(s): GPL-2.0, AGPL-1.0
  1. /*****************************************************************************\
  2. * slurm_php.c - php interface to slurm.
  3. *
  4. *****************************************************************************
  5. * Copyright (C) 2011 - Trinity Centre for High Performance Computing
  6. * Copyright (C) 2011 - Trinity College Dublin
  7. * Written By : Vermeulen Peter <HoWest><Belgium>
  8. *
  9. * This file is part of php-slurm, a resource management program.
  10. * Please also read the included file: DISCLAIMER.
  11. *
  12. * php-slurm is free software; you can redistribute it and/or modify it under
  13. * the terms of the GNU General Public License as published by the Free
  14. * Software Foundation; either version 2 of the License, or (at your option)
  15. * any later version.
  16. *
  17. * In addition, as a special exception, the copyright holders give permission
  18. * to link the code of portions of this program with the OpenSSL library under
  19. * certain conditions as described in each individual source file, and
  20. * distribute linked combinations including the two. You must obey the GNU
  21. * General Public License in all respects for all of the code used other than
  22. * OpenSSL. If you modify file(s) with this exception, you may extend this
  23. * exception to your version of the file(s), but you are not obligated to do
  24. * so. If you do not wish to do so, delete this exception statement from your
  25. * version. If you delete this exception statement from all source files in
  26. * the program, then also delete it here.
  27. *
  28. * php-slurm is distributed in the hope that it will be useful, but WITHOUT ANY
  29. * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  30. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  31. * details.
  32. *
  33. * You should have received a copy of the GNU General Public License along
  34. * with php-slurm; if not, write to the Free Software Foundation, Inc.,
  35. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  36. \*****************************************************************************/
  37. /*****************************************************************************\
  38. *
  39. * Documentation for each function can be found in the slurm_php.h file
  40. *
  41. \*****************************************************************************/
  42. #ifdef HAVE_CONFIG_H
  43. #include "config.h"
  44. #endif
  45. #include "slurm_php.h"
  46. static function_entry slurm_functions[] = {
  47. PHP_FE(slurm_ping, NULL)
  48. PHP_FE(slurm_slurmd_status, NULL)
  49. PHP_FE(slurm_print_partition_names, NULL)
  50. PHP_FE(slurm_get_specific_partition_info, NULL)
  51. PHP_FE(slurm_get_partition_node_names, NULL)
  52. PHP_FE(slurm_version, NULL)
  53. PHP_FE(slurm_get_node_names, NULL)
  54. PHP_FE(slurm_get_node_elements, NULL)
  55. PHP_FE(slurm_get_node_element_by_name, NULL)
  56. PHP_FE(slurm_get_node_state_by_name, NULL)
  57. PHP_FE(slurm_get_control_configuration_keys, NULL)
  58. PHP_FE(slurm_get_control_configuration_values, NULL)
  59. PHP_FE(slurm_load_job_information, NULL)
  60. PHP_FE(slurm_load_partition_jobs, NULL)
  61. PHP_FE(slurm_get_node_states, NULL)
  62. PHP_FE(slurm_hostlist_to_array, NULL)
  63. PHP_FE(slurm_array_to_hostlist, NULL) {
  64. NULL, NULL, NULL
  65. }
  66. };
  67. zend_module_entry slurm_php_module_entry = {
  68. #if ZEND_MODULE_API_NO >= 20010901
  69. STANDARD_MODULE_HEADER,
  70. #endif
  71. SLURM_PHP_EXTNAME,
  72. slurm_functions,
  73. NULL,
  74. NULL,
  75. NULL,
  76. NULL,
  77. NULL,
  78. #if ZEND_MODULE_API_NO >= 20010901
  79. SLURM_PHP_VERSION,
  80. #endif
  81. STANDARD_MODULE_PROPERTIES
  82. };
  83. #ifdef COMPILE_DL_SLURM_PHP
  84. ZEND_GET_MODULE(slurm_php)
  85. #endif
  86. /*****************************************************************************\
  87. * HELPER FUNCTION PROTOTYPES
  88. \*****************************************************************************/
  89. /*
  90. * _parse_node_pointer - Parse a node pointer's contents into an
  91. * assocative zval array where the key is descriptive to the
  92. * value
  93. *
  94. * IN sub_arr - array to store the contents of the node pointer
  95. * IN node_arr - node pointer that needs parsing
  96. */
  97. static void _parse_node_pointer(zval *sub_arr, node_info_t *node_arr);
  98. /*
  99. * _parse_assoc_array - Parse a character array where the elements are
  100. * key-value pairs separated by delimiters into an associative
  101. * array
  102. *
  103. * IN char_arr - character array that needs parsing
  104. * IN delims - character array that contains the delimeters used in parsing
  105. * IN result_arr - associative array used to store the key_value pairs in
  106. */
  107. static void _parse_assoc_array(char *char_arr, char *delims, zval *result_arr);
  108. /*
  109. * _parse_array - Parse a character array where the elements are values
  110. * separated by delimiters into a numerically indexed array
  111. *
  112. * IN char_arr - character array that needs parsing
  113. * IN delims - character array that contains the delimeters used in parsing
  114. * IN result_arr - numerically indexed array used to store the values in
  115. */
  116. static void _parse_array(char *char_arr, char *delims, zval *rslt_arr);
  117. /*
  118. * _zend_add_valid_assoc_string - checks a character array to see if
  119. * it's NULL or not, if so an associative null is added, if not
  120. * an associative string is added.
  121. *
  122. * IN rstl_arr - array to store the associative key_value pairs in
  123. * IN key - character array used as the associative key
  124. * IN val - character array to be validated and added as value if valid
  125. */
  126. static void _zend_add_valid_assoc_string(zval *rstl_arr, char *key, char *val);
  127. /*
  128. * _zend_add_valid_assoc_time_string - checks a unix timestamp to see if it's
  129. * 0 or not, if so an associative null is added, if not a formatted string
  130. * is added.
  131. *
  132. * IN rstl_arr - array to store the associative key_value pairs in
  133. * IN key - character array used as the associative key
  134. * IN val - time_t unix timestamp to be validated and added if valid
  135. * NOTE : If you'd like to change the format in which the valid strings are
  136. * returned, you can change the TIME_FORMAT_STRING macro to the needed format
  137. */
  138. static void _zend_add_valid_assoc_time_string(
  139. zval *rstl_arr, char *key, time_t *val);
  140. /*****************************************************************************\
  141. * TODO
  142. *****************************************************************************
  143. * [ADJUSTING EXISTING FUNCTIONS]
  144. * - _parse_node_pointer
  145. * dynamic_plugin_data_t is currently not returned
  146. * [EXTRA FUNCTIONS]
  147. * - Functions that filter jobs on the nodes they are running on
  148. * - Scheduling
  149. * - ...
  150. \*****************************************************************************/
  151. /*****************************************************************************\
  152. * HELPER FUNCTIONS
  153. \*****************************************************************************/
  154. static void _parse_node_pointer(zval *sub_arr, node_info_t *node_arr)
  155. {
  156. zval *sub_arr_2 = NULL;
  157. _zend_add_valid_assoc_string(sub_arr, "Name", node_arr->name);
  158. _zend_add_valid_assoc_string(sub_arr, "Arch.", node_arr->arch);
  159. _zend_add_valid_assoc_time_string(sub_arr, "Boot Time",
  160. &node_arr->boot_time);
  161. add_assoc_long(sub_arr, "#CPU'S", node_arr->cpus);
  162. add_assoc_long(sub_arr, "#Cores/CPU", node_arr->cores);
  163. if (node_arr->features == NULL) {
  164. add_assoc_null(sub_arr, "Features");
  165. } else {
  166. ALLOC_INIT_ZVAL(sub_arr_2);
  167. array_init(sub_arr_2);
  168. _parse_array(node_arr->features, ",", sub_arr_2);
  169. add_assoc_zval(sub_arr, "Features", sub_arr_2);
  170. }
  171. _zend_add_valid_assoc_string(sub_arr, "GRES", node_arr->gres);
  172. add_assoc_long(sub_arr, "State", node_arr->node_state);
  173. _zend_add_valid_assoc_string(sub_arr, "OS", node_arr->os);
  174. add_assoc_long(sub_arr, "Real Mem", node_arr->real_memory);
  175. if (node_arr->reason!=NULL) {
  176. _zend_add_valid_assoc_string(sub_arr, "Reason",
  177. node_arr->reason);
  178. _zend_add_valid_assoc_time_string(sub_arr,"Reason Timestamp",
  179. &node_arr->reason_time);
  180. add_assoc_long(sub_arr, "Reason User Id",
  181. node_arr->reason_uid);
  182. } else {
  183. add_assoc_null(sub_arr, "Reason");
  184. add_assoc_null(sub_arr, "Reason Timestamp");
  185. add_assoc_null(sub_arr, "Reason User Id");
  186. }
  187. _zend_add_valid_assoc_time_string(sub_arr, "Slurmd Startup Time",
  188. &node_arr->slurmd_start_time);
  189. add_assoc_long(sub_arr, "#Sockets/Node", node_arr->sockets);
  190. add_assoc_long(sub_arr, "#Threads/Core", node_arr->threads);
  191. add_assoc_long(sub_arr, "TmpDisk", node_arr->tmp_disk);
  192. add_assoc_long(sub_arr, "Weight", node_arr->weight);
  193. }
  194. static void _parse_assoc_array(char *char_arr, char *delims, zval *result_arr)
  195. {
  196. char *rslt = NULL;
  197. char *tmp;
  198. int i = 0;
  199. rslt = strtok(char_arr, delims);
  200. while (rslt != NULL) {
  201. if (i == 0) {
  202. tmp = rslt;
  203. } else if (i == 1) {
  204. if (strcmp(rslt,"(null)")==0) {
  205. add_assoc_null(result_arr, tmp);
  206. } else {
  207. _zend_add_valid_assoc_string(result_arr,
  208. tmp, rslt);
  209. }
  210. }
  211. i++;
  212. if (i == 2) {
  213. i = 0;
  214. }
  215. rslt = strtok(NULL, delims);
  216. }
  217. }
  218. static void _parse_array(char *char_arr, char *delims, zval *rslt_arr)
  219. {
  220. char *rslt = NULL;
  221. char *tmp = NULL;
  222. rslt = strtok(char_arr, delims);
  223. while (rslt != NULL) {
  224. if (strcmp(rslt, "(null)")==0) {
  225. add_next_index_null(rslt_arr);
  226. } else {
  227. tmp = slurm_xstrdup(rslt);
  228. add_next_index_string(rslt_arr, tmp, 1);
  229. xfree(tmp);
  230. }
  231. rslt = strtok(NULL, delims);
  232. }
  233. }
  234. static void _zend_add_valid_assoc_string(zval *rstl_arr, char *key, char *val)
  235. {
  236. if (!val)
  237. add_assoc_null(rstl_arr, key);
  238. else
  239. add_assoc_string(rstl_arr, key, val, 1);
  240. }
  241. static void _zend_add_valid_assoc_time_string(
  242. zval *rstl_arr, char *key, time_t *val)
  243. {
  244. char buf[80];
  245. struct tm *timeinfo;
  246. if (val==0) {
  247. add_assoc_null(rstl_arr, key);
  248. } else {
  249. timeinfo = localtime(val);
  250. strftime(buf, 80, TIME_FORMAT_STRING, timeinfo);
  251. add_assoc_string(rstl_arr, key, buf, 1);
  252. }
  253. }
  254. /*****************************************************************************\
  255. * SLURM STATUS FUNCTIONS
  256. \*****************************************************************************/
  257. PHP_FUNCTION(slurm_ping)
  258. {
  259. int err = SLURM_SUCCESS;
  260. array_init(return_value);
  261. err = slurm_ping(1);
  262. add_assoc_long(return_value,"Prim. Controller",err);
  263. err = slurm_ping(2);
  264. add_assoc_long(return_value,"Sec. Controller",err);
  265. }
  266. PHP_FUNCTION(slurm_slurmd_status)
  267. {
  268. int err = SLURM_SUCCESS;
  269. slurmd_status_t *status_ptr = NULL;
  270. err = slurm_load_slurmd_status(&status_ptr);
  271. if (err) {
  272. RETURN_LONG(-2);
  273. }
  274. array_init(return_value);
  275. _zend_add_valid_assoc_time_string(return_value,"Booted_at",
  276. &status_ptr->booted);
  277. _zend_add_valid_assoc_time_string(return_value,"Last_Msg",
  278. &status_ptr->last_slurmctld_msg);
  279. add_assoc_long(return_value,"Logging_Level", status_ptr->slurmd_debug);
  280. add_assoc_long(return_value,"Actual_CPU's", status_ptr->actual_cpus);
  281. add_assoc_long(return_value,"Actual_Sockets",
  282. status_ptr->actual_sockets);
  283. add_assoc_long(return_value,"Actual_Cores",status_ptr->actual_cores);
  284. add_assoc_long(return_value,"Actual_Threads",
  285. status_ptr->actual_threads);
  286. add_assoc_long(return_value,"Actual_Real_Mem",
  287. status_ptr->actual_real_mem);
  288. add_assoc_long(return_value,"Actual_Tmp_Disk",
  289. status_ptr->actual_tmp_disk);
  290. add_assoc_long(return_value,"PID",status_ptr->pid);
  291. _zend_add_valid_assoc_string(return_value, "Hostname",
  292. status_ptr->hostname);
  293. _zend_add_valid_assoc_string(return_value, "Slurm Logfile",
  294. status_ptr->slurmd_logfile);
  295. _zend_add_valid_assoc_string(return_value, "Step List",
  296. status_ptr->step_list);
  297. _zend_add_valid_assoc_string(return_value, "Version",
  298. status_ptr->version);
  299. if (status_ptr != NULL) {
  300. slurm_free_slurmd_status(status_ptr);
  301. }
  302. }
  303. PHP_FUNCTION(slurm_version)
  304. {
  305. long option = -1;
  306. if (zend_parse_parameters(ZEND_NUM_ARGS()TSRMLS_CC,
  307. "l", &option) == FAILURE) {
  308. RETURN_LONG(-3);
  309. }
  310. switch (option) {
  311. case 0:
  312. RETURN_LONG(SLURM_VERSION_MAJOR(SLURM_VERSION_NUMBER));
  313. break;
  314. case 1:
  315. RETURN_LONG(SLURM_VERSION_MINOR(SLURM_VERSION_NUMBER));
  316. break;
  317. case 2:
  318. RETURN_LONG(SLURM_VERSION_MICRO(SLURM_VERSION_NUMBER));
  319. break;
  320. default:
  321. array_init(return_value);
  322. add_next_index_long(return_value,
  323. SLURM_VERSION_MAJOR(SLURM_VERSION_NUMBER));
  324. add_next_index_long(return_value,
  325. SLURM_VERSION_MINOR(SLURM_VERSION_NUMBER));
  326. add_next_index_long(return_value,
  327. SLURM_VERSION_MICRO(SLURM_VERSION_NUMBER));
  328. break;
  329. }
  330. }
  331. /*****************************************************************************\
  332. * SLURM PHP HOSTLIST FUNCTIONS
  333. \*****************************************************************************/
  334. PHP_FUNCTION(slurm_hostlist_to_array)
  335. {
  336. long lngth = 0;
  337. char *host_list = NULL;
  338. hostlist_t hl = NULL;
  339. int hl_length = 0;
  340. int i=0;
  341. if (zend_parse_parameters(ZEND_NUM_ARGS()TSRMLS_CC, "s|d",
  342. &host_list, &lngth) == FAILURE) {
  343. RETURN_LONG(-3);
  344. }
  345. if ((host_list == NULL) || !strcmp(host_list, "")) {
  346. RETURN_LONG(-3);
  347. }
  348. hl = slurm_hostlist_create(host_list);
  349. hl_length = slurm_hostlist_count(hl);
  350. if (hl_length==0) {
  351. RETURN_LONG(-2);
  352. }
  353. array_init(return_value);
  354. for (i=0; i<hl_length; i++) {
  355. char *name = slurm_hostlist_shift(hl);
  356. add_next_index_string(return_value, name, 1);
  357. free(name);
  358. }
  359. }
  360. PHP_FUNCTION(slurm_array_to_hostlist)
  361. {
  362. zval *node_arr = NULL, **data;
  363. hostlist_t hl = NULL;
  364. HashTable *arr_hash;
  365. HashPosition pointer;
  366. int arr_length = 0;
  367. char *buf;
  368. if (zend_parse_parameters(ZEND_NUM_ARGS()TSRMLS_CC, "a",
  369. &node_arr) == FAILURE) {
  370. RETURN_LONG(-3);
  371. }
  372. if (node_arr == NULL) {
  373. RETURN_LONG(-3);
  374. }
  375. arr_hash = Z_ARRVAL_P(node_arr);
  376. arr_length = zend_hash_num_elements(arr_hash);
  377. if (arr_length==0) {
  378. RETURN_LONG(-2);
  379. }
  380. hl = slurm_hostlist_create(NULL);
  381. for (zend_hash_internal_pointer_reset_ex(arr_hash, &pointer);
  382. zend_hash_get_current_data_ex(arr_hash, (void**) &data,
  383. &pointer) == SUCCESS;
  384. zend_hash_move_forward_ex(arr_hash, &pointer)) {
  385. if (Z_TYPE_PP(data) == IS_STRING) {
  386. slurm_hostlist_push_host(hl,Z_STRVAL_PP(data));
  387. }
  388. }
  389. array_init(return_value);
  390. buf = slurm_hostlist_ranged_string_xmalloc(hl);
  391. _zend_add_valid_assoc_string(return_value, "HOSTLIST", buf);
  392. xfree(buf);
  393. }
  394. /*****************************************************************************\
  395. * SLURM PARTITION READ FUNCTIONS
  396. \*****************************************************************************/
  397. PHP_FUNCTION(slurm_print_partition_names)
  398. {
  399. int err = SLURM_SUCCESS;
  400. int i;
  401. partition_info_msg_t *prt_ptr = NULL;
  402. err = slurm_load_partitions((time_t) NULL, &prt_ptr, 0);
  403. if (err) {
  404. RETURN_LONG(-2);
  405. }
  406. array_init(return_value);
  407. for (i = 0; i < prt_ptr->record_count; i++) {
  408. add_next_index_string(return_value,
  409. prt_ptr->partition_array[i].name, 1);
  410. }
  411. slurm_free_partition_info_msg(prt_ptr);
  412. if (i == 0) {
  413. RETURN_LONG(-1);
  414. }
  415. }
  416. PHP_FUNCTION(slurm_get_specific_partition_info)
  417. {
  418. long lngth = 0;
  419. int err = SLURM_SUCCESS;
  420. partition_info_msg_t *prt_ptr = NULL;
  421. partition_info_t *prt_data = NULL;
  422. char *name = NULL;
  423. char *tmp = NULL;
  424. int i = 0;
  425. int y = 0;
  426. if (zend_parse_parameters(ZEND_NUM_ARGS()TSRMLS_CC, "s|d", &name,
  427. &lngth) == FAILURE) {
  428. RETURN_LONG(-3);
  429. }
  430. if ((name == NULL) || !strcmp(name, "")) {
  431. RETURN_LONG(-3);
  432. }
  433. err = slurm_load_partitions((time_t) NULL, &prt_ptr, 0);
  434. if (err) {
  435. RETURN_LONG(-2);
  436. }
  437. if (prt_ptr->record_count != 0) {
  438. for (i = 0; i < prt_ptr->record_count; i++) {
  439. if (strcmp(prt_ptr->partition_array->name, name) == 0) {
  440. prt_data = &prt_ptr->partition_array[i];
  441. tmp = slurm_sprint_partition_info(prt_data, 1);
  442. array_init(return_value);
  443. _parse_assoc_array(tmp, "= ", return_value);
  444. y++;
  445. break;
  446. }
  447. }
  448. }
  449. slurm_free_partition_info_msg(prt_ptr);
  450. if (y == 0) {
  451. RETURN_LONG(-1);
  452. }
  453. }
  454. PHP_FUNCTION(slurm_get_partition_node_names)
  455. {
  456. char *prt_name = NULL;
  457. long lngth = 0;
  458. int err = SLURM_SUCCESS;
  459. partition_info_msg_t *prt_ptr = NULL;
  460. partition_info_t *prt_data = NULL;
  461. int i = 0;
  462. int y = 0;
  463. if (zend_parse_parameters(ZEND_NUM_ARGS()TSRMLS_CC, "s|d", &prt_name,
  464. &lngth) == FAILURE) {
  465. RETURN_LONG(-3);
  466. }
  467. if ((prt_name == NULL) || (strcmp(prt_name,"")==0)) {
  468. RETURN_LONG(-3);
  469. }
  470. err = slurm_load_partitions((time_t) NULL, &prt_ptr, 0);
  471. if (err)
  472. RETURN_LONG(-2);
  473. if (prt_ptr->record_count != 0) {
  474. for (i = 0; i < prt_ptr->record_count; i++) {
  475. if (!strcmp(prt_ptr->partition_array->name, prt_name)) {
  476. prt_data = &prt_ptr->partition_array[i];
  477. array_init(return_value);
  478. add_next_index_string(
  479. return_value, prt_data->nodes, 1);
  480. y++;
  481. break;
  482. }
  483. }
  484. }
  485. slurm_free_partition_info_msg(prt_ptr);
  486. if (y == 0)
  487. RETURN_LONG(-1);
  488. }
  489. /*****************************************************************************\
  490. * SLURM NODE CONFIGURATION READ FUNCTIONS
  491. \*****************************************************************************/
  492. PHP_FUNCTION(slurm_get_node_names)
  493. {
  494. int err = SLURM_SUCCESS;
  495. int i = 0;
  496. node_info_msg_t *node_ptr = NULL;
  497. err = slurm_load_node((time_t) NULL, &node_ptr, 0);
  498. if (err) {
  499. RETURN_LONG(-2);
  500. }
  501. if (node_ptr->record_count > 0) {
  502. array_init(return_value);
  503. for (i = 0; i < node_ptr->record_count; i++) {
  504. add_next_index_string(
  505. return_value, node_ptr->node_array[i].name, 1);
  506. }
  507. }
  508. slurm_free_node_info_msg(node_ptr);
  509. if(i==0) {
  510. RETURN_LONG(-1);
  511. }
  512. }
  513. PHP_FUNCTION(slurm_get_node_elements)
  514. {
  515. int err = SLURM_SUCCESS;
  516. int i = 0;
  517. node_info_msg_t *node_ptr;
  518. zval *sub_arr = NULL;
  519. err = slurm_load_node((time_t) NULL, &node_ptr, 0);
  520. if (err) {
  521. RETURN_LONG(-2);
  522. }
  523. if (node_ptr->record_count > 0) {
  524. array_init(return_value);
  525. for (i = 0; i < node_ptr->record_count; i++) {
  526. ALLOC_INIT_ZVAL(sub_arr);
  527. array_init(sub_arr);
  528. _parse_node_pointer(sub_arr, &node_ptr->node_array[i]);
  529. add_assoc_zval(return_value,
  530. node_ptr->node_array[i].name,
  531. sub_arr);
  532. }
  533. }
  534. slurm_free_node_info_msg(node_ptr);
  535. if(i==0) {
  536. RETURN_LONG(-1);
  537. }
  538. }
  539. PHP_FUNCTION(slurm_get_node_element_by_name)
  540. {
  541. int err = SLURM_SUCCESS;
  542. int i = 0,y = 0;
  543. node_info_msg_t *node_ptr;
  544. char *node_name = NULL;
  545. long lngth;
  546. zval *sub_arr = NULL;
  547. if (zend_parse_parameters(ZEND_NUM_ARGS()TSRMLS_CC, "s|d", &node_name,
  548. &lngth) == FAILURE) {
  549. RETURN_LONG(-3);
  550. }
  551. if ((node_name == NULL) || (strcmp(node_name,"")==0)) {
  552. RETURN_LONG(-3);
  553. }
  554. err = slurm_load_node((time_t) NULL, &node_ptr, 0);
  555. if (err) {
  556. RETURN_LONG(-2);
  557. }
  558. array_init(return_value);
  559. for (i = 0; i < node_ptr->record_count; i++) {
  560. if (strcmp(node_ptr->node_array->name, node_name) == 0) {
  561. y++;
  562. ALLOC_INIT_ZVAL(sub_arr);
  563. array_init(sub_arr);
  564. _parse_node_pointer(sub_arr, &node_ptr->node_array[i]);
  565. add_assoc_zval(return_value, node_name,
  566. sub_arr);
  567. break;
  568. }
  569. }
  570. slurm_free_node_info_msg(node_ptr);
  571. if (y == 0) {
  572. RETURN_LONG(-1);
  573. }
  574. }
  575. PHP_FUNCTION(slurm_get_node_state_by_name)
  576. {
  577. int err = SLURM_SUCCESS;
  578. int i = 0,y = 0;
  579. node_info_msg_t *node_ptr;
  580. char *node_name = NULL;
  581. long lngth;
  582. if (zend_parse_parameters(ZEND_NUM_ARGS()TSRMLS_CC, "s|d", &node_name,
  583. &lngth) == FAILURE) {
  584. RETURN_LONG(-3);
  585. }
  586. if ((node_name == NULL) || (strcmp(node_name,"")==0)) {
  587. RETURN_LONG(-3);
  588. }
  589. err = slurm_load_node((time_t) NULL, &node_ptr, 0);
  590. if (err) {
  591. RETURN_LONG(-2);
  592. }
  593. for (i = 0; i < node_ptr->record_count; i++) {
  594. if (strcmp(node_ptr->node_array->name, node_name) == 0) {
  595. y++;
  596. RETURN_LONG(node_ptr->node_array[i].node_state);
  597. break;
  598. }
  599. }
  600. slurm_free_node_info_msg(node_ptr);
  601. if (i == 0) {
  602. RETURN_LONG(-1);
  603. }
  604. if (y==0) {
  605. RETURN_LONG(-1);
  606. }
  607. }
  608. PHP_FUNCTION(slurm_get_node_states)
  609. {
  610. int err = SLURM_SUCCESS;
  611. int i = 0;
  612. node_info_msg_t *node_ptr;
  613. err = slurm_load_node((time_t) NULL, &node_ptr, 0);
  614. if (err) {
  615. RETURN_LONG(-2);
  616. }
  617. array_init(return_value);
  618. for (i = 0; i < node_ptr->record_count; i++) {
  619. add_next_index_long(return_value,
  620. node_ptr->node_array[i].node_state);
  621. }
  622. slurm_free_node_info_msg(node_ptr);
  623. if (i == 0) {
  624. RETURN_LONG(-1);
  625. }
  626. }
  627. /*****************************************************************************\
  628. * SLURM CONFIGURATION READ FUNCTIONS
  629. \*****************************************************************************/
  630. PHP_FUNCTION(slurm_get_control_configuration_keys)
  631. {
  632. int err = SLURM_SUCCESS;
  633. slurm_ctl_conf_t *ctrl_conf_ptr;
  634. List lst;
  635. ListIterator iter = NULL;
  636. key_pair_t *k_p;
  637. err = slurm_load_ctl_conf((time_t) NULL, &ctrl_conf_ptr);
  638. if (err) {
  639. RETURN_LONG(-2);
  640. }
  641. lst = slurm_ctl_conf_2_key_pairs(ctrl_conf_ptr);
  642. if (!lst) {
  643. RETURN_LONG(-1);
  644. }
  645. iter = slurm_list_iterator_create(lst);
  646. array_init(return_value);
  647. while ((k_p = slurm_list_next(iter))) {
  648. add_next_index_string(return_value, k_p->name, 1);
  649. }
  650. slurm_free_ctl_conf(ctrl_conf_ptr);
  651. }
  652. PHP_FUNCTION(slurm_get_control_configuration_values)
  653. {
  654. int err = SLURM_SUCCESS;
  655. slurm_ctl_conf_t *ctrl_conf_ptr;
  656. List lst;
  657. ListIterator iter = NULL;
  658. key_pair_t *k_p;
  659. err = slurm_load_ctl_conf((time_t) NULL, &ctrl_conf_ptr);
  660. if (err) {
  661. RETURN_LONG(-2);
  662. }
  663. lst = slurm_ctl_conf_2_key_pairs(ctrl_conf_ptr);
  664. if (!lst) {
  665. RETURN_LONG(-1);
  666. }
  667. iter = slurm_list_iterator_create(lst);
  668. array_init(return_value);
  669. while ((k_p = slurm_list_next(iter))) {
  670. if (k_p->value==NULL) {
  671. add_next_index_null(return_value);
  672. } else {
  673. add_next_index_string(return_value, k_p->value, 1);
  674. }
  675. }
  676. slurm_free_ctl_conf(ctrl_conf_ptr);
  677. }
  678. /*****************************************************************************\
  679. * SLURM JOB READ FUNCTIONS
  680. \*****************************************************************************/
  681. PHP_FUNCTION(slurm_load_job_information)
  682. {
  683. int err = SLURM_SUCCESS;
  684. int i = 0;
  685. job_info_msg_t *job_ptr;
  686. zval *sub_arr = NULL;
  687. char *tmp;
  688. err = slurm_load_jobs((time_t) NULL, &job_ptr, 0);
  689. if (err) {
  690. RETURN_LONG(-2);
  691. }
  692. array_init(return_value);
  693. for (i = 0; i < job_ptr->record_count; i++) {
  694. ALLOC_INIT_ZVAL(sub_arr);
  695. array_init(sub_arr);
  696. _parse_assoc_array(slurm_sprint_job_info(
  697. &job_ptr->job_array[i], 1),
  698. "= ", sub_arr);
  699. tmp = slurm_xstrdup_printf("%u", job_ptr->job_array[i].job_id);
  700. add_assoc_zval(return_value, tmp, sub_arr);
  701. xfree(tmp);
  702. }
  703. slurm_free_job_info_msg(job_ptr);
  704. if (i == 0) {
  705. RETURN_LONG(-1);
  706. }
  707. }
  708. PHP_FUNCTION(slurm_load_partition_jobs)
  709. {
  710. int err = SLURM_SUCCESS;
  711. int i = 0;
  712. job_info_msg_t *job_ptr;
  713. zval *sub_arr = NULL;
  714. char *tmp;
  715. char *pname = NULL;
  716. long lngth;
  717. long checker = 0;
  718. if (zend_parse_parameters(ZEND_NUM_ARGS()TSRMLS_CC, "s|d", &pname,
  719. &lngth) == FAILURE) {
  720. RETURN_LONG(-3);
  721. }
  722. if ((pname == NULL) || !strcmp(pname,"")) {
  723. RETURN_LONG(-3);
  724. }
  725. err = slurm_load_jobs((time_t) NULL, &job_ptr, 0);
  726. if (err) {
  727. RETURN_LONG(-2);
  728. }
  729. array_init(return_value);
  730. for (i = 0; i < job_ptr->record_count; i++) {
  731. if (!strcmp(job_ptr->job_array->partition, pname)) {
  732. checker++;
  733. ALLOC_INIT_ZVAL(sub_arr);
  734. array_init(sub_arr);
  735. _parse_assoc_array(slurm_sprint_job_info(
  736. &job_ptr->job_array[i], 1),
  737. "= ", sub_arr);
  738. tmp = slurm_xstrdup_printf(
  739. "%u", job_ptr->job_array[i].job_id);
  740. add_assoc_zval(return_value, tmp, sub_arr);
  741. xfree(tmp);
  742. }
  743. }
  744. slurm_free_job_info_msg(job_ptr);
  745. if (i == 0) {
  746. RETURN_LONG(-1);
  747. }
  748. if (checker==0) {
  749. RETURN_LONG(-1);
  750. }
  751. }