int DC_initMaster(const char *config_file) { char *cfgval; int ret; _DC_init_common(); if (!config_file) config_file = DC_CONFIG_FILE; ret = _DC_parseCfg(config_file); if (ret) { DC_log(LOG_ERR, "The DC-API cannot be initialized without a " "config file"); return ret; } /* Check the working directory */ cfgval = DC_getCfgStr(CFG_WORKDIR); if (!cfgval) { DC_log(LOG_ERR, "%s is not specified in the config file", CFG_WORKDIR); return DC_ERR_CONFIG; } free(cfgval); /* Check sleep interval */ sleep_interval = DC_getCfgInt(CFG_SLEEPINTERVAL, DEFAULT_SLEEP_INTERVAL); if (sleep_interval < 1) sleep_interval = 1; /* Check the project UUID */ cfgval = DC_getCfgStr(CFG_INSTANCEUUID); if (!cfgval) { DC_log(LOG_ERR, "%s is not set in the config file", CFG_INSTANCEUUID); return DC_ERR_CONFIG; } ret = uuid_parse((char *)cfgval, project_uuid); if (ret) { DC_log(LOG_ERR, "Invalid project UUID"); free(cfgval); return DC_ERR_CONFIG; } free(cfgval); /* Enforce a canonical string representation of the UUID */ uuid_unparse_lower(project_uuid, project_uuid_str); return DC_OK; }
/* Submits a work unit. */ int DC_submitWU(DC_Workunit *wu) { int ret; /*GString *fn;*/ char *id; int tries; int sleeptime; int maxtries; if (!_DC_wu_check(wu)) return(DC_ERR_UNKNOWN_WU); DC_log(LOG_DEBUG, "DC_submitWU(%p-\"%s\")", wu, wu->data.name); if (wu->data.state != DC_WU_READY) { DC_log(LOG_INFO, "Re-submission of %s", wu->data.name); return(DC_ERR_BADPARAM); } ret= _DC_wu_gen_condor_submit(wu); if (ret) { DC_log(LOG_ERR, "Submit file generation failed"); return(ret); } /*fn= g_string_new(wu->workdir);*/ /*fn= g_string_append(fn, "/condor_submit.txt");*/ tries=0; sleeptime= DC_getCfgInt("SubmitRetrySleepTime", 2); maxtries = DC_getCfgInt("SubmitRetry", 5); do { ret= _DC_start_condor_job(wu); tries++; if (ret != 0) { if (tries > maxtries) break; DC_log(LOG_INFO, "Failed to submit WU to Condor. Sleeping for %d seconds and retrying (%d of %d)", sleeptime, tries, maxtries); sleep(sleeptime); sleeptime*=2; } } while (ret != 0); if (ret == 0) { /* Fix #1105 */ _DC_wu_set_state(wu, DC_WU_RUNNING); _DC_wu_update_condor_events(wu); while (wu->condor_events->len == 0) { sleep(1); _DC_wu_update_condor_events(wu); } /*_DC_wu_set_state(wu, DC_WU_RUNNING);*/ id= DC_getWUId(wu); DC_log(LOG_INFO, "Condor id of wu's job: %s", id); g_free(id); } return(ret); }