summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Baumann <mail@andreasbaumann.cc>2014-11-23 19:49:11 +0100
committerAndreas Baumann <mail@andreasbaumann.cc>2014-11-23 19:49:11 +0100
commita784c8f795f60604a2cd6f9633a213e891e4d7df (patch)
tree2e115572d1bc28243237c5a525548b6a7206d7cd
parent7b6d970a87fbfc2079ba98a26c0b457cc8cd05ee (diff)
downloadbiruda-a784c8f795f60604a2cd6f9633a213e891e4d7df.tar.gz
biruda-a784c8f795f60604a2cd6f9633a213e891e4d7df.tar.bz2
got to POSTing the start command to the master, now we have to design the messaging below
-rw-r--r--PROTOCOL12
-rw-r--r--src/3rdParty/http_tiny/http_lib.c24
-rw-r--r--src/3rdParty/http_tiny/http_lib.h4
-rw-r--r--src/biruda.c25
-rw-r--r--src/master.c5
-rw-r--r--src/master.h2
-rw-r--r--src/webserver.c90
7 files changed, 116 insertions, 46 deletions
diff --git a/PROTOCOL b/PROTOCOL
index 35ed369..14b0691 100644
--- a/PROTOCOL
+++ b/PROTOCOL
@@ -45,3 +45,15 @@ The coordinators also send all known workers to the master as a list:
{ "workers": { "name": "worker1", "mode": "direct", "command": "build.sh" }
{ "name": "worker2", "mode": "direct", "command": "build.sh" }
}
+
+Coordinator operations:
+-----------------------
+
+{ "op": "start", "rule": "master", "worker": "worker1" }
+{ "op": "stop", "rule": "master", "worker": "worker1" }
+{ "op": "kill", "rule": "master", "worker": "worker1" }
+
+The master sends this as survey call to all coordinators, the coordinator
+who feels responsible for this working with start/stop/kill the worker
+with the given name.
+
diff --git a/src/3rdParty/http_tiny/http_lib.c b/src/3rdParty/http_tiny/http_lib.c
index f11df19..93743a7 100644
--- a/src/3rdParty/http_tiny/http_lib.c
+++ b/src/3rdParty/http_tiny/http_lib.c
@@ -297,22 +297,28 @@ http_retcode http_put(filename, data, length, overwrite, type)
* limitations: filename is truncated to first 256 characters
* and type to 64.
*/
-http_retcode http_post(filename, data, length, type)
+http_retcode http_post(filename, data_in, length_in, type_in, data_out, length_out, type_out)
char *filename; /* name of the ressource to create */
- char *data; /* pointer to the data to send */
- int length; /* length of the data to send */
- char *type; /* type of the data, if NULL default type is used */
+ char *data_in; /* pointer to the data to send */
+ int length_in; /* length of the data to send */
+ char *type_in; /* type of the data, if NULL default type is used */
+ char **data_out; /* address of a pointer variable which will be set
+ to point toward allocated memory containing read data.*/
+ int *length_out;/* address of integer variable which will be set to
+ length of the read data */
+ char *type_out; /* allocated buffer where the read data type is returned.
+ If NULL, the type is not returned */
{
char header[MAXBUF];
- if (type)
+ if (type_in)
sprintf(header,"Content-length: %d\015\012Content-type: %.64s\015\012",
- length,
- type
+ length_in,
+ type_in
);
else
- sprintf(header,"Content-length: %d\015\012",length
+ sprintf(header,"Content-length: %d\015\012",length_in
);
- return http_query("POST",filename,header,CLOSE, data, length, NULL);
+ return http_query("POST",filename,header,CLOSE, data_out, length_out, type_out);
}
diff --git a/src/3rdParty/http_tiny/http_lib.h b/src/3rdParty/http_tiny/http_lib.h
index cd63c7c..2bc72ab 100644
--- a/src/3rdParty/http_tiny/http_lib.h
+++ b/src/3rdParty/http_tiny/http_lib.h
@@ -69,7 +69,7 @@ http_retcode http_delete(char *filename) ;
http_retcode http_head(char *filename, int *plength, char *typebuf);
-http_retcode http_post(char *filename, char *data, int length,
- char *type) ;
+http_retcode http_post(char *filename, char *data_in, int length_in, char *type_in,
+ char **data_out, int *length_out, char *type_out);
#endif
diff --git a/src/biruda.c b/src/biruda.c
index da8b215..685c3ff 100644
--- a/src/biruda.c
+++ b/src/biruda.c
@@ -411,6 +411,29 @@ static void print_status( )
free( data );
}
+static void start_worker( const char *worker_name )
+{
+ char url[128];
+ snprintf( url, sizeof( url ), "start?op=start&type=worker&name=%s", worker_name );
+ char *data = NULL;
+ int len;
+ http_retcode ret = http_post( url, "", 0, "Content-Type: text/plain",
+ &data, &len, NULL );
+ if( ret == 200 ) {
+ if( strlen( data ) > 0 && data[len-1] == '\n' ) {
+ data[len-1] = '\0';
+ len--;
+ }
+ if( strlen( data ) > 0 && data[len-1] == '\r' ) {
+ data[len-1] = '\0';
+ }
+ print_answer( data );
+ } else {
+ print_error( "ERROR: HTTP error %d", ret );
+ }
+ free( data );
+}
+
static int start_interactive( bool colors )
{
char history_filename[1024];
@@ -503,7 +526,7 @@ static int start_interactive( bool colors )
break;
case WORKER_PARAM:
- printf( "starting worker '%s'\n", line );
+ start_worker( line );
command_state = COMMAND;
break;
}
diff --git a/src/master.c b/src/master.c
index d93427c..73d1d76 100644
--- a/src/master.c
+++ b/src/master.c
@@ -261,3 +261,8 @@ int master_free( )
return 0;
}
+
+int master_start_worker( const char *name )
+{
+ return 0;
+}
diff --git a/src/master.h b/src/master.h
index 06461d9..cdbb621 100644
--- a/src/master.h
+++ b/src/master.h
@@ -8,6 +8,8 @@ int master_init( const char *control );
void master_terminate( int terminate_nano_msg );
int master_free( );
+int master_start_worker( const char *name );
+
#define MAX_COORDINATORS 128
#define MAX_COORDINATOR_AGE 10
diff --git a/src/webserver.c b/src/webserver.c
index a824506..8093ec8 100644
--- a/src/webserver.c
+++ b/src/webserver.c
@@ -14,47 +14,69 @@ static int handle_request( void *cls, struct MHD_Connection *connection,
{
struct MHD_Response *response;
int ret;
-
- if( strcmp( method, "GET" ) != 0 ) {
- return MHD_NO;
- }
-
- fprintf( stderr, "http request: %s\n", url );
+
+ fprintf( stderr, "%s http request: %s\n", method, url );
- char biruda_msg[2048];
- biruda_msg[0] = '\0';
- if( strcmp( url, "/status" ) == 0 ) {
- for( int pos = 0; pos < MAX_COORDINATORS; pos++ ) {
- coordinator_t *c = &coordinator[pos];
- if( c->used ) {
- char part[256];
- snprintf( part, sizeof( part ),
- "coordinator %s %s %s %d %s %lld (%d)\n",
- c->host, c->os, c->arch, c->cpus,
- ( c->alive ? "alive" : "dead" ),
- (long long)c->lastAlive, pos );
- strncat( biruda_msg, part, sizeof( biruda_msg ) );
-
- for( int i = 0; i < c->nof_workers; i++ ) {
- worker_t *w = &c->worker[i];
+ if( strcmp( method, "GET" ) == 0 ) {
+ char biruda_msg[2048];
+ biruda_msg[0] = '\0';
+ if( strcmp( url, "/status" ) == 0 ) {
+ for( int pos = 0; pos < MAX_COORDINATORS; pos++ ) {
+ coordinator_t *c = &coordinator[pos];
+ if( c->used ) {
+ char part[256];
snprintf( part, sizeof( part ),
- "worker %s %s %s (%d)\n",
- w->name, worker_exection_mode_str( w->mode ),
- ( w->command == NULL ? "" : w->command ),
- i );
+ "coordinator %s %s %s %d %s %lld (%d)\n",
+ c->host, c->os, c->arch, c->cpus,
+ ( c->alive ? "alive" : "dead" ),
+ (long long)c->lastAlive, pos );
strncat( biruda_msg, part, sizeof( biruda_msg ) );
+
+ for( int i = 0; i < c->nof_workers; i++ ) {
+ worker_t *w = &c->worker[i];
+ snprintf( part, sizeof( part ),
+ "worker %s %s %s (%d)\n",
+ w->name, worker_exection_mode_str( w->mode ),
+ ( w->command == NULL ? "" : w->command ),
+ i );
+ strncat( biruda_msg, part, sizeof( biruda_msg ) );
+ }
}
}
+ } else {
+ snprintf( biruda_msg, sizeof( biruda_msg ), "Welcome to biruda! Please state your wish..\n" );
}
- } else {
- snprintf( biruda_msg, sizeof( biruda_msg ), "Welcome to biruda! Please state your wish..\n" );
- }
- response = MHD_create_response_from_buffer( strlen( biruda_msg ),
- (void *)biruda_msg, MHD_RESPMEM_MUST_COPY );
- ret = MHD_queue_response( connection, MHD_HTTP_OK, response );
- MHD_destroy_response( response );
-
+ response = MHD_create_response_from_buffer( strlen( biruda_msg ),
+ (void *)biruda_msg, MHD_RESPMEM_MUST_COPY );
+ ret = MHD_queue_response( connection, MHD_HTTP_OK, response );
+ MHD_destroy_response( response );
+
+ } else if( strcmp( method, "POST" ) == 0 ) {
+
+ const char *op = MHD_lookup_connection_value( connection, MHD_GET_ARGUMENT_KIND, "op" );
+
+ printf( "Got POST operation '%s'\n", op );
+
+ if( strcmp( op, "start" ) == 0 ) {
+
+ const char *type = MHD_lookup_connection_value( connection, MHD_GET_ARGUMENT_KIND, "type" );
+
+ printf( "Got POST parameter for type of process '%s'\n", type );
+
+ if( strcmp( type, "worker" ) == 0 ) {
+
+ const char *name = MHD_lookup_connection_value( connection, MHD_GET_ARGUMENT_KIND, "name" );
+
+ printf( "Got POST parameter for starting a worker with name '%s'\n", name );
+
+ master_start_worker( name );
+ }
+ }
+
+ return MHD_NO;
+ }
+
return ret;
}