char * prolog_fail(int which_fail) { char *reason; char *jt; int job_id; int deps[GW_JT_DEPS]; int rc; signed long timeout = -1; int exit_code; reason = malloc(sizeof(char)*200); jt = malloc(sizeof(char)*50); if ( gw_session == NULL ) { sprintf(reason,"Could not connect to gwd"); return reason; } deps[0]=-1; switch(which_fail) { case 0: sprintf(jt,"prolog_stdin_nr.jt"); break; case 1: sprintf(jt,"prolog_stdin_r.jt"); break; case 2: sprintf(jt,"prolog_input_nr.jt"); break; case 3: sprintf(jt,"prolog_ex_nr.jt"); break; } if((rc=gw_client_job_submit(jt,GW_JOB_STATE_PENDING,&job_id,deps,GW_JOB_DEFAULT_PRIORITY))!=GW_RC_SUCCESS) { sprintf(reason,"[gw_client_job_submit] %s",gw_ret_code_string(rc)); return reason; } free(jt); rc = gw_client_wait(job_id, &exit_code, timeout); if(rc==GW_RC_FAILED_JOB_FAIL) { sprintf(reason,"OK"); } else { sprintf(reason,"[gw_client_wait] %s",gw_ret_code_string(rc)); } return reason; }
char * kill_sync() { char *reason; char *jt; int job_id; int deps[GW_JT_DEPS]; int rc; gw_msg_job_t job_status; reason = malloc(sizeof(char)*200); jt = malloc(sizeof(char)*50); if ( gw_session == NULL ) { sprintf(reason,"Could not connect to gwd"); return reason; } deps[0]=-1; sprintf(jt,"normal_execution.jt"); // Submit job for synchronous kill if((rc=gw_client_job_submit(jt,GW_JOB_STATE_PENDING,&job_id,deps,GW_JOB_DEFAULT_PRIORITY))!=GW_RC_SUCCESS) { sprintf(reason,"[gw_client_job_submit] %s",gw_ret_code_string(rc)); return reason; } // Blocking kill rc = gw_client_job_signal (job_id, GW_CLIENT_SIGNAL_KILL, GW_TRUE); // Check that it finished in the correct state if((rc = gw_client_job_status(job_id, &job_status))!=GW_RC_FAILED_BAD_JOB_ID) { sprintf(reason,"Wrong job state %s, the job shouldn't exist",gw_job_state_string(job_status.job_state)); return reason; } sprintf(reason,"OK"); return reason; }
char * kill_hard() { char *reason; char *jt; int job_id; int deps[GW_JT_DEPS]; int rc; gw_msg_job_t job_status; reason = malloc(sizeof(char)*200); jt = malloc(sizeof(char)*50); if ( gw_session == NULL ) { sprintf(reason,"Could not connect to gwd"); return reason; } deps[0]=-1; sprintf(jt,"normal_execution.jt"); // Submit job for hard kill if((rc=gw_client_job_submit(jt,GW_JOB_STATE_PENDING,&job_id,deps,GW_JOB_DEFAULT_PRIORITY))!=GW_RC_SUCCESS) { sprintf(reason,"[gw_client_job_submit] %s",gw_ret_code_string(rc)); return reason; } // Non Blocking kill rc = gw_client_job_signal (job_id, GW_CLIENT_SIGNAL_KILL_HARD, GW_FALSE); // Wait for job to disappear from GW do { rc = gw_client_job_status(job_id, &job_status); }while(rc!=GW_RC_FAILED_BAD_JOB_ID); sprintf(reason,"OK"); return reason; }
int main(int argc, char **argv) { int job_id = -1; int array_id = -1; char opt; int a = 0, k = 0, t = 0, o = 0, s = 0, r = 0, l = 0, A = 0, hard=0; gw_client_t * gw_session; gw_boolean_t blocking = GW_TRUE; gw_client_signal_t signal = GW_CLIENT_SIGNAL_KILL; struct sigaction act; gw_return_code_t rc; int mrc; /* ---------------------------------------------------------------- */ /* Parse arguments */ /* ---------------------------------------------------------------- */ opterr = 0; optind = 1; while((opt = getopt(argc, argv, ":haktosrl9A:")) != -1) switch(opt) { case 'a': a = 1; blocking = GW_FALSE; break; case 't': t = 1; signal = GW_CLIENT_SIGNAL_STOP; break; case 'o': o = 1; signal = GW_CLIENT_SIGNAL_HOLD; break; case 's': s = 1; signal = GW_CLIENT_SIGNAL_RESCHEDULE; break; case 'r': r = 1; signal = GW_CLIENT_SIGNAL_RESUME; break; case 'l': l = 1; signal = GW_CLIENT_SIGNAL_RELEASE; break; case 'k': k = 1; signal = GW_CLIENT_SIGNAL_KILL; break; case '9': hard = 1; signal = GW_CLIENT_SIGNAL_KILL_HARD; break; case 'A': A = 1; array_id = atoi(optarg); break; case 'h': printf("%s", usage); exit(0); break; case '?': fprintf(stderr,"error: invalid option \'%c\'\n",optopt); printf("%s", susage); exit(1); break; case ':': fprintf(stderr,"error: must provide an argument for option \'%c\'\n", optopt); printf("%s", susage); exit(1); break; } if ( t+o+s+r+l+k+hard > 1 ) { printf("%s", susage); exit(1); } if (!A) { if (!(optind < argc)) { printf("%s", susage); return -1; } } /* ---------------------------------------------------------------- */ /* Connect to GWD */ /* ---------------------------------------------------------------- */ gw_session = gw_client_init(); if ( gw_session == NULL ) { fprintf(stderr,"Could not connect to gwd\n"); return (-1); } act.sa_handler = signal_handler; act.sa_flags = SA_RESTART; sigemptyset(&act.sa_mask); sigaction(SIGTERM||SIGINT,&act,NULL); if (A) { rc = gw_client_array_signal (array_id, signal, blocking); if ( rc != GW_RC_SUCCESS) { fprintf(stderr,"FAILED: failed could not signal one or more jobs!\n"); mrc = -1; } else mrc = 0; } else { for (;optind<argc;optind++) { job_id = atoi(argv[optind]); rc = gw_client_job_signal (job_id, signal, blocking); if ( rc != GW_RC_SUCCESS) { fprintf(stderr,"FAILED: %s (job %i)\n", gw_ret_code_string(rc),job_id); mrc = -1; } } } gw_client_finalize(); return mrc; }
int main(int argc, char **argv) { int job_id = -1; char opt; int c = 0, n = 0, f = 0, x = 0; int delay = 0; gw_client_t * gw_session; gw_msg_job_t job_status; struct sigaction act; gw_return_code_t rc; char * hostname = NULL; char * username = NULL; char * outoption = NULL; char jobstate = '&'; // If not set to other value all job states will be printed // (see gw_check_state in gw_cmds_common.c) int i; int array_id = -1; /* ---------------------------------------------------------------- */ /* Parse arguments */ /* ---------------------------------------------------------------- */ opterr = 0; optind = 1; while((opt = getopt(argc, argv, ":nfxhc:u:r:s:o:A:")) != -1) switch(opt) { case 'c': c = 1; delay = atoi(optarg); break; case 'n': n = 1; break; case 'f': f = 1; break; case 'x': x = 1; break; case 'u': username = strdup(optarg); break; case 'r': hostname = strdup(optarg); break; case 's': jobstate = strdup(optarg)[0]; switch(jobstate) { case 'i': case 'p': case 'h': case 'w': case 'e': case 's': case 'k': case 'm': case 'z': case 'f': break; default: printf("ERROR: Job state must be one of {i,p,h,w,e,s,k,m,z,f}\n"); printf("%s", susage); return (-1); break; } break; case 'o': outoption = strdup(optarg); int seen_t=0; for(i=0;i<strlen(outoption);i++) switch(outoption[i]) { case 't': if(seen_t) { printf("ERROR: options t and T are mutually exclusive\n"); printf("%s", susage); return (-1); } seen_t++; break; case 'T': if(seen_t) { printf("ERROR: options t and T are mutually exclusive\n"); printf("%s", susage); return (-1); } seen_t++; break; case 'e': case 's': case 'u': case 'j': case 'h': case 'x': case 'i': case 'f': case 'p': case 'J': case 'y': case 'n': break; default: printf("ERROR: Output format must be constructed with {e,s,u,j,t,h,x,i,p,J,y,n}\n"); printf("%s", susage); return (-1); break; } break; case 'A': array_id = atoi(optarg); break; case 'h': printf("%s", usage); exit(0); break; case '?': fprintf(stderr,"error: invalid option \'%c\'\n",optopt); printf("%s", susage); exit(1); break; case ':': fprintf(stderr,"error: must provide an argument for option \'%c\'\n", optopt); printf("%s", susage); exit(1); break; } if ( optind < argc) job_id = atoi(argv[optind]); /* ---------------------------------------------------------------- */ /* Connect to GWD */ /* ---------------------------------------------------------------- */ gw_session = gw_client_init(); if ( gw_session == NULL ) { if(username != NULL) free(username); if(hostname != NULL) free(hostname); if(outoption != NULL) free(outoption); fprintf(stderr,"Could not connect to gwd\n"); return (-1); } act.sa_handler = signal_handler; act.sa_flags = SA_RESTART; sigemptyset(&act.sa_mask); sigaction(SIGTERM||SIGINT,&act,NULL); /* ---------------------------------------------------------------- */ /* Get job or pool status */ /* ---------------------------------------------------------------- */ do { if (c) { cls(); move(0,0); } if (job_id != -1){ rc = gw_client_job_status(job_id, &job_status); } else { rc = gw_client_job_status_all( ); } if (rc == GW_RC_SUCCESS) { if (f) { if (job_id != -1) gw_client_print_status_full(&job_status); else gw_client_print_pool_status_full(username, hostname, jobstate, array_id); } else if (x) { char command[]=GW_PS_COMMAND_XML; char command_open[GW_PS_COMMAND_OPEN_SIZE_XML]; if ( username == NULL && hostname == NULL ){ sprintf (command_open, "%s", command); } else if ( username != NULL && hostname == NULL ){ sprintf (command_open, "%s USERNAME=\"%s\"", command, username); } else if ( username == NULL && hostname != NULL ){ sprintf (command_open, "%s HOSTNAME=\"%s\"", command, hostname); } else if ( username != NULL && hostname != NULL ){ sprintf (command_open, "%s USERNAME=\"%s\" HOSTNAME=\"%s\"", command, username, hostname); } gw_print_xml_header(command_open); if (job_id != -1){ gw_client_print_status_xml(&job_status); } else { gw_client_print_pool_status_xml(username, hostname, jobstate, array_id); } gw_print_xml_footer(command); } else { if (!n) gw_client_print_status_header(outoption); if (job_id != -1) gw_client_print_status(&job_status, outoption); else gw_client_print_pool_status(username, hostname, jobstate, outoption, array_id); } } else { if(username != NULL) free(username); if(hostname != NULL) free(hostname); if(outoption != NULL) free(outoption); fprintf(stderr,"FAILED: %s\n",gw_ret_code_string(rc)); gw_client_finalize(); return -1; } sleep(delay); } while(c); if(username != NULL) free(username); if(hostname != NULL) free(hostname); if(outoption != NULL) free(outoption); return 0; }
char * normal_execution_bulk() { char *reason; int *job_ids; int *ot_ids; int deps[GW_JT_DEPS]; int rc; int *exit_codes; gw_msg_job_t job_status; int array_id; int i; int num_of_tasks = 5; signed long timeout = -1; reason = malloc(sizeof(char)*200); if ( gw_session == NULL ) { sprintf(reason,"Could not connect to gwd"); return reason; } deps[0]=-1; // Submit jobs if((rc = gw_client_array_submit("normal_execution.jt",num_of_tasks,GW_JOB_STATE_PENDING,&array_id,&job_ids,deps,0,1,GW_JOB_DEFAULT_PRIORITY))!=GW_RC_SUCCESS) { sprintf(reason,"[gw_client_array_submit] %s",gw_ret_code_string(rc)); return reason; } /*realloc(job_ids,sizeof(int)*num_of_tasks+1); job_ids[num_of_tasks] = -1;*/ ot_ids=malloc(sizeof(int)*num_of_tasks+1); for(i=0;i<num_of_tasks;i++) *(ot_ids+i)=*(job_ids+i); ot_ids[num_of_tasks] = -1; if((rc = gw_client_wait_set(ot_ids,&exit_codes,GW_FALSE,timeout)!=GW_RC_SUCCESS)) { sprintf(reason,"[gw_client_wait_set] %s",gw_ret_code_string(rc)); fflush(NULL); return reason; } for(i=0;i<num_of_tasks;i++) { if(exit_codes[i]!=0) { sprintf(reason,"Wrong exit code %d in task number %i",exit_codes[i],i); return reason; } if((rc = gw_client_job_status(ot_ids[i], &job_status))!=GW_RC_SUCCESS) { sprintf(reason,"[gw_client_job_status] %s",gw_ret_code_string(rc)); return reason; } else if(strcmp(gw_job_state_string(job_status.job_state),"done")!=0) { sprintf(reason,"Wrong job state %s for job %d",gw_job_state_string(job_status.job_state),i); return reason; } printf(" Task %d finished with code %d and state \"done\"\n",ot_ids[i],exit_codes[i]); } sprintf(reason,"OK"); return reason; }
/** prewrapper != 0 then use prewrapper.jt **/ char * normal_execution(int prewrapper) { char *reason; char *jt; int job_id; int deps[GW_JT_DEPS]; int rc; signed long timeout = -1; int exit_code; gw_msg_job_t job_status; reason = malloc(sizeof(char)*200); jt = malloc(sizeof(char)*50); if ( gw_session == NULL ) { sprintf(reason,"Could not connect to gwd"); return reason; } deps[0]=-1; if(prewrapper) sprintf(jt,"pre_wrapper.jt"); else sprintf(jt,"normal_execution.jt"); if((rc=gw_client_job_submit(jt,GW_JOB_STATE_PENDING,&job_id,deps,GW_JOB_DEFAULT_PRIORITY))!=GW_RC_SUCCESS) { sprintf(reason,"[gw_client_job_submit] %s",gw_ret_code_string(rc)); return reason; } free(jt); // Wait for the job if((rc = gw_client_wait(job_id, &exit_code, timeout)!=GW_RC_SUCCESS)) { sprintf(reason,"[gw_client_wait] %s",gw_ret_code_string(rc)); return reason; } if(exit_code!=0) { sprintf(reason,"Wrong exit code %d",exit_code); return reason; } if((rc = gw_client_job_status(job_id, &job_status))!=GW_RC_SUCCESS) { sprintf(reason,"[gw_client_job_status] %s",gw_ret_code_string(rc)); return reason; } else if(strcmp(gw_job_state_string(job_status.job_state),"done")!=0) { sprintf(reason,"Wrong job state %s",gw_job_state_string(job_status.job_state)); return reason; } sprintf(reason,"OK"); return reason; }
char * epilog_fail_bulk() { char *reason; int *job_ids; int *ot_ids; int deps[GW_JT_DEPS]; int rc; int *exit_codes; gw_msg_job_t job_status; int array_id; int i; int num_of_tasks = 5; signed long timeout = -1; reason = malloc(sizeof(char)*200); if ( gw_session == NULL ) { sprintf(reason,"Could not connect to gwd"); return reason; } deps[0]=-1; // Submit jobs if((rc = gw_client_array_submit("epilog_output_nr.jt",num_of_tasks,GW_JOB_STATE_PENDING,&array_id,&job_ids,deps,0,1,GW_JOB_DEFAULT_PRIORITY))!=GW_RC_SUCCESS) { sprintf(reason,"[gw_client_array_submit] %s",gw_ret_code_string(rc)); return reason; } /*realloc(job_ids,sizeof(int)*num_of_tasks+1); job_ids[num_of_tasks] = -1;*/ ot_ids=malloc(sizeof(int)*num_of_tasks+1); for(i=0;i<num_of_tasks;i++) *(ot_ids+i)=*(job_ids+i); ot_ids[num_of_tasks] = -1; // Wait for the array (all of them) if((rc = gw_client_wait_set(ot_ids,&exit_codes,GW_FALSE,timeout))!=GW_RC_FAILED_JOB_FAIL) { sprintf(reason,"[gw_client_wait_set] %s",gw_ret_code_string(rc)); fflush(NULL); return reason; } for(i=0;i<num_of_tasks;i++) { if((rc = gw_client_job_status(ot_ids[i], &job_status))!=GW_RC_SUCCESS) { sprintf(reason,"[gw_client_job_status] %s",gw_ret_code_string(rc)); return reason; } if(job_status.job_state==GW_JOB_STATE_FAILED) printf(" Task %d finished with state failed.\n",ot_ids[i]); else { sprintf(reason,"Wrong job state for task %d (job state = %s)",ot_ids[i],gw_job_state_string(job_status.job_state)); return reason; } } unlink("doesnt_exist.txt"); sprintf(reason,"OK"); return reason; }
char * input_output() { char *reason; char *jt; int job_id; int deps[GW_JT_DEPS]; int rc; int exit_code; gw_msg_job_t job_status; struct stat buf; reason = malloc(sizeof(char)*200); jt = malloc(sizeof(char)*50); if ( gw_session == NULL ) { sprintf(reason,"Could not connect to gwd"); return reason; } deps[0]=-1; sprintf(jt,"input_output_files.jt"); if((rc=gw_client_job_submit(jt,GW_JOB_STATE_PENDING,&job_id,deps,GW_JOB_DEFAULT_PRIORITY))!=GW_RC_SUCCESS) { sprintf(reason,"[gw_client_job_submit] %s",gw_ret_code_string(rc)); return reason; } free(jt); while((rc = gw_client_wait(job_id, &exit_code, -1)!=GW_RC_SUCCESS)) { printf(" Still waiting for job %d to finish.\n",job_id); fflush(NULL); sleep(2); } if((rc = gw_client_job_status(job_id, &job_status))!=GW_RC_SUCCESS) { sprintf(reason,"[gw_client_job_status] %s",gw_ret_code_string(rc)); return reason; } else if(strcmp(gw_job_state_string(job_status.job_state),"done")!=0) { sprintf(reason,"Wrong job state %s",gw_job_state_string(job_status.job_state)); return reason; } // Check files were created correctly // Absolut path output if( stat("/tmp/test.txt.out",&buf) != 0 ) { sprintf(reason,"Absolut path output file not found"); return reason; } unlink("/tmp/test.txt.out"); // Relative path output if( stat("passwd.out",&buf) != 0 ) { sprintf(reason,"Relative path output file not found"); return reason; } unlink("passwd.out"); // gsiftp output if( stat("/tmp/passwd.gsi",&buf) != 0 ) { sprintf(reason,"Gsiftp output file not found"); return reason; } unlink("/tmp/passwd.gsi"); sprintf(reason,"OK"); return reason; }
char * checkpoint(int which_jt) { char *reason; char *jt; int job_id; int deps[GW_JT_DEPS]; int rc; gw_msg_job_t job_status; struct stat buf; int exit_code; signed long timeout = -1; reason = malloc(sizeof(char)*200); jt = malloc(sizeof(char)*50); if ( gw_session == NULL ) { sprintf(reason,"Could not connect to gwd"); return reason; } deps[0]=-1; switch(which_jt) { case 0: sprintf(jt,"checkpoint.jt"); break; case 1: sprintf(jt,"checkpoint_gsiftp.jt"); break; } // Submit job if((rc=gw_client_job_submit(jt,GW_JOB_STATE_PENDING,&job_id,deps,GW_JOB_DEFAULT_PRIORITY))!=GW_RC_SUCCESS) { sprintf(reason,"[gw_client_job_submit] %s",gw_ret_code_string(rc)); return reason; } // Wait for the job if((rc = gw_client_wait(job_id, &exit_code, timeout)!=GW_RC_SUCCESS)) { sprintf(reason,"[gw_client_wait] %s",gw_ret_code_string(rc)); return reason; } if(exit_code!=0) { sprintf(reason,"Wrong exit code %d",exit_code); return reason; } if((rc = gw_client_job_status(job_id, &job_status))!=GW_RC_SUCCESS) { sprintf(reason,"[gw_client_job_status] %s",gw_ret_code_string(rc)); return reason; } else if(strcmp(gw_job_state_string(job_status.job_state),"done")!=0) { sprintf(reason,"Wrong job state %s",gw_job_state_string(job_status.job_state)); return reason; } if( stat("outfile",&buf) != 0 ) { sprintf(reason,"Checkpointing file not found"); return reason; } unlink("outfile"); sprintf(reason,"OK"); return reason; }
char * migrate() { char *reason; char *jt; int job_id; int deps[GW_JT_DEPS]; int rc; gw_msg_job_t job_status; int exit_code; signed long timeout = -1; reason = malloc(sizeof(char)*200); jt = malloc(sizeof(char)*50); if ( gw_session == NULL ) { sprintf(reason,"Could not connect to gwd"); return reason; } deps[0]=-1; sprintf(jt,"migration.jt"); // Submit job for migration if((rc=gw_client_job_submit(jt,GW_JOB_STATE_PENDING,&job_id,deps,GW_JOB_DEFAULT_PRIORITY))!=GW_RC_SUCCESS) { sprintf(reason,"[gw_client_job_submit] %s",gw_ret_code_string(rc)); return reason; } // Wait for wrapper state do { if((rc = gw_client_job_status(job_id, &job_status))!=GW_RC_SUCCESS) { sprintf(reason,"[gw_client_job_status] %s",gw_ret_code_string(rc)); return reason; } sleep(1); }while(strcmp(gw_job_state_string(job_status.job_state),"wrap")!=0); // Send migrate signal rc = gw_client_job_signal (job_id, GW_CLIENT_SIGNAL_RESCHEDULE, GW_FALSE); printf(" Migrating job %d\n",job_id); fflush(NULL); // Wait for the job if((rc = gw_client_wait(job_id, &exit_code, timeout)!=GW_RC_SUCCESS)) { sprintf(reason,"[gw_client_wait] %s",gw_ret_code_string(rc)); return reason; } if(exit_code!=0) { sprintf(reason,"Wrong exit code %d",exit_code); return reason; } if((rc = gw_client_job_status(job_id, &job_status))!=GW_RC_SUCCESS) { sprintf(reason,"[gw_client_job_status] %s",gw_ret_code_string(rc)); return reason; } else if(strcmp(gw_job_state_string(job_status.job_state),"done")!=0) { sprintf(reason,"Wrong job state %s",gw_job_state_string(job_status.job_state)); return reason; } sprintf(reason,"OK"); return reason; }
char * stop_resume() { char *reason; char *jt; int job_id; int deps[GW_JT_DEPS]; int rc; signed long timeout = -1; int exit_code; gw_msg_job_t job_status; reason = malloc(sizeof(char)*200); jt = malloc(sizeof(char)*50); if ( gw_session == NULL ) { sprintf(reason,"Could not connect to gwd"); return reason; } deps[0]=-1; sprintf(jt,"normal_execution.jt"); // Submit job printf(" Submitting job\n"); fflush(NULL); if((rc=gw_client_job_submit(jt,GW_JOB_STATE_PENDING,&job_id,deps,GW_JOB_DEFAULT_PRIORITY))!=GW_RC_SUCCESS) { sprintf(reason,"[gw_client_job_submit] %s",gw_ret_code_string(rc)); return reason; } // Wait for wrapper state do { if((rc = gw_client_job_status(job_id, &job_status))!=GW_RC_SUCCESS) { sprintf(reason,"[gw_client_job_status] %s",gw_ret_code_string(rc)); return reason; } sleep(1); }while(strcmp(gw_job_state_string(job_status.job_state),"wrap")!=0); // Stop the job rc = gw_client_job_signal (job_id, GW_CLIENT_SIGNAL_STOP, GW_TRUE); printf(" Job stopped\n"); fflush(NULL); // Wait for stop state do { if((rc = gw_client_job_status(job_id, &job_status))!=GW_RC_SUCCESS) { sprintf(reason,"[gw_client_job_status] %s",gw_ret_code_string(rc)); return reason; } }while(strcmp(gw_job_state_string(job_status.job_state),"stop")!=0); // Resume the job rc = gw_client_job_signal (job_id, GW_CLIENT_SIGNAL_RESUME, GW_TRUE); printf(" Job resumed\n"); fflush(NULL); // Wait for the job to finish if((rc = gw_client_wait(job_id, &exit_code, timeout))!=GW_RC_SUCCESS) { sprintf(reason,"[gw_client_wait] %s",gw_ret_code_string(rc)); return reason; } if(exit_code!=0) { sprintf(reason,"Wrong exit code %d",exit_code); return reason; } // Check that it finished in the correct state if((rc = gw_client_job_status(job_id, &job_status))!=GW_RC_SUCCESS) { sprintf(reason,"[gw_client_job_status] %s",gw_ret_code_string(rc)); return reason; } else if(strcmp(gw_job_state_string(job_status.job_state),"done")!=0) { sprintf(reason,"Wrong job state %s",gw_job_state_string(job_status.job_state)); return reason; } sprintf(reason,"OK"); return reason; }
char * hold_release() { char *reason; char *jt; int job_id; int deps[GW_JT_DEPS]; int rc; signed long timeout = -1; int exit_code; gw_msg_job_t job_status; reason = malloc(sizeof(char)*200); jt = malloc(sizeof(char)*50); if ( gw_session == NULL ) { sprintf(reason,"Could not connect to gwd"); return reason; } deps[0]=-1; sprintf(jt,"normal_execution.jt"); // Submit job in hold if((rc=gw_client_job_submit(jt,GW_JOB_STATE_HOLD,&job_id,deps,GW_JOB_DEFAULT_PRIORITY))!=GW_RC_SUCCESS) { sprintf(reason,"[gw_client_job_submit] %s",gw_ret_code_string(rc)); return reason; } // Check that it's being submitted in hold if((rc = gw_client_job_status(job_id, &job_status))!=GW_RC_SUCCESS) { sprintf(reason,"[gw_client_job_status] %s",gw_ret_code_string(rc)); return reason; } else if(strcmp(gw_job_state_string(job_status.job_state),"hold")!=0) { sprintf(reason,"Wrong job state %s",gw_job_state_string(job_status.job_state)); return reason; } // Release it rc = gw_client_job_signal (job_id, GW_CLIENT_SIGNAL_RELEASE, GW_TRUE); // Wait for the job to finish if((rc = gw_client_wait(job_id, &exit_code, timeout))!=GW_RC_SUCCESS) { sprintf(reason,"[gw_client_wait] %s",gw_ret_code_string(rc)); return reason; } if(exit_code!=0) { sprintf(reason,"Wrong exit code %d",exit_code); return reason; } // Check that it finished in the correct state if((rc = gw_client_job_status(job_id, &job_status))!=GW_RC_SUCCESS) { sprintf(reason,"[gw_client_job_status] %s",gw_ret_code_string(rc)); return reason; } else if(strcmp(gw_job_state_string(job_status.job_state),"done")!=0) { sprintf(reason,"Wrong job state %s",gw_job_state_string(job_status.job_state)); return reason; } sprintf(reason,"OK"); return reason; }
char * execution_fail(int which_fail) { char *reason; char *jt; int job_id; int deps[GW_JT_DEPS]; int rc; signed long timeout = -1; int exit_code; gw_msg_job_t job_status; reason = malloc(sizeof(char)*200); jt = malloc(sizeof(char)*50); if ( gw_session == NULL ) { sprintf(reason,"Could not connect to gwd"); return reason; } deps[0]=-1; switch(which_fail) { case 0: sprintf(jt,"failed_execution_no_reschedule.jt"); break; case 1: sprintf(jt,"failed_execution_reschedule.jt"); break; } if((rc=gw_client_job_submit(jt,GW_JOB_STATE_PENDING,&job_id,deps,GW_JOB_DEFAULT_PRIORITY))!=GW_RC_SUCCESS) { sprintf(reason,"[gw_client_job_submit] %s",gw_ret_code_string(rc)); return reason; } free(jt); // Wait for the job if((rc = gw_client_wait(job_id, &exit_code, timeout))!=GW_RC_SUCCESS) { sprintf(reason,"[gw_client_wait] %s",gw_ret_code_string(rc)); return reason; } if(exit_code!=1) { sprintf(reason,"Wrong exit code %d",exit_code); return reason; } if((rc = gw_client_job_status(job_id, &job_status))!=GW_RC_SUCCESS) { sprintf(reason,"[gw_client_job_status] %s",gw_ret_code_string(rc)); return reason; } else if(strcmp(gw_job_state_string(job_status.job_state),"done")!=0) { sprintf(reason,"Wrong job state %s",gw_job_state_string(job_status.job_state)); return reason; } sprintf(reason,"OK"); return reason; }
int main(int argc, char **argv) { int job_id[MAX_JOBS_WAIT]; int i; int number_of_jobs; int array_id = -1; int error = 0; char opt; int exit_code; int * exit_codes; int a = 0, A = 0, v = 0, k = 0; signed long timeout = -1; gw_client_t * gw_session; gw_boolean_t any = GW_FALSE; struct sigaction act; gw_return_code_t rc; /* ---------------------------------------------------------------- */ /* Parse arguments */ /* ---------------------------------------------------------------- */ opterr = 0; optind = 1; while((opt = getopt(argc,argv,":hkavt:A:"))!= -1) switch(opt) { case 'h': printf("%s", usage); exit(0); break; case 'v': v = 1; break; case 'a': a = 1; any = GW_TRUE; break; case 'A': A = 1; array_id = atoi(optarg); break; case 't': timeout = atoi(optarg); break; case 'k': k = 1; break; case '?': fprintf(stderr,"error: invalid option \'%c\'\n",optopt); printf("%s", susage); exit(1); break; case ':': fprintf(stderr,"error: must provide an argument for option \'%c\'\n", optopt); printf("%s", susage); exit(1); break; } /* ---------------------------------------------------------------- */ /* Connect to GWD */ /* ---------------------------------------------------------------- */ gw_session = gw_client_init(); if ( gw_session == NULL ) { fprintf(stderr,"Could not connect to gwd\n"); return (-1); } act.sa_handler = signal_handler; act.sa_flags = SA_RESTART; sigemptyset(&act.sa_mask); sigaction(SIGTERM||SIGINT,&act,NULL); /* ---------------------------------------------------------------- */ /* Set job id array */ /* ---------------------------------------------------------------- */ if (!A) { if (optind < argc) { number_of_jobs = 0; while ( optind < argc ) { job_id[number_of_jobs++] = atoi(argv[optind++]); if (number_of_jobs >= (MAX_JOBS_WAIT - 1) ) { fprintf(stderr,"FAILED: Max number of jobs reached\n"); error = 1; } } job_id[number_of_jobs] = -1; } else { printf("%s",susage); error = 1; } } else { rc = gw_client_job_status_all( ); if (rc == GW_RC_SUCCESS) { number_of_jobs = 0; for (i=0; i<gw_client.number_of_jobs; i++) if (gw_client.job_pool[i] != NULL) if (gw_client.job_pool[i]->array_id == array_id) { job_id[number_of_jobs++] = gw_client.job_pool[i]->id; if (number_of_jobs>=(MAX_JOBS_WAIT - 1)) { fprintf(stderr,"FAILED: Max number of jobs reached\n"); error = 1; } } job_id[number_of_jobs] = -1; if (number_of_jobs == 0) { fprintf(stderr,"FAILED: failed bad array id\n"); error = 1; } } else { fprintf(stderr,"FAILED: %s\n",gw_ret_code_string(rc)); error = 1; } } if (error) { gw_client_finalize(); return -1; } /* ---------------------------------------------------------------- */ /* Wait for the jobs */ /* ---------------------------------------------------------------- */ if ( number_of_jobs == 1 ) { rc = gw_client_wait(job_id[0], &exit_code, timeout); if ( rc == GW_RC_SUCCESS ) { if (v) { printf("%i\n",exit_code); } if (!k) { gw_client_job_signal(job_id[0],GW_CLIENT_SIGNAL_KILL,GW_FALSE); } } } else { rc = gw_client_wait_set(job_id,&exit_codes,any,timeout); if (rc == GW_RC_SUCCESS) { if (any) { if (v) { printf("%i: %i\n",job_id[0],exit_codes[0]); } if (!k) { gw_client_job_signal(job_id[0],GW_CLIENT_SIGNAL_KILL,GW_FALSE); } } else { for (i=0; i<number_of_jobs; i++) { if (v) { printf("%-4i: %i\n",job_id[i],exit_codes[i]); } if (!k) { gw_client_job_signal(job_id[i],GW_CLIENT_SIGNAL_KILL,GW_FALSE); } } } } free(exit_codes); } gw_client_finalize(); if ( rc != GW_RC_SUCCESS) { fprintf(stderr,"FAILED: %s\n",gw_ret_code_string(rc)); return -1; } else return 0; }
char * wait_timeout(int _timeout) { char *reason; char *jt; int job_id; int deps[GW_JT_DEPS]; int rc; signed long timeout=0; int exit_code; gw_msg_job_t job_status; reason = malloc(sizeof(char)*200); jt = malloc(sizeof(char)*50); if ( gw_session == NULL ) { sprintf(reason,"Could not connect to gwd"); return reason; } deps[0]=-1; sprintf(jt,"normal_execution.jt"); if((rc=gw_client_job_submit(jt,GW_JOB_STATE_PENDING,&job_id,deps,GW_JOB_DEFAULT_PRIORITY))!=GW_RC_SUCCESS) { sprintf(reason,"[gw_client_job_submit] %s",gw_ret_code_string(rc)); return reason; } free(jt); // by default, zerotimeout if(_timeout==0) timeout = 5; while((rc = gw_client_wait(job_id, &exit_code, timeout)!=GW_RC_SUCCESS)) { printf(" Still waiting for job %d to finish.\n",job_id); fflush(NULL); sleep(2); } if(exit_code!=0) { sprintf(reason,"Wrong exit code %d",exit_code); return reason; } if((rc = gw_client_job_status(job_id, &job_status))!=GW_RC_SUCCESS) { sprintf(reason,"[gw_client_job_status] %s",gw_ret_code_string(rc)); return reason; } else if(strcmp(gw_job_state_string(job_status.job_state),"done")!=0) { sprintf(reason,"Wrong job state %s",gw_job_state_string(job_status.job_state)); return reason; } sprintf(reason,"OK"); return reason; }
int main(int argc, char **argv) { char opt; int n = 0, x = 0; gw_client_t * gw_session; int num_users, i; gw_msg_user_t * user_status; struct sigaction act; gw_return_code_t rc; /* ---------------------------------------------------------------- */ /* Parse arguments */ /* ---------------------------------------------------------------- */ opterr = 0; optind = 1; while((opt = getopt(argc,argv,"nhx"))!= -1) switch(opt) { case 'n': n = 1; break; case 'x': x = 1; break; case 'h': printf("%s", usage); exit(0); break; case '?': fprintf(stderr,"error: invalid option \'%c\'\n",optopt); printf("%s", susage); exit(1); break; } /* ---------------------------------------------------------------- */ /* Connect to GWD */ /* ---------------------------------------------------------------- */ gw_session = gw_client_init(); if ( gw_session == NULL ) { fprintf(stderr,"Could not connect to gwd\n"); return (-1); } act.sa_handler = signal_handler; act.sa_flags = SA_RESTART; sigemptyset(&act.sa_mask); sigaction(SIGTERM||SIGINT,&act,NULL); /* ---------------------------------------------------------------- */ /* Get job or pool status */ /* ---------------------------------------------------------------- */ rc = gw_client_user_status(&user_status, &num_users); if (rc == GW_RC_SUCCESS) { if (x){ // A.L: It would be nice to include all this settings for header and footer // in the gw_client_print_user_xml function char command[]="gwuser"; int xml_header_flag = 1, xml_footer_flag = 1; if ( xml_header_flag ){ gw_print_xml_header(command); xml_header_flag = 0; } for (i=0;i<num_users;i++){ gw_client_print_user_xml(&(user_status[i])); } if ( xml_footer_flag ){ gw_print_xml_footer(command); xml_footer_flag = 0; } } else { if (!n) gw_client_print_user_header(); for (i=0;i<num_users;i++) gw_client_print_user(&(user_status[i])); } gw_client_finalize(); } else { fprintf(stderr,"FAILED: %s\n",gw_ret_code_string(rc)); gw_client_finalize(); return -1; } return 0; }
int main(int argc, char **argv) { char opt; int n = 0, u = 0, r = 0; char * name = NULL; #ifdef HAVE_LIBDB gw_acct_t **accts; gw_return_code_t rc; int num; #endif struct sigaction act; /* ---------------------------------------------------------------- */ /* Parse arguments */ /* ---------------------------------------------------------------- */ opterr = 0; optind = 1; while((opt = getopt(argc,argv,":nhu:r:"))!= -1) switch(opt) { case 'n': n = 1; break; case 'h': printf("%s", usage); exit(0); break; case 'u': if ( name != NULL ) free(name); name = strdup(optarg); u = 1; break; case 'r': if ( name != NULL ) free(name); name = strdup(optarg); r = 1; break; case '?': fprintf(stderr,"error: invalid option \'%c\'\n",optopt); printf("%s", susage); exit(1); break; case ':': fprintf(stderr,"error: must provide an argument for option \'%c\'\n", optopt); printf("%s", susage); exit(1); break; } if (((u == 1) && (r == 1)) || ((u==0) && (r == 0))) { if ( name != NULL ) free(name); printf("%s", susage); exit(1); } act.sa_handler = signal_handler; act.sa_flags = SA_RESTART; sigemptyset(&act.sa_mask); sigaction(SIGTERM||SIGINT,&act,NULL); /* ---------------------------------------------------------------- */ /* Get acct info */ /* ---------------------------------------------------------------- */ #ifdef HAVE_LIBDB if ( u == 1 ) rc = gw_client_user_accts(name, &accts, &num); else rc = gw_client_host_accts(name, &accts, &num); if (rc == GW_RC_SUCCESS) { if (num == 0) { fprintf(stderr,"FAILED: No records found for %s.\n",name); free(name); return -1; } if (!n) { if ( u == 1 ) gw_client_print_user_accts_header(name); else gw_client_print_host_accts_header(name); } gw_client_print_accts(accts, num); } else { fprintf(stderr,"FAILED: %s\n",gw_ret_code_string(rc)); free(name); return -1; } #else fprintf(stderr,"FAILED: Berkley Database support not compiled in GridWay\n"); #endif free(name); return 0; }