diff options
author | Benoit Foucher <benoit@zeroc.com> | 2005-04-29 15:06:42 +0000 |
---|---|---|
committer | Benoit Foucher <benoit@zeroc.com> | 2005-04-29 15:06:42 +0000 |
commit | 917b860b9c7f7387d8bf9f507f39fced6d8f7836 (patch) | |
tree | 5a0296de28d5a9dca2ef89098ddc8a5ac1bf78c5 /cpp/src | |
parent | Added tests for templates. (diff) | |
download | ice-917b860b9c7f7387d8bf9f507f39fced6d8f7836.tar.bz2 ice-917b860b9c7f7387d8bf9f507f39fced6d8f7836.tar.xz ice-917b860b9c7f7387d8bf9f507f39fced6d8f7836.zip |
Fixed bugs, added method to instantiate a server with the admin interface.
Diffstat (limited to 'cpp/src')
-rw-r--r-- | cpp/src/IceGrid/AdminI.cpp | 108 | ||||
-rw-r--r-- | cpp/src/IceGrid/AdminI.h | 2 | ||||
-rw-r--r-- | cpp/src/IceGrid/Database.cpp | 82 | ||||
-rw-r--r-- | cpp/src/IceGrid/Database.h | 1 | ||||
-rw-r--r-- | cpp/src/IceGrid/Grammar.y | 5 | ||||
-rw-r--r-- | cpp/src/IceGrid/Makefile | 4 | ||||
-rw-r--r-- | cpp/src/IceGrid/NodeI.cpp | 5 | ||||
-rw-r--r-- | cpp/src/IceGrid/NodeI.h | 1 | ||||
-rw-r--r-- | cpp/src/IceGrid/Parser.cpp | 70 | ||||
-rw-r--r-- | cpp/src/IceGrid/Parser.h | 1 | ||||
-rw-r--r-- | cpp/src/IceGrid/Scanner.l | 4 |
11 files changed, 216 insertions, 67 deletions
diff --git a/cpp/src/IceGrid/AdminI.cpp b/cpp/src/IceGrid/AdminI.cpp index ff6f5c2e07c..891c5d57437 100644 --- a/cpp/src/IceGrid/AdminI.cpp +++ b/cpp/src/IceGrid/AdminI.cpp @@ -11,6 +11,7 @@ #include <IceGrid/AdminI.h> #include <IceGrid/RegistryI.h> #include <IceGrid/Database.h> +#include <IceGrid/DescriptorHelper.h> #include <Ice/LoggerUtil.h> #include <Ice/TraceUtil.h> #include <Ice/SliceChecksums.h> @@ -56,6 +57,17 @@ AdminI::getApplicationDescriptor(const string& name, const Current&) const return _database->getApplicationDescriptor(name); } +void +AdminI::instantiateApplicationServer(const string& name, const string& tmpl, const StringStringDict& variables, + const Current&) +{ + StringStringDict vars = variables; + vars.insert(make_pair("template", tmpl)); + ApplicationDescriptorHelper helper(_communicator, _database->getApplicationDescriptor(name)); + auto_ptr<ServerDescriptorHelper> server(helper.addServer(vars)); + _database->updateApplicationDescriptor(helper.getDescriptor()); +} + Ice::StringSeq AdminI::getAllApplicationNames(const Current&) const { @@ -65,53 +77,95 @@ AdminI::getAllApplicationNames(const Current&) const void AdminI::addServer(const ServerDescriptorPtr& server, const Current&) { - if(!server->application.empty()) - { - DeploymentException ex; - ex.reason = "You need to update the descriptor of the application `" + server->application + "'" + - "to add this server."; - throw ex; - } - - ApplicationDescriptorPtr application = new ApplicationDescriptor(); - application->name = '_' + server->name; - application->servers.push_back(server); - try - { - _database->addApplicationDescriptor(application); - } - catch(const ApplicationExistsException&) - { - ServerExistsException ex; - ex.name = server->name; - throw ex; + if(server->application.empty()) + { + ApplicationDescriptorPtr application = new ApplicationDescriptor(); + application->name = '_' + server->name; + application->servers.push_back(server); + try + { + _database->addApplicationDescriptor(application); + } + catch(const ApplicationExistsException&) + { + ServerExistsException ex; + ex.name = server->name; + throw ex; + } + } + else + { + try + { + ApplicationDescriptorPtr application = _database->getApplicationDescriptor(server->application); + application->servers.push_back(server); + _database->updateApplicationDescriptor(application); + } + catch(const ApplicationNotExistException&) + { + DeploymentException ex; + ex.reason = "application `" + server->application + "' doesn't exist"; + throw ex; + } } } void -AdminI::updateServer(const ServerDescriptorPtr& server, const Current&) +AdminI::updateServer(const ServerDescriptorPtr& newServer, const Current&) { - ApplicationDescriptorPtr application = new ApplicationDescriptor(); - application->name = '_' + server->name; - application->servers.push_back(server); + ServerDescriptorPtr server = _database->getServerDescriptor(newServer->name); try { - _database->updateApplicationDescriptor(application); + if(server->application.empty()) + { + ApplicationDescriptorPtr application = new ApplicationDescriptor(); + application->name = '_' + newServer->name; + application->servers.push_back(newServer); + _database->updateApplicationDescriptor(application); + } + else + { + ApplicationDescriptorPtr application = _database->getApplicationDescriptor(server->application); + for(ServerDescriptorSeq::iterator p = application->servers.begin(); p != application->servers.end(); ++p) + { + application->servers.erase(p); + application->servers.push_back(newServer); + } + _database->updateApplicationDescriptor(application); + } } catch(const ApplicationNotExistException&) { ServerNotExistException ex; - ex.name = server->name; + ex.name = newServer->name; throw ex; } + } void AdminI::removeServer(const string& name, const Current&) { + ServerDescriptorPtr server = _database->getServerDescriptor(name); try { - _database->removeApplicationDescriptor('_' + name); + if(server->application.empty()) + { + _database->removeApplicationDescriptor('_' + name); + } + else + { + ApplicationDescriptorPtr application = _database->getApplicationDescriptor(server->application); + for(ServerDescriptorSeq::iterator p = application->servers.begin(); p != application->servers.end(); ++p) + { + if((*p)->name == name) + { + application->servers.erase(p); + break; + } + } + _database->updateApplicationDescriptor(application); + } } catch(const ApplicationNotExistException&) { diff --git a/cpp/src/IceGrid/AdminI.h b/cpp/src/IceGrid/AdminI.h index 4b1d7b5321d..c6ec1b7390e 100644 --- a/cpp/src/IceGrid/AdminI.h +++ b/cpp/src/IceGrid/AdminI.h @@ -29,6 +29,8 @@ public: virtual void updateApplication(const ApplicationDescriptorPtr&, const Ice::Current&); virtual void removeApplication(const std::string&, const Ice::Current&); virtual ApplicationDescriptorPtr getApplicationDescriptor(const ::std::string&, const Ice::Current&) const; + virtual void instantiateApplicationServer(const std::string&, const std::string&, const StringStringDict&, + const Ice::Current&); virtual Ice::StringSeq getAllApplicationNames(const Ice::Current&) const; virtual void addServer(const ServerDescriptorPtr&, const Ice::Current&); diff --git a/cpp/src/IceGrid/Database.cpp b/cpp/src/IceGrid/Database.cpp index f60baa7b414..fd129078e62 100644 --- a/cpp/src/IceGrid/Database.cpp +++ b/cpp/src/IceGrid/Database.cpp @@ -1076,7 +1076,14 @@ void Database::clearServer(const std::string& name) { Lock sync(*this); - _servers.erase(name); + map<string, ServerEntryPtr>::iterator p = _servers.find(name); + if(p != _servers.end()) + { + if(p->second->canRemove()) + { + _servers.erase(p); + } + } } void @@ -1244,48 +1251,77 @@ Database::ServerEntry::sync(map<string, AdapterPrx>& adapters) { if(destroy) { - _database.getNode(destroy->node)->destroyServer(destroy); + try + { + _database.getNode(destroy->node)->destroyServer(destroy); + } + catch(const NodeNotExistException& ex) + { + if(!load) + { + throw NodeUnreachableException(); + } + } + catch(Ice::LocalException& ex) + { + if(!load) + { + throw NodeUnreachableException(); + } + } } + if(load) { - proxy = _database.getNode(load->node)->loadServer(load, adapters); + try + { + proxy = _database.getNode(load->node)->loadServer(load, adapters); + } + catch(const NodeNotExistException& ex) + { + throw NodeUnreachableException(); + } + catch(Ice::LocalException& ex) + { + throw NodeUnreachableException(); + } } } - catch(const NodeNotExistException& ex) + catch(const NodeUnreachableException& ex) { - if(!load && destroy) { - _database.clearServer(destroy->name); + Lock sync(*this); + _synchronizing = false; + _destroy = 0; + notifyAll(); } - Lock sync(*this); - _synchronizing = false; - notifyAll(); - throw NodeUnreachableException(); - } - catch(Ice::LocalException& ex) - { if(!load && destroy) { _database.clearServer(destroy->name); } + throw; + } + + { Lock sync(*this); _synchronizing = false; + _loaded = _load; + _load = 0; + _destroy = 0; + _proxy = proxy; + _adapters = adapters; notifyAll(); - throw NodeUnreachableException(); } - if(!load && destroy) { _database.clearServer(destroy->name); } - Lock sync(*this); - _synchronizing = false; - _loaded = _load; - _load = 0; - _destroy = 0; - _proxy = proxy; - _adapters = adapters; - notifyAll(); return proxy; } +bool +Database::ServerEntry::canRemove() +{ + Lock sync(*this); + return !_loaded && !_load && !_destroy; +} diff --git a/cpp/src/IceGrid/Database.h b/cpp/src/IceGrid/Database.h index dd7e43678f3..ca488bebb5e 100644 --- a/cpp/src/IceGrid/Database.h +++ b/cpp/src/IceGrid/Database.h @@ -76,6 +76,7 @@ private: ServerDescriptorPtr getDescriptor(); ServerPrx getProxy(); AdapterPrx getAdapter(const std::string&); + bool canRemove(); private: diff --git a/cpp/src/IceGrid/Grammar.y b/cpp/src/IceGrid/Grammar.y index cf4e8465db5..e693787e489 100644 --- a/cpp/src/IceGrid/Grammar.y +++ b/cpp/src/IceGrid/Grammar.y @@ -63,6 +63,7 @@ yyerror(const char* s) %token ICE_GRID_WARRANTY %token ICE_GRID_DIFF %token ICE_GRID_UPDATE +%token ICE_GRID_INSTANTIATE %% @@ -119,6 +120,10 @@ command { parser->describeApplication($3); } +| ICE_GRID_APPLICATION ICE_GRID_INSTANTIATE strings ';' +{ + parser->instantiateApplication($3); +} | ICE_GRID_APPLICATION ICE_GRID_LIST ';' { parser->listAllApplications(); diff --git a/cpp/src/IceGrid/Makefile b/cpp/src/IceGrid/Makefile index 63ac4266945..de5ab845b82 100644 --- a/cpp/src/IceGrid/Makefile +++ b/cpp/src/IceGrid/Makefile @@ -49,8 +49,7 @@ NODE_OBJS = NodeI.o \ ServerAdapterI.o \ Activator.o \ WaitQueue.o \ - DescriptorParser.o \ - DescriptorHelper.o + DescriptorParser.o REGISTRY_OBJS = RegistryI.o \ StringObjectProxyDict.o \ @@ -61,6 +60,7 @@ REGISTRY_OBJS = RegistryI.o \ LocatorRegistryI.o \ AdminI.o \ Util.o \ + DescriptorHelper.o \ QueryI.o NODE_SVR_OBJS = $(COMMON_OBJS) \ diff --git a/cpp/src/IceGrid/NodeI.cpp b/cpp/src/IceGrid/NodeI.cpp index 459fb6ca528..88f99c16a7f 100644 --- a/cpp/src/IceGrid/NodeI.cpp +++ b/cpp/src/IceGrid/NodeI.cpp @@ -188,11 +188,6 @@ NodeI::checkConsistency(const Ice::StringSeq& servers) } } -void -NodeI::removeServerDirectory(const string& backupDir, const string& name) -{ -} - bool NodeI::canRemoveServerDirectory(const string& name) { diff --git a/cpp/src/IceGrid/NodeI.h b/cpp/src/IceGrid/NodeI.h index dd531762c17..fbbb687efc5 100644 --- a/cpp/src/IceGrid/NodeI.h +++ b/cpp/src/IceGrid/NodeI.h @@ -45,7 +45,6 @@ public: void checkConsistency(const Ice::StringSeq&); bool canRemoveServerDirectory(const std::string&); - void removeServerDirectory(const std::string&, const std::string&); private: diff --git a/cpp/src/IceGrid/Parser.cpp b/cpp/src/IceGrid/Parser.cpp index 4b7ee2f637d..a8df0298e71 100644 --- a/cpp/src/IceGrid/Parser.cpp +++ b/cpp/src/IceGrid/Parser.cpp @@ -13,6 +13,7 @@ #include <IceGrid/Parser.h> #include <IceGrid/Util.h> #include <IceGrid/DescriptorParser.h> +#include <IceGrid/DescriptorHelper.h> #ifdef GPL_BUILD # include <IceGrid/GPL.h> @@ -243,7 +244,10 @@ Parser::usage() " described in DESC and the current deployment.\n" "application update DESC [TARGET ... ] [NAME=VALUE ... ]\n" " Update the application described in DESC.\n" + "application instantiate NAME TEMPLATE [NAME=VALUE ...]\n" + " Instantiate a server template and add the server\n" "application list List all deployed applications.\n" + " to the application." "\n" "node list List all registered nodes.\n" "node ping NAME Ping node NAME.\n" @@ -353,9 +357,9 @@ Parser::addApplication(const list<string>& args) void Parser::removeApplication(const list<string>& args) { - if(args.size() < 1) + if(args.size() != 1) { - error("`application remove' requires at exactly one argument\n(`help' for more info)"); + error("`application remove' requires exactly one argument\n(`help' for more info)"); return; } @@ -386,7 +390,7 @@ Parser::describeApplication(const list<string>& args) { if(args.size() < 1) { - error("`application describe' requires at exactly one argument\n(`help' for more info)"); + error("`application describe' requires at least one argument\n(`help' for more info)"); return; } @@ -456,7 +460,7 @@ Parser::diffApplication(const list<string>& args) { if(args.size() < 1) { - error("`application diff' requires at exactly one argument\n(`help' for more info)"); + error("`application diff' requires at least one argument\n(`help' for more info)"); return; } @@ -559,7 +563,7 @@ Parser::updateApplication(const list<string>& args) { if(args.size() < 1) { - error("`application diff' requires at exactly one argument\n(`help' for more info)"); + error("`application diff' requires at least one argument\n(`help' for more info)"); return; } @@ -608,6 +612,54 @@ Parser::updateApplication(const list<string>& args) } void +Parser::instantiateApplication(const list<string>& args) +{ + if(args.size() < 2) + { + error("`application instantiate' requires at least two arguments\n(`help' for more info)"); + return; + } + + try + { + map<string, string> vars; + + list<string>::const_iterator p = args.begin(); + string application = *p++; + string templ = *p++; + + for(; p != args.end(); ++p) + { + string::size_type pos = p->find('='); + if(pos != string::npos) + { + vars[p->substr(0, pos)] = p->substr(pos + 1); + } + } + + _admin->instantiateApplicationServer(application, templ, vars); + } + catch(const IceXML::ParserException& ex) + { + ostringstream s; + s << ex; + error(s.str()); + } + catch(const DeploymentException& ex) + { + ostringstream s; + s << ex << ":\n" << ex.reason; + error(s.str()); + } + catch(const Ice::Exception& ex) + { + ostringstream s; + s << ex; + error(s.str()); + } +} + +void Parser::listAllApplications() { try @@ -712,9 +764,9 @@ Parser::listAllNodes() void Parser::addServer(const list<string>& args) { - if(args.size() < 3) + if(args.size() < 2) { - error("`server add' requires at least three arguments\n(`help' for more info)"); + error("`server add' requires at least two arguments\n(`help' for more info)"); return; } @@ -759,9 +811,9 @@ Parser::addServer(const list<string>& args) void Parser::updateServer(const list<string>& args) { - if(args.size() < 3) + if(args.size() < 2) { - error("`server add' requires at least three arguments\n(`help' for more info)"); + error("`server update' requires at least two arguments\n(`help' for more info)"); return; } diff --git a/cpp/src/IceGrid/Parser.h b/cpp/src/IceGrid/Parser.h index 70255ad1df4..3d9493226fd 100644 --- a/cpp/src/IceGrid/Parser.h +++ b/cpp/src/IceGrid/Parser.h @@ -72,6 +72,7 @@ public: void describeApplication(const std::list<std::string>&); void diffApplication(const std::list<std::string>&); void updateApplication(const std::list<std::string>&); + void instantiateApplication(const std::list<std::string>&); void listAllApplications(); void pingNode(const std::list<std::string>&); diff --git a/cpp/src/IceGrid/Scanner.l b/cpp/src/IceGrid/Scanner.l index 8cb8498b6a1..967e6de47b0 100644 --- a/cpp/src/IceGrid/Scanner.l +++ b/cpp/src/IceGrid/Scanner.l @@ -205,6 +205,10 @@ NL [\n] return ICE_GRID_UPDATE; } +"instantiate" { + return ICE_GRID_INSTANTIATE; +} + {WS}*(\\{WS}*{NL})? { size_t len = strlen(yytext); for(size_t i = 0; i < len; ++i) |