int main (int argc, char **argv ) { int rc; char action[20]; char jid_s[20]; int jid = 0; char contact[500]; char rsl_file[1024]; int status = -1; char info[500]; int end = 0; fd_set in_pipes; int j; char c; char str[4096]; struct timeval tv; int timer_interval = 300; time_t last_timer = 0; time_t the_time; struct timeval t1,t2; double waited; setbuf(stdout,NULL); rc = globus_module_activate(GLOBUS_COMMON_MODULE); if ( rc != GLOBUS_SUCCESS ) return -1; waited = 0; while (!end) { FD_ZERO(&in_pipes); FD_SET (0,&in_pipes); tv.tv_sec = 0; tv.tv_usec = 1000; gettimeofday(&t1, NULL); rc = select(1, &in_pipes, NULL, NULL, &tv); gettimeofday(&t2, NULL); waited += ((t2.tv_sec - t1.tv_sec)*1000000) + (t2.tv_usec - t1.tv_usec); if ( waited > 999 ) { globus_poll(); waited = 0; } if (rc == -1) { exit(-1); } else if (rc == 1) { j = 0; do { rc = read(0, (void *) &c, sizeof(char)); str[j++] = c; } while ( rc > 0 && c != '\n' ); str[j] = '\0'; if (rc <= 0) exit(-1); rc = sscanf(str, "%s %s %s %[^\n]", action, jid_s, contact, rsl_file); if (rc != 4 ) { printf("FAILURE Not all four arguments defined\n"); continue; } jid = atoi(jid_s); if (strcmp(action, "INIT") == 0 ) { status = gw_em_mad_init(jid, info); } else if (strcmp(action, "SUBMIT") == 0 ) { status = gw_em_mad_submit(jid, contact, rsl_file, info); } else if (strcmp(action, "RECOVER") == 0 ) { status = gw_em_mad_recover(jid, contact, info); } else if (strcmp(action, "CANCEL") == 0 ) { status = gw_em_mad_cancel(jid, info); } else if (strcmp(action, "POLL") == 0 ) { status = gw_em_mad_poll(jid, info); } else if (strcmp(action, "FINALIZE") == 0 ) { status = gw_em_mad_finalize(info); end = 1; return 0; } if (status != 0) printf("%s %d FAILURE %s\n", action, jid, info); } the_time = time(NULL); if (the_time - last_timer >= timer_interval) { last_timer = the_time; if (mad.initialized == 1) { status = gw_em_mad_check_credentials(info); if (status != 0) printf("%s %d FAILURE %s\n", action, jid, info); } } } return 0; }
void gw_em_submit(void *_job_id) { int job_id; gw_job_t *job; char *rsl=NULL; char *contact; gw_job_state_t state; char rsl_filename[2048]; FILE *fd; time_t now; /* ----------------------------------------------------------- */ /* 0.- Get job pointer, check if it exits and lock mutex */ /* ----------------------------------------------------------- */ if ( _job_id != NULL ) { job_id = *( (int *) _job_id ); job = gw_job_pool_get(job_id, GW_TRUE); if ( job == NULL ) { gw_log_print("EM",'E',"Job %s no longer exists (PENDING).\n", job_id); return; } } else return; if (job->history == NULL) { gw_log_print("EM",'E',"History of job %s doesn't exists\n", job_id); free(_job_id); pthread_mutex_unlock(&(job->mutex)); return; } state = job->job_state; /* ----------------------------------------------------------- */ /* 1.- Get execution MAD for this host */ /* ----------------------------------------------------------- */ job->em_state = GW_EM_STATE_INIT; job->history->counter = -1; if ( job->job_state == GW_JOB_STATE_PRE_WRAPPER ) { contact = job->history->em_fork_rc; rsl = (char *) job->history->em_mad->pre_wrapper_rsl((void *) job); } else { contact = job->history->em_rc; rsl = (char *) job->history->em_mad->wrapper_rsl((void *) job); } if ( rsl == NULL ) { job->em_state = GW_EM_STATE_FAILED; gw_log_print("EM",'E',"Job %i failed, could not generate RSL.\n", job_id); gw_am_trigger(gw_em.dm_am, "GW_DM_WRAPPER_FAILED", _job_id); pthread_mutex_unlock(&(job->mutex)); return; } sprintf(rsl_filename, "%s/job.rsl.%i", job->directory,job->restarted); fd = fopen(rsl_filename,"w"); if (fd != NULL ) { gw_job_print(job,"EM",'I',"Submitting wrapper to %s, RSL used is in %s.\n",contact,rsl_filename); fprintf(fd,"%s",rsl); fclose(fd); } else { job->em_state = GW_EM_STATE_FAILED; gw_log_print("EM",'E',"Job %i failed, could not open RSL file.\n", job_id); gw_job_print(job,"EM",'E',"Job failed, could not open RSL file %s.\n",rsl_filename); gw_am_trigger(gw_em.dm_am, "GW_DM_WRAPPER_FAILED", _job_id); pthread_mutex_unlock(&(job->mutex)); return; } /* -------------------------------------------------------------------- */ now = time(NULL); job->next_poll_time = now + gw_conf.poll_interval/2 + gw_rand(gw_conf.poll_interval); /* randomize polls */ gw_job_print(job,"EM",'I',"Job will be polled in %d seconds.\n", job->next_poll_time-now); job->last_checkpoint_time = 0; job->history->stats[LAST_SUSPENSION_TIME] = now; job->history->stats[SUSPENSION_TIME] = 0; job->history->stats[ACTIVE_TIME] = 0; job->history->tries++; /* -------------------------------------------------------------------- */ pthread_mutex_unlock(&(job->mutex)); gw_em_mad_submit(job->history->em_mad, job_id, contact, rsl_filename); /* -------------------------------------------------------------------- */ free(_job_id); free(rsl); }