forked from lei.chen/myxce
save works
This commit is contained in:
parent
b1faeb94b6
commit
b748e30d20
35 changed files with 1247 additions and 2149 deletions
|
|
@ -2,9 +2,11 @@
|
|||
#include <stdlib.h>
|
||||
|
||||
#include "cluster.h"
|
||||
#include "wobj.h"
|
||||
#include "worker.h"
|
||||
#include "xce/cluster_def.h"
|
||||
#include "xce/errnox.h"
|
||||
#include "xstring.h"
|
||||
|
||||
static int hostmatched(const char* pattern, const char* name)
|
||||
{
|
||||
|
|
@ -68,7 +70,7 @@ static int update_val_res(cluster_t* c, worker_t* w, xce_resource_t* r,
|
|||
array = &(c->sharedinst);
|
||||
} else {
|
||||
/* update host based resource */
|
||||
array = &(w->host.resvals);
|
||||
array = &(w->host->resvals);
|
||||
}
|
||||
|
||||
if (idx < array->caps) {
|
||||
|
|
@ -95,11 +97,14 @@ static int update_val_res(cluster_t* c, worker_t* w, xce_resource_t* r,
|
|||
|
||||
static int update_resval(cluster_t* c, worker_t* w, xce_resval_t* val)
|
||||
{
|
||||
xce_resource_t* r;
|
||||
xce_resource_t* r = NULL;
|
||||
xce_val_t* v = NULL;
|
||||
int rc;
|
||||
|
||||
r = resmgr_lockres(&(c->resmgr), val->name, OBJREF_READ);
|
||||
rc = key_find(c->resmgr, (void*)val->name, (void**)&r);
|
||||
if (rc < 0) {
|
||||
return rc;
|
||||
}
|
||||
if (r == NULL) {
|
||||
ERROR("resource `%s' can not be found", val->name);
|
||||
return -errno;
|
||||
|
|
@ -114,8 +119,6 @@ static int update_resval(cluster_t* c, worker_t* w, xce_resval_t* val)
|
|||
|
||||
rc = update_val_res(c, w, r, v);
|
||||
|
||||
obj_deref(r);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
|
@ -151,14 +154,18 @@ int update_resval_list(cluster_t* c, worker_t* w, xce_resval_list_t* l)
|
|||
|
||||
static int mark_host_res(cluster_t* c, worker_t* w, xce_config_t* config)
|
||||
{
|
||||
xce_resource_t* r;
|
||||
xce_resource_t* r = NULL;
|
||||
char* n = config->name;
|
||||
int rc;
|
||||
/* clang-format-off */
|
||||
xce_val_t val;
|
||||
/* clang-format-on */
|
||||
|
||||
r = resmgr_lockres(&(c->resmgr), n, OBJREF_READ);
|
||||
rc = key_find(c->resmgr, (void*)n, (void**)&r);
|
||||
if (rc < 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
if (r == NULL) {
|
||||
ERROR("resource `%s' can not be found", n);
|
||||
return -ENOENT;
|
||||
|
|
@ -199,7 +206,6 @@ static int mark_host_res(cluster_t* c, worker_t* w, xce_config_t* config)
|
|||
}
|
||||
rc = update_val_res(c, w, r, &val);
|
||||
|
||||
obj_deref(r);
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
|
@ -207,16 +213,17 @@ static int add_hostattrs_resvals(cluster_t* c, worker_t* w)
|
|||
{
|
||||
#define N_HOST_ATTRS (8)
|
||||
xce_val_t values[N_HOST_ATTRS] = {
|
||||
{ .which = Value_u_svalue, .u = { .svalue = w->host.attrs->hosttype } },
|
||||
{ .which = Value_u_svalue,
|
||||
.u = { .svalue = w->host.attrs->hostmodel } },
|
||||
.u = { .svalue = w->host->attrs->hosttype } },
|
||||
{ .which = Value_u_svalue,
|
||||
.u = { .svalue = w->host->attrs->hostmodel } },
|
||||
{ .which = Value_u_fvalue,
|
||||
.u = { .fvalue = w->host.attrs->cpufactor } },
|
||||
{ .which = Value_u_fvalue, .u = { .fvalue = w->host.attrs->maxcpus } },
|
||||
{ .which = Value_u_fvalue, .u = { .fvalue = w->host.attrs->maxmem } },
|
||||
{ .which = Value_u_fvalue, .u = { .fvalue = w->host.attrs->maxswap } },
|
||||
{ .which = Value_u_fvalue, .u = { .fvalue = w->host.attrs->maxtmp } },
|
||||
{ .which = Value_u_fvalue, .u = { .fvalue = w->host.attrs->ndisks } }
|
||||
.u = { .fvalue = w->host->attrs->cpufactor } },
|
||||
{ .which = Value_u_fvalue, .u = { .fvalue = w->host->attrs->maxcpus } },
|
||||
{ .which = Value_u_fvalue, .u = { .fvalue = w->host->attrs->maxmem } },
|
||||
{ .which = Value_u_fvalue, .u = { .fvalue = w->host->attrs->maxswap } },
|
||||
{ .which = Value_u_fvalue, .u = { .fvalue = w->host->attrs->maxtmp } },
|
||||
{ .which = Value_u_fvalue, .u = { .fvalue = w->host->attrs->ndisks } }
|
||||
};
|
||||
xce_resval_t resvals[N_HOST_ATTRS] = {
|
||||
{ .name = "type", .val = &values[0] },
|
||||
|
|
@ -259,7 +266,7 @@ int add_worker(void* cls, endpoint_t* ep, const char* host, hostattrs_t* attrs)
|
|||
cluster_t* c = (cluster_t*)cls;
|
||||
/* clang-format off */
|
||||
worker_t worker = {
|
||||
.host = {
|
||||
.host = &(xce_worker_t){
|
||||
.name = (char*)host,
|
||||
}
|
||||
};
|
||||
|
|
@ -273,35 +280,38 @@ int add_worker(void* cls, endpoint_t* ep, const char* host, hostattrs_t* attrs)
|
|||
return -EINVAL;
|
||||
}
|
||||
|
||||
w = calloc(1, sizeof(*w));
|
||||
if (w == NULL) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
hconfig = find_matched_hostconfig(c, host);
|
||||
if (hconfig == NULL) {
|
||||
return -errno;
|
||||
}
|
||||
|
||||
worker.host.attrs = attrs;
|
||||
worker.host->attrs = attrs;
|
||||
|
||||
w = create_obj_by_typename(&(c->objmgr), "xworker", &worker);
|
||||
if (w == NULL) {
|
||||
w->host = makeWorker(worker.host);
|
||||
if (w->host == NULL) {
|
||||
return -errno;
|
||||
}
|
||||
|
||||
/* we should hold the update lock */
|
||||
/* If admin makes the host in locked or closed, we need keep this */
|
||||
w->host.status &= ~XCE_WORKER_UNAVAIL; /* status OK */
|
||||
w->host->status &= ~XCE_WORKER_UNAVAIL; /* status OK */
|
||||
w->ep = ep;
|
||||
|
||||
/* override host type? */
|
||||
if (strcmp(hconfig->hosttype, "!") != 0) {
|
||||
obj_deref(w->host.attrs->hosttype);
|
||||
w->host.attrs->hosttype = create_obj_by_typename(
|
||||
&(c->objmgr), "xstring", hconfig->hosttype);
|
||||
dereference(w->host->attrs->hosttype);
|
||||
w->host->attrs->hosttype = makeString(hconfig->hosttype);
|
||||
}
|
||||
|
||||
/* override host model */
|
||||
if (strcmp(hconfig->hostmodel, "!") != 0) {
|
||||
obj_deref(w->host.attrs->hostmodel);
|
||||
w->host.attrs->hostmodel = create_obj_by_typename(
|
||||
&(c->objmgr), "xstring", hconfig->hostmodel);
|
||||
dereference(w->host->attrs->hostmodel);
|
||||
w->host->attrs->hostmodel = makeString(hconfig->hostmodel);
|
||||
}
|
||||
add_hostattrs_resvals(c, w);
|
||||
idx = w->idx;
|
||||
|
|
@ -309,31 +319,31 @@ int add_worker(void* cls, endpoint_t* ep, const char* host, hostattrs_t* attrs)
|
|||
/* using auto detected or pre configured MXJ? */
|
||||
nslots = hconfig->mxj;
|
||||
if (nslots < 0) {
|
||||
nslots = w->host.attrs->maxcpus;
|
||||
nslots = w->host->attrs->maxcpus;
|
||||
}
|
||||
|
||||
set_host_slots(c, w, nslots);
|
||||
|
||||
if (w->host.dispatch_window_config != NULL) {
|
||||
free_timewindow_config(w->host.dispatch_window_config);
|
||||
w->host.dispatch_window_config = NULL;
|
||||
if (w->host->dispatch_window_config != NULL) {
|
||||
free_timewindow_config(w->host->dispatch_window_config);
|
||||
w->host->dispatch_window_config = NULL;
|
||||
}
|
||||
|
||||
if (hconfig->dispatchwindow != NULL) {
|
||||
w->host.dispatch_window_config
|
||||
w->host->dispatch_window_config
|
||||
= dup_timewindow_config(hconfig->dispatchwindow);
|
||||
}
|
||||
|
||||
if (w->host.thresholds != NULL) {
|
||||
free_resource_thresholds(w->host.thresholds, w->host.nthresholds);
|
||||
w->host.nthresholds = 0;
|
||||
w->host.thresholds = NULL;
|
||||
if (w->host->thresholds != NULL) {
|
||||
free_resource_thresholds(w->host->thresholds, w->host->nthresholds);
|
||||
w->host->nthresholds = 0;
|
||||
w->host->thresholds = NULL;
|
||||
}
|
||||
|
||||
if (hconfig->thresholds != NULL) {
|
||||
w->host.thresholds = dup_resource_thresholds(hconfig->thresholds,
|
||||
hconfig->nthresholds);
|
||||
w->host.nthresholds = hconfig->nthresholds;
|
||||
w->host->thresholds = dup_resource_thresholds(hconfig->thresholds,
|
||||
hconfig->nthresholds);
|
||||
w->host->nthresholds = hconfig->nthresholds;
|
||||
}
|
||||
|
||||
/* add bool resources to host */
|
||||
|
|
@ -354,20 +364,24 @@ int restore_worker(void* cls, xce_worker_t host)
|
|||
/* do work in add_worker() doing for normal worker join */
|
||||
/* clang-format off */
|
||||
worker_t worker = {
|
||||
.host = {
|
||||
.host = &(xce_worker_t){
|
||||
.name = (char*)host.name,
|
||||
.status = host.status,
|
||||
},
|
||||
};
|
||||
/* clang-format on */
|
||||
|
||||
w = create_obj_by_typename(&(c->objmgr), "xworker", &worker);
|
||||
w = calloc(1, sizeof(*w));
|
||||
if (w == NULL) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
w->host = makeWorker(worker.host);
|
||||
if (w->host == NULL) {
|
||||
return -errno;
|
||||
}
|
||||
add_hostattrs_resvals(c, w);
|
||||
idx = w->idx;
|
||||
w->host.status |= XCE_WORKER_UNAVAIL;
|
||||
w->host->status |= XCE_WORKER_UNAVAIL;
|
||||
|
||||
DEREF_OBJ(w);
|
||||
|
||||
|
|
@ -432,12 +446,17 @@ int on_worker_join(void* cls, endpoint_t* ep)
|
|||
|
||||
int get_resval(cluster_t* c, char* resname, char* host, xce_val_t* val)
|
||||
{
|
||||
xce_resource_t* r;
|
||||
xce_resource_t* r = NULL;
|
||||
zarray_t* array = NULL;
|
||||
xce_val_t* v = NULL;
|
||||
worker_t* w = NULL;
|
||||
int rc = 0;
|
||||
|
||||
rc = key_find(c->resmgr, (void*)resname, (void**)&r);
|
||||
if (rc < 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
r = resmgr_lockres(&(c->resmgr), resname, OBJREF_READ);
|
||||
if (r == NULL) {
|
||||
return -ENOENT;
|
||||
}
|
||||
|
|
@ -449,13 +468,15 @@ int get_resval(cluster_t* c, char* resname, char* host, xce_val_t* val)
|
|||
return -EINVAL;
|
||||
}
|
||||
|
||||
w = workermgr_lock(&(c->workermgr), host, OBJREF_READ);
|
||||
rc = key_find(c->workermgr, (void*)host, (void**)&w);
|
||||
if (rc < 0) {
|
||||
return rc;
|
||||
}
|
||||
if (w == NULL) {
|
||||
DEREF_OBJ(r);
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
array = &(w->host.resvals);
|
||||
array = &(w->host->resvals);
|
||||
} else {
|
||||
array = &(c->sharedinst);
|
||||
}
|
||||
|
|
@ -464,15 +485,11 @@ int get_resval(cluster_t* c, char* resname, char* host, xce_val_t* val)
|
|||
v = (xce_val_t*)array->data[r->idx];
|
||||
}
|
||||
|
||||
obj_deref(r);
|
||||
|
||||
if (v == NULL) {
|
||||
DEREF_OBJ(w);
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
memcpy(val, v, sizeof(*val));
|
||||
DEREF_OBJ(w);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
@ -480,7 +497,7 @@ int mark_worker_unavail(cluster_t* c, worker_t* w)
|
|||
{
|
||||
xce_run_hooks(&(c->hooksys), XCE_CONTROLLER_HOOK_WORKER, HOOK_BEFORE_EVENT,
|
||||
HOOK_DETAIL_WORKER_DEAD, c, w);
|
||||
w->host.status |= XCE_WORKER_UNAVAIL;
|
||||
w->host->status |= XCE_WORKER_UNAVAIL;
|
||||
|
||||
xce_run_hooks(&(c->hooksys), XCE_CONTROLLER_HOOK_WORKER, HOOK_AFTER_EVENT,
|
||||
HOOK_DETAIL_WORKER_DEAD, c, w);
|
||||
|
|
@ -491,7 +508,7 @@ int mark_worker_back(cluster_t* c, worker_t* w)
|
|||
{
|
||||
xce_run_hooks(&(c->hooksys), XCE_CONTROLLER_HOOK_WORKER, HOOK_BEFORE_EVENT,
|
||||
HOOK_DETAIL_WORKER_UPDATE, c, w);
|
||||
w->host.status &= ~XCE_WORKER_UNAVAIL;
|
||||
w->host->status &= ~XCE_WORKER_UNAVAIL;
|
||||
|
||||
xce_run_hooks(&(c->hooksys), XCE_CONTROLLER_HOOK_WORKER, HOOK_AFTER_EVENT,
|
||||
HOOK_DETAIL_WORKER_UPDATE, c, w);
|
||||
|
|
@ -501,6 +518,7 @@ int mark_worker_back(cluster_t* c, worker_t* w)
|
|||
int handle_worker_leave(cluster_t* c, int idx)
|
||||
{
|
||||
worker_t* w = NULL;
|
||||
int rc;
|
||||
|
||||
TRACE("%s worker %d broken connection", __func__, idx);
|
||||
|
||||
|
|
@ -514,7 +532,11 @@ int handle_worker_leave(cluster_t* c, int idx)
|
|||
return -errno;
|
||||
}
|
||||
|
||||
w = workermgr_lock_byid(&(c->workermgr), idx, OBJREF_UPDATE);
|
||||
rc = vget(c->workermgr, idx, (void**)&w);
|
||||
if (rc < 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
if (w == NULL) {
|
||||
ERROR("fail to find worker by id %d", idx);
|
||||
SET_ERROR(E_XCE_BAD_WORKER);
|
||||
|
|
@ -539,7 +561,12 @@ int worker_ctrl(cluster_t* c, xce_hostctrl_t* ctrl)
|
|||
return -EINVAL;
|
||||
}
|
||||
TRACE("%s worker_ctrl worker %s", __func__, ctrl->hostname);
|
||||
w = workermgr_lock(&(c->workermgr), ctrl->hostname, OBJREF_UPDATE);
|
||||
|
||||
rc = key_find(c->workermgr, (void*)ctrl->hostname, (void**)&w);
|
||||
if (rc < 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
if (w == NULL) {
|
||||
PERROR("workermgr_lock");
|
||||
return -ENOENT;
|
||||
|
|
@ -547,16 +574,16 @@ int worker_ctrl(cluster_t* c, xce_hostctrl_t* ctrl)
|
|||
|
||||
switch (ctrl->action) {
|
||||
case HOST_OPEN:
|
||||
if (!(w->host.status & XCE_WORKER_CLOSED)) {
|
||||
if (!(w->host->status & XCE_WORKER_CLOSED)) {
|
||||
goto clean;
|
||||
}
|
||||
w->host.status &= ~XCE_WORKER_CLOSED;
|
||||
w->host->status &= ~XCE_WORKER_CLOSED;
|
||||
break;
|
||||
case HOST_CLOSE:
|
||||
if (w->host.status & XCE_WORKER_CLOSED) {
|
||||
if (w->host->status & XCE_WORKER_CLOSED) {
|
||||
goto clean;
|
||||
}
|
||||
w->host.status |= XCE_WORKER_CLOSED;
|
||||
w->host->status |= XCE_WORKER_CLOSED;
|
||||
break;
|
||||
default:
|
||||
rc = -1;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue