1
1

Significant clean up of the orteconsole.

- Added user help messages.
 - Abstracted the internal commands, and the mechanism for
   parsing and executing them.
 - Cleaned up the command line parsing
 - Some other misc. cleanup items.

Still much more work to do here, but should provide a more
intuitive interface for extending functionality in the 
system.

This commit was SVN r6676.
Этот коммит содержится в:
Josh Hursey 2005-07-28 23:48:46 +00:00
родитель cbf04e3d3f
Коммит e849f7ba07
4 изменённых файлов: 298 добавлений и 69 удалений

Просмотреть файл

@ -16,6 +16,9 @@
include $(top_srcdir)/config/Makefile.options
EXTRA_DIST = $(pkgdata_DATA)
pkgdata_DATA = help-orteconsole.txt
libs = \
$(top_builddir)/orte/liborte.la \
$(top_builddir)/opal/libopal.la

36
orte/tools/console/help-orteconsole.txt Обычный файл
Просмотреть файл

@ -0,0 +1,36 @@
# -*- text -*-
#
# Copyright (c) 2004-2005 The Trustees of Indiana University.
# All rights reserved.
# Copyright (c) 2004-2005 The Trustees of the University of Tennessee.
# All rights reserved.
# Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
# University of Stuttgart. All rights reserved.
# Copyright (c) 2004-2005 The Regents of the University of California.
# All rights reserved.
# $COPYRIGHT$
#
# Additional copyrights may follow
#
# $HEADER$
#
# This is the US/English general help file for Open RTE's Console.
#
[orteconsole:usage]
Usage: %s [OPTION]...
Start the Open RTE Console interface
%s
[orteconsole:init-failure]
Open RTE was unable to initialize properly. The error occured while
attempting to %s. Returned value %d instead of ORTE_SUCCESS.
[orteconsole:finalize-failure]
Open RTE was unable to finalize properly. The error occured while
attempting to %s. Returned value %d instead of ORTE_SUCCESS.
[orteconsole:unknown-command]
Open RTE Console did not recognize the command:
%s
[orteconsole:unimplemented-command]
The command "%s" is not currently implemented in the Open RTE Console.
[orteconsole:failed-command]
The command "%s" failed with return value %d.

Просмотреть файл

