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
|
/*___INFO__MARK_BEGIN__*/
/*************************************************************************
*
* The Contents of this file are made available subject to the terms of
* the Sun Industry Standards Source License Version 1.2
*
* Sun Microsystems Inc., March, 2001
*
*
* Sun Industry Standards Source License Version 1.2
* =================================================
* The contents of this file are subject to the Sun Industry Standards
* Source License Version 1.2 (the "License"); You may not use this file
* except in compliance with the License. You may obtain a copy of the
* License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html
*
* Software provided under this License is provided on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
* See the License for the specific provisions governing your rights and
* obligations concerning the Software.
*
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
*
* Copyright: 2001 by Sun Microsystems, Inc.
*
* All Rights Reserved.
*
************************************************************************/
/*___INFO__MARK_END__*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include <sys/types.h>
#include <unistd.h>
#include <limits.h>
#include <math.h>
#ifndef NO_SGE_COMPILE_DEBUG
# define NO_SGE_COMPILE_DEBUG
#endif
#include "uti/sge_rmon.h"
#include "uti/sge_prog.h"
#include "uti/sge_time.h"
#include "comm/commlib.h"
#include "sgeobj/sge_schedd_conf.h"
#include "sgeobj/sge_usage.h"
#include "sgeobj/sge_userprj.h"
#include "sgeobj/sge_sharetree.h"
#include "sgeobj/sge_job.h"
#include "sgeobj/sge_ja_task.h"
#include "sge_orders.h"
#include "sge_job_schedd.h"
#include "sgeee.h"
#include "sge_support.h"
#include "valid_queue_user.h"
#include "sge_eejob_SGEJ_L.h"
static const long sge_usage_interval = SGE_USAGE_INTERVAL;
/*--------------------------------------------------------------------
* decay_usage - decay usage for the passed usage list
*--------------------------------------------------------------------*/
static void decay_usage(lList *usage_list, const lList *decay_list, double interval)
{
lListElem *usage = NULL;
if (usage_list) {
double decay = 0;
double default_decay = 0;
default_decay = pow(sconf_get_decay_constant(),
interval /
(double)sge_usage_interval);
for_each(usage, usage_list) {
lListElem *decay_elem;
if (decay_list &&
((decay_elem = lGetElemStr(decay_list, UA_name,
lGetPosString(usage, UA_name_POS))))) {
decay = pow(lGetPosDouble(decay_elem, UA_value_POS),
interval /
(double)sge_usage_interval);
} else {
decay = default_decay;
}
lSetPosDouble(usage, UA_value_POS,
lGetPosDouble(usage, UA_value_POS) * decay);
}
}
return;
}
/*--------------------------------------------------------------------
* decay_userprj_usage - decay usage for the passed user/project object
*--------------------------------------------------------------------*/
void
decay_userprj_usage( lListElem *userprj,
bool is_user,
const lList *decay_list,
u_long seqno,
u_long curr_time )
{
u_long usage_time_stamp;
int obj_usage_seqno_POS = is_user ? UU_usage_seqno_POS : PR_usage_seqno_POS;
int obj_usage_time_stamp_POS = is_user ? UU_usage_time_stamp_POS : PR_usage_time_stamp_POS;
int obj_usage_POS = is_user ? UU_usage_POS : PR_usage_POS;
int obj_project_POS = is_user ? UU_project_POS : PR_project_POS;
if (userprj && seqno != lGetPosUlong(userprj, obj_usage_seqno_POS)) {
/*-------------------------------------------------------------
* Note: In order to decay usage once per decay interval, we
* keep a time stamp in the user/project of when it was last
* decayed and then apply the approriate decay based on the time
* stamp. This allows the usage to be decayed on the scheduling
* interval, even though the decay interval is different than
* the scheduling interval.
*-------------------------------------------------------------*/
usage_time_stamp = lGetPosUlong(userprj, obj_usage_time_stamp_POS);
if (usage_time_stamp > 0 && (curr_time > usage_time_stamp)) {
lListElem *upp;
double interval = curr_time - usage_time_stamp;
decay_usage(lGetPosList(userprj, obj_usage_POS), decay_list, interval);
for_each(upp, lGetPosList(userprj, obj_project_POS)) {
decay_usage(lGetPosList(upp, UPP_usage_POS), decay_list, interval);
}
}
lSetPosUlong(userprj, obj_usage_time_stamp_POS, curr_time);
if (seqno != (u_long) -1) {
lSetPosUlong(userprj, obj_usage_seqno_POS, seqno);
}
}
return;
}
/*--------------------------------------------------------------------
* calculate_decay_constant - calculates decay rate and constant based
* on the decay half life and usage interval. The halftime argument
* is in minutes.
*--------------------------------------------------------------------*/
void
calculate_decay_constant( double halftime,
double *decay_rate,
double *decay_constant )
{
if (halftime < 0) {
*decay_rate = 1.0;
*decay_constant = 0;
} else if (halftime == 0) {
*decay_rate = 0;
*decay_constant = 1.0;
} else {
*decay_rate = - log(0.5) / (halftime * 60);
*decay_constant = 1 - (*decay_rate * sge_usage_interval);
}
return;
}
/*--------------------------------------------------------------------
* calculate_default_decay_constant - calculates the default decay
* rate and constant based on the decay half life and usage interval.
* The halftime argument is in hours.
*--------------------------------------------------------------------*/
void
calculate_default_decay_constant( int halftime )
{
double sge_decay_rate = 0.0;
double sge_decay_constant = 0.0;
calculate_decay_constant(halftime*60.0, &sge_decay_rate, &sge_decay_constant);
sconf_set_decay_constant(sge_decay_constant);
}
/*--------------------------------------------------------------------
* sge_for_each_node - visit each node and call the supplied function
* until a non-zero return code is returned.
*--------------------------------------------------------------------*/
int
sge_for_each_share_tree_node( lListElem *node,
sge_node_func_t func,
void *ptr )
{
int retcode=0;
lList *children = NULL;
lListElem *child_node = NULL;
if (node == NULL) {
return 0;
}
if ((retcode = (*func)(node, ptr))) {
return retcode;
}
if ((children = lGetPosList(node, STN_children_POS))) {
for_each(child_node, children) {
if ((retcode = sge_for_each_share_tree_node(child_node, func, ptr))) {
break;
}
}
}
return retcode;
}
/*--------------------------------------------------------------------
* zero_node_fields - zero out the share tree node fields that are
* passed to the qmaster from schedd and are displayed at qmon
*--------------------------------------------------------------------*/
int
sge_zero_node_fields( lListElem *node,
void *ptr )
{
lSetPosDouble(node, STN_m_share_POS, 0);
lSetPosDouble(node, STN_adjusted_current_proportion_POS, 0);
lSetPosUlong(node, STN_job_ref_count_POS, 0);
return 0;
}
/*--------------------------------------------------------------------
* sge_init_node_fields - zero out the share tree node fields that are
* passed to the qmaster from schedd and are displayed at qmon
*
* Always returns 0.
*--------------------------------------------------------------------*/
int
sge_init_node_fields( lListElem *root )
{
return sge_for_each_share_tree_node(root, sge_zero_node_fields, NULL);
}
/*--------------------------------------------------------------------
* sge_calc_node_usage - calculate usage for this share tree node
* and all descendant nodes.
*--------------------------------------------------------------------*/
double
sge_calc_node_usage( lListElem *node,
const lList *user_list,
const lList *project_list,
const lList *decay_list,
u_long curr_time,
const char *projname,
u_long seqno )
{
double usage_value = 0;
int project_node = 0;
lListElem *child_node;
lList *children;
lListElem *userprj = NULL;
lList *usage_list=NULL;
lListElem *usage_weight, *usage_elem;
double sum_of_usage_weights = 0;
const char *usage_name;
bool is_user = false;
DENTER(TOP_LAYER, "sge_calc_node_usage");
children = lGetPosList(node, STN_children_POS);
if (!children) {
if (projname) {
/*-------------------------------------------------------------
* Get usage from project usage sub-list in user object
*-------------------------------------------------------------*/
if ((userprj = user_list_locate(user_list,
lGetPosString(node, STN_name_POS)))) {
lList *projects = lGetList(userprj, UU_project);
lListElem *upp;
is_user = true;
if (projects) {
if ((upp=lGetElemStr(projects, UPP_name, projname))) {
usage_list = lGetList(upp, UPP_usage);
}
}
}
} else {
/*-------------------------------------------------------------
* Get usage directly from corresponding user or project object
*-------------------------------------------------------------*/
if ((userprj = user_list_locate(user_list,
lGetPosString(node, STN_name_POS)))) {
is_user = true;
usage_list = lGetList(userprj, UU_usage);
} else if ((userprj = prj_list_locate(project_list,
lGetPosString(node, STN_name_POS)))) {
is_user = false;
usage_list = lGetList(userprj, PR_usage);
}
}
} else {
/*-------------------------------------------------------------
* If this is a project node, then return the project usage
* rather than the children's usage
*-------------------------------------------------------------*/
if (!projname) {
if ((userprj = prj_list_locate(project_list,
lGetPosString(node, STN_name_POS)))) {
project_node = 1;
is_user = false;
usage_list = lGetList(userprj, PR_usage);
projname = lGetString(userprj, PR_name);
}
}
}
if (usage_list) {
lList *usage_weight_list = NULL;
/*-------------------------------------------------------------
* Decay usage
*-------------------------------------------------------------*/
if (curr_time && userprj) {
decay_userprj_usage(userprj, is_user, decay_list, seqno, curr_time);
}
/*-------------------------------------------------------------
* Sum usage weighting factors
*-------------------------------------------------------------*/
if (sconf_is()) {
usage_weight_list = sconf_get_usage_weight_list();
if (usage_weight_list) {
for_each(usage_weight, usage_weight_list)
sum_of_usage_weights +=
lGetPosDouble(usage_weight, UA_value_POS);
}
}
/*-------------------------------------------------------------
* Combine user/project usage based on usage weighting factors
*-------------------------------------------------------------*/
if (usage_weight_list) {
for_each(usage_elem, usage_list) {
usage_name = lGetPosString(usage_elem, UA_name_POS);
usage_weight = lGetElemStr(usage_weight_list, UA_name,
usage_name);
if (usage_weight && sum_of_usage_weights>0) {
usage_value += lGetPosDouble(usage_elem, UA_value_POS) *
(lGetPosDouble(usage_weight, UA_value_POS) /
sum_of_usage_weights);
}
}
}
lFreeList(&usage_weight_list);
/*-------------------------------------------------------------
* Store other usage values in node usage list
*-------------------------------------------------------------*/
for_each(usage_elem, usage_list) {
const char *nm = lGetPosString(usage_elem, UA_name_POS);
lListElem *u;
if (strcmp(nm, USAGE_ATTR_CPU) != 0 &&
strcmp(nm, USAGE_ATTR_MEM) != 0 &&
strcmp(nm, USAGE_ATTR_IO) != 0) {
if (((u=lGetElemStr(lGetPosList(node, STN_usage_list_POS),
UA_name, nm))) ||
((u = lAddSubStr(node, UA_name, nm, STN_usage_list, UA_Type))))
lSetPosDouble(u, UA_value_POS,
lGetPosDouble(u, UA_value_POS) +
lGetPosDouble(usage_elem, UA_value_POS));
}
}
}
if (children) {
double child_usage = 0;
/*-------------------------------------------------------------
* Sum child usage
*-------------------------------------------------------------*/
for_each(child_node, children) {
lListElem *nu;
child_usage += sge_calc_node_usage(child_node, user_list,
project_list, decay_list, curr_time,
projname, seqno);
/*-------------------------------------------------------------
* Sum other usage values
*-------------------------------------------------------------*/
if (!project_node)
for_each(nu, lGetPosList(child_node, STN_usage_list_POS)) {
const char *nm = lGetPosString(nu, UA_name_POS);
lListElem *u;
if (((u=lGetElemStr(lGetPosList(node, STN_usage_list_POS),
UA_name, nm))) ||
((u=lAddSubStr(node, UA_name, nm, STN_usage_list, UA_Type))))
lSetPosDouble(u, UA_value_POS,
lGetPosDouble(u, UA_value_POS) +
lGetPosDouble(nu, UA_value_POS));
}
}
if (!project_node)
/* if this is not a project node, we include the child usage */
usage_value += child_usage;
else {
/* If this is a project node, then we calculate the usage
being used by all users which map to the "default" user node
by subtracting the sum of all the child usage from the
project usage. Then, we add this usage to all of the nodes
leading to the "default" user node. */
ancestors_t ancestors;
int i;
if (search_ancestors(node, "default", &ancestors, 1)) {
double default_usage = usage_value - child_usage;
if (default_usage > 1.0) {
for(i=1; i<ancestors.depth; i++) {
double u = lGetPosDouble(ancestors.nodes[i], STN_combined_usage_POS);
lSetPosDouble(ancestors.nodes[i], STN_combined_usage_POS, u + default_usage);
}
}
free_ancestors(&ancestors);
}
}
#ifdef notdef
else {
lListElem *default_node;
if ((default_node=search_named_node(node, "default")))
lSetPosDouble(default_node, STN_combined_usage_POS,
MAX(usage_value - child_usage, 0));
}
#endif
}
/*-------------------------------------------------------------
* Set combined usage in the node
*-------------------------------------------------------------*/
lSetPosDouble(node, STN_combined_usage_POS, usage_value);
DEXIT;
return usage_value;
}
/*--------------------------------------------------------------------
* sge_calc_node_proportions - calculate share tree node proportions
* for this node and all descendant nodes.
*--------------------------------------------------------------------*/
void
sge_calc_node_proportion( lListElem *node,
double total_usage )
{
lList *children = NULL;
lListElem *child_node = NULL;
/*-------------------------------------------------------------
* Calculate node proportions for all children
*-------------------------------------------------------------*/
if ((children = lGetPosList(node, STN_children_POS))) {
for_each(child_node, children) {
sge_calc_node_proportion(child_node, total_usage);
}
}
/*-------------------------------------------------------------
* Set proportion in the node
*-------------------------------------------------------------*/
if (total_usage == 0) {
lSetPosDouble(node, STN_actual_proportion_POS, 0);
}
else {
lSetPosDouble(node, STN_actual_proportion_POS,
lGetPosDouble(node, STN_combined_usage_POS) / total_usage);
}
return;
}
/*--------------------------------------------------------------------
* sge_calc_share_tree_proportions - calculate share tree node
* usage and proportions.
*
* Sets STN_combined_usage and STN_actual_proportion in each share
* tree node contained in the passed-in share_tree argument.
*--------------------------------------------------------------------*/
void
_sge_calc_share_tree_proportions( lList *share_tree,
const lList *user_list,
const lList *project_list,
const lList *decay_list,
u_long curr_time )
{
lListElem *root;
double total_usage;
DENTER(TOP_LAYER, "sge_calc_share_tree_proportions");
if (!share_tree || !((root=lFirst(share_tree)))) {
DEXIT;
return;
}
calculate_default_decay_constant( sconf_get_halftime());
total_usage = sge_calc_node_usage(root,
user_list,
project_list,
decay_list,
curr_time,
NULL,
-1);
sge_calc_node_proportion(root, total_usage);
DEXIT;
return;
}
void
sge_calc_share_tree_proportions( lList *share_tree,
const lList *user_list,
const lList *project_list,
const lList *decay_list )
{
_sge_calc_share_tree_proportions(share_tree, user_list, project_list,
decay_list, sge_get_gmt());
return;
}
/*--------------------------------------------------------------------
* set_share_tree_project_flags - set the share tree project flag for
* node and descendants
*--------------------------------------------------------------------*/
void
set_share_tree_project_flags( const lList *project_list,
lListElem *node )
{
lList *children;
lListElem *child;
if (!project_list || !node)
return;
if (prj_list_locate(project_list, lGetString(node, STN_name)))
lSetUlong(node, STN_project, 1);
else
lSetUlong(node, STN_project, 0);
children = lGetList(node, STN_children);
if (children) {
for_each(child, children) {
set_share_tree_project_flags(project_list, child);
}
}
return;
}
void
sge_add_default_user_nodes( lListElem *root_node,
const lList *user_list,
const lList *project_list,
const lList *userset_list)
{
lListElem *user, *project, *pnode, *dnode;
const char *proj_name, *user_name;
/*
* do for each project and for no project
* if default node exists
* do for each user
* if user maps to default node
* add temp node as sibling to default node
* endif
* end do
* endif
* end do
*/
set_share_tree_project_flags(project_list, root_node);
for_each(project, project_list) {
/*
** check acl and xacl of project for the temp users
** only users that are allowed for the project are shown
*/
lList *xacl = lGetList(project, PR_xacl);
lList *acl = lGetList(project, PR_acl);
proj_name = lGetString(project, PR_name);
if (search_userprj_node(root_node, "default", proj_name, NULL)) {
for_each(user, user_list) {
int has_access = 1;
user_name = lGetString(user, UU_name);
/*
** check if user would be allowed
*/
has_access = sge_has_access_(user_name, NULL, acl, xacl, userset_list);
if (has_access &&
((dnode=search_userprj_node(root_node, user_name,
proj_name, &pnode))) &&
!strcmp("default", lGetString(dnode, STN_name))) {
lListElem *node = lCopyElem(dnode);
lSetString(node, STN_name, user_name);
lSetList(node, STN_children, NULL);
lSetUlong(node, STN_temp, 1);
if (lGetList(dnode,STN_children) == NULL) {
lList *children = lCreateList("display", STN_Type);
lSetList(dnode, STN_children, children);
}
lAppendElem(lGetList(dnode,STN_children), node);
}
}
}
}
proj_name = NULL;
if (search_userprj_node(root_node, "default", proj_name, NULL)) {
for_each(user, user_list) {
user_name = lGetString(user, UU_name);
if (((dnode=search_userprj_node(root_node, user_name, proj_name, &pnode))) &&
strcmp("default", lGetString(dnode, STN_name)) == 0) {
lListElem *node = lCopyElem(dnode);
lSetString(node, STN_name, user_name);
lSetList(node, STN_children, NULL);
lSetUlong(node, STN_temp, 1);
if (lGetList(dnode,STN_children) == NULL) {
lList *children = lCreateList("display", STN_Type);
lSetList(dnode, STN_children, children);
}
lAppendElem(lGetList(dnode,STN_children), node);
}
}
}
}
/********************************************************
Search the share tree for the node corresponding to the
user / project combination
********************************************************/
static lListElem *
search_userprj_node_work( lListElem *ep, /* branch to search */
const char *username,
const char *projname,
lListElem **pep, /* parent of found node */
lListElem *root )
{
lListElem *cep, *fep;
const char *nodename;
lList *children;
if (ep == NULL || (username == NULL && projname == NULL)) {
return NULL;
}
nodename = lGetPosString(ep, STN_name_POS);
/*
* skip project nodes which don't match
*/
if (lGetPosUlong(ep, STN_project_POS) &&
ep != root &&
(!projname || strcmp(nodename, projname))) {
return NULL;
}
children = lGetPosList(ep, STN_children_POS);
/*
* if project name is supplied, look for the project
*/
if (projname != NULL) {
if (strcmp(nodename, projname) == 0) {
/*
* We have found the project node, now find the user node
* within the project sub-tree. If there are no children,
* return the project node.
*/
if (children == NULL) {
return ep;
}
return search_userprj_node_work(ep, username, NULL, pep, ep);
}
else {
/* search the child nodes for the project */
for_each(cep, children) {
if ((fep = search_userprj_node_work(cep, username, projname, pep, root))) {
if (pep && (cep == fep)) {
*pep = ep;
}
return fep;
}
}
/* project was not found, fall thru and return NULL */
}
}
else {
if (strcmp(nodename, username) == 0) {
return ep;
}
/*
* no project name supplied, so search for child node
*/
for_each(cep, children) {
if ((fep = search_userprj_node_work(cep, username, projname, pep, root))) {
if (pep && (cep == fep)) {
*pep = ep;
}
return fep;
}
}
/*
* if we've searched the entire tree, search for default user
*/
if (ep == root && strcmp(username, "default")) {
return search_userprj_node(ep, "default", NULL, pep);
}
/*
* user was not found, fall thru and return NULL
*/
}
return NULL;
}
/********************************************************
Search the share tree for the node corresponding to the
user / project combination
********************************************************/
lListElem *
search_userprj_node( lListElem *ep, /* root of the tree */
const char *username,
const char *projname,
lListElem **pep ) /* parent of found node */
{
return search_userprj_node_work(ep, username, projname, pep, ep);
}
/*--------------------------------------------------------------------
* sgeee_sort_jobs - sort jobs according the task-priority and job number
*--------------------------------------------------------------------*/
void sgeee_sort_jobs(lList **job_list) /* JB_Type */
{
sgeee_sort_jobs_by(job_list, SGEJ_priority, SGEJ_sort_decending , SGEJ_sort_ascending); /* decreasing priority then increasing job number */
}
void sgeee_sort_jobs_by( lList **job_list , int by_SGEJ_field, int field_sort_direction, int jobnum_sort_direction) /* JB_Type */
{
lListElem *job = NULL, *nxt_job = NULL;
lList *tmp_list = NULL; /* SGEJ_Type */
char *sortorder = NULL;
DENTER(TOP_LAYER, "sgeee_sort_jobs_by");
if (!job_list || !*job_list) {
DEXIT;
return;
}
#if 0
DPRINTF(("+ + + + + + + + + + + + + + + + \n"));
DPRINTF((" SORTING SGEEE JOB LIST \n"));
DPRINTF(("+ + + + + + + + + + + + + + + + \n"));
#endif
/*-----------------------------------------------------------------
* Create tmp list
*-----------------------------------------------------------------*/
tmp_list = lCreateList("tmp list", SGEJ_Type);
nxt_job = lFirst(*job_list);
while((job=nxt_job)) {
lListElem *tmp_sge_job = NULL; /* SGEJ_Type */
nxt_job = lNext(nxt_job);
tmp_sge_job = lCreateElem(SGEJ_Type);
{
lListElem *tmp_task; /* JAT_Type */
/*
* First try to find an enrolled task
* It will have the highest priority
*/
tmp_task = lFirst(lGetList(job, JB_ja_tasks));
/*
* If there is no enrolled task than take the template element
*/
if (tmp_task == NULL) {
tmp_task = lFirst(lGetList(job, JB_ja_template));
}
lSetDouble(tmp_sge_job, SGEJ_priority,
lGetDouble(tmp_task, JAT_prio));
if (by_SGEJ_field != SGEJ_priority) {
lSetUlong(tmp_sge_job, SGEJ_state,
lGetUlong(tmp_task, JAT_state));
lSetString(tmp_sge_job, SGEJ_master_queue,
lGetString(tmp_task, JAT_master_queue));
}
}
/*
** JB_job_number (Ulong)
** JAT_prio (Double)
** JB_job_name (String)
** JB_owner (String)
** JAT_status (Ulong)
** JAT_master_queue (String)
*/
lSetUlong(tmp_sge_job, SGEJ_job_number, lGetUlong(job, JB_job_number));
lSetUlong(tmp_sge_job, SGEJ_submission_time, lGetUlong(job, JB_submission_time));
if (by_SGEJ_field != SGEJ_priority) {
lSetString(tmp_sge_job, SGEJ_job_name, lGetString(job, JB_job_name));
lSetString(tmp_sge_job, SGEJ_owner, lGetString(job, JB_owner));
}
lSetRef(tmp_sge_job, SGEJ_job_reference, job);
#if 0
DPRINTF(("JOB: "sge_u32" SUBMISSION_TIME: "sge_u32" PRIORITY: %f NAME: %s OWNER: %s QUEUE: %s STATUS: "sge_u32"\n",
lGetUlong(tmp_sge_job, SGEJ_job_number),
lGetUlong(tmp_sge_job, SGEJ_submission_time),
lGetDouble(tmp_sge_job, SGEJ_priority),
lGetString(tmp_sge_job, SGEJ_job_name) ? lGetString(tmp_sge_job, SGEJ_job_name) : "",
lGetString(tmp_sge_job, SGEJ_owner) ? lGetString(tmp_sge_job, SGEJ_owner) : "",
lGetString(tmp_sge_job, SGEJ_master_queue) ? lGetString(tmp_sge_job, SGEJ_master_queue) :"",
lGetUlong(tmp_sge_job, SGEJ_state)));
#endif
lAppendElem(tmp_list, tmp_sge_job);
lDechainElem(*job_list, job);
}
/*-----------------------------------------------------------------
* Sort tmp list
*-----------------------------------------------------------------*/
if ((field_sort_direction) && (jobnum_sort_direction)) {
sortorder = "%I+ %I+ %I+";
} else if (!field_sort_direction) {
sortorder = "%I- %I+ %I+";
} else if (!jobnum_sort_direction) {
sortorder = "%I+ %I- %I-";
} else {
sortorder = "%I- %I- %I-";
}
lPSortList(tmp_list, sortorder,
by_SGEJ_field,
SGEJ_submission_time,
SGEJ_job_number);
/*-----------------------------------------------------------------
* rebuild job_list according sort order
*-----------------------------------------------------------------*/
for_each(job, tmp_list) {
lAppendElem(*job_list, lGetRef(job, SGEJ_job_reference));
}
/*-----------------------------------------------------------------
* Release tmp list
*-----------------------------------------------------------------*/
lFreeList(&tmp_list);
DEXIT;
return;
}
|