Enabled notifications based on JDL ettributes (VirtualOrganisation).
authorZdeněk Šustr <sustr4@cesnet.cz>
Fri, 7 Mar 2008 16:01:44 +0000 (16:01 +0000)
committerZdeněk Šustr <sustr4@cesnet.cz>
Fri, 7 Mar 2008 16:01:44 +0000 (16:01 +0000)
org.glite.lb.client/src/notify.c
org.glite.lb.server/interface/index.h
org.glite.lb.server/src/index.c.T
org.glite.lb.server/src/notif_match.c

index 9445a47..64f5f58 100644 (file)
@@ -45,7 +45,7 @@ static void usage(char *cmd)
                        me);
        }
        if ( !cmd || !strcmp(cmd, "new") )
-               fprintf(stderr,"\n'new' command usage: %s new [ { -s socket_fd | -a fake_addr } ] {-j jobid | -o owner | -n network_server}\n"
+               fprintf(stderr,"\n'new' command usage: %s new [ { -s socket_fd | -a fake_addr } ] {-j jobid | -o owner | -n network_server | -v virtual_organization}\n"
                        "    jobid      job ID to connect notif. reg. with\n"
                        "    owner      match this owner DN\n"
                        "    network_server     match only this networ server (WMS entry point)\n\n"
@@ -108,7 +108,7 @@ int main(int argc,char **argv)
                char    *arg = NULL;
                int     attr = 0;
 
-               while ((c = getopt(argc-1,argv+1,"j:o:n:s:a:")) > 0) switch (c) {
+               while ((c = getopt(argc-1,argv+1,"j:o:v:n:s:a:")) > 0) switch (c) {
                        case 'j':
                                if (arg) { usage("new"); return EX_USAGE; }
                                attr = EDG_WLL_QUERY_ATTR_JOBID;
@@ -117,6 +117,10 @@ int main(int argc,char **argv)
                                if (arg) { usage("new"); return EX_USAGE; }
                                attr = EDG_WLL_QUERY_ATTR_OWNER;
                                arg = optarg; break;
+                       case 'v':
+                               if (arg) { usage("new"); return EX_USAGE; }
+                               attr = EDG_WLL_QUERY_ATTR_JDL_ATTR;
+                               arg = optarg; break;
                        case 'n':
                                if (arg) { usage("new"); return EX_USAGE; }
                                attr= EDG_WLL_QUERY_ATTR_NETWORK_SERVER; 
@@ -143,7 +147,10 @@ int main(int argc,char **argv)
                conditions[0][0].attr = attr;
                conditions[0][0].op = EDG_WLL_QUERY_OP_EQUAL;
                if (attr == EDG_WLL_QUERY_ATTR_JOBID) conditions[0][0].value.j = jid;
-               else conditions[0][0].value.c = arg;
+               else {
+                       conditions[0][0].value.c = arg;
+                       if (attr == EDG_WLL_QUERY_ATTR_JDL_ATTR) asprintf(&(conditions[0][0].attr_id.tag), "VirtualOrganisation");
+               }
 
                if ( !edg_wll_NotifNew(ctx,
                                        (edg_wll_QueryRec const* const*)conditions,
index 15f4f34..2a6b9ad 100644 (file)
@@ -17,6 +17,7 @@ int edg_wll_DumpIndexConfig(edg_wll_Context,const char *,edg_wll_QueryRec * cons
 int edg_wll_CmpColumn(const edg_wll_QueryRec *,const edg_wll_QueryRec *);
 
 char *edg_wll_StatToSQL(edg_wll_JobStat const *stat,edg_wll_QueryAttr attr);
+char *edg_wll_JDLStatToSQL(edg_wll_JobStat const *stat, edg_wll_QueryRec col_rec);
 
 
 typedef struct _edg_wll_IColumnRec {
@@ -36,5 +37,6 @@ extern int    lex_line;
 #define STD_PREFIX     "STD_"
 #define USR_PREFIX     "USR_"
 #define TIME_PREFIX    "TIME_"
+#define JDL_PREFIX     "JDL_"
 
 #endif /* GLITE_LB_INDEX_H */
index b92f57d..5b68b81 100644 (file)
@@ -3,6 +3,7 @@
 #include <string.h>
 #include <assert.h>
 #include <errno.h>
+#include <cclassad.h>
 
 #include "glite/lb/context-int.h"
 #include "glite/lbu/trio.h"
@@ -105,7 +106,7 @@ static int parse_indices(edg_wll_Context ctx,char **keys,char ***column_names,co
                                idx[nkeys] = realloc(idx[nkeys],(j+2)*sizeof idx[nkeys][0]);
                                memset(&idx[nkeys][j+1],0,sizeof idx[nkeys][0]);
                        }
-               
+
                        if (edg_wll_ColumnToQueryRec(column_names[i][j],&idx[nkeys][j])) {
                                int   code;
                                char *ed;
@@ -199,6 +200,23 @@ char *edg_wll_StatToSQL(edg_wll_JobStat const *stat,edg_wll_QueryAttr attr)
        return std_attrs[i].attr ? std_attrs[i].to_sql(stat,std_attrs[i].offset) : (char *) -1;
 }
 
+char *edg_wll_JDLStatToSQL(edg_wll_JobStat const *stat,edg_wll_QueryRec col_rec)
+{
+        struct cclassad *ad = NULL;
+        char *extr_val = NULL;
+
+        ad = cclassad_create(stat->jdl);
+        if (ad) {
+                if (!cclassad_evaluate_to_string(ad, col_rec.attr_id.tag, &extr_val)) { // Extract attribute value
+                        extr_val = NULL;
+                        cclassad_delete(ad);
+                }
+        }
+
+        //return extr_val ? extr_val : (char *) -1;
+        return extr_val;
+}
+
 int edg_wll_ColumnToQueryRec(const char *col_name,edg_wll_QueryRec *rec)
 {
        int     i;
@@ -219,6 +237,11 @@ int edg_wll_ColumnToQueryRec(const char *col_name,edg_wll_QueryRec *rec)
                rec->attr_id.tag = strdup(col_name+const_len(USR_PREFIX));
                rec->value.c = NULL;
        }
+       else if (strncasecmp(col_name,JDL_PREFIX,const_len(JDL_PREFIX)) == 0) {
+               rec->attr = EDG_WLL_QUERY_ATTR_JDL_ATTR;
+               rec->attr_id.tag = strdup(col_name+const_len(JDL_PREFIX));
+               rec->value.c = NULL;
+       }
 
        return !rec->attr;
 }
@@ -240,6 +263,10 @@ char * edg_wll_QueryRecToColumn(const edg_wll_QueryRec *rec)
                        free(s);
                }
        }
+       else if (rec->attr == EDG_WLL_QUERY_ATTR_JDL_ATTR) {
+               strcpy(col,JDL_PREFIX);
+               strcat(col,rec->attr_id.tag);
+       }
        else {
                int     i;
                for (i=0; std_attrs[i].name && std_attrs[i].attr != rec->attr; i++);
index ef9310d..7e0365d 100644 (file)
@@ -33,27 +33,42 @@ int edg_wll_NotifMatch(edg_wll_Context ctx, const edg_wll_JobStat *stat)
        time_t  now = time(NULL);
        
        char *cond_where = NULL;
+       char *cond_and_where = NULL;
 
        edg_wll_ResetError(ctx);
 
        if (ctx->notif_index) {
-               cond_where = strdup("");
                edg_wll_IColumnRec *notif_index_cols = ctx->notif_index_cols;
 
                for (i=0; notif_index_cols[i].qrec.attr; i++) {
                        char    *val = NULL;
 
-                       val = edg_wll_StatToSQL(stat,notif_index_cols[i].qrec.attr);
-                       assert(val != (char *) -1);
+                       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;
-                               trio_asprintf(&aux, "%s or %s = %s",cond_where,
+                               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 = NULL",cond_and_where,
+                                               notif_index_cols[i].colname);
+                               free(cond_and_where);
+                               cond_and_where = aux;
+                               free(val);
+                       }
                }
        }
 
@@ -67,8 +82,8 @@ int edg_wll_NotifMatch(edg_wll_Context ctx, const edg_wll_JobStat *stat)
                "select distinct n.notifid,n.destination,n.valid,u.cert_subj,n.conditions "
                "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)",
-               ju = edg_wlc_JobIdGetUnique(stat->jobId),NOTIF_ALL_JOBS,cond_where ? cond_where : "");
+               "   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);