jobid format and parse
This commit is contained in:
parent
26e3c21c87
commit
3488b62716
6 changed files with 212 additions and 15 deletions
108
src/lib/utils.c
108
src/lib/utils.c
|
|
@ -15,6 +15,7 @@
|
|||
#include <execinfo.h>
|
||||
#endif
|
||||
|
||||
#include <regex.h>
|
||||
#include <tlog.h>
|
||||
|
||||
#include "config.h"
|
||||
|
|
@ -409,3 +410,110 @@ void free_strlist(xce_strlist_t* l)
|
|||
|
||||
FREEUP(l->data);
|
||||
}
|
||||
|
||||
int fmt_jobid(char* buf, size_t sz, uint64_t jobid)
|
||||
{
|
||||
uint32_t tag, id_cluster, id_apiserver, id_timestamp;
|
||||
char data[128];
|
||||
int len = 0;
|
||||
|
||||
tag = EXTRACT_ID_TAG(jobid);
|
||||
id_cluster = EXTRACT_ID_CLUSTER(jobid);
|
||||
id_apiserver = EXTRACT_ID_APISERVER(jobid);
|
||||
id_timestamp = EXTRACT_ID_TIMESTAMP(jobid);
|
||||
|
||||
memset(data, 0x0, sizeof(data));
|
||||
|
||||
if ((tag & TAG_JOB_ARRAY) != 0) {
|
||||
uint32_t id_job, id_idx;
|
||||
|
||||
id_job = EXTRACT_ARRAY_JOB(jobid);
|
||||
id_idx = EXTRACT_ARRAY_IDX(jobid);
|
||||
|
||||
snprintf(data, sizeof(data) - 1, "%d-%d-%d-%d[%d]", id_cluster,
|
||||
id_apiserver, id_timestamp, id_job, id_idx);
|
||||
} else {
|
||||
uint32_t id_seq;
|
||||
|
||||
id_seq = EXTRACT_ID_SEQUENCE(jobid);
|
||||
snprintf(data, sizeof(data) - 1, "%d-%d-%d-%d", id_cluster,
|
||||
id_apiserver, id_timestamp, id_seq);
|
||||
}
|
||||
|
||||
len = strlen(data);
|
||||
if (len > sz - 1) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
strncpy(buf, data, sz);
|
||||
return len;
|
||||
}
|
||||
|
||||
int parse_jobid(uint64_t* jobid, char* buf)
|
||||
{
|
||||
regex_t regex;
|
||||
regmatch_t pmatch[N_MAX_FIELDS_JOBID + 1];
|
||||
int rc;
|
||||
int len = strlen(buf);
|
||||
|
||||
if ((jobid == NULL) || (buf == NULL)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
rc = regcomp(®ex, REGEX_JOBARRAY_ID, REG_EXTENDED);
|
||||
if (rc != 0) {
|
||||
return -errno;
|
||||
}
|
||||
|
||||
*jobid = 0;
|
||||
rc = regexec(®ex, buf, N_EL_ARRAY(pmatch), pmatch, 0);
|
||||
if (rc == 0) {
|
||||
regfree(®ex);
|
||||
|
||||
if ((pmatch[0].rm_so == 0) && (pmatch[0].rm_eo == len)) {
|
||||
uint32_t tag, id_cluster, id_apiserver, id_timestamp, id_job,
|
||||
id_idx;
|
||||
|
||||
tag = 0x01; /* job array */
|
||||
id_cluster = atoi(&buf[pmatch[1].rm_so]);
|
||||
id_apiserver = atoi(&buf[pmatch[2].rm_so]);
|
||||
id_timestamp = atoi(&buf[pmatch[3].rm_so]);
|
||||
id_job = atoi(&buf[pmatch[4].rm_so]);
|
||||
id_idx = atoi(&buf[pmatch[5].rm_so]);
|
||||
|
||||
*jobid = MAKE_JOBID(id_cluster, id_apiserver, id_timestamp, tag,
|
||||
id_job + id_idx);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
regfree(®ex);
|
||||
rc = regcomp(®ex, REGEX_JOBID, REG_EXTENDED);
|
||||
if (rc != 0) {
|
||||
return -errno;
|
||||
}
|
||||
|
||||
rc = regexec(®ex, buf, N_EL_ARRAY(pmatch), pmatch, 0);
|
||||
if (rc == 0) {
|
||||
uint32_t id_cluster, id_apiserver, id_timestamp, id_job;
|
||||
|
||||
if ((pmatch[0].rm_so != 0) || (pmatch[0].rm_eo != len)) {
|
||||
regfree(®ex);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
id_cluster = atoi(&buf[pmatch[1].rm_so]);
|
||||
id_apiserver = atoi(&buf[pmatch[2].rm_so]);
|
||||
id_timestamp = atoi(&buf[pmatch[3].rm_so]);
|
||||
id_job = atoi(&buf[pmatch[4].rm_so]);
|
||||
|
||||
*jobid
|
||||
= MAKE_JOBID(id_cluster, id_apiserver, id_timestamp, 0x0, id_job);
|
||||
|
||||
regfree(®ex);
|
||||
return 1;
|
||||
}
|
||||
|
||||
regfree(®ex);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue