diff options
author | Andreas Baumann <mail@andreasbaumann.cc> | 2014-11-16 20:16:01 +0100 |
---|---|---|
committer | Andreas Baumann <mail@andreasbaumann.cc> | 2014-11-16 20:16:01 +0100 |
commit | 36a9558737abb4fc6440903361a6c175a4140f35 (patch) | |
tree | 1d08e3f3ecdf41ebecf017222cb1cbcf2edd09b5 /src/master.c | |
parent | 3ecaed99580f378fbcb2598b2570c65d0f3ebc99 (diff) | |
download | biruda-36a9558737abb4fc6440903361a6c175a4140f35.tar.gz biruda-36a9558737abb4fc6440903361a6c175a4140f35.tar.bz2 |
workers are communicated from coordinator to master during registration now
status shows worker states too
Diffstat (limited to 'src/master.c')
-rw-r--r-- | src/master.c | 46 |
1 files changed, 42 insertions, 4 deletions
diff --git a/src/master.c b/src/master.c index 7933c0b..d93427c 100644 --- a/src/master.c +++ b/src/master.c @@ -32,7 +32,7 @@ static void recompute_coordinator_states( void ) } } -static void register_coordinator( json_object *obj ) +static int register_coordinator( json_object *obj ) { json_object *host_obj; json_object_object_get_ex( obj, "host", &host_obj ); @@ -58,7 +58,7 @@ static void register_coordinator( json_object *obj ) time( &coord->lastAlive ); coord->alive = true; fprintf( stderr, "master: already registered coordinator from host '%s' (%d)\n", host, pos ); - return; + return 0; } } @@ -66,7 +66,7 @@ static void register_coordinator( json_object *obj ) if( pos == MAX_COORDINATORS ) { fprintf( stderr, "Can't accept more coordinators, limit reached!\n" ); - return; + return -1; } coordinator_t *coord = &coordinator[pos]; @@ -83,6 +83,40 @@ static void register_coordinator( json_object *obj ) json_object *worker_array; json_object_object_get_ex( obj, "workers", &worker_array ); coord->nof_workers = json_object_array_length( worker_array ); + + if( coord->nof_workers >= MAX_WORKERS ) { + fprintf( stderr, "Can't define more workers per coordinator, limit reached!\n" ); + return -1; + } + + for( int i = 0; i < coord->nof_workers; i++ ) { + json_object *worker_obj; + worker_obj= json_object_array_get_idx( worker_array, i ); + + json_object *name_obj; + json_object_object_get_ex( worker_obj, "name", &name_obj ); + const char *name = json_object_get_string( name_obj ); + + json_object *mode_obj; + json_object_object_get_ex( worker_obj, "mode", &mode_obj ); + const char *mode = json_object_get_string( mode_obj ); + + json_object *command_obj; + json_object_object_get_ex( worker_obj, "command", &command_obj ); + const char *command = json_object_get_string( command_obj ); + + worker_t *w = &coord->worker[i]; + + w->name = strdup( name ); + w->mode = worker_execution_mode_from_str( mode ); + if( command != NULL ) { + w->command = strdup( command ); + } else { + w->mode = WORKER_EXECUTION_DISABLED; + } + } + + return 0; } static void *master_func( void *thread_data ) @@ -149,7 +183,11 @@ NEXT_DISCOVER: json_object_object_get_ex( recv_obj, "role", &role_obj ); const char *role = json_object_get_string( role_obj ); if( strcmp( role, "coordinator" ) == 0 ) { - register_coordinator( recv_obj ); + if( register_coordinator( recv_obj ) < 0 ) { + fprintf( stderr, "Termiating master because out of resources!\n" ); + master_must_terminate = 1; + continue; + } } } |