initial work of api server
This commit is contained in:
parent
280c22671f
commit
70970434ca
13 changed files with 394 additions and 9 deletions
140
src/controller/apiserver.c
Normal file
140
src/controller/apiserver.c
Normal file
|
|
@ -0,0 +1,140 @@
|
|||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "cluster.h"
|
||||
#include "controller.capnp.h"
|
||||
#include "request.h"
|
||||
#include "xce/types.h"
|
||||
|
||||
static int xce_apiserver_push_configs(cluster_t* c, endpoint_t* ep)
|
||||
{
|
||||
xce_configdata_t configdata;
|
||||
int rc = 0;
|
||||
|
||||
memset(&configdata, 0x0, sizeof(configdata));
|
||||
configdata.data.clusterconfig = c->myconf->cluster_config;
|
||||
configdata.data_which = ConfigData_data_clusterconfig;
|
||||
|
||||
rc = xce_pushconfig_req(ep, c->myhost, &configdata);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
static int xce_apiserver_push_workers(cluster_t* c, endpoint_t* ep)
|
||||
{
|
||||
xce_data_t data;
|
||||
xce_workers_data_t workers
|
||||
= { .n_total = 0, .pos = 0, .count = 0, .workers = NULL };
|
||||
int i, rc = 0;
|
||||
|
||||
memset(&data, 0x0, sizeof(data));
|
||||
|
||||
data.table = Data_data_schedworkers;
|
||||
data.data.workers = &workers;
|
||||
|
||||
collect_workers(c, (collect_check_fn_t)check_worker_, &(workers.n_total),
|
||||
&(workers.workers));
|
||||
workers.count = workers.n_total;
|
||||
|
||||
rc = xce_push_data_req(ep, c->myhost, &data, check_controller, c, 100);
|
||||
|
||||
/* free up collected resource value which used
|
||||
passed to scheduler
|
||||
*/
|
||||
for (i = 0; i < workers.n_total; i++) {
|
||||
xce_worker_t* w = workers.workers[i];
|
||||
|
||||
free_resval_with_idx_list(&(w->resvals_to_sched), w->nresvals_to_sched);
|
||||
}
|
||||
|
||||
deref_objs(workers.n_total, (void**)workers.workers);
|
||||
FREEUP(workers.workers);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int check_job_(xce_job_t* j)
|
||||
{
|
||||
if (j == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int xce_apiserver_push_jobs(cluster_t* c, endpoint_t* ep)
|
||||
{
|
||||
xce_data_t data;
|
||||
xce_jobs_data_t jobs = { .n_total = 0, .pos = 0, .count = 0, .jobs = NULL };
|
||||
int rc = 0;
|
||||
|
||||
memset(&data, 0x0, sizeof(data));
|
||||
|
||||
data.table = Data_data_schedjobs;
|
||||
data.data.jobs = &jobs;
|
||||
|
||||
collect_jobs(c, (collect_check_fn_t)check_job_, &(jobs.n_total),
|
||||
&(jobs.jobs));
|
||||
jobs.count = jobs.n_total;
|
||||
|
||||
rc = xce_push_data_req(c->sched.ep, c->myhost, &data, check_controller, c,
|
||||
100);
|
||||
deref_objs(jobs.n_total, (void**)jobs.jobs);
|
||||
FREEUP(jobs.jobs);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int apiserver_job_hook_fun(int type, int situation, int detail,
|
||||
void* data, va_list ap)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int apiserver_worker_hook_fun(int type, int situation, int detail,
|
||||
void* data, va_list ap)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int apiserver_resource_hook_fun(int type, int situation, int detail,
|
||||
void* data, va_list ap)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int apiserver_queue_hook_fun(int type, int situation, int detail,
|
||||
void* data, va_list ap)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int on_apiserver_join(cluster_t* c, endpoint_t* ep)
|
||||
{
|
||||
/* FIXME: use lock to protect this later */
|
||||
static int hook_installed = 0;
|
||||
|
||||
xce_apiserver_push_configs(c, ep);
|
||||
xce_apiserver_push_workers(c, ep);
|
||||
xce_apiserver_push_jobs(c, ep);
|
||||
|
||||
if (!hook_installed) {
|
||||
hook_installed = 1;
|
||||
|
||||
xce_add_hook(&(c->hooksys), XCE_CONTROLLER_HOOK_JOB,
|
||||
(hook_fn_t)apiserver_job_hook_fun, NULL);
|
||||
xce_add_hook(&(c->hooksys), XCE_CONTROLLER_HOOK_WORKER,
|
||||
(hook_fn_t)apiserver_worker_hook_fun, NULL);
|
||||
xce_add_hook(&(c->hooksys), XCE_CONTROLLER_HOOK_RESOURCE,
|
||||
(hook_fn_t)apiserver_resource_hook_fun, NULL);
|
||||
xce_add_hook(&(c->hooksys), XCE_CONTROLLER_HOOK_QUEUE,
|
||||
(hook_fn_t)apiserver_queue_hook_fun, NULL);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int handle_apiserver_leave(cluster_t* c, endpoint_t* ep)
|
||||
{
|
||||
/* FIXME */
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue