Пример #1
0
void gw_rm_job_match(int client_socket, int job_id)
{
    int            i,j,rc;
    int            number_of_queues;
    gw_host_t *    host;
    gw_job_t *     job;
    gw_msg_match_t msg;
    gw_boolean_t   match;
    int            length;
    int            gwfreenc;
    
    msg.msg_type = GW_MSG_JOB_MATCH;
    length       = sizeof(gw_msg_match_t);
    
    job = gw_job_pool_get(job_id, GW_TRUE);
      
    if ( job == NULL )
    {
        msg.msg_type = GW_MSG_END_JOB;
        msg.rc       = GW_RC_FAILED_BAD_JOB_ID;
        msg.job_id   = job_id;
        rc           = send(client_socket,(void *) &msg,length,0);
        return;
    }
    
    for (i=0;i<gw_conf.number_of_hosts;i++)
    {
        host = gw_host_pool_get_host (i, GW_TRUE);
        
        if ( host != NULL )
        {
			number_of_queues   = 0;
			msg.rc             = GW_RC_SUCCESS;
			msg.matched        = GW_FALSE;
			msg.host_id        = i;
			msg.job_id         = job_id;
			msg.fixed_priority = host->fixed_priority;
			msg.running_jobs   = host->running_jobs;
			
			gw_rm_copy_str_host(host->hostname, msg.hostname);
              
            for (j=0;j<GW_HOST_MAX_QUEUES;j++)
            {
                if (host->queue_name[j]!=NULL)
                {
                    gw_rm_copy_str_short(host->queue_name[j],
                        msg.queue_name[number_of_queues]);
                        
                    match = gw_host_check_reqs(host, j, job->template.requirements);
                    
                    if (match == GW_TRUE)
                    {
                        msg.matched = GW_TRUE;
                        msg.match[number_of_queues] = 1;
                        msg.rank [number_of_queues] = gw_host_compute_rank(host,j,job->template.rank);
Пример #2
0
static void gw_acct_db_write_record(gw_job_t *job, gw_history_t *record, int number)
{
	DBT            key;
	DBT            data;	
    gw_acct_key_t  gw_key;
	gw_acct_data_t gw_data;
	
	u_int32_t      flags;
	
	int rc,i;
	
	if ((job == NULL) || ( record == NULL ))
		return;

	/* ----- Set the key ------ */
			
	gw_key.start_time = job->start_time;
	gw_key.job_id     = job->id;	
	gw_key.restarted  = number;	
	
	memset(&key,0,sizeof(DBT));
		
	key.data = &gw_key;
	key.size = sizeof(gw_acct_key_t);

	/* ----- Set the data ------ */
		
	gw_data.rank   = record->rank;
	gw_data.reason = record->reason;	
	
	gw_rm_copy_str_short(job->owner,gw_data.username);
	gw_rm_copy_str_host(record->host->hostname,gw_data.hostname);
	
	for (i=0;i<GW_HISTORY_MAX_STATS;i++)
		gw_data.stats[i] = record->stats[i];
		
	memset(&data,0,sizeof(DBT));
	
	data.data = &gw_data;
	data.size = sizeof(gw_acct_data_t);

	/* ----- Write it ------ */
	
    flags = DB_NOOVERWRITE;
    
	rc = gw_acct_db.acct_db->put(gw_acct_db.acct_db,
                                 NULL,
                                 &key,
                                 &data,
                                 flags);
                                 
    if (rc == DB_KEYEXIST)
		gw_log_print("DB",'W',"Duplicate entry in database for job id=%i, stime=%i.\n",
		             job->id,job->start_time);		    	
}
Пример #3
0
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;
}
Пример #4
0
void gw_rm_host_to_msg (gw_host_t *host, gw_msg_host_t *msg)
{
	int i;
	int number_of_queues;
	int number_of_int_vars;
	int number_of_str_vars;
	
	msg->msg_type = GW_MSG_HOST_STATUS;
	msg->rc       = GW_RC_SUCCESS;

	gw_rm_copy_str_short(host->em_mad,msg->em_mad);
	gw_rm_copy_str_short(host->tm_mad,msg->tm_mad);
	gw_rm_copy_str_short(host->im_mad,msg->im_mad);

	msg->used_slots   = host->used_slots;
	msg->running_jobs = host->running_jobs;
	
	msg->host_id        = host->host_id;
	msg->fixed_priority = host->fixed_priority;
	
	gw_rm_copy_str_host(host->hostname,msg->hostname);
	gw_rm_copy_str_short(host->arch,msg->arch);
	gw_rm_copy_str_short(host->os_name,msg->os_name);
	gw_rm_copy_str_short(host->os_version,msg->os_version);	
	gw_rm_copy_str_short(host->cpu_model,msg->cpu_model);
	
	msg->cpu_mhz  = host->cpu_mhz;
	msg->cpu_free = host->cpu_free;
	msg->cpu_smp  = host->cpu_smp;
	msg->nodecount= host->nodecount;

    msg->size_mem_mb = host->size_mem_mb;
    msg->free_mem_mb = host->free_mem_mb;
    msg->size_disk_mb= host->size_disk_mb;
    msg->free_disk_mb= host->free_disk_mb;

	gw_rm_copy_str_short(host->fork_name,msg->fork_name);
	gw_rm_copy_str_short(host->lrms_name,msg->lrms_name);
	gw_rm_copy_str_short(host->lrms_type,msg->lrms_type);
	
	number_of_queues   = 0;
	number_of_int_vars = 0;
	number_of_str_vars = 0;
	
	for (i=0;i<GW_HOST_MAX_QUEUES;i++)
		if (host->queue_name[i]!=NULL)
		{
			msg->queue_nodecount[number_of_queues]      = 
				host->queue_nodecount[i];
			msg->queue_freenodecount[number_of_queues]  = 
				host->queue_freenodecount[i];
			msg->queue_maxtime[number_of_queues]        = 
				host->queue_maxtime[i];
			msg->queue_maxcputime[number_of_queues]     = 
				host->queue_maxcputime[i];
			msg->queue_maxcount[number_of_queues]       = 
				host->queue_maxcount[i];
			msg->queue_maxrunningjobs[number_of_queues] = 
				host->queue_maxrunningjobs[i];
			msg->queue_maxjobsinqueue[number_of_queues] = 
				host->queue_maxjobsinqueue[i];

			gw_rm_copy_str_short(host->queue_name[i],
				msg->queue_name[number_of_queues]);
			gw_rm_copy_str_short(host->queue_status[i],
				msg->queue_status[number_of_queues]);
			gw_rm_copy_str_short(host->queue_dispatchtype[i],
				msg->queue_dispatchtype[number_of_queues]);
			gw_rm_copy_str_short(host->queue_priority[i],
				msg->queue_priority[number_of_queues]);
			
			number_of_queues++;
		}
	msg->number_of_queues = number_of_queues;
	
	for (i=0;i<GW_HOST_MAX_GENVARS;i++)
		if (host->genvar_int[i].name != NULL )
		{
			gw_rm_copy_str_short(host->genvar_int[i].name
				,msg->gen_var_int_name[number_of_int_vars]);
			msg->gen_var_int_value[number_of_int_vars] = 
				host->genvar_int[i].value;
				
			number_of_int_vars++;
		}
	msg->number_of_int_vars = number_of_int_vars;	

	for (i=0;i<GW_HOST_MAX_GENVARS;i++)
		if (host->genvar_str[i].name != NULL )
		{
			gw_rm_copy_str_short(host->genvar_str[i].name,
				msg->gen_var_str_name[number_of_str_vars]);
			gw_rm_copy_str_long(host->genvar_str[i].value,
				msg->gen_var_str_value[number_of_str_vars]);
			number_of_str_vars++;
		}
	msg->number_of_str_vars = number_of_str_vars;
}