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
|
/*
* Copyright 1999-2009 University of Chicago
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef GLOBUS_DONT_DOCUMENT_INTERNAL
/**
* @file globus_gram_job_manager_validate.c
*
* RSL Validation Support for the GRAM Job Manager.
*
* CVS Information:
* $Source$
* $Date$
* $Revision$
* $Author$
*/
#define GLOBUS_GRAM_VALIDATE_JOB_SUBMIT_STRING \
"GLOBUS_GRAM_JOB_SUBMIT"
#define GLOBUS_GRAM_VALIDATE_JOB_MANAGER_RESTART_STRING \
"GLOBUS_GRAM_JOB_MANAGER_RESTART"
#define GLOBUS_GRAM_VALIDATE_STDIO_UPDATE_STRING \
"GLOBUS_GRAM_JOB_MANAGER_STDIO_UPDATE"
#include "globus_common.h"
#include "globus_gram_job_manager.h"
#include "globus_rsl.h"
#include "globus_rvf_parser.h"
#include <stdio.h>
#include <string.h>
#include <ctype.h>
static char * validation_filename;
static char * site_validation_filename;
static char * lrm_validation_filename;
static char * lrm_validation_filename_pattern;
static char * site_lrm_validation_filename;
static char * site_lrm_validation_filename_pattern;
static
int
globus_l_gram_job_manager_attribute_match(
void * datum,
void * args);
static
int
globus_gram_job_manager_validation_init(
globus_gram_job_manager_t * manager);
static
globus_bool_t
globus_l_gram_job_manager_validation_string_match(
const char * str1,
const char * str2);
static
int
globus_l_gram_job_manager_check_rsl_attributes(
globus_gram_jobmanager_request_t * request,
globus_rsl_t * rsl,
globus_gram_job_manager_validation_when_t
when);
static
globus_bool_t
globus_l_gram_job_manager_attribute_exists(
globus_list_t * attributes,
char * attribute_name);
static
int
globus_l_gram_job_manager_insert_default_rsl(
globus_gram_jobmanager_request_t * request,
globus_rsl_t * rsl,
globus_gram_job_manager_validation_when_t
when);
static
void
globus_l_gram_job_manager_validation_record_free(
globus_rvf_record_t * record);
static
int
globus_l_gram_job_manager_validation_rsl_error(
const char * attribute);
static
int
globus_l_gram_job_manager_validation_value_error(
globus_gram_jobmanager_request_t * request,
const char * attribute,
const char * value,
const char * enumerated_values);
static
int
globus_l_gram_job_manager_missing_value_error(
const char * attribute);
extern
int
globus_gram_job_manager_validation_update(
globus_gram_job_manager_t * manager)
{
time_t validation_timestamp = time(NULL);
int rc = GLOBUS_SUCCESS;
globus_result_t result;
struct stat st;
globus_bool_t do_update = GLOBUS_FALSE;
if (validation_timestamp <= manager->validation_record_timestamp)
{
goto skip_update_check;
}
if (validation_filename == NULL)
{
result = globus_eval_path(
"${datadir}/globus/globus_gram_job_manager/globus-gram-job-manager.rvf",
&validation_filename);
if (result != GLOBUS_SUCCESS || validation_filename == NULL)
{
rc = GLOBUS_GRAM_PROTOCOL_ERROR_MALLOC_FAILED;
goto validation_filename_failed;
}
}
if (site_validation_filename == NULL)
{
result = globus_eval_path(
"${sysconfdir}/globus/gram/job-manager.rvf",
&site_validation_filename);
if (result != GLOBUS_SUCCESS || site_validation_filename == NULL)
{
rc = GLOBUS_GRAM_PROTOCOL_ERROR_MALLOC_FAILED;
goto site_validation_filename_failed;
}
}
if (lrm_validation_filename_pattern == NULL)
{
lrm_validation_filename_pattern = globus_common_create_string(
"${datadir}/globus/globus_gram_job_manager/%s.rvf",
manager->config->jobmanager_type);
if(lrm_validation_filename_pattern == NULL)
{
rc = GLOBUS_GRAM_PROTOCOL_ERROR_MALLOC_FAILED;
goto lrm_validation_filename_pattern_failed;
}
}
if (lrm_validation_filename == NULL)
{
result = globus_eval_path(
lrm_validation_filename_pattern,
&lrm_validation_filename);
if (result != GLOBUS_SUCCESS || lrm_validation_filename == NULL)
{
rc = GLOBUS_GRAM_PROTOCOL_ERROR_MALLOC_FAILED;
goto lrm_validation_filename_failed;
}
}
if (site_lrm_validation_filename_pattern == NULL)
{
site_lrm_validation_filename_pattern = globus_common_create_string(
"${sysconfdir}/globus/gram/%s.rvf",
manager->config->jobmanager_type);
if(site_lrm_validation_filename_pattern == NULL)
{
rc = GLOBUS_GRAM_PROTOCOL_ERROR_MALLOC_FAILED;
goto site_lrm_validation_filename_pattern_failed;
}
}
if (site_lrm_validation_filename == NULL)
{
result = globus_eval_path(site_lrm_validation_filename_pattern,
&site_lrm_validation_filename);
if (result != GLOBUS_SUCCESS || site_lrm_validation_filename == NULL)
{
rc = GLOBUS_GRAM_PROTOCOL_ERROR_MALLOC_FAILED;
goto site_lrm_validation_filename_failed;
}
}
rc = stat(validation_filename, &st);
if ((rc == GLOBUS_SUCCESS
&& ((!manager->validation_file_exists[0]) ||
st.st_mtime > manager->validation_record_timestamp)) ||
(rc != GLOBUS_SUCCESS
&& errno == ENOENT && manager->validation_file_exists[0]))
{
do_update = GLOBUS_TRUE;
}
if (!do_update)
{
rc = stat(lrm_validation_filename, &st);
if ((rc == GLOBUS_SUCCESS
&& ((!manager->validation_file_exists[1]) ||
st.st_mtime > manager->validation_record_timestamp)) ||
(rc != GLOBUS_SUCCESS
&& errno == ENOENT && manager->validation_file_exists[1]))
{
do_update = GLOBUS_TRUE;
}
}
if (!do_update)
{
rc = stat(site_validation_filename, &st);
if ((rc == GLOBUS_SUCCESS
&& ((!manager->validation_file_exists[2]) ||
st.st_mtime > manager->validation_record_timestamp)) ||
(rc != GLOBUS_SUCCESS
&& errno == ENOENT && manager->validation_file_exists[2]))
{
do_update = GLOBUS_TRUE;
}
}
if (!do_update)
{
rc = stat(site_lrm_validation_filename, &st);
if ((rc == GLOBUS_SUCCESS
&& ((!manager->validation_file_exists[3]) ||
st.st_mtime > manager->validation_record_timestamp)) ||
(rc != GLOBUS_SUCCESS
&& errno == ENOENT && manager->validation_file_exists[3]))
{
do_update = GLOBUS_TRUE;
}
}
if (! (manager->validation_file_exists[0] ||
manager->validation_file_exists[1] ||
manager->validation_file_exists[2] ||
manager->validation_file_exists[3]) )
{
do_update = 1;
}
if (do_update)
{
/* Free old validation entries */
globus_gram_job_manager_validation_destroy(
manager->validation_records);
manager->validation_records = NULL;
rc = globus_gram_job_manager_validation_init(manager);
}
else
{
rc = GLOBUS_SUCCESS;
}
site_lrm_validation_filename_failed:
site_lrm_validation_filename_pattern_failed:
lrm_validation_filename_failed:
lrm_validation_filename_pattern_failed:
site_validation_filename_failed:
validation_filename_failed:
skip_update_check:
return rc;
}
/* globus_gram_job_manager_validation_update() */
/**
* @param manager
* A job request. The validation field of this job request will be
* updated with a list of validation records constructed from the
* rsl validation files associated with the job manager.
*/
static
int
globus_gram_job_manager_validation_init(
globus_gram_job_manager_t * manager)
{
time_t validation_timestamp = time(NULL);
int rc = GLOBUS_SUCCESS;
globus_list_t * l;
manager->validation_records = NULL;
manager->validation_file_exists[0] = GLOBUS_FALSE;
manager->validation_file_exists[1] = GLOBUS_FALSE;
manager->validation_file_exists[2] = GLOBUS_FALSE;
manager->validation_file_exists[3] = GLOBUS_FALSE;
/* Read in validation files. Do the generic job manager one first,
* as the scheduler-specific one overrides it.
*/
rc = globus_rvf_parse_file(
validation_filename,
&manager->validation_records,
&manager->gt3_failure_message);
if(rc != GLOBUS_SUCCESS)
{
manager->validation_file_exists[0] = GLOBUS_FALSE;
rc = globus_rvf_parse_string(
globus_i_gram_default_rvf,
&manager->validation_records,
&manager->gt3_failure_message);
}
else
{
manager->validation_file_exists[0] = GLOBUS_TRUE;
}
if(rc != GLOBUS_SUCCESS)
{
goto read_validation_failed;
}
if(access(lrm_validation_filename, R_OK) == 0)
{
rc = globus_rvf_parse_file(
lrm_validation_filename,
&manager->validation_records,
&manager->gt3_failure_message);
if (rc != GLOBUS_SUCCESS)
{
goto read_lrm_validation_filename_failed;
}
manager->validation_file_exists[1] = GLOBUS_TRUE;
}
if (access(site_validation_filename, R_OK) == 0)
{
rc = globus_rvf_parse_file(
site_validation_filename,
&manager->validation_records,
&manager->gt3_failure_message);
if (rc != GLOBUS_SUCCESS)
{
goto read_site_validation_filename_failed;
}
manager->validation_file_exists[2] = GLOBUS_TRUE;
}
if (access(site_lrm_validation_filename, R_OK) == 0)
{
rc = globus_rvf_parse_file(
site_lrm_validation_filename,
&manager->validation_records,
&manager->gt3_failure_message);
if (rc != GLOBUS_SUCCESS)
{
goto read_site_lrm_validation_filename_failed;
}
manager->validation_file_exists[3] = GLOBUS_TRUE;
}
for(l = manager->validation_records; l != NULL; l = globus_list_rest(l))
{
globus_rvf_record_t * record = globus_list_first(l);
if (record->valid_when == -1)
{
record->valid_when = 0;
}
if (record->default_when == -1)
{
record->default_when = 0;
}
if (record->required_when == -1)
{
record->required_when = 0;
}
if (record->publishable == -1)
{
record->publishable = 1;
}
}
manager->validation_record_timestamp = validation_timestamp;
read_site_lrm_validation_filename_failed:
read_site_validation_filename_failed:
read_lrm_validation_filename_failed:
if(rc != GLOBUS_SUCCESS)
{
globus_gram_job_manager_validation_destroy(
manager->validation_records);
manager->validation_records = NULL;
}
read_validation_failed:
return rc;
}
/* globus_gram_job_manager_validation_init() */
int
globus_gram_job_manager_validation_destroy(
globus_list_t * validation_records)
{
globus_list_t * tmp;
globus_rvf_record_t * record;
tmp = validation_records;
while (!globus_list_empty(tmp))
{
record = globus_list_first(tmp);
tmp = globus_list_rest(tmp);
globus_l_gram_job_manager_validation_record_free(record);
}
globus_list_free(validation_records);
return GLOBUS_SUCCESS;
}
/**
* Validate a request's RSL.
* @ingroup globus_gram_job_manager_rsl_validation
*
* Validate the RSL tree defining a job request, using validation files.
* An RSL is valid if all required RSL parameters and defined in the RSL,
* and if all RSL parameters in the RSL tree are supported by the job
* manager and/or scheduler.
*
* As a side effect, the RSL will be modified to include any missing RSL
* paramaters which have default values defined in one of the validation
* files.
*
* @param request
* A job request. The rsl field of this job request is validated
* according to the rsl validation data stored in the two files
* passed in to this function.
*
* @return Returns GLOBUS_SUCCESS if the RSL is valid, and GLOBUS_FAILURE
* if it is not.
* @see globus_gram_job_manager_rsl_validation_file
*/
int
globus_gram_job_manager_validate_rsl(
globus_gram_jobmanager_request_t * request,
globus_rsl_t * rsl,
globus_gram_job_manager_validation_when_t
when)
{
int rc;
/* First validation: RSL is a boolean "&" */
if(!globus_rsl_is_boolean_and(rsl))
{
return GLOBUS_GRAM_PROTOCOL_ERROR_BAD_RSL;
}
rc = globus_gram_job_manager_validation_update(request->manager);
if (rc != GLOBUS_SUCCESS)
{
return rc;
}
/*
* Make sure all of the attributes match defined RSL validation records.
*/
rc = globus_l_gram_job_manager_check_rsl_attributes(
request,
rsl,
when);
if(rc != GLOBUS_SUCCESS)
{
goto rsl_check_failed;
}
/*
* Insert default RSL values where appropriate, make sure everything
* which is required is defined.
*/
rc = globus_l_gram_job_manager_insert_default_rsl(
request,
rsl,
when);
if (rc != GLOBUS_SUCCESS)
{
goto insert_default_rsl_failed;
}
insert_default_rsl_failed:
rsl_check_failed:
return rc;
}
/* globus_gram_job_manager_validate_rsl() */
/**
* Attribute name matching search predicate.
*
* Compares a validation record against the desired attribute name. Used
* as a predicate in globus_list_search_pred().
*
* @param datum
* A void * cast of a validation record.
* @param args
* A void * cast of the desired attribute name.
*/
static
int
globus_l_gram_job_manager_attribute_match(
void * datum,
void * args)
{
globus_rvf_record_t * tmp = datum;
return globus_l_gram_job_manager_validation_string_match(
tmp->attribute,
args);
}
/* globus_l_gram_job_manager_attribute_match() */
static
globus_bool_t
globus_l_gram_job_manager_validation_string_match(
const char * str1,
const char * str2)
{
return (strcmp(str1, str2) == 0);
}
/* globus_l_gram_job_manager_validation_string_match() */
/**
* Validate RSL attributes
*
* Checks that all of the RSL attributes in the request's RSL match
* a validation record. If an RSL has an enumerated list of values,
* then the value of the RSL is compared against that list.
*
* @param request
* The job request containing the RSL to validate.
* @param when
* Which RSL validation time scope we will use to decide
* whether to use the default values or not.
*/
static
int
globus_l_gram_job_manager_check_rsl_attributes(
globus_gram_jobmanager_request_t * request,
globus_rsl_t * rsl,
globus_gram_job_manager_validation_when_t
when)
{
globus_list_t * operands;
globus_list_t * node;
globus_rsl_t * relation;
char * attribute;
char * value_str;
globus_rvf_record_t * record;
globus_rsl_value_t * value;
int rc = GLOBUS_SUCCESS;
static const char * operation_types[] =
{
"??",
"=",
"!=",
">",
">=",
"<",
"<=",
"??",
"&",
"|",
"+"
};
operands = globus_rsl_boolean_get_operand_list(rsl);
/* Check to make sure that every attribute is recognized by this
* job manager.
*/
while(!globus_list_empty(operands))
{
relation = globus_list_first(operands);
operands = globus_list_rest(operands);
if (!globus_rsl_is_relation(relation))
{
int operator = globus_rsl_boolean_get_operator(relation);
if (operator > 10 || operator < 0)
{
operator = 0;
}
globus_gram_job_manager_request_log(
request,
GLOBUS_GRAM_JOB_MANAGER_LOG_ERROR,
"event=gram.validate_rsl.end "
"level=ERROR "
"msg=\"Required RSL relation, got boolean\" "
"operator=%s "
"status=%d "
"\n",
operation_types[operator],
-GLOBUS_GRAM_PROTOCOL_ERROR_BAD_RSL);
if (request->gt3_failure_message == NULL)
{
request->gt3_failure_message = globus_common_create_string(
"Required RSL relation, got boolean %s",
operation_types[operator]);
}
}
else if (!globus_rsl_is_relation_eq(relation))
{
int operator = globus_rsl_relation_get_operator(relation);
if (operator > 10 || operator < 0)
{
operator = 0;
}
globus_gram_job_manager_request_log(
request,
GLOBUS_GRAM_JOB_MANAGER_LOG_ERROR,
"event=gram.validate_rsl.end "
"level=ERROR "
"msg=\"Unsupported RSL operation\" "
"attribute=%s "
"operator=%s "
"status=%d "
"\n",
globus_rsl_relation_get_attribute(relation),
operation_types[operator],
-GLOBUS_GRAM_PROTOCOL_ERROR_BAD_RSL);
if (request->gt3_failure_message == NULL)
{
request->gt3_failure_message = globus_common_create_string(
"the job manager does not support the RSL operator "
"\"%s\" for the %s attribute",
operation_types[operator],
globus_rsl_relation_get_attribute(relation));
}
return GLOBUS_GRAM_PROTOCOL_ERROR_BAD_RSL;
}
attribute = globus_rsl_relation_get_attribute(relation);
node = globus_list_search_pred(
request->manager->validation_records,
globus_l_gram_job_manager_attribute_match,
attribute);
if(!node)
{
globus_gram_job_manager_request_log(
request,
GLOBUS_GRAM_JOB_MANAGER_LOG_ERROR,
"event=gram.validate_rsl.end "
"level=ERROR "
"msg=\"Unsupported RSL attribute\" "
"attribute=%s "
"status=%d "
"\n",
globus_rsl_relation_get_attribute(relation),
-GLOBUS_GRAM_PROTOCOL_ERROR_BAD_RSL);
if (request->gt3_failure_message == NULL)
{
request->gt3_failure_message = globus_common_create_string(
"the RSL attribute \"%s\" is not supported by the LRM adapter",
globus_rsl_relation_get_attribute(relation));
}
return GLOBUS_GRAM_PROTOCOL_ERROR_PARAMETER_NOT_SUPPORTED;
}
record = globus_list_first(node);
/* Check valid_when */
if((record->valid_when & when) == 0)
{
const char * whenstr = "unknown operation";
switch(when)
{
case GLOBUS_GRAM_VALIDATE_JOB_SUBMIT:
whenstr = "submit";
rc = GLOBUS_GRAM_PROTOCOL_ERROR_INVALID_SUBMIT_ATTRIBUTE;
break;
case GLOBUS_GRAM_VALIDATE_JOB_MANAGER_RESTART:
whenstr = "restart";
rc = GLOBUS_GRAM_PROTOCOL_ERROR_INVALID_RESTART_ATTRIBUTE;
break;
case GLOBUS_GRAM_VALIDATE_STDIO_UPDATE:
whenstr = "stdio_update";
rc = GLOBUS_GRAM_PROTOCOL_ERROR_INVALID_STDIO_UPDATE_ATTRIBUTE;
break;
}
globus_gram_job_manager_request_log(
request,
GLOBUS_GRAM_JOB_MANAGER_LOG_ERROR,
"event=gram.validate_rsl.end "
"level=ERROR "
"msg=\"Invalid RSL attribute for operation\" "
"attribute=%s "
"operation=%s "
"status=%d "
"\n",
globus_rsl_relation_get_attribute(relation),
whenstr,
-rc);
if (request->gt3_failure_message == NULL)
{
request->gt3_failure_message = globus_common_create_string(
"Invalid RSL attribute \"%s\" for %s",
globus_rsl_relation_get_attribute(relation),
whenstr);
}
return rc;
}
/* Check enumerated values if applicable */
if(record->enumerated_values)
{
value = globus_rsl_relation_get_single_value(relation);
if(!value)
{
return
globus_l_gram_job_manager_validation_rsl_error(attribute);
}
value_str = globus_rsl_value_literal_get_string(value);
if(!value_str)
{
return globus_l_gram_job_manager_validation_rsl_error(
attribute);
}
if(strstr(record->enumerated_values, value_str) == GLOBUS_NULL)
{
rc = globus_l_gram_job_manager_validation_value_error(
request,
attribute,
value_str,
record->enumerated_values);
globus_gram_job_manager_request_log(
request,
GLOBUS_GRAM_JOB_MANAGER_LOG_ERROR,
"event=gram.validate_rsl.end "
"level=ERROR "
"msg=\"RSL attribute value not in enumeration\" "
"attribute=%s "
"value=%s "
"enumeration=\"%s\" "
"status=%d "
"\n",
record->attribute,
value_str,
record->enumerated_values,
-rc);
return rc;
}
}
}
return GLOBUS_SUCCESS;
}
/* globus_l_gram_job_manager_check_rsl_attributes() */
/**
* Add default values to RSL and verify required parameters
*
* Inserts default values to RSL when an RSL parameter is not defined
* in it. After this is complete, it checks that all RSL parameters
* with the "required_when" flag set are present in the RSL tree.
*
* @param request
* Request which contains the RSL tree to validate.
* @param when
* Which RSL validation time scope we will use to decide
* whether to use the default values or not.
*/
static
int
globus_l_gram_job_manager_insert_default_rsl(
globus_gram_jobmanager_request_t * request,
globus_rsl_t * rsl,
globus_gram_job_manager_validation_when_t
when)
{
globus_rvf_record_t * record;
globus_list_t ** attributes;
globus_rsl_t * new_relation;
char * new_relation_str;
globus_list_t * validation_records;
int rc = GLOBUS_SUCCESS;
attributes = globus_rsl_boolean_get_operand_list_ref(rsl);
validation_records = request->manager->validation_records;
while(!globus_list_empty(validation_records))
{
record = globus_list_first(validation_records);
validation_records = globus_list_rest(validation_records);
if(record->default_value && (record->default_when&when))
{
if(!globus_l_gram_job_manager_attribute_exists(
*attributes,
record->attribute))
{
new_relation_str = globus_common_create_string(
"%s = %s",
record->attribute,
record->default_value);
globus_gram_job_manager_request_log(
request,
GLOBUS_GRAM_JOB_MANAGER_LOG_TRACE,
"event=gram.validate_rsl.info "
"level=TRACE "
"msg=\"Inserting default RSL for attribute\" "
"attribute=%s "
"default=\"%s\" "
"\n",
record->attribute,
record->default_value);
new_relation = globus_rsl_parse(new_relation_str);
globus_list_insert(attributes, new_relation);
free(new_relation_str);
}
}
if(record->required_when & when)
{
if(!globus_l_gram_job_manager_attribute_exists(
*attributes,
record->attribute))
{
rc = globus_l_gram_job_manager_missing_value_error(
record->attribute);
globus_gram_job_manager_request_log(
request,
GLOBUS_GRAM_JOB_MANAGER_LOG_ERROR,
"event=gram.validate_rsl.end "
"level=ERROR "
"msg=\"RSL missing required attribute\" "
"attribute=%s "
"\n",
record->attribute);
return rc;
}
}
}
return rc;
}
/* globus_l_gram_job_manager_insert_default_rsl() */
/**
* Check that a relation for a required RSL attribute is present.
*
* @param attributes
* List of relations which are part of the job request's
* RSL.
* @param attribute_name
* The name of the attribute to search for.
*/
static
globus_bool_t
globus_l_gram_job_manager_attribute_exists(
globus_list_t * attributes,
char * attribute_name)
{
char * tmp;
globus_rsl_t * relation;
while(!globus_list_empty(attributes))
{
relation = globus_list_first(attributes);
attributes = globus_list_rest(attributes);
tmp = globus_rsl_relation_get_attribute(relation);
if(globus_l_gram_job_manager_validation_string_match(
tmp,
attribute_name))
{
return GLOBUS_TRUE;
}
}
return GLOBUS_FALSE;
}
/* globus_l_gram_job_manager_attribute_exists() */
/**
* Free a validation record
*
* Frees all strings referenced by the validation record, and
* then frees the record itself.
*
* @param record
* The record to free.
*/
static
void
globus_l_gram_job_manager_validation_record_free(
globus_rvf_record_t * record)
{
if(!record)
{
return;
}
if(record->attribute)
{
free(record->attribute);
}
if(record->description)
{
free(record->description);
}
if(record->default_value)
{
free(record->default_value);
}
if(record->enumerated_values)
{
free(record->enumerated_values);
}
free(record);
}
/* globus_l_gram_job_manager_validation_record_free() */
#define HANDLE_RSL_ERROR(param,error) \
if(globus_l_gram_job_manager_validation_string_match( \
attribute, param)) \
{ \
return error; \
}
/**
* Decide what type of RSL error to return when the value of @a attribute.
* is not of the appropriate type.
*
* @param attribute
* Attribute to check.
*
* @note This should go away when we have better error reporting in the
* GRAM protocol.
*/
static
int
globus_l_gram_job_manager_validation_rsl_error(
const char * attribute)
{
HANDLE_RSL_ERROR(GLOBUS_GRAM_PROTOCOL_ARGUMENTS_PARAM,
GLOBUS_GRAM_PROTOCOL_ERROR_RSL_ARGUMENTS)
HANDLE_RSL_ERROR(GLOBUS_GRAM_PROTOCOL_COUNT_PARAM,
GLOBUS_GRAM_PROTOCOL_ERROR_RSL_COUNT)
HANDLE_RSL_ERROR(GLOBUS_GRAM_PROTOCOL_DIR_PARAM,
GLOBUS_GRAM_PROTOCOL_ERROR_RSL_DIRECTORY)
HANDLE_RSL_ERROR(GLOBUS_GRAM_PROTOCOL_DRY_RUN_PARAM,
GLOBUS_GRAM_PROTOCOL_ERROR_RSL_DRYRUN)
HANDLE_RSL_ERROR(GLOBUS_GRAM_PROTOCOL_ENVIRONMENT_PARAM,
GLOBUS_GRAM_PROTOCOL_ERROR_RSL_ENVIRONMENT)
HANDLE_RSL_ERROR(GLOBUS_GRAM_PROTOCOL_EXECUTABLE_PARAM,
GLOBUS_GRAM_PROTOCOL_ERROR_RSL_EXECUTABLE)
HANDLE_RSL_ERROR(GLOBUS_GRAM_PROTOCOL_FILE_CLEANUP_PARAM,
GLOBUS_GRAM_PROTOCOL_ERROR_RSL_FILE_CLEANUP)
HANDLE_RSL_ERROR(GLOBUS_GRAM_PROTOCOL_FILE_STAGE_IN_PARAM,
GLOBUS_GRAM_PROTOCOL_ERROR_RSL_FILE_STAGE_IN)
HANDLE_RSL_ERROR(GLOBUS_GRAM_PROTOCOL_FILE_STAGE_IN_SHARED_PARAM,
GLOBUS_GRAM_PROTOCOL_ERROR_RSL_FILE_STAGE_IN_SHARED)
HANDLE_RSL_ERROR(GLOBUS_GRAM_PROTOCOL_FILE_STAGE_OUT_PARAM,
GLOBUS_GRAM_PROTOCOL_ERROR_RSL_FILE_STAGE_OUT)
HANDLE_RSL_ERROR(GLOBUS_GRAM_PROTOCOL_GASS_CACHE_PARAM,
GLOBUS_GRAM_PROTOCOL_ERROR_RSL_GASS_CACHE)
HANDLE_RSL_ERROR(GLOBUS_GRAM_PROTOCOL_MYJOB_PARAM,
GLOBUS_GRAM_PROTOCOL_ERROR_RSL_MYJOB)
HANDLE_RSL_ERROR(GLOBUS_GRAM_PROTOCOL_HOST_COUNT_PARAM,
GLOBUS_GRAM_PROTOCOL_ERROR_RSL_HOST_COUNT)
HANDLE_RSL_ERROR(GLOBUS_GRAM_PROTOCOL_JOB_TYPE_PARAM,
GLOBUS_GRAM_PROTOCOL_ERROR_RSL_JOBTYPE)
HANDLE_RSL_ERROR(GLOBUS_GRAM_PROTOCOL_MAX_CPU_TIME_PARAM,
GLOBUS_GRAM_PROTOCOL_ERROR_RSL_MAX_CPU_TIME)
HANDLE_RSL_ERROR(GLOBUS_GRAM_PROTOCOL_MAX_MEMORY_PARAM,
GLOBUS_GRAM_PROTOCOL_ERROR_RSL_MAX_MEMORY)
HANDLE_RSL_ERROR(GLOBUS_GRAM_PROTOCOL_MAX_TIME_PARAM,
GLOBUS_GRAM_PROTOCOL_ERROR_RSL_MAXTIME)
HANDLE_RSL_ERROR(GLOBUS_GRAM_PROTOCOL_MAX_WALL_TIME_PARAM,
GLOBUS_GRAM_PROTOCOL_ERROR_RSL_MAX_WALL_TIME)
HANDLE_RSL_ERROR(GLOBUS_GRAM_PROTOCOL_MIN_MEMORY_PARAM,
GLOBUS_GRAM_PROTOCOL_ERROR_RSL_MIN_MEMORY)
HANDLE_RSL_ERROR(GLOBUS_GRAM_PROTOCOL_PROJECT_PARAM,
GLOBUS_GRAM_PROTOCOL_ERROR_RSL_PROJECT)
HANDLE_RSL_ERROR(GLOBUS_GRAM_PROTOCOL_QUEUE_PARAM,
GLOBUS_GRAM_PROTOCOL_ERROR_RSL_QUEUE)
HANDLE_RSL_ERROR(GLOBUS_GRAM_PROTOCOL_REMOTE_IO_URL_PARAM,
GLOBUS_GRAM_PROTOCOL_ERROR_RSL_REMOTE_IO_URL)
HANDLE_RSL_ERROR(GLOBUS_GRAM_PROTOCOL_RESTART_PARAM,
GLOBUS_GRAM_PROTOCOL_ERROR_RSL_RESTART)
HANDLE_RSL_ERROR(GLOBUS_GRAM_PROTOCOL_SAVE_STATE_PARAM,
GLOBUS_GRAM_PROTOCOL_ERROR_RSL_SAVE_STATE)
HANDLE_RSL_ERROR(GLOBUS_GRAM_PROTOCOL_SCRATCHDIR_PARAM,
GLOBUS_GRAM_PROTOCOL_ERROR_RSL_SCRATCH)
HANDLE_RSL_ERROR(GLOBUS_GRAM_PROTOCOL_STDERR_PARAM,
GLOBUS_GRAM_PROTOCOL_ERROR_RSL_STDERR)
HANDLE_RSL_ERROR(GLOBUS_GRAM_PROTOCOL_STDERR_POSITION_PARAM,
GLOBUS_GRAM_PROTOCOL_ERROR_RSL_STDERR_POSITION)
HANDLE_RSL_ERROR(GLOBUS_GRAM_PROTOCOL_STDIN_PARAM,
GLOBUS_GRAM_PROTOCOL_ERROR_RSL_STDIN)
HANDLE_RSL_ERROR(GLOBUS_GRAM_PROTOCOL_STDOUT_PARAM,
GLOBUS_GRAM_PROTOCOL_ERROR_RSL_STDOUT)
HANDLE_RSL_ERROR(GLOBUS_GRAM_PROTOCOL_STDOUT_POSITION_PARAM,
GLOBUS_GRAM_PROTOCOL_ERROR_RSL_STDOUT_POSITION)
HANDLE_RSL_ERROR(GLOBUS_GRAM_PROTOCOL_TWO_PHASE_COMMIT_PARAM,
GLOBUS_GRAM_PROTOCOL_ERROR_RSL_TWO_PHASE_COMMIT)
HANDLE_RSL_ERROR(GLOBUS_GRAM_PROTOCOL_PROXY_TIMEOUT_PARAM,
GLOBUS_GRAM_PROTOCOL_ERROR_RSL_PROXY_TIMEOUT)
return GLOBUS_GRAM_PROTOCOL_ERROR_RSL_SCHEDULER_SPECIFIC;
}
/* globus_l_gram_job_manager_validation_rsl_error() */
static
int
globus_l_gram_job_manager_validation_value_error(
globus_gram_jobmanager_request_t * request,
const char * attribute,
const char * value,
const char * enumerated_values)
{
if (request->gt3_failure_message == NULL)
{
request->gt3_failure_message = globus_common_create_string(
"RSL attribute \"%s\" has value \"%s\" which is not one of the allowed values (%s)",
attribute,
value,
enumerated_values);
}
HANDLE_RSL_ERROR(GLOBUS_GRAM_PROTOCOL_COUNT_PARAM,
GLOBUS_GRAM_PROTOCOL_ERROR_INVALID_COUNT)
HANDLE_RSL_ERROR(GLOBUS_GRAM_PROTOCOL_MYJOB_PARAM,
GLOBUS_GRAM_PROTOCOL_ERROR_INVALID_GRAM_MYJOB)
HANDLE_RSL_ERROR(GLOBUS_GRAM_PROTOCOL_HOST_COUNT_PARAM,
GLOBUS_GRAM_PROTOCOL_ERROR_INVALID_HOST_COUNT)
HANDLE_RSL_ERROR(GLOBUS_GRAM_PROTOCOL_JOB_TYPE_PARAM,
GLOBUS_GRAM_PROTOCOL_ERROR_INVALID_JOBTYPE)
HANDLE_RSL_ERROR(GLOBUS_GRAM_PROTOCOL_MAX_CPU_TIME_PARAM,
GLOBUS_GRAM_PROTOCOL_ERROR_INVALID_MAX_CPU_TIME)
HANDLE_RSL_ERROR(GLOBUS_GRAM_PROTOCOL_MAX_MEMORY_PARAM,
GLOBUS_GRAM_PROTOCOL_ERROR_INVALID_MAX_MEMORY)
HANDLE_RSL_ERROR(GLOBUS_GRAM_PROTOCOL_MAX_TIME_PARAM,
GLOBUS_GRAM_PROTOCOL_ERROR_INVALID_MAXTIME)
HANDLE_RSL_ERROR(GLOBUS_GRAM_PROTOCOL_MAX_WALL_TIME_PARAM,
GLOBUS_GRAM_PROTOCOL_ERROR_INVALID_MAX_WALL_TIME)
HANDLE_RSL_ERROR(GLOBUS_GRAM_PROTOCOL_MIN_MEMORY_PARAM,
GLOBUS_GRAM_PROTOCOL_ERROR_INVALID_MIN_MEMORY)
HANDLE_RSL_ERROR(GLOBUS_GRAM_PROTOCOL_PROJECT_PARAM,
GLOBUS_GRAM_PROTOCOL_ERROR_INVALID_PROJECT)
HANDLE_RSL_ERROR(GLOBUS_GRAM_PROTOCOL_QUEUE_PARAM,
GLOBUS_GRAM_PROTOCOL_ERROR_INVALID_QUEUE)
HANDLE_RSL_ERROR(GLOBUS_GRAM_PROTOCOL_SAVE_STATE_PARAM,
GLOBUS_GRAM_PROTOCOL_ERROR_INVALID_SAVE_STATE)
HANDLE_RSL_ERROR(GLOBUS_GRAM_PROTOCOL_SCRATCHDIR_PARAM,
GLOBUS_GRAM_PROTOCOL_ERROR_INVALID_SCRATCH)
HANDLE_RSL_ERROR(GLOBUS_GRAM_PROTOCOL_STDERR_POSITION_PARAM,
GLOBUS_GRAM_PROTOCOL_ERROR_INVALID_STDERR_POSITION)
HANDLE_RSL_ERROR(GLOBUS_GRAM_PROTOCOL_STDOUT_POSITION_PARAM,
GLOBUS_GRAM_PROTOCOL_ERROR_INVALID_STDOUT_POSITION)
HANDLE_RSL_ERROR(GLOBUS_GRAM_PROTOCOL_TWO_PHASE_COMMIT_PARAM,
GLOBUS_GRAM_PROTOCOL_ERROR_INVALID_TWO_PHASE_COMMIT)
HANDLE_RSL_ERROR(GLOBUS_GRAM_PROTOCOL_PROXY_TIMEOUT_PARAM,
GLOBUS_GRAM_PROTOCOL_ERROR_INVALID_PROXY_TIMEOUT)
return GLOBUS_GRAM_PROTOCOL_ERROR_RSL_SCHEDULER_SPECIFIC;
}
/* globus_l_gram_job_manager_validation_value_error() */
static
int
globus_l_gram_job_manager_missing_value_error(
const char * attribute)
{
HANDLE_RSL_ERROR(GLOBUS_GRAM_PROTOCOL_EXECUTABLE_PARAM,
GLOBUS_GRAM_PROTOCOL_ERROR_UNDEFINED_EXE)
return GLOBUS_GRAM_PROTOCOL_ERROR_UNDEFINED_ATTRIBUTE;
}
/* globus_l_gram_job_manager_missing_value_error() */
#endif /* !GLOBUS_DONT_DOCUMENT_INTERNAL */
|