diff options
author | Benoit Foucher <benoit@zeroc.com> | 2005-05-31 16:35:04 +0000 |
---|---|---|
committer | Benoit Foucher <benoit@zeroc.com> | 2005-05-31 16:35:04 +0000 |
commit | 49e0e0650eaf4ba741d144dddad0fd39a6fc6128 (patch) | |
tree | 0e75478a1c4b55c30e5f885f8c0cfe2c942009b4 /cpp/src | |
parent | Fixes (diff) | |
download | ice-49e0e0650eaf4ba741d144dddad0fd39a6fc6128.tar.bz2 ice-49e0e0650eaf4ba741d144dddad0fd39a6fc6128.tar.xz ice-49e0e0650eaf4ba741d144dddad0fd39a6fc6128.zip |
Replaced "server" with "server-instance"
Fixed describe admin commands
Fixed instantiate server template command.
Diffstat (limited to 'cpp/src')
-rw-r--r-- | cpp/src/IceGrid/AdminI.cpp | 20 | ||||
-rw-r--r-- | cpp/src/IceGrid/AdminI.h | 4 | ||||
-rw-r--r-- | cpp/src/IceGrid/DescriptorHelper.cpp | 61 | ||||
-rw-r--r-- | cpp/src/IceGrid/DescriptorParser.cpp | 38 | ||||
-rw-r--r-- | cpp/src/IceGrid/Grammar.y | 14 | ||||
-rw-r--r-- | cpp/src/IceGrid/Parser.cpp | 305 | ||||
-rw-r--r-- | cpp/src/IceGrid/Parser.h | 7 |
7 files changed, 277 insertions, 172 deletions
diff --git a/cpp/src/IceGrid/AdminI.cpp b/cpp/src/IceGrid/AdminI.cpp index 8991a278714..9f6252c15cb 100644 --- a/cpp/src/IceGrid/AdminI.cpp +++ b/cpp/src/IceGrid/AdminI.cpp @@ -58,12 +58,22 @@ AdminI::getApplicationDescriptor(const string& name, const Current&) const } void -AdminI::instantiateApplicationServer(const string& name, const string& tmpl, const StringStringDict& variables, - const Current&) +AdminI::instantiateServer(const string& name, const string& tmpl, const string& node, + const StringStringDict& parameters, const Current&) { - ApplicationDescriptorHelper helper(_communicator, _database->getApplicationDescriptor(name)); - helper.addServer(tmpl, variables); - _database->updateApplicationDescriptor(helper.getDescriptor()); + try + { + ApplicationDescriptorHelper helper(_communicator, _database->getApplicationDescriptor(name)); + helper.getVariables()->addVariable("node", node); + helper.addServer(tmpl, parameters); + _database->updateApplicationDescriptor(helper.getDescriptor()); + } + catch(const std::string& msg) + { + DeploymentException ex; + ex.reason = msg; + throw ex; + } } Ice::StringSeq diff --git a/cpp/src/IceGrid/AdminI.h b/cpp/src/IceGrid/AdminI.h index 182972bcd93..16f412b8d44 100644 --- a/cpp/src/IceGrid/AdminI.h +++ b/cpp/src/IceGrid/AdminI.h @@ -29,8 +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 void instantiateServer(const std::string&, const std::string&, const std::string&, const StringStringDict&, + const Ice::Current&); virtual Ice::StringSeq getAllApplicationNames(const Ice::Current&) const; virtual void addServer(const ApplicationDescriptorPtr&, const Ice::Current&); diff --git a/cpp/src/IceGrid/DescriptorHelper.cpp b/cpp/src/IceGrid/DescriptorHelper.cpp index 0194e2a35f7..f77a244b057 100644 --- a/cpp/src/IceGrid/DescriptorHelper.cpp +++ b/cpp/src/IceGrid/DescriptorHelper.cpp @@ -980,30 +980,65 @@ ServerDescriptorHelper::operator==(const ServerDescriptorHelper& helper) const { return false; } - + + // + // First we compare the service instances which have a + // descriptor set (this is the case for services not based on + // a template or server instances). + // for(InstanceDescriptorSeq::const_iterator p = ilhs->services.begin(); p != ilhs->services.end(); ++p) { - bool found = false; - for(InstanceDescriptorSeq::const_iterator q = irhs->services.begin(); q != irhs->services.end(); ++q) + if(p->descriptor) { - if(p->descriptor->name != q->descriptor->name) + bool found = false; + for(InstanceDescriptorSeq::const_iterator q = irhs->services.begin(); q != irhs->services.end(); ++q) { - continue; + if(q->descriptor && p->descriptor->name == q->descriptor->name) + { + found = true; + if(ServiceDescriptorHelper(*this, ServiceDescriptorPtr::dynamicCast(p->descriptor)) != + ServiceDescriptorHelper(*this, ServiceDescriptorPtr::dynamicCast(q->descriptor))) + { + return false; + } + break; + } } - - found = true; - if(ServiceDescriptorHelper(*this, ServiceDescriptorPtr::dynamicCast(p->descriptor)) != - ServiceDescriptorHelper(*this, ServiceDescriptorPtr::dynamicCast(q->descriptor))) + if(!found) { - return false; + return false; } - break; } - if(!found) + } + + // + // Then, we compare the service instances for which no + // descriptor is set. + // + set<InstanceDescriptor> lsvcs; + set<InstanceDescriptor> rsvcs; + for(InstanceDescriptorSeq::const_iterator p = ilhs->services.begin(); p != ilhs->services.end(); ++p) + { + if(!p->descriptor) + { + InstanceDescriptor instance = *p; + instance.descriptor = 0; + lsvcs.insert(instance); + } + } + for(InstanceDescriptorSeq::const_iterator p = irhs->services.begin(); p != irhs->services.end(); ++p) + { + if(!p->descriptor) { - return false; + InstanceDescriptor instance = *p; + instance.descriptor = 0; + rsvcs.insert(instance); } } + if(lsvcs != rsvcs) + { + return false; + } } return true; } diff --git a/cpp/src/IceGrid/DescriptorParser.cpp b/cpp/src/IceGrid/DescriptorParser.cpp index aff1fc7e6a8..38f07c95138 100644 --- a/cpp/src/IceGrid/DescriptorParser.cpp +++ b/cpp/src/IceGrid/DescriptorParser.cpp @@ -205,7 +205,7 @@ DescriptorHandler::startElement(const string& name, const IceXML::Attributes& at { _currentApplication->addNode(attrs); } - else if(name == "server") + else if(name == "server" || name == "server-instance") { if(!_currentApplication.get()) { @@ -220,7 +220,7 @@ DescriptorHandler::startElement(const string& name, const IceXML::Attributes& at error("the <server> element can only be a child of a <node> element"); } - if(attributes.contains("template")) + if(name == "server-instance") { _currentApplication->addServer(attributes("template"), attrs); } @@ -240,7 +240,7 @@ DescriptorHandler::startElement(const string& name, const IceXML::Attributes& at _currentServer = _currentApplication->addServerTemplate(attributes("id"), attrs); _currentComponent = _currentServer.get(); } - else if(name == "service") + else if(name == "service" || name == "service-instance") { if(!_currentServer.get()) { @@ -251,7 +251,7 @@ DescriptorHandler::startElement(const string& name, const IceXML::Attributes& at error("element <service> inside a service definition"); } - if(attributes.contains("template")) + if(name == "service-instance") { _currentServer->addService(attributes("template"), attrs); } @@ -374,33 +374,29 @@ DescriptorHandler::endElement(const string& name, int line, int column) } else if(name == "node") { - _variables->remove("node"); + _currentApplication->endNodeParsing(); } else if(name == "server" || name == "server-template") { - if(_currentServer.get()) + assert(_currentServer.get()); + _currentServer->endParsing(); + if(name == "server") { - _currentServer->endParsing(); - if(name == "server") - { - _currentApplication->addServer(_currentServer->getDescriptor()); - } - _currentServer.reset(0); - _currentComponent = 0; + _currentApplication->addServer(_currentServer->getDescriptor()); } + _currentServer.reset(0); + _currentComponent = 0; } else if(name == "service" || name == "service-template") { - if(_currentService.get()) + assert(_currentService.get()); + _currentService->endParsing(); + if(name == "service") { - _currentService->endParsing(); - if(name == "service") - { - _currentServer->addService(_currentService->getDescriptor()); - } - _currentService.reset(0); - _currentComponent = _currentServer.get(); + _currentServer->addService(_currentService->getDescriptor()); } + _currentService.reset(0); + _currentComponent = _currentServer.get(); } else if(name == "comment") { diff --git a/cpp/src/IceGrid/Grammar.y b/cpp/src/IceGrid/Grammar.y index b0598b3f876..897c05af293 100644 --- a/cpp/src/IceGrid/Grammar.y +++ b/cpp/src/IceGrid/Grammar.y @@ -122,17 +122,17 @@ command { parser->describeApplication($3); } -| ICE_GRID_APPLICATION ICE_GRID_SERVER ICE_GRID_TEMPLATE ICE_GRID_DESCRIBE strings ';' +| ICE_GRID_SERVER ICE_GRID_TEMPLATE ICE_GRID_DESCRIBE strings ';' { - parser->describeApplicationServerTemplate($5); + parser->describeServerTemplate($4); } -| ICE_GRID_APPLICATION ICE_GRID_SERVICE ICE_GRID_TEMPLATE ICE_GRID_DESCRIBE strings ';' +| ICE_GRID_SERVER ICE_GRID_TEMPLATE ICE_GRID_INSTANTIATE strings ';' { - parser->describeApplicationServiceTemplate($5); -}| - ICE_GRID_APPLICATION ICE_GRID_INSTANTIATE strings ';' + parser->instantiateServerTemplate($4); +} +| ICE_GRID_SERVICE ICE_GRID_TEMPLATE ICE_GRID_DESCRIBE strings ';' { - parser->instantiateApplication($3); + parser->describeServiceTemplate($4); } | ICE_GRID_APPLICATION ICE_GRID_LIST ';' { diff --git a/cpp/src/IceGrid/Parser.cpp b/cpp/src/IceGrid/Parser.cpp index fed59d3ec86..2d4feb1d44c 100644 --- a/cpp/src/IceGrid/Parser.cpp +++ b/cpp/src/IceGrid/Parser.cpp @@ -77,7 +77,7 @@ describeDbEnv(Output& out, const DbEnvDescriptor& dbEnv) out << sb; for(PropertyDescriptorSeq::const_iterator p = dbEnv.properties.begin(); p != dbEnv.properties.end(); ++p) { - out << nl << p->name << " = " << p->value; + out << nl << p->name << " = '" << p->value << "'"; } out << eb; } @@ -114,7 +114,7 @@ describeProperties(Output& out, const PropertyDescriptorSeq& properties) out << sb; for(PropertyDescriptorSeq::const_iterator p = properties.begin(); p != properties.end(); ++p) { - out << nl << p->name << " = " << p->value; + out << nl << p->name << " = '" << p->value << "'"; } out << eb; } @@ -129,6 +129,16 @@ describeComponent(Output& out, const Ice::CommunicatorPtr& communicator, const C out << nl << desc->comment; out << eb; } + if(!desc->variables.empty()) + { + out << nl << "variables"; + out << sb; + for(StringStringDict::const_iterator p = desc->variables.begin(); p != desc->variables.end(); ++p) + { + out << nl << p->first << " = '" << p->second << "'"; + } + out << eb; + } if(!desc->properties.empty()) { describeProperties(out, desc->properties); @@ -220,7 +230,7 @@ describe(Output& out, const Ice::CommunicatorPtr& communicator, const string& id ServiceDescriptorPtr service = ServiceDescriptorPtr::dynamicCast(templ.descriptor); if(service) { - out << nl << "service template '" << id << "'"; + out << "service template '" << id << "'"; } out << sb; @@ -228,29 +238,19 @@ describe(Output& out, const Ice::CommunicatorPtr& communicator, const string& id { out << nl << "parameters = '" << toString(templ.parameters) << "'"; } - if(!server->variables.empty()) - { - out << nl << "variables"; - out << sb; - for(StringStringDict::const_iterator p = server->variables.begin(); p != server->variables.end(); ++p) - { - out << nl << p->first << " = " << p->second; - } - out << eb; - } - out << nl << "name = '" << server->name << "'"; + out << nl << "name = '" << templ.descriptor->name << "'"; if(server) { describeServer(out, communicator, server); out << eb; - out << nl; } if(service) { describeService(out, communicator, service); out << eb; } + out << nl; } @@ -260,27 +260,70 @@ describe(Output& out, const Ice::CommunicatorPtr& communicator, const InstanceDe ServerDescriptorPtr server = ServerDescriptorPtr::dynamicCast(inst.descriptor); if(server) { - out << "server '" << server->name << "' "; + if(inst._cpp_template.empty()) + { + out << "server '" << server->name << "' "; + } + else + { + out << "server instance '" << server->name << "' "; + } IceBoxDescriptorPtr iceBox = IceBoxDescriptorPtr::dynamicCast(server); if(iceBox) { out << " (IceBox)"; } - out << sb; - describeServer(out, communicator, server); - out << eb; } ServiceDescriptorPtr service = ServiceDescriptorPtr::dynamicCast(inst.descriptor); if(service) { - out << nl << "service '" << service->name << "'"; - out << sb; + if(inst._cpp_template.empty()) + { + out << nl << "service '" << service->name << "'"; + } + else + { + out << nl << "service instance '" << service->name << "'"; + } + } + + if(!server && !service) + { + out << nl << "service instance"; + } + + out << sb; + if(!inst._cpp_template.empty()) + { + out << nl << "template = '" << inst._cpp_template << "'"; + if(!inst.parameterValues.empty()) + { + out << nl << "parameters"; + out << sb; + for(StringStringDict::const_iterator p = inst.parameterValues.begin(); p != inst.parameterValues.end(); + ++p) + { + out << nl << p->first << " = '" << p->second << "'"; + } + out << eb; + } + } + if(server) + { + describeServer(out, communicator, server); + out << eb; + out << nl; + } + if(service) + { describeService(out, communicator, service); out << eb; } - - out << nl; + if(!server && !service) + { + out << eb; + } } } @@ -303,21 +346,22 @@ Parser::usage() " the optional targets TARGET will be deployed.\n" "application remove NAME Remove application NAME.\n" "application describe NAME Describe application NAME.\n" - "application server template describe NAME TEMPLATE\n" - " Describe application NAME server template TEMPLATE.\n" - "application service template describe NAME TEMPLATE\n" - " Describe application NAME service template TEMPLATE.\n" - "application describe NAME Describe application NAME.\n" "application diff DESC [TARGET ... ] [NAME=VALUE ... ]\n" " Print the differences betwen the application\n" " 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" + "server template instantiate APPLICATION TEMPLATE NODE [NAME=VALUE ...]\n" + " Instantiate a server template\n" + "server template describe APPLICATION TEMPLATE\n" + " Describe application server template TEMPLATE.\n" + "\n" + "service template describe APPLICATION TEMPLATE\n" + " Describe application service template TEMPLATE.\n" + "\n" "node list List all registered nodes.\n" "node ping NAME Ping node NAME.\n" "node remove NAME Remove the servers deployed on node NAME and\n" @@ -508,8 +552,7 @@ Parser::describeApplication(const list<string>& args) map<string, set<string> > servers; { for(InstanceDescriptorSeq::const_iterator p = application->servers.begin(); - p != application->servers.end(); - ++p) + p != application->servers.end(); ++p) { const ServerDescriptorPtr descriptor = ServerDescriptorPtr::dynamicCast(p->descriptor); map<string, set<string> >::iterator q = servers.find(descriptor->node); @@ -521,15 +564,35 @@ Parser::describeApplication(const list<string>& args) } } { - for(map<string, set<string> >::const_iterator p = servers.begin(); p != servers.end(); ++p) + for(NodeDescriptorSeq::const_iterator p = application->nodes.begin(); + p != application->nodes.end(); ++p) { - out << nl << "node '" << p->first << "'"; + out << nl << "node '" << p->name << "'"; out << sb; - for(set<string>::const_iterator q = p->second.begin(); q != p->second.end(); ++q) + if(!p->variables.empty()) + { + out << nl << "variables"; + out << sb; + for(StringStringDict::const_iterator q = p->variables.begin(); q != p->variables.end(); ++q) + { + out << nl << q->first << " = '" << q->second << "'"; + } + out << eb; + } { - out << nl << *q; + map<string, set<string> >::const_iterator q = servers.find(p->name); + if(q != servers.end()) + { + out << nl << "servers"; + out << sb; + for(set<string>::const_iterator r = q->second.begin(); r != q->second.end(); ++r) + { + out << nl << *r; + } + out << eb; + } + out << eb; } - out << eb; } } } @@ -551,81 +614,6 @@ Parser::describeApplication(const list<string>& args) } void -Parser::describeApplicationServerTemplate(const list<string>& args) -{ - if(args.size() != 2) - { - error("`application server template describe' requires exactly two arguments\n(`help' for more info)"); - return; - } - - try - { - list<string>::const_iterator p = args.begin(); - - string name = *p++; - string templ = *p++; - - ApplicationDescriptorPtr application = _admin->getApplicationDescriptor(name); - - Output out(cout); - TemplateDescriptorDict::const_iterator q = application->serverTemplates.find(templ); - if(q != application->serverTemplates.end()) - { - describe(out, _communicator, templ, q->second); - } - else - { - error("no server template with id `" + templ + "'"); - } - } - catch(const Ice::Exception& ex) - { - ostringstream s; - s << ex; - error(s.str()); - } -} - -void -Parser::describeApplicationServiceTemplate(const list<string>& args) -{ - if(args.size() != 2) - { - error("`application service template describe' requires exactly two arguments\n(`help' for more info)"); - return; - } - - try - { - list<string>::const_iterator p = args.begin(); - - string name = *p++; - string templ = *p++; - - ApplicationDescriptorPtr application = _admin->getApplicationDescriptor(name); - - Output out(cout); - TemplateDescriptorDict::const_iterator q = application->serviceTemplates.find(templ); - if(q != application->serviceTemplates.end()) - { - describe(out, _communicator, templ, q->second); - } - else - { - error("no service template with id `" + templ + "'"); - } - } - catch(const Ice::Exception& ex) - { - ostringstream s; - s << ex; - error(s.str()); - } -} - - -void Parser::diffApplication(const list<string>& args) { if(args.size() < 1) @@ -892,11 +880,64 @@ Parser::updateApplication(const list<string>& args) } void -Parser::instantiateApplication(const list<string>& args) +Parser::listAllApplications() { - if(args.size() < 2) + try + { + Ice::StringSeq names = _admin->getAllApplicationNames(); + copy(names.begin(), names.end(), ostream_iterator<string>(cout,"\n")); + } + catch(const Ice::Exception& ex) + { + ostringstream s; + s << ex; + error(s.str()); + } +} + +void +Parser::describeServerTemplate(const list<string>& args) +{ + if(args.size() != 2) { - error("`application instantiate' requires at least two arguments\n(`help' for more info)"); + error("`server template describe' requires exactly two arguments\n(`help' for more info)"); + return; + } + + try + { + list<string>::const_iterator p = args.begin(); + + string name = *p++; + string templ = *p++; + + ApplicationDescriptorPtr application = _admin->getApplicationDescriptor(name); + + Output out(cout); + TemplateDescriptorDict::const_iterator q = application->serverTemplates.find(templ); + if(q != application->serverTemplates.end()) + { + describe(out, _communicator, templ, q->second); + } + else + { + error("no server template with id `" + templ + "'"); + } + } + catch(const Ice::Exception& ex) + { + ostringstream s; + s << ex; + error(s.str()); + } +} + +void +Parser::instantiateServerTemplate(const list<string>& args) +{ + if(args.size() < 3) + { + error("`server template instantiate' requires at least three arguments\n(`help' for more info)"); return; } @@ -907,6 +948,7 @@ Parser::instantiateApplication(const list<string>& args) list<string>::const_iterator p = args.begin(); string application = *p++; string templ = *p++; + string node = *p++; for(; p != args.end(); ++p) { @@ -917,7 +959,7 @@ Parser::instantiateApplication(const list<string>& args) } } - _admin->instantiateApplicationServer(application, templ, vars); + _admin->instantiateServer(application, templ, node, vars); } catch(const IceXML::ParserException& ex) { @@ -940,12 +982,33 @@ Parser::instantiateApplication(const list<string>& args) } void -Parser::listAllApplications() +Parser::describeServiceTemplate(const list<string>& args) { + if(args.size() != 2) + { + error("`service template describe' requires exactly two arguments\n(`help' for more info)"); + return; + } + try { - Ice::StringSeq names = _admin->getAllApplicationNames(); - copy(names.begin(), names.end(), ostream_iterator<string>(cout,"\n")); + list<string>::const_iterator p = args.begin(); + + string name = *p++; + string templ = *p++; + + ApplicationDescriptorPtr application = _admin->getApplicationDescriptor(name); + + Output out(cout); + TemplateDescriptorDict::const_iterator q = application->serviceTemplates.find(templ); + if(q != application->serviceTemplates.end()) + { + describe(out, _communicator, templ, q->second); + } + else + { + error("no service template with id `" + templ + "'"); + } } catch(const Ice::Exception& ex) { @@ -1545,8 +1608,8 @@ Parser::describeObject(const list<string>& args) if(arg.find('*') == string::npos) { ObjectDescriptor desc = _admin->getObjectDescriptor(Ice::stringToIdentity(arg)); - cout << "proxy = " << _communicator->proxyToString(desc.proxy) << endl; - cout << "type = " << desc.type << endl; + cout << "proxy = '" << _communicator->proxyToString(desc.proxy) << "'" << endl; + cout << "type = '" << desc.type << "'" << endl; return; } else diff --git a/cpp/src/IceGrid/Parser.h b/cpp/src/IceGrid/Parser.h index c9db686d181..f36ec9de160 100644 --- a/cpp/src/IceGrid/Parser.h +++ b/cpp/src/IceGrid/Parser.h @@ -70,13 +70,14 @@ public: void addApplication(const std::list<std::string>&); void removeApplication(const std::list<std::string>&); void describeApplication(const std::list<std::string>&); - void describeApplicationServerTemplate(const std::list<std::string>&); - void describeApplicationServiceTemplate(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 describeServerTemplate(const std::list<std::string>&); + void describeServiceTemplate(const std::list<std::string>&); + void instantiateServerTemplate(const std::list<std::string>&); + void pingNode(const std::list<std::string>&); void shutdownNode(const std::list<std::string>&); void removeNode(const std::list<std::string>&); |