From 96c10ed5c6f7eaac8d559cc9187d29ca9c95bce8 Mon Sep 17 00:00:00 2001 From: tewk <tewk@unknown> Date: Tue, 18 Jun 2002 16:07:51 +0000 Subject: [PATCH] Implemented new slurm_api_init that takes a configuration object containing pri and sec controller address and the default port to connect to --- src/common/slurm_protocol_api.c | 66 ++++++++++++++++++++------------ src/common/slurm_protocol_api.h | 13 +++---- src/common/slurm_protocol_defs.h | 2 +- 3 files changed, 48 insertions(+), 33 deletions(-) diff --git a/src/common/slurm_protocol_api.c b/src/common/slurm_protocol_api.c index 6ca4259eee0..44bc384d449 100644 --- a/src/common/slurm_protocol_api.c +++ b/src/common/slurm_protocol_api.c @@ -17,7 +17,40 @@ /* EXTERNAL VARIABLES */ /* #DEFINES */ +#define SLURM_PORT 7000 +#define SLURM_PROTOCOL_DEFAULT_PORT 7000 +#define SLURM_PROTOCOL_DEFAULT_PRIMARY_CONTROLLER "localhost" +#define SLURM_PROTOCOL_DEFAULT_SECONDARY_CONTROLLER "localhost" +/* STATIC VARIABLES */ +static slurm_protocol_config_t * proto_conf = NULL ; +static slurm_protocol_config_t proto_conf_default ; + + +/************************/ +/***** API init functions */ +/************************/ +int slurm_api_init ( slurm_protocol_config_t * protocol_conf ) +{ + proto_conf = protocol_conf ; + return SLURM_SUCCESS ; +} + +int slurm_api_cleanup ( ) +{ + return SLURM_SUCCESS ; +} + +int slurm_api_set_defaults ( ) +{ + if ( proto_conf == NULL ) + { + slurm_set_addr ( & proto_conf_default . primary_controller , SLURM_PROTOCOL_DEFAULT_PORT , SLURM_PROTOCOL_DEFAULT_PRIMARY_CONTROLLER ) ; + slurm_set_addr ( & proto_conf_default . secondary_controller , SLURM_PROTOCOL_DEFAULT_PORT , SLURM_PROTOCOL_DEFAULT_SECONDARY_CONTROLLER ) ; + + } + return SLURM_SUCCESS ; +} /************************/ /***** msg functions */ @@ -81,19 +114,15 @@ slurm_fd slurm_open_msg_conn ( slurm_addr * slurm_address ) slurm_fd slurm_open_controller_conn ( ) { slurm_fd connection_fd ; - slurm_addr primary_destination_address ; - slurm_addr secondary_destination_address ; - - /* set slurm_addr structures */ - slurm_set_addr ( & primary_destination_address , SLURM_PORT , PRIMARY_SLURM_CONTROLLER ) ; - slurm_set_addr ( & secondary_destination_address , SLURM_PORT , SECONDARY_SLURM_CONTROLLER ) ; + slurm_api_set_defaults ( ) ; + /* try to send to primary first then secondary */ - if ( ( connection_fd = slurm_open_msg_conn ( & primary_destination_address ) ) == SLURM_SOCKET_ERROR ) + if ( ( connection_fd = slurm_open_msg_conn ( & proto_conf -> primary_controller ) ) == SLURM_SOCKET_ERROR ) { info ( "Send message to primary controller failed" ) ; - if ( ( connection_fd = slurm_open_msg_conn ( & secondary_destination_address ) ) == SLURM_SOCKET_ERROR ) + if ( ( connection_fd = slurm_open_msg_conn ( & proto_conf -> secondary_controller ) ) == SLURM_SOCKET_ERROR ) { info ( "Send messge to secondary controller failed" ) ; } @@ -170,19 +199,12 @@ int slurm_receive_msg ( slurm_fd open_fd , slurm_msg_t * msg ) int slurm_send_controller_msg ( slurm_fd open_fd , slurm_msg_t * msg ) { int rc ; - slurm_addr primary_destination_address ; - slurm_addr secondary_destination_address ; - - /* set slurm_addr structures */ - slurm_set_addr ( & primary_destination_address , SLURM_PORT , PRIMARY_SLURM_CONTROLLER ) ; - slurm_set_addr ( & secondary_destination_address , SLURM_PORT , SECONDARY_SLURM_CONTROLLER ) ; - /* try to send to primary first then secondary */ - msg -> address = primary_destination_address ; + msg -> address = proto_conf -> primary_controller ; if ( (rc = slurm_send_node_msg ( open_fd , msg ) ) == SLURM_SOCKET_ERROR ) { info ( "Send message to primary controller failed" ) ; - msg -> address = secondary_destination_address ; + msg -> address = proto_conf -> secondary_controller ; if ( (rc = slurm_send_node_msg ( open_fd , msg ) ) == SLURM_SOCKET_ERROR ) { info ( "Send messge to secondary controller failed" ) ; @@ -276,19 +298,13 @@ int slurm_receive_buffer ( slurm_fd open_fd , slurm_addr * source_address , slur int slurm_send_controller_buffer ( slurm_fd open_fd , slurm_msg_type_t msg_type , char * data_buffer , size_t buf_len ) { int rc ; - slurm_addr primary_destination_address ; - slurm_addr secondary_destination_address ; - - /* set slurm_addr structures */ - slurm_set_addr ( & primary_destination_address , SLURM_PORT , PRIMARY_SLURM_CONTROLLER ) ; - slurm_set_addr ( & secondary_destination_address , SLURM_PORT , SECONDARY_SLURM_CONTROLLER ) ; /* try to send to primary first then secondary */ - if ( ( rc = slurm_send_node_buffer ( open_fd , & primary_destination_address , msg_type , data_buffer , buf_len ) ) == SLURM_SOCKET_ERROR ) + if ( ( rc = slurm_send_node_buffer ( open_fd , & proto_conf -> primary_controller , msg_type , data_buffer , buf_len ) ) == SLURM_SOCKET_ERROR ) { info ( "Send message to primary controller failed" ) ; - if ( ( rc = slurm_send_node_buffer ( open_fd , & secondary_destination_address , msg_type , data_buffer , buf_len ) ) == SLURM_SOCKET_ERROR ) + if ( ( rc = slurm_send_node_buffer ( open_fd , & proto_conf -> secondary_controller , msg_type , data_buffer , buf_len ) ) == SLURM_SOCKET_ERROR ) { info ( "Send messge to secondary controller failed" ) ; } diff --git a/src/common/slurm_protocol_api.h b/src/common/slurm_protocol_api.h index 77328ca8ec6..d56237ddb57 100644 --- a/src/common/slurm_protocol_api.h +++ b/src/common/slurm_protocol_api.h @@ -21,15 +21,14 @@ #include <src/common/slurm_protocol_defs.h> #include <src/common/slurm_protocol_errno.h> -#define SLURM_PORT 7000 -/*#define PRIMARY_SLURM_CONTROLLER "pri_slrumctld.llnl.gov" */ -/*#define SECONDARY_SLURM_CONTROLLER "sec_slrumctld.llnl.gov" */ -#define PRIMARY_SLURM_CONTROLLER "localhost" -#define SECONDARY_SLURM_CONTROLLER "localhost" -//WHAT ABOUT THESE INCLUDES + /* high level routines */ +/* API init routines */ +int slurm_api_init ( slurm_protocol_config_t * protocol_conf ) ; +int slurm_api_cleanup ( ) ; + /* msg functions */ /* In the socket implementation it creates a socket, binds to it, and listens for connections. @@ -130,11 +129,11 @@ int inline slurm_close_stream ( slurm_fd open_fd ) ; /* Low level routines */ /* msg functions +*/ int slurm_receive_buffer ( slurm_fd open_fd , slurm_addr * source_address , slurm_msg_type_t * msg_type , char * data_buffer , size_t buf_len ) ; int slurm_send_controller_buffer ( slurm_fd open_fd , slurm_msg_type_t msg_type , char * data_buffer , size_t buf_len ) ; int slurm_send_node_buffer ( slurm_fd open_fd , slurm_addr * destination_address , slurm_msg_type_t msg_type , char * data_buffer , size_t buf_len ) ; -*/ /* Address Conversion Functions */ diff --git a/src/common/slurm_protocol_defs.h b/src/common/slurm_protocol_defs.h index 9f622813e09..cf78569ab13 100644 --- a/src/common/slurm_protocol_defs.h +++ b/src/common/slurm_protocol_defs.h @@ -89,7 +89,7 @@ typedef struct slurm_protocol_config { slurm_addr primary_controller; slurm_addr secondary_controller; -} +} slurm_protocol_config_t ; /*core api protocol message structures */ typedef struct slurm_protocol_header -- GitLab