implementation of proxy purge
authorMiloš Mulač <mulac@civ.zcu.cz>
Tue, 18 Mar 2008 16:23:39 +0000 (16:23 +0000)
committerMiloš Mulač <mulac@civ.zcu.cz>
Tue, 18 Mar 2008 16:23:39 +0000 (16:23 +0000)
org.glite.lb.client/interface/consumer.h
org.glite.lb.server/src/srv_purge.c
org.glite.lb.utils/src/dump.c
org.glite.lb.utils/src/load.c
org.glite.lb.utils/src/purge.c

index 3af3669..fe78142 100644 (file)
@@ -319,8 +319,7 @@ extern int edg_wll_http_send_recv(
 
 extern int http_check_status(
        edg_wll_Context,
-       char *,
-       char **
+       char *
 );
 
 extern int set_server_name_and_port(
index d50f77d..bf51f9e 100644 (file)
@@ -249,7 +249,7 @@ int edg_wll_PurgeServer(edg_wll_Context ctx,const edg_wll_PurgeRequest *request,
                                parse = 1;
                        }
                        else {
-                               switch (purge_one(ctx,job,dumpfile,request->flags&EDG_WLL_PURGE_REALLY_PURGE,0)) {
+                               switch (purge_one(ctx,job,dumpfile,request->flags&EDG_WLL_PURGE_REALLY_PURGE,ctx->isProxy)) {
                                        case 0: if (request->flags & EDG_WLL_PURGE_LIST_JOBS) {
                                                        result->jobs = realloc(result->jobs,(naffected_jobs+2) * sizeof(*(result->jobs)));
                                                        result->jobs[naffected_jobs] = strdup(request->jobs[i]);
@@ -277,7 +277,9 @@ int edg_wll_PurgeServer(edg_wll_Context ctx,const edg_wll_PurgeRequest *request,
                for (i=0; i<EDG_WLL_NUMBER_OF_STATCODES; i++)
                        timeout[i] = request->timeout[i] < 0 ? ctx->purge_timeout[i] : request->timeout[i];
 
-               if (edg_wll_ExecSQL(ctx,"select dg_jobid from jobs where server='1'",&s) < 0) goto abort;
+               if (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 ((res = edg_wll_FetchRow(ctx,s,1,NULL,&job_s)) > 0) {
                        if (edg_wlc_JobIdParse(job_s,&job)) {
                                fprintf(stderr,"%s: parse error (internal inconsistency !)\n",job_s);
@@ -316,7 +318,7 @@ int edg_wll_PurgeServer(edg_wll_Context ctx,const edg_wll_PurgeRequest *request,
 
                                if (now-stat.lastUpdateTime.tv_sec > timeout[i] && !check_strict_jobid(ctx,job))
                                {
-                                       if (purge_one(ctx,job,dumpfile,request->flags&EDG_WLL_PURGE_REALLY_PURGE,0)) {
+                                       if (purge_one(ctx,job,dumpfile,request->flags&EDG_WLL_PURGE_REALLY_PURGE,ctx->isProxy)) {
                                                edg_wll_FreeStatus(&stat);
                                                if (edg_wll_Error(ctx, NULL, NULL) == ENOENT) {
                                                        /* job purged meanwhile, ignore */
index 4e22639..1cbba21 100644 (file)
@@ -211,7 +211,7 @@ static int edg_wll_DumpEvents(
        if ( error != 0 )
                goto edg_wll_dumpevents_end;
 
-       if (http_check_status(ctx, response, &recv_mess))
+       if (http_check_status(ctx, response))
                goto edg_wll_dumpevents_end;
 
        edg_wll_ParseDumpResult(ctx, recv_mess, result);
index 3657a47..a80dcd0 100644 (file)
@@ -191,7 +191,7 @@ static int edg_wll_LoadEvents(
        if ( error != 0 )
                goto edg_wll_loadevents_end;
 
-       if (http_check_status(ctx, response, &recv_mess))
+       if (http_check_status(ctx, response))
                goto edg_wll_loadevents_end;
 
        edg_wll_ParseLoadResult(ctx, recv_mess, result);
index 605f4ec..2afee97 100644 (file)
@@ -15,6 +15,7 @@
 #include "glite/lb/mini_http.h"
 #include "glite/lb/query_rec.h"
 #include "glite/lb/consumer.h"
+#include "glite/lb/connection.h"
 
 #define dprintf(x) { if (debug) printf x; }
 
@@ -54,6 +55,8 @@ static struct option opts[] = {
        { "version",            no_argument, NULL, 'v' },
        { "debug",              no_argument, NULL, 'd' },
        { "server",             required_argument, NULL, 'm' },
+       { "proxy",              no_argument, NULL, 'x' },
+       { "sock",               required_argument, NULL, 'X' },
        { NULL,                 no_argument, NULL,  0 }
 };
 
@@ -72,7 +75,9 @@ static void usage(char *me)
                "       -h, --help                  display this help\n"
                "       -v, --version               display version\n"
                "       -d, --debug                 diagnostic output\n"
-               "       -m, --server                L&B server machine name\n",
+               "       -m, --server                L&B server machine name\n"
+               "       -x, --proxy                 purge L&B proxy\n"
+               "       -X, --sock <path>           purge L&B proxy using default socket path\n",
                me);
 }
 
@@ -101,8 +106,11 @@ int main(int argc,char *argv[])
        me = strrchr(argv[0],'/');
        if (me) me++; else me=argv[0];
 
+       /* initialize context */
+       edg_wll_InitContext(&ctx);
+
        /* get arguments */
-       while ((opt = getopt_long(argc,argv,"a:c:n:o:j:m:rlsidhv",opts,NULL)) != EOF) {
+       while ((opt = getopt_long(argc,argv,"a:c:n:o:j:m:rlsidhvxX:",opts,NULL)) != EOF) {
                timeout=-1;
 
                switch (opt) {
@@ -156,14 +164,16 @@ int main(int argc,char *argv[])
                case 'i': request->flags |= EDG_WLL_PURGE_CLIENT_DUMP; break;
                case 'd': debug = 1; break;
                case 'v': fprintf(stdout,"%s:\t%s\n",me,rcsid); exit(0);
+               case 'x': ctx->isProxy = 1; break;
+               case 'X': 
+                       ctx->isProxy = 1; 
+                       edg_wll_SetParam(ctx, EDG_WLL_PARAM_LBPROXY_SERVE_SOCK, optarg); 
+                       break;
                case 'h':
                case '?': usage(me); return 1;
                }
        }
 
-       /* initialize context */
-       edg_wll_InitContext(&ctx);
-
        /* read the jobIds from file, if wanted */
        if (file) {
                char **jobs=NULL;
@@ -363,15 +373,24 @@ static int edg_wll_Purge(
        ctx->p_tmp_timeout = ctx->p_query_timeout;
        if (ctx->p_tmp_timeout.tv_sec < 600) ctx->p_tmp_timeout.tv_sec = 600;
 
-       if (set_server_name_and_port(ctx, NULL)) 
-               goto edg_wll_purge_end;
-
-       if (edg_wll_http_send_recv(ctx,
-               "POST /purgeRequest HTTP/1.1", request_headers, send_mess,
-               &response, NULL, &recv_mess)) 
-               goto edg_wll_purge_end;
+       
+       if (ctx->isProxy){
+               ctx->isProxy = 0;
+               if (edg_wll_http_send_recv_proxy(ctx, "POST /purgeRequest HTTP/1.1",
+                               request_headers,send_mess,&response,NULL,&recv_mess))
+                       goto edg_wll_purge_end;
+       }
+       else {
+               if (set_server_name_and_port(ctx, NULL)) 
+                       goto edg_wll_purge_end;
+
+               if (edg_wll_http_send_recv(ctx,
+                       "POST /purgeRequest HTTP/1.1", request_headers, send_mess,
+                       &response, NULL, &recv_mess)) 
+                       goto edg_wll_purge_end;
+       }
 
-       if (http_check_status(ctx, response, &recv_mess))
+       if (http_check_status(ctx, response))
                goto edg_wll_purge_end;
 
        if (edg_wll_ParsePurgeResult(ctx, recv_mess, result))