1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953
|
/*
Copyright (C) 2003 by Sean David Fleming
sean@ivec.org
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
The GNU GPL can also be found at http://www.gnu.org
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#ifndef __WIN32
#include <sys/wait.h>
#endif
#include "gdis.h"
#include "file.h"
#include "grid.h"
#include "job.h"
#include "task.h"
#include "parse.h"
#include "model.h"
#include "grisu_client.h"
#include "interface.h"
extern struct sysenv_pak sysenv;
/* CURRENT - register apps for a GRID destination */
/* NULL -> not on grid */
/* TODO - consider storing structs containing more info */
/* ie site, app details etc - for faster job building */
GHashTable *grid_table=NULL;
/* CURRENT - assume credential already uploaded for the time being */
gint grid_authenticated=FALSE;
gchar *myproxy_init=NULL;
void grid_application_set(const gchar *name, const gchar *value)
{
#ifdef WITH_GRISU
if (grid_table)
g_hash_table_replace(grid_table, g_strdup(name), g_strdup(value));
#endif
}
gchar *grid_application_get(const gchar *name)
{
#ifdef WITH_GRISU
if (grid_table)
return(g_hash_table_lookup(grid_table, name));
else
return(NULL);
#else
return(NULL);
#endif
}
void grid_application_remove(const gchar *name)
{
#ifdef WITH_GRISU
if (grid_table)
g_hash_table_remove(grid_table, name);
#endif
}
GList *grid_application_all(void)
{
#ifdef WITH_GRISU
return(g_hash_table_get_keys(grid_table));
#else
return(NULL);
#endif
}
GSList *grid_search_by_name(const gchar *name)
{
#ifdef WITH_GRISU
return(grisu_submit_find(name));
#else
return(NULL);
#endif
}
/*********************************************/
/* allocate and initialize a grid job object */
/*********************************************/
gpointer grid_new(void)
{
struct grid_pak *grid;
grid = g_malloc(sizeof(struct grid_pak));
grid->user_vo = NULL;
grid->jobname = NULL;
grid->exename = NULL;
grid->exe_version = NULL;
grid->jobcode = JOB_UNKNOWN;
grid->remote_q = NULL;
grid->remote_root = NULL;
grid->remote_exe = NULL;
grid->remote_exe_module = NULL;
grid->remote_site = NULL;
grid->remote_exe_type=-1;
grid->remote_exe_np=1;
grid->local_cwd = NULL;
grid->local_input = NULL;
grid->local_output = NULL;
return(grid);
}
/**************************/
/* free a grid job object */
/**************************/
void grid_free(gpointer data)
{
struct grid_pak *grid=data;
g_assert(grid != NULL);
g_free(grid->user_vo);
g_free(grid->jobname);
g_free(grid->exename);
g_free(grid->exe_version);
g_free(grid->remote_q);
g_free(grid->remote_root);
g_free(grid->remote_exe);
g_free(grid->remote_exe_module);
g_free(grid->remote_site);
g_free(grid->local_cwd);
g_free(grid->local_input);
g_free(grid->local_output);
g_free(grid);
}
/***************************************/
/* get the DN from an x509 certificate */
/***************************************/
// openssl x509 -noout -in usercert.pem -subject
gchar *grid_get_DN(gchar *certificate_fullpath)
{
gint i, j, status;
gchar *cmd, *out, *err, *subject=NULL;
GError *error=NULL;
cmd = g_strdup_printf("openssl x509 -noout -in %s -subject", certificate_fullpath);
/* TODO - get the output */
if (g_spawn_command_line_sync(cmd, &out, &err, &status, &error))
{
for (i=0 ; i<8000 ; i++)
{
if (out[i] == '/')
{
/* not sure why but plain g_strdup adds a crappy char (null?) */
/* to the string, so scan for the end and use strndup instead */
for (j=i ; j<9000 ; j++)
{
if (out[j] == '\0')
break;
}
subject = g_strndup(&out[i], j-i-1);
break;
}
}
}
g_free(cmd);
return(subject);
}
gboolean grid_credential_get()
{
return(FALSE);
}
/*******************************************************/
/* set valid auth in case of external means (eg) grisu */
/*******************************************************/
/* TODO - could chuck into sysenv eventually */
void grid_auth_set(gint value)
{
grid_authenticated=value;
}
/*********************************************/
/* verify current authentication information */
/*********************************************/
gint grid_auth_check(void)
{
#ifdef WITH_GRISU
GSList *list;
/* perform a grisu operation that requires authentication */
/* NB: use anything fast (as long as auth info is in the header) */
//list = grisu_fqans_get();
list = grisu_site_list();
if (list)
{
g_slist_free(list);
grid_authenticated = TRUE;
return(TRUE);
}
#endif
grid_authenticated = FALSE;
return(FALSE);
}
/****************************************************/
/* upload a temporary credential to a remote server */
/****************************************************/
/* TODO - if grid_passwd is NULL -> use stdin */
#define DEBUG_GRID_CREDENTIAL_INIT 0
void grid_credential_init(const gchar *grid_password)
{
#ifdef WITH_GRISU
gint inp, out, err;
gchar **argv, **envp;
const gchar *username, *password, *server, *port;
GError *error=NULL;
GPid pid;
FILE *fpi, *fpo, *fpe;
/* TODO - informative user error messages */
if (!grid_password)
return;
if (grid_authenticated)
return;
if (!myproxy_init)
return;
username = grisu_username_get();
password = grisu_password_get();
server = grisu_myproxy_get();
port = grisu_myproxyport_get();
#if DEBUG_GRID_CREDENTIAL_INIT
printf("Credential for: ");
printf("%s : %s -> %s : %s\n", username, password, server, port);
#endif
/* FIXME - authentication issues with myproxy/myproxy2 */
/* solution is to point at myproxy2 and set */
/* MYPROXY_SERVER_DN /C=AU/O=APACGrid/OU=VPAC/CN=myproxy2.arcs.org.au */
/* FIXME - need to ensure enviroment has GT_PROXY_MODE set to "old" */
/* unless markus fixes grisu's credential retrieval */
/* build argument vector */
/* FIXME - implement this */
envp = g_malloc(3 * sizeof(gchar *));
*(envp) = g_strdup("GT_PROXYMODE=old");
*(envp+1) = g_strdup("MYPROXY_SERVER_DN=/C=AU/O=APACGrid/OU=VPAC/CN=myproxy2.arcs.org.au");
*(envp+2) = NULL;
argv = g_malloc(10 * sizeof(gchar *));
/* NB: need full path to executable */
*(argv) = g_strdup(myproxy_init);
*(argv+1) = g_strdup("-l");
*(argv+2) = g_strdup(username);
/* small lifetime while we debug */
*(argv+3) = g_strdup("-c");
*(argv+4) = g_strdup("1");
*(argv+5) = g_strdup("-a");
*(argv+6) = g_strdup("-S");
*(argv+7) = g_strdup("-s");
*(argv+8) = g_strdup(server);
*(argv+9) = NULL;
/* spawn process */
if (g_spawn_async_with_pipes(NULL, argv, NULL, G_SPAWN_DO_NOT_REAP_CHILD,
NULL, NULL, &pid, &inp, &out, &err, &error))
{
if (pid)
{
/* parent - wait until child is done */
//printf("parent: waiting for child...\n");
fpi = fdopen(inp, "a");
fpo = fdopen(out, "r");
fpe = fdopen(err, "r");
/* NB: -S will make myproxy prompt for grid passphrase */
/* and then the credential password once only */
/* CURRENT - not sure why this isnt working - it seems */
/* to work if run manually from the command line */
fprintf(fpi, "%s\n", grid_password);
fflush(fpi);
/* CURRENT - this seems to fix the problem! */
/* obviously a delay is needed while myproxy-init processes the */
/* grid_password to generate a local proxy */
/* the problem is - how to we poll stdout to know when to send the */
/* passphrase ... which is probably better than an arbitrary sleep */
#ifndef WIN32
sleep(5);
#endif
/* test if process has terminated */
/* note that if it has - child is reaped and we cant call waitpid() again */
#ifndef __WIN32
if (waitpid(pid, NULL, WNOHANG) > 0)
{
printf("Bad password.\n");
g_spawn_close_pid(pid);
grid_authenticated = FALSE;
return;
}
#endif
//printf("waitpid 4: %d\n", waitpid(pid, NULL, WEXITED | WNOHANG));
fprintf(fpi, "%s\n", password);
fflush(fpi);
fclose(fpi);
#if DEBUG_GRID_CREDENTIAL_INIT
gchar *line;
do
{
line = file_read_line(fpo);
printf("FORK, stdout: %s\n", line);
g_free(line);
}
while(line != NULL);
do
{
line = file_read_line(fpe);
printf("FORK, stderr : %s\n", line);
g_free(line);
}
while(line != NULL);
#endif
/* cleanup */
fclose(fpo);
fclose(fpe);
close(inp);
close(out);
close(err);
#ifndef __WIN32
waitpid(pid, NULL, WEXITED);
#endif
g_spawn_close_pid(pid);
grid_authenticated = TRUE;
/* sleep - give the uploaded proxy some time to "stick" to the server */
/* FIXME - better to poll (myproxy-logon?) for the credential */
printf("Uploading Credential, please wait ...\n");
#ifndef WIN32
sleep(5);
#endif
printf("Done.\n");
}
}
else
{
printf("Failed to upload credential, myproxy-init not found or bad connectivity?\n");
}
g_strfreev(argv);
g_strfreev(envp);
#endif
return;
}
/****************************************************/
/* get short text message describing current status */
/****************************************************/
const gchar *grid_get_status()
{
if (grid_authenticated)
return("Authenticated");
else
return("Not authenticated");
}
/***********************************************************/
/* generate a random alphabetical string of specified size */
/***********************************************************/
gchar *grid_random_alpha(gint length)
{
gint i;
GRand *r;
GString *text;
r = g_rand_new();
text = g_string_new(NULL);
for (i=length ; i-- ; )
{
g_string_sprintfa(text, "%c", g_rand_int_range(r, 'a', 'z'));
}
g_rand_free(r);
return(g_string_free(text, FALSE));
}
/************************************************************/
/* generate a random alpha-numeric string of specified size */
/************************************************************/
gchar *grid_random_alphanum(gint length)
{
gint i, decide;
GRand *r;
GString *text;
r = g_rand_new();
text = g_string_new(NULL);
/* NB: some systems require an alphabetical character first */
g_string_sprintfa(text, "%c", g_rand_int_range(r, 'a', 'z'));
i=1;
while (i<length)
{
decide = g_rand_int_range(r, 0, 99);
if (decide < 50)
g_string_sprintfa(text, "%c", g_rand_int_range(r, 'a', 'z'));
else
g_string_sprintfa(text, "%c", g_rand_int_range(r, '0', '9'));
i++;
}
g_rand_free(r);
return(g_string_free(text, FALSE));
}
/**********************************/
/* attempt to upload a credential */
/**********************************/
gint grid_connect(gint method)
{
#ifdef WITH_GRISU
switch (method)
{
case GRID_MYPROXY:
grid_auth_check();
break;
case GRID_LOCALPROXY:
/* if successful, send info to grisu client for soap header */
/* CURRENT - myproxy-init fed with grid_passwd */
grid_credential_init(grisu_password_get());
break;
}
grisu_auth_set(TRUE);
return(TRUE);
#else
return(FALSE);
#endif
}
/**************/
/* initialize */
/**************/
void grid_setup(void)
{
if (!grid_table)
{
#ifdef WITH_GRISU
grisu_init();
if (!myproxy_init)
myproxy_init = g_find_program_in_path("myproxy-init");
if (!myproxy_init)
printf("grid_setup() Warning. Failed to locate: myproxy-init\n");
#endif
grid_table = g_hash_table_new(g_str_hash, g_str_equal);
}
}
/***********/
/* cleanup */
/***********/
void grid_cleanup(void)
{
g_hash_table_destroy(grid_table);
}
/*****************************************/
/* process completed jobs after download */
/*****************************************/
/* this could be generic, since we assume output is on local filestore */
void grid_process_job(const gchar *job_name, GSList *file_list)
{
#ifdef WITH_GRISU
gint type;
gchar *ext, *name;
gchar *input=NULL, *output=NULL;
GSList *item;
struct model_pak *model;
type = grisu_job_type(job_name);
switch (type)
{
case JOB_GULP:
printf("processing GULP job ... \n");
for (item=file_list ; item ; item=g_slist_next(item))
{
name = item->data;
/* skip if no extension */
ext = file_extension_get(name);
if (!ext)
continue;
/* load results file as preference for coords */
if (g_strncasecmp(ext, "res", 3) == 0)
input = name;
/* only load original input file if no results file found */
if (g_strncasecmp(ext, "gin", 3) == 0)
{
if (!input)
input = name;
}
/* output file containing energies etc */
if (g_strncasecmp(ext, "go", 2) == 0)
output = name;
}
if (!output)
{
printf("No GULP output file found. Failed job?\n");
break;
}
if (!input)
{
printf("No GULP input file found. Failed authentication?\n");
break;
}
/* create new model for the results */
model = model_new();
/* read main data from the res file (correct charges etc.) */
read_gulp(input, model);
/* graft to the model tree, so subsequent GULP read doesn't replace coords */
/* CURRENT - give the loaded model the same name as the job ... better method? */
if (model->basename)
{
g_free(model->basename);
// model->basename = g_strdup(job_name);
// model->basename = g_strdup(input);
model->basename = parse_strip(input);
}
sysenv.active_model = model;
tree_model_add(model);
/* get the output energy/phonons etc. */
read_gulp_output(output, model);
/* FIXME - if the GULP job fails - model_prep() isnt called, and the */
/* model camera isnt initialized => error trap when gdis tries to visualize */
if (!model->camera)
{
printf("WARNING: GULP calculation has possibly failed.\n");
model_prep(model);
}
/* TODO - return model - so gui part decides whether to force a select/display or not */
//gui_model_select(model);
break;
case JOB_GAMESS:
printf("processsing GAMESS job ... \n");
for (item=file_list ; item ; item=g_slist_next(item))
{
name = item->data;
ext = file_extension_get(name);
/* skip if no extension */
if (!ext)
continue;
if (g_strncasecmp(ext, "gmot", 4) == 0)
output = name;
}
if (output)
{
/* create new model for the results */
model = model_new();
/* read main data from the res file (correct charges etc.) */
read_gms_out(output, model);
if (model->basename)
{
g_free(model->basename);
model->basename = g_strdup(job_name);
}
sysenv.active_model = model;
tree_model_add(model);
/* FIXME - if the job fails - model_prep() isnt called, and the */
/* model camera isnt initialized => error trap when gdis tries to visualize */
if (!model->camera)
{
printf("WARNING: GAMESS calculation has possibly failed.\n");
model_prep(model);
}
/* TODO - return model - so gui part decides whether to force a select/display or not */
//gui_model_select(model);
//sysenv.active_model = model;
}
else
{
printf("No GAMESS output file found. Failed job?\n");
}
break;
default:
printf("Error, unknown job\n");
return;
}
#endif
}
/***************************/
/* download completed jobs */
/***************************/
GSList *grid_download_job(const gchar *name)
{
#ifdef WITH_GRISU
gchar *remote_cwd, *local, *remote;
GSList *item, *list, *results=NULL;
printf("Getting result files for: %s\n", name);
remote_cwd = grisu_job_cwd(name);
/* TODO - get job type (GULP etc) from name (eg grisu_job_type()) and filter */
//printf("Working directory = %s\n", cwd);
if (remote_cwd)
{
list = grisu_file_list(remote_cwd);
for (item=list ; item ; item=g_slist_next(item))
{
gchar *file = item->data;
printf("[%s]\n", file);
// TODO - strictly - should be the job's local_output destination here */
local = g_build_filename(sysenv.cwd, file, NULL);
remote = g_build_filename(remote_cwd, file, NULL);
//printf("Transferring [%s] -> [%s]\n", remote, local);
/* if download is successful add to results list for post-processing */
if (grisu_file_download(remote, local))
results = g_slist_prepend(results, local);
g_free(remote);
}
g_free(remote_cwd);
}
return(results);
#else
return(NULL);
#endif
}
/**********************************/
/* background task job submission */
/**********************************/
void grid_job_start(gpointer data)
{
#ifdef WITH_GRISU
gint alen, rlen;
gchar *jobxml, *value, *tmp;
gchar *fs_absolute, *fs_relative;
gchar *local, *remote;
GHashTable *details;
GSList *list;
struct grid_pak *grid=data;
g_assert(grid != NULL);
g_assert(grid->exename != NULL);
g_assert(grid->remote_q != NULL);
grid->jobcode = grisu_job_type(grid->exename);
grid->user_vo = g_strdup(grisu_vo_get());
grid->remote_site = grisu_site_name(grid->remote_q);
if (!grid->remote_site)
{
printf("Could not determine submission site.\n");
return;
}
list = grisu_application_versions(grid->exename, grid->remote_site);
if (list)
{
/* CURRENT - just use the first entry */
if (grid->exe_version)
g_free(grid->exe_version);
grid->exe_version = g_strdup(list->data);
}
else
{
/* strictly, not all programs would require a version */
/* eg gamess does, but gulp doesnt */
printf("Warning: could not determine executable version of [%s] at [%s]\n", grid->exename, grid->remote_site);
}
details = grisu_application_details(grid->exename, grid->remote_site);
if (details)
{
tmp = g_hash_table_lookup(details, "Executables");
if (!tmp)
{
printf("Failed to locate executable on remote site.\n");
return;
}
grid->remote_exe = g_strdup(tmp);
tmp = g_hash_table_lookup(details, "Module");
if (tmp)
grid->remote_exe_module = g_strdup(tmp);
//printf("Requiring module [%s]\n", grid->remote_exe_module);
/* CURRENT - prefer serial over parallel */
value = g_hash_table_lookup(details, "ParallelAvail");
if (g_strncasecmp(value, "true", 4) == 0)
{
grid->remote_exe_type = GRID_MPI;
/* CURRENT - hack to force // ie mpi */
grid->remote_exe_np = 2;
}
/* CURRENT - prefer serial over parallel */
value = g_hash_table_lookup(details, "SerialAvail");
if (g_strncasecmp(value, "true", 4) == 0)
{
grid->remote_exe_type = GRID_SERIAL;
grid->remote_exe_np = 1;
}
if (grid->remote_exe_type == -1)
{
printf("Failed to determine serial/parallel invocation method on remote site.\n");
return;
}
}
else
{
printf("Failed to get application details from MDS.\n");
return;
}
// -----------------
grid->jobname = grisu_jobname_request(grid->jobcode);
if (!grid->jobname)
{
printf("Failed to create job, not authenticated?\n");
return;
}
/* calculate mount point */
fs_absolute = grisu_absolute_job_dir(grid->jobname, grid->remote_q, grid->user_vo);
if (!fs_absolute)
{
printf("Failed to locate a valid remote filesystem for VO [%s] at [%s]\n", grid->user_vo, grid->remote_site);
return;
}
fs_relative = grisu_relative_job_dir(grid->jobname);
g_assert(fs_relative != NULL);
alen = strlen(fs_absolute);
rlen = strlen(fs_relative);
if (alen > rlen)
grid->remote_root = g_strndup(fs_absolute, alen-rlen);
else
{
printf("Bad filesystem returned by grisu.\n");
// cope as best we can
grid->remote_root = g_strdup(fs_absolute);
}
//printf("Remote root: %s\n", grid->remote_root);
/* upload stage */
/* TODO - stat the file to ensure it was written */
if (!grid->local_input || !grid->local_cwd)
{
printf("Error, job input file not correctly written.\n");
return;
}
/* TODO - could do this earlier as well ... */
switch (grid->jobcode)
{
case JOB_GAMESS:
grid->local_output = parse_extension_set(grid->local_input, "gmot");
break;
case JOB_GULP:
grid->local_output = parse_extension_set(grid->local_input, "got");
break;
}
local = g_build_filename(grid->local_cwd, grid->local_input, NULL);
remote = g_build_filename(fs_absolute, grid->local_input, NULL);
//printf("upload [%s] -> [%s]\n", local, remote);
grisu_file_upload(local, remote);
g_free(local);
g_free(remote);
jobxml = grisu_xml_create(grid);
//printf(" *** XML:\n%s\n", jobxml);
grisu_job_configure(grid->jobname, jobxml);
grisu_job_submit(grid->jobname, grid->user_vo);
g_free(fs_absolute);
g_free(fs_relative);
g_free(jobxml);
#endif
}
/*******************/
/* completion task */
/*******************/
void grid_job_stop(gpointer data)
{
struct grid_pak *grid=data;
/* TODO - free the grid structre */
grid_free(grid);
#ifdef WITH_GUI
grid_task_stop();
#endif
/* refresh all jobs */
/* FIXME - too expensive to keep doing all the time */
/* FIXME - do this at start (eg when connecting ... and only add/del subsequently) */
//gui_job_refresh_all();
}
/*******************************************************/
/* submit a grid job (potentially from setup a dialog) */
/*******************************************************/
/* name = application name (eg "gulp") */
gint grid_job_submit(const gchar *name, gpointer data)
{
#ifdef WITH_GRISU
gchar *remote_q;
struct grid_pak *grid=data;
/* checks */
g_assert(grid != NULL);
/* test we have a valid grid destination */
remote_q = grid_application_get(name);
if (!remote_q)
{
printf("No valid destination queue registered for: %s\n", name);
return(FALSE);
}
#ifdef WITH_GUI
if (!grid_task_start())
return(FALSE);
#endif
grid->exename = g_strdup(name);
grid->remote_q = g_strdup(remote_q);
/* submit and lock model */
task_new("grid", grid_job_start, grid, grid_job_stop, grid, NULL);
return(TRUE);
#else
printf("No grid support installed.\n");
return(FALSE);
#endif
}
|