static char * getLSFAdmin(void) { static char admin[MAXLSFNAMELEN]; static char fname[] = "getLSFAdmin"; char *mycluster; struct clusterInfo *clusterInfo; struct passwd *pw; char *lsfUserName; if (admin[0] != '\0') return admin; if ((mycluster = ls_getclustername()) == NULL) { ls_syslog(LOG_ERR, I18N_FUNC_FAIL_MM, fname, "ls_getclustername"); return NULL; } if ((clusterInfo = ls_clusterinfo(NULL, NULL, NULL, 0, 0)) == NULL) { ls_syslog(LOG_ERR, I18N_FUNC_FAIL_MM, fname, "ls_clusterinfo"); return NULL; } lsfUserName = (clusterInfo->nAdmins == 0 ? clusterInfo->managerName : clusterInfo->admins[0]); if ((pw = getpwnam(lsfUserName)) == NULL) { ls_syslog(LOG_ERR, I18N_FUNC_S_FAIL_M, fname, "getpwnam", lsfUserName); return NULL; } strcpy(admin, lsfUserName); return admin; }
int ls_isclustername (char *name) { char *clname; clname = ls_getclustername (); if (clname && strcmp (clname, name) == 0) return (1); return (0); }
int main (int argc, char **argv) { char *name; int cc; if (ls_initdebug (argv[0]) < 0) { ls_perror ("ls_initdebug"); return -1; } while ((cc = getopt (argc, argv, "hV")) != EOF) { switch (cc) { case 'h': usage (argv[0]); return 0; case 'V': fputs (_LS_VERSION_, stderr); return 0; default: usage (argv[0]); return -1; } } puts (_LS_VERSION_); TIMEIT (0, (name = ls_getclustername ()), "ls_getclustername"); if (name == NULL) { ls_perror ("ls_getclustername()"); return -1; } printf ("My cluster name is %s\n", name); TIMEIT (0, (name = ls_getmastername ()), "ls_getmastername"); if (name == NULL) { ls_perror ("ls_getmastername()"); return -1; } printf ("My master name is %s\n", name); return 0; }
/* Get batch nodes informations ------------------------------- You don't have to create all bridge_batch_node_t structure, you just have to set parameters according to the following rules : if batch_nodes_batch_ids equals NULL or "" or "all", get all current nodes, otherwise get only batch_nodes by given batch_id if p_batch_nodes==NULL : - set total batch nodes number in p_batch_nodes_nb - allocate a bridge_batch_node_t** containing *p_batch_nodes_nb bridge_batch_node_t* - fill the *p_batch_nodes_nb bridge_batch_node_t else : - get max batch nodes number in *p_batch_nodes_nb - fill the *p_batch_nodes_nb bridge_batch_node_t if possible - update value of *p_batch_nodes_nb according to Returns : 0 on success 1 on succes, but p_nodes_nb contains a new valid value for nodes_nb -1 on error On succes, you 'll have to clean all nodes with bridge_rmi_clean_node(...) before freeing *p_nodes */ int get_batch_nodes(bridge_batch_manager_t* p_batch_manager, bridge_batch_node_t** p_p_batch_nodes, int* p_batch_nodes_nb, char* batch_node_name) { int fstatus=-1; int status; int i,j,k; char buffer[256]; char* node_array[1]; char* reason; struct hostInfoEnt* p_nodeInfo=NULL; struct groupInfoEnt* p_grpInfo=NULL; int node_nb=0; int grp_nb=0; int stored_node_nb=0; char* node_grouplist_item; size_t node_grouplist_default_length=128; size_t node_grouplist_length; node_array[0]=NULL; /* * Check that batch system is running or exit with error 1 */ if(!ls_getclustername()) { DEBUG3_LOGGER("unable to get cluster informations\n"); return 1; } p_nodeInfo=lsb_hostinfo(NULL,&node_nb); p_grpInfo=lsb_hostgrpinfo(NULL,&grp_nb,GRP_ALL); if(p_nodeInfo==NULL) DEBUG3_LOGGER("unable to get nodes informations\n"); else { if(*p_p_batch_nodes!=NULL) { if(*p_batch_nodes_nb<node_nb) node_nb=*p_batch_nodes_nb; } else { *p_p_batch_nodes=(bridge_batch_node_t*)malloc(node_nb*(sizeof(bridge_batch_node_t)+1)); if(*p_p_batch_nodes==NULL) { *p_batch_nodes_nb=0; node_nb=*p_batch_nodes_nb; } else { *p_batch_nodes_nb=node_nb; } } stored_node_nb=0; for(i=0; i<node_nb; i++) { if(batch_node_name!=NULL) { if(strcmp(batch_node_name,p_nodeInfo[i].host)!=0) continue; } init_batch_node(p_batch_manager,(*p_p_batch_nodes)+stored_node_nb); /* Node Name */ (*p_p_batch_nodes)[stored_node_nb].name=strdup(p_nodeInfo[i].host); /* Node description */ (*p_p_batch_nodes)[stored_node_nb].description=strdup("Batch node"); /* Node groups */ node_grouplist_length=node_grouplist_default_length; (*p_p_batch_nodes)[stored_node_nb].grouplist=(char*)malloc(node_grouplist_length); if((*p_p_batch_nodes)[stored_node_nb].grouplist!=NULL) { (*p_p_batch_nodes)[stored_node_nb].grouplist[0]='\0'; for(k=0; k<grp_nb; k++) { node_grouplist_item=strstr(p_grpInfo[k].memberList,(*p_p_batch_nodes)[stored_node_nb].name); if(node_grouplist_item!=NULL) if(*(node_grouplist_item+strlen((*p_p_batch_nodes)[stored_node_nb].name)) == '\0' || *(node_grouplist_item+strlen((*p_p_batch_nodes)[stored_node_nb].name)) == ' ') { bridge_common_string_appends_and_extends(&((*p_p_batch_nodes)[stored_node_nb].grouplist), &node_grouplist_length,128,p_grpInfo[k].group," "); } } } if(strlen((*p_p_batch_nodes)[stored_node_nb].grouplist)==0) { free((*p_p_batch_nodes)[stored_node_nb].grouplist); (*p_p_batch_nodes)[stored_node_nb].grouplist=NULL; } /* Node state */ if(p_nodeInfo[i].hStatus==HOST_STAT_OK || (p_nodeInfo[i].hStatus & HOST_STAT_LOCKED) ) { (*p_p_batch_nodes)[stored_node_nb].state=BRIDGE_BATCH_NODE_STATE_OPENED; } else if( (p_nodeInfo[i].hStatus & HOST_STAT_DISABLED) || (p_nodeInfo[i].hStatus & HOST_STAT_WIND) ) { (*p_p_batch_nodes)[stored_node_nb].state=BRIDGE_BATCH_NODE_STATE_CLOSED; } else if( (p_nodeInfo[i].hStatus & HOST_STAT_BUSY) || (p_nodeInfo[i].hStatus & HOST_STAT_FULL) ) { (*p_p_batch_nodes)[stored_node_nb].state=BRIDGE_BATCH_NODE_STATE_BUSY; } else if( (p_nodeInfo[i].hStatus & HOST_STAT_UNAVAIL) || (p_nodeInfo[i].hStatus & HOST_STAT_NO_LIM) ) { (*p_p_batch_nodes)[stored_node_nb].state=BRIDGE_BATCH_NODE_STATE_UNAVAILABLE; } else if( (p_nodeInfo[i].hStatus & HOST_STAT_UNREACH)) { (*p_p_batch_nodes)[stored_node_nb].state=BRIDGE_BATCH_NODE_STATE_UNREACHABLE; } else if( (p_nodeInfo[i].hStatus & HOST_STAT_UNLICENSED)) { (*p_p_batch_nodes)[stored_node_nb].state=BRIDGE_BATCH_NODE_STATE_UNLICENSED; } else { (*p_p_batch_nodes)[stored_node_nb].state=BRIDGE_BATCH_NODE_STATE_UNKNOWN; } /* Get informations only if host is open or closed or busy */ if((*p_p_batch_nodes)[stored_node_nb].state == BRIDGE_BATCH_NODE_STATE_OPENED || (*p_p_batch_nodes)[stored_node_nb].state == BRIDGE_BATCH_NODE_STATE_CLOSED || (*p_p_batch_nodes)[stored_node_nb].state == BRIDGE_BATCH_NODE_STATE_BUSY) { /* running jobs number */ (*p_p_batch_nodes)[stored_node_nb].running_jobs_nb=p_nodeInfo[i].numRUN; /* user suspended jobs number */ (*p_p_batch_nodes)[stored_node_nb].usersuspended_jobs_nb=p_nodeInfo[i].numUSUSP; /* system suspended jobs number */ (*p_p_batch_nodes)[stored_node_nb].syssuspended_jobs_nb=p_nodeInfo[i].numSSUSP; /* total jobs number */ (*p_p_batch_nodes)[stored_node_nb].jobs_nb=p_nodeInfo[i].numJobs; /* max jobs number */ (*p_p_batch_nodes)[stored_node_nb].jobs_nb_limit=(p_nodeInfo[i].maxJobs==INT_MAX)?NO_LIMIT:p_nodeInfo[i].maxJobs; /* max jobs number per user */ (*p_p_batch_nodes)[stored_node_nb].perUser_jobs_nb_limit=(p_nodeInfo[i].userJobLimit==INT_MAX)?NO_LIMIT:p_nodeInfo[i].userJobLimit; /* free swap space (in Mo) */ (*p_p_batch_nodes)[stored_node_nb].free_swap=p_nodeInfo[i].realLoad[SWP]; /* free tmp space (in Mo) */ (*p_p_batch_nodes)[stored_node_nb].free_tmp=p_nodeInfo[i].realLoad[TMP]; /* free mem space (in Mo) */ (*p_p_batch_nodes)[stored_node_nb].free_mem=p_nodeInfo[i].realLoad[MEM]; /* one minute cpu load */ (*p_p_batch_nodes)[stored_node_nb].one_min_cpu_load=p_nodeInfo[i].realLoad[R1M]*100; } stored_node_nb++; } fstatus=0; } if(stored_node_nb<node_nb) { *p_p_batch_nodes=(bridge_batch_node_t*)realloc(*p_p_batch_nodes,stored_node_nb*(sizeof(bridge_batch_node_t)+1)); if(*p_p_batch_nodes==NULL) *p_batch_nodes_nb=0; else *p_batch_nodes_nb=stored_node_nb; } return fstatus; }