2
Copyright (C) 2005- The University of Notre Dame
3
This software is distributed under the GNU General Public License.
4
See the file COPYING for details.
14
#include "chirp_matrix.h"
16
void printUsage(char* cmd) {
17
printf("Use: %s <options> -F [finalize file]",cmd);
18
printf(" where options are:\n");
19
printf(" -a <mode> Explicit authentication mode.\n");
20
printf(" -d <subsystem> Enable debugging for this subsystem. (Try -d all to start.)\n");
21
//printf(" -t <string> Timeout, e.g. 60s\n");
22
printf(" -D <file> Download Results Matrix to a file.\n");
23
printf(" -R Remove remote state.\n");
24
printf(" -L Remove local state.\n");
25
printf(" -M Remove results matrix.\n");
26
printf(" -h Show this help screen\n");
29
int main(int argc, char** argv) {
31
int did_explicit_auth = 0;
32
int download,rm_local,rm_remote,rm_mat,file_provided;
33
int rm_remote_error = 0;
34
char matrix_target[CHIRP_PATH_MAX];
35
char finalize_file[CHIRP_PATH_MAX];
36
time_t stoptime = time(0)+3600;
38
download=rm_local=rm_remote=rm_mat=file_provided=0;
40
while((cl=getopt(argc,argv,"+a:d:hD:LRMF:"))!=(char)-1) {
43
auth_register_byname(optarg);
44
did_explicit_auth = 1;
47
debug_flags_set(optarg);
53
case 'D': // download matrix data to local disk
55
strcpy(matrix_target,optarg);
57
case 'L': // force LOCAL state removal
60
case 'R': // force REMOTE state removal (chirp_distribute -X)
63
case 'M': // force REMOTE MATRIX state removal
68
strcpy(finalize_file,optarg);
74
fprintf(stderr,"Please provide argument -F [finalize file]\n");
79
if(!did_explicit_auth) auth_register_all(); // if an authentication mechanism wasn't chosen, default register all.
80
debug_config(argv[0]); // indicate what string to use as the executable name when printing debugging information
81
// first, parse finalize file to get information.
92
FILE* fp = fopen(finalize_file,"r");
94
fprintf(stderr,"Finalize file not readable.\n");
98
// 0th item is workload id
99
if(fscanf(fp, " wID=%i ",&strlentmp) == 1) {
100
wID = malloc((strlentmp+1)*sizeof(char));
103
fprintf(stderr,"Could not allocate %i bytes for workload ID\n",strlentmp);
106
if(fscanf(fp, " %s ", wID) != 1) {
107
fprintf(stderr,"Could not read in workload ID\n");
113
// first item is local prefix -- remove everything.
114
if(fscanf(fp, " local_dir=%i ",&strlentmp) == 1) {
115
local_dir = (char*) malloc((strlentmp+1)*sizeof(char));
118
fprintf(stderr,"Could not allocate %i bytes for local directory\n",strlentmp);
121
if(fscanf(fp," %s ", local_dir) != 1) {
122
fprintf(stderr,"Could not read in local directory\n");
127
// second item is matrix host -\ remove
128
// third item is matrix path -/ matrix
129
if(fscanf(fp, " mat_host=%i ",&strlentmp) == 1) {
130
mat_host = (char *) malloc((strlentmp+1)*sizeof(char));
133
fprintf(stderr,"Could not allocate %i bytes for matrix host\n",strlentmp);
136
if(fscanf(fp," %s ", mat_host) != 1) {
137
fprintf(stderr,"Could not read in matrix host\n");
142
if(fscanf(fp, " mat_path=%i ",&strlentmp) == 1) {
143
mat_path = (char *) malloc((strlentmp+1)*sizeof(char));
146
fprintf(stderr,"Could not allocate %i bytes for matrix path\n",strlentmp);
149
if(fscanf(fp," %s ", mat_path) != 1) {
150
fprintf(stderr,"Could not read in matrix path\n");
156
// 4th item is chirp_dirname
157
if(fscanf(fp, " remote_dir=%i ",&strlentmp) == 1) {
158
remote_dir = (char *) malloc((strlentmp+1)*sizeof(char));
161
fprintf(stderr,"Could not allocate %i bytes for remote path\n",strlentmp);
164
if(fscanf(fp," %s ", remote_dir) != 1) {
165
fprintf(stderr,"Could not read in remote path\n");
170
fprintf(stderr,"Asked to remove remote state, but there is no remote state specified.\n");
174
// 7th item is full goodstring
175
if(fscanf(fp, " node_list=%i ",&strlentmp) == 1) {
176
node_list = (char *) malloc((strlentmp+1)*sizeof(char));
179
fprintf(stderr,"Could not allocate %i bytes for remote hosts\n",strlentmp);
182
if(fread(node_list,1,strlentmp,fp) != strlentmp) {
183
fprintf(stderr,"Could not read in remote hosts\n");
187
if(rm_remote==1 && rm_remote_error == 0) {
188
fprintf(stderr,"Asked to remove remote state, but there is no remote state specified.\n");
192
// 9th item is hostname
193
if(fscanf(fp, " host=%i ",&strlentmp) == 1) {
194
hn = malloc((strlentmp+1)*sizeof(char));
197
fprintf(stderr,"Could not allocate %i bytes for hostname\n",strlentmp);
200
if(fscanf(fp, " %s ", hn) != 1) {
201
fprintf(stderr,"Could not read in hostname\n");
205
if(rm_remote==1 && rm_remote_error == 0) {
206
fprintf(stderr,"Asked to remove remote state, but there is no remote state specified.\n");
210
// 10th item is full function directory -- remove tarball, exception list
211
if(fscanf(fp, " fun_path=%i ",&strlentmp) == 1) {
212
fun_path = (char *) malloc((strlentmp+1)*sizeof(char));
215
fprintf(stderr,"Could not allocate %i bytes for function directory\n",strlentmp);
218
if(fscanf(fp," %s ", fun_path) != 1) {
219
fprintf(stderr,"Could not read in function directory\n");
222
cmd = (char *) malloc((strlen(fun_path)+strlen("rm -f ")+strlen(wID)+strlen(".func.tar")+12)*sizeof(char));
225
fprintf(stderr,"Could not allocate memory for command\n");
228
sprintf(cmd,"rm -f %s/%s.func.tar",fun_path,wID);
229
if(system(cmd)) { fprintf(stderr,"Could not remove %s/%s.func.tar\n",fun_path,wID); exit(1);}
230
sprintf(cmd,"rm -f %s/exclude.list",fun_path);
231
if(system(cmd)) { fprintf(stderr,"Could not remove %s/exclude.list\n",fun_path); exit(1);}
242
// end parsing finalize file
244
// next, download if desired.
247
fprintf(stderr,"Download Matrix Mode\n");
248
FILE* mt = fopen(matrix_target, "w");
249
struct chirp_matrix* m = chirp_matrix_open( mat_host, mat_path, stoptime);
251
int w = chirp_matrix_width( m );
252
int h = chirp_matrix_height( m );
253
//int e = chirp_matrix_element_size( m );
254
double* buf = malloc(w*sizeof(double));
256
for(y=0; y < h; y++) {
257
chirp_matrix_get_row( m , y, buf, stoptime );
259
fprintf(mt,"%i %i %.2lf\n",y,x,buf[x]);
265
printf("Could not open matrix %s %s\n",mat_host,mat_path);
269
// next, delete remote state if desired.
270
if(rm_remote && !rm_remote_error) {
271
fprintf(stderr,"Remove Remote State Mode\n");
272
cmd = (char *) malloc(strlen("chirp_distribute -a hostname -X ")+10+(2*strlen(hn))+1+strlen(remote_dir)+1+strlen(node_list)+1);
274
fprintf(stderr,"Allocating distribute command string memory failed!\n");
277
sprintf(cmd,"chirp_distribute -a hostname -X %s %s %s",hn,remote_dir,node_list);
278
debug(D_CHIRP,"%s\n",cmd);
280
sprintf(cmd,"chirp_distribute -a hostname -X %s %s %s",hn,remote_dir,hn);
281
debug(D_CHIRP,"%s\n",cmd);
286
// next, delete matrix if desired.
288
fprintf(stderr,"Remove Matrix State Mode\n");
289
chirp_matrix_delete( mat_host, mat_path, time(0)+600 );
292
// next, delete local if desired.
294
fprintf(stderr,"Remove Local State Mode\n");
295
cmd = (char *) malloc(strlen("rm -rf ")+1+strlen(local_dir)+1);
297
fprintf(stderr,"Allocating distribute command string memory failed!\n");
300
sprintf(cmd,"rm -rf %s",local_dir);