diff --git a/oam/etc/ConsoleCmds.xml b/oam/etc/ConsoleCmds.xml index 01b258751..a5a29e750 100644 --- a/oam/etc/ConsoleCmds.xml +++ b/oam/etc/ConsoleCmds.xml @@ -29,7 +29,12 @@ AVAILABLE - AVAILABLE + findObjectFile + Get the name of the directory containing the first file of the object + Object ID (OID) of object + Schema + Table + Column getModuleTypeConfig diff --git a/oamapps/mcsadmin/CMakeLists.txt b/oamapps/mcsadmin/CMakeLists.txt index 5d06594df..c8d4af0e2 100644 --- a/oamapps/mcsadmin/CMakeLists.txt +++ b/oamapps/mcsadmin/CMakeLists.txt @@ -8,7 +8,7 @@ set(mcsadmin_SRCS mcsadmin.cpp) add_executable(mcsadmin ${mcsadmin_SRCS}) -target_link_libraries(mcsadmin ${ENGINE_LDFLAGS} readline ncurses ${ENGINE_EXEC_LIBS}) +target_link_libraries(mcsadmin ${ENGINE_LDFLAGS} readline ncurses ${ENGINE_EXEC_LIBS} ${ENGINE_WRITE_LIBS}) install(TARGETS mcsadmin DESTINATION ${ENGINE_BINDIR} COMPONENT platform) diff --git a/oamapps/mcsadmin/mcsadmin.cpp b/oamapps/mcsadmin/mcsadmin.cpp index 50af96f0b..f15e760d3 100644 --- a/oamapps/mcsadmin/mcsadmin.cpp +++ b/oamapps/mcsadmin/mcsadmin.cpp @@ -32,13 +32,15 @@ extern int h_errno; #include "boost/tokenizer.hpp" #include "sessionmanager.h" #include "dbrm.h" +#include "we_config.h" // for findObjectFile +#include "we_fileop.h" // for findObjectFile namespace fs = boost::filesystem; using namespace alarmmanager; using namespace std; using namespace oam; using namespace config; - +using namespace execplan; #include "installdir.h" // Variables shared in both main and functions @@ -707,8 +709,95 @@ int processCommand(string* arguments) } break; - case 5: // Available + case 5: // findObjectFile { + unsigned maxDBRoot = WriteEngine::Config::DBRootCount(); + if (maxDBRoot < 1) + { + cout << endl << "getDatafileName fails because there are no dbroots defined for this server" << endl; + break;; + } + if (arguments[1] == "") + { + cout << endl << "getDatafileName requires one of" << endl; + cout << "a) oid of column for which file name is to be retrieved" << endl; + cout << "b) schema, table and column for which file name is to be retrieved" << endl; + break; + } + char* endchar; + int oid = strtol(arguments[1].c_str(), &endchar, 0); + // test to see if not all numeric + if (endchar < &(*arguments[1].end())) + { + oid = 0; + } + if (oid == 0) + { + // Need to convert the arguments to oid + boost::shared_ptr systemCatalogPtr = + execplan::CalpontSystemCatalog::makeCalpontSystemCatalog(0); + CalpontSystemCatalog::TableColName columnName; + columnName.schema = arguments[1]; + if (arguments[2] == "") + { + cout << endl << "getDatafileName requires a table and column for schema " << arguments[1] << endl; + break; + } + columnName.table = arguments[2]; + if (arguments[3] == "") + { + // No column was given. Use the first column in the table. + CalpontSystemCatalog::TableName tableName; + tableName.schema = arguments[1]; + tableName.table = arguments[2]; + CalpontSystemCatalog::RIDList rdlist = systemCatalogPtr->columnRIDs(tableName); + oid = rdlist.front().objnum; + } + else + { + columnName.column = arguments[3]; + oid = systemCatalogPtr->lookupOID(columnName); + } + } + + // Use writeengine code to get the filename + WriteEngine::FileOp fileOp; + char fileName[WriteEngine::FILE_NAME_SIZE]; + memset(fileName, 0, WriteEngine::FILE_NAME_SIZE); + int rc; + + if (oid < 1000) + rc = fileOp.getVBFileName(oid, fileName); + else + rc = fileOp.oid2DirName(oid, fileName); + cout << "file name for oid " << oid << ":" << endl; + if (strlen(fileName) > 0) + { + cout << fileName; + } + if (rc == WriteEngine::NO_ERROR) + { + // Success. No more output. + cout << endl; + } + else if (rc == WriteEngine::ERR_FILE_NOT_EXIST) + { + if (strlen(fileName) == 0) + { + // We couldn't get a name + cout << "Error: Filename could not be determined" << endl; + } + else + { + // We got a name, but the file doesn't exist + cout << " (OID directory not found)" << endl; + } + } + else + { + // Something broke + cerr << "WriteEngine::FileOp::oid2DirName() error. rc=" << rc << endl; + } } break;