static bool eval_rsl (const char * name, const classad::ArgumentList &arguments, classad::EvalState &state, classad::Value &result) { if (arguments.size() != 1) { std::stringstream ss; result.SetErrorValue(); ss << "Invalid number of arguments passed to " << name << "; " << arguments.size() << "given, 1 required."; classad::CondorErrMsg = ss.str(); return false; } std::string rsl_string; classad::Value rsl_value; if (!arguments[0]->Evaluate(state, rsl_value) || (!rsl_value.IsStringValue(rsl_string))) { result.SetErrorValue(); std::string unp_string; std::stringstream ss; classad::ClassAdUnParser unp; unp.Unparse(unp_string, arguments[0]); ss << "Could not evaluate the first argument of " << name << " to string. Expression: " << unp_string << "."; classad::CondorErrMsg = ss.str(); return false; } if (rsl_string[0] == '(') { rsl_string = "&" + rsl_string; } globus_rsl_t *rsl = globus_rsl_parse(const_cast<char*>(rsl_string.c_str())); if (!rsl) { std::stringstream ss; result.SetErrorValue(); ss << "Unable to parse string to RSL: " << rsl_string; classad::CondorErrMsg = ss.str(); return false; } classad::ClassAd *ad = new classad::ClassAd(); if (!rsl_to_classad(rsl, *ad)) { result.SetErrorValue(); std::stringstream ss; ss << "Unable to convert RSL to ClassAd: " << rsl_string; globus_rsl_free_recursive(rsl); return false; } result.SetClassAdValue(ad); globus_rsl_free_recursive(rsl); return true; }
/** * 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; }