Skip to content

Commit

Permalink
Merge pull request #294 from bill1600/cnheal
Browse files Browse the repository at this point in the history
Add logic to save parodus connection status in health file
  • Loading branch information
shilpa24balaji authored Apr 4, 2019
2 parents 50176fb + 0962712 commit da6614b
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 6 deletions.
27 changes: 22 additions & 5 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@ int parseCommandLine(int argc,char **argv,ParodusCfg * cfg)
{"client-cert-path", required_argument, 0, 'P'},
{"token-server-url", required_argument, 0, 'U'},
{"crud-config-file", required_argument, 0, 'C'},
{"connection-health-file", required_argument, 0, 'S'},
{"mtls-client-key-path", required_argument, 0, 'K'},
{"mtls-client-cert-path", required_argument, 0,'M'},
{0, 0, 0, 0}
Expand All @@ -382,6 +383,7 @@ int parseCommandLine(int argc,char **argv,ParodusCfg * cfg)
cfg->jwt_algo = 0;
parStrncpy (cfg->jwt_key, "", sizeof(cfg->jwt_key));
cfg->crud_config_file = NULL;
cfg->connection_health_file = NULL;
cfg->client_cert_path = NULL;
cfg->token_server_url = NULL;
cfg->cloud_status = NULL;
Expand All @@ -392,7 +394,7 @@ int parseCommandLine(int argc,char **argv,ParodusCfg * cfg)

/* getopt_long stores the option index here. */
int option_index = 0;
c = getopt_long (argc, argv, "m:s:f:d:r:n:b:u:t:o:i:l:p:e:D:j:a:k:c:T:w:J:46:C:K:M",
c = getopt_long (argc, argv, "m:s:f:d:r:n:b:u:t:o:i:l:p:e:D:j:a:k:c:T:w:J:46:C:S:K:M",
long_options, &option_index);

/* Detect the end of the options. */
Expand Down Expand Up @@ -530,10 +532,15 @@ int parseCommandLine(int argc,char **argv,ParodusCfg * cfg)
ParodusInfo("boot_retry_wait is %d\n",cfg->boot_retry_wait);
break;

case 'C':
cfg->crud_config_file = strdup(optarg);
ParodusInfo("crud_config_file is %s\n", cfg->crud_config_file);
break;
case 'S':
cfg->connection_health_file = strdup(optarg);
ParodusInfo("connection_health_file is %s\n", cfg->connection_health_file);
break;

case 'C':
cfg->crud_config_file = strdup(optarg);
ParodusInfo("crud_config_file is %s\n", cfg->crud_config_file);
break;

case 'P':
cfg->client_cert_path = strdup(optarg);
Expand Down Expand Up @@ -628,6 +635,7 @@ void setDefaultValuesToCfg(ParodusCfg *cfg)
parStrncpy(cfg->webpa_uuid, "1234567-345456546",sizeof(cfg->webpa_uuid));
ParodusPrint("cfg->webpa_uuid is :%s\n", cfg->webpa_uuid);
cfg->crud_config_file = NULL;
cfg->connection_health_file = NULL;
cfg->client_cert_path = NULL;
cfg->token_server_url = NULL;

Expand Down Expand Up @@ -779,6 +787,15 @@ void loadParodusCfg(ParodusCfg * config,ParodusCfg *cfg)
parStrncpy(cfg->webpa_uuid, "1234567-345456546",sizeof(cfg->webpa_uuid));
ParodusPrint("cfg->webpa_uuid is :%s\n", cfg->webpa_uuid);

if(config->connection_health_file != NULL)
{
cfg->connection_health_file = strdup(config->connection_health_file);
}
else
{
ParodusPrint("connection_health_file is NULL. set to empty\n");
}

if(config->crud_config_file != NULL)
{
cfg->crud_config_file = strdup(config->crud_config_file);
Expand Down
1 change: 1 addition & 0 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ typedef struct
char token_read_script[64];
char *client_cert_path;
char *token_server_url;
char *connection_health_file;
char *mtls_client_key_path;
char *mtls_client_cert_path;
char *crud_config_file;
Expand Down
8 changes: 7 additions & 1 deletion src/conn_interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ void createSocketConnection(void (* initKeypress)())
//ParodusCfg *tmpCfg = (ParodusCfg*)config_in;
noPollCtx *ctx;
bool seshat_registered = false;
int create_conn_rtn = 0;
unsigned int webpa_ping_timeout_ms = 1000 * get_parodus_cfg()->webpa_ping_timeout;
unsigned int heartBeatTimer = 0;
struct timespec start_svc_alive_timer;
Expand All @@ -94,7 +95,10 @@ void createSocketConnection(void (* initKeypress)())
nopoll_log_set_handler (ctx, __report_log, NULL);
#endif

if(!createNopollConnection(ctx))
start_conn_in_progress ();
create_conn_rtn = createNopollConnection(ctx);
stop_conn_in_progress ();
if(!create_conn_rtn)
{
ParodusError("Unrecovered error, terminating the process\n");
abort();
Expand Down Expand Up @@ -177,7 +181,9 @@ void createSocketConnection(void (* initKeypress)())
free(get_parodus_cfg()->cloud_disconnect);
reset_cloud_disconnect_reason(get_parodus_cfg());
}
start_conn_in_progress ();
createNopollConnection(ctx);
stop_conn_in_progress ();
}
} while(!get_close_retry() && !g_shutdown);

Expand Down
35 changes: 35 additions & 0 deletions src/connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -662,3 +662,38 @@ void close_and_unref_connection(noPollConn *conn)
}
}

void write_conn_in_prog_file (const char *msg)
{
int fd;
FILE *fp;
unsigned long timestamp;
ParodusCfg *cfg = get_parodus_cfg();

if (NULL == cfg->connection_health_file)
return;
fd = open (cfg->connection_health_file, O_CREAT | O_WRONLY | O_SYNC, 0666);
if (fd < 0) {
ParodusError ("Error(1) %d opening file %s\n", errno, cfg->connection_health_file);
return;
}
ftruncate (fd, 0);
fp = fdopen (fd, "w");
if (fp == NULL) {
ParodusError ("Error(2) %d opening file %s\n", errno, cfg->connection_health_file);
return;
}
timestamp = (unsigned long) time(NULL);
fprintf (fp, "{%s=%lu}\n", msg, timestamp);
fclose (fp);
}

void start_conn_in_progress (void)
{
write_conn_in_prog_file ("START");
}

void stop_conn_in_progress (void)
{
write_conn_in_prog_file ("STOP");
}

7 changes: 7 additions & 0 deletions src/connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ void set_global_reconnect_status(bool status);

int get_cloud_disconnect_time();
void set_cloud_disconnect_time(int disconnTime);

/**
* @brief Interface to self heal connection in progress getting stuck
*/
void start_conn_in_progress (void);
void stop_conn_in_progress (void);

#ifdef __cplusplus
}
#endif
Expand Down
9 changes: 9 additions & 0 deletions tests/test_conn_interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,15 @@ noPollMutexUnlock mutex_unlock
UNUSED(mutex_create); UNUSED(mutex_destroy); UNUSED(mutex_lock); UNUSED(mutex_unlock);
function_called();
}

void start_conn_in_progress (void)
{
}

void stop_conn_in_progress (void)
{
}

void packMetaData()
{
function_called();
Expand Down

0 comments on commit da6614b

Please sign in to comment.