int gw_acct_join_search_by_host_and_user(const char * hostname, const char * username, gw_acct_t ***accts, int * nrecs, time_t from_time) { gw_acct_t * tmp; int rc; *nrecs = 0; *accts = NULL; // This sum is for the combination of user+@+host int user_at_host_size=GW_MSG_STRING_USER_AT_HOST; char user_at_host[user_at_host_size]; tmp = (gw_acct_t *) malloc(sizeof(gw_acct_t)); rc = gw_acct_join_search(hostname, username, tmp, from_time); if ( rc == 0 ) { sprintf(user_at_host,"%s@%s",username,hostname); gw_rm_copy_str_user_at_host(user_at_host,tmp->name); /* This always is going to be 1 (username @ hostname)*/ *nrecs = *nrecs + 1; *accts = realloc(*accts, *nrecs *sizeof(gw_acct_t *)); (*accts)[*nrecs-1] = tmp; } else free(tmp); return 0; }
void gw_scheduler_update_usage_host(gw_scheduler_t * sched) { int i,j; gw_acct_t acct; int rc; time_t from_time; gw_sch_user_host_t * host; rc = gw_acct_db_open(GW_FALSE); if ( rc != 0 ) { gw_scheduler_print('E',"Opening accounting database when updating host usage\n"); return; } from_time = time(NULL) - (86400 * sched->sch_conf.ug_window); for (i=0;i<sched->num_users;i++) { for (j=0;j<sched->num_hosts;j++) { host = &(sched->users[i].hosts[j]); rc = gw_acct_join_search(sched->hosts[host->ha_id].name, sched->users[i].name, &acct, from_time); if (( rc == 0 )&& (acct.tot >= 1)) { host->avrg_execution = (float) acct.execution / (float) acct.tot; host->avrg_suspension = (float) acct.suspension/ (float) acct.tot; host->avrg_transfer = (float) acct.transfer / (float) acct.tot; } } } gw_acct_db_close(); return; }
void gw_scheduler_add_user(gw_scheduler_t * sched, int uid, int ajobs, int rjobs, char * name) { int i,j; #ifdef HAVE_LIBDB gw_acct_t acct; int rc; time_t from_time; gw_boolean_t usedb; #endif /* -------------------------------- */ /* Look for this user in the list */ /* -------------------------------- */ for (i=0;i<sched->num_users;i++) if ( sched->users[i].uid == uid ) { #ifdef GWSCHEDDEBUG gw_scheduler_print('D',"Updating user %i AJOBS:%i, RJOBS:%i\n", uid,ajobs,rjobs); #endif sched->users[i].active_jobs = ajobs; sched->users[i].running_jobs = rjobs; return; } /* ----------------------------- */ /* Add a new entry to the list */ /* ----------------------------- */ i = sched->num_users; sched->num_users = sched->num_users + 1; sched->users = realloc((void *)sched->users, (sched->num_users) * sizeof(gw_sch_user_t)); strncpy(sched->users[i].name, name, GW_MSG_STRING_SHORT-1); sched->users[i].uid = uid; sched->users[i].active_jobs = ajobs; sched->users[i].running_jobs = rjobs; sched->users[i].dispatched = 0; /* ---------------------------------- */ /* From the scheduler configuration */ /* ---------------------------------- */ sched->users[i].share = 0; gw_scheduler_print('I',"User (%i) %s added, building host list...\n" ,uid,name); /* --------------------------------------- */ /* Add the list of hosts for this user */ /* --------------------------------------- */ if (sched->num_hosts == 0) { sched->users[i].hosts = NULL; return; } sched->users[i].hosts = (gw_sch_user_host_t *) malloc (sched->num_hosts * sizeof (gw_sch_user_host_t)); #ifdef HAVE_LIBDB rc = gw_acct_db_open(GW_FALSE); if ( rc != 0 ) usedb = GW_FALSE; else usedb = GW_TRUE; #endif for (j=0; j<sched->num_hosts; j++) { sched->users[i].hosts[j].ha_id = j; sched->users[i].hosts[j].hid = sched->hosts[j].hid; sched->users[i].hosts[j].banned = 0; sched->users[i].hosts[j].last_banned = 0; #ifdef HAVE_LIBDB if (usedb == GW_TRUE) { from_time = time(NULL) - 24*60*60*GW_SCHED_DMEM; rc = gw_acct_join_search(sched->hosts[j].name, sched->users[i].name, &acct, from_time); } else rc = -1; if (rc == 0) { sched->users[i].hosts[j].avrg_execution = (float) acct.execution / (float) acct.tot; sched->users[i].hosts[j].avrg_suspension = (float) acct.suspension/ (float) acct.tot; sched->users[i].hosts[j].avrg_transfer = (float) acct.transfer / (float) acct.tot; } else { sched->users[i].hosts[j].avrg_execution = 0; sched->users[i].hosts[j].avrg_suspension = 0; sched->users[i].hosts[j].avrg_transfer = 0; } #else sched->users[i].hosts[j].avrg_execution = 0; sched->users[i].hosts[j].avrg_suspension = 0; sched->users[i].hosts[j].avrg_transfer = 0; #endif gw_scheduler_print('I',"\t%-30s: avg_xfr = %8.2f avg_que = %8.2f avg_exe = %8.2f\n", sched->hosts[j].name, sched->users[i].hosts[j].avrg_transfer, sched->users[i].hosts[j].avrg_suspension, sched->users[i].hosts[j].avrg_execution); } #ifdef HAVE_LIBDB if (usedb == GW_TRUE) gw_acct_db_close(); #endif }
int gw_acct_join_search_by_host(const char * hostname, gw_acct_t *** accts, int * nrecs, time_t from_time) { char **users = NULL; char username[GW_MSG_STRING_SHORT]; DBT hkey; DBT pdata; DBC *cp; gw_acct_t * tmp; int i; int rc; int nuser = 0; /* Get the users from the user database */ rc = gw_acct_db.uinx_db->cursor(gw_acct_db.uinx_db, NULL, &(gw_acct_db.ucursor), 0); if ( rc != 0 ) { *accts = NULL; *nrecs = 0; return -1; } cp = gw_acct_db.ucursor; /* --- Iterate over the host database to get all hosts ------ */ memset(&hkey,0,sizeof(DBT)); hkey.data = (void *) username; hkey.ulen = sizeof(char) * GW_MSG_STRING_SHORT; hkey.flags = DB_DBT_USERMEM; memset(&pdata,0,sizeof(DBT)); while ((rc = cp->c_get(cp,&hkey,&pdata,DB_NEXT_NODUP))==0) { nuser = nuser +1; users = realloc((users),nuser*sizeof(char *)); users[nuser-1] = malloc(sizeof(char) * GW_MSG_STRING_SHORT); gw_rm_copy_str_short(hkey.data,users[nuser-1]); } if ((rc != DB_NOTFOUND) || (users == NULL)) { cp->c_close(cp); gw_acct_db.ucursor = NULL; if (users != NULL ) { for (i=0;i<nuser;i++) free(users[i]); free(users); } *accts = NULL; *nrecs = 0; return -1; } *nrecs = 0; *accts = NULL; cp->c_close(cp); gw_acct_db.ucursor = NULL; for ( i=0;i<nuser;i++) { tmp = (gw_acct_t *) malloc(sizeof(gw_acct_t)); rc = gw_acct_join_search(hostname, users[i], tmp, from_time); if ( rc == 0 ) { gw_rm_copy_str_short(users[i],tmp->name); *nrecs = *nrecs + 1; *accts = realloc(*accts, *nrecs *sizeof(gw_acct_t *)); (*accts)[*nrecs-1] = tmp; } else free(tmp); } if (users != NULL ) { for (i=0;i<nuser;i++) free(users[i]); free(users); } return 0; }
void gw_scheduler_add_host(gw_scheduler_t * sched, int hid, int uslots, int rjobs, char * hostname) { int i,j; #ifdef HAVE_LIBDB gw_acct_t acct; int rc; time_t from_time; gw_boolean_t usedb; #endif /* -------------------------------- */ /* Look for this host in the list */ /* -------------------------------- */ for (i=0;i<sched->num_hosts;i++) if (sched->hosts[i].hid == hid) { #ifdef GWSCHEDDEBUG gw_scheduler_print('D',"Updating Host %i USLOTS:%i, RJOBS:%i\n", hid,uslots,rjobs); #endif sched->hosts[i].used_slots = uslots; sched->hosts[i].running_jobs = rjobs; return; } /* ----------------------------- */ /* Add a new entry to the list */ /* ----------------------------- */ i = sched->num_hosts; sched->num_hosts = sched->num_hosts + 1; sched->hosts = realloc((void *)sched->hosts, (sched->num_hosts) * sizeof(gw_sch_host_t)); sched->hosts[i].hid = hid; sched->hosts[i].running_jobs = rjobs; sched->hosts[i].used_slots = uslots; sched->hosts[i].dispatched = 0; strncpy(sched->hosts[i].name, hostname, GW_MSG_STRING_HOST-1); #ifdef GWSCHEDDEBUG gw_scheduler_print('D',"Host %s (%i) added, updating user information:\n", hostname,hid,uslots,rjobs); #endif /* --------------------------------------- */ /* Add a new entry to the user host list */ /* --------------------------------------- */ #ifdef HAVE_LIBDB /* ------------------------------------ */ /* Get usage information from database */ /* ------------------------------------ */ from_time = time(NULL) - 86400 * sched->sch_conf.ug_window; rc = gw_acct_db_open(GW_FALSE); if ( rc != 0 ) usedb = GW_FALSE; else usedb = GW_TRUE; #endif for (j=0;j<sched->num_users;j++) { sched->users[j].hosts = realloc((void *) sched->users[j].hosts, (sched->num_hosts)*sizeof(gw_sch_user_host_t)); sched->users[j].hosts[i].ha_id = i; sched->users[j].hosts[i].hid = hid; sched->users[j].hosts[i].banned = 0; sched->users[j].hosts[i].last_banned = 0; #ifdef HAVE_LIBDB if (usedb == GW_TRUE) { rc = gw_acct_join_search(hostname, sched->users[j].name, &acct, from_time); } else rc = -1; if ((rc == 0) && (acct.tot >= 1)) { sched->users[j].hosts[i].avrg_execution = (float) acct.execution / (float) acct.tot; sched->users[j].hosts[i].avrg_suspension = (float) acct.suspension/ (float) acct.tot; sched->users[j].hosts[i].avrg_transfer = (float) acct.transfer / (float) acct.tot; } else { sched->users[j].hosts[i].avrg_execution = 0; sched->users[j].hosts[i].avrg_suspension = 0; sched->users[j].hosts[i].avrg_transfer = 0; } #else sched->users[j].hosts[i].avrg_execution = 0; sched->users[j].hosts[i].avrg_suspension = 0; sched->users[j].hosts[i].avrg_transfer = 0; #endif sched->users[j].hosts[i].last_execution = 0; sched->users[j].hosts[i].last_suspension = 0; sched->users[j].hosts[i].last_transfer = 0; #ifdef GWSCHEDDEBUG gw_scheduler_print('D',"\t%-15s (%-15s): avg_xfr = %8.2f avg_que = %8.2f avg_exe = %8.2f\n", hostname,sched->users[j].name, sched->users[j].hosts[i].avrg_transfer, sched->users[j].hosts[i].avrg_suspension, sched->users[j].hosts[i].avrg_execution); #endif } #ifdef HAVE_LIBDB gw_acct_db_close(); #endif }