Skip to content

Commit

Permalink
Add Remote "-status" command to see if a server is running and where (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
eisenhauer committed Nov 10, 2023
1 parent e8fd4e6 commit 19846e9
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 16 deletions.
22 changes: 22 additions & 0 deletions source/adios2/toolkit/remote/remote_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,25 @@ FMStructDescRec KillResponseStructs[] = {
{"KillResponse", KillResponseList, sizeof(struct _KillResponseMsg), NULL},
{NULL, NULL, 0, NULL}};

FMField StatusServerList[] = {{"StatusResponseCondition", "integer", sizeof(long),
FMOffset(StatusServerMsg, StatusResponseCondition)},
{NULL, NULL, 0, 0}};

FMStructDescRec StatusServerStructs[] = {
{"StatusServer", StatusServerList, sizeof(struct _StatusServerMsg), NULL},
{NULL, NULL, 0, NULL}};

FMField StatusResponseList[] = {
{"StatusResponseCondition", "integer", sizeof(long),
FMOffset(StatusResponseMsg, StatusResponseCondition)},
{"Hostname", "string", sizeof(char *), FMOffset(StatusResponseMsg, Hostname)},
{"Status", "string", sizeof(char *), FMOffset(StatusResponseMsg, Status)},
{NULL, NULL, 0, 0}};

FMStructDescRec StatusResponseStructs[] = {
{"StatusResponse", StatusResponseList, sizeof(struct _StatusResponseMsg), NULL},
{NULL, NULL, 0, NULL}};

void RegisterFormats(RemoteCommon::Remote_evpath_state &ev_state)
{
ev_state.OpenFileFormat = CMregister_format(ev_state.cm, RemoteCommon::OpenFileStructs);
Expand All @@ -129,6 +148,9 @@ void RegisterFormats(RemoteCommon::Remote_evpath_state &ev_state)
ev_state.CloseFileFormat = CMregister_format(ev_state.cm, RemoteCommon::CloseFileStructs);
ev_state.KillServerFormat = CMregister_format(ev_state.cm, RemoteCommon::KillServerStructs);
ev_state.KillResponseFormat = CMregister_format(ev_state.cm, RemoteCommon::KillResponseStructs);
ev_state.StatusServerFormat = CMregister_format(ev_state.cm, RemoteCommon::StatusServerStructs);
ev_state.StatusResponseFormat =
CMregister_format(ev_state.cm, RemoteCommon::StatusResponseStructs);
}
}
}
14 changes: 14 additions & 0 deletions source/adios2/toolkit/remote/remote_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,18 @@ typedef struct _KillResponseMsg
char *Status;
} *KillResponseMsg;

typedef struct _StatusServerMsg
{
int StatusResponseCondition;
} *StatusServerMsg;

typedef struct _StatusResponseMsg
{
int StatusResponseCondition;
char *Hostname;
char *Status;
} *StatusResponseMsg;

enum VerbosityLevel
{
NoVerbose = 0, // Generally no output (but not absolutely quiet?)
Expand All @@ -129,6 +141,8 @@ struct Remote_evpath_state
CMFormat CloseFileFormat;
CMFormat KillServerFormat;
CMFormat KillResponseFormat;
CMFormat StatusServerFormat;
CMFormat StatusResponseFormat;
};

void RegisterFormats(struct Remote_evpath_state &ev_state);
Expand Down
97 changes: 81 additions & 16 deletions source/adios2/toolkit/remote/remote_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,38 @@ static void KillResponseHandler(CManager cm, CMConnection conn, void *vevent, vo
exit(0);
}

static void StatusServerHandler(CManager cm, CMConnection conn, void *vevent, void *client_data,
attr_list attrs)
{
StatusServerMsg status_msg = static_cast<StatusServerMsg>(vevent);
struct Remote_evpath_state *ev_state = static_cast<struct Remote_evpath_state *>(client_data);
_StatusResponseMsg status_response_msg;
char hostbuffer[256];

// To retrieve hostname
gethostname(hostbuffer, sizeof(hostbuffer));
memset(&status_response_msg, 0, sizeof(status_response_msg));
status_response_msg.StatusResponseCondition = status_msg->StatusResponseCondition;
status_response_msg.Hostname = &hostbuffer[0];
std::stringstream Status;
Status << "ADIOS files Opened: " << ADIOSFilesOpened << " (" << TotalGets << " gets for "
<< readable_size(TotalGetBytesSent) << ") Simple files opened: " << SimpleFilesOpened
<< " (" << TotalSimpleReads << " reads for " << readable_size(TotalSimpleBytesSent)
<< ")";
status_response_msg.Status = strdup(Status.str().c_str());
CMwrite(conn, ev_state->StatusResponseFormat, &status_response_msg);
free(status_response_msg.Status);
}

