forked from lei.chen/myxce
save works
This commit is contained in:
parent
b748e30d20
commit
f4b1ba4cd7
21 changed files with 373 additions and 324 deletions
|
|
@ -70,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) {
|
||||
|
|
@ -213,17 +213,16 @@ 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->hosttype } },
|
||||
{ .which = Value_u_svalue,
|
||||
.u = { .svalue = w->host->attrs->hostmodel } },
|
||||
.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] },
|
||||
|
|
@ -266,7 +265,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 = &(xce_worker_t){
|
||||
.host = (xce_worker_t){
|
||||
.name = (char*)host,
|
||||
}
|
||||
};
|
||||
|
|
@ -290,28 +289,28 @@ int add_worker(void* cls, endpoint_t* ep, const char* host, hostattrs_t* attrs)
|
|||
return -errno;
|
||||
}
|
||||
|
||||
worker.host->attrs = attrs;
|
||||
worker.host.attrs = attrs;
|
||||
|
||||
w->host = makeWorker(worker.host);
|
||||
if (w->host == NULL) {
|
||||
w = makeWorker(c->workermgr, &(worker.host));
|
||||
if (w == 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) {
|
||||
dereference(w->host->attrs->hosttype);
|
||||
w->host->attrs->hosttype = makeString(hconfig->hosttype);
|
||||
dereference(w->host.attrs->hosttype);
|
||||
w->host.attrs->hosttype = makeString(hconfig->hosttype);
|
||||
}
|
||||
|
||||
/* override host model */
|
||||
if (strcmp(hconfig->hostmodel, "!") != 0) {
|
||||
dereference(w->host->attrs->hostmodel);
|
||||
w->host->attrs->hostmodel = makeString(hconfig->hostmodel);
|
||||
dereference(w->host.attrs->hostmodel);
|
||||
w->host.attrs->hostmodel = makeString(hconfig->hostmodel);
|
||||
}
|
||||
add_hostattrs_resvals(c, w);
|
||||
idx = w->idx;
|
||||
|
|
@ -319,31 +318,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 */
|
||||
|
|
@ -361,27 +360,18 @@ int restore_worker(void* cls, xce_worker_t host)
|
|||
cluster_t* c = (cluster_t*)cls;
|
||||
int idx = 0;
|
||||
worker_t* w = NULL;
|
||||
/* do work in add_worker() doing for normal worker join */
|
||||
/* clang-format off */
|
||||
worker_t worker = {
|
||||
.host = &(xce_worker_t){
|
||||
.name = (char*)host.name,
|
||||
.status = host.status,
|
||||
},
|
||||
};
|
||||
/* clang-format on */
|
||||
|
||||
w = calloc(1, sizeof(*w));
|
||||
if (w == NULL) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
w->host = makeWorker(worker.host);
|
||||
if (w->host == NULL) {
|
||||
w = makeWorker(c->workermgr, &host);
|
||||
if (w == 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);
|
||||
|
||||
|
|
@ -476,7 +466,7 @@ int get_resval(cluster_t* c, char* resname, char* host, xce_val_t* val)
|
|||
return -ENOENT;
|
||||
}
|
||||
|
||||
array = &(w->host->resvals);
|
||||
array = &(w->host.resvals);
|
||||
} else {
|
||||
array = &(c->sharedinst);
|
||||
}
|
||||
|
|
@ -497,7 +487,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);
|
||||
|
|
@ -508,7 +498,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);
|
||||
|
|
@ -574,16 +564,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