本文整理汇总了C++中slurm_atoul函数的典型用法代码示例。如果您正苦于以下问题:C++ slurm_atoul函数的具体用法?C++ slurm_atoul怎么用?C++ slurm_atoul使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了slurm_atoul函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: _get_db_index
/* Used in job functions for getting the database index based off the
* submit time, job and assoc id. 0 is returned if none is found
*/
static int _get_db_index(mysql_conn_t *mysql_conn,
time_t submit, uint32_t jobid, uint32_t associd)
{
MYSQL_RES *result = NULL;
MYSQL_ROW row;
int db_index = 0;
char *query = xstrdup_printf("select job_db_inx from \"%s_%s\" where "
"time_submit=%d and id_job=%u "
"and id_assoc=%u",
mysql_conn->cluster_name, job_table,
(int)submit, jobid, associd);
if (!(result = mysql_db_query_ret(mysql_conn, query, 0))) {
xfree(query);
return 0;
}
xfree(query);
row = mysql_fetch_row(result);
if (!row) {
mysql_free_result(result);
debug4("We can't get a db_index for this combo, "
"time_submit=%d and id_job=%u and id_assoc=%u. "
"We must not have heard about the start yet, "
"no big deal, we will get one right after this.",
(int)submit, jobid, associd);
return 0;
}
db_index = slurm_atoul(row[0]);
mysql_free_result(result);
return db_index;
}
示例2: _reset_default_wckey
static int _reset_default_wckey(mysql_conn_t *mysql_conn,
slurmdb_wckey_rec_t *wckey)
{
time_t now = time(NULL);
int rc = SLURM_SUCCESS;
char *query = NULL;
MYSQL_RES *result = NULL;
MYSQL_ROW row;
if ((wckey->is_def != 1)
|| !wckey->cluster || !wckey->user || !wckey->name)
return SLURM_ERROR;
xstrfmtcat(query, "update \"%s_%s\" set is_def=0, mod_time=%ld "
"where (user='%s' && wckey_name!='%s' && is_def=1);"
"select id_wckey from \"%s_%s\" "
"where (user='%s' && wckey_name!='%s' && is_def=1);",
wckey->cluster, wckey_table, (long)now,
wckey->user, wckey->name,
wckey->cluster, wckey_table,
wckey->user, wckey->name);
if (debug_flags & DEBUG_FLAG_DB_WCKEY)
DB_DEBUG(mysql_conn->conn, "query\n%s", query);
if (!(result = mysql_db_query_ret(mysql_conn, query, 1))) {
xfree(query);
rc = SLURM_ERROR;
goto end_it;
}
xfree(query);
while ((row = mysql_fetch_row(result))) {
slurmdb_wckey_rec_t *mod_wckey =
xmalloc(sizeof(slurmdb_wckey_rec_t));
slurmdb_init_wckey_rec(mod_wckey, 0);
mod_wckey->id = slurm_atoul(row[0]);
mod_wckey->is_def = 0;
if (addto_update_list(mysql_conn->update_list,
SLURMDB_MODIFY_WCKEY,
mod_wckey)
!= SLURM_SUCCESS) {
slurmdb_destroy_wckey_rec(mod_wckey);
error("couldn't add to the update list");
rc = SLURM_ERROR;
break;
}
}
mysql_free_result(result);
end_it:
return rc;
}
示例3: memset
static void *_cluster_rollup_usage(void *arg)
{
local_rollup_t *local_rollup = (local_rollup_t *)arg;
int rc = SLURM_SUCCESS;
char timer_str[128];
mysql_conn_t mysql_conn;
MYSQL_RES *result = NULL;
MYSQL_ROW row;
char *query = NULL;
struct tm start_tm;
struct tm end_tm;
time_t my_time = local_rollup->sent_end;
time_t last_hour = local_rollup->sent_start;
time_t last_day = local_rollup->sent_start;
time_t last_month = local_rollup->sent_start;
time_t hour_start;
time_t hour_end;
time_t day_start;
time_t day_end;
time_t month_start;
time_t month_end;
DEF_TIMERS;
char *update_req_inx[] = {
"hourly_rollup",
"daily_rollup",
"monthly_rollup"
};
enum {
UPDATE_HOUR,
UPDATE_DAY,
UPDATE_MONTH,
UPDATE_COUNT
};
memset(&mysql_conn, 0, sizeof(mysql_conn_t));
mysql_conn.rollback = 1;
mysql_conn.conn = local_rollup->mysql_conn->conn;
slurm_mutex_init(&mysql_conn.lock);
/* Each thread needs it's own connection we can't use the one
* sent from the parent thread. */
rc = check_connection(&mysql_conn);
if (rc != SLURM_SUCCESS)
goto end_it;
if (!local_rollup->sent_start) {
char *tmp = NULL;
int i=0;
xstrfmtcat(tmp, "%s", update_req_inx[i]);
for(i=1; i<UPDATE_COUNT; i++) {
xstrfmtcat(tmp, ", %s", update_req_inx[i]);
}
query = xstrdup_printf("select %s from \"%s_%s\"",
tmp, local_rollup->cluster_name,
last_ran_table);
xfree(tmp);
debug4("%d(%s:%d) query\n%s", mysql_conn.conn,
THIS_FILE, __LINE__, query);
if (!(result = mysql_db_query_ret(&mysql_conn, query, 0))) {
xfree(query);
rc = SLURM_ERROR;
goto end_it;
}
xfree(query);
row = mysql_fetch_row(result);
if (row) {
last_hour = slurm_atoul(row[UPDATE_HOUR]);
last_day = slurm_atoul(row[UPDATE_DAY]);
last_month = slurm_atoul(row[UPDATE_MONTH]);
mysql_free_result(result);
} else {
time_t now = time(NULL);
time_t lowest = now;
mysql_free_result(result);
query = xstrdup_printf(
"select time_start from \"%s_%s\" "
"where node_name='' order by "
"time_start asc limit 1;",
local_rollup->cluster_name, event_table);
debug3("%d(%s:%d) query\n%s", mysql_conn.conn,
THIS_FILE, __LINE__, query);
if (!(result = mysql_db_query_ret(
&mysql_conn, query, 0))) {
xfree(query);
rc = SLURM_ERROR;
goto end_it;
}
xfree(query);
if ((row = mysql_fetch_row(result))) {
time_t check = slurm_atoul(row[0]);
if (check < lowest)
lowest = check;
//.........这里部分代码省略.........
示例4: xstrfmtcat
static local_cluster_usage_t *_setup_cluster_usage(mysql_conn_t *mysql_conn,
char *cluster_name,
time_t curr_start,
time_t curr_end,
List cluster_down_list)
{
local_cluster_usage_t *c_usage = NULL;
char *query = NULL;
MYSQL_RES *result = NULL;
MYSQL_ROW row;
int i = 0;
ListIterator c_itr = NULL;
local_cluster_usage_t *loc_c_usage;
char *event_req_inx[] = {
"node_name",
"cpu_count",
"time_start",
"time_end",
"state",
};
char *event_str = NULL;
enum {
EVENT_REQ_NAME,
EVENT_REQ_CPU,
EVENT_REQ_START,
EVENT_REQ_END,
EVENT_REQ_STATE,
EVENT_REQ_COUNT
};
xstrfmtcat(event_str, "%s", event_req_inx[i]);
for(i=1; i<EVENT_REQ_COUNT; i++) {
xstrfmtcat(event_str, ", %s", event_req_inx[i]);
}
/* first get the events during this time. All that is
* except things with the maintainance flag set in the
* state. We handle those later with the reservations.
*/
query = xstrdup_printf("select %s from \"%s_%s\" where "
"!(state & %d) && (time_start < %ld "
"&& (time_end >= %ld "
"|| time_end = 0)) "
"order by node_name, time_start",
event_str, cluster_name, event_table,
NODE_STATE_MAINT,
curr_end, curr_start);
xfree(event_str);
if (debug_flags & DEBUG_FLAG_DB_USAGE)
DB_DEBUG(mysql_conn->conn, "query\n%s", query);
if (!(result = mysql_db_query_ret(mysql_conn, query, 0))) {
xfree(query);
return NULL;
}
xfree(query);
c_itr = list_iterator_create(cluster_down_list);
while ((row = mysql_fetch_row(result))) {
time_t row_start = slurm_atoul(row[EVENT_REQ_START]);
time_t row_end = slurm_atoul(row[EVENT_REQ_END]);
uint32_t row_cpu = slurm_atoul(row[EVENT_REQ_CPU]);
uint16_t state = slurm_atoul(row[EVENT_REQ_STATE]);
if (row_start < curr_start)
row_start = curr_start;
if (!row_end || row_end > curr_end)
row_end = curr_end;
/* Don't worry about it if the time is less
* than 1 second.
*/
if ((row_end - row_start) < 1)
continue;
/* this means we are a cluster registration
entry */
if (!row[EVENT_REQ_NAME][0]) {
/* if the cpu count changes we will
* only care about the last cpu count but
* we will keep a total of the time for
* all cpus to get the correct cpu time
* for the entire period.
*/
if (state || !c_usage) {
loc_c_usage = xmalloc(
sizeof(local_cluster_usage_t));
loc_c_usage->cpu_count = row_cpu;
loc_c_usage->total_time =
(row_end - row_start) * row_cpu;
loc_c_usage->start = row_start;
loc_c_usage->end = row_end;
/* If this has a state it
means the slurmctld went
down and we should put this
on the list and remove any
jobs from this time that
were running later.
*/
if (state)
//.........这里部分代码省略.........
示例5: as_mysql_get_cluster_events
//.........这里部分代码省略.........
set = 1;
}
list_iterator_destroy(itr);
xstrcat(extra, ")");
}
if (event_cond->state_list
&& list_count(event_cond->state_list)) {
set = 0;
if (extra)
xstrcat(extra, " && (");
else
xstrcat(extra, " where (");
itr = list_iterator_create(event_cond->state_list);
while ((object = list_next(itr))) {
if (set)
xstrcat(extra, " || ");
xstrfmtcat(extra, "state='%s'", object);
set = 1;
}
list_iterator_destroy(itr);
xstrcat(extra, ")");
}
if (event_cond->cluster_list && list_count(event_cond->cluster_list))
use_cluster_list = event_cond->cluster_list;
empty:
xfree(tmp);
xstrfmtcat(tmp, "%s", event_req_inx[0]);
for(i=1; i<EVENT_REQ_COUNT; i++) {
xstrfmtcat(tmp, ", %s", event_req_inx[i]);
}
if (use_cluster_list == as_mysql_cluster_list)
slurm_mutex_lock(&as_mysql_cluster_list_lock);
ret_list = list_create(slurmdb_destroy_event_rec);
itr = list_iterator_create(use_cluster_list);
while ((object = list_next(itr))) {
query = xstrdup_printf("select %s from \"%s_%s\"",
tmp, object, event_table);
if (extra)
xstrfmtcat(query, " %s", extra);
if (debug_flags & DEBUG_FLAG_DB_ASSOC)
DB_DEBUG(mysql_conn->conn, "query\n%s", query);
if (!(result = mysql_db_query_ret(
mysql_conn, query, 0))) {
xfree(query);
if (mysql_errno(mysql_conn->db_conn)
!= ER_NO_SUCH_TABLE) {
FREE_NULL_LIST(ret_list);
ret_list = NULL;
}
break;
}
xfree(query);
while ((row = mysql_fetch_row(result))) {
slurmdb_event_rec_t *event =
xmalloc(sizeof(slurmdb_event_rec_t));
list_append(ret_list, event);
event->cluster = xstrdup(object);
if (row[EVENT_REQ_NODE] && row[EVENT_REQ_NODE][0]) {
event->node_name = xstrdup(row[EVENT_REQ_NODE]);
event->event_type = SLURMDB_EVENT_NODE;
} else
event->event_type = SLURMDB_EVENT_CLUSTER;
event->state = slurm_atoul(row[EVENT_REQ_STATE]);
event->period_start = slurm_atoul(row[EVENT_REQ_START]);
event->period_end = slurm_atoul(row[EVENT_REQ_END]);
if (row[EVENT_REQ_REASON] && row[EVENT_REQ_REASON][0])
event->reason = xstrdup(row[EVENT_REQ_REASON]);
event->reason_uid =
slurm_atoul(row[EVENT_REQ_REASON_UID]);
if (row[EVENT_REQ_CNODES] && row[EVENT_REQ_CNODES][0])
event->cluster_nodes =
xstrdup(row[EVENT_REQ_CNODES]);
if (row[EVENT_REQ_TRES] && row[EVENT_REQ_TRES][0])
event->tres_str = xstrdup(row[EVENT_REQ_TRES]);
}
mysql_free_result(result);
}
list_iterator_destroy(itr);
xfree(tmp);
xfree(extra);
if (use_cluster_list == as_mysql_cluster_list)
slurm_mutex_unlock(&as_mysql_cluster_list_lock);
return ret_list;
}
示例6: as_mysql_node_down
extern int as_mysql_node_down(mysql_conn_t *mysql_conn,
struct node_record *node_ptr,
time_t event_time, char *reason,
uint32_t reason_uid)
{
int rc = SLURM_SUCCESS;
char *query = NULL;
char *my_reason;
MYSQL_RES *result = NULL;
MYSQL_ROW row;
if (check_connection(mysql_conn) != SLURM_SUCCESS)
return ESLURM_DB_CONNECTION;
if (!mysql_conn->cluster_name) {
error("%s:%d no cluster name", THIS_FILE, __LINE__);
return SLURM_ERROR;
}
if (!node_ptr) {
error("No node_ptr given!");
return SLURM_ERROR;
}
if (!node_ptr->tres_str) {
error("node ptr has no tres_list!");
return SLURM_ERROR;
}
query = xstrdup_printf("select state, reason from \"%s_%s\" where "
"time_end=0 and node_name='%s';",
mysql_conn->cluster_name, event_table,
node_ptr->name);
/* info("%d(%s:%d) query\n%s", */
/* mysql_conn->conn, THIS_FILE, __LINE__, query); */
result = mysql_db_query_ret(mysql_conn, query, 0);
xfree(query);
if (!result)
return SLURM_ERROR;
if (reason)
my_reason = slurm_add_slash_to_quotes(reason);
else
my_reason = slurm_add_slash_to_quotes(node_ptr->reason);
row = mysql_fetch_row(result);
if (row && (node_ptr->node_state == slurm_atoul(row[0])) &&
my_reason && row[1] &&
!strcasecmp(my_reason, row[1])) {
debug("as_mysql_node_down: no change needed %u == %s "
"and %s == %s",
node_ptr->node_state, row[0], my_reason, row[1]);
xfree(my_reason);
mysql_free_result(result);
return SLURM_SUCCESS;
}
mysql_free_result(result);
debug2("inserting %s(%s) with tres of '%s'",
node_ptr->name, mysql_conn->cluster_name, node_ptr->tres_str);
query = xstrdup_printf(
"update \"%s_%s\" set time_end=%ld where "
"time_end=0 and node_name='%s';",
mysql_conn->cluster_name, event_table,
event_time, node_ptr->name);
/* If you are clean-restarting the controller over and over again you
* could get records that are duplicates in the database. If
* this is the case we will zero out the time_end we are
* just filled in. This will cause the last time to be erased
* from the last restart, but if you are restarting things
* this often the pervious one didn't mean anything anyway.
* This way we only get one for the last time we let it run.
*/
xstrfmtcat(query,
"insert into \"%s_%s\" "
"(node_name, state, tres, time_start, "
"reason, reason_uid) "
"values ('%s', %u, '%s', %ld, '%s', %u) "
"on duplicate key update time_end=0;",
mysql_conn->cluster_name, event_table,
node_ptr->name, node_ptr->node_state,
node_ptr->tres_str, event_time, my_reason, reason_uid);
debug2("%d(%s:%d) query\n%s",
mysql_conn->conn, THIS_FILE, __LINE__, query);
rc = mysql_db_query(mysql_conn, query);
xfree(query);
xfree(my_reason);
return rc;
}
示例7: _cluster_get_jobs
//.........这里部分代码省略.........
easy to look for duplicates, it is also easy to sort the
resized jobs.
*/
xstrcat(query, " group by id_job, time_submit desc");
if (debug_flags & DEBUG_FLAG_DB_JOB)
DB_DEBUG(mysql_conn->conn, "query\n%s", query);
if (!(result = mysql_db_query_ret(mysql_conn, query, 0))) {
xfree(query);
rc = SLURM_ERROR;
goto end_it;
}
xfree(query);
/* Here we set up environment to check used nodes of jobs.
Since we store the bitmap of the entire cluster we can use
that to set up a hostlist and set up the bitmap to make
things work. This should go before the setup of conds
since we could update the start/end time.
*/
if (job_cond && job_cond->used_nodes) {
local_cluster_list = setup_cluster_list_with_inx(
mysql_conn, job_cond, (void **)&curr_cluster);
if (!local_cluster_list) {
rc = SLURM_ERROR;
goto end_it;
}
}
while ((row = mysql_fetch_row(result))) {
char *id = row[JOB_REQ_ID];
bool job_ended = 0;
int start = slurm_atoul(row[JOB_REQ_START]);
curr_id = slurm_atoul(row[JOB_REQ_JOBID]);
if (job_cond && !job_cond->duplicates
&& (curr_id == last_id)
&& (slurm_atoul(row[JOB_REQ_STATE]) != JOB_RESIZING))
continue;
/* check the bitmap to see if this is one of the jobs
we are looking for */
/* Use start time instead of submit time because node
* indexes are determined at start time and not submit. */
if (!good_nodes_from_inx(local_cluster_list,
(void **)&curr_cluster,
row[JOB_REQ_NODE_INX], start)) {
last_id = curr_id;
continue;
}
job = slurmdb_create_job_rec();
job->state = slurm_atoul(row[JOB_REQ_STATE]);
if (curr_id == last_id)
/* put in reverse so we order by the submit getting
larger which it is given to us in reverse
order from the database */
list_prepend(job_list, job);
else
list_append(job_list, job);
last_id = curr_id;
if (row[JOB_REQ_GRES_ALLOC])
job->alloc_gres = xstrdup(row[JOB_REQ_GRES_ALLOC]);
示例8: setup_job_cluster_cond_limits
extern int setup_job_cluster_cond_limits(mysql_conn_t *mysql_conn,
slurmdb_job_cond_t *job_cond,
char *cluster_name, char **extra)
{
int set = 0;
ListIterator itr = NULL;
char *object = NULL;
if (!job_cond)
return SLURM_SUCCESS;
/* this must be done before resvid_list since we set
resvid_list up here */
if (job_cond->resv_list && list_count(job_cond->resv_list)) {
char *query = xstrdup_printf(
"select distinct job_db_inx from \"%s_%s\" where (",
cluster_name, job_table);
int my_set = 0;
MYSQL_RES *result = NULL;
MYSQL_ROW row;
itr = list_iterator_create(job_cond->resv_list);
while ((object = list_next(itr))) {
if (my_set)
xstrcat(query, " || ");
xstrfmtcat(query, "resv_name='%s'", object);
my_set = 1;
}
list_iterator_destroy(itr);
xstrcat(query, ")");
if (!(result = mysql_db_query_ret(
mysql_conn, query, 0))) {
xfree(query);
error("couldn't query the database");
goto no_resv;
}
xfree(query);
if (!job_cond->resvid_list)
job_cond->resvid_list = list_create(slurm_destroy_char);
while ((row = mysql_fetch_row(result))) {
list_append(job_cond->resvid_list, xstrdup(row[0]));
}
mysql_free_result(result);
}
no_resv:
if (job_cond->resvid_list && list_count(job_cond->resvid_list)) {
set = 0;
if (*extra)
xstrcat(*extra, " && (");
else
xstrcat(*extra, " where (");
itr = list_iterator_create(job_cond->resvid_list);
while ((object = list_next(itr))) {
if (set)
xstrcat(*extra, " || ");
xstrfmtcat(*extra, "t1.id_resv='%s'", object);
set = 1;
}
list_iterator_destroy(itr);
xstrcat(*extra, ")");
}
if (job_cond->state_list && list_count(job_cond->state_list)) {
set = 0;
if (*extra)
xstrcat(*extra, " && (");
else
xstrcat(*extra, " where (");
itr = list_iterator_create(job_cond->state_list);
while ((object = list_next(itr))) {
if (set)
xstrcat(*extra, " || ");
_state_time_string(extra, cluster_name,
(uint32_t)slurm_atoul(object),
job_cond->usage_start,
job_cond->usage_end);
set = 1;
}
list_iterator_destroy(itr);
xstrcat(*extra, ")");
}
return SLURM_SUCCESS;
}
示例9: setup_job_cond_limits
//.........这里部分代码省略.........
if (job_cond->nodes_max) {
xstrfmtcat(*extra,
"(t1.nodes_alloc between %u and %u))",
job_cond->nodes_min, job_cond->nodes_max);
} else {
xstrfmtcat(*extra, "(t1.nodes_alloc='%u'))",
job_cond->nodes_min);
}
}
if (job_cond->timelimit_min) {
if (*extra)
xstrcat(*extra, " && (");
else
xstrcat(*extra, " where (");
if (job_cond->timelimit_max) {
xstrfmtcat(*extra, "(t1.timelimit between %u and %u))",
job_cond->timelimit_min,
job_cond->timelimit_max);
} else {
xstrfmtcat(*extra, "(t1.timelimit='%u'))",
job_cond->timelimit_min);
}
}
if (job_cond->state_list && list_count(job_cond->state_list)) {
set = 0;
if (*extra)
xstrcat(*extra, " && (");
else
xstrcat(*extra, " where (");
itr = list_iterator_create(job_cond->state_list);
while ((object = list_next(itr))) {
if (set)
xstrcat(*extra, " || ");
_state_time_string(extra, (uint32_t)slurm_atoul(object),
job_cond->usage_start,
job_cond->usage_end);
set = 1;
}
list_iterator_destroy(itr);
xstrcat(*extra, ")");
} else {
/* Only do this (default of all eligible jobs) if no
state is given */
if (job_cond->usage_start) {
if (*extra)
xstrcat(*extra, " && (");
else
xstrcat(*extra, " where (");
if (!job_cond->usage_end)
xstrfmtcat(*extra,
"(t1.time_end >= %ld "
"|| t1.time_end = 0))",
job_cond->usage_start);
else
xstrfmtcat(*extra,
"(t1.time_eligible < %ld "
"&& (t1.time_end >= %ld "
"|| t1.time_end = 0)))",
job_cond->usage_end,
job_cond->usage_start);
} else if (job_cond->usage_end) {
if (*extra)
xstrcat(*extra, " && (");
else
xstrcat(*extra, " where (");
xstrfmtcat(*extra,
"(t1.time_eligible < %ld))",
job_cond->usage_end);
}
}
if (job_cond->wckey_list && list_count(job_cond->wckey_list)) {
set = 0;
if (*extra)
xstrcat(*extra, " && (");
else
xstrcat(*extra, " where (");
itr = list_iterator_create(job_cond->wckey_list);
while ((object = list_next(itr))) {
if (set)
xstrcat(*extra, " || ");
xstrfmtcat(*extra, "t1.wckey='%s'", object);
set = 1;
}
list_iterator_destroy(itr);
xstrcat(*extra, ")");
}
return set;
}
示例10: _cluster_get_wckeys
static int _cluster_get_wckeys(mysql_conn_t *mysql_conn,
slurmdb_wckey_cond_t *wckey_cond,
char *fields,
char *extra,
char *cluster_name,
List sent_list)
{
List wckey_list = NULL;
MYSQL_RES *result = NULL;
MYSQL_ROW row;
char *query = NULL;
bool with_usage = 0;
if (wckey_cond)
with_usage = wckey_cond->with_usage;
xstrfmtcat(query, "select distinct %s from \"%s_%s\" as t1%s "
"order by wckey_name, user;",
fields, cluster_name, wckey_table, extra);
if (debug_flags & DEBUG_FLAG_DB_WCKEY)
DB_DEBUG(mysql_conn->conn, "query\n%s", query);
if (!(result = mysql_db_query_ret(
mysql_conn, query, 0))) {
xfree(query);
if (mysql_errno(mysql_conn->db_conn) == ER_NO_SUCH_TABLE)
return SLURM_SUCCESS;
else
return SLURM_ERROR;
}
xfree(query);
if (!mysql_num_rows(result)) {
mysql_free_result(result);
return SLURM_SUCCESS;
}
wckey_list = list_create(slurmdb_destroy_wckey_rec);
while ((row = mysql_fetch_row(result))) {
slurmdb_wckey_rec_t *wckey =
xmalloc(sizeof(slurmdb_wckey_rec_t));
list_append(wckey_list, wckey);
wckey->id = slurm_atoul(row[WCKEY_REQ_ID]);
wckey->is_def = slurm_atoul(row[WCKEY_REQ_DEFAULT]);
wckey->user = xstrdup(row[WCKEY_REQ_USER]);
/* we want a blank wckey if the name is null */
if (row[WCKEY_REQ_NAME])
wckey->name = xstrdup(row[WCKEY_REQ_NAME]);
else
wckey->name = xstrdup("");
wckey->cluster = xstrdup(cluster_name);
}
mysql_free_result(result);
if (with_usage && wckey_list && list_count(wckey_list))
get_usage_for_list(mysql_conn, DBD_GET_WCKEY_USAGE,
wckey_list, cluster_name,
wckey_cond->usage_start,
wckey_cond->usage_end);
list_transfer(sent_list, wckey_list);
list_destroy(wckey_list);
return SLURM_SUCCESS;
}
示例11: _cluster_modify_wckeys
static int _cluster_modify_wckeys(mysql_conn_t *mysql_conn,
slurmdb_wckey_rec_t *wckey,
char *cluster_name, char *extra,
char *vals, char *user_name,
List ret_list)
{
int rc = SLURM_SUCCESS;
MYSQL_RES *result = NULL;
MYSQL_ROW row;
char *wckey_char = NULL;
time_t now = time(NULL);
char *query = NULL;
query = xstrdup_printf("select t1.id_wckey, t1.wckey_name, t1.user "
"from \"%s_%s\" as t1%s;",
cluster_name, wckey_table, extra);
if (!(result = mysql_db_query_ret(mysql_conn, query, 0))) {
xfree(query);
return SLURM_ERROR;
}
/* This key doesn't exist on this cluster, that is ok. */
if (!mysql_num_rows(result))
return SLURM_SUCCESS;
while ((row = mysql_fetch_row(result))) {
slurmdb_wckey_rec_t *wckey_rec = NULL;
char *object = xstrdup_printf(
"C = %-10s W = %-20s U = %-9s",
cluster_name, row[1], row[2]);
list_append(ret_list, object);
if (!wckey_char)
xstrfmtcat(wckey_char, "id_wckey='%s'", row[0]);
else
xstrfmtcat(wckey_char, " || id_wckey='%s'", row[0]);
wckey_rec = xmalloc(sizeof(slurmdb_wckey_rec_t));
/* we only need id and cluster when removing
no real need to init */
wckey_rec->id = slurm_atoul(row[0]);
wckey_rec->cluster = xstrdup(cluster_name);
wckey_rec->is_def = wckey->is_def;
if (addto_update_list(mysql_conn->update_list,
SLURMDB_MODIFY_WCKEY, wckey_rec)
!= SLURM_SUCCESS)
slurmdb_destroy_wckey_rec(wckey_rec);
if (wckey->is_def == 1) {
/* Use fresh one here so we don't have to
worry about dealing with bad values.
*/
slurmdb_wckey_rec_t tmp_wckey;
slurmdb_init_wckey_rec(&tmp_wckey, 0);
tmp_wckey.is_def = 1;
tmp_wckey.cluster = cluster_name;
tmp_wckey.name = row[1];
tmp_wckey.user = row[2];
if ((rc = _reset_default_wckey(mysql_conn, &tmp_wckey))
!= SLURM_SUCCESS)
break;
}
}
mysql_free_result(result);
if (!list_count(ret_list)) {
errno = SLURM_NO_CHANGE_IN_DATA;
if (debug_flags & DEBUG_FLAG_DB_WCKEY)
DB_DEBUG(mysql_conn->conn,
"didn't effect anything\n%s", query);
xfree(query);
xfree(wckey_char);
return SLURM_SUCCESS;
}
xfree(query);
rc = modify_common(mysql_conn, DBD_MODIFY_WCKEYS, now,
user_name, wckey_table, wckey_char,
vals, cluster_name);
xfree(wckey_char);
return rc;
}
示例12: _cluster_remove_wckeys
static int _cluster_remove_wckeys(mysql_conn_t *mysql_conn,
char *extra,
char *cluster_name,
char *user_name,
List ret_list)
{
int rc = SLURM_SUCCESS;
MYSQL_RES *result = NULL;
MYSQL_ROW row;
char *assoc_char = NULL;
time_t now = time(NULL);
char *query = xstrdup_printf("select t1.id_wckey, t1.wckey_name "
"from \"%s_%s\" as t1%s;",
cluster_name, wckey_table, extra);
if (!(result = mysql_db_query_ret(mysql_conn, query, 0))) {
xfree(query);
return SLURM_ERROR;
}
if (!mysql_num_rows(result)) {
mysql_free_result(result);
xfree(query);
return SLURM_SUCCESS;
}
while ((row = mysql_fetch_row(result))) {
slurmdb_wckey_rec_t *wckey_rec = NULL;
list_append(ret_list, xstrdup(row[1]));
if (!assoc_char)
xstrfmtcat(assoc_char, "id_wckey='%s'", row[0]);
else
xstrfmtcat(assoc_char, " || id_wckey='%s'", row[0]);
wckey_rec = xmalloc(sizeof(slurmdb_wckey_rec_t));
/* we only need id and cluster when removing
no real need to init */
wckey_rec->id = slurm_atoul(row[0]);
wckey_rec->cluster = xstrdup(cluster_name);
if (addto_update_list(mysql_conn->update_list,
SLURMDB_REMOVE_WCKEY, wckey_rec)
!= SLURM_SUCCESS)
slurmdb_destroy_wckey_rec(wckey_rec);
}
mysql_free_result(result);
if (!list_count(ret_list)) {
errno = SLURM_NO_CHANGE_IN_DATA;
if (debug_flags & DEBUG_FLAG_DB_WCKEY)
DB_DEBUG(mysql_conn->conn,
"didn't effect anything\n%s", query);
xfree(query);
xfree(assoc_char);
return SLURM_SUCCESS;
}
xfree(query);
rc = remove_common(mysql_conn, DBD_REMOVE_WCKEYS, now,
user_name, wckey_table, assoc_char, assoc_char,
cluster_name, NULL, NULL);
xfree(assoc_char);
if (rc == SLURM_ERROR) {
list_destroy(ret_list);
return SLURM_ERROR;
}
return SLURM_SUCCESS;
}
示例13: mysql_jobcomp_process_get_jobs
extern List mysql_jobcomp_process_get_jobs(slurmdb_job_cond_t *job_cond)
{
char *query = NULL;
char *extra = NULL;
char *tmp = NULL;
char *selected_part = NULL;
slurmdb_selected_step_t *selected_step = NULL;
ListIterator itr = NULL;
int set = 0;
MYSQL_RES *result = NULL;
MYSQL_ROW row;
int i;
int lc = 0;
jobcomp_job_rec_t *job = NULL;
char time_str[32];
time_t temp_time;
List job_list = list_create(jobcomp_destroy_job);
if (job_cond->step_list && list_count(job_cond->step_list)) {
set = 0;
xstrcat(extra, " where (");
itr = list_iterator_create(job_cond->step_list);
while((selected_step = list_next(itr))) {
if (set)
xstrcat(extra, " || ");
tmp = xstrdup_printf("jobid=%d",
selected_step->jobid);
xstrcat(extra, tmp);
set = 1;
xfree(tmp);
}
list_iterator_destroy(itr);
xstrcat(extra, ")");
}
if (job_cond->partition_list && list_count(job_cond->partition_list)) {
set = 0;
if (extra)
xstrcat(extra, " && (");
else
xstrcat(extra, " where (");
itr = list_iterator_create(job_cond->partition_list);
while((selected_part = list_next(itr))) {
if (set)
xstrcat(extra, " || ");
tmp = xstrdup_printf("`partition`='%s'",
selected_part);
xstrcat(extra, tmp);
set = 1;
xfree(tmp);
}
list_iterator_destroy(itr);
xstrcat(extra, ")");
}
i = 0;
while(jobcomp_table_fields[i].name) {
if (i)
xstrcat(tmp, ", ");
xstrcat(tmp, jobcomp_table_fields[i].name);
i++;
}
query = xstrdup_printf("select %s from %s", tmp, jobcomp_table);
xfree(tmp);
if (extra) {
xstrcat(query, extra);
xfree(extra);
}
//info("query = %s", query);
if (!(result =
mysql_db_query_ret(jobcomp_mysql_conn, query, 0))) {
xfree(query);
list_destroy(job_list);
return NULL;
}
xfree(query);
while((row = mysql_fetch_row(result))) {
lc++;
job = xmalloc(sizeof(jobcomp_job_rec_t));
if (row[JOBCOMP_REQ_JOBID])
job->jobid = slurm_atoul(row[JOBCOMP_REQ_JOBID]);
job->partition = xstrdup(row[JOBCOMP_REQ_PARTITION]);
temp_time = atoi(row[JOBCOMP_REQ_STARTTIME]);
slurm_make_time_str(&temp_time,
time_str,
sizeof(time_str));
job->start_time = xstrdup(time_str);
temp_time = atoi(row[JOBCOMP_REQ_ENDTIME]);
slurm_make_time_str(&temp_time,
time_str,
sizeof(time_str));
//.........这里部分代码省略.........
示例14: _load_dbd_state
static void _load_dbd_state(void)
{
char *dbd_fname;
Buf buffer;
int fd, recovered = 0;
uint16_t rpc_version = 0;
dbd_fname = slurm_get_state_save_location();
xstrcat(dbd_fname, "/dbd.messages");
fd = open(dbd_fname, O_RDONLY);
if (fd < 0) {
/* don't print an error message if there is no file */
if (errno == ENOENT)
debug4("slurmdbd: There is no state save file to "
"open by name %s", dbd_fname);
else
error("slurmdbd: Opening state save file %s: %m",
dbd_fname);
} else {
char *ver_str = NULL;
uint32_t ver_str_len;
buffer = _load_dbd_rec(fd);
if (buffer == NULL)
goto end_it;
/* This is set to the end of the buffer for send so we
need to set it back to 0 */
set_buf_offset(buffer, 0);
safe_unpackstr_xmalloc(&ver_str, &ver_str_len, buffer);
debug3("Version string in dbd_state header is %s", ver_str);
unpack_error:
free_buf(buffer);
buffer = NULL;
if (ver_str) {
/* get the version after VER */
rpc_version = slurm_atoul(ver_str + 3);
xfree(ver_str);
}
while (1) {
/* If the buffer was not the VER%d string it
was an actual message so we don't want to
skip it.
*/
if (!buffer)
buffer = _load_dbd_rec(fd);
if (buffer == NULL)
break;
if (rpc_version != SLURM_PROTOCOL_VERSION) {
/* unpack and repack with new
* PROTOCOL_VERSION just so we keep
* things up to date.
*/
slurmdbd_msg_t msg;
int rc;
set_buf_offset(buffer, 0);
rc = unpack_slurmdbd_msg(
&msg, rpc_version, buffer);
free_buf(buffer);
if (rc == SLURM_SUCCESS)
buffer = pack_slurmdbd_msg(
&msg, SLURM_PROTOCOL_VERSION);
else
buffer = NULL;
}
if (!buffer) {
error("no buffer given");
continue;
}
if (!list_enqueue(agent_list, buffer))
fatal("slurmdbd: list_enqueue, no memory");
recovered++;
buffer = NULL;
}
end_it:
verbose("slurmdbd: recovered %d pending RPCs", recovered);
(void) close(fd);
}
xfree(dbd_fname);
}
示例15: as_mysql_get_usage
//.........这里部分代码省略.........
if (username && !strcmp(slurmdb_assoc->user, user.name))
goto is_user;
if (type != DBD_GET_ASSOC_USAGE)
goto bad_user;
if (!slurmdb_assoc->acct) {
debug("No account name given "
"in association.");
goto bad_user;
}
if (!is_user_any_coord(mysql_conn, &user)) {
debug4("This user is not a coordinator.");
goto bad_user;
}
/* Existance of user.coord_accts is checked in
is_user_any_coord.
*/
itr = list_iterator_create(user.coord_accts);
while ((coord = list_next(itr)))
if (!strcasecmp(coord->name,
slurmdb_assoc->acct))
break;
list_iterator_destroy(itr);
if (coord)
goto is_user;
bad_user:
errno = ESLURM_ACCESS_DENIED;
return SLURM_ERROR;
}
}
is_user:
if (set_usage_information(&my_usage_table, type, &start, &end)
!= SLURM_SUCCESS) {
return SLURM_ERROR;
}
xfree(tmp);
i=0;
xstrfmtcat(tmp, "%s", usage_req_inx[i]);
for(i=1; i<USAGE_COUNT; i++) {
xstrfmtcat(tmp, ", %s", usage_req_inx[i]);
}
switch (type) {
case DBD_GET_ASSOC_USAGE:
query = xstrdup_printf(
"select %s from \"%s_%s\" as t1, "
"\"%s_%s\" as t2, \"%s_%s\" as t3 "
"where (t1.time_start < %ld && t1.time_start >= %ld) "
"&& t1.id_assoc=t2.id_assoc && t3.id_assoc=%d && "
"t2.lft between t3.lft and t3.rgt "
"order by t3.id_assoc, time_start;",
tmp, cluster_name, my_usage_table,
cluster_name, cluster_name, assoc_table, assoc_table,
end, start, id);
break;
case DBD_GET_WCKEY_USAGE:
query = xstrdup_printf(
"select %s from \"%s_%s\" "
"where (time_start < %ld && time_start >= %ld) "
"&& id_wckey=%d order by id_wckey, time_start;",
tmp, cluster_name, my_usage_table, end, start, id);
break;
default:
error("Unknown usage type %d", type);
return SLURM_ERROR;
break;
}
xfree(tmp);
debug4("%d(%s:%d) query\n%s",
mysql_conn->conn, THIS_FILE, __LINE__, query);
if (!(result = mysql_db_query_ret(
mysql_conn, query, 0))) {
xfree(query);
return SLURM_ERROR;
}
xfree(query);
if (!(*my_list))
(*my_list) = list_create(slurmdb_destroy_accounting_rec);
while ((row = mysql_fetch_row(result))) {
slurmdb_accounting_rec_t *accounting_rec =
xmalloc(sizeof(slurmdb_accounting_rec_t));
accounting_rec->id = slurm_atoul(row[USAGE_ID]);
accounting_rec->period_start = slurm_atoul(row[USAGE_START]);
accounting_rec->alloc_secs = slurm_atoull(row[USAGE_ACPU]);
accounting_rec->consumed_energy = slurm_atoull(row[USAGE_ENERGY]);
list_append((*my_list), accounting_rec);
}
mysql_free_result(result);
return rc;
}