static void StatusResponseHandler(CManager cm, CMConnection conn, void *vevent, void *client_data,
attr_list attrs)
{
StatusResponseMsg status_response_msg = static_cast<StatusResponseMsg>(vevent);
std::cout << "Server running on " << status_response_msg->Hostname
<< " current status: " << status_response_msg->Status << std::endl;
exit(0);
}

void ServerRegisterHandlers(struct Remote_evpath_state &ev_state)
{
CMregister_handler(ev_state.OpenFileFormat, OpenHandler, &ev_state);
Expand All @@ -357,6 +389,8 @@ void ServerRegisterHandlers(struct Remote_evpath_state &ev_state)
CMregister_handler(ev_state.ReadRequestFormat, ReadRequestHandler, &ev_state);
CMregister_handler(ev_state.KillServerFormat, KillServerHandler, &ev_state);
CMregister_handler(ev_state.KillResponseFormat, KillResponseHandler, &ev_state);
CMregister_handler(ev_state.StatusServerFormat, StatusServerHandler, &ev_state);
CMregister_handler(ev_state.StatusResponseFormat, StatusResponseHandler, &ev_state);
}

static const char *hostname = "localhost";
Expand Down Expand Up @@ -390,6 +424,35 @@ void connect_and_kill(int ServerPort)
exit(0);
}

void connect_and_get_status(int ServerPort)
{
CManager cm = CManager_create();
_StatusServerMsg status_msg;
struct Remote_evpath_state ev_state;
attr_list contact_list = create_attr_list();
atom_t CM_IP_PORT = -1;
atom_t CM_IP_HOSTNAME = -1;
CM_IP_HOSTNAME = attr_atom_from_string("IP_HOST");
CM_IP_PORT = attr_atom_from_string("IP_PORT");
add_attr(contact_list, CM_IP_HOSTNAME, Attr_String, (attr_value)hostname);
add_attr(contact_list, CM_IP_PORT, Attr_Int4, (attr_value)ServerPort);
CMConnection conn = CMinitiate_conn(cm, contact_list);
if (!conn)
return;

ev_state.cm = cm;

RegisterFormats(ev_state);

ServerRegisterHandlers(ev_state);

memset(&status_msg, 0, sizeof(status_msg));
status_msg.StatusResponseCondition = CMCondition_get(ev_state.cm, conn);
CMwrite(conn, ev_state.StatusServerFormat, &status_msg);
CMCondition_wait(ev_state.cm, status_msg.StatusResponseCondition);
exit(0);
}

static atom_t CM_IP_PORT = -1;

static bool server_timeout(void *CMvoid, int time_since_service)
Expand Down Expand Up @@ -430,6 +493,7 @@ int main(int argc, char **argv)
struct Remote_evpath_state ev_state;
int background = 0;
int kill_server = 0;
int status_server = 0;
int no_timeout = 0; // default to timeout

for (int i = 1; i < argc; i++)
Expand All @@ -442,31 +506,27 @@ int main(int argc, char **argv)
{
kill_server++;
}
else if (strcmp(argv[i], "-status") == 0)
{
status_server++;
}
else if (strcmp(argv[i], "-no_timeout") == 0)
{
no_timeout++;
}
if (argv[i][0] == '-')
else if (strcmp(argv[i], "-v") == 0)
{
size_t j = 1;
while (argv[i][j] != 0)
{
if (argv[i][j] == 'v')
{
verbose++;
}
else if (argv[i][j] == 'q')
{
verbose--;
}
j++;
}
verbose++;
}
else if (strcmp(argv[i], "-q") == 0)
{
verbose--;
}
else
{
fprintf(stderr, "Unknown argument \"%s\"\n", argv[i]);
fprintf(stderr,
"Usage: remote_server [-background] [-kill_server] [-no_timeout] [-v] [-q]\n");
fprintf(stderr, "Usage: remote_server [-background] [-kill_server] [-no_timeout] "
"[-status] [-v] [-q]\n");
exit(1);
}
}
Expand All @@ -476,6 +536,11 @@ int main(int argc, char **argv)
connect_and_kill(ServerPort);
exit(0);
}
if (status_server)
{
connect_and_get_status(ServerPort);
exit(0);
}
if (background)
{
if (verbose)
Expand Down

0 comments on commit 19846e9

Please sign in to comment.