#include <stdio.h> |
#include <stdlib.h> |
#include <string.h> |
#include <sys/types.h> |
#ifndef WINNT |
# include <unistd.h> |
# include <sys/time.h> |
# include <sys/uio.h> |
# include <sys/socket.h> |
# include <netinet/in.h> |
# include <netdb.h> |
#else |
# include <winsock.h> |
#endif |
#include <time.h> |
#define AM_INITIALIZE 1 |
#include “api.h” |
int dont_connect = 0; |
int has_qmgr_host; |
int has_qmgr_port; |
int has_org; |
int has_orgpath; |
char lic_file[256]; |
char org_name[256]; |
char binpath[256]; |
char orgpath[256]; |
char qmgr_host[256]; |
int qmgr_port; |
int rmgr_port; |
int msg_sock = -1; |
int msg_port = -1; |
int msg_sock_job = -1; |
int auto_startup; |
char sys_rcf_file[256]; |
char usr_rcf_file[256]; |
int has_cmd_rcf; |
char cmd_rcf_file[256]; |
/* ==================== */ |
#define SUBMIT 1 |
#define ABORT 2 |
#define WATCHJOB 3 |
#define WATCHQUE_LOG 4 |
#define WATCHQUE_FULL 5 |
#define WATCHQUE_CPU 6 |
#define LISTCOMP 7 |
#define RCFILEWRITE 8 |
#define ADMINTEST 9 |
#define RECONFIG 10 |
#define QUIT 11 /* must be highest defined number type */ |
#define NOTVALID 9999 |
/* ==================== */ |
#ifdef WINNT |
BOOL console_event_func(DWORD dwEvent) |
{ |
if(dwEvent == CTRL_LOGOFF_EVENT) |
return TRUE; |
#ifdef DEBUG |
fprintf(stderr,”\nbye ...”); |
#endif |
fprintf(stderr,”\n”); |
api_release_license(); |
#ifdef WINNT |
WSACleanup(); |
#endif |
return FALSE; |
} |
#endif |
/* ==================== */ |
void leafname(char *input_string, char *output_string) |
{ |
int string_length; |
int i; |
char temp_string[256]; |
int found; |
/*********************************************************************/ |
/* First get rid of the leading path (if any). */ |
/*********************************************************************/ |
string_length = strlen(input_string); |
if(string_length < 1){ |
output_string[0] = ‘\0’; |
return; |
} |
found = 0; |
for(i = string_length - 1; i >= 0; i--){ |
if( (input_string[i] == ‘/’) || (input_string[i] == ‘\\’) ){ |
found = 1; |
strcpy(temp_string, &input_string[i + 1]); |
break; |
} |
} |
if(found == 0) |
strcpy(temp_string, input_string); |
/*********************************************************************/ |
/* Now get rid of the extention (if any). */ |
/*********************************************************************/ |
string_length = strlen(temp_string); |
if(string_length < 1){ |
output_string[0] = ‘\0’; |
return; |
} |
for(i = string_length - 1; i >= 0; i--){ |
if( (temp_string[i] == ‘.’) && (i != 0) ){ |
temp_string[i] = ‘\0’; |
strcpy(output_string, temp_string); |
return; |
} |
} |
strcpy(output_string, temp_string); |
return; |
} |
/* ==================== */ |
int submit_job(void) |
{ |
int background; |
int i; |
int lenc; |
int submit_index; |
int job_number; |
int jmgr_port; |
char job_name[256]; |
int mem; |
char job_fullname[256]; |
int srtn; |
char out_str[2048]; |
int ans; |
char ques_text[512]; |
char ans1_text[32]; |
char ans2_text[32]; |
background = 0; |
/* |
** if not auto_startup, ask for details ... |
*/ |
if(auto_startup == 0){ |
background = 1; |
/* |
** ask jobname ... |
*/ |
printf(“\nEnter job name: “); |
scanf(“%s”,job_name); |
/* |
** ask memory ... |
*/ |
printf(“\nEnter memory (in set units): “); |
scanf(“%d”,&mem); |
/* |
** print list of hosts from QueMgr ... |
** and ask for which to submit to ... |
*/ |
if(cfg->QUE_TYPE == MSC_QUEUE){ |
printf(“\nhosts:\n”); |
printf(“index name\n”); |
printf(“------------\n”); |
for(i=0;i<cfg->hsts[api_application_index-1].num_hosts;i++){ |
printf(“%-5d %s\n”,i+1,cfg->hsts[api_application_index-1].hosts[i].pseudohost_name); |
} |
printf(“\nEnter host index: “); |
scanf(“%d”,&submit_index); |
submit_index--; |
printf(“\n”); |
if( (submit_index < 0) || (submit_index >= cfg->hsts[api_application_index-1].num_hosts) ){ |
printf(“Error, invalid index\n”); |
return 1; |
} |
}else{ |
printf(“\nqueues:\n”); |
printf(“index name\n”); |
printf(“------------\n”); |
for(i=0;i<cfg->ques[api_application_index-1].num_queues;i++){ |
printf(“%-5d %s -> %s\n”,i+1,cfg->ques[api_application_index-1].queues[i].queue_name1, |
cfg->ques[api_application_index-1].queues[i].queue_name2); |
} |
printf(“\nEnter queue index: “); |
scanf(“%d”,&submit_index); |
submit_index--; |
printf(“\n”); |
if( (submit_index < 0) || (submit_index >= cfg->ques[api_application_index-1].num_queues) ){ |
printf(“Error, invalid index\n”); |
return 1; |
} |
} |
/* |
** set up config/submit struct info ... |
*/ |
strcpy(job_fullname,job_name); |
lenc = (int)strlen(job_fullname); |
for(i=0;i<lenc;i++){ |
if(job_fullname[i] == ‘\\’) |
job_fullname[i] = ‘/’; |
} |
leafname(job_fullname,job_name); |
if(api_application_index == MSC_NASTRAN){ |
sprintf(nas_submit.nas_input_deck,”%s”,job_fullname); |
nas_config.mem_req = (float)mem; |
nas_submit.submit_index = submit_index; |
}else if(api_application_index == HKS_ABAQUS){ |
sprintf(aba_submit.aba_input_deck,”%s”,job_fullname); |
aba_config.mem_req = (float)mem; |
aba_submit.submit_index = submit_index; |
}else if(api_application_index == MSC_MARC){ |
sprintf(mar_submit.datfile_name,”%s”,job_fullname); |
mar_config.mem_req = (float)mem; |
mar_submit.submit_index = submit_index; |
}else{ |
sprintf(gen_submit[api_application_index-GENERAL].gen_input_deck,”%s”,job_fullname); |
gen_config[api_application_index-GENERAL].mem_req = (float)mem; |
gen_submit[api_application_index-GENERAL].submit_index = submit_index; |
} |
}else{ |
/* |
** leave all config and submit struct settings alone, as |
** the rcf/override ASSUME to have it all correct ... |
** (just get job_name for use below ...) |
*/ |
if(api_application_index == MSC_NASTRAN){ |
leafname(nas_submit.nas_input_deck,job_name); |
}else if(api_application_index == HKS_ABAQUS){ |
leafname(aba_submit.aba_input_deck,job_name); |
}else if(api_application_index == MSC_MARC){ |
leafname(mar_submit.datfile_name,job_name); |
}else{ |
leafname(gen_submit[api_application_index-GENERAL].gen_input_deck,job_name); |
} |
} |
ans = NO; |
srtn = api_check_job(ques_text,ans1_text,ans2_text,out_str); |
if(srtn < 0){ |
printf(“%s”,out_str); |
return srtn; |
} |
if(srtn > 0){ |
redo: |
printf(“%s\n”,ques_text); |
printf(“\nAnswer:\n”); |
printf(“-------\n”); |
printf(“0 - %s\n”,ans1_text); |
printf(“1 - %s\n”,ans2_text); |
printf(“\nanswer: “); |
scanf(“%d”,&ans); |
printf(“\n”); |
if( (ans != NO) && (ans != YES) ){ |
printf(“Error, invalid answer\n\n”); |
goto redo; |
} |
} |
srtn = api_submit_job(qmgr_host,qmgr_port,job_name,background,&job_number,binpath, |
&jmgr_port,ans,out_str); |
if(out_str[0] != ‘\0’){ |
printf(“%s”,out_str); |
} |
if( (srtn == 0) && (background == 1) ){ |
/* |
** right away get monitor socket ... |
*/ |
msg_sock = api_mon_job_init(api_this_host,jmgr_port,&msg_port,out_str); |
if(msg_sock < 0){ |
msg_port = -1; |
msg_sock_job = -1; |
printf(“%s”,out_str); |
}else{ |
msg_sock_job = job_number; |
} |
} |
return srtn; |
} |
/* ==================== */ |
int abort_job(void) |
{ |
int srtn; |
Job_List *jr_ptr = NULL; |
int num_running_jobs; |
int job_number; |
char j_numstr[100]; |
int found; |
char job_user[256]; |
char job_name[256]; |
char proj_name[256]; |
int i; |
char out_str[2048]; |
jr_ptr = api_get_runningjob_list(qmgr_host,qmgr_port,&num_running_jobs,out_str); |
if(num_running_jobs == 0){ |
printf(“\nNo active jobs found\n”); |
return 0; |
} |
if( (num_running_jobs < 0) || (jr_ptr == NULL) ){ |
printf(“%s”,out_str); |
if(jr_ptr != NULL) |
free(jr_ptr); |
return 1; |
} |
job_number = -1; |
if(auto_startup == 0){ |
/* |
** present list to user ... |
*/ |
printf(“\nRunning jobs ....\n\n”); |
printf(“num jobname jobuser project amhost runhost subtime\n”); |
printf(“----------------------------------------------------------------------------------------------------------\n”); |
for(i=0;i<num_running_jobs;i++){ |
printf(“%-4d %-20s %-20s %-20s %-20s %-20s %-20s\n”,jr_ptr[i].job_number, |
jr_ptr[i].job_name, |
jr_ptr[i].job_user, |
jr_ptr[i].job_proj, |
jr_ptr[i].am_host_name, |
jr_ptr[i].job_run_host, |
jr_ptr[i].sub_time_str); |
} |
for(i=0;i<100;i++) |
j_numstr[i] = ‘\0’; |
printf(“\nEnter job number: “); |
scanf(“%s”,j_numstr); |
if( (j_numstr[0] == ‘q’) || (j_numstr[0] == ‘Q’) || (j_numstr[0] == ‘0’) ){ |
free(jr_ptr); |
return 0; |
} |
sscanf(j_numstr,”%d”,&job_number); |
found = 0; |
for(i=0;i<num_running_jobs;i++){ |
if(job_number == jr_ptr[i].job_number){ |
found = 1; |
break; |
} |
} |
if(!found){ |
printf(“Error, job number %d not in list\n”,job_number); |
free(jr_ptr); |
return 1; |
} |
printf(“\n”); |
}else{ |
if(api_application_index == MSC_NASTRAN){ |
leafname(nas_submit.nas_input_deck,job_name); |
}else if(api_application_index == HKS_ABAQUS){ |
leafname(aba_submit.aba_input_deck,job_name); |
}else if(api_application_index == MSC_MARC){ |
leafname(mar_submit.datfile_name,job_name); |
}else{ |
leafname(gen_submit[api_application_index-GENERAL].gen_input_deck,job_name); |
} |
strcpy(proj_name,ui_config.project_name); |
/* |
** search list for match and set job_number ... |
*/ |
job_number = -1; |
for(i=0;i<num_running_jobs;i++){ |
if(strcmp(jr_ptr[i].job_name,job_name) == 0){ |
if(strcmp(jr_ptr[i].job_proj,proj_name) == 0){ |
job_number = jr_ptr[i].job_number; |
break; |
} |
} |
} |
} |
strcpy(job_user,api_user_name); |
srtn = api_abort_job(qmgr_host,qmgr_port,job_number,job_user,out_str); |
if(out_str[0] != ‘\0’){ |
printf(“%s”,out_str); |
} |
free(jr_ptr); |
return srtn; |
} |
/* ==================== */ |
int watch_job(void) |
{ |
Job_List *jr_ptr = NULL; |
int num_running_jobs; |
int check; |
char job_host[128]; |
int job_port = 0; |
char j_numstr[100]; |
int found; |
int srtn; |
char *log_str; |
char job_name[256]; |
char proj_name[256]; |
char sfile[256]; |
int i; |
int job_number; |
int sev_level; |
char out_str[2048]; |
int num_msgs; |
Msg_List *msg_ptr = NULL; |
int cpu, pct_cpu; |
int mem, pct_mem; |
int dsk, pct_dsk; |
int elapsed; |
int status; |
FILE_LIST *file_list = NULL; |
int num_files = 0; |
int file_index; |
int sizekb; |
int num_fs; |
JOB_FS_LIST *job_fs_list; |
extern void get_leaf_and_extention(char *,char *); |
jr_ptr = api_get_runningjob_list(qmgr_host,qmgr_port,&num_running_jobs,out_str); |
if(num_running_jobs == 0){ |
printf(“\nNo active jobs found\n”); |
return 0; |
} |
if( (num_running_jobs < 0) || (jr_ptr == NULL) ){ |
printf(“%s”,out_str); |
if(jr_ptr != NULL) |
free(jr_ptr); |
return 1; |
} |
job_number = -1; |
if(auto_startup == 0){ |
/* |
** present list to user ... |
*/ |
printf(“\nRunning jobs ....\n\n”); |
printf(“num jobname jobuser project amhost runhost subtime\n”); |
printf(“----------------------------------------------------------------------------------------------------------\n”); |
for(i=0;i<num_running_jobs;i++){ |
printf(“%-4d %-20s %-20s %-20s %-20s %-20s %-20s\n”,jr_ptr[i].job_number, |
jr_ptr[i].job_name, |
jr_ptr[i].job_user, |
jr_ptr[i].job_proj, |
jr_ptr[i].am_host_name, |
jr_ptr[i].job_run_host, |
jr_ptr[i].sub_time_str); |
} |
for(i=0;i<100;i++) |
j_numstr[i] = ‘\0’; |
printf(“\nEnter job number: “); |
scanf(“%s”,j_numstr); |
if( (j_numstr[0] == ‘q’) || (j_numstr[0] == ‘Q’) || (j_numstr[0] == ‘0’) ){ |
free(jr_ptr); |
return 0; |
} |
sscanf(j_numstr,”%d”,&job_number); |
found = 0; |
for(i=0;i<num_running_jobs;i++){ |
if(job_number == jr_ptr[i].job_number){ |
job_port = jr_ptr[i].port_number; |
strcpy(job_host,jr_ptr[i].job_submit_host); |
found = 1; |
break; |
} |
} |
if(!found){ |
printf(“Error, job number %d not in list\n”,job_number); |
free(jr_ptr); |
return 1; |
} |
}else{ |
if(api_application_index == MSC_NASTRAN){ |
leafname(nas_submit.nas_input_deck,job_name); |
}else if(api_application_index == HKS_ABAQUS){ |
leafname(aba_submit.aba_input_deck,job_name); |
}else if(api_application_index == MSC_MARC){ |
leafname(mar_submit.datfile_name,job_name); |
}else{ |
leafname(gen_submit[api_application_index-GENERAL].gen_input_deck,job_name); |
} |
strcpy(proj_name,ui_config.project_name); |
/* |
** search list for match and set job_number ... |
*/ |
job_number = -1; |
for(i=0;i<num_running_jobs;i++){ |
if(strcmp(jr_ptr[i].job_name,job_name) == 0){ |
if(strcmp(jr_ptr[i].job_proj,proj_name) == 0){ |
job_port = jr_ptr[i].port_number; |
strcpy(job_host,jr_ptr[i].job_submit_host); |
break; |
} |
} |
} |
if(job_number < 0){ |
printf(“Error, job name %s not in list\n”,job_name); |
free(jr_ptr); |
return 1; |
} |
} |
free(jr_ptr); |
#ifdef DEBUG |
fprintf(stderr,”posa\n”); |
#endif |
/* |
** get msg socket if needed ... |
*/ |
if( (msg_sock < 0) || (msg_sock_job != job_number) ){ |
#ifdef DEBUG |
fprintf(stderr,”posa1\n”); |
#endif |
msg_sock = api_mon_job_init(job_host,job_port,&msg_port,out_str); |
if(msg_sock < 0){ |
msg_port = -1; |
msg_sock_job = -1; |
printf(“%s”,out_str); |
return 1; |
}else{ |
msg_sock_job = job_number; |
} |
} |
#ifdef DEBUG |
fprintf(stderr,”posb\n”); |
#endif |
/* |
** get severity if not auto ... |
*/ |
sev_level = 3; |
if(auto_startup == 0){ |
#ifdef MSGPOP |
if(api_application_index == MSC_NASTRAN){ |
printf(“Enter message severity level >=: “); |
scanf(“%d”,&sev_level); |
printf(“\n”); |
} |
if(sev_level < 0) sev_level = 0; |
if(sev_level > 3) sev_level = 3; |
#endif |
} |
#ifdef DEBUG |
fprintf(stderr,”posc\n”); |
#endif |
/* |
** get monitor info ... |
*/ |
msg_ptr = api_mon_job_msgs(msg_sock,api_this_host,msg_port,sev_level,&num_msgs,out_str); |
if(num_msgs < 0){ |
printf(“%s”,out_str); |
return 2; |
} |
#ifdef DEBUG |
fprintf(stderr,”posd\n”); |
#endif |
if(msg_ptr == NULL){ |
printf(“%s”,out_str); |
return 3; |
}else if(num_msgs == 0){ |
printf(“\nNo messages at this time ...\n\n”); |
}else{ |
/* |
** mgs format is “severity@sevbuf@msgtxt” ... sevbuf is string “NULL” when severity=0 |
*/ |
for(i=0;i<num_msgs-1;i++){ |
printf(“ %s\n”,msg_ptr[i].msg); |
} |
free(msg_ptr); |
} |
#ifdef DEBUG |
fprintf(stderr,”pose\n”); |
#endif |
job_fs_list = api_mon_job_stats(msg_sock,api_this_host,msg_port,&cpu,&pct_cpu,&mem,&pct_mem, |
&dsk,&pct_dsk,&elapsed,&status,&num_fs,&srtn,out_str); |
if(srtn != 0){ |
printf(“%s”,out_str); |
}else{ |
printf(“job stats:\n”); |
if(status == JOB_SUBMITTED){ |
printf(“cpu=%d, %%cpu=%d, mem=%d, %%mem=%d, disk=%d, %%disk=%d, elapsed=%d, status=%s\n”, |
cpu,pct_cpu,mem,pct_mem,dsk,pct_dsk,elapsed,”submitted”); |
}else if(status == JOB_QUEUED){ |
printf(“cpu=%d, %%cpu=%d, mem=%d, %%mem=%d, disk=%d, %%disk=%d, elapsed=%d, status=%s\n”, |
cpu,pct_cpu,mem,pct_mem,dsk,pct_dsk,elapsed,”queued”); |
}else if(status == JOB_RUNNING){ |
printf(“cpu=%d, %%cpu=%d, mem=%d, %%mem=%d, disk=%d, %%disk=%d, elapsed=%d, status=%s\n”, |
cpu,pct_cpu,mem,pct_mem,dsk,pct_dsk,elapsed,”running”); |
}else{ |
printf(“cpu=%d, %%cpu=%d, mem=%d, %%mem=%d, disk=%d, %%disk=%d, elapsed=%d, status=%s\n”, |
cpu,pct_cpu,mem,pct_mem,dsk,pct_dsk,elapsed,”unknown”); |
} |
/* |
printf(“total num filesys = %d\n”,num_fs); |
for(i=0;i<num_fs;i++){ |
fprintf(stdout,” %s max=%d usage=%d\n”,job_fs_list[i].file_sys_name, |
job_fs_list[i].disk_max_size_mb, |
job_fs_list[i].disk_used_pct); |
} |
*/ |
printf(“\n”); |
if( (num_fs > 0) && (job_fs_list != NULL) ){ |
free(job_fs_list); |
} |
} |
#ifdef DEBUG |
fprintf(stderr,”posf\n”); |
#endif |
log_str = api_mon_job_mon(msg_sock,api_this_host,msg_port,out_str); |
if(log_str == NULL){ |
printf(“%s”,out_str); |
}else{ |
printf(“mon file contents:\n”); |
printf(“%s”,log_str); |
free(log_str); |
} |
file_list = api_mon_job_running_files_list(msg_sock,api_this_host,msg_port,&num_files,out_str); |
#ifdef DEBUG |
printf(“api_mon_job_running_files_list: num_files = %d\n”,num_files); |
#endif |
if(num_files < 0){ |
printf(“%s”,out_str); |
return 4; |
} |
if(num_files == 0) |
return 0; |
for(i=0;i<num_files;i++){ |
if(i == 0){ |
printf(“\ndownloadable files: (use q to quit)\n”); |
printf(“index job file size (kb)\n”); |
printf(“--------------------------------------------------\n”); |
} |
get_leaf_and_extention(file_list[i].filename,sfile); |
printf(“%-10d%-30s %d\n”,i+1,sfile,file_list[i].sizekb); |
} |
for(i=0;i<100;i++) |
j_numstr[i] = ‘\0’; |
printf(“\nEnter file index to download: “); |
scanf(“%s”,j_numstr); |
if( (j_numstr[0] == ‘q’) || (j_numstr[0] == ‘Q’) || (j_numstr[0] == ‘0’) ){ |
free(file_list); |
return 0; |
} |
sscanf(j_numstr,”%d”,&file_index); |
if(file_index == 0){ |
free(file_list); |
return 0; |
} |
check = 0; |
if(file_index < 0){ |
check = 1; |
file_index *= -1; |
} |
if(file_index > num_files){ |
printf(“invalid index\n”); |
free(file_list); |
return 5; |
} |
if(check){ |
srtn = api_download_file_check(job_number,file_list[file_index-1].filename,&sizekb); |
#ifdef DEBUG |
printf(“check returns %d\n”,srtn); |
#endif |
if(srtn == FILE_STILL_DOWNLOADING){ |
printf(“File %s is still being transfered\n”,file_list[file_index-1].filename); |
}else if(srtn == FILE_DOWNLOAD_COMPLETE){ |
printf(“File %s transfer complete !\n”,file_list[file_index-1].filename); |
} |
}else{ |
srtn = api_download_file_start(msg_sock,job_number,file_list[file_index-1].filename,out_str); |
if(srtn != 0){ |
printf(“File download (%s) start failed, error = %d (%s)”, |
file_list[file_index-1].filename,srtn,out_str); |
} |
} |
free(file_list); |
return 0; |
} |
/* ==================== */ |
int watch_que(int which) |
{ |
int i; |
int num_tasks; |
Que_List *ql_ptr = NULL; |
char out_str[2048]; |
char *log_str = NULL; |
Cpu_List *cpu_ptr = NULL; |
if(which == WATCHQUE_LOG){ |
log_str = api_mon_que_log(qmgr_host,qmgr_port,out_str); |
if(log_str == NULL){ |
printf(“%s”,out_str); |
return 1; |
} |
printf(“\n”); |
printf(“%s”,log_str); |
free(log_str); |
return 0; |
}else if(which == WATCHQUE_FULL){ |
ql_ptr = api_mon_que_full(qmgr_host,qmgr_port,&num_tasks,out_str); |
if( (num_tasks < 0) || (ql_ptr == NULL) ){ |
if(ql_ptr != NULL) |
free(ql_ptr); |
printf(“%s”,out_str); |
return 1; |
} |
if(num_tasks == 0){ |
printf(“\nNo active jobs found\n”); |
return 0; |
} |
printf(“\nQueue stats for all hosts/apps\n”); |
printf(“\n%-35s%-6s%-6s%-6s %s\n”, “hostname”,”run”,”que”,”max”,”status”); |
printf(“------------------------------------------------------------\n”); |
for(i=0;i<num_tasks;i++){ |
printf(“%-35s%-6d%-6d%-6d %s\n”, |
ql_ptr[i].host_name,ql_ptr[i].num_running,ql_ptr[i].num_waiting, |
ql_ptr[i].maxtsk,ql_ptr[i].stat_str); |
} |
free(ql_ptr); |
return 0; |
}else if(which == WATCHQUE_CPU){ |
cpu_ptr = api_mon_que_cpu(qmgr_host,qmgr_port,out_str); |
if(cpu_ptr == NULL){ |
printf(“%s”,out_str); |
return 1; |
} |
printf(“\nQueue load stats for all hosts/apps\n”); |
printf(“\n%-35s%-12s%-12s%-12s\n”, “hostname”,”%cpu util”,”avail mem”,”avail disk”); |
printf(“---------------------------------------------------------------------\n”); |
for(i=0;i<cfg->total_h;i++){ |
printf(“%-35s%-12d%-12d%-12d\n”, |
cpu_ptr[i].host_name,cpu_ptr[i].cpu_util,cpu_ptr[i].avail_mem,cpu_ptr[i].free_disk); |
} |
free(cpu_ptr); |
return 0; |
}else{ |
printf(“\nError, invalid selection\n”); |
return 1; |
} |
/*NOTREACHED*/ |
} |
/* ==================== */ |
int list_complete(void) |
{ |
int num_completed_jobs; |
Job_List *jc_ptr = NULL; |
Job_List *jc_ptr2 = NULL; |
char *mon_msgs = NULL; |
int num_files; |
FILE_LIST *fl_list = NULL; |
int srtn; |
int i; |
int job_number; |
char j_numstr[100]; |
int found; |
char out_str[2048]; |
char sfile[256]; |
char mon_file[256]; |
int cpu_secs, pct_cpu_avg, pct_cpu_max; |
int mem_kbts, pct_mem_avg, pct_mem_max; |
int dsk_mbts, pct_dsk_avg, pct_dsk_max; |
int elapsed,status; |
int num_fs; |
JOB_FS_LIST *job_fs_list; |
extern void get_leaf_and_extention(char *,char *); |
jc_ptr = api_get_completedjob_list(qmgr_host,qmgr_port,&num_completed_jobs,out_str); |
if(num_completed_jobs == 0){ |
printf(“\nNo completed jobs found\n”); |
return 0; |
} |
if( (num_completed_jobs < 0) || (jc_ptr == NULL) ){ |
printf(“%s”,out_str); |
if(jc_ptr != NULL) |
free(jc_ptr); |
return 1; |
} |
job_number = -1; |
if(auto_startup == 0){ |
/* |
** present list to user ... |
*/ |
printf(“\nCompleted jobs ....\n\n”); |
printf(“num jobname username subtime\n”); |
printf(“------------------------------------------------------\n”); |
for(i=0;i<num_completed_jobs;i++){ |
printf(“%-4d %-20s %-20s %-20s\n”,jc_ptr[i].job_number, |
jc_ptr[i].job_name,jc_ptr[i].job_user,jc_ptr[i].sub_time_str); |
} |
printf(“\nEnter job number: “); |
scanf(“%s”,j_numstr); |
if( (j_numstr[0] == ‘q’) || (j_numstr[0] == ‘Q’) || (j_numstr[0] == ‘0’) ){ |
free(jc_ptr); |
return 0; |
} |
sscanf(j_numstr,”%d”,&job_number); |
printf(“\n”); |
}else{ |
printf(“\nError, cant list completed jobs in batch mode.\n”); |
free(jc_ptr); |
return 1; |
} |
found = -1; |
for(i=0;i<num_completed_jobs;i++){ |
if(job_number == jc_ptr[i].job_number){ |
found = i; |
break; |
} |
} |
if(found < 0){ |
printf(“Error, job number %d not in list\n”,job_number); |
free(jc_ptr); |
return 1; |
} |
printf(“Job name: %s\n”,jc_ptr[found].job_name); |
printf(“Job user: %s\n”,jc_ptr[found].job_user); |
printf(“Job originating host: %s\n”,jc_ptr[found].job_submit_host); |
printf(“Job originating dir: %s\n”,jc_ptr[found].work_dir); |
printf(“Job AM hostname: %s\n”,jc_ptr[found].am_host_name); |
printf(“Job run host: %s\n”,jc_ptr[found].job_run_host); |
if(jc_ptr[found].jobstatus == JOB_SUCCESSFUL) |
printf(“Job complete status: success\n”); |
else if(jc_ptr[found].jobstatus == JOB_ABORTED) |
printf(“Job complete status: aborted\n”); |
else if(jc_ptr[found].jobstatus == JOB_FAILED) |
printf(“Job complete status: failed\n”); |
else |
printf(“Job complete status: unknown\n”); |
/* ------------ */ |
sprintf(mon_file,”%s/%s.mon”,jc_ptr[found].work_dir,jc_ptr[found].job_name); |
jc_ptr2 = api_com_job_gen(jc_ptr[found].job_submit_host,mon_file,out_str); |
if(jc_ptr2 == NULL){ |
printf(“%s”,out_str); |
free(jc_ptr); |
return 1; |
} |
/* check job number ... */ |
if(jc_ptr[found].job_number != jc_ptr2->job_number){ |
printf(“\nJob numbers do not match -\n”); |
printf( “assuming newer job with same .mon file is currently running\n”); |
printf( “so no additional job info is available\n”); |
free(jc_ptr); |
free(jc_ptr2); |
return 1; |
} |
printf(“\ngeneral info:\n”); |
printf(“num jobname jobuser amhost runhost subtime status\n”); |
printf(“-----------------------------------------------------------------------------------------------------------\n”); |
printf(“%-4d %-20s %-20s %-20s %-20s %-30s %-6d\n”,jc_ptr2->job_number, |
jc_ptr2->job_name, |
jc_ptr2->job_user, |
jc_ptr2->am_host_name, |
jc_ptr2->job_run_host, |
jc_ptr2->sub_time_str, |
jc_ptr2->jobstatus); |
/* ------------ */ |
job_fs_list = api_com_job_stats(jc_ptr[found].job_submit_host,mon_file, |
&cpu_secs,&pct_cpu_avg,&pct_cpu_max, |
&mem_kbts,&pct_mem_avg,&pct_mem_max, |
&dsk_mbts,&pct_dsk_avg,&pct_dsk_max, |
&elapsed,&status, |
&num_fs,&srtn,out_str); |
if(srtn < 0){ |
printf(“%s”,out_str); |
if( (num_fs > 0) && (job_fs_list != NULL) ){ |
free(job_fs_list); |
} |
free(jc_ptr); |
free(jc_ptr2); |
return 1; |
} |
printf(“\njob stats:\n”); |
printf(“cpu(sec)=%d, %%cpu(avg)=%d, %%cpu(max)=%d\n”,cpu_secs,pct_cpu_avg,pct_cpu_max); |
printf(“mem(kb) =%d, %%mem(avg)=%d, %%mem(max)=%d\n”,mem_kbts,pct_mem_avg,pct_mem_max); |
printf(“dsk(mb) =%d, %%dsk(avg)=%d, %%dsk(max)=%d\n”,dsk_mbts,pct_dsk_avg,pct_dsk_max); |
printf(“elapsed =%d, status=%d\n”,elapsed,status); |
/* |
printf(“total num filesys = %d\n”,num_fs); |
for(i=0;i<num_fs;i++){ |
fprintf(stdout,” %s max=%d usage=%d\n”,job_fs_list[i].file_sys_name, |
job_fs_list[i].disk_max_size_mb, |
job_fs_list[i].disk_used_pct); |
} |
printf(“\n”); |
*/ |
if( (num_fs > 0) && (job_fs_list != NULL) ){ |
free(job_fs_list); |
} |
/* ------------ */ |
mon_msgs = api_com_job_mon(jc_ptr[found].job_submit_host,mon_file,out_str); |
if(mon_msgs == NULL){ |
printf(“Error, unable to determine mon file msgs\n%s\n”,out_str); |
free(jc_ptr); |
free(jc_ptr2); |
return 1; |
} |
printf(“\nmon file contents:\n%s”,mon_msgs); |
free(mon_msgs); |
/* ------------ */ |
fl_list = api_com_job_received_files_list(jc_ptr[found].job_submit_host,mon_file,&num_files,out_str); |
#ifdef DEBUG |
printf(“api_com_job_received_files_list: num_files = %d\n”,num_files); |
#endif |
if(num_files < 0){ |
printf(“%s”,out_str); |
free(jc_ptr); |
free(jc_ptr2); |
return 4; |
} |
if(num_files > 0){ |
for(i=0;i<num_files;i++){ |
if(i == 0){ |
printf(“\nviewable files:\n”); |
printf(“index job file size (kb)\n”); |
printf(“--------------------------------------------------\n”); |
} |
get_leaf_and_extention(fl_list[i].filename,sfile); |
printf(“%-10d%-30s %d\n”,i+1,sfile,fl_list[i].sizekb); |
} |
free(fl_list); |
} |
/* ------------ */ |
free(jc_ptr); |
free(jc_ptr2); |
return 0; |
} |
/* ==================== */ |
int write_rcfile(void) |
{ |
int srtn; |
char out_str[2048]; |
if(has_cmd_rcf){ |
srtn = api_rcfile_write(cmd_rcf_file,out_str); |
if(srtn != 0){ |
printf(“%s”,out_str); |
return 1; |
}else{ |
printf(“\nSettings successfully written to rc file <%s>\n”,cmd_rcf_file); |
} |
}else{ |
printf(“\nWarning, no -rcf file specified so cannot write settings\n”); |
} |
return 0; |
} |
/* ==================== */ |
int admin_test(void) |
{ |
int status; |
char *test_str = NULL; |
char out_str[2048]; |
test_str = api_admin_test(orgpath,org_name,rmgr_port,&status,out_str); |
if(status != 0){ |
printf(“\nAdmin test returns %d, text = %s”,status,out_str); |
} |
if(test_str != NULL){ |
printf(“\n%s”,test_str); |
free(test_str); |
} |
return 0; |
} |
/* ==================== */ |
int reconfig_quemgr(void) |
{ |
int status; |
char *recfg_str = NULL; |
char out_str[2048]; |
/* |
** if user is Admin then ... |
*/ |
if(strcmp(api_user_name,cfg->ADMIN) != 0){ |
printf(“\nError, user <%s> is not the Admin <%s>, so cannot reconfig\n”, |
api_user_name,cfg->ADMIN); |
return 0; |
} |
recfg_str = api_reconfig_quemgr(qmgr_host,qmgr_port,&status,out_str); |
if(status != 0){ |
printf(“\nReconfig returns %d, text = %s”,status,out_str); |
} |
if(recfg_str != NULL){ |
printf(“\n%s”,recfg_str); |
free(recfg_str); |
} |
return 0; |
} |
/* ==================== */ |
void print_menu(void) |
{ |
printf(“\n”); |
printf(“Enter selection:\n”); |
printf(“ 1). submit a job\n”); |
printf(“ 2). abort a job\n”); |
printf(“ 3). monitor a job\n”); |
printf(“ 4). show QueMgr log file\n”); |
printf(“ 5). show QueMgr jobs/queues\n”); |
printf(“ 6). show QueMgr cpu/mem/disk\n”); |
printf(“ 7). list completed jobs\n”); |
printf(“ 8). write rcfile settings\n”); |
printf(“ 9). admin test\n”); |
printf(“ 10). admin reconfig QueMgr\n”); |
printf(“ 11). quit\n”); |
printf(“\n”); |
printf(“choice: “); |
return; |
} |
/* ==================== */ |
int get_response(void) |
{ |
char bogus[100]; |
int choice; |
(void)scanf(“%s”,bogus); |
if( (bogus[0] == ‘q’) || (bogus[0] == ‘Q’)) |
choice = QUIT; |
else |
choice = atoi(bogus); |
if( (choice < SUBMIT) || (choice > QUIT) ) |
return NOTVALID; |
return choice; |
} |
/* ==================== */ |
int doit(int choice) |
{ |
int srtn; |
if(choice == QUIT) |
return -1; |
#ifdef DEBUG |
printf(“choice made was: %d\n”,choice); |
#endif |
if(dont_connect){ |
if(choice != ADMINTEST){ |
printf(“\nError, only valid option with -nocon is Admin test\n”); |
return 0; |
} |
} |
if(choice == SUBMIT){ |
srtn = submit_job(); |
}else if(choice == ABORT){ |
srtn = abort_job(); |
}else if(choice == WATCHJOB){ |
srtn = watch_job(); |
}else if(choice == WATCHQUE_LOG){ |
srtn = watch_que(choice); |
}else if(choice == WATCHQUE_FULL){ |
srtn = watch_que(choice); |
}else if(choice == WATCHQUE_CPU){ |
srtn = watch_que(choice); |
}else if(choice == LISTCOMP){ |
srtn = list_complete(); |
}else if(choice == RCFILEWRITE){ |
srtn = write_rcfile(); |
}else if(choice == ADMINTEST){ |
srtn = admin_test(); |
}else if(choice == RECONFIG){ |
srtn = reconfig_quemgr(); |
}else{ |
srtn = 0; |
printf(“invalid choice ?\n”); |
} |
return srtn; |
} |
/* ==================== */ |
int main(int argc,char **argv) |
{ |
int i,j,k; |
int len1; |
int done; |
int not_first_real_app; |
int first_real_app_num; |
FILE *wp = NULL; |
int do_print; |
char env_file[256]; |
char first_real_app_str[128]; |
int srtn; |
int choice; |
int timout; |
int has_timout; |
char *ptr; |
char *qmgr_hoststr; |
char *qmgr_portstr; |
char *user_str; |
char home_dir[256]; |
char tmpstr[256]; |
char error_msg[256]; |
char tmp_host[256]; |
char out_str[2048]; |
#ifdef WINNT |
int err; |
WORD wVersionRequested; |
WSADATA wsaData; |
#endif |
struct hostent *host_entry; |
#ifdef WINNT |
extern BOOL console_event_func(DWORD ); |
#endif |
extern void get_home_dir(char *); |
/* ------------ */ |
/* |
** necessary windows startup socket code ... |
*/ |
#ifdef WINNT |
wVersionRequested = MAKEWORD( SOCKET_VERSION1, SOCKET_VERSION2 ); |
err = WSAStartup( wVersionRequested, &wsaData ); |
if(err != 0){ |
printf(“Error, WSAStartup failed\n”); |
return 1; |
} |
if( ( LOBYTE( wsaData.wVersion ) != 1 ) || |
( HIBYTE( wsaData.wVersion ) != 1 ) ){ |
WSACleanup(); |
printf(“Error, WSAStartup version incompatible\n”); |
return 1; |
} |
#endif |
/* ------------ */ |
#ifdef WINNT |
/* |
** console handler ... |
*/ |
(void)SetConsoleCtrlHandler((PHANDLER_ROUTINE)console_event_func, TRUE); |
#endif |
/* ------------ */ |
/* |
** get this hostname ... |
*/ |
gethostname(api_this_host,256); |
strcpy(tmp_host,api_this_host); |
host_entry = (struct hostent *)gethostbyname(tmp_host); |
if(host_entry != NULL) |
strcpy(api_this_host,host_entry->h_name); |
/* ------------ */ |
/* |
** get this username ... |
*/ |
user_str = api_getlogin(); |
strcpy(api_user_name,user_str); |
/* ------------ */ |
/* |
** assume binpath is from P3_HOME (or AM_HOME) ... |
** command-line will override ... |
*/ |
binpath[0] =’\0’; |
orgpath[0] =’\0’; |
#ifdef ULTIMA |
ptr = getenv(“AM_HOME”); |
#else |
ptr = getenv(“P3_HOME”); |
#endif |
if(ptr != NULL){ |
strcpy(binpath,ptr); |
} |
#ifdef DEBUG |
printf(“binpath = <%s>\n”,binpath); |
#endif |
/* ------------ */ |
/* |
** get QueMgr host, port, app name, index, p3home (or amhome), |
** and -rcf from command line args ... |
*/ |
lic_file[0] = ‘\0’; |
has_qmgr_host = 0; |
has_qmgr_port = 0; |
has_org = 0; |
has_orgpath = 0; |
has_timout = 0; |
timout = BLOCK_TIMEOUT; |
strcpy(org_name,”default”); |
ptr = getenv(“P3_ORG”); |
if(ptr != NULL){ |
strcpy(org_name,ptr); |
has_org = 1; |
} |
qmgr_host[0] = ‘\0’; |
qmgr_port = -1111; |
rmgr_port = RMTMGR_RESV_PORT; |
api_application_name[0] = ‘\0’; |
api_application_index = -1; |
sys_rcf_file[0] = ‘\0’; |
usr_rcf_file[0] = ‘\0’; |
has_cmd_rcf = 0; |
cmd_rcf_file[0] = ‘\0’; |
strcpy(usr_rcf_file,”.p3mgrrc”); |
get_home_dir(home_dir); |
if(home_dir[0] != ‘\0’){ |
sprintf(usr_rcf_file,”%s/.p3mgrrc”,home_dir); |
} |
#ifdef DEBUG |
fprintf(stderr,”usr_rcf_file = <%s>\n”,usr_rcf_file); |
#endif |
auto_startup = 0; |
do_print = 0; |
env_file[0] = ‘\0’; |
if(argc > 1){ |
i = 1; |
while(i < argc){ |
if((strcmp(argv[i],”-qmgrhost”) == 0) && (i < argc-1)){ |
has_qmgr_host = 1; |
strcpy(qmgr_host,argv[i+1]); |
i++; |
}else if((strcmp(argv[i],”-qmgrport”) == 0) && (i < argc-1)){ |
has_qmgr_port = 1; |
qmgr_port = atoi(argv[i+1]); |
i++; |
}else if((strcmp(argv[i],”-rmgrport”) == 0) && (i < argc-1)){ |
rmgr_port = atoi(argv[i+1]); |
i++; |
}else if((strcmp(argv[i],”-timeout”) == 0) && (i < argc-1)){ |
timout = atoi(argv[i+1]); |
has_timout = 1; |
i++; |
}else if((strcmp(argv[i],”-org”) == 0) && (i < argc-1)){ |
has_org = 1; |
strcpy(org_name,argv[i+1]); |
i++; |
}else if((strcmp(argv[i],”-orgpath”) == 0) && (i < argc-1)){ |
has_orgpath = 1; |
strcpy(orgpath,argv[i+1]); |
i++; |
}else if((strcmp(argv[i],”-auth”) == 0) && (i < argc-1)){ |
strcpy(lic_file,argv[i+1]); |
i++; |
}else if((strcmp(argv[i],”-app”) == 0) && (i < argc-1)){ |
strcpy(api_application_name,argv[i+1]); |
i++; |
}else if((strcmp(argv[i],”-rcf”) == 0) && (i < argc-1)){ |
has_cmd_rcf = 1; |
strcpy(cmd_rcf_file,argv[i+1]); |
i++; |
#ifdef ULTIMA |
}else if((strcmp(argv[i],”-amhome”) == 0) && (i < argc-1)){ |
#else |
}else if((strcmp(argv[i],”-p3home”) == 0) && (i < argc-1)){ |
#endif |
strcpy(binpath,argv[i+1]); |
i++; |
}else if((strcmp(argv[i],”-choice”) == 0) && (i < argc-1)){ |
auto_startup = atoi(argv[i+1]); |
i++; |
}else if(strcmp(argv[i],”-env”) == 0){ |
do_print = 1; |
}else if(strcmp(argv[i],”-envall”) == 0){ |
do_print = 2; |
}else if((strcmp(argv[i],”-envf”) == 0) && (i < argc-1)){ |
strcpy(env_file,argv[i+1]); |
do_print = 3; |
i++; |
}else if((strcmp(argv[i],”-envfall”) == 0) && (i < argc-1)){ |
strcpy(env_file,argv[i+1]); |
do_print = 4; |
i++; |
}else if(strcmp(argv[i],”-nocon”) == 0){ |
dont_connect = 1; |
}else if(strcmp(argv[i],”-version”) == 0){ |
fprintf(stderr,”version: %s\n”,GLOBAL_AM_VERSION); |
return 0; |
} |
i++; |
} |
} |
#ifdef DEBUG |
if(has_cmd_rcf) |
fprintf(stderr,”cmd_rcf_file = <%s>\n”,cmd_rcf_file); |
#endif |
/* ------------ */ |
/* |
** if binpath is still emtpy then its an error ... |
*/ |
#ifdef DEBUG |
printf(“binpath = <%s>\n”,binpath); |
#endif |
if(binpath[0] == ‘\0’){ |
#ifdef ULTIMA |
printf(“Error, AM_HOME env var not set\n”); |
#else |
printf(“Error, P3_HOME env var not set\n”); |
#endif |
return 1; |
} |
#ifdef LAPI |
if(lic_file[0] == ‘\0’){ |
ptr = getenv(“MSC_LICENSE_FILE”); |
if(ptr == NULL){ |
ptr = getenv(“LM_LICENSE_FILE”); |
} |
if(ptr == NULL){ |
printf(“Error, authorization file not set (MSC_LICENSE_FILE)\n”); |
return 1; |
} |
strcpy(lic_file,ptr); |
} |
#else |
strcpy(lic_file,”empty.noauth”); |
#endif |
/* |
** change back-slashes to forward slashes for binpath ... |
*/ |
i = 0; |
j = 0; |
k = (int)strlen(binpath); |
while(i < k){ |
#ifdef DEBUG |
fprintf(stderr,”txtmgr: i=%d, k=%d\n”,i,k); |
fprintf(stderr,”txtmgr: binpath[i] = %c\n”,binpath[i]); |
#endif |
if(binpath[i] == ‘\\’){ |
if(i < k-1){ |
if(binpath[i+1] == ‘\\’){ |
i++; |
} |
} |
tmpstr[j] = ‘/’; |
j++; |
}else{ |
tmpstr[j] = binpath[i]; |
j++; |
} |
#ifdef DEBUG |
fprintf(stderr,”HERE\n”); |
#endif |
i++; |
} |
tmpstr[j] = ‘\0’; |
strcpy(binpath,tmpstr); |
/* |
** make sure binpath has no slash at end ... |
*/ |
len1 = (int)strlen(binpath); |
if(len1 > 0){ |
if( (binpath[len1-1] == ‘/’) || (binpath[len1-1] == ‘\\’) ){ |
binpath[len1-1] = ‘\0’; |
} |
} |
/* |
** mck - add /p3manager_files (or analysis_manager) to binpath ... |
*/ |
#ifdef ULTIMA |
strcat(binpath,”/analysis_manager”); |
#else |
strcat(binpath,”/p3manager_files”); |
#endif |
/* ------------ */ |
/* |
** MCK MCK MCK - get orgpath - it WILL be the same as binpath |
** for the org.cfg file ... |
*/ |
if(has_orgpath == 0){ |
strcpy(orgpath,binpath); |
}else{ |
/* |
** change back-slashes to forward slashes for orgpath ... |
*/ |
i = 0; |
j = 0; |
k = (int)strlen(orgpath); |
while(i < k){ |
#ifdef DEBUG |
fprintf(stderr,”txtmgr: i=%d, k=%d\n”,i,k); |
fprintf(stderr,”txtmgr: orgpath[i] = %c\n”,orgpath[i]); |
#endif |
if(orgpath[i] == ‘\\’){ |
if(i < k-1){ |
if(orgpath[i+1] == ‘\\’){ |
i++; |
} |
} |
tmpstr[j] = ‘/’; |
j++; |
}else{ |
tmpstr[j] = orgpath[i]; |
j++; |
} |
#ifdef DEBUG |
fprintf(stderr,”HERE\n”); |
#endif |
i++; |
} |
tmpstr[j] = ‘\0’; |
strcpy(orgpath,tmpstr); |
/* |
** make sure orgpath has no slash at end ... |
*/ |
len1 = (int)strlen(orgpath); |
if(len1 > 0){ |
if( (orgpath[len1-1] == ‘/’) || (orgpath[len1-1] == ‘\\’) ){ |
orgpath[len1-1] = ‘\0’; |
} |
} |
/* |
** mck - add /p3manager_files (or analysis_manager) to orgpath ... |
*/ |
#ifdef ULTIMA |
strcat(orgpath,”/analysis_manager”); |
#else |
strcat(orgpath,”/p3manager_files”); |
#endif |
} |
/* ------------ */ |
sprintf(sys_rcf_file,”%s/%s/p3mgrrc”,orgpath,org_name); |
#ifdef DEBUG |
fprintf(stderr,”sys_rcf_file = <%s>\n”,sys_rcf_file); |
#endif |
/* ------------ */ |
/* |
** check env vars if not set on command-line |
*/ |
if(qmgr_host[0] == ‘\0’){ |
qmgr_hoststr = getenv(“P3_MASTER”); |
if(qmgr_hoststr != NULL){ |
strcpy(qmgr_host,qmgr_hoststr); |
has_qmgr_host = 1; |
} |
} |
if(qmgr_host[0] == ‘\0’){ |
qmgr_hoststr = getenv(“MSC_AM_QUEMGR”); |
if(qmgr_hoststr != NULL){ |
strcpy(qmgr_host,qmgr_hoststr); |
has_qmgr_host = 1; |
} |
} |
if(qmgr_host[0] == ‘\0’){ |
qmgr_hoststr = getenv(“QUEMGR_HOST”); |
if(qmgr_hoststr != NULL){ |
strcpy(qmgr_host,qmgr_hoststr); |
has_qmgr_host = 1; |
} |
} |
if(qmgr_port == -1111){ |
qmgr_portstr = getenv(“P3_PORT”); |
if(qmgr_portstr != NULL){ |
qmgr_port = atoi(qmgr_portstr); |
has_qmgr_port = 1; |
} |
} |
if(qmgr_port == -1111){ |
qmgr_portstr = getenv(“MSC_AM_QUEPORT”); |
if(qmgr_portstr != NULL){ |
qmgr_port = atoi(qmgr_portstr); |
has_qmgr_port = 1; |
} |
} |
if(qmgr_port == -1111){ |
qmgr_portstr = getenv(“QUEMGR_PORT”); |
if(qmgr_portstr != NULL){ |
qmgr_port = atoi(qmgr_portstr); |
has_qmgr_port = 1; |
} |
} |
/* ------------ */ |
#ifndef ULTIMA |
/* |
** checkout license ... |
*/ |
if( (do_print == 0) && (dont_connect == 0) ){ |
if((srtn = api_checkout_license(lic_file)) != 0){ |
printf(“Error, Authorization failure %d.”,srtn); |
if(global_auth_msg != NULL){ |
printf(“ Error msg = %s\n”,global_auth_msg); |
}else{ |
printf(“\n”); |
} |
return 1; |
} |
#ifdef DEBUG |
fprintf(stderr,”auth_file = %s\n”,lic_file); |
fprintf(stderr,”checkout_license returns %d\n”,srtn); |
#endif |
} |
#endif |
/* ------------ */ |
/* |
** init api ... |
*/ |
srtn = api_init(out_str); |
if(srtn != 0){ |
printf(“%s, error code = %d\n”,out_str,srtn); |
return 1; |
} |
/* ------------ */ |
/* |
** adjust global network timeout if desired ... |
*/ |
if(has_timout == 0){ |
timout = 30; |
} |
srtn = api_set_gbl_timeout(timout); |
if(srtn != 0){ |
printf(“Error, unable to set global timeout to %d secs\n”,timout); |
api_release_license(); |
#ifdef WINNT |
WSACleanup(); |
#endif |
return 1; |
} |
/* ------------ */ |
ptr = getenv(“AM_THIS_HOST”); |
if(ptr != NULL){ |
if( (strcmp(ptr,”no”) != 0) && (strcmp(ptr,”NO”) != 0) ){ |
api_use_this_host = 1; |
} |
} |
/* ------------ */ |
/* |
** read orgs if possible (org.cfg is in binpath) ... |
*/ |
org = NULL; |
num_orgs = 0; |
if( (has_qmgr_host == 0) && (has_qmgr_port == 0) ){ |
org = api_read_orgs(binpath,&num_orgs,&srtn); |
if(srtn != 0){ |
printf(“Warning, unable to read org.cfg file, code = %d\n”,srtn); |
/* |
* use defaults ... |
*/ |
strcpy(qmgr_host,api_this_host); |
qmgr_port = QUEMGR_RESV_PORT; |
}else{ |
if( (num_orgs > 0) && (org != NULL) ){ |
/* |
** figure out which quemgr to connect to ... |
*/ |
done = 0; |
for(i=0;i<num_orgs;i++){ |
if(strcmp(org[i].org_name,org_name) == 0){ |
strcpy(qmgr_host,org[i].host_name); |
qmgr_port = org[i].port; |
done = 1; |
break; |
} |
} |
if( (!done) && (has_org == 0) ){ |
/* |
** use first available ... |
*/ |
strcpy(qmgr_host,org[0].host_name); |
qmgr_port = org[0].port; |
done = 1; |
}else if( (!done) && (has_org == 1) ){ |
/* |
** no match found, assume this host and all ... |
*/ |
strcpy(qmgr_host,api_this_host); |
qmgr_port = QUEMGR_RESV_PORT; |
done = 1; |
} |
}else{ |
printf(“Warning, unable to read org.cfg file, no orgs found\n”); |
/* |
* use defaults ... |
*/ |
strcpy(qmgr_host,api_this_host); |
qmgr_port = QUEMGR_RESV_PORT; |
done = 1; |
} |
} |
} |
#ifdef DEBUG |
printf(“\n”); |
printf(“quemgr org = %s\n”,org_name); |
printf(“quemgr host = %s\n”,qmgr_host); |
printf(“quemgr port = %d\n”,qmgr_port); |
#endif |
/* ------------ */ |
if(! dont_connect){ |
/* |
** get config info ... |
*/ |
cfg = api_get_config(qmgr_host, qmgr_port, &srtn, error_msg); |
if(srtn != 0){ |
printf(“Error, msg = %s, error = %d\n”,error_msg,srtn); |
api_release_license(); |
#ifdef WINNT |
WSACleanup(); |
#endif |
return 1; |
} |
/* ------------ */ |
/* find first real app, just in case */ |
first_real_app_str[0] = ‘\0’; |
not_first_real_app = 1; |
first_real_app_num = 1; |
for(i=0;i<MAX_APPS;i++){ |
if(not_first_real_app){ |
#ifdef DEBUG |
fprintf(stderr,”cfg->progs[%d].app_name = <%s>\n”,i,cfg->progs[i].app_name); |
#endif |
if(cfg->progs[i].app_name[0] != ‘\0’){ |
not_first_real_app = 0; |
strcpy(first_real_app_str,cfg->progs[i].app_name); |
first_real_app_num = i + 1; |
break; |
} |
} |
} |
if(not_first_real_app){ |
/* error, no apps defined */ |
fprintf(stderr,”TxtMgr Error: No valid applications defined.\n”); |
return 1; |
} |
if(api_application_name[0] != ‘\0’){ |
for(i=0;i<MAX_APPS;i++){ |
if(strcmp(api_application_name,cfg->progs[i].app_name) == 0){ |
api_application_index = i + 1; |
break; |
} |
} |
} |
if(api_application_index <= 0){ |
/* app not specified - use first available */ |
strcpy(api_application_name,first_real_app_str); |
api_application_index = first_real_app_num; |
/* put up message about app not found, using first one */ |
fprintf(stderr,”\nTxtMgr Info: No application specified.\nUsing first available application of <%s> = %d\n”,api_application_name,api_application_index); |
} |
#ifdef DEBUG |
fprintf(stderr,”application_name = <%s>\n”,api_application_name); |
fprintf(stderr,”application_index = %d\n”,api_application_index); |
#endif |
/* ----------- */ |
/* DEBUGGING |
if(orgpath[0] != ‘\0’){ |
api_write_config(cfg,orgpath,”bogus”,&srtn,error_msg); |
if(srtn != 0){ |
printf(“Error, unable to write config files, msg = %s, code = %d\n”,error_msg,srtn); |
api_release_license(); |
#ifdef WINNT |
WSACleanup(); |
#endif |
return 0; |
} |
} |
DEBUGGING */ |
/* ----------- */ |
/* |
** initialize config values ... |
*/ |
api_init_uiconfig(cfg); |
/* |
** because we are txtmgr, reset job_mon_flag of ui_config |
** to be off by default ... |
*/ |
if(auto_startup == SUBMIT){ |
ui_config.job_mon_flag = 0; |
} |
#ifdef DEBUG_111 |
api_rcfile_print(1); |
#endif |
/* ----------- */ |
/* |
** override some settings if needed ... |
*/ |
(void)api_rcfile_read(sys_rcf_file,out_str); |
(void)api_rcfile_read(usr_rcf_file,out_str); |
if(has_cmd_rcf){ |
srtn = api_rcfile_read(cmd_rcf_file,out_str); |
if(srtn != 0){ |
printf(“%s\n”,out_str); |
} |
} |
#ifdef DEBUG_111 |
api_rcfile_print(1); |
#endif |
/* ----------- */ |
/* |
** if just a print env then do it and stop ... |
*/ |
if(do_print){ |
if(do_print >= 3){ |
if(env_file[0] != ‘\0’){ |
wp = fopen(env_file,”wb”); |
if(wp != NULL){ |
api_rcfile_write2(wp,(do_print-3)); |
fclose(wp); |
} |
} |
}else{ |
api_rcfile_print(do_print-1); |
} |
api_release_license(); |
#ifdef WINNT |
WSACleanup(); |
#endif |
return 0; |
} |
} /* ! dont_connect ... */ |
/* ----------- */ |
if(auto_startup > 0){ |
srtn = doit(auto_startup); |
}else{ |
/* |
** query for selection and do work ... |
*/ |
while(1){ |
print_menu(); |
choice = get_response(); |
srtn = doit(choice); |
#ifdef DEBUG |
printf(“doit(%d) returns %d\n”,choice,srtn); |
#endif |
if(srtn < 0) |
break; |
} |
srtn = 0; |
} |
api_release_license(); |
#ifdef WINNT |
WSACleanup(); |
#endif |
return srtn; |
} |