+++ /dev/null
-#include <getopt.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <errno.h>
-
-#include <globus_common.h>
-
-#include "glite/wmsutils/jobid/cjobid.h"
-#include "glite/lb/notifid.h"
-#include "glite/lb/producer.h"
-#include "glite/lb/events.h"
-
-
-static struct option opts[] = {
- {"help", 0, NULL, 'h'},
- {"sock", 1, NULL, 's'},
- {"jobid", 1, NULL, 'j'},
- {"seq", 1, NULL, 'c'},
- {"name", 1, NULL, 'n'},
- {"value", 1, NULL, 'v'}
-};
-
-static void usage(char *me)
-{
- fprintf(stderr, "usage: %s [option]\n"
- "\t-h, --help Shows this screen.\n"
- "\t-s, --server LB Proxy socket.\n"
- "\t-j, --jobid ID of requested job.\n"
- "\t-c, --seq Sequence code.\n"
- "\t-n, --name Name of the tag.\n"
- "\t-v, --value Value of the tag.\n"
- , me);
-}
-
-
-int main(int argc, char *argv[])
-{
- edg_wll_Context ctx;
- edg_wlc_JobId jobid = NULL;
- char *server, *code, *jobid_s, *name, *value;
- int opt, err = 0;
-
-
- server = code = jobid_s = name = value = NULL;
- while ( (opt = getopt_long(argc, argv, "hs:j:c:n:v:", opts, NULL)) != EOF)
- switch (opt) {
- case 'h': usage(name); return 0;
- case 's': server = strdup(optarg); break;
- case 'j': jobid_s = strdup(optarg); break;
- case 'c': code = strdup(optarg); break;
- case 'n': name = strdup(optarg); break;
- case 'v': value = strdup(optarg); break;
- case '?': usage(name); return 1;
- }
-
- if ( !jobid_s ) { fprintf(stderr, "JobId not given\n"); return 1; }
- if ( !code ) { fprintf(stderr, "Sequence code not given\n"); return 1; }
- if ( !server ) { fprintf(stderr, "LB proxy socket not given\n"); return 1; }
- if ( !name ) { fprintf(stderr, "Tag name not given\n"); return 1; }
- if ( !value ) { fprintf(stderr, "Tag value not given\n"); return 1; }
-
- if ( (errno = edg_wlc_JobIdParse(jobid_s, &jobid)) ) { perror(jobid_s); return 1; }
-
- if (globus_module_activate(GLOBUS_COMMON_MODULE) != GLOBUS_SUCCESS) {
- fprintf(stderr, "Cannot initialize Globus common module\n");
- exit(1);
- }
-
- edg_wll_InitContext(&ctx);
-
- edg_wll_SetParam(ctx, EDG_WLL_PARAM_SOURCE, EDG_WLL_SOURCE_USER_INTERFACE);
- edg_wll_SetParam(ctx, EDG_WLL_PARAM_LBPROXY_STORE_SOCK, server);
-
- if (edg_wll_SetLoggingJob(ctx, jobid, code, EDG_WLL_SEQ_NORMAL)) {
- char *et,*ed;
- edg_wll_Error(ctx,&et,&ed);
- fprintf(stderr,"SetLoggingJob(%s,%s): %s (%s)\n",jobid_s,code,et,ed);
- exit(1);
- }
-
- err = edg_wll_LogEventProxy(ctx,
- EDG_WLL_EVENT_USERTAG, EDG_WLL_FORMAT_USERTAG,
- name, value);
-
- if (err) {
- char *et,*ed;
-
- edg_wll_Error(ctx,&et,&ed);
- fprintf(stderr,"%s: edg_wll_LogEvent*(): %s (%s)\n",
- argv[0],et,ed);
- free(et); free(ed);
- }
-
- code = edg_wll_GetSequenceCode(ctx);
- puts(code);
- free(code);
-
- edg_wll_FreeContext(ctx);
-
- return err;
-}
edg_wll_Args parray[] = {
{ EDG_WLL_ARGS_EVENT, "e", "event", "select event type (see -e help)", &event },
{ EDG_WLL_ARGS_BOOL, "p", "priority", "send as priority event", &pri },
- { EDG_WLL_ARGS_STRING, "x", "lbproxy", "send directly to L&B Proxy (not locallogger) with given credentials", &lbproxy },
{ EDG_WLL_ARGS_STRING, "m", "machine", 0, &server },
{ EDG_WLL_ARGS_SOURCE, "s", "source", "event source (see -s help)", &src },
{ EDG_WLL_ARGS_STRING, "i", "source-instance", "event source instance", &src_instance },
/* log the event - priority/normal/proxy */
logev = (pri) ? edg_wll_LogEventSync : edg_wll_LogEvent;
- logev = (lbproxy) ? edg_wll_LogEventProxy : logev;
/* if no job given - generate some */
if (jobid_s == 0) {
edg_wll_SetParam(ctx, EDG_WLL_PARAM_LEVEL,
(deb) ? EDG_WLL_LEVEL_DEBUG : EDG_WLL_LEVEL_SYSTEM);
- if (lbproxy) {
- edg_wll_SetParam(ctx, EDG_WLL_PARAM_LBPROXY_STORE_SOCK, "/tmp/lb_proxy_store.sock");
- edg_wll_SetParam(ctx, EDG_WLL_PARAM_LBPROXY_SERVE_SOCK, "/tmp/lb_proxy_serve.sock");
- if (edg_wll_SetLoggingJobProxy(ctx,jobid,code,lbproxy,EDG_WLL_SEQ_NORMAL)) {
- char *et,*ed;
- edg_wll_Error(ctx,&et,&ed);
- fprintf(stderr,"SetLoggingJobProxy(%s,%s,%s): %s (%s)\n",jobid_s,code,lbproxy,et,ed);
- exit(1);
- }
- } else {
- if (edg_wll_SetLoggingJob(ctx,jobid,code,EDG_WLL_SEQ_NORMAL)) {
- char *et,*ed;
- edg_wll_Error(ctx,&et,&ed);
- fprintf(stderr,"SetLoggingJob(%s,%s): %s (%s)\n",jobid_s,code,et,ed);
- exit(1);
- }
+ if (edg_wll_SetLoggingJob(ctx,jobid,code,EDG_WLL_SEQ_NORMAL)) {
+ char *et,*ed;
+ edg_wll_Error(ctx,&et,&ed);
+ fprintf(stderr,"SetLoggingJob(%s,%s): %s (%s)\n",jobid_s,code,et,ed);
+ exit(1);
}
#ifdef ENABLE_REASON_LENGTH
#ifdef FAKE_VERSION
int edg_wll_DoLogEvent(edg_wll_Context context, edg_wll_LogLine logline);
-int edg_wll_DoLogEventProxy(edg_wll_Context context, edg_wll_LogLine logline);
#else
/**
*----------------------------------------------------------------------
return edg_wll_Error(context, NULL, NULL);
}
-/**
- *----------------------------------------------------------------------
- * Connects to L&B Proxy and sends already formatted ULM string
- * \brief helper logging function
- * \param context INOUT context to work with,
- * \param logline IN formated ULM string
- *----------------------------------------------------------------------
- */
-static int edg_wll_DoLogEventProxy(
- edg_wll_Context context,
- edg_wll_LogLine logline)
-{
- int answer;
- struct sockaddr_un saddr;
- int flags;
- edg_wll_PlainConnection conn;
-
- edg_wll_ResetError(context);
- answer = 0;
-
- /* open a connection to the L&B Proxy: */
-
-#ifdef EDG_WLL_LOG_STUB
- fprintf(stderr,"Logging to L&B Proxy at socket %s\n",
- context->p_lbproxy_store_sock? context->p_lbproxy_store_sock: socket_path);
-#endif
- memset(&conn, 0, sizeof(conn));
- conn.sock = socket(PF_UNIX, SOCK_STREAM, 0);
- if (conn.sock < 0) {
- edg_wll_SetError(context,answer = errno,"socket() error");
- goto edg_wll_DoLogEventProxy_end;
- }
- memset(&saddr, 0, sizeof(saddr));
- saddr.sun_family = AF_UNIX;
- strcpy(saddr.sun_path, context->p_lbproxy_store_sock?
- context->p_lbproxy_store_sock: socket_path);
- if ((flags = fcntl(conn.sock, F_GETFL, 0)) < 0 || fcntl(conn.sock, F_SETFL, flags | O_NONBLOCK) < 0) {
- edg_wll_SetError(context,answer = errno,"fcntl()");
- close(conn.sock);
- goto edg_wll_DoLogEventProxy_end;
- }
- if (connect(conn.sock, (struct sockaddr *)&saddr, sizeof(saddr)) < 0) {
- if(errno != EISCONN) {
- edg_wll_SetError(context,answer = errno,"connect()");
- close(conn.sock);
- goto edg_wll_DoLogEventProxy_end;
- }
- }
-
-
- /* and send the message to the L&B Proxy: */
-
- answer = edg_wll_log_proto_client_proxy(context,&conn,logline);
-
- edg_wll_plain_close(&conn);
-
-edg_wll_DoLogEventProxy_end:
-
- switch(answer) {
- case 0:
- case EINVAL:
- case ENOSPC:
- case ENOMEM:
- case EDG_WLL_ERROR_GSS:
- case EDG_WLL_ERROR_DNS:
- case ENOTCONN:
- case ECONNREFUSED:
- case ETIMEDOUT:
- case EAGAIN:
- break;
- case EDG_WLL_ERROR_PARSE_EVENT_UNDEF:
- case EDG_WLL_ERROR_PARSE_MSG_INCOMPLETE:
- case EDG_WLL_ERROR_PARSE_KEY_DUPLICITY:
- case EDG_WLL_ERROR_PARSE_KEY_MISUSE:
-// case EDG_WLL_ERROR_PARSE_OK_WITH_EXTRA_FIELDS:
- edg_wll_UpdateError(context,EINVAL,"edg_wll_DoLogEventProxy(): Error code mapped to EINVAL");
- break;
-
- default:
- edg_wll_UpdateError(context,EAGAIN,"edg_wll_DoLogEventProxy(): Error code mapped to EAGAIN");
- break;
- }
-
- return edg_wll_Error(context, NULL, NULL);
-}
#endif /* FAKE_VERSION */
/**
*----------------------------------------------------------------------
- * Formats a logging message and sends it to L&B Proxy
- * \brief master proxy logging event function
- * \param context INOUT context to work with,
- * \param event IN type of the event,
- * \param fmt IN printf()-like format string,
- * \param ... IN event specific values/data according to fmt.
- *----------------------------------------------------------------------
- */
-static int edg_wll_LogEventMasterProxy(
- edg_wll_Context context,
- edg_wll_EventCode event,
- char *fmt, ...)
-{
- va_list fmt_args;
- int ret,answer;
- char *fix,*var,*dguser;
- char *source,*eventName,*lvl, *fullid,*seq,*name_esc;
- struct timeval start_time;
- char date[ULM_DATE_STRING_LENGTH+1];
- edg_wll_LogLine out;
- size_t size;
- int i;
-
- i = errno = size = 0;
- seq = fix = var = dguser = out = source = eventName = lvl = fullid = NULL;
-
- edg_wll_ResetError(context);
-
- /* default return value is "Try Again" */
- answer = ret = EAGAIN;
-
- /* format the message: */
- va_start(fmt_args,fmt);
-
- gettimeofday(&start_time,0);
- if (edg_wll_ULMTimevalToDate(start_time.tv_sec,start_time.tv_usec,date) != 0) {
- edg_wll_SetError(context,ret = EINVAL,"edg_wll_LogEventMasterProxy(): edg_wll_ULMTimevalToDate() error");
- goto edg_wll_logeventmasterproxy_end;
- }
- source = edg_wll_SourceToString(context->p_source);
- lvl = edg_wll_LevelToString(context->p_level);
- eventName = edg_wll_EventToString(event);
- if (!eventName) {
- edg_wll_SetError(context,ret = EINVAL,"edg_wll_LogEventMasterProxy(): event name not specified");
- goto edg_wll_logeventmasterproxy_end;
- }
- if (!(fullid = edg_wlc_JobIdUnparse(context->p_jobid))) {
- edg_wll_SetError(context,ret = EINVAL,"edg_wll_LogEventMasterProxy(): edg_wlc_JobIdUnparse() error");
- goto edg_wll_logeventmasterproxy_end;
- }
- seq = edg_wll_GetSequenceCode(context);
- if (edg_wll_IncSequenceCode(context)) {
- ret = EINVAL;
- goto edg_wll_logeventmasterproxy_end;
- }
- if (trio_asprintf(&fix,EDG_WLL_FORMAT_COMMON,
- date,context->p_host,lvl,1,
- source,context->p_instance ? context->p_instance : "",
- eventName,fullid,seq) == -1) {
- edg_wll_SetError(context,ret = ENOMEM,"edg_wll_LogEventMasterProxy(): trio_asprintf() error");
- goto edg_wll_logeventmasterproxy_end;
- }
- if (trio_vasprintf(&var,fmt,fmt_args) == -1) {
- edg_wll_SetError(context,ret = ENOMEM,"edg_wll_LogEventMasterProxy(): trio_vasprintf() error");
- goto edg_wll_logeventmasterproxy_end;
- }
- /* format the DG.USER string */
-/* XXX: put user credentials here probably from context */
- name_esc = edg_wll_LogEscape(context->p_user_lbproxy);
- if (asprintf(&dguser,"DG.USER=\"%s\" ",name_esc) == -1) {
- edg_wll_SetError(context,ret = ENOMEM,"edg_wll_LogEventMasterProxy(): asprintf() error");
- goto edg_wll_logeventmasterproxy_end;
- }
- if (asprintf(&out,"%s%s%s\n",dguser,fix,var) == -1) {
- edg_wll_SetError(context,ret = ENOMEM,"edg_wll_LogEventMasterProxy(): asprintf() error");
- goto edg_wll_logeventmasterproxy_end;
- }
- size = strlen(out);
-
- if (size > EDG_WLL_LOG_SYNC_MAXMSGSIZE) {
- edg_wll_SetError(context,ret = ENOSPC,"edg_wll_LogEventMasterProxy(): Message size too large for synchronous transfer");
- goto edg_wll_logeventmasterproxy_end;
- }
-
-#ifdef EDG_WLL_LOG_STUB
-// fprintf(stderr,"edg_wll_LogEvent (%d chars): %s",size,out);
-#endif
-
- context->p_tmp_timeout = context->p_sync_timeout;
-
- /* and send the message to the L&B Proxy: */
- ret = edg_wll_DoLogEventProxy(context, out);
-
-edg_wll_logeventmasterproxy_end:
- va_end(fmt_args);
- if (seq) free(seq);
- if (fix) free(fix);
- if (var) free(var);
- if (dguser) free(dguser);
- if (out) free(out);
- if (source) free(source);
- if (lvl) free(lvl);
- if (eventName) free(eventName);
- if (fullid) free(fullid);
- if (name_esc) free(name_esc);
-
- if (ret) edg_wll_UpdateError(context,0,"Logging library ERROR: ");
-
- return edg_wll_Error(context,NULL,NULL);
-}
-
-/**
- *----------------------------------------------------------------------
* Formats a logging message and sends it asynchronously to local-logger
* \brief generic asynchronous logging function
*----------------------------------------------------------------------
}
/**
- *----------------------------------------------------------------------
- * Formats a logging message and sends it synchronously to L&B Proxy
- * \brief generic synchronous logging function
- *----------------------------------------------------------------------
- */
-int edg_wll_LogEventProxy(
- edg_wll_Context context,
- edg_wll_EventCode event,
- char *fmt, ...)
-{
- int ret=0;
- char *list=NULL;
- va_list fmt_args;
-
- edg_wll_ResetError(context);
-
- va_start(fmt_args,fmt);
- if (trio_vasprintf(&list,fmt,fmt_args) == -1) {
- edg_wll_SetError(context,ret = ENOMEM,"edg_wll_LogEventProxy(): trio_vasprintf() error");
- goto edg_wll_logevent_end;
- }
-
- ret=edg_wll_LogEventMasterProxy(context,event,"%s",list);
-
-edg_wll_logevent_end:
- va_end(fmt_args);
- if (list) free(list);
-
- if (ret) edg_wll_UpdateError(context,0,"edg_wll_LogEventProxy(): ");
-
- return edg_wll_Error(context,NULL,NULL);
-}
-
-
-/**
*-----------------------------------------------------------------------
* Instructs interlogger to to deliver all pending events related to current job
* \brief flush events from interlogger
/**
*-----------------------------------------------------------------------
- * Set a current job for given context.
- * \note Should be called before any logging call.
- *-----------------------------------------------------------------------
- */
-int edg_wll_SetLoggingJobProxy(
- edg_wll_Context context,
- const edg_wlc_JobId job,
- const char *code,
- const char *user,
- int flags)
-{
- int err;
- char *code_loc = NULL;
-
- edg_wll_ResetError(context);
-
- if (!job) return edg_wll_SetError(context,EINVAL,"jobid is null");
-
- edg_wlc_JobIdFree(context->p_jobid);
- if ((err = edg_wlc_JobIdDup(job,&context->p_jobid))) {
- edg_wll_SetError(context,err,"edg_wll_SetLoggingJob(): edg_wlc_JobIdDup() error");
- goto edg_wll_setloggingjobproxy_end;
- }
-
- /* add user credentials to context */
- edg_wll_SetParamString(context, EDG_WLL_PARAM_LBPROXY_USER, user);
-
- /* query LBProxyServer for sequence code if not user-suplied */
-/* FIXME: doesn't work yet
- if (!code) {
- edg_wll_QuerySequenceCodeProxy(context, job, &code_loc);
- goto edg_wll_setloggingjobproxy_end;
- } else {
- code_loc = strdup(code);
- }
-
- if (!edg_wll_SetSequenceCode(context,code_loc,flags)) */ {
- edg_wll_IncSequenceCode(context);
- }
-
-edg_wll_setloggingjobproxy_end:
- if (code_loc) free(code_loc);
- return edg_wll_Error(context,NULL,NULL);
-}
-
-/**
- *-----------------------------------------------------------------------
* Register job with L&B service.
*-----------------------------------------------------------------------
*/
return edg_wll_Error(context,NULL,NULL);
}
-/**
- *-----------------------------------------------------------------------
- * Register job with L&B Proxy service.
- *-----------------------------------------------------------------------
- */
-static int edg_wll_RegisterJobMasterProxy(
- edg_wll_Context context,
- const edg_wlc_JobId job,
- enum edg_wll_RegJobJobtype type,
- const char * user,
- const char * jdl,
- const char * ns,
- edg_wlc_JobId parent,
- int num_subjobs,
- const char * seed,
- edg_wlc_JobId ** subjobs)
-{
- char *type_s = NULL,*intseed = NULL, *seq = NULL;
- char *parent_s = NULL;
- int err = 0;
-
- edg_wll_ResetError(context);
-
- intseed = seed ? strdup(seed) :
- str2md5base64(seq = edg_wll_GetSequenceCode(context));
-
- free(seq);
-
- type_s = edg_wll_RegJobJobtypeToString(type);
- if (!type_s) return edg_wll_SetError(context,EINVAL,"edg_wll_RegisterJobMaster(): no jobtype specified");
-
- if ((type == EDG_WLL_REGJOB_DAG || type == EDG_WLL_REGJOB_PARTITIONED)
- && num_subjobs > 0)
- err = edg_wll_GenerateSubjobIds(context,job,
- num_subjobs,intseed,subjobs);
-
- parent_s = parent ? edg_wlc_JobIdUnparse(parent) : strdup("");
-
- if (err == 0 &&
- edg_wll_SetLoggingJobProxy(context,job,NULL,user,EDG_WLL_SEQ_NORMAL) == 0)
- edg_wll_LogEventMasterProxy(context,
- EDG_WLL_EVENT_REGJOB,EDG_WLL_FORMAT_REGJOB,
- (char *)jdl,ns,parent_s,type_s,num_subjobs,intseed);
-
- free(type_s); free(intseed); free(parent_s);
- return edg_wll_Error(context,NULL,NULL);
-}
-
int edg_wll_RegisterJobSync(
edg_wll_Context context,
const edg_wlc_JobId job,
return edg_wll_Error(ctx, NULL, NULL);
}
-int edg_wll_RegisterJobProxy(
- edg_wll_Context context,
- const edg_wlc_JobId job,
- enum edg_wll_RegJobJobtype type,
- const char * user,
- const char * jdl,
- const char * ns,
- int num_subjobs,
- const char * seed,
- edg_wlc_JobId ** subjobs)
-{
- return edg_wll_RegisterJobMasterProxy(context,job,type,user,jdl,ns, NULL, num_subjobs,seed,subjobs);
-}
-
int edg_wll_ChangeACL(
edg_wll_Context ctx,
const edg_wlc_JobId jobid,