Exemplo n.º 1
0
static void free_events(edg_wll_Event *events)
{
	int	i;

	if (events) {
		for (i=0; events[i].type != EDG_WLL_EVENT_UNDEF; i++) edg_wll_FreeEvent(&(events[i]));
		edg_wll_FreeEvent(&(events[i])); /* free last line */
		free(events);	
		events = NULL;
	}
}
Exemplo n.º 2
0
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;
}
Exemplo n.º 3
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;
}
Exemplo n.º 4
0
/*
 *----------------------------------------------------------------------
 *
 * 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;
}
Exemplo n.º 5
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;
}
Exemplo n.º 6
0
int
event_queue_send(struct event_queue *eq)
{
	OutputPlugin *output = (OutputPlugin*)eq->plugin_data;
	edg_wll_Context context;
	edg_wll_Event *notif_event;
    edg_wll_JobStat *state_out;
    il_octet_string_t event;
    char *jobstat_char;
	int ret;

	assert(output != NULL);

	edg_wll_InitContext(&context);

	while(!event_queue_empty(eq)) {
	    struct server_msg *msg;
	    cms::TextMessage *cms_msg;
	    char *s;
	    unsigned int i;
	    std::string val;

	    if(event_queue_get(eq, &msg) < 0) {
	    	goto err;
	    }

	    try {
	    	if(decode_il_msg(&event, msg->msg) < 0) {
	    		set_error(IL_LBAPI, EINVAL, "event_queue_send: error parsing notification event data");
	    		goto err;
	    	}
	    	ret=edg_wll_ParseNotifEvent(context, event.data, &notif_event);
	    	if(ret) {
	    		set_error(IL_LBAPI, ret, "event_queue_send: error parsing notification event");
	    		goto err;
	    	}
	        jobstat_char = glite_lbu_UnescapeXML((const char *) notif_event->notification.jobstat);
	        if (jobstat_char == NULL) {
	            set_error(IL_LBAPI, EINVAL, "event_queue_send: error unescaping job status");
	            goto err;
	        }
	        if ( edg_wll_ParseJobStat(context, jobstat_char, strlen(jobstat_char), state_out)) {
	        	set_error(IL_LBAPI, EINVAL, "event_queue_send: error parsing job status");
	        	goto err;
	        }


	    	cms_msg = output->session->createTextMessage();
	    	/* ownerDn */
	    	val.assign(state_out->owner);
	    	cms_msg->setStringProperty("ownerDn", val);
	    	/* voname */
	    	s = edg_wll_JDLField(state_out,"VirtualOrganisation");
	    	val.assign(s);
	    	free(s);
	    	cms_msg->setStringProperty("voname", val);
	    	/* bkHost */
	    	glite_jobid_getServerParts(state_out->jobId, &s, &i);
	    	val.assign(s);
	    	free(s);
	    	cms_msg->setStringProperty("bkHost", val);
	    	/* networkServer */
	    	/* TODO: XXX cut out hostname */
	    	val.assign(state_out->network_server);
	    	cms_msg->setStringProperty("networkHost", val);
	    	timeval2str(&state_out->lastUpdateTime, &s);
	    	val.assign(s);
	    	if(s) free(s);
	    	cms_msg->setStringProperty("lastUpdateTime", val);
	    	/* stateName */
	    	s = edg_wll_StatToString(state_out->state);
	    	val.assign(s);
	    	if(s) free(s);
	    	cms_msg->setStringProperty("stateName", val);
	    	timeval2str(&state_out->stateEnterTime, &s);
	    	val.assign(s);
	    	if(s) free(s);
	    	cms_msg->setStringProperty("stateStartTime", val);
	    	/* condorId */
	    	val.assign(state_out->condorId);
	    	cms_msg->setStringProperty("condorId", val);
	    	/* destSite */
	    	val.assign(state_out->destination);
	    	cms_msg->setStringProperty("destSite", val);
	    	/* exitCode */
	    	cms_msg->setIntProperty("exitCode", state_out->exit_code);
	    	/* doneCode */
	    	cms_msg->setIntProperty("doneCode", state_out->done_code);
	    	/* statusReason */
	    	val.assign(state_out->reason);
	    	cms_msg->setStringProperty("statusReason", val);

	    	free(event.data);
	    	edg_wll_FreeEvent(notif_event);
	    	free(notif_event);
	    	edg_wll_FreeStatus(state_out);
	    	free(state_out);
	    	free(jobstat_char);
	    } catch(cms::CMSException &e) {
	    	goto err;
	    }

	    try {
	    	output->send(cms_msg);
		    delete cms_msg;
	    	if(event_store_commit(msg->es, msg->ev_len, queue_list_is_log(eq), msg->generation) < 0) {
	    		/* failure committing message, this is bad */
	    		goto err;
	    	}
	        event_queue_remove(eq);
	        eq->first_event_sent = 1;
	    } catch(cms::CMSException &e) {
		    delete cms_msg;
	    	output->cleanup();
	    	eq->timeout = TIMEOUT;
	    	edg_wll_FreeContext(context);
	    	return 0;
	    }
	}
	edg_wll_FreeContext(context);
	return 1;