@ -22,7 +22,9 @@
#include "include/orte_constants.h"
#include <stdlib.h>
#include <sys/types.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include "dps/dps.h"
@ -44,99 +46,216 @@
#include "mca/pls/base/base.h"
#include "tools/orted/orted.h"
#define ORTE_CONSOLE_MAX_LINE_LENGTH 1024
#include "tools/console/orteconsole.h"
static char *orte_getinputline(void);
/*
* Global Variables
*/
static bool exit_cmd;
static void orte_console_sendcmd(orte_daemon_cmd_flag_t usercmd);
/*
* Globals for catching command line options
*/
orteconsole_globals_t orteconsole_globals;
opal_cmd_line_init_t cmd_line_opts[] = {
{ NULL, NULL, NULL, 'h', NULL, "help", 0,
&orteconsole_globals.help, OPAL_CMD_LINE_TYPE_BOOL,
"This help message" },
/* End of list */
{ NULL, NULL, NULL, '\0', NULL, NULL, 0,
NULL, OPAL_CMD_LINE_TYPE_NULL, NULL }
};
/*
* Global structure describing valid internal commands
*/
orte_console_command_t console_commands[] = {
{ "quit", "q", 0, ORTE_CONSOLE_TYPE_STD,
orte_console_exit,
"Exit the console" },
{ "help", "h", 0, ORTE_CONSOLE_TYPE_STD,
orte_console_help,
"Print this display" },
{ "contactinfo", "ci", 0, ORTE_CONSOLE_TYPE_STD,
orte_console_contactinfo,
"Query Contact Information from Daemons" },
{ "dumpvm", "vm", 0, ORTE_CONSOLE_TYPE_STD,
orte_console_dumpvm,
"Get VM List from daemons" },
/* End of list */
{ NULL, NULL, 0, ORTE_CONSOLE_TYPE_NULL,
NULL,
NULL }
};
int main(int argc, char *argv[])
{
int ret=0;
opal_cmd_line_t *cmd_line;
bool exit_cmd;
char *usercmd, *str_response;
orte_buffer_t *buffer = NULL;
orte_process_name_t seed={0,0,0};
size_t n;
char *usercmd;
/* setup to check common command line options that just report and die */
/*
* Setup to check common command line options
*/
memset(&orteconsole_globals, 0, sizeof(orteconsole_globals_t));
cmd_line = OBJ_NEW(opal_cmd_line_t);
opal_cmd_line_make_opt(cmd_line, 'v', "version", 0,
"Show version of this program");
opal_cmd_line_make_opt(cmd_line, 'h', "help", 0,
"Show help for this function");
/* parse the local commands */
if (OMPI_SUCCESS != opal_cmd_line_parse(cmd_line, true, argc, argv)) {
opal_cmd_line_create(cmd_line, cmd_line_opts);
if (OMPI_SUCCESS != (ret = opal_cmd_line_parse(cmd_line, false,
argc, argv))) {
char *args = NULL;
args = opal_cmd_line_get_usage_msg(cmd_line);
opal_show_help("help-console.txt", "console:usage", false,
opal_show_help("help-orteconsole.txt", "orteconsole:usage", false,
argv[0], args);
free(args);
return ret;
}
/* Check for help request */
if(orteconsole_globals.help) {
char *args = NULL;
args = opal_cmd_line_get_usage_msg(cmd_line);
opal_show_help("help-orteconsole.txt", "orteconsole:usage", false,
argv[0], args);
free(args);
return 1;
}
/* check for help and version requests */
if (opal_cmd_line_is_taken(cmd_line, "help") ||
opal_cmd_line_is_taken(cmd_line, "h")) {
char *args = NULL;
args = opal_cmd_line_get_usage_msg(cmd_line);
opal_show_help("help-console.txt", "console:usage", false,
argv[0], args);
free(args);
return 1;
}
if (opal_cmd_line_is_taken(cmd_line, "version") ||
opal_cmd_line_is_taken(cmd_line, "v")) {
printf("...showing off my version!\n");
exit(1);
}
/*
* Intialize the ORTE environment
*/
if (OMPI_SUCCESS != orte_init()) {
/* BWB show_help */
printf("show_help: ompi_init failed\n");
if (OMPI_SUCCESS != (ret = orte_init()) ) {
opal_show_help("help-orteconsole.txt", "orteconsole:init-failure", false,
"orte_init()", ret);
return ret;
}
/*
* Work Loop
*/
exit_cmd = false;
while (!exit_cmd) {
printf("ompiconsole> ");
usercmd = orte_getinputline();
if (0 == strncmp(usercmd, "exit", strlen("exit"))) {
exit_cmd = true;
orte_console_sendcmd(ORTE_DAEMON_EXIT_CMD);
} else if (0 == strncmp(usercmd, "contactinfo", strlen("contactinfo"))) {
orte_console_sendcmd(ORTE_DAEMON_CONTACT_QUERY_CMD);
if (0 > orte_rml.recv_buffer(&seed, buffer, ORTE_RML_TAG_DAEMON)) {
printf("****got a bad response\n");
} else {
n = 1;
if (ORTE_SUCCESS != orte_dps.unpack(buffer, &str_response, &n, ORTE_STRING)) {
printf("****couldn't decode answer\n");
} else {
printf(str_response);
printf("\n");
}
}
} else if (0 == strncmp(usercmd, "dumpvm", strlen("dumpvm"))) {
fprintf(stderr, "getting vm list\n");
} else {
printf("huh???\n");
}
printf("ompiconsole> ");
usercmd = orte_getinputline();
execute_command(usercmd);
}
fprintf(stderr, "finalize rte\n");
orte_finalize();
exit(0);
/*
* Finialize ORTE Environment
*/
if(ORTE_SUCCESS != (ret = orte_finalize()) ) {
opal_show_help("help-orteconsole.txt", "orteconsole:finalize-failure", false,
"orte_finalize()", ret);
return ret;
}
return ORTE_SUCCESS;
}
static int execute_command(char *command) {
orte_console_command_t *cur_cmd;
int i, ret;
for(i = 0; console_commands[i].cmd_type != ORTE_CONSOLE_TYPE_NULL; ++i) {
cur_cmd = &console_commands[i];
/*
* Check Full Name then check short name
*/
if ( ( 0 == strncmp(command, cur_cmd->cmd_full_name,
strlen(cur_cmd->cmd_full_name)) ) ||
( ( strlen(command) == strlen(cur_cmd->cmd_short_name) ) &&
( 0 == strncmp(command, cur_cmd->cmd_short_name,
strlen(cur_cmd->cmd_short_name)) ) ) ) {
ret = cur_cmd->cmd_function();
if(ret == ORTE_ERR_NOT_IMPLEMENTED) {
opal_show_help("help-orteconsole.txt", "orteconsole:unimplemented-command", false,
cur_cmd->cmd_full_name);
return ret;
}
else if(ret != ORTE_SUCCESS) {
opal_show_help("help-orteconsole.txt", "orteconsole:failed-command", false,
cur_cmd->cmd_full_name, ret);
return ret;
}
break;
}
}
/*
* If command was not found :(
*/
if( console_commands[i].cmd_type == ORTE_CONSOLE_TYPE_NULL ) {
opal_show_help("help-orteconsole.txt", "orteconsole:unknown-command", false,
command);
return ORTE_ERR_NOT_IMPLEMENTED;
}
return ORTE_SUCCESS;
}
static int orte_console_exit() {
exit_cmd = true;
orte_console_sendcmd(ORTE_DAEMON_EXIT_CMD);
return ORTE_SUCCESS;
}
static int orte_console_help() {
orte_console_command_t *cur_cmd;
int i;
printf("Open RTE Console Commands:\n\n");
for(i = 0; console_commands[i].cmd_type != ORTE_CONSOLE_TYPE_NULL; ++i) {
cur_cmd = &console_commands[i];
printf("%15s | %5s \t%s\n",
cur_cmd->cmd_full_name,
cur_cmd->cmd_short_name,
cur_cmd->cmd_description);
}
printf("\n");
return ORTE_SUCCESS;
}
static int orte_console_dumpvm() {
return ORTE_ERR_NOT_IMPLEMENTED;
}
static int orte_console_contactinfo() {
char * str_response;
orte_buffer_t *buffer = NULL;
orte_process_name_t seed={0,0,0};
size_t n;
orte_console_sendcmd(ORTE_DAEMON_CONTACT_QUERY_CMD);
if (0 > orte_rml.recv_buffer(&seed, buffer, ORTE_RML_TAG_DAEMON)) {
printf("****got a bad response\n");
return ORTE_ERROR;
} else {
n = 1;
if (ORTE_SUCCESS != orte_dps.unpack(buffer, &str_response, &n, ORTE_STRING)) {
printf("****couldn't decode answer\n");
return ORTE_ERROR;
} else {
printf(str_response);
printf("\n");
}
}
return ORTE_SUCCESS;
}
static void orte_console_sendcmd(orte_daemon_cmd_flag_t usercmd)
@ -171,9 +290,9 @@ char *orte_getinputline()
ret = fgets(input, ORTE_CONSOLE_MAX_LINE_LENGTH, stdin);
if (NULL != ret) {
input[strlen(input)-1] = '\0'; /* remove newline */
buff = strdup(input);
return buff;
input[strlen(input)-1] = '\0'; /* remove newline */
buff = strdup(input);
return buff;
}
return NULL;
}

71
orte/tools/console/orteconsole.h Обычный файл
Просмотреть файл

@ -0,0 +1,71 @@
/*
* Copyright (c) 2004-2005 The Trustees of Indiana University.
* All rights reserved.
* Copyright (c) 2004-2005 The Trustees of the University of Tennessee.
* All rights reserved.
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
* University of Stuttgart. All rights reserved.
* Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#ifndef ORTECONSOLE_H
#define ORTECONSOLE_H
#define ORTE_CONSOLE_MAX_LINE_LENGTH 1024
/*
* Local Structures
*/
/* Command line Structure */
typedef struct {
bool help;
opal_mutex_t lock;
opal_condition_t cond;
} orteconsole_globals_t;
enum orte_console_type_t {
ORTE_CONSOLE_TYPE_NULL,
ORTE_CONSOLE_TYPE_STD
};
typedef enum orte_console_type_t orte_console_type_t;
/* Structure detailing each command allowed by the console */
typedef struct {
/* Full Name for the command */
const char *cmd_full_name;
/* Common abbreviation for this command */
const char *cmd_short_name;
/* Number of expected arguments */
int cmd_args;
/* Type of command */
orte_console_type_t cmd_type;
/* Pointer to the function to execute */
int (*cmd_function) (void);
/* Short description of what this command does */
const char *cmd_description;
} orte_console_command_t;
/*
* Function for each command
*/
static int orte_console_exit(void);
static int orte_console_help(void);
static int orte_console_contactinfo(void);
static int orte_console_dumpvm(void);
/*
* Support Functions
*/
static char *orte_getinputline(void);
static void orte_console_sendcmd(orte_daemon_cmd_flag_t usercmd);
static int execute_command(char *command);
#endif /* ORTECONSOLE_H */