diff options
author | Andreas Baumann <mail@andreasbaumann.cc> | 2014-09-20 12:00:21 +0200 |
---|---|---|
committer | Andreas Baumann <mail@andreasbaumann.cc> | 2014-09-20 12:00:21 +0200 |
commit | 0361d622ec13ebd5e6366f660826432e344c75c7 (patch) | |
tree | 5a39fa91094b96a82c8003fc8d6e1bd426b606a0 /src/coordinator.c | |
parent | bce9c6b26500a2d225faacf83f21215dab86b736 (diff) | |
download | biruda-0361d622ec13ebd5e6366f660826432e344c75c7.tar.gz biruda-0361d622ec13ebd5e6366f660826432e344c75c7.tar.bz2 |
added arch in coodinator and some cleanup there
Diffstat (limited to 'src/coordinator.c')
-rw-r--r-- | src/coordinator.c | 77 |
1 files changed, 58 insertions, 19 deletions
diff --git a/src/coordinator.c b/src/coordinator.c index 4439e21..37ac4bc 100644 --- a/src/coordinator.c +++ b/src/coordinator.c @@ -23,6 +23,59 @@ static pthread_t coordinator_thread; static int coordinator_sock; static int coordinator_must_terminate = 0; +static char *create_discover_answer( ) +{ + json_object *obj = json_object_new_object( ); + json_object *op = json_object_new_string( "register" ); + json_object_object_add( obj, "op", op ); + + /* we are a coordinator */ + json_object *role = json_object_new_string( "coordinator" ); + json_object_object_add( obj, "role", role ); + + /* return hostname for unique identification (maybe better + * or additionally the MAC of the first interface or hostid?) + */ + char hostname[100]; + gethostname( hostname, sizeof( hostname ) ); + json_object *host = json_object_new_string( hostname ); + json_object_object_add( obj, "host", host ); + + /* number of CPUs, important so we don't overload the + * server (TODO: should maybe be configurable how many + * CPUs we want to use in absolute, percentage use or + * leave free + */ + unsigned int nofCpus = system_available_cpus( ); + json_object *cpus = json_object_new_int( nofCpus ); + json_object_object_add( obj, "cpus", cpus ); + + /* Operating system running on the coordinator, this is + * important so we know what we can run on the system + * directly + */ + char os_name[100]; + system_os( os_name, sizeof( os_name ) ); + json_object *os = json_object_new_string( os_name ); + json_object_object_add( obj, "os", os ); + + /* system architecture, important whether we can run chrooted + * environments as workers directly without an virtualizer + */ + char machine_arch[100]; + system_arch( machine_arch, sizeof( machine_arch ) ); + json_object *arch = json_object_new_string( machine_arch ); + json_object_object_add( obj, "arch", arch ); + + /* produce message as string, caller must free it */ + const char *msg = json_object_to_json_string( obj ); + char *res = strdup( msg ); + + json_object_put( obj ); + + return res; +} + static void *coordinator_func( void *thread_data ) { char *control = (char *)thread_data; @@ -48,24 +101,9 @@ static void *coordinator_func( void *thread_data ) const char *op = json_object_get_string( op_obj ); if( strcmp( op, "discover" ) == 0 ) { - json_object *obj = json_object_new_object( ); - json_object *op = json_object_new_string( "register" ); - json_object_object_add( obj, "op", op ); - json_object *role = json_object_new_string( "coordinator" ); - json_object_object_add( obj, "role", role ); - char hostname[100]; - gethostname( hostname, sizeof( hostname ) ); - json_object *host = json_object_new_string( hostname ); - json_object_object_add( obj, "host", host ); - unsigned int nofCpus = system_available_cpus( ); - json_object *cpus = json_object_new_int( nofCpus ); - json_object_object_add( obj, "cpus", cpus ); - char cpe_name[100]; - system_cpe_name( cpe_name, sizeof( cpe_name ) ); - json_object *os = json_object_new_string( cpe_name ); - json_object_object_add( obj, "os", os ); - const char *msg = json_object_to_json_string( obj ); - int msg_size = strlen( msg ) + 1; + char *msg = create_discover_answer( ); + size_t msg_size = strlen( msg ) + 1; + printf( "coordinator send: %s\n", msg ); bytes = nn_send( coordinator_sock, msg, msg_size, 0 ); if( bytes < 0 ) { @@ -80,7 +118,8 @@ static void *coordinator_func( void *thread_data ) if( bytes != msg_size ) { fprintf( stderr, "ERROR: truncated message!" ); } - json_object_put( obj ); + + free( msg ); } json_object_put( recv_obj ); |