err:
	if(event.data) {
		free(event.data);
	}
	if(notif_event) {
    	edg_wll_FreeEvent(notif_event);
    	free(notif_event);
	}
	if(jobstat_char) {
		free(jobstat_char);
	}
	if(state_out) {
		edg_wll_FreeStatus(state_out);
		free(state_out);
	}
	return -1;
}
Exemplo n.º 7
0
int
event_queue_send(struct event_queue *eq, struct queue_thread *me)
{
	OutputPlugin *output = (OutputPlugin*)eq->plugin_data;
	edg_wll_Context context;
	edg_wll_Event *notif_event;
	edg_wll_JobStat state_out;
	il_octet_string_t event;
	char *jobstat_char;
	int ret;

	assert(output != NULL);

	edg_wll_InitContext(&context);

	while(!event_queue_empty(eq)) {
	    struct server_msg *msg;
	    cms::Message *cms_msg = NULL;

	    if(event_queue_get(eq, me, &msg) == 0) {
		    break;
	    }

	    if(0 == msg->len) {
		    glite_common_log(IL_LOG_CATEGORY, LOG_PRIORITY_DEBUG,
				     "    not sending empty message at offset %ld for job %s",
				     msg->offset, msg->job_id_s);
		    if(event_store_commit(msg->es, msg->ev_len, 0, msg->generation) < 0) {
			    /* failure committing message, this is bad */
			    goto err;
		    }
		    event_queue_remove(eq, me);
		    continue;
	    }

	    glite_common_log(IL_LOG_CATEGORY, LOG_PRIORITY_DEBUG, 
			     "    trying to deliver event at offset %ld for job %s",
			     msg->offset, msg->job_id_s);
	    
	    if(decode_il_msg(&event, msg->msg + 17) < 0) {
		    set_error(IL_LBAPI, EINVAL, "event_queue_send: error parsing notification event data");
		    goto err;
	    }
	    ret=edg_wll_ParseNotifEvent(context, event.data, &notif_event);
	    if(ret) {
		    set_error(IL_LBAPI, ret, "event_queue_send: error parsing notification event");
		    goto err;
	    }
	    jobstat_char = glite_lbu_UnescapeXML((const char *) notif_event->notification.jobstat);
	    if (jobstat_char == NULL) {
		    set_error(IL_LBAPI, EINVAL, "event_queue_send: error unescaping job status");
		    goto err;
	    }
	    if ( edg_wll_ParseJobStat(context, jobstat_char, strlen(jobstat_char), &state_out)) {
		    set_error(IL_LBAPI, EINVAL, "event_queue_send: error parsing job status");
		    fprintf(stderr, "Status string: %s\n", jobstat_char);
		    goto err;
	    }
	    
	    try {
		    cms_msg = output->createMessage(state_out);
		    
		    free(event.data); event.data = NULL;
		    edg_wll_FreeEvent(notif_event);
		    free(notif_event); notif_event = NULL;
		    edg_wll_FreeStatus(&state_out);
		    free(jobstat_char); jobstat_char = NULL;
		    
		    output->send(cms_msg); 
		    delete cms_msg;
		    if(event_store_commit(msg->es, msg->ev_len, 0, msg->generation) < 0) {
			    /* failure committing message, this is bad */
			    goto err;
		    }
		    glite_common_log(IL_LOG_CATEGORY, LOG_PRIORITY_DEBUG, 
				     "    event sent to %s", eq->dest_name);
		    
	    } catch(cms::CMSException &e) {
		    if(cms_msg) {
			    delete cms_msg;
		    }
		    me->timeout = TIMEOUT;
		    edg_wll_FreeContext(context);
		    set_error(IL_DL, 0, e.what());
		    return 0;
	    }
	    event_queue_remove(eq, me);
	    me->first_event_sent = 1;
	    eq->last_sent = time(NULL);
	}
	edg_wll_FreeContext(context);
	return 1;

err:
	if(event.data) {
		free(event.data);
	}
	if(notif_event) {
		edg_wll_FreeEvent(notif_event);
		free(notif_event);
	}
	if(jobstat_char) {
		free(jobstat_char);
	}
	edg_wll_FreeStatus(&state_out);

	return -1;
}
Exemplo n.º 8
0
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);
}
Exemplo n.º 9
0
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;
}