diff options
Diffstat (limited to 'cpp/src/IceGrid/Parser.cpp')
-rw-r--r-- | cpp/src/IceGrid/Parser.cpp | 267 |
1 files changed, 137 insertions, 130 deletions
diff --git a/cpp/src/IceGrid/Parser.cpp b/cpp/src/IceGrid/Parser.cpp index ea380d6bf9b..cd5aeb55fcf 100644 --- a/cpp/src/IceGrid/Parser.cpp +++ b/cpp/src/IceGrid/Parser.cpp @@ -39,23 +39,23 @@ namespace { const char* _commandsHelp[][3] = { -{ "application", "add", +{ "application", "add", "application add [-n | --no-patch] DESC [TARGET ... ] [NAME=VALUE ... ]\n" " Add application described in DESC. If specified\n" -" the optional targets TARGET will be deployed.\n" +" the optional targets TARGET will be deployed.\n" }, -{ "application", "remove", -"application remove NAME Remove application NAME.\n" +{ "application", "remove", +"application remove NAME Remove application NAME.\n" }, { "application", "describe", -"application describe NAME Describe application NAME.\n" +"application describe NAME Describe application NAME.\n" }, { "application", "diff", "application diff [-s | --servers] DESC [TARGET ... ] [NAME=VALUE ... ]\n" " Print the differences betwen the application\n" -" described in DESC and the current deployment.\n" +" described in DESC and the current deployment.\n" " If -s or --servers is specified, print the\n" -" the list of servers affected by the differences.\n" +" the list of servers affected by the differences.\n" }, { "application", "update", "application update [-n | --no-restart] DESC [TARGET ... ] [NAME=VALUE ... ]\n" @@ -70,35 +70,35 @@ const char* _commandsHelp[][3] = { " will be stopped if necessary.\n" }, { "application", "list", -"application list List all deployed applications.\n" +"application list List all deployed applications.\n" }, -{ "server template", "instantiate", +{ "server template", "instantiate", "server template instantiate APPLICATION NODE TEMPLATE [NAME=VALUE ...]\n" -" Instantiate a server template.\n" +" Instantiate a server template.\n" }, -{ "server template", "describe", -"server template describe APPLICATION TEMPLATE\n" -" Describe application server template TEMPLATE.\n" +{ "server template", "describe", +"server template describe APPLICATION TEMPLATE\n" +" Describe application server template TEMPLATE.\n" }, { "service template", "describe", -"service template describe APPLICATION TEMPLATE\n" -" Describe application service template TEMPLATE.\n" +"service template describe APPLICATION TEMPLATE\n" +" Describe application service template TEMPLATE.\n" }, { "node", "list", -"node list List all registered nodes.\n" +"node list List all registered nodes.\n" }, -{ "node", "describe", -"node describe NAME Show information about node NAME.\n" +{ "node", "describe", +"node describe NAME Show information about node NAME.\n" }, { "node", "ping", -"node ping NAME Ping node NAME.\n" +"node ping NAME Ping node NAME.\n" }, { "node", "load", -"node load NAME Print the load of the node NAME.\n" +"node load NAME Print the load of the node NAME.\n" }, { "node", "sockets", "node sockets [NAME] Print the number of CPU sockets of the\n" -" node NAME or all the nodes if NAME is omitted.\n" +" node NAME or all the nodes if NAME is omitted.\n" }, { "node", "show", "node show [OPTIONS] NAME [log | stderr | stdout]\n" @@ -109,36 +109,36 @@ const char* _commandsHelp[][3] = { " -h N | --head N: Print the first N lines (stderr and stdout only)\n" }, { "node", "shutdown", -"node shutdown NAME Shutdown node NAME.\n" +"node shutdown NAME Shutdown node NAME.\n" }, { "registry", "list", -"registry list List all registered registries.\n" +"registry list List all registered registries.\n" }, { "registry", "describe", -"registry describe NAME Show information about registry NAME.\n" +"registry describe NAME Show information about registry NAME.\n" }, { "registry", "ping", -"registry ping NAME Ping registry NAME.\n" +"registry ping NAME Ping registry NAME.\n" }, { "registry", "show", -"registry show [OPTIONS] NAME [log | stderr | stdout ]\n" -" Show registry NAME Ice log, stderr or stdout.\n" +"registry show [OPTIONS] NAME [log | stderr | stdout ]\n" +" Show registry NAME Ice log, stderr or stdout.\n" " Options:\n" " -f | --follow: Wait for new log or data to be available\n" " -t N | --tail N: Print the last N log messages or lines\n" " -h N | --head N: Print the first N lines (stderr and stdout only)\n" }, { "registry", "shutdown", -"registry shutdown NAME Shutdown registry NAME.\n" +"registry shutdown NAME Shutdown registry NAME.\n" }, { "server", "list", -"server list List all registered servers.\n" +"server list List all registered servers.\n" }, { "server", "remove", -"server remove ID Remove server ID.\n" +"server remove ID Remove server ID.\n" }, -{ "server", "describe", -"server describe ID Describe server ID.\n" +{ "server", "describe", +"server describe ID Describe server ID.\n" }, { "server", "properties", "server properties ID Get the run-time properties of server ID.\n" @@ -147,28 +147,28 @@ const char* _commandsHelp[][3] = { "server property ID NAME Get the run-time property NAME of server ID.\n" }, { "server", "state", -"server state ID Get the state of server ID.\n" +"server state ID Get the state of server ID.\n" }, { "server", "pid", -"server pid ID Get the process id of server ID.\n" +"server pid ID Get the process id of server ID.\n" }, { "server", "start", -"server start ID Start server ID.\n" +"server start ID Start server ID.\n" }, { "server", "stop", -"server stop ID Stop server ID.\n" +"server stop ID Stop server ID.\n" }, { "server", "patch", -"server patch ID Patch server ID.\n" +"server patch ID Patch server ID.\n" }, -{ "server", "signal", -"server signal ID SIGNAL Send SIGNAL (e.g. SIGTERM or 15) to server ID.\n" +{ "server", "signal", +"server signal ID SIGNAL Send SIGNAL (e.g. SIGTERM or 15) to server ID.\n" }, { "server", "stdout", -"server stdout ID MESSAGE Write MESSAGE on server ID's stdout.\n" +"server stdout ID MESSAGE Write MESSAGE on server ID's stdout.\n" }, { "server", "stderr", -"server stderr ID MESSAGE Write MESSAGE on server ID's stderr.\n" +"server stderr ID MESSAGE Write MESSAGE on server ID's stderr.\n" }, { "server", "show", "server show [OPTIONS] ID [log | stderr | stdout | LOGFILE ]\n" @@ -179,11 +179,11 @@ const char* _commandsHelp[][3] = { " -h N | --head N: Print the first N lines (not available for Ice log)\n" }, { "server", "enable", -"server enable ID Enable server ID.\n" +"server enable ID Enable server ID.\n" }, { "server", "disable", "server disable ID Disable server ID (a disabled server can't be\n" -" started on demand or administratively).\n" +" started on demand or administratively).\n" }, { "service", "start", @@ -210,26 +210,26 @@ const char* _commandsHelp[][3] = { }, { "adapter", "list", -"adapter list List all registered adapters.\n" +"adapter list List all registered adapters.\n" }, { "adapter", "endpoints", -"adapter endpoints ID Show the endpoints of adapter or replica group ID.\n" +"adapter endpoints ID Show the endpoints of adapter or replica group ID.\n" }, { "adapter", "remove", -"adapter remove ID Remove adapter or replica group ID.\n" +"adapter remove ID Remove adapter or replica group ID.\n" }, { "object", "add", "object add PROXY [TYPE] Add an object to the object registry,\n" -" optionally specifying its type.\n" +" optionally specifying its type.\n" }, { "object", "remove", -"object remove IDENTITY Remove an object from the object registry.\n" +"object remove IDENTITY Remove an object from the object registry.\n" }, { "object", "find", -"object find TYPE Find all objects with the type TYPE.\n" +"object find TYPE Find all objects with the type TYPE.\n" }, { "object", "describe", -"object describe EXPR Describe all registered objects whose stringified\n" +"object describe EXPR Describe all registered objects whose stringified\n" " identities match the expression EXPR. A trailing\n" " wildcard is supported in EXPR, for example\n" " \"object describe Ice*\".\n" @@ -238,7 +238,7 @@ const char* _commandsHelp[][3] = { "object list EXPR List all registered objects whose stringified\n" " identities match the expression EXPR. A trailing\n" " wildcard is supported in EXPR, for example\n" -" \"object list Ice*\".\n" +" \"object list Ice*\".\n" }, { 0, 0, 0 } }; @@ -277,9 +277,9 @@ string toConsoleEncoding(const string& s) // Convert from UTF-8 to console CP string consoleString; windowsConsoleConverter->fromUTF8(reinterpret_cast<const IceUtil::Byte*>(s.data()), - reinterpret_cast<const IceUtil::Byte*>(s.data() + s.size()), + reinterpret_cast<const IceUtil::Byte*>(s.data() + s.size()), consoleString); - + return consoleString; } catch(const IceUtil::IllegalConversionException&) @@ -331,7 +331,7 @@ void writeMessage(const string& message, bool indent) ++idx; } } - + outputString(s); outputNewline(); flushOutput(); @@ -347,7 +347,7 @@ void printLogMessage(const string& p, const Ice::LogMessage& logMessage) } string timestamp = IceUtil::Time::microSeconds(logMessage.timestamp).toDateTime(); - + switch(logMessage.type) { case Ice::PrintMessage: @@ -386,14 +386,14 @@ void printLogMessage(const string& p, const Ice::LogMessage& logMessage) class RemoteLoggerI : public Ice::RemoteLogger -{ +{ public: RemoteLoggerI(); virtual void init(const string&, const Ice::LogMessageSeq&, const Ice::Current&); virtual void log(const Ice::LogMessage&, const Ice::Current&); - + void destroy(); private: @@ -414,23 +414,23 @@ RemoteLoggerI::RemoteLoggerI() : void RemoteLoggerI::init(const string& prefix, const Ice::LogMessageSeq& logMessages, const Ice::Current&) -{ +{ IceUtil::Monitor<IceUtil::Mutex>::Lock lock(_monitor); if(!_destroyed) { _prefix = prefix; - + for(Ice::LogMessageSeq::const_iterator p = logMessages.begin(); p != logMessages.end(); ++p) { printLogMessage(_prefix, *p); } - + _initDone = true; _monitor.notifyAll(); } } -void +void RemoteLoggerI::log(const Ice::LogMessage& logMessage, const Ice::Current&) { IceUtil::Monitor<IceUtil::Mutex>::Lock lock(_monitor); @@ -468,7 +468,7 @@ Parser::createParser(const CommunicatorPtr& communicator, const AdminSessionPrx& return new Parser(communicator, session, admin, interactive); } -void +void Parser::usage(const string& category, const string& command) { if(_helpCommands.find(category) == _helpCommands.end()) @@ -496,7 +496,7 @@ Parser::usage(const string& category, const list<string>& args) { invalidCommand("`help' requires at most 1 argument"); } - else + else { usage(category, *args.begin()); } @@ -513,15 +513,15 @@ Parser::usage() "\n" "List of help categories:\n" "\n" - " application: commands to manage applications\n" - " node: commands to manage nodes\n" - " registry: commands to manage registries\n" - " server: commands to manage servers\n" + " application: commands to manage applications\n" + " node: commands to manage nodes\n" + " registry: commands to manage registries\n" + " server: commands to manage servers\n" " service: commands to manage services\n" - " adapter: commands to manage adapters\n" + " adapter: commands to manage adapters\n" " object: commands to manage objects\n" - " server template: commands to manage server templates\n" - " service template: commands to manage service templates\n" + " server template: commands to manage server templates\n" + " service template: commands to manage service templates\n" "\n"; } @@ -565,7 +565,7 @@ Parser::addApplication(const list<string>& origArgs) { list<string> copyArgs = origArgs; copyArgs.push_front("icegridadmin"); - + IceUtilInternal::Options opts; opts.addOpt("n", "no-patch"); vector<string> args; @@ -615,7 +615,7 @@ Parser::addApplication(const list<string>& origArgs) // ApplicationDescriptor app = DescriptorParser::parseDescriptor(desc, targets, vars, _communicator, _admin); _admin->addApplication(app); - + if(!opts.isSet("no-patch")) { // @@ -743,7 +743,7 @@ Parser::diffApplication(const list<string>& origArgs) ApplicationHelper newAppHelper(_communicator, newApp); ApplicationHelper oldAppHelper(_communicator, origApp.descriptor); - + ostringstream os; Output out(os); if(opts.isSet("servers")) @@ -796,7 +796,7 @@ Parser::diffApplication(const list<string>& origArgs) newAppHelper.printDiff(out, oldAppHelper); } out << nl; - outputString(os.str()); + outputString(os.str()); } catch(const Ice::Exception& ex) { @@ -879,7 +879,7 @@ Parser::patchApplication(const list<string>& origArgs) { list<string> copyArgs = origArgs; copyArgs.push_front("icegridadmin"); - + IceUtilInternal::Options opts; opts.addOpt("f", "force"); vector<string> args; @@ -954,7 +954,7 @@ Parser::describeServerTemplate(const list<string>& args) string templ = *p++; ApplicationInfo application = _admin->getApplicationInfo(name); - + ostringstream os; Output out(os); TemplateDescriptorDict::const_iterator q = application.descriptor.serverTemplates.find(templ); @@ -1045,7 +1045,7 @@ Parser::describeServiceTemplate(const list<string>& args) string templ = *p++; ApplicationInfo application = _admin->getApplicationInfo(name); - + ostringstream os; Output out(os); TemplateDescriptorDict::const_iterator q = application.descriptor.serviceTemplates.find(templ); @@ -1382,7 +1382,7 @@ Parser::removeServer(const list<string>& args) catch(const Ice::Exception& ex) { exception(ex); - } + } } void @@ -1533,7 +1533,7 @@ Parser::describeServer(const list<string>& args) invalidCommand("server describe", "requires exactly one argument"); return; } - + try { ServerInfo info = _admin->getServerInfo(args.front()); @@ -1637,7 +1637,7 @@ Parser::pidServer(const list<string>& args) } else { - error("server is not running"); + error("server is not running"); } } catch(const Ice::Exception& ex) @@ -1825,7 +1825,7 @@ Parser::describeService(const list<string>& args) invalidCommand("service describe", "requires exactly two arguments"); return; } - + string server = args.front(); string service = *(++args.begin()); try @@ -1852,7 +1852,7 @@ Parser::describeService(const list<string>& args) } } outputString(os.str()); - + if(!found) { error("couldn't find service `" + service + "'"); @@ -1913,8 +1913,15 @@ Parser::propertiesService(const list<string>& args, bool single) } Ice::ObjectPrx admin = _admin->getServerAdmin(server); - Ice::PropertiesAdminPrx propAdmin = - Ice::PropertiesAdminPrx::uncheckedCast(admin, "IceBox.Service." + service + ".Properties"); + Ice::PropertiesAdminPrx propAdmin; + if(getPropertyAsInt(info.descriptor->propertySet.properties, "IceBox.UseSharedCommunicator." + service) > 0) + { + propAdmin = Ice::PropertiesAdminPrx::uncheckedCast(admin, "IceBox.SharedCommunicator.Properties"); + } + else + { + propAdmin = Ice::PropertiesAdminPrx::uncheckedCast(admin, "IceBox.Service." + service + ".Properties"); + } if(single) { @@ -2116,7 +2123,7 @@ Parser::findObject(const list<string>& args) for(ObjectInfoSeq::const_iterator p = objects.begin(); p != objects.end(); ++p) { cout << _communicator->proxyToString(p->proxy) << endl; - } + } } catch(const Ice::Exception& ex) { @@ -2155,12 +2162,12 @@ Parser::describeObject(const list<string>& args) { objects = _admin->getAllObjectInfos(""); } - + for(ObjectInfoSeq::const_iterator p = objects.begin(); p != objects.end(); ++p) { cout << "proxy = `" << _communicator->proxyToString(p->proxy) << "' type = `" << p->type << "'" << endl; } - + } catch(const Ice::Exception& ex) { @@ -2188,11 +2195,11 @@ Parser::listObject(const list<string>& args) { objects = _admin->getAllObjectInfos(""); } - + for(ObjectInfoSeq::const_iterator p = objects.begin(); p != objects.end(); ++p) { cout << _communicator->identityToString(p->proxy->ice_getIdentity()) << endl; - } + } } catch(const Ice::Exception& ex) { @@ -2205,7 +2212,7 @@ Parser::show(const string& reader, const list<string>& origArgs) { list<string> copyArgs = origArgs; copyArgs.push_front("icegridadmin"); - + IceUtilInternal::Options opts; opts.addOpt("f", "follow"); opts.addOpt("h", "head", IceUtilInternal::Options::NeedArg); @@ -2273,9 +2280,9 @@ Parser::show(const string& reader, const list<string>& origArgs) return; } } - + bool follow = opts.isSet("follow"); - + if(head && follow) { invalidCommand("can't use -f | --follow option with -h | --head option"); @@ -2298,12 +2305,12 @@ Parser::show(const string& reader, const list<string>& origArgs) } void -Parser::showFile(const string& id, const string& reader, const string& filename, +Parser::showFile(const string& id, const string& reader, const string& filename, bool head, bool tail, bool follow, int lineCount) { - + int maxBytes = _communicator->getProperties()->getPropertyAsIntWithDefault("Ice.MessageSizeMax", 1024) * 1024; - + FileIteratorPrx it; try @@ -2355,13 +2362,13 @@ Parser::showFile(const string& id, const string& reader, const string& filename, it = _session->openServerLog(id, filename, tail ? lineCount : -1); } } - + resetInterrupt(); Ice::StringSeq lines; if(head) { assert(!follow); - + int i = 0; bool eof = false; while(!interrupted() && !eof && i < lineCount) @@ -2389,7 +2396,7 @@ Parser::showFile(const string& id, const string& reader, const string& filename, } } } - + if(follow) { while(!interrupted()) @@ -2407,7 +2414,7 @@ Parser::showFile(const string& id, const string& reader, const string& filename, flushOutput(); } } - + if(eof) { Lock sync(*this); @@ -2419,13 +2426,13 @@ Parser::showFile(const string& id, const string& reader, const string& filename, } } } - + if(lines.empty() || !lines.back().empty()) { outputNewline(); flushOutput(); } - + it->destroy(); } catch(...) @@ -2448,7 +2455,7 @@ void Parser::showLog(const string& id, const string& reader, bool tail, bool follow, int lineCount) { outputNewline(); - + Ice::ObjectPrx admin; if(reader == "server") @@ -2469,9 +2476,9 @@ Parser::showLog(const string& id, const string& reader, bool tail, bool follow, error("cannot retrieve Admin proxy for " + reader + " `" + id + "'"); return; } - + Ice::LoggerAdminPrx loggerAdmin; - + try { loggerAdmin = Ice::LoggerAdminPrx::checkedCast(admin, "Logger"); @@ -2479,26 +2486,26 @@ Parser::showLog(const string& id, const string& reader, bool tail, bool follow, catch(const Ice::Exception&) { } - + if(loggerAdmin == 0) { error("cannot retrieve Logger admin facet for " + reader + " `" + id + "'"); return; } - + if(follow) { Ice::ObjectPrx adminCallbackTemplate = _session->getAdminCallbackTemplate(); - + if(adminCallbackTemplate == 0) { error("cannot retriever Callback template from IceGrid registry"); return; } - - const Ice::EndpointSeq endpoints = adminCallbackTemplate->ice_getEndpoints(); + + const Ice::EndpointSeq endpoints = adminCallbackTemplate->ice_getEndpoints(); string publishedEndpoints; - + for(Ice::EndpointSeq::const_iterator p = endpoints.begin(); p != endpoints.end(); ++p) { if(publishedEndpoints.empty()) @@ -2510,26 +2517,26 @@ Parser::showLog(const string& id, const string& reader, bool tail, bool follow, publishedEndpoints += ":" + (*p)->toString(); } } - + _communicator->getProperties()->setProperty("RemoteLoggerAdapter.PublishedEndpoints", publishedEndpoints); - + Ice::ObjectAdapterPtr adapter = _communicator->createObjectAdapter("RemoteLoggerAdapter"); - + _session->ice_getConnection()->setAdapter(adapter); - + Ice::Identity id; ostringstream name; name << "RemoteLogger-" << loggerCallbackCount++; id.name = name.str(); id.category = adminCallbackTemplate->ice_getIdentity().category; - + RemoteLoggerIPtr servant = new RemoteLoggerI; - Ice::RemoteLoggerPrx prx = + Ice::RemoteLoggerPrx prx = Ice::RemoteLoggerPrx::uncheckedCast(adapter->add(servant, id)); adapter->activate(); - + loggerAdmin->attachRemoteLogger(prx, Ice::LogMessageTypeSeq(), Ice::StringSeq(), tail ? lineCount : -1); - + resetInterrupt(); { Lock lock(*this); @@ -2538,10 +2545,10 @@ Parser::showLog(const string& id, const string& reader, bool tail, bool follow, wait(); } } - + servant->destroy(); adapter->destroy(); - + try { loggerAdmin->detachRemoteLogger(prx); @@ -2554,9 +2561,9 @@ Parser::showLog(const string& id, const string& reader, bool tail, bool follow, else { string prefix; - const Ice::LogMessageSeq logMessages = loggerAdmin->getLog(Ice::LogMessageTypeSeq(), Ice::StringSeq(), + const Ice::LogMessageSeq logMessages = loggerAdmin->getLog(Ice::LogMessageTypeSeq(), Ice::StringSeq(), tail ? lineCount : -1, prefix); - + for(Ice::LogMessageSeq::const_iterator p = logMessages.begin(); p != logMessages.end(); ++p) { printLogMessage(prefix, *p); @@ -2583,7 +2590,7 @@ Parser::showWarranty() } // -// With older flex version <= 2.5.35 YY_INPUT second +// With older flex version <= 2.5.35 YY_INPUT second // paramenter is of type int&, in newer versions it // changes to size_t& // @@ -2669,7 +2676,7 @@ Parser::getInput(char* buf, size_t& result, size_t maxSize) break; } } - + result = line.length(); if(result > maxSize) { @@ -2733,7 +2740,7 @@ Parser::invalidCommand(const list<string>& s) { return; } - + string cat = *s.begin(); if(_helpCommands.find(cat) == _helpCommands.end()) { @@ -2812,7 +2819,7 @@ Parser::error(const char* s) cerr << "error: " #ifdef _WIN32 - << toConsoleEncoding(s) + << toConsoleEncoding(s) #else << s #endif @@ -2831,7 +2838,7 @@ Parser::warning(const char* s) { cerr << "warning: " #ifdef _WIN32 - << toConsoleEncoding(s) + << toConsoleEncoding(s) #else << s #endif @@ -2894,8 +2901,8 @@ Parser::parse(const std::string& commands, bool debug) return status; } -Parser::Parser(const CommunicatorPtr& communicator, - const AdminSessionPrx& session, +Parser::Parser(const CommunicatorPtr& communicator, + const AdminSessionPrx& session, const AdminPrx& admin, bool interactive) : _communicator(communicator), @@ -2960,7 +2967,7 @@ Parser::exception(const Ice::Exception& ex) { ostringstream s; s << ex << ":\n" << ex.reason; - error(s.str()); + error(s.str()); } catch(const PatchException& ex) { |