int edg_wll_IncSequenceCode(edg_wll_Context ctx) { edg_wll_ResetError(ctx); switch (ctx->p_seqcode.type) { case EDG_WLL_SEQ_CREAM: /* fall through */ case EDG_WLL_SEQ_PBS: /* fall through */ case EDG_WLL_SEQ_DUPLICATE: /* fall through */ case EDG_WLL_SEQ_NORMAL: if (ctx->p_source <= EDG_WLL_SOURCE_NONE || ctx->p_source >= EDG_WLL_SOURCE__LAST) { return edg_wll_SetError(ctx,EINVAL, "edg_wll_IncSequenceCode(): context param: source missing"); } ctx->p_seqcode.c[ctx->p_source]++; break; default: break; } return edg_wll_Error(ctx, NULL, NULL); }
static int get_jobid_suffix(edg_wll_Context ctx, glite_jobid_const_t job, enum edg_wll_StatJobtype jobtype, char **unique, char **suffix) { char *ptr = NULL, *dbjob = NULL; dbjob = glite_jobid_getUnique(job); switch (jobtype) { case EDG_WLL_STAT_SIMPLE: case EDG_WLL_STAT_DAG: case EDG_WLL_STAT__PARTITIONABLE_UNUSED: case EDG_WLL_STAT__PARTITIONED_UNUSED: case EDG_WLL_STAT_COLLECTION: case EDG_WLL_STAT_CREAM: case EDG_WLL_STAT_FILE_TRANSFER: case EDG_WLL_STAT_FILE_TRANSFER_COLLECTION: // glite jobs, no suffix *suffix = strdup(""); *unique = strdup(dbjob); break; case EDG_WLL_STAT_PBS: // PBS jobs; suffix is everything starting from first '.' ptr = strchr(dbjob,'.'); if (ptr) { *suffix = strdup(ptr); ptr[0] = '\0'; *unique = strdup(dbjob); ptr[0] = '.'; } else { edg_wll_SetError(ctx,EINVAL,"Uknown PBS job format"); goto err; } break; case EDG_WLL_STAT_CONDOR: // condor jobs assert(0); // XXX: todo break; default: edg_wll_SetError(ctx,EINVAL,"Uknown job type"); goto err; break; } err: free(dbjob); return edg_wll_Error(ctx, NULL, NULL); }
static int purge_one_with_subjobs(edg_wll_Context ctx, purge_ctx_t *prg, edg_wll_JobStat *stat, const edg_wll_PurgeRequest *request, edg_wll_PurgeResult *result) { char *job_s; int i; if (purge_one(ctx,stat,prg->dumpfile,request->flags&EDG_WLL_PURGE_REALLY_PURGE,ctx->isProxy)) return edg_wll_Error(ctx, NULL, NULL); purge_throttle(prg); /* XXX: change with the streaming interface */ if (request->flags & EDG_WLL_PURGE_LIST_JOBS) { job_s = glite_jobid_unparse(stat->jobId); if (prg->naffected_jobs % GRAN == 0 || !result->jobs) result->jobs = realloc(result->jobs,(prg->naffected_jobs+GRAN+1) * sizeof(*(result->jobs))); result->jobs[prg->naffected_jobs] = job_s; result->jobs[prg->naffected_jobs+1] = NULL; } prg->naffected_jobs++; /* purge the subjobs */ if (stat->children_num && stat->children) { for (i = 0; i < stat->children_num && stat->children[i]; i++) { if (purge_one(ctx, stat->children_states + i, prg->dumpfile, request->flags&EDG_WLL_PURGE_REALLY_PURGE,ctx->isProxy)) { return edg_wll_Error(ctx, NULL, NULL); } purge_throttle(prg); if (request->flags & EDG_WLL_PURGE_LIST_JOBS) { if (prg->naffected_jobs % GRAN == 0 || !result->jobs) result->jobs = realloc(result->jobs,(prg->naffected_jobs+GRAN+1) * sizeof(*(result->jobs))); result->jobs[prg->naffected_jobs] = strdup(stat->children[i]); result->jobs[prg->naffected_jobs+1] = NULL; } prg->naffected_jobs++; } } return edg_wll_Error(ctx, NULL, NULL); }
static void unlock_and_check(edg_wll_Context ctx,edg_wlc_JobId job) { char *job_s,*et,*ed; if (edg_wll_UnlockJob(ctx,job)) { job_s = edg_wlc_JobIdUnparse(job); edg_wll_Error(ctx,&et,&ed); fprintf(stderr,"%s: edg_wll_UnlockJob(): %s (%s) -- expect bogus things\n", job_s,et,ed); syslog(LOG_CRIT,"%s: edg_wll_UnlockJob(): %s (%s) -- expect bogus things", job_s,et,ed); free(et); free(ed); free(job_s); } }
static void dgerr(edg_wll_Context ctx, char *where) { char *errText, *errDesc; edg_wll_Error(ctx, &errText, &errDesc); if ( where ) fprintf(stderr, ": %s", where); if ( errDesc ) fprintf(stderr, " (%s)\n", errDesc); else putc('\n', stderr); free(errText); free(errDesc); }
int edg_wll_PurgeServerProxy(edg_wll_Context ctx, glite_jobid_const_t job) { edg_wll_JobStat stat; memset(&stat, 0, sizeof stat); stat.jobId = (glite_jobid_t)job; switch ( purge_one(ctx, &stat, -1, 1, 1) ) { case 0: case ENOENT: return(edg_wll_ResetError(ctx)); break; default: return(edg_wll_Error(ctx,NULL,NULL)); break; } }
int edg_wll_GetServerState(edg_wll_Context ctx,const char *name,char **val) { char *stmt = NULL; glite_lbu_Statement q = NULL; trio_asprintf(&stmt,"select value from server_state " "where prefix = 'https://%|Ss:%d' and name = '%|Ss'", ctx->srvName,ctx->srvPort,name); glite_common_log_msg(LOG_CATEGORY_LB_SERVER_DB, LOG_PRIORITY_DEBUG, stmt); switch (edg_wll_ExecSQL(ctx,stmt,&q)) { case 0: edg_wll_SetError(ctx,ENOENT,name); break; case -1: break; default: edg_wll_FetchRow(ctx,q,sizeof(val)/sizeof(val[0]),NULL,val); break; } glite_lbu_FreeStmt(&q); free(stmt); return edg_wll_Error(ctx,NULL,NULL); }
static int get_jobid_prefix(edg_wll_Context ctx, glite_jobid_const_t job, enum edg_wll_StatJobtype jobtype, char **prefix) { char *ser = NULL; switch (jobtype) { case EDG_WLL_STAT_SIMPLE: case EDG_WLL_STAT_DAG: case EDG_WLL_STAT__PARTITIONABLE_UNUSED: case EDG_WLL_STAT__PARTITIONED_UNUSED: case EDG_WLL_STAT_COLLECTION: case EDG_WLL_STAT_CREAM: case EDG_WLL_STAT_FILE_TRANSFER: case EDG_WLL_STAT_FILE_TRANSFER_COLLECTION: // glite job prefix ser = glite_jobid_getServer(job); asprintf(prefix,"%s/",ser); free(ser); break; case EDG_WLL_STAT_PBS: // PBS jobs; prefix same as glite job prefix ser = glite_jobid_getServer(job); asprintf(prefix,"%s/",ser); free(ser); break; case EDG_WLL_STAT_CONDOR: // condor jobs assert(0); // XXX: todo break; default: edg_wll_SetError(ctx,EINVAL,"Uknown job type"); goto err; break; } err: return edg_wll_Error(ctx, NULL, NULL); }
int edg_wll_SetServerState(edg_wll_Context ctx,const char *name,const char *val) { char *stmt = NULL; int sql_retval; // Check if record exists trio_asprintf(&stmt,"select value from server_state " "where prefix = 'https://%|Ss:%d' and name = '%|Ss'", ctx->srvName,ctx->srvPort,name); glite_common_log_msg(LOG_CATEGORY_LB_SERVER_DB, LOG_PRIORITY_DEBUG, stmt); sql_retval = edg_wll_ExecSQL(ctx,stmt,NULL); free(stmt); if (!sql_retval) { trio_asprintf(&stmt,"insert into server_state (prefix,name,value) " "values ('https://%|Ss:%d','%|Ss','%|Ss')", ctx->srvName,ctx->srvPort,name,val); glite_common_log_msg(LOG_CATEGORY_LB_SERVER_DB, LOG_PRIORITY_DEBUG, stmt); edg_wll_ExecSQL(ctx,stmt,NULL); free(stmt); } else { if (sql_retval > 0) { trio_asprintf(&stmt,"update server_state set value = '%|Ss' " "where prefix = 'https://%|Ss:%d' " "and name = '%|Ss'", val,ctx->srvName,ctx->srvPort,name); glite_common_log_msg(LOG_CATEGORY_LB_SERVER_DB, LOG_PRIORITY_DEBUG, stmt); edg_wll_ExecSQL(ctx,stmt,NULL); free(stmt); } else abort(); } return edg_wll_Error(ctx,NULL,NULL); }
boost::tuple<int,std::string, std::string> get_error_info(Context const& context) { int error; std::string error_txt; std::string description_txt; char* c_error_txt = 0; char* c_description_txt = 0; error = edg_wll_Error(context.c_context(), &c_error_txt, &c_description_txt); if (c_error_txt) { error_txt = c_error_txt; } free(c_error_txt); if (c_description_txt) { description_txt = c_description_txt; } free(c_description_txt); return boost::make_tuple(error, error_txt, description_txt); }
void edg_wll_ErrToFault(const edg_wll_Context ctx,struct soap *soap) { char *et,*ed; struct SOAP_ENV__Detail *detail; #if GSOAP_VERSION >= 20709 struct lbt__genericFault *f = soap_malloc(soap,sizeof *f); struct lbt__genericFault *item = f; #else struct _genericFault *f = soap_malloc(soap,sizeof *f); struct lbt__genericFault *item = f->lbe__genericFault = soap_malloc(soap, sizeof *item); #endif memset(item, 0, sizeof(*item)); item->code = edg_wll_Error(ctx,&et,&ed); item->text = soap_malloc(soap,strlen(et)+1); strcpy(item->text, et); free(et); if (ed) { item->description = soap_malloc(soap,strlen(ed)+1); strcpy(item->description,ed); free(ed); } detail = (struct SOAP_ENV__Detail *)soap_faultdetail(soap); detail->__type = GFNUM; #if GSOAP_VERSION >= 20700 detail->fault = f; #else detail->value = f; #endif detail->__any = NULL; soap_receiver_fault(soap,"An error occurred, see detail",NULL); if (soap->version == 2) soap->fault->SOAP_ENV__Detail = detail; else soap->fault->detail = detail; }
int edg_wll_NotifExpired(edg_wll_Context ctx,const char *notif) { char *dn = NULL,*dj = NULL; trio_asprintf(&dn,"delete from notif_registrations where notifid='%|Ss'",notif); trio_asprintf(&dj,"delete from notif_jobs where notifid='%|Ss'",notif); glite_common_log_msg(LOG_CATEGORY_LB_SERVER_DB, LOG_PRIORITY_DEBUG, dn); glite_common_log_msg(LOG_CATEGORY_LB_SERVER_DB, LOG_PRIORITY_DEBUG, dj); if (edg_wll_ExecSQL(ctx,dn,NULL) < 0 || edg_wll_ExecSQL(ctx,dj,NULL) < 0) { char *et,*ed; edg_wll_Error(ctx,&et,&ed); glite_common_log(LOG_CATEGORY_CONTROL, LOG_PRIORITY_WARN, "delete notification %s: %s (%s)", notif, et, ed); free(et); free(ed); } free(dn); free(dj); return edg_wll_ResetError(ctx); }
/* * edg_wll_log_event_send - send event to the socket * * Returns: 0 if done properly or errno * */ int edg_wll_log_event_send( edg_wll_Context ctx, const char *socket_path, long filepos, const char *msg, int msg_size, int conn_attempts, struct timeval *timeout) { struct sockaddr_un saddr; int msg_sock, flags, conn_timeout, i; ssize_t count = 0; if ( (msg_sock = socket(PF_UNIX, SOCK_STREAM, 0)) < 0 ) { edg_wll_SetError(ctx, errno, "socket()"); goto event_send_end; } memset(&saddr, 0, sizeof(saddr)); saddr.sun_family = AF_UNIX; strcpy(saddr.sun_path, socket_path); if ( (flags = fcntl(msg_sock, F_GETFL, 0)) < 0 || fcntl(msg_sock, F_SETFL, flags | O_NONBLOCK) < 0 ) { edg_wll_SetError(ctx, errno, "fcntl()"); goto cleanup; } conn_timeout = floor(timeout->tv_sec/(conn_attempts + 1)); for ( i = 0; i < conn_attempts; i++) { if ( connect(msg_sock, (struct sockaddr *)&saddr, sizeof(saddr)) < 0 ) { if ( errno == EISCONN ) break; else if ((errno == EAGAIN) || (errno == ETIMEDOUT)) { sleep(conn_timeout); timeout->tv_sec -= conn_timeout; continue; } else { edg_wll_SetError(ctx, errno, "Can't connect to the interlogger"); goto cleanup; } } else break; } if ( edg_wll_socket_write_full(msg_sock, &filepos, sizeof(filepos), timeout, &count) < 0 ) { edg_wll_SetError(ctx, errno, "edg_wll_socket_write_full()"); goto cleanup; } if ( edg_wll_socket_write_full(msg_sock, (void *)msg, msg_size, timeout, &count) < 0 ) { edg_wll_SetError(ctx, errno, "edg_wll_socket_write_full()"); goto cleanup; } cleanup: close(msg_sock); event_send_end: return edg_wll_Error(ctx, NULL, NULL)? edg_wll_Error(ctx, NULL, NULL): 0; }
/* * edg_wll_log_event_write - write event to the local file * * Returns: 0 if done properly or errno * */ int edg_wll_log_event_write( edg_wll_Context ctx, const char *event_file, const char *msg, unsigned int fcntl_attempts, unsigned int fcntl_timeout, long *filepos) { FILE *outfile; struct flock filelock; int filedesc, i, filelock_status=-1; struct stat statbuf; char *group_name; try_again: if ( (outfile = fopen(event_file, "a")) == NULL ) { edg_wll_SetError(ctx, errno, "fopen()"); goto event_write_end; } if ( (filedesc = fileno(outfile)) == -1 ) { edg_wll_SetError(ctx, errno, "fileno()"); goto cleanup; } for ( i = 0; i < fcntl_attempts; i++ ) { filelock.l_type = F_WRLCK; filelock.l_whence = SEEK_SET; filelock.l_start = 0; filelock.l_len = 0; if ( (filelock_status = fcntl(filedesc, F_SETLK, &filelock) < 0) ) { switch(errno) { case EAGAIN: case EACCES: case EINTR: if ((i+1) < fcntl_attempts) sleep(fcntl_timeout); break; default: edg_wll_SetError(ctx, errno, "fcntl()"); goto cleanup; } } else { /* check that the file still exists */ if(stat(event_file, &statbuf)) { if(errno == ENOENT) { /* not there anymore - reopen it */ fclose(outfile); goto try_again; } else { /* could not stat the output file */ edg_wll_SetError(ctx, errno, "stat()"); goto cleanup; } } else { /* file exists and is locked */ break; } } } if (i == fcntl_attempts) { edg_wll_SetError(ctx, ETIMEDOUT, "timed out trying to lock event file"); goto cleanup; } /* make the file writable for given group, if specified */ if(NULL != (group_name = getenv("GLITE_GROUP"))) { struct group *glite_group = getgrnam(group_name); if(NULL != glite_group) { /* errors are ignored */ fchown(filedesc, -1, glite_group->gr_gid); fchmod(filedesc, 0660); } } if ( fseek(outfile, 0, SEEK_END) == -1 ) { edg_wll_SetError(ctx, errno, "fseek()"); goto cleanup; } if ( (*filepos = ftell(outfile)) == -1 ) { edg_wll_SetError(ctx, errno, "ftell()"); goto cleanup; } i = strlen(msg); if( i != fwrite(msg, sizeof(char), i, outfile)) { edg_wll_SetError(ctx, errno, "fwrite()"); /* partially written message may corrupt event file */ ftruncate(filedesc, *filepos); goto cleanup; } if ( fflush(outfile) == EOF ) { edg_wll_SetError(ctx, errno, "fflush()"); /* partially written message may corrupt event file */ ftruncate(filedesc, *filepos); goto cleanup; } if ( fsync(filedesc) < 0 ) { edg_wll_SetError(ctx, errno, "fsync()"); /* partially written message may corrupt event file */ ftruncate(filedesc, *filepos); goto cleanup; } cleanup: fclose(outfile); event_write_end: return edg_wll_Error(ctx, NULL, NULL)? edg_wll_Error(ctx, NULL, NULL): 0; }
int main(int argc,char **argv) { /* VARIABLES DECLARATION */ edg_wll_Context ctx; struct tm tm; time_t from,to; int i, err = 0; /* VARIABLES INITIALIZATION */ edg_wll_QueryRec cond[3]; /* [2] is terminator */ edg_wll_Event *events = NULL; edg_wll_InitContext(&ctx); if (argc != 3) usage(argv[0]); memset(&tm,0,sizeof tm); if (sscanf(argv[1],"%d-%d-%d:%d:%d:%d", &tm.tm_year, &tm.tm_mon, &tm.tm_mday, &tm.tm_hour, &tm.tm_min, &tm.tm_sec)!= 6) usage(argv[0]); tm.tm_mon--; tm.tm_year -= 1900; from = timegm(&tm); memset(&tm,0,sizeof tm); if (sscanf(argv[2],"%d-%d-%d:%d:%d:%d", &tm.tm_year, &tm.tm_mon, &tm.tm_mday, &tm.tm_hour, &tm.tm_min, &tm.tm_sec) != 6) usage(argv[0]); tm.tm_mon--; tm.tm_year -= 1900; to = timegm(&tm); memset(cond,0,sizeof cond); /* QUERY CONDITIONS INITIALIZATION: ALL JOBS DONE WITHIN TIME INTERVAL */ cond[0].attr = EDG_WLL_QUERY_ATTR_TIME; cond[0].op = EDG_WLL_QUERY_OP_WITHIN; cond[0].value.t.tv_sec = from; cond[0].value2.t.tv_sec = to; cond[1].attr = EDG_WLL_QUERY_ATTR_EVENT_TYPE; cond[1].value.i = EDG_WLL_EVENT_DONE; if (edg_wll_QueryEventsProxy(ctx,NULL,cond,&events)) { char *et,*ed; et = ed = NULL; edg_wll_Error(ctx,&et,&ed); fprintf(stderr,"edg_wll_QueryEventsProxy: %s, %s\n", et,ed ? ed : ""); free(et); free(ed); err = 1; goto cleanup; } /* SELECTION OF DONE FAILED-OR-OK JOBS */ // printf("SELECTION OF DONE JOBS\n"); // printf("OWNER\tJOBID\tEXITCODE\tTIMESTAMP\tFAILUREREASON\n"); for (i=0; events[i].type; i++) { edg_wll_Event *e = events+i; if(e->done.status_code == EDG_WLL_DONE_OK) { char *job = glite_jobid_unparse(e->any.jobId); printf("%s\t%s\t%s", e->any.user, job, ctime(&e->done.timestamp.tv_sec) //asctime(gmtime(&e->done.timestamp.tv_sec)) ); free(job); } /* if (e->done.status_code == EDG_WLL_DONE_FAILED) { char *job = glite_jobid_unparse(e->any.jobId); printf("%s\t%s\t%d\t%s\t%s\n", e->any.user, job, e->done.status_code, ctime(&e->done.timestamp.tv_sec), e->done.reason ); free(job); } else if(e->done.status_code == EDG_WLL_DONE_OK) { char *job = glite_jobid_unparse(e->any.jobId); printf("%s\t%s\t%d\t%s\tNULL\n", e->any.user, job, e->done.status_code, ctime(&e->done.timestamp.tv_sec) ); free(job);}*/ } cleanup: if (events) { for (i=0; events[i].type; i++) edg_wll_FreeEvent(events+i); free(events); events = NULL; } edg_wll_FreeContext(ctx); return err; }
int main(int argc, char *argv[]) { char *server, *jobid_s, *user; edg_wlc_JobId jobid = NULL; int opt, err = 0; long i; int port = 0; server = jobid_s = user = NULL; while ( (opt = getopt_long(argc, argv, "hs:p:j:u:c:n:v:", opts, NULL)) != EOF) switch (opt) { case 'h': usage(argv[0]); return 0; case 's': server = strdup(optarg); break; case 'p': port = atoi(optarg); break; case 'j': jobid_s = strdup(optarg); break; case 'u': user = strdup(optarg); break; case '?': usage(argv[0]); return 1; } if ( !jobid_s ) { fprintf(stderr, "JobId not given\n"); return 1; } /*variables*/ edg_wll_Context ctx; edg_wll_QueryRec *jc[4]; edg_wll_JobStat *statesOut = NULL; edg_wlc_JobId *jobsOut = NULL; /*end variables*/ if ( (errno = edg_wlc_JobIdParse(jobid_s, &jobid)) ) { perror(jobid_s); return 1; } /*context*/ edg_wll_InitContext(&ctx); edg_wll_SetParam(ctx, EDG_WLL_PARAM_QUERY_SERVER, server); if (port) edg_wll_SetParam(ctx, EDG_WLL_PARAM_QUERY_SERVER_PORT, port); /*end context*/ /*queryrec*/ jc[0] = (edg_wll_QueryRec *) malloc(2*sizeof(edg_wll_QueryRec)); jc[0][0].attr = EDG_WLL_QUERY_ATTR_OWNER; jc[0][0].op = EDG_WLL_QUERY_OP_EQUAL; jc[0][0].value.c = NULL; jc[0][1].attr = EDG_WLL_QUERY_ATTR_UNDEF; jc[1] = (edg_wll_QueryRec *) malloc(2*sizeof(edg_wll_QueryRec)); jc[1][0].attr = EDG_WLL_QUERY_ATTR_STATUS; jc[1][0].op = EDG_WLL_QUERY_OP_EQUAL; jc[1][0].value.i = EDG_WLL_JOB_RUNNING; jc[1][1].attr = EDG_WLL_QUERY_ATTR_UNDEF; jc[2] = (edg_wll_QueryRec *) malloc(3*sizeof(edg_wll_QueryRec)); jc[2][0].attr = EDG_WLL_QUERY_ATTR_DESTINATION; jc[2][0].op = EDG_WLL_QUERY_OP_EQUAL; jc[2][0].value.c = "XXX"; jc[2][1].attr = EDG_WLL_QUERY_ATTR_DESTINATION; jc[2][1].op = EDG_WLL_QUERY_OP_EQUAL; jc[2][1].value.c = "YYY"; jc[2][2].attr = EDG_WLL_QUERY_ATTR_UNDEF; jc[3] = NULL; /*end queryrec*/ /*query*/ err = edg_wll_QueryJobsExt(ctx, (const edg_wll_QueryRec **)jc, 0, &jobsOut, &statesOut); /*end query*/ if ( err == E2BIG ) { fprintf(stderr,"Warning: only limited result returned!\n"); return 0; } else if (err) { char *et,*ed; edg_wll_Error(ctx,&et,&ed); fprintf(stderr,"%s: edg_wll_QueryJobs(): %s (%s)\n",argv[0],et,ed); free(et); free(ed); } /*printstates*/ for (i = 0; statesOut[i].state; i++ ) { printf("jobId : %s\n", edg_wlc_JobIdUnparse(statesOut[i].jobId)); printf("state : %s\n\n", edg_wll_StatToString(statesOut[i].state)); } /*end printstates*/ if ( jobsOut ) { for (i=0; jobsOut[i]; i++) edg_wlc_JobIdFree(jobsOut[i]); free(jobsOut); } if ( statesOut ) { for (i=0; statesOut[i].state; i++) edg_wll_FreeStatus(&statesOut[i]); free(statesOut); } free(jc[0]); free(jc[1]); free(jc[2]); edg_wll_FreeContext(ctx); return err; }
int edg_wll_GenerateSubjobIds( edg_wll_Context ctx, glite_jobid_const_t parent, int num_subjobs, const char * seed, edg_wlc_JobId ** subjobs) { int subjob, ret; char *p_unique, *p_bkserver, *intseed; char *unhashed, *hashed; unsigned int p_port; edg_wlc_JobId *retjobs; if (num_subjobs < 1) return edg_wll_SetError(ctx, EINVAL, "edg_wll_GenerateSubjobIds(): num_subjobs < 1"); p_unique = edg_wlc_JobIdGetUnique(parent); edg_wlc_JobIdGetServerParts(parent, &p_bkserver, &p_port); retjobs = calloc(num_subjobs+1, sizeof(edg_wlc_JobId)); if (p_unique == NULL || p_bkserver == NULL || retjobs == NULL) return edg_wll_SetError(ctx, ENOMEM, NULL); if ( !seed ) { intseed = strdup("edg_wll_GenerateSubjobIds()"); } else { intseed = strdup(seed); } for (subjob = 0; subjob < num_subjobs; subjob++) { asprintf(&unhashed, "%s,%s,%d", p_unique, intseed, subjob); if (unhashed == NULL) { edg_wll_SetError(ctx, ENOMEM, "edg_wll_GenerateSubjobIds(): asprintf() error"); goto handle_error; } hashed = str2md5base64(unhashed); free(unhashed); if (hashed == NULL) { edg_wll_SetError(ctx, ENOMEM, "edg_wll_GenerateSubjobIds(): str2md5base64() error"); goto handle_error; } ret = edg_wlc_JobIdRecreate(p_bkserver, p_port, hashed, &retjobs[subjob]); free(hashed); if (ret != 0) { edg_wll_SetError(ctx, ret, "edg_wll_GenerateSubjobIds(): edg_wlc_JobIdRecreate() error"); goto handle_error; } } free(intseed); free(p_unique); free(p_bkserver); *subjobs = retjobs; return 0; handle_error: free(intseed); free(p_unique); free(p_bkserver); for ( subjob-- ;subjob >= 0; subjob--) edg_wlc_JobIdFree(retjobs[subjob]); return edg_wll_Error(ctx, NULL, NULL); }
int main(int argc,char **argv) { edg_wll_Context ctx; struct tm tm; time_t from,to; int i, err = 0; edg_wll_QueryRec cond[3],jcond[2]; /* [2] is terminator */ edg_wll_Event *events = NULL; if (edg_wll_InitContext(&ctx) != 0) { fprintf(stderr, "Couldn't create L&B context.\n"); return 1; } if (argc != 3) usage(argv[0]); memset(&tm,0,sizeof tm); if (sscanf(argv[1],"%d-%d-%d:%d:%d", &tm.tm_year, &tm.tm_mon, &tm.tm_mday, &tm.tm_hour, &tm.tm_min) != 5) usage(argv[0]); tm.tm_mon--; tm.tm_year -= 1900; from = mktime(&tm); if (sscanf(argv[2],"%d-%d-%d:%d:%d", &tm.tm_year, &tm.tm_mon, &tm.tm_mday, &tm.tm_hour, &tm.tm_min) != 5) usage(argv[0]); tm.tm_mon--; tm.tm_year -= 1900; to = mktime(&tm); memset(jcond,0,sizeof jcond); jcond[0].attr = EDG_WLL_QUERY_ATTR_OWNER; jcond[0].op = EDG_WLL_QUERY_OP_UNEQUAL; jcond[0].value.c = "nonexistent"; memset(cond,0,sizeof cond); cond[0].attr = EDG_WLL_QUERY_ATTR_TIME; cond[0].op = EDG_WLL_QUERY_OP_WITHIN; cond[0].value.t.tv_sec = from; cond[0].value2.t.tv_sec = to; cond[1].attr = EDG_WLL_QUERY_ATTR_EVENT_TYPE; cond[1].value.i = EDG_WLL_EVENT_DONE; if (edg_wll_QueryEvents(ctx,jcond,cond,&events)) { char *et,*ed; et = ed = NULL; edg_wll_Error(ctx,&et,&ed); fprintf(stderr,"edg_wll_QueryEventsProxy: %s, %s\n", et,ed ? ed : ""); free(et); free(ed); err = 1; goto cleanup; } for (i=0; events[i].type; i++) { edg_wll_Event *e = events+i; if (e->done.status_code == EDG_WLL_DONE_FAILED) { char *job = glite_jobid_unparse(e->any.jobId); printf("%s\t%s\t%s\t%s\n", job, ctime(&e->done.timestamp.tv_sec), e->done.host, e->done.reason ); free(job); } } cleanup: if (events) { for (i=0; events[i].type; i++) edg_wll_FreeEvent(events+i); free(events); events = NULL; } edg_wll_FreeContext(ctx); return err; }
int edg_wll_PurgeServer(edg_wll_Context ctx,const edg_wll_PurgeRequest *request, edg_wll_PurgeResult *result) { int i; glite_jobid_t job; char *tmpfname = NULL; int ret; double now; struct timeval tp; edg_wll_JobStat stat; purge_ctx_t prg; memset(&prg, 0, sizeof prg); prg.naffected_jobs = 0; prg.parse = 0; prg.dumpfile = -1; if (!ctx->noAuth && !check_authz_policy_ctx(ctx, PURGE)) { edg_wll_SetError(ctx,EPERM,"only superusers may purge"); goto abort; } edg_wll_ResetError(ctx); memset(result, 0, sizeof(*result)); if ( (request->flags & EDG_WLL_PURGE_SERVER_DUMP) && ((prg.dumpfile = edg_wll_CreateTmpPurgeFile(ctx, &tmpfname)) == -1 ) ) goto abort; /* should be changed so that only purged events are sent to whole-server dumps (with this commented out, severely delayed events (>purge interval) can miss whole-server dumps, but it is more acceptable than invoking whole-server dump on each purge request (whole-server dumps are used rarely if at all) if (request->flags&EDG_WLL_PURGE_REALLY_PURGE) { edg_wll_DumpRequest req = { EDG_WLL_DUMP_LAST_END, EDG_WLL_DUMP_NOW }; edg_wll_DumpResult res; if (edg_wll_DumpEventsServer(ctx,&req,&res)) { if ( request->flags & EDG_WLL_PURGE_SERVER_DUMP ) unlink(tmpfname); goto abort; } } */ /* throttle parameters */ gettimeofday(&tp, NULL); now = tp.tv_sec + (double)tp.tv_usec / 1000000.0; prg.purge_end = now + request->target_runtime; prg.target_runtime = request->target_runtime; prg.time_per_job = -1.0; if (request->jobs) { for (prg.jobs_to_exa=0; request->jobs[prg.jobs_to_exa]; prg.jobs_to_exa++); for (i=0; request->jobs[i] && !purge_quit; i++) { if (edg_wlc_JobIdParse(request->jobs[i],&job)) { glite_common_log(LOG_CATEGORY_CONTROL, LOG_PRIORITY_ERROR, "%s: parse error", request->jobs[i]); prg.parse = 1; prg.jobs_to_exa--; } else { if (check_strict_jobid(ctx,job)) { glite_common_log(LOG_CATEGORY_CONTROL, LOG_PRIORITY_WARN, "%s: not my job", request->jobs[i]); prg.parse = 1; prg.jobs_to_exa--; } else { if (purge_quit) break; memset(&stat,0,sizeof stat); if (edg_wll_JobStatusServer(ctx,job,EDG_WLL_STAT_CHILDSTAT | EDG_WLL_STAT_CHILDREN,&stat)) { if (edg_wll_Error(ctx, NULL, NULL) == ENOENT) { /* job purged meanwhile, ignore */ edg_wll_ResetError(ctx); glite_jobid_free(job); purge_throttle(&prg); continue; } edg_wll_FreeStatus(&stat); goto abort; } switch (purge_one_with_subjobs(ctx, &prg, &stat, request, result)) { case 0: break; case ENOENT: /* job does not exist, consider purged and ignore */ edg_wll_ResetError(ctx); break; default: goto abort; } edg_wll_FreeStatus(&stat); } glite_jobid_free(job); } } } else { glite_lbu_Statement s; char *job_s; time_t timeout[EDG_WLL_NUMBER_OF_STATCODES], start = time(NULL); for (i=0; i<EDG_WLL_NUMBER_OF_STATCODES; i++) if (request->timeout[i] < 0) { // no specific timeout if (request->timeout[i] == -2) //no purge timeout[i] = request->timeout[i]; else {// use server default timeout[i] = ctx->purge_timeout[i]; } } else timeout[i] = request->timeout[i]; //specific given glite_common_log(LOG_CATEGORY_LB_SERVER_DB, LOG_PRIORITY_DEBUG, (ctx->isProxy) ? "select dg_jobid from jobs where proxy='1'" : "select dg_jobid from jobs where server='1'"); if ((prg.jobs_to_exa = edg_wll_ExecSQL(ctx, (ctx->isProxy) ? "select dg_jobid from jobs where proxy='1'" : "select dg_jobid from jobs where server='1'", &s)) < 0) goto abort; while (edg_wll_FetchRow(ctx,s,1,NULL,&job_s) > 0 && !purge_quit) { if (edg_wlc_JobIdParse(job_s,&job)) { glite_common_log(LOG_CATEGORY_CONTROL, LOG_PRIORITY_ERROR, "%s: parse error (internal inconsistency !)", job_s); prg.parse = 1; prg.jobs_to_exa--; } else { if (check_strict_jobid(ctx,job)) { edg_wlc_JobIdFree(job); free(job_s); prg.parse = 1; prg.jobs_to_exa--; continue; } if (purge_quit) break; memset(&stat,0,sizeof stat); if (edg_wll_JobStatusServer(ctx,job,EDG_WLL_STAT_CHILDSTAT | EDG_WLL_STAT_CHILDREN,&stat)) { if (edg_wll_Error(ctx, NULL, NULL) == ENOENT) { /* job purged meanwhile, ignore */ edg_wll_ResetError(ctx); glite_jobid_free(job); free(job_s); purge_throttle(&prg); continue; } edg_wll_FreeStatus(&stat); goto abort; } if (purge_check(ctx, &stat, start, timeout)) { if (purge_one_with_subjobs(ctx, &prg, &stat, request, result)) { edg_wll_FreeStatus(&stat); if (edg_wll_Error(ctx, NULL, NULL) == ENOENT) { /* job purged meanwhile, ignore */ edg_wll_ResetError(ctx); glite_jobid_free(job); free(job_s); continue; } goto abort; } } glite_jobid_free(job); edg_wll_FreeStatus(&stat); } free(job_s); } glite_lbu_FreeStmt(&s); } abort: if (prg.parse && !edg_wll_Error(ctx,NULL,NULL)) { if ( prg.naffected_jobs ) { glite_common_log(LOG_CATEGORY_CONTROL, LOG_PRIORITY_INFO, "[%d] Found only jobs not matching server address/port; these were not purged.", getpid()); } else { glite_common_log(LOG_CATEGORY_CONTROL, LOG_PRIORITY_INFO, "[%d] Found only jobs not matching server address/port; these were not purged.", getpid()); } } ret = edg_wll_Error(ctx,NULL,NULL); if (ret == 0 || ret == ENOENT || ret == EPERM || ret == EINVAL) { if ( request->flags & EDG_WLL_PURGE_SERVER_DUMP && tmpfname ) { edg_wll_CreatePurgeFileFromTmp(ctx, tmpfname, &(result->server_file)); unlink(tmpfname); } } return edg_wll_Error(ctx,NULL,NULL); }
int main(int argc,char **argv) { edg_wll_Context ctx; char *errt,*errd,*e,a; edg_wll_Event *events; int i; edg_wll_QueryRec jq[2],eq[2]; edg_wlc_JobId job; edg_wll_Source src; if (argc != 3) help(argv[0]); puts( "*\n" "* USE WITH CARE, AT YOUR OWN RISK, UNDER ABNORMAL CONDITIONS ONLY,\n" "* AND BE ALWAYS SURE WHAT YOU ARE DOING.\n" "* \n" "* THIS PROGRAM IS A PERFECT EXAMPLE HOW L&B SEQENCE CODES SHOULD NOT BE USED\n" "* IN NORMAL OPERATION.\n" "\n" "Do you want to proceed?" ); scanf("%c",&a); if (a != 'y' && a != 'Y') return 1; if (edg_wll_InitContext(&ctx) != 0) { fprintf(stderr, "Couldn't create L&B context.\n"); return 1; } if (edg_wlc_JobIdParse(argv[1],&job)) { fprintf(stderr,"%s: can't parse job ID\n",argv[1]); return 1; } if (( src = edg_wll_StringToSource(argv[2])) == EDG_WLL_SOURCE_NONE) { fprintf(stderr,"%s: unknown event source\n",argv[2]); return 1; } jq[0].attr = EDG_WLL_QUERY_ATTR_JOBID; jq[0].op = EDG_WLL_QUERY_OP_EQUAL; jq[0].value.j = job; jq[1].attr = EDG_WLL_QUERY_ATTR_UNDEF; eq[0].attr = EDG_WLL_QUERY_ATTR_SOURCE; eq[0].op = EDG_WLL_QUERY_OP_EQUAL; eq[0].value.i = src; eq[1].attr = EDG_WLL_QUERY_ATTR_UNDEF; if ( edg_wll_QueryEvents(ctx,jq,eq,&events) ) { if ( edg_wll_Error(ctx, &errt, &errd) != E2BIG ) goto err; fprintf(stderr,"%s: %s (%s)\n",argv[0],errt,errd); } for ( i = 0; events[i].type != EDG_WLL_EVENT_UNDEF; i++ ); e = edg_wll_UnparseEvent(ctx,events+i-1); fputs(e,stdout); fputs("\n",stdout); if (edg_wll_SetParam(ctx,EDG_WLL_PARAM_SOURCE,src) || edg_wll_SetLoggingJob(ctx,job,events[i-1].any.seqcode,EDG_WLL_SEQ_NORMAL) || edg_wll_IncSequenceCode(ctx) || /* necessary to simulate this * call in last event logging * _after_ current seq. was used */ edg_wll_LogAbort(ctx,"manual abort")) goto err; free(e); free_events(events); edg_wll_FreeContext(ctx); return 0; err: switch (edg_wll_Error(ctx,&errt,&errd)) { case 0: break; case ENOENT: puts("No events found"); break; default: fprintf(stderr,"%s: %s (%s)\n",argv[0],errt,errd); return 1; } edg_wll_FreeContext(ctx); return 0; }
int main(int argc,char **argv) { /* VARIABLES DECLARATION */ edg_wll_Context ctx; struct tm tm; time_t from,to; int i, err = 0; /* VARIABLES INITIALIZATION */ edg_wll_QueryRec cond[4]; /* [3] is terminator */ edg_wll_Event *events = NULL; edg_wll_InitContext(&ctx); if (argc != 3) usage(argv[0]); memset(&tm,0,sizeof tm); if (sscanf(argv[1],"%d-%d-%d:%d:%d:%d", &tm.tm_year, &tm.tm_mon, &tm.tm_mday, &tm.tm_hour, &tm.tm_min, &tm.tm_sec)!= 6) usage(argv[0]); tm.tm_mon--; tm.tm_year -= 1900; from = timegm(&tm); memset(&tm,0,sizeof tm); if (sscanf(argv[2],"%d-%d-%d:%d:%d:%d", &tm.tm_year, &tm.tm_mon, &tm.tm_mday, &tm.tm_hour, &tm.tm_min, &tm.tm_sec) != 6) usage(argv[0]); tm.tm_mon--; tm.tm_year -= 1900; to = timegm(&tm); memset(cond,0,sizeof cond); /* QUERY CONDITIONS INITIALIZATION: ALL JOBS DONE WITHIN TIME INTERVAL */ cond[0].attr = EDG_WLL_QUERY_ATTR_TIME; cond[0].op = EDG_WLL_QUERY_OP_WITHIN; cond[0].value.t.tv_sec = from; cond[0].value2.t.tv_sec = to; cond[1].attr = EDG_WLL_QUERY_ATTR_EVENT_TYPE; cond[1].value.i = EDG_WLL_EVENT_TRANSFER; cond[2].attr = EDG_WLL_QUERY_ATTR_SOURCE; cond[2].value.i = EDG_WLL_SOURCE_JOB_SUBMISSION; if (edg_wll_QueryEventsProxy(ctx,NULL,cond,&events)) { char *et,*ed; et = ed = NULL; edg_wll_Error(ctx,&et,&ed); fprintf(stderr,"edg_wll_QueryEventsProxy: %s, %s\n", et,ed ? ed : ""); free(et); free(ed); err = 1; goto cleanup; } // printf("JOBS TRANSFERED TO CONDOR\n"); // printf("OWNER\tJOBID\tSOURCE\tQUEUE\tTIMESTAMP\tRESULT\n"); for (i=0; events[i].type; i++) { edg_wll_Event *e = events+i; if (e->transfer.result == 2) { char *job = glite_jobid_unparse(e->any.jobId); printf("%s\t%s\t%s", e->any.user, job, ctime(&e->transfer.timestamp.tv_sec) ); free(job); } } cleanup: if (events) { for (i=0; events[i].type; i++) edg_wll_FreeEvent(events+i); free(events); events = NULL; } edg_wll_FreeContext(ctx); return err; }
int main(int argc,char **argv) { edg_wll_Context ctx; char *errt,*errd; edg_wll_Event *events = NULL; edg_wlc_JobId job; int i,opt,delay = 1,count = 0, proxy = 0; if (argc < 2) help(argv[0]); if (edg_wll_InitContext(&ctx) != 0) { fprintf(stderr, "Couldn't create L&B context.\n"); return 1; } while ((opt=getopt(argc,argv,"r:d:xX:")) != -1) switch (opt) { case 'd': delay = atoi(optarg); break; case 'r': count = atoi(optarg); break; case 'x': proxy = 1; break; case 'X': proxy = 1; edg_wll_SetParam(ctx, EDG_WLL_PARAM_LBPROXY_SERVE_SOCK, optarg); break; default: help(argv[0]); } if (edg_wlc_JobIdParse(argv[optind],&job)) { fprintf(stderr,"%s: can't parse job ID\n",argv[1]); return 1; } #ifdef USE_CALLBACKS edg_wll_RegisterTestQueryEvents(query_events_cb); #endif if ( proxy ? edg_wll_JobLogProxy(ctx,job,&events) : edg_wll_JobLog(ctx,job,&events) ) { edg_wll_Error(ctx,&errt,&errd); fprintf(stderr,"%s: %s (%s)\n",argv[0],errt,errd); } for ( i = 0; events && events[i].type != EDG_WLL_EVENT_UNDEF; i++ ) { char *e = edg_wll_UnparseEvent(ctx,events+i); fputs(e,stdout); fputs("\n",stdout); free(e); } free_events(events); printf("\nFound %d events\n",i); while (count--) { puts("Sleeping ..."); sleep(delay); if (proxy ? edg_wll_JobLogProxy(ctx,job,&events) : edg_wll_JobLog(ctx,job,&events)) { edg_wll_Error(ctx,&errt,&errd); fprintf(stderr,"%s: %s (%s)\n",argv[0],errt,errd); free(errt); free(errd); errt = errd = NULL; free_events(events); } else puts("OK"); } edg_wlc_JobIdFree(job); edg_wll_FreeContext(ctx); #ifdef USE_CALLBACKS edg_wll_UnregisterTestQueryEvents(); #endif return 0; #ifdef USE_CALLBACKS edg_wll_UnregisterTestQueryEvents(); #endif switch (edg_wll_Error(ctx,&errt,&errd)) { case 0: break; case ENOENT: puts("No events found"); break; default: fprintf(stderr,"%s: %s (%s)\n",argv[0],errt,errd); return 1; } edg_wlc_JobIdFree(job); edg_wll_FreeContext(ctx); return 0; }
int edg_wll_NotifMatch(edg_wll_Context ctx, const edg_wll_JobStat *oldstat, const edg_wll_JobStat *stat) { edg_wll_NotifId nid = NULL; char *jobq,*ju = NULL,*jobc[6]; glite_lbu_Statement jobs = NULL; int ret,flags; size_t i; time_t expires,now = time(NULL); char *cond_where = NULL; char *cond_and_where = NULL; edg_wll_JobStat newstat = *stat; // shallow copy edg_wll_JobStat* statcopy[2][2][2]; int m, a, h; edg_wll_Event* events = NULL; memset(statcopy, 0, sizeof(statcopy)); edg_wll_ResetError(ctx); if (ctx->notif_index) { edg_wll_IColumnRec *notif_index_cols = ctx->notif_index_cols; for (i=0; notif_index_cols[i].qrec.attr; i++) { char *val = NULL; if (notif_index_cols[i].qrec.attr != EDG_WLL_QUERY_ATTR_JDL_ATTR) { val = edg_wll_StatToSQL(stat,notif_index_cols[i].qrec.attr); assert(val != (char *) -1); } else { // Special Treatment for JDL attributes val = edg_wll_JDLStatToSQL(stat,notif_index_cols[i].qrec); } if (val) { char *aux; if (!cond_where) cond_where = strdup(""); trio_asprintf(&aux, "%s or %s = %s",cond_where, notif_index_cols[i].colname,val); free(cond_where); cond_where = aux; free(val); } else if (notif_index_cols[i].qrec.attr == EDG_WLL_QUERY_ATTR_JDL_ATTR) { char *aux; if (!cond_and_where) cond_and_where = strdup(""); trio_asprintf(&aux, "%s AND %s is NULL",cond_and_where, notif_index_cols[i].colname); free(cond_and_where); cond_and_where = aux; free(val); } } } if ( (ret = edg_wll_NotifIdCreate(ctx->srvName, ctx->srvPort, &nid)) ) { edg_wll_SetError(ctx, ret, "edg_wll_NotifMatch()"); goto err; } trio_asprintf(&jobq, "select distinct n.notifid,n.destination,n.valid,u.cert_subj,n.conditions,n.flags " "from notif_jobs j,users u,notif_registrations n " "where j.notifid=n.notifid and n.userid=u.userid " " and (j.jobid = '%|Ss' or j.jobid = '%|Ss' %s) %s", ju = edg_wlc_JobIdGetUnique(stat->jobId),NOTIF_ALL_JOBS,cond_where ? cond_where : "",cond_and_where ? cond_and_where : ""); free(ju); ju = NULL; free(cond_where); cond_where = NULL; free(cond_and_where); cond_and_where = NULL; glite_common_log_msg(LOG_CATEGORY_LB_SERVER_DB, LOG_PRIORITY_DEBUG, jobq); if (edg_wll_ExecSQL(ctx,jobq,&jobs) < 0) goto err; statcopy[0][0][0]=&newstat; while ((ret = edg_wll_FetchRow(ctx,jobs,sizeof(jobc)/sizeof(jobc[0]),NULL,jobc)) > 0) { flags = atoi(jobc[5]); if (now > (expires = glite_lbu_StrToTime(jobc[2]))) { edg_wll_NotifExpired(ctx,jobc[0]); glite_common_log(LOG_CATEGORY_LB_SERVER, LOG_PRIORITY_DEBUG, "[%d] NOTIFY:%s expired at %s UTC", getpid(),jobc[0],asctime(gmtime(&expires))); } else if (notif_match_conditions(ctx,oldstat,&newstat,jobc[4],flags)) { char *errt, *errd; char *dest; int authz_flags; ret = edg_wll_NotifCheckAuthz(ctx, &newstat, flags, jobc[3], &authz_flags); if (ret != 1) { char *ju; glite_common_log(LOG_CATEGORY_CONTROL, LOG_PRIORITY_INFO, "[%d] authorization failed when sending notification for job %s", getpid(), ju = glite_jobid_getUnique(newstat.jobId)); free(ju); for (i=0; i<sizeof(jobc)/sizeof(jobc[0]); i++) free(jobc[i]); continue; } m = (authz_flags & STATUS_FOR_MONITORING) == STATUS_FOR_MONITORING; a = (authz_flags & READ_ANONYMIZED) == READ_ANONYMIZED; h = (flags & EDG_WLL_NOTIF_HISTORY) == EDG_WLL_NOTIF_HISTORY; if (!statcopy[m][a][h]) { statcopy[m][a][h]=(edg_wll_JobStat*)calloc(sizeof(edg_wll_JobStat),1); edg_wll_CpyStatus(&newstat, statcopy[m][a][h]); glite_common_log(LOG_CATEGORY_LB_SERVER, LOG_PRIORITY_DEBUG, "NOTIFY: Populating status copy for flag combination [%d][%d][%d]", m, a, h); if (authz_flags & STATUS_FOR_MONITORING) blacken_fields(statcopy[m][a][h], authz_flags); if (authz_flags & READ_ANONYMIZED) anonymize_stat(ctx, statcopy[m][a][h]); if (flags & EDG_WLL_NOTIF_HISTORY) { if (!events) { glite_common_log(LOG_CATEGORY_LB_SERVER, LOG_PRIORITY_DEBUG, "NOTIFY: extracting event history for job %s", jobc[0]); if (!(events = fetch_history(ctx, statcopy[m][a][h]))) { edg_wll_Error(ctx, &errt, &errd); glite_common_log(LOG_CATEGORY_LB_SERVER, LOG_PRIORITY_ERROR, "NOTIFY: query events for %s failed, %s: %s", jobc[0], errt, errd); free(errt); free(errd); edg_wll_ResetError(ctx); continue; } } collate_history(ctx, statcopy[m][a][h], events, authz_flags); } } glite_common_log(LOG_CATEGORY_LB_SERVER, LOG_PRIORITY_DEBUG, "NOTIFY: %s, job %s", jobc[0], ju = edg_wlc_JobIdGetUnique(newstat.jobId)); free(ju); ju = NULL; dest = jobc[1]; if ( edg_wll_NotifIdSetUnique(&nid, jobc[0]) ) { free(dest); goto err; } /* XXX: only temporary hack!!! */ ctx->p_instance = strdup(""); if ( edg_wll_NotifJobStatus(ctx, nid, dest, jobc[3], atoi(jobc[5]), expires, *statcopy[m][a][h], authz_flags) ) { for (i=0; i<sizeof(jobc)/sizeof(jobc[0]); i++) free(jobc[i]); goto err; } } if (! strncmp(jobc[1], "x-msg", 5)) edg_wll_ServerStatisticsIncrement(ctx, SERVER_STATS_NOTIF_MSG_SENT); else edg_wll_ServerStatisticsIncrement(ctx, SERVER_STATS_NOTIF_LEGACY_SENT); for (i=0; i<sizeof(jobc)/sizeof(jobc[0]); i++) free(jobc[i]); } if (ret < 0) goto err; err: for ( m = 0; m < 2 ; m++ ) for ( a = 0; a < 2 ; a++ ) for ( h = 0; h < 2 ; h++ ) if (statcopy[m][a][h] && (m || a || h)) { edg_wll_FreeStatus(statcopy[m][a][h]); free(statcopy[m][a][h]); } free(ctx->p_instance); ctx->p_instance = NULL; if ( nid ) edg_wll_NotifIdFree(nid); free(jobq); glite_lbu_FreeStmt(&jobs); free(cond_where); free(cond_and_where); return edg_wll_Error(ctx,NULL,NULL); }
static int dump_events(edg_wll_Context ctx, glite_jobid_const_t job, int dump, char **res) { edg_wll_Event e; int event; event = atoi(res[0]); free(res[0]); res[0] = NULL; res[0] = edg_wlc_JobIdUnparse(job); if (convert_event_head(ctx,res,&e) || edg_wll_get_event_flesh(ctx,event,&e)) { char *et,*ed, *dbjob; /* Most likely sort of internal inconsistency. * Must not be fatal -- just complain */ edg_wll_Error(ctx,&et,&ed); dbjob = edg_wlc_JobIdGetUnique(job); glite_common_log(LOG_CATEGORY_CONTROL, LOG_PRIORITY_WARN, "%s event %d: %s (%s)", dbjob, event, et, ed); free(et); free(ed); free(dbjob); edg_wll_ResetError(ctx); } else { char *event_s = edg_wll_UnparseEvent(ctx,&e); char arr_s[100]; int len, written, total; strcpy(arr_s, "DG.ARRIVED="); edg_wll_ULMTimevalToDate(e.any.arrived.tv_sec, e.any.arrived.tv_usec, arr_s+strlen("DG.ARRIVED=")); len = strlen(arr_s); total = 0; while (total != len) { written = write(dump,arr_s+total,len-total); if (written < 0 && errno != EAGAIN) { edg_wll_SetError(ctx,errno,"writing dump file"); free(event_s); return edg_wll_Error(ctx,NULL,NULL); } total += written; } write(dump, " ", 1); len = strlen(event_s); total = 0; while (total != len) { written = write(dump,event_s+total,len-total); if (written < 0 && errno != EAGAIN) { glite_common_log(LOG_CATEGORY_CONTROL, LOG_PRIORITY_ERROR, "dump to file"); dump = -1; /* XXX: likely to be a permanent error * give up writing but do purge */ break; } total += written; } /* write(dump,"\n",1); edg_wll_UnparseEvent does so */ free(event_s); } edg_wll_FreeEvent(&e); return edg_wll_Error(ctx,NULL,NULL); }
/* *---------------------------------------------------------------------- * * edg_wll_log_proto_server - handle incoming data * * Returns: 0 if done properly or errno * * Calls: * * Algorithm: * *---------------------------------------------------------------------- */ int edg_wll_log_proto_server(edg_wll_GssConnection *con, struct timeval *timeout, char *name, char *prefix, int noipc, int noparse) { char *buf,*dglllid,*dguser,*jobId,*name_esc; char header[EDG_WLL_LOG_SOCKET_HEADER_LENGTH+1]; char outfilename[FILENAME_MAX]; size_t count; int count_total,size; u_int8_t size_end[4]; size_t msg_size,dglllid_size,dguser_size; int i,answer,answer_sent; int msg_sock; char *msg,*msg_begin; int filedesc,filelock_status; long filepos; int priority; long lllid; int unique; int err; edg_wll_Context context; edg_wll_Event *event; edg_wlc_JobId j; edg_wll_GssStatus gss_stat; errno = i = answer = answer_sent = size = msg_size = dglllid_size = dguser_size = count = count_total = msg_sock = filedesc = filelock_status = /* priority */ unique = err = 0; buf = dglllid = dguser = jobId = name_esc = msg = msg_begin = NULL; event = NULL; /* init */ if (edg_wll_InitContext(&context) != 0) { glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_ERROR,"edg_wll_InitContex(): error.\n"); answer = ENOMEM; goto edg_wll_log_proto_server_end; } if (edg_wll_ResetError(context) != 0) { glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_ERROR,"edg_wll_ResetError(): error.\n"); answer = ENOMEM; goto edg_wll_log_proto_server_end; } /* look for the unique unused long local-logger id (LLLID) */ lllid = 1000*getpid(); for (i=0; (i<1000)&&(!unique); i++) { struct stat statbuf; lllid += i; snprintf(confirm_sock_name, sizeof(confirm_sock_name), "/tmp/dglogd_sock_%ld", lllid); if ((filedesc = stat(confirm_sock_name,&statbuf)) == 0) { glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_WARN,"Warning: LLLID %ld already in use.\n",lllid); } else { if (errno == ENOENT) { unique = 1; } else { glite_common_log_SYS_ERROR("stat"); } } } if (!unique) { glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_ERROR,"Cannot determine the unique long local-logger id (LLLID %ld)!\n",lllid); return EAGAIN; } glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_INFO,"Long local-logger id (LLLID): %ld ... [ok]\n",lllid); /* receive socket header */ memset(header, 0, EDG_WLL_LOG_SOCKET_HEADER_LENGTH+1); if ((err = edg_wll_gss_read_full(con, header, EDG_WLL_LOG_SOCKET_HEADER_LENGTH, timeout, &count, &gss_stat)) < 0) { if (err == EDG_WLL_GSS_ERROR_EOF) { glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_WARN,"Reading socket header - no data available.\n"); answer = err; answer_sent = 1; /* i.e. do not try to send answer back */ } else { glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_WARN,"Error reading socket header.\n"); answer = handle_gss_failures(err,&gss_stat,"Error reading socket header"); } goto edg_wll_log_proto_server_end; } else { glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_DEBUG,"Reading socket header... [ok]\n"); } /* Check socket header */ header[EDG_WLL_LOG_SOCKET_HEADER_LENGTH] = '\0'; if (strncmp(header,EDG_WLL_LOG_SOCKET_HEADER,EDG_WLL_LOG_SOCKET_HEADER_LENGTH)) { /* not the proper socket header text */ glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_WARN,"edg_wll_log_proto_server(): invalid socket header\n"); glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_DEBUG,"edg_wll_log_proto_server(): read header '%s' instead of '%s'\n", header,EDG_WLL_LOG_SOCKET_HEADER); answer = EINVAL; goto edg_wll_log_proto_server_end; } else { glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_DEBUG,"Read socket header: \"%s\" [ok]\n",header); } /* XXX: obsolete count = 0; if ((err = edg_wll_gss_read_full(con, &priority, sizeof(priority), timeout, &count, &gss_stat)) < 0) { glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_WARN,"Error reading message priority.\n"); answer = handle_gss_failures(err,&gss_stat,"Error receiving message priority"); goto edg_wll_log_proto_server_end; } else { glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_DEBUG,"Read message priority: %d [ok]\n",priority); } */ /* read message size */ count = 0; if ((err = edg_wll_gss_read_full(con, size_end, 4, timeout, &count,&gss_stat)) < 0) { glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_DEBUG,"Error reading message size.\n"); answer = handle_gss_failures(err,&gss_stat,"Error reading message size"); goto edg_wll_log_proto_server_end; } else { glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_DEBUG,"Reading message size... [ok]\n"); } size = size_end[3]; size <<=8; size |= size_end[2]; size <<=8; size |= size_end[1]; size <<=8; size |= size_end[0]; if (size <= 0) { /* probably wrong size in the header or nothing to read */ glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_WARN,"edg_wll_log_proto_server(): invalid size read from socket header\n"); glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_DEBUG,"Read message size '%d' [error].\n",size); answer = EINVAL; goto edg_wll_log_proto_server_end; } else { glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_DEBUG,"Read message size: %d bytes [ok].\n",size); } /* format the DG.LLLID string */ if (asprintf(&dglllid,"DG.LLLID=%ld ",lllid) == -1) { glite_common_log_SYS_ERROR("asprintf"); glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_WARN,"edg_wll_log_proto_server(): nomem for DG.LLLID\n"); answer = ENOMEM; goto edg_wll_log_proto_server_end; } dglllid_size = strlen(dglllid); /* format the DG.USER string */ name_esc = glite_lbu_EscapeULM(name); if (asprintf(&dguser,"DG.USER=\"%s\" ",name_esc) == -1) { glite_common_log_SYS_ERROR("asprintf"); glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_WARN,"edg_wll_log_proto_server(): nomem for DG.USER\n"); answer = ENOMEM; goto edg_wll_log_proto_server_end; } dguser_size = strlen(dguser); /* allocate enough memory for all data */ msg_size = dglllid_size + dguser_size + size + 1; if ((msg = malloc(msg_size)) == NULL) { glite_common_log_SYS_ERROR("malloc"); glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_WARN,"edg_wll_log_proto_server(): out of memory for allocating message\n"); answer = ENOMEM; goto edg_wll_log_proto_server_end; } strncpy(msg,dglllid,dglllid_size); msg_begin = msg + dglllid_size; // this is the "official" beginning of the message strncpy(msg_begin,dguser,dguser_size); /* receive message */ buf = msg_begin + dguser_size; count = 0; if ((err = edg_wll_gss_read_full(con, buf, size, timeout, &count, &gss_stat)) < 0) { glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_WARN,"Error reading message from socket.\n"); answer = handle_gss_failures(err,&gss_stat,"Error reading message from socket."); goto edg_wll_log_proto_server_end; } else { glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_DEBUG,"Reading message... [ok]\n"); // glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_TRACE,"Read message: \"%s\"\n",msg); } buf[count] = '\0'; /* parse message and get jobId and priority from it */ if (!noparse && strstr(msg, "DG.TYPE=\"command\"") == NULL) { if (edg_wll_ParseEvent(context,msg_begin,&event) != 0) { glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_WARN,"edg_wll_log_proto_server(): edg_wll_ParseEvent error\n"); glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_WARN,"edg_wll_ParseEvent(): %s\n",context->errDesc); answer = edg_wll_Error(context,NULL,NULL); goto edg_wll_log_proto_server_end; } else { glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_DEBUG,"Parsing message for correctness...[ok]\n"); } jobId = edg_wlc_JobIdGetUnique(event->any.jobId); priority = event->any.priority; edg_wll_FreeEvent(event); event->any.priority = priority; glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_DEBUG,"Getting jobId from message...[ok]\n"); } else { if ((event = edg_wll_InitEvent(EDG_WLL_EVENT_UNDEF)) == NULL) { glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_WARN, "edg_wll_InitEvent(): out of memory\n"); answer = ENOMEM; goto edg_wll_log_proto_server_end; } jobId = edg_wll_GetJobId(msg); if (!jobId || edg_wlc_JobIdParse(jobId,&j)) { glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_WARN,"Error getting jobId from message.\n"); glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_WARN,"edg_wlc_JobIdParse(%s)\n",jobId?jobId:"NULL"); answer = EINVAL; goto edg_wll_log_proto_server_end; } else { glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_DEBUG,"Getting jobId from message...[ok]\n"); } free(jobId); jobId = edg_wlc_JobIdGetUnique(j); edg_wlc_JobIdFree(j); /* TODO: get the priority from message some better way */ if (strstr(msg, "DG.PRIORITY=1") != NULL) event->any.priority = 1; else event->any.priority = 0; } if (event->any.priority & (EDG_WLL_LOGFLAG_SYNC|EDG_WLL_LOGFLAG_SYNC_COMPAT)) { if(init_confirmation() < 0) { glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_WARN,"Error initializing 2nd UNIX socket (%s) for priority messages confirmation.\n",confirm_sock_name); answer = errno; goto edg_wll_log_proto_server_end; } else { glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_DEBUG,"Initializing 2nd UNIX socket (%s) for priority messages confirmation...[ok]\n",confirm_sock_name); } } /* if not command, save message to file */ if(strstr(msg, "DG.TYPE=\"command\"") == NULL) { /* compose the name of the log file */ count = strlen(prefix); strncpy(outfilename,prefix,count); count_total=count; strncpy(outfilename+count_total,".",1); count_total+=1; count=strlen(jobId); strncpy(outfilename+count_total,jobId,count); count_total+=count; outfilename[count_total]='\0'; // glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_DEBUG,"Composing filename from prefix \"%s\" and unique jobId \"%s\"...[ok]",prefix,jobId); /* fopen and properly handle the filelock */ #ifdef LOGD_NOFILE glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_INFO,"NOT writing message to \"%s\".\n",outfilename); filepos = 0; #else if ( edg_wll_log_event_write(context, outfilename, msg, FCNTL_ATTEMPTS, FCNTL_TIMEOUT, &filepos) ) { char *errd; // FIXME: there is probably not a correct errno glite_common_log_SYS_ERROR("edg_wll_log_event_write"); answer = edg_wll_Error(context, NULL, &errd); glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_WARN,"edg_wll_log_event_write error: %s\n",errd); free(errd); goto edg_wll_log_proto_server_end; } else glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_INFO,"Writing message to \"%s\"... [ok]",outfilename); #endif } else { filepos = 0; } #ifdef LB_PERF glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_INFO,"Calling perftest\n"); glite_wll_perftest_consumeEventString(msg); glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_INFO,"Calling perftest... [done]\n"); #endif /* if not priority send now the answer back to client */ if (!(event->any.priority & (EDG_WLL_LOGFLAG_SYNC|EDG_WLL_LOGFLAG_SYNC_COMPAT))) { if (!send_answer_back(con,answer,timeout)) { answer_sent = 1; } } /* send message via IPC (UNIX socket) */ if (!noipc) { if ( edg_wll_log_event_send(context, socket_path, filepos, msg, msg_size, CONNECT_ATTEMPTS, timeout) ) { char *errd; // XXX: probably not a SYSTEM ERROR // glite_common_log_SYS_ERROR("edg_wll_log_event_send"); answer = edg_wll_Error(context, NULL, &errd); glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_WARN,"edg_wll_log_event_send error: %s\n",errd); free(errd); goto edg_wll_log_proto_server_end_1; } else glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_DEBUG, "Sending via IPC (UNIX socket \"%s\")\n\t" "the message position %ld (%ld bytes)... [ok]", socket_path, filepos, sizeof(filepos)); } else { glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_DEBUG,"NOT sending via IPC.\n"); } if (event->any.priority & (EDG_WLL_LOGFLAG_SYNC|EDG_WLL_LOGFLAG_SYNC_COMPAT)) { if ((count = wait_for_confirmation(timeout, &answer)) < 0) { glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_WARN,"Error waiting for confirmation.\n"); answer = errno; } else { glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_DEBUG,"Waiting for confirmation... [ok].\n"); if (count == 0) { glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_DEBUG,"Waking up, timeout expired.\n"); answer = EAGAIN; } else { glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_DEBUG,"Confirmation received, waking up.\n"); } } } edg_wll_log_proto_server_end: /* if not sent already, send the answer back to client */ if (!answer_sent) { answer = send_answer_back(con,answer,timeout); } /* clean */ edg_wll_FreeContext(context); if (name_esc) free(name_esc); if (dglllid) free(dglllid); if (dguser) free(dguser); if (jobId) free(jobId); if (msg) free(msg); if (event) free(event); // glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_INFO,"Done.\n"); return answer; edg_wll_log_proto_server_end_1: if (event->any.priority) { close(confirm_sock); unlink(confirm_sock_name); } goto edg_wll_log_proto_server_end; }
int edg_wll_SetSequenceCode(edg_wll_Context ctx, const char * seqcode_str, int seq_type) { int res; unsigned int *c; edg_wll_ResetError(ctx); ctx->p_seqcode.type = seq_type; switch (seq_type) { case EDG_WLL_SEQ_CREAM: /* fall through */ case EDG_WLL_SEQ_DUPLICATE: /* fall through */ case EDG_WLL_SEQ_NORMAL: if (!seqcode_str) { memset(&ctx->p_seqcode.c, 0, sizeof ctx->p_seqcode.c); return 0; } c = &ctx->p_seqcode.c[0]; res = sscanf(seqcode_str, EDG_WLL_SEQ_FORMAT_SCANF, &c[EDG_WLL_SOURCE_USER_INTERFACE], &c[EDG_WLL_SOURCE_NETWORK_SERVER], &c[EDG_WLL_SOURCE_WORKLOAD_MANAGER], &c[EDG_WLL_SOURCE_BIG_HELPER], &c[EDG_WLL_SOURCE_JOB_SUBMISSION], &c[EDG_WLL_SOURCE_LOG_MONITOR], &c[EDG_WLL_SOURCE_LRMS], &c[EDG_WLL_SOURCE_APPLICATION], &c[EDG_WLL_SOURCE_LB_SERVER]); /* XXX: can't be true anymore. What was the reason for assert()? assert(EDG_WLL_SOURCE__LAST == 10); */ if (res == EDG_WLL_SOURCE_LB_SERVER-1) { /* pre-collections compatibility */ c[EDG_WLL_SOURCE_LB_SERVER] = 0; } else if (res != EDG_WLL_SEQ_FORMAT_NUMBER) { if (seq_type == EDG_WLL_SEQ_CREAM) return 0; else return edg_wll_SetError(ctx, EINVAL, "edg_wll_SetSequenceCode(): syntax error in sequence code"); } if (seq_type == EDG_WLL_SEQ_DUPLICATE) { if (ctx->p_source <= EDG_WLL_SOURCE_NONE || ctx->p_source >= EDG_WLL_SOURCE__LAST) { return edg_wll_SetError(ctx,EINVAL, "edg_wll_SetSequenceCode(): context param: source missing"); } c[ctx->p_source] = time(NULL); } break; case EDG_WLL_SEQ_PBS: /* original version if (!seqcode_str) memset(&ctx->p_seqcode.pbs, 0, sizeof ctx->p_seqcode.pbs); else strncpy(ctx->p_seqcode.pbs, seqcode_str, sizeof(ctx->p_seqcode.pbs)); */ if (!seqcode_str) { memset(&ctx->p_seqcode.c, 0, sizeof(ctx->p_seqcode.c)); return 0; } c = ctx->p_seqcode.c; res = sscanf(seqcode_str, EDG_WLL_SEQ_PBS_FORMAT_SCANF, &c[EDG_WLL_SOURCE_PBS_CLIENT], &c[EDG_WLL_SOURCE_PBS_SERVER], &c[EDG_WLL_SOURCE_PBS_SCHEDULER], &c[EDG_WLL_SOURCE_PBS_SMOM], &c[EDG_WLL_SOURCE_PBS_MOM]); if(res != EDG_WLL_SEQ_PBS_FORMAT_NUMBER) { return edg_wll_SetError(ctx, EINVAL, "edg_wll_SetSequenceCode(): syntax error in sequence code"); } break; case EDG_WLL_SEQ_CONDOR: if (!seqcode_str) memset(&ctx->p_seqcode.condor, 0, sizeof ctx->p_seqcode.condor); else strncpy(ctx->p_seqcode.condor, seqcode_str, sizeof(ctx->p_seqcode.condor)); break; default: return edg_wll_SetError(ctx, EINVAL, "edg_wll_SetSequenceCode(): unrecognized value of seq_type parameter"); } return edg_wll_Error(ctx, NULL, NULL); }
int main(int argc,char **argv) { edg_wll_Context ctx; edg_wll_QueryRec **conditions = NULL; time_t valid = 0; char *errt, *errd; void *fields = NULL; int sock = -1, flags = 0; char *fake_addr = NULL; // sleep(20); me = argv[0]; if (edg_wll_InitContext(&ctx) != 0) { fprintf(stderr, "Couldn't create L&B context.\n"); exit(1); } if ( argc < 2 ) { usage(NULL); goto cleanup; } if ( (argc < 2) || !strcmp(argv[1], "help") || !strcmp(argv[1], "--help") || !strcmp(argv[1], "-h") || !strcmp(argv[1], "-?")) { usage(NULL); goto cleanup; } else if ( !strcmp(argv[1], "new") ) { int c; edg_wlc_JobId jid; edg_wll_NotifId id_out; int attr = 0, i = 0, excl = 0; edg_wll_GssCred mycred; edg_wll_GssStatus gss_code; static struct option long_options[] = { {"state", required_argument, 0, 'S'}, {"jdl", no_argument, 0, 'J'}, {"bootstrap", no_argument, 0, 'B'}, {"terminal", no_argument, 0, 'T'}, {"history", no_argument, 0, 'H'}, {"anonymize", no_argument, 0, 'N'}, {"type", no_argument, 0, 'E'}, {0, 0, 0, 0}}; int option_index = 0; char *single, *statelist, *notif_server, *typelist, *type, *typestor; edg_wll_JobStatCode single_code; enum edg_wll_StatJobtype typecode; int statno, stdelims, sti; unsigned int notif_server_port; #define MAX_NEW_CONDS 7 conditions = (edg_wll_QueryRec **)calloc(MAX_NEW_CONDS + 1,sizeof(edg_wll_QueryRec *)); conditions[0] = (edg_wll_QueryRec *)calloc(2,sizeof(edg_wll_QueryRec)); while ((c = getopt_long(argc-1,argv+1,"j:o:v:n:s:a:t:f:cOS:JBTHNE:",long_options,&option_index)) > 0) { switch (c) { case 'j': conditions[i] = (edg_wll_QueryRec *)calloc(2,sizeof(edg_wll_QueryRec)); conditions[i][0].attr = EDG_WLL_QUERY_ATTR_JOBID; conditions[i][0].op = EDG_WLL_QUERY_OP_EQUAL; if (edg_wlc_JobIdParse(optarg, &jid) ) { fprintf(stderr,"Job ID parameter not set propperly!\n"); usage("new"); goto cleanup; } conditions[i][0].value.j = jid; i++; edg_wll_GetParam(ctx, EDG_WLL_PARAM_NOTIF_SERVER, ¬if_server); if (!notif_server) { glite_jobid_getServerParts(jid, ¬if_server, ¬if_server_port); edg_wll_SetParam(ctx, EDG_WLL_PARAM_NOTIF_SERVER, notif_server); edg_wll_SetParamInt(ctx, EDG_WLL_PARAM_NOTIF_SERVER_PORT, notif_server_port); } free(notif_server); break; case 'o': if (excl) { usage("new"); return EX_USAGE; } else excl = 1; conditions[i] = (edg_wll_QueryRec *)calloc(2,sizeof(edg_wll_QueryRec)); conditions[i][0].attr = EDG_WLL_QUERY_ATTR_OWNER; conditions[i][0].op = EDG_WLL_QUERY_OP_EQUAL; conditions[i][0].value.c = optarg; i++; break; case 'v': conditions[i] = (edg_wll_QueryRec *)calloc(2,sizeof(edg_wll_QueryRec)); conditions[i][0].attr = EDG_WLL_QUERY_ATTR_JDL_ATTR; conditions[i][0].op = EDG_WLL_QUERY_OP_EQUAL; conditions[i][0].value.c = optarg; asprintf(&(conditions[i][0].attr_id.tag), "VirtualOrganisation"); i++; break; case 'n': conditions[i] = (edg_wll_QueryRec *)calloc(2,sizeof(edg_wll_QueryRec)); conditions[i][0].attr = EDG_WLL_QUERY_ATTR_NETWORK_SERVER; conditions[i][0].op = EDG_WLL_QUERY_OP_EQUAL; conditions[i][0].value.c = optarg; i++; break; case 's': if (fake_addr) { usage("new"); return EX_USAGE; } sock = atoi(optarg); break; case 'a': if (sock >= 0) { usage("new"); return EX_USAGE; } fake_addr = optarg; break; case 't': valid = time(NULL) + atol(optarg); break; case 'f': flags |= atoi(optarg); break; case 'J': flags |= EDG_WLL_STAT_CLASSADS; break; case 'B': flags |= EDG_WLL_NOTIF_BOOTSTRAP; break; case 'T': flags |= EDG_WLL_NOTIF_TERMINAL_STATES; break; case 'H': flags |= EDG_WLL_NOTIF_TERMINAL_STATES | EDG_WLL_NOTIF_HISTORY; break; case 'N': flags |= EDG_WLL_NOTIF_ANONYMIZE; break; case 'c': conditions[i] = (edg_wll_QueryRec *)calloc(2,sizeof(edg_wll_QueryRec)); conditions[i][0].attr = EDG_WLL_QUERY_ATTR_STATUS; conditions[i][0].op = EDG_WLL_QUERY_OP_CHANGED; i++; break; case 'O': if (excl) { usage("new"); return EX_USAGE; } else excl = 1; if ( !edg_wll_gss_acquire_cred(NULL, NULL, GSS_C_INITIATE, &mycred, &gss_code) ) { conditions[i] = (edg_wll_QueryRec *)calloc(2,sizeof(edg_wll_QueryRec)); conditions[i][0].attr = EDG_WLL_QUERY_ATTR_OWNER; conditions[i][0].op = EDG_WLL_QUERY_OP_EQUAL; conditions[i][0].value.c = strdup(mycred->name); edg_wll_gss_release_cred(&mycred, NULL); i++; } else { fprintf(stderr,"No credentials found! Exiting. \n"); goto cleanup; } break; case 'S': statelist = optarg; statno = 0; stdelims = 0; for (sti = 0; sti < strlen(statelist); sti++) if (statelist[sti] == ',') stdelims++; conditions[i] = (edg_wll_QueryRec *)calloc(stdelims+2,sizeof(edg_wll_QueryRec)); while((single = strtok(statelist, ","))) { single_code = edg_wll_StringToStat(single); if (single_code != -1) { conditions[i][statno].attr = EDG_WLL_QUERY_ATTR_STATUS; conditions[i][statno].op = EDG_WLL_QUERY_OP_EQUAL; conditions[i][statno].value.i = single_code; statelist = NULL; statno++; } else { fprintf(stderr,"'%s' is not a valid state name! Exitting.\n", single); goto cleanup; } } i++; break; case 'E': typelist = optarg; statno = 0; for( type = strtok_r(typelist, ",", &typestor); type ; type = strtok_r(NULL, ",", &typestor)) statno++; conditions[i] = (edg_wll_QueryRec *)calloc(statno+1,sizeof(edg_wll_QueryRec)); statno = 0; for( type = strtok_r(typelist, ",", &typestor); type ; type = strtok_r(NULL, ",", &typestor)) { typecode=edg_wll_JobtypeStrToCode(type); if (((int)typecode)<0) { fprintf(stderr,"'%s' is not a valid job type! Exitting.\n", type); goto cleanup; } else { conditions[i][statno].attr = EDG_WLL_QUERY_ATTR_JOB_TYPE; conditions[i][statno].op = EDG_WLL_QUERY_OP_EQUAL; conditions[i][statno].value.i = typecode; statelist = NULL; statno++; } } i++; break; default: usage("new"); return EX_USAGE; } if (i > MAX_NEW_CONDS) { usage("new"); return EX_USAGE; } } if ( !edg_wll_NotifNew(ctx, (edg_wll_QueryRec const* const*)conditions, flags, sock, fake_addr, &id_out, &valid)) fprintf(stdout,"notification ID: %s\nvalid: %s (%ld)\n", edg_wll_NotifIdUnparse(id_out), TimeToStr(valid), valid); edg_wll_NotifIdFree(id_out); if (attr == EDG_WLL_QUERY_ATTR_JOBID) edg_wlc_JobIdFree(jid); if (edg_wll_Error(ctx,&errt,&errd)) { fprintf(stderr, "%s: %s (%s)\n", me, errt, errd); return EX_IOERR; } } else if ( !strcmp(argv[1], "bind") ) { edg_wll_NotifId nid; int c; while ((c = getopt(argc-1,argv+1,"s:a:t:")) > 0) switch (c) { case 's': if (fake_addr) { usage("bind"); return EX_USAGE; } sock = atoi(optarg); break; case 'a': if (sock >= 0) { usage("bind"); return EX_USAGE; } fake_addr = optarg; break; case 't': valid = time(NULL) + atol(optarg); break; default: usage("bind"); return EX_USAGE; } if ( (optind+1 == argc) || edg_wll_NotifIdParse(argv[optind+1], &nid) ) { fprintf(stderr,"Notification ID parameter not set propperly!\n\n"); usage("bind"); return EX_USAGE; } if ( !edg_wll_NotifBind(ctx, nid, sock, fake_addr, &valid) ) printf("valid until: %s (%ld)\n", TimeToStr(valid), valid); edg_wll_NotifIdFree(nid); if (edg_wll_Error(ctx,&errt,&errd)) { fprintf(stderr, "%s: %s (%s)\n", me, errt, errd); return EX_IOERR; } } else if ( !strcmp(argv[1], "receive") ) { edg_wll_JobStat stat; edg_wll_NotifId nid = NULL; int c; char *field_arg = "owner",*err; time_t client_tout = time(NULL) + 600; int refresh = 0; struct timeval tout; time_t opt_valid = 0,do_refresh = client_tout,now; while ((c = getopt(argc-1,argv+1,"s:a:i:f:t:r")) > 0) switch (c) { case 's': if (fake_addr || refresh || opt_valid) { usage("receive"); return EX_USAGE; } sock = atoi(optarg); break; case 'a': if (sock >= 0) { usage("receive"); return EX_USAGE; } fake_addr = optarg; break; case 'i': client_tout = time(NULL) + atoi(optarg); break; case 'f': field_arg = optarg; break; case 't': if (sock >= 0) { usage("receive"); return EX_USAGE; } opt_valid = atol(optarg); break; case 'r': if (sock >= 0) { usage("receive"); return EX_USAGE; } refresh = 1; break; default: usage("receive"); return EX_USAGE; } if (opt_valid == 0) opt_valid = 3600; if ((err = glite_lb_parse_stat_fields(field_arg,&fields))) { fprintf(stderr,"%s: invalid argument\n",err); return EX_USAGE; } memset(&stat,0,sizeof stat); if (sock == -1) { int param = optind+1; if (param == argc) { fprintf(stderr, "Notification ID parameter not set propperly!\n\n"); usage("receive"); return EX_USAGE; } valid = time(NULL) + opt_valid; while (param < argc) { if (edg_wll_NotifIdParse(argv[param], &nid)) { fprintf(stderr, "Notification ID parameter not set propperly!\n\n"); usage("receive"); return EX_USAGE; } if (edg_wll_NotifBind(ctx, nid, -1, fake_addr, &valid) ) goto receive_err; fprintf(stderr,"notification is valid until: %s (%ld)\n", TimeToStr(valid), valid); param++; } now = time(NULL); do_refresh = now + (valid - now)/2; if (refresh) fprintf(stderr,"next refresh %s (%ld)\n", TimeToStr(do_refresh),do_refresh); } do { edg_wll_NotifId recv_nid = NULL; int err; tout.tv_sec = (refresh && client_tout >= do_refresh ? do_refresh : client_tout) - time(NULL); if (tout.tv_sec < 0) tout.tv_sec = 0; tout.tv_usec = 0; if ( (err = edg_wll_NotifReceive(ctx, sock, &tout, &stat, &recv_nid)) ) { edg_wll_NotifIdFree(recv_nid); recv_nid = NULL; if (err != ETIMEDOUT) goto receive_err; } else { glite_lb_print_stat_fields(fields,&stat); edg_wll_FreeStatus(&stat); stat.state = EDG_WLL_JOB_UNDEF; } if ((now = time(NULL)) >= client_tout) goto cleanup; if (refresh && now >= do_refresh) { valid = now + opt_valid; if (!edg_wll_NotifRefresh(ctx,nid,&valid)) { do_refresh = now + (valid - now)/2; fprintf(stderr,"notification is valid until: %s (%ld)\n",TimeToStr(valid), valid); fprintf(stderr,"next refresh %s (%ld)\n", TimeToStr(do_refresh),do_refresh); } else { char *et,*ed; edg_wll_Error(ctx,&et,&ed); do_refresh = now + (valid - now)/2; fprintf(stderr,"warning: edg_wll_NotifRefresh failed (%s, %s)\n" "next refresh %s (%ld)\n", et,ed,TimeToStr(do_refresh),do_refresh); } } /* original example */ #if 0 printf("\nnotification ID: %s\n", edg_wll_NotifIdUnparse(recv_nid)); if (stat.state != EDG_WLL_JOB_UNDEF) { char *jobid_s; jobid_s = edg_wlc_JobIdUnparse(stat.jobId); printf("Jobid:\t%s\nStatus:\t%s\n", jobid_s, edg_wll_StatToString(stat.state)); edg_wll_FreeStatus(&stat); free(jobid_s); stat.state = EDG_WLL_JOB_UNDEF; } #endif if (recv_nid) { edg_wll_NotifIdFree(recv_nid); recv_nid = NULL; } } while (1); // till timeout.... return 0; receive_err: if (stat.state != EDG_WLL_JOB_UNDEF) edg_wll_FreeStatus(&stat); if (nid) edg_wll_NotifIdFree(nid); edg_wll_NotifCloseFd(ctx); edg_wll_NotifClosePool(ctx); if (edg_wll_Error(ctx,&errt,&errd)) fprintf(stderr, "%s: %s (%s)\n", me, errt, errd); return EX_IOERR; } else if ( !strcmp(argv[1], "change") ) { edg_wlc_JobId jid; edg_wll_NotifId nid; if ( (argc < 3) || edg_wll_NotifIdParse(argv[2], &nid) ) { printf("Notification ID parameter not set propperly!\n"); usage("bind"); return 1; } if ( (argc < 4) || edg_wlc_JobIdParse(argv[3], &jid) ) { fprintf(stderr,"Job ID parameter not set propperly!\n"); usage("change"); goto cleanup; } conditions = (edg_wll_QueryRec **)calloc(2,sizeof(edg_wll_QueryRec *)); conditions[0] = (edg_wll_QueryRec *)calloc(2,sizeof(edg_wll_QueryRec)); conditions[0][0].attr = EDG_WLL_QUERY_ATTR_JOBID; conditions[0][0].op = EDG_WLL_QUERY_OP_EQUAL; conditions[0][0].value.j = jid; conditions[1] = NULL; /*conditions[1] = (edg_wll_QueryRec *)calloc(3, sizeof(edg_wll_QueryRec)); conditions[1][0].attr = EDG_WLL_QUERY_ATTR_STATUS; conditions[1][0].op = EDG_WLL_QUERY_OP_EQUAL; conditions[1][0].value.i = EDG_WLL_JOB_DONE; conditions[1][1].attr = EDG_WLL_QUERY_ATTR_STATUS; conditions[1][1].op = EDG_WLL_QUERY_OP_EQUAL; conditions[1][1].value.i = EDG_WLL_JOB_RUNNING;*/ edg_wll_NotifChange(ctx, nid, (edg_wll_QueryRec const * const *) conditions, EDG_WLL_NOTIF_REPLACE); edg_wlc_JobIdFree(jid); edg_wll_NotifIdFree(nid); } else if ( !strcmp(argv[1], "refresh") ) { edg_wll_NotifId nid; int c; while ((c = getopt(argc-1,argv+1,"t:")) > 0) switch (c) { case 't': valid = time(NULL) + atol(optarg); break; default: usage("refresh"); return EX_USAGE; } if ( (optind+1 == argc) || edg_wll_NotifIdParse(argv[optind+1], &nid) ) { fprintf(stderr,"Notification ID parameter not set propperly!\n\n"); usage("refresh"); return EX_USAGE; } if ( !edg_wll_NotifRefresh(ctx, nid, &valid) ) printf("valid until: %s (%ld)\n", TimeToStr(valid), valid); edg_wll_NotifIdFree(nid); } else if ( !strcmp(argv[1], "drop") ) { edg_wll_NotifId nid; if ( (argc < 3) || edg_wll_NotifIdParse(argv[2], &nid) ) { fprintf(stderr,"Notification ID parameter not set propperly!\n"); usage("drop"); return EX_USAGE; } edg_wll_NotifDrop(ctx, nid); edg_wll_NotifIdFree(nid); } else { usage(NULL); return EX_USAGE; } cleanup: if ( conditions ) { /* for ( i = 0; conditions[i][0].attr; i++ ) free(conditions[1]); */ free(conditions); } int retval; if (retval = edg_wll_Error(ctx,&errt,&errd)) fprintf(stderr, "%s: %s (%s)\n", me, errt, errd); edg_wll_NotifCloseFd(ctx); edg_wll_FreeContext(ctx); edg_wll_poolFree(); return retval; }
int purge_one(edg_wll_Context ctx,edg_wll_JobStat *stat,int dump, int purge, int purge_from_proxy_only) { char *dbjob = NULL; char *stmt = NULL; glite_lbu_Statement q = NULL; int ret,dumped = 0; char *res[10]; char *prefix = NULL, *suffix = NULL, *root = NULL; char *prefix_id = NULL, *suffix_id = NULL; int sql_retval; glite_jobid_const_t job = stat->jobId; edg_wll_JobStat new_stat; edg_wll_ResetError(ctx); if ( !purge && dump < 0 ) return 0; do { if (edg_wll_Transaction(ctx)) goto err; switch (edg_wll_jobMembership(ctx, job)) { case DB_PROXY_JOB: if (!ctx->isProxy) { /* should not happen */ goto commit; } /* continue */ break; case DB_SERVER_JOB: if (purge_from_proxy_only) { /* no action needed */ goto commit; } if (ctx->isProxy) { /* should not happen */ goto commit; } /* continue */ break; case DB_PROXY_JOB+DB_SERVER_JOB: if (ctx->isProxy) { purge = 0; if (unset_proxy_flag(ctx, job) < 0) { goto rollback; } } else { purge = 0; /* if server&proxy DB is shared ... */ if (is_job_local(ctx,job) && purge_from_proxy_only) { if (unset_proxy_flag(ctx, job) < 0) { goto rollback; } } else { if (unset_server_flag(ctx, job) < 0) { goto rollback; } } } break; case 0: // Zombie job (server=0, proxy=0)? should not happen; // clear it to keep DB healthy break; default: goto rollback; break; } dbjob = glite_jobid_getUnique(job); /* XXX: strict jobid already checked */ if ( purge ) { enum edg_wll_StatJobtype jobtype = get_job_type(ctx, job); // get job prefix/suffix before its state is deleted if ( jobtype == EDG_WLL_NUMBER_OF_JOBTYPES) goto rollback; if (get_jobid_suffix(ctx, job, jobtype, &root, &suffix) || get_jobid_prefix(ctx, job, jobtype, &prefix)) { glite_common_log(LOG_CATEGORY_CONTROL, LOG_PRIORITY_WARN, "[%d] unknown job type %d of job %s", getpid(), jobtype, dbjob); edg_wll_ResetError(ctx); } // notifications memcpy(&new_stat, stat, sizeof new_stat); new_stat.state = EDG_WLL_JOB_PURGED; edg_wll_NotifMatch(ctx, stat, &new_stat); } if ( purge ) { edg_wll_jobsconnection_purgeall(ctx, job); } if ( purge ) { trio_asprintf(&stmt,"delete from jobs where jobid = '%|Ss'",dbjob); glite_common_log_msg(LOG_CATEGORY_LB_SERVER_DB, LOG_PRIORITY_DEBUG, stmt); if (edg_wll_ExecSQL(ctx,stmt,NULL) < 0) goto rollback; free(stmt); stmt = NULL; trio_asprintf(&stmt,"delete from states where jobid = '%|Ss'",dbjob); glite_common_log_msg(LOG_CATEGORY_LB_SERVER_DB, LOG_PRIORITY_DEBUG, stmt); if (edg_wll_ExecSQL(ctx,stmt,NULL) < 0) goto rollback; free(stmt); stmt = NULL; trio_asprintf(&stmt,"delete from status_tags where jobid = '%|Ss'",dbjob); glite_common_log_msg(LOG_CATEGORY_LB_SERVER_DB, LOG_PRIORITY_DEBUG, stmt); if (edg_wll_ExecSQL(ctx,stmt,NULL) < 0) goto rollback; free(stmt); stmt = NULL; } if ( purge && prefix && suffix ) { /* Store zombie prefix */ // See if that prefix is already stored in the database trio_asprintf(&stmt,"select prefix_id from zombie_prefixes where prefix = '%|Ss'", prefix); glite_common_log_msg(LOG_CATEGORY_LB_SERVER_DB, LOG_PRIORITY_DEBUG, stmt); sql_retval = edg_wll_ExecSQL(ctx,stmt,&q); free(stmt); stmt = NULL; if (sql_retval < 0) goto rollback; if (sql_retval == 0) { //prefix does not exist yet glite_lbu_FreeStmt(&q); trio_asprintf(&stmt,"insert into zombie_prefixes (prefix) VALUES ('%|Ss')", prefix); glite_common_log_msg(LOG_CATEGORY_LB_SERVER_DB, LOG_PRIORITY_DEBUG, stmt); if (edg_wll_ExecSQL(ctx,stmt,&q) <= 0) goto rollback; free(stmt); stmt = NULL; glite_lbu_FreeStmt(&q); // The record should exist now, however we need to look up the prefix_id trio_asprintf(&stmt,"select prefix_id from zombie_prefixes where prefix = '%|Ss'", prefix); glite_common_log_msg(LOG_CATEGORY_LB_SERVER_DB, LOG_PRIORITY_DEBUG, stmt); if (edg_wll_ExecSQL(ctx,stmt,&q) <= 0) goto rollback; free(stmt); stmt = NULL; } ret = edg_wll_FetchRow(ctx,q, 1, NULL, &prefix_id); glite_lbu_FreeStmt(&q); /* Store zombie suffix */ // See if that suffix is already stored in the database trio_asprintf(&stmt,"select suffix_id from zombie_suffixes where suffix = '%|Ss'", suffix); glite_common_log_msg(LOG_CATEGORY_LB_SERVER_DB, LOG_PRIORITY_DEBUG, stmt); sql_retval = edg_wll_ExecSQL(ctx,stmt,&q); free(stmt); stmt = NULL; if (sql_retval < 0) goto rollback; if (sql_retval == 0) { //suffix does not exist yet glite_lbu_FreeStmt(&q); trio_asprintf(&stmt,"insert into zombie_suffixes (suffix) VALUES ('%|Ss')", suffix); glite_common_log_msg(LOG_CATEGORY_LB_SERVER_DB, LOG_PRIORITY_DEBUG, stmt); if (edg_wll_ExecSQL(ctx,stmt,&q) <= 0) goto rollback; free(stmt); stmt = NULL; glite_lbu_FreeStmt(&q); // The record should exist now, however we need to look up the suffix_id trio_asprintf(&stmt,"select suffix_id from zombie_suffixes where suffix = '%|Ss'", suffix); glite_common_log_msg(LOG_CATEGORY_LB_SERVER_DB, LOG_PRIORITY_DEBUG, stmt); if (edg_wll_ExecSQL(ctx,stmt,&q) <= 0) goto rollback; free(stmt); stmt = NULL; } ret = edg_wll_FetchRow(ctx,q, 1, NULL, &suffix_id); glite_lbu_FreeStmt(&q); /* Store zombie job */ trio_asprintf(&stmt,"insert into zombie_jobs (jobid, prefix_id, suffix_id)" " VALUES ('%|Ss', '%|Ss', '%|Ss')", root, prefix_id, suffix_id); glite_common_log_msg(LOG_CATEGORY_LB_SERVER_DB, LOG_PRIORITY_DEBUG, stmt); if (edg_wll_ExecSQL(ctx,stmt,&q) < 0) { if (edg_wll_Error(ctx, NULL, NULL) == EEXIST) { /* job already among zombies */ /* print warning but continue */ /* erasing other jobs */ char *et, *ed, *msg, *job_s; edg_wll_Error(ctx, &et, &ed); job_s = glite_jobid_unparse(job); asprintf(&msg,"Warning: erasing job %s that already existed in this LB " "(reused jobid or corruped DB) (%s: %s)",job_s,et,ed); glite_common_log(LOG_CATEGORY_CONTROL, LOG_PRIORITY_WARN, "[%d] %s", getpid(), msg); free(et); free(ed); free(msg); free(job_s); edg_wll_ResetError(ctx); } else goto rollback; } glite_lbu_FreeStmt(&q); free(stmt); stmt = NULL; } if (dump >= 0) trio_asprintf(&stmt, "select event,code,prog,host,u.cert_subj,time_stamp,usec,level,arrived,seqcode " "from events e,users u " "where e.jobid='%|Ss' " "and u.userid=e.userid " "order by event", dbjob); else trio_asprintf(&stmt,"select event from events " "where jobid='%|Ss' " "order by event", dbjob); glite_common_log_msg(LOG_CATEGORY_LB_SERVER_DB, LOG_PRIORITY_DEBUG, stmt); if (edg_wll_ExecSQL(ctx,stmt,&q) < 0) goto rollback; free(stmt); stmt = NULL; dumped = 1; while ((ret = edg_wll_FetchRow(ctx,q,sizofa(res),NULL,res)) > 0) { int event, ret_dump = 0, i; event = atoi(res[0]); if (dump >= 0) { assert(ret == 10); ret_dump = dump_events( ctx, job, dump, (char **) &res); } for (i=0; i<sizofa(res); i++) free(res[i]); if (dump >= 0 && ret_dump) goto rollback; if ( purge ) if (edg_wll_delete_event(ctx,dbjob,event)) goto rollback; } glite_lbu_FreeStmt(&q); if (ret < 0) goto rollback; commit: rollback:; } while (edg_wll_TransNeedRetry(ctx)); err: free(root); free(suffix); free(prefix); free(prefix_id); free(suffix_id); free(dbjob); free(stmt); glite_lbu_FreeStmt(&q); return edg_wll_Error(ctx,NULL,NULL); }
int main(int argc, char *argv[]) { char *server, *jobid_s, *user; int opt, err = 0; edg_wlc_JobId jobid = NULL; long i; int port = 0; server = jobid_s = NULL; while ( (opt = getopt_long(argc, argv, "hs:p:j:u:c:n:v:", opts, NULL)) != EOF) switch (opt) { case 'h': usage(argv[0]); return 0; case 's': server = strdup(optarg); break; case 'p': port = atoi(optarg); break; case 'j': jobid_s = strdup(optarg); break; case 'u': user = strdup(optarg); break; case '?': usage(argv[0]); return 1; } if ( !jobid_s ) { fprintf(stderr, "JobId not given\n"); return 1; } /*variables*/ edg_wll_Context ctx; edg_wll_Event *eventsOut; edg_wll_QueryRec jc[2]; edg_wll_QueryRec ec[2]; /*end variables*/ if ( (errno = edg_wlc_JobIdParse(jobid_s, &jobid)) ) { perror(jobid_s); return 1; } /*context*/ edg_wll_InitContext(&ctx); edg_wll_SetParam(ctx, EDG_WLL_PARAM_QUERY_SERVER, server); if (port) edg_wll_SetParam(ctx, EDG_WLL_PARAM_QUERY_SERVER_PORT, port); /*end context*/ /*queryrec*/ jc[0].attr = EDG_WLL_QUERY_ATTR_USERTAG; jc[0].op = EDG_WLL_QUERY_OP_EQUAL; jc[0].attr_id.tag = "color"; jc[0].value.c = "red"; jc[1].attr = EDG_WLL_QUERY_ATTR_UNDEF; ec[0].attr = EDG_WLL_QUERY_ATTR_USERTAG; ec[0].op = EDG_WLL_QUERY_OP_EQUAL; ec[0].attr_id.tag = "color"; ec[0].value.c = "green"; ec[1].attr = EDG_WLL_QUERY_ATTR_UNDEF; /*end queryrec*/ /*query*/ err = edg_wll_QueryEvents(ctx, jc, ec, &eventsOut); /*end query*/ if ( err == E2BIG ) { fprintf(stderr,"Warning: only limited result returned!\n"); return 0; } else if (err) { char *et,*ed; edg_wll_Error(ctx,&et,&ed); fprintf(stderr,"%s: edg_wll_QueryEvents(): %s (%s)\n",argv[0],et,ed); free(et); free(ed); } if ( err == ENOENT ) return err; /*printevents*/ for (i = 0; eventsOut && (eventsOut[i].type); i++ ) { //printf("jobId : %s\n", edg_wlc_JobIdUnparse(eventsOut[i].jobId)); printf("event : %s\n\n", edg_wll_EventToString(eventsOut[i].type)); } /*end printevents*/ if ( eventsOut ) { for (i=0; &(eventsOut[i]); i++) edg_wll_FreeEvent(&(eventsOut[i])); free(eventsOut); } edg_wll_FreeContext(ctx); return err; }
int main(int argc, char *argv[]) { char *destname= NULL,*hostname=NULL,*testname = NULL,*filename = NULL; char *event; int num_jobs = 1; int opt; int skip = -1; edg_wll_Context ctx; enum { DEST_UNDEF = 0, DEST_LL, DEST_IL, DEST_PROXY, DEST_BKSERVER, DEST_DUMP, } dest = 0; struct timeval log_timeout = { tv_sec: 2, tv_usec: 0 }; if (edg_wll_InitContext(&ctx) != 0) { fprintf(stderr, "Couldn't create L&B context.\n"); return 1; } opterr = 0; while ((opt = getopt_long(argc,argv,"hd:t:f:m:n:Ns:P::p:", long_options, (int *) 0)) != EOF) { switch (opt) { case 'd': destname = (char *) strdup(optarg); break; case 't': testname = (char *) strdup(optarg); break; case 'f': filename = (char *) strdup(optarg); break; case 'm': hostname = (char *) strdup(optarg); break; case 'p': logfile_prefix = (char*) strdup(optarg); break; case 's': il_socket = (char*) strdup(optarg); break; case 'n': num_jobs = atoi(optarg); break; case 'P': skip = optarg ? atoi(optarg) : 0; break; case 'h': default: usage(argv[0]); exit(0); } } if(destname) { if(!strncasecmp(destname, "pr", 2)) dest=DEST_PROXY; else if(!strncasecmp(destname, "lo", 2) || !strncasecmp(destname, "ll", 2)) dest=DEST_LL; else if(!strncasecmp(destname, "in", 2) || !strncasecmp(destname, "il", 2)) dest=DEST_IL; else if(!strncasecmp(destname, "bk", 2) || !strncasecmp(destname, "se", 2)) dest=DEST_BKSERVER; else if(!strncasecmp(destname, "du", 2)) dest=DEST_DUMP; else { fprintf(stderr,"%s: wrong destination\n",argv[0]); usage(argv[0]); exit(1); } } if((dest == DEST_IL) && (il_socket == NULL)) il_socket = DEFAULT_SOCKET; if((dest == DEST_PROXY) && il_socket) { char store_sock[256], serve_sock[256]; sprintf(store_sock, "%s%s", il_socket, "store.sock"); sprintf(serve_sock, "%s%s", il_socket, "serve.sock"); edg_wll_SetParam(ctx, EDG_WLL_PARAM_LBPROXY_STORE_SOCK, store_sock); edg_wll_SetParam(ctx, EDG_WLL_PARAM_LBPROXY_SERVE_SOCK, serve_sock); } if (num_jobs <= 0) { fprintf(stderr,"%s: wrong number of jobs\n",argv[0]); usage(argv[0]); exit(1); } if (!filename && destname) { fprintf(stderr,"%s: -f required\n",argv[0]); usage(argv[0]); exit(1); } if (glite_wll_perftest_init(hostname, NULL, testname, filename, num_jobs) < 0) { fprintf(stderr,"%s: glite_wll_perftest_init failed\n",argv[0]); exit(1); } if(dest) { char *jobid; int len; while ((len=glite_wll_perftest_produceEventString(&event, &jobid)) > 0) { switch(dest) { case DEST_PROXY: ctx->p_tmp_timeout = ctx->p_sync_timeout; if (edg_wll_DoLogEventServer(ctx,EDG_WLL_LOGFLAG_PROXY,event)) { char *et,*ed; edg_wll_Error(ctx,&et,&ed); fprintf(stderr,"edg_wll_DoLogEventServer(): %s (%s)\n",et,ed); fprintf(stderr,"Event:\n%s\n", event); exit(1); } break; case DEST_LL: #if defined(EVENTS_USER_PRESENT) /* erase DG.USER, will be added by LL */ do { char *p = strstr(event, "DG.USER"); if(p != NULL) { char *s = strchr(p+9, '"'); if(s == NULL) { s = strstr(p+7, "DG."); if(s == NULL) { s = event + len - 1; } } else { while(*++s == ' ') ; } memmove(p, s, event + len + 1 - s); } } while(0); #endif ctx->p_tmp_timeout = ctx->p_log_timeout; if (edg_wll_DoLogEvent(ctx,event)) { char *et,*ed; edg_wll_Error(ctx,&et,&ed); fprintf(stderr,"edg_wll_DoLogEvent(): %s (%s)\n",et,ed); fprintf(stderr,"Event:\n%s\n", event); exit(1); } break; case DEST_BKSERVER: ctx->p_tmp_timeout = ctx->p_log_timeout; edg_wlc_JobIdParse(jobid, &ctx->p_jobid); if (edg_wll_DoLogEventServer(ctx,EDG_WLL_LOGFLAG_DIRECT,event)) { char *et,*ed; edg_wll_Error(ctx,&et,&ed); fprintf(stderr,"edg_wll_DoLogEventServer(): %s (%s)\n",et,ed); fprintf(stderr,"Event:\n%s\n", event); exit(1); } break; case DEST_IL: ctx->p_tmp_timeout = log_timeout; /* ctx->p_log_timeout */; if (edg_wll_DoLogEventIl(ctx, event, jobid, len, skip)) { char *et,*ed; edg_wll_Error(ctx,&et,&ed); fprintf(stderr,"edg_wll_DoLogEventIl(): %s (%s)\n",et,ed); fprintf(stderr,"Event:\n%s\n", event); exit(1); } break; case DEST_DUMP: printf("%s", event); break; default: break; } free(event); } } else { /* no destination - only print jobid's that would be used */ char *jobid; while(jobid = glite_wll_perftest_produceJobId()) { fprintf(stdout, "%s\n", jobid); } } edg_wll_FreeContext(ctx); return 0; }