diff options
Diffstat (limited to 'cpp/src')
-rw-r--r-- | cpp/src/IceGrid/AdminI.cpp | 26 | ||||
-rw-r--r-- | cpp/src/IceGrid/AdminI.h | 4 | ||||
-rw-r--r-- | cpp/src/IceGrid/Database.cpp | 169 | ||||
-rw-r--r-- | cpp/src/IceGrid/Database.h | 31 | ||||
-rw-r--r-- | cpp/src/IceGrid/DescriptorHelper.cpp | 67 | ||||
-rw-r--r-- | cpp/src/IceGrid/DescriptorHelper.h | 4 | ||||
-rw-r--r-- | cpp/src/IceGrid/Parser.cpp | 109 | ||||
-rw-r--r-- | cpp/src/IceGrid/ServerI.cpp | 7 | ||||
-rw-r--r-- | cpp/src/IceGrid/Util.h | 12 |
9 files changed, 247 insertions, 182 deletions
diff --git a/cpp/src/IceGrid/AdminI.cpp b/cpp/src/IceGrid/AdminI.cpp index 7f14b8669e3..1fb425490d4 100644 --- a/cpp/src/IceGrid/AdminI.cpp +++ b/cpp/src/IceGrid/AdminI.cpp @@ -64,36 +64,24 @@ AdminI::getApplicationDescriptor(const string& name, const Current&) const return _database->getApplicationDescriptor(name); } -void -AdminI::instantiateServer(const string& name, const string& tmpl, const StringStringDict& parameters, const Current&) -{ - try - { - ApplicationDescriptorHelper helper(_communicator, _database->getApplicationDescriptor(name)); - helper.addServerInstance(tmpl, parameters); - _database->syncApplicationDescriptor(0, helper.getDescriptor()); - ApplicationUpdateDescriptor update; - } - catch(const std::string& msg) - { - DeploymentException ex; - ex.reason = msg; - throw ex; - } -} - Ice::StringSeq AdminI::getAllApplicationNames(const Current&) const { return _database->getAllApplications(); } -InstanceDescriptor +ServerInstanceDescriptor AdminI::getServerDescriptor(const string& name, const Current&) const { return _database->getServerDescriptor(name); } +string +AdminI::getServerApplication(const string& name, const Current&) const +{ + return _database->getServerApplication(name); +} + ServerState AdminI::getServerState(const string& name, const Current&) const { diff --git a/cpp/src/IceGrid/AdminI.h b/cpp/src/IceGrid/AdminI.h index fe0f17082b6..dd195430e97 100644 --- a/cpp/src/IceGrid/AdminI.h +++ b/cpp/src/IceGrid/AdminI.h @@ -30,10 +30,10 @@ public: virtual void updateApplication(const ApplicationUpdateDescriptor&, const Ice::Current&); virtual void removeApplication(const std::string&, const Ice::Current&); virtual ApplicationDescriptorPtr getApplicationDescriptor(const ::std::string&, const Ice::Current&) const; - virtual void instantiateServer(const std::string&, const std::string&, const StringStringDict&,const Ice::Current&); virtual Ice::StringSeq getAllApplicationNames(const Ice::Current&) const; - virtual InstanceDescriptor getServerDescriptor(const ::std::string&, const Ice::Current&) const; + virtual ServerInstanceDescriptor getServerDescriptor(const ::std::string&, const Ice::Current&) const; + virtual std::string getServerApplication(const ::std::string&, const Ice::Current&) const; virtual ServerState getServerState(const ::std::string&, const Ice::Current&) const; virtual Ice::Int getServerPid(const ::std::string&, const Ice::Current&) const; virtual bool startServer(const ::std::string&, const Ice::Current&); diff --git a/cpp/src/IceGrid/Database.cpp b/cpp/src/IceGrid/Database.cpp index 0ff1480acdf..788611e868b 100644 --- a/cpp/src/IceGrid/Database.cpp +++ b/cpp/src/IceGrid/Database.cpp @@ -208,9 +208,10 @@ Database::Database(const Ice::ObjectAdapterPtr& adapter, // for(StringApplicationDescriptorDict::const_iterator p = _descriptors.begin(); p != _descriptors.end(); ++p) { - for(InstanceDescriptorSeq::const_iterator q = p->second->servers.begin(); q != p->second->servers.end(); ++q) + ServerInstanceDescriptorSeq::const_iterator q; + for(q = p->second->servers.begin(); q != p->second->servers.end(); ++q) { - addServer(*q); + addServer(p->first, *q); } } } @@ -363,7 +364,7 @@ Database::addApplicationDescriptor(ObserverSessionI* session, const ApplicationD // // Register the application servers. // - addServers(descriptor->servers, servers, entries); + addServers(descriptor->name, descriptor->servers, servers, entries); // // Save the application descriptor. @@ -577,9 +578,9 @@ Database::syncApplicationDescriptorNoSync(const ApplicationDescriptorPtr& origDe // Register the new servers, unregister the old ones and // update the updated ones. // - addServers(newDesc->servers, added, entries); + addServers(newDesc->name, newDesc->servers, added, entries); updateServers(origDesc, newDesc, updated, entries); - removeServers(origDesc->servers, removed, entries); + removeServers(origDesc->name, origDesc->servers, removed, entries); _descriptors.put(make_pair(newDesc->name, newDesc)); } @@ -605,7 +606,7 @@ Database::removeApplicationDescriptor(ObserverSessionI* session, const std::stri set<string> servers; for_each(descriptor->servers.begin(), descriptor->servers.end(), AddServerName(servers)); - removeServers(descriptor->servers, servers, entries); + removeServers(descriptor->name, descriptor->servers, servers, entries); serial = ++_serial; } @@ -737,26 +738,17 @@ Database::getAllNodes(const string& expression) return Ice::StringSeq(nodes.begin(), nodes.end()); } -InstanceDescriptor +ServerInstanceDescriptor Database::getServerDescriptor(const std::string& name) { - ServerDescriptorPtr descriptor; - { - Lock sync(*this); - map<string, ServerEntryPtr>::const_iterator p = _servers.find(name); - if(p == _servers.end()) - { - ServerNotExistException ex; - ex.name = name; - throw ex; - } - descriptor = p->second->getDescriptor(); - } - assert(descriptor); - ApplicationDescriptorPtr app = getApplicationDescriptor(descriptor->application); - for(InstanceDescriptorSeq::const_iterator p = app->servers.begin(); p != app->servers.end(); ++p) + ApplicationDescriptorPtr app = getApplicationDescriptor(getServerApplication(name)); + + // + // TODO: Is it really safe to read the application descriptor outside the lock!? + // + for(ServerInstanceDescriptorSeq::const_iterator p = app->servers.begin(); p != app->servers.end(); ++p) { - if(p->descriptor->name == descriptor->name) + if(p->descriptor->name == name) { return *p; } @@ -767,6 +759,21 @@ Database::getServerDescriptor(const std::string& name) throw ex; } +string +Database::getServerApplication(const string& name) +{ + Lock sync(*this); + map<string, string>::const_iterator p = _applicationsByServerName.find(name); + if(p == _applicationsByServerName.end()) + { + ServerNotExistException ex; + ex.name = name; + throw ex; + } + + return p->second; +} + ServerPrx Database::getServer(const string& name) { @@ -1069,15 +1076,16 @@ Database::checkObjectForAddition(const Ice::Identity& objectId) } void -Database::addServers(const InstanceDescriptorSeq& servers, const set<string>& names, ServerEntrySeq& entries) +Database::addServers(const string& application, const ServerInstanceDescriptorSeq& servers, const set<string>& names, + ServerEntrySeq& entries) { - for(InstanceDescriptorSeq::const_iterator p = servers.begin(); p != servers.end(); ++p) + for(ServerInstanceDescriptorSeq::const_iterator p = servers.begin(); p != servers.end(); ++p) { if(names.find(p->descriptor->name) == names.end()) { continue; } - entries.push_back(addServer(*p)); + entries.push_back(addServer(application, *p)); } } @@ -1088,14 +1096,16 @@ Database::updateServers(const ApplicationDescriptorPtr& oldAppDesc, const Applic ApplicationDescriptorHelper oldAppDescHelper(_communicator, oldAppDesc); ApplicationDescriptorHelper newAppDescHelper(_communicator, newAppDesc); - for(InstanceDescriptorSeq::const_iterator p = newAppDesc->servers.begin(); p != newAppDesc->servers.end(); ++p) + ServerInstanceDescriptorSeq::const_iterator p; + for(p = newAppDesc->servers.begin(); p != newAppDesc->servers.end(); ++p) { if(names.find(p->descriptor->name) == names.end()) { continue; } - for(InstanceDescriptorSeq::const_iterator q = oldAppDesc->servers.begin(); q != oldAppDesc->servers.end(); ++q) + ServerInstanceDescriptorSeq::const_iterator q; + for(q = oldAppDesc->servers.begin(); q != oldAppDesc->servers.end(); ++q) { if(p->descriptor->name == q->descriptor->name) { @@ -1111,20 +1121,21 @@ Database::updateServers(const ApplicationDescriptorPtr& oldAppDesc, const Applic } void -Database::removeServers(const InstanceDescriptorSeq& servers, const set<string>& names, ServerEntrySeq& entries) +Database::removeServers(const string& application, const ServerInstanceDescriptorSeq& servers, + const set<string>& names, ServerEntrySeq& entries) { - for(InstanceDescriptorSeq::const_iterator p = servers.begin(); p != servers.end(); ++p) + for(ServerInstanceDescriptorSeq::const_iterator p = servers.begin(); p != servers.end(); ++p) { if(names.find(p->descriptor->name) == names.end()) { continue; } - entries.push_back(removeServer(*p)); + entries.push_back(removeServer(application, *p)); } } Database::ServerEntryPtr -Database::addServer(const InstanceDescriptor& instance) +Database::addServer(const string& application, const ServerInstanceDescriptor& instance) { const ServerDescriptorPtr descriptor = ServerDescriptorPtr::dynamicCast(instance.descriptor); ServerEntryPtr entry; @@ -1132,27 +1143,29 @@ Database::addServer(const InstanceDescriptor& instance) if(q != _servers.end()) { entry = q->second; - entry->update(descriptor); + entry->update(instance); } else { - entry = new ServerEntry(*this, descriptor); + entry = new ServerEntry(*this, instance); _servers.insert(make_pair(descriptor->name, entry)); } map<string, set<string> >::iterator p = _serversByNode.find(descriptor->node); if(p == _serversByNode.end()) { - p = _serversByNode.insert(make_pair(descriptor->node, set<string>())).first; + p = _serversByNode.insert(make_pair(instance.node, set<string>())).first; } p->second.insert(p->second.begin(), descriptor->name); + _applicationsByServerName.insert(make_pair(descriptor->name, application)); + forEachComponent(AddComponent(*this, entry))(instance); return entry; } Database::ServerEntryPtr -Database::updateServer(const InstanceDescriptor& instance) +Database::updateServer(const ServerInstanceDescriptor& instance) { // // Get the server entry and the current descriptor then check @@ -1164,25 +1177,25 @@ Database::updateServer(const InstanceDescriptor& instance) assert(q != _servers.end()); entry = q->second; - ServerDescriptorPtr old = entry->getDescriptor(); + ServerInstanceDescriptor old = entry->getDescriptor(); // // If the node changed, move the server from the old node to the // new one. // - if(old->node != descriptor->node) + if(old.node != instance.node) { - map<string, set<string> >::iterator p = _serversByNode.find(old->node); + map<string, set<string> >::iterator p = _serversByNode.find(old.node); assert(p != _serversByNode.end()); - p->second.erase(old->name); + p->second.erase(descriptor->name); if(p->second.empty()) { _serversByNode.erase(p); } - p = _serversByNode.find(descriptor->node); + p = _serversByNode.find(instance.node); if(p == _serversByNode.end()) { - p = _serversByNode.insert(make_pair(descriptor->node, set<string>())).first; + p = _serversByNode.insert(make_pair(instance.node, set<string>())).first; } p->second.insert(p->second.begin(), descriptor->name); } @@ -1195,7 +1208,7 @@ Database::updateServer(const InstanceDescriptor& instance) // // Update the server entry. // - entry->update(descriptor); + entry->update(instance); // // Add the new object adapters and objects. @@ -1205,14 +1218,14 @@ Database::updateServer(const InstanceDescriptor& instance) } Database::ServerEntryPtr -Database::removeServer(const InstanceDescriptor& instance) +Database::removeServer(const string& application, const ServerInstanceDescriptor& instance) { const ServerDescriptorPtr descriptor = ServerDescriptorPtr::dynamicCast(instance.descriptor); ServerEntryPtr entry; map<string, ServerEntryPtr>::iterator q = _servers.find(descriptor->name); assert(q != _servers.end()); - map<string, set<string> >::iterator p = _serversByNode.find(descriptor->node); + map<string, set<string> >::iterator p = _serversByNode.find(instance.node); assert(p != _serversByNode.end()); p->second.erase(descriptor->name); if(p->second.empty()) @@ -1221,7 +1234,9 @@ Database::removeServer(const InstanceDescriptor& instance) } entry = q->second; - entry->update(0); + entry->destroy(); + + _applicationsByServerName.erase(descriptor->name); // // Remove the object adapters and objects. @@ -1270,11 +1285,12 @@ Database::removeComponent(const ComponentDescriptorPtr& component) } } -Database::ServerEntry::ServerEntry(Database& database, const ServerDescriptorPtr& descriptor) : +Database::ServerEntry::ServerEntry(Database& database, const ServerInstanceDescriptor& descriptor) : _database(database), - _load(descriptor), _synchronizing(false) { + _load.reset(new ServerInstanceDescriptor()); + *_load = descriptor; } void @@ -1298,37 +1314,62 @@ Database::ServerEntry::needsSync() const } void -Database::ServerEntry::update(const ServerDescriptorPtr& descriptor) +Database::ServerEntry::update(const ServerInstanceDescriptor& instance) { Lock sync(*this); - if(_loaded && (!descriptor || descriptor->node != _loaded->node)) + + auto_ptr<ServerInstanceDescriptor> descriptor(new ServerInstanceDescriptor()); + *descriptor = instance; + + if(_loaded.get() && descriptor->node != _loaded->node) { - assert(!_destroy); + assert(!_destroy.get()); _destroy = _loaded; } - else if(_load && (!descriptor || descriptor->node != _load->node)) + else if(_load.get() && descriptor->node != _load->node) { - assert(!_destroy); + assert(!_destroy.get()); _destroy = _load; } _load = descriptor; - _loaded = 0; + _loaded.reset(0); + _proxy = 0; + _adapters.clear(); +} + +void +Database::ServerEntry::destroy() +{ + Lock sync(*this); + if(_loaded.get()) + { + assert(!_destroy.get()); + _destroy = _loaded; + } + else if(_load.get()) + { + assert(!_destroy.get()); + _destroy = _load; + } + + _load.reset(0); + _loaded.reset(0); _proxy = 0; _adapters.clear(); } -ServerDescriptorPtr +ServerInstanceDescriptor Database::ServerEntry::getDescriptor() { Lock sync(*this); if(_proxy) { - return _loaded; + return *_loaded.get(); } else { - return _load; + return *_load.get(); } } @@ -1401,15 +1442,15 @@ Database::ServerEntry::sync(map<string, AdapterPrx>& adapters) wait(); } - if(!_load && !_destroy) + if(!_load.get() && !_destroy.get()) { _load = _loaded; // Re-load the current server. } _synchronizing = true; _failed = false; - load = _load; - destroy = _destroy; + load = _load.get() ? _load->descriptor : ServerDescriptorPtr(); + destroy = _destroy.get() ? _destroy->descriptor : ServerDescriptorPtr(); } ServerPrx proxy; @@ -1462,7 +1503,7 @@ Database::ServerEntry::sync(map<string, AdapterPrx>& adapters) { Lock sync(*this); _synchronizing = false; - _destroy = 0; + _destroy.reset(0); _failed = true; notifyAll(); } @@ -1477,8 +1518,8 @@ Database::ServerEntry::sync(map<string, AdapterPrx>& adapters) Lock sync(*this); _synchronizing = false; _loaded = _load; - _load = 0; - _destroy = 0; + _load.reset(0); + _destroy.reset(0); _proxy = proxy ? ServerPrx::uncheckedCast(proxy->ice_timeout(_database._nodeSessionTimeout)) : ServerPrx(); _adapters.clear(); for(StringAdapterPrxDict::const_iterator p = adapters.begin(); p != adapters.end(); ++p) @@ -1499,5 +1540,5 @@ bool Database::ServerEntry::canRemove() { Lock sync(*this); - return !_loaded && !_load && !_destroy; + return !_loaded.get() && !_load.get() && !_destroy.get(); } diff --git a/cpp/src/IceGrid/Database.h b/cpp/src/IceGrid/Database.h index c44da283842..c7c5cde3959 100644 --- a/cpp/src/IceGrid/Database.h +++ b/cpp/src/IceGrid/Database.h @@ -38,12 +38,13 @@ class Database : public IceUtil::Shared, public IceUtil::Mutex { public: - ServerEntry(Database&, const ServerDescriptorPtr&); + ServerEntry(Database&, const ServerInstanceDescriptor&); void sync(); bool needsSync() const; - void update(const ServerDescriptorPtr&); - ServerDescriptorPtr getDescriptor(); + void update(const ServerInstanceDescriptor&); + void destroy(); + ServerInstanceDescriptor getDescriptor(); ServerPrx getProxy(); AdapterPrx getAdapter(const std::string&); bool canRemove(); @@ -53,9 +54,9 @@ class Database : public IceUtil::Shared, public IceUtil::Mutex ServerPrx sync(StringAdapterPrxDict& adapters); Database& _database; - ServerDescriptorPtr _loaded; - ServerDescriptorPtr _load; - ServerDescriptorPtr _destroy; + std::auto_ptr<ServerInstanceDescriptor> _loaded; + std::auto_ptr<ServerInstanceDescriptor> _load; + std::auto_ptr<ServerInstanceDescriptor> _destroy; ServerPrx _proxy; std::map<std::string, AdapterPrx> _adapters; bool _synchronizing; @@ -90,7 +91,8 @@ public: void removeNode(const std::string&); Ice::StringSeq getAllNodes(const std::string& = std::string()); - InstanceDescriptor getServerDescriptor(const std::string&); + ServerInstanceDescriptor getServerDescriptor(const std::string&); + std::string getServerApplication(const std::string&); ServerPrx getServer(const std::string&); Ice::StringSeq getAllServers(const std::string& = std::string()); Ice::StringSeq getAllNodeServers(const std::string&); @@ -113,13 +115,15 @@ private: void syncApplicationDescriptorNoSync(const ApplicationDescriptorPtr&, const ApplicationDescriptorPtr&, ServerEntrySeq&); - void addServers(const InstanceDescriptorSeq&, const std::set<std::string>&, ServerEntrySeq&); + void addServers(const std::string&, const ServerInstanceDescriptorSeq&, const std::set<std::string>&, + ServerEntrySeq&); void updateServers(const ApplicationDescriptorPtr&, const ApplicationDescriptorPtr&, const std::set<std::string>&, ServerEntrySeq&); - void removeServers(const InstanceDescriptorSeq&, const std::set<std::string>&, ServerEntrySeq&); - ServerEntryPtr addServer(const InstanceDescriptor&); - ServerEntryPtr updateServer(const InstanceDescriptor&); - ServerEntryPtr removeServer(const InstanceDescriptor&); + void removeServers(const std::string&, const ServerInstanceDescriptorSeq&, const std::set<std::string>&, + ServerEntrySeq&); + ServerEntryPtr addServer(const std::string&, const ServerInstanceDescriptor&); + ServerEntryPtr updateServer(const ServerInstanceDescriptor&); + ServerEntryPtr removeServer(const std::string&, const ServerInstanceDescriptor&); void clearServer(const std::string&); void addComponent(const ServerEntryPtr&, const ComponentDescriptorPtr&); void removeComponent(const ComponentDescriptorPtr&); @@ -145,7 +149,8 @@ private: std::map<std::string, ServerEntryPtr> _serversByAdapterId; std::map<std::string, std::set<std::string> > _serversByNode; std::map<std::string, NodeSessionIPtr> _nodes; - + std::map<std::string, std::string> _applicationsByServerName; + Freeze::ConnectionPtr _connection; StringApplicationDescriptorDict _descriptors; IdentityObjectDescDict _objects; diff --git a/cpp/src/IceGrid/DescriptorHelper.cpp b/cpp/src/IceGrid/DescriptorHelper.cpp index ad7c1bcc500..72acb4dd26b 100644 --- a/cpp/src/IceGrid/DescriptorHelper.cpp +++ b/cpp/src/IceGrid/DescriptorHelper.cpp @@ -618,10 +618,10 @@ void ApplicationDescriptorHelper::addServer(const string& tmpl, const IceXML::Attributes& attrs) { assert(_variables->hasVariable("node")); - InstanceDescriptor instance; + ServerInstanceDescriptor instance; instance._cpp_template = tmpl; + instance.node = _variables->getVariable("node"); instance.parameterValues = attrs; - instance.parameterValues["node"] = _variables->getVariable("node"); instance.parameterValues.erase("template"); _descriptor->servers.push_back(instantiate(instance)); } @@ -630,7 +630,8 @@ void ApplicationDescriptorHelper::addServer(const ServerDescriptorPtr& descriptor) { assert(_variables->hasVariable("node")); - InstanceDescriptor instance; + ServerInstanceDescriptor instance; + instance.node = _variables->getVariable("node"); instance.descriptor = descriptor; instance.targets = _variables->getDeploymentTargets(descriptor->name + "."); _descriptor->servers.push_back(instance); @@ -709,7 +710,7 @@ ApplicationDescriptorHelper::update(const ApplicationUpdateDescriptor& update) } newApp->servers.clear(); - for(InstanceDescriptorSeq::iterator q = newUpdate.servers.begin(); q != newUpdate.servers.end(); ++q) + for(ServerInstanceDescriptorSeq::iterator q = newUpdate.servers.begin(); q != newUpdate.servers.end(); ++q) { *q = instantiate(*q); newApp->servers.push_back(*q); @@ -718,9 +719,9 @@ ApplicationDescriptorHelper::update(const ApplicationUpdateDescriptor& update) set<string> remove(newUpdate.removeServers.begin(), newUpdate.removeServers.end()); set<string> updated; for_each(newApp->servers.begin(), newApp->servers.end(), AddServerName(updated)); - for(InstanceDescriptorSeq::const_iterator q = oldApp->servers.begin(); q != oldApp->servers.end(); ++q) + for(ServerInstanceDescriptorSeq::const_iterator q = oldApp->servers.begin(); q != oldApp->servers.end(); ++q) { - InstanceDescriptor inst = instantiate(*q); // Re-instantiate old server. + ServerInstanceDescriptor inst = instantiate(*q); // Re-instantiate old server. if(updated.find(inst.descriptor->name) == updated.end() && remove.find(inst.descriptor->name) == remove.end()) { if(ServerDescriptorHelper(*this, ServerDescriptorPtr::dynamicCast(q->descriptor)) != @@ -736,13 +737,15 @@ ApplicationDescriptorHelper::update(const ApplicationUpdateDescriptor& update) } void -ApplicationDescriptorHelper::addServerInstance(const string& tmpl, const map<string, string>& parameters) +ApplicationDescriptorHelper::addServerInstance(const string& tmpl, + const string& node, + const map<string, string>& parameters) { - XmlAttributesHelper attributes(_variables, parameters); - pushNodeVariables(attributes("node")); + pushNodeVariables(node); - InstanceDescriptor instance; + ServerInstanceDescriptor instance; instance._cpp_template = tmpl; + instance.node = node; instance.parameterValues = parameters; instance.descriptor = _templates->instantiateServer(*this, tmpl, instance.parameterValues); _descriptor->servers.push_back(instance); @@ -753,23 +756,23 @@ ApplicationDescriptorHelper::addServerInstance(const string& tmpl, const map<str void ApplicationDescriptorHelper::instantiate() { - for(InstanceDescriptorSeq::iterator p = _descriptor->servers.begin(); p != _descriptor->servers.end(); ++p) + for(ServerInstanceDescriptorSeq::iterator p = _descriptor->servers.begin(); p != _descriptor->servers.end(); ++p) { *p = instantiate(*p); } } -InstanceDescriptor -ApplicationDescriptorHelper::instantiate(const InstanceDescriptor& inst) +ServerInstanceDescriptor +ApplicationDescriptorHelper::instantiate(const ServerInstanceDescriptor& inst) { - InstanceDescriptor instance = inst; + ServerInstanceDescriptor instance = inst; if(instance._cpp_template.empty()) { assert(instance.descriptor); return instance; } - XmlAttributesHelper attributes(_variables, instance.parameterValues); - pushNodeVariables(attributes("node")); + + pushNodeVariables(inst.node); instance.descriptor = _templates->instantiateServer(*this, instance._cpp_template, instance.parameterValues); _variables->pop(); return instance; @@ -1025,7 +1028,6 @@ ServerDescriptorHelper::ServerDescriptorHelper(const DescriptorHelper& helper, c if(!_templateId.empty()) { _variables->substitution(false); - _variables->addParameter("node"); } string interpreter = attributes("interpreter", ""); @@ -1043,7 +1045,6 @@ ServerDescriptorHelper::ServerDescriptorHelper(const DescriptorHelper& helper, c ComponentDescriptorHelper::init(_descriptor, attrs); - _descriptor->application = _variables->substitute("${application}"); _descriptor->node = _variables->substitute("${node}"); _descriptor->pwd = attributes("pwd", ""); _descriptor->activation = attributes("activation", "manual"); @@ -1111,11 +1112,6 @@ ServerDescriptorHelper::operator==(const ServerDescriptorHelper& helper) const return false; } - if(_descriptor->application != helper._descriptor->application) - { - return false; - } - if(set<string>(_descriptor->options.begin(), _descriptor->options.end()) != set<string>(helper._descriptor->options.begin(), helper._descriptor->options.end())) { @@ -1161,12 +1157,14 @@ ServerDescriptorHelper::operator==(const ServerDescriptorHelper& helper) const // 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) + for(ServiceInstanceDescriptorSeq::const_iterator p = ilhs->services.begin(); p != ilhs->services.end(); ++p) { if(p->descriptor) { bool found = false; - for(InstanceDescriptorSeq::const_iterator q = irhs->services.begin(); q != irhs->services.end(); ++q) + for(ServiceInstanceDescriptorSeq::const_iterator q = irhs->services.begin(); + q != irhs->services.end(); + ++q) { if(q->descriptor && p->descriptor->name == q->descriptor->name) { @@ -1190,22 +1188,22 @@ ServerDescriptorHelper::operator==(const ServerDescriptorHelper& helper) const // 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) + set<ServiceInstanceDescriptor> lsvcs; + set<ServiceInstanceDescriptor> rsvcs; + for(ServiceInstanceDescriptorSeq::const_iterator p = ilhs->services.begin(); p != ilhs->services.end(); ++p) { if(!p->descriptor) { - InstanceDescriptor instance = *p; + ServiceInstanceDescriptor instance = *p; instance.descriptor = 0; lsvcs.insert(instance); } } - for(InstanceDescriptorSeq::const_iterator p = irhs->services.begin(); p != irhs->services.end(); ++p) + for(ServiceInstanceDescriptorSeq::const_iterator p = irhs->services.begin(); p != irhs->services.end(); ++p) { if(!p->descriptor) { - InstanceDescriptor instance = *p; + ServiceInstanceDescriptor instance = *p; instance.descriptor = 0; rsvcs.insert(instance); } @@ -1252,7 +1250,7 @@ ServerDescriptorHelper::addService(const string& tmpl, const IceXML::Attributes& throw "element <service> can only be a child of an IceBox <server> element"; } - InstanceDescriptor instance; + ServiceInstanceDescriptor instance; instance._cpp_template = tmpl; instance.parameterValues = attrs; instance.parameterValues.erase("template"); @@ -1268,7 +1266,7 @@ ServerDescriptorHelper::addService(const ServiceDescriptorPtr& descriptor) throw "element <service> can only be a child of an IceBox <server> element"; } - InstanceDescriptor instance; + ServiceInstanceDescriptor instance; instance.descriptor = descriptor; if(_templateId.empty()) { @@ -1318,7 +1316,6 @@ ServerDescriptorHelper::instantiateImpl(const ServerDescriptorPtr& desc, set<str ComponentDescriptorHelper::instantiateImpl(desc, missing); - substitute(desc->application); substitute(desc->node); substitute(desc->exe); substitute(desc->pwd); @@ -1331,7 +1328,7 @@ ServerDescriptorHelper::instantiateImpl(const ServerDescriptorPtr& desc, set<str if(iceBox) { ServiceDescriptorDict newServices; - for(InstanceDescriptorSeq::iterator p = iceBox->services.begin(); p != iceBox->services.end(); ++p) + for(ServiceInstanceDescriptorSeq::iterator p = iceBox->services.begin(); p != iceBox->services.end(); ++p) { if(p->_cpp_template.empty()) { diff --git a/cpp/src/IceGrid/DescriptorHelper.h b/cpp/src/IceGrid/DescriptorHelper.h index d31612f6d94..30767621e92 100644 --- a/cpp/src/IceGrid/DescriptorHelper.h +++ b/cpp/src/IceGrid/DescriptorHelper.h @@ -146,14 +146,14 @@ public: std::auto_ptr<ServiceDescriptorHelper> addServiceTemplate(const std::string&, const IceXML::Attributes&); ApplicationUpdateDescriptor update(const ApplicationUpdateDescriptor&); - void addServerInstance(const std::string&, const std::map<std::string, std::string>&); + void addServerInstance(const std::string&, const std::string&, const std::map<std::string, std::string>&); void instantiate(); private: void pushNodeVariables(const std::string&); - InstanceDescriptor instantiate(const InstanceDescriptor&); + ServerInstanceDescriptor instantiate(const ServerInstanceDescriptor&); ApplicationDescriptorPtr _descriptor; }; diff --git a/cpp/src/IceGrid/Parser.cpp b/cpp/src/IceGrid/Parser.cpp index ee95ccbd916..9ca2ddbdaa4 100644 --- a/cpp/src/IceGrid/Parser.cpp +++ b/cpp/src/IceGrid/Parser.cpp @@ -164,13 +164,11 @@ describeService(Output& out, const Ice::CommunicatorPtr& communicator, const Ser describeComponent(out, communicator, service); } -void describe(Output& out, const Ice::CommunicatorPtr&, const InstanceDescriptor&); +void describe(Output& out, const Ice::CommunicatorPtr&, const ServiceInstanceDescriptor&); void describeServer(Output& out, const Ice::CommunicatorPtr& communicator, const ServerDescriptorPtr& server) { - out << nl << "node = '" << server->node << "'"; - out << nl << "application = '" << server->application << "'"; if(!server->interpreter.empty()) { out << nl << "interpreter = '" << server->interpreter << "'"; @@ -207,7 +205,7 @@ describeServer(Output& out, const Ice::CommunicatorPtr& communicator, const Serv // if(iceBox) { - for(InstanceDescriptorSeq::const_iterator p = iceBox->services.begin(); p != iceBox->services.end(); ++p) + for(ServiceInstanceDescriptorSeq::const_iterator p = iceBox->services.begin(); p != iceBox->services.end(); ++p) { describe(out, communicator, *p); } @@ -255,40 +253,75 @@ describe(Output& out, const Ice::CommunicatorPtr& communicator, const string& id void -describe(Output& out, const Ice::CommunicatorPtr& communicator, const InstanceDescriptor& inst) +describe(Output& out, const Ice::CommunicatorPtr& communicator, const ServerInstanceDescriptor& inst) { - ServerDescriptorPtr server = ServerDescriptorPtr::dynamicCast(inst.descriptor); - if(server) + if(inst.descriptor) { if(inst._cpp_template.empty()) { - out << "server '" << server->name << "' "; + out << "server '" << inst.descriptor->name << "' "; } else { - out << "server instance '" << server->name << "' "; + out << "server instance '" << inst.descriptor->name << "' "; } - IceBoxDescriptorPtr iceBox = IceBoxDescriptorPtr::dynamicCast(server); + IceBoxDescriptorPtr iceBox = IceBoxDescriptorPtr::dynamicCast(inst.descriptor); if(iceBox) { out << " (IceBox)"; } } + else + { + out << nl << "server instance"; + } - ServiceDescriptorPtr service = ServiceDescriptorPtr::dynamicCast(inst.descriptor); - if(service) + 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(!inst.targets.empty()) + { + out << nl << "targets = '" << toString(inst.targets) << "'"; + } + + out << nl << "node = '" << inst.node << "'"; + + if(inst.descriptor) + { + describeServer(out, communicator, inst.descriptor); + } + out << eb; +} + +void +describe(Output& out, const Ice::CommunicatorPtr& communicator, const ServiceInstanceDescriptor& inst) +{ + if(inst.descriptor) { if(inst._cpp_template.empty()) { - out << nl << "service '" << service->name << "'"; + out << nl << "service '" << inst.descriptor->name << "'"; } else { - out << nl << "service instance '" << service->name << "'"; + out << nl << "service instance '" << inst.descriptor->name << "'"; } } - - if(!server && !service) + else { out << nl << "service instance"; } @@ -309,25 +342,17 @@ describe(Output& out, const Ice::CommunicatorPtr& communicator, const InstanceDe out << eb; } } + if(!inst.targets.empty()) { out << nl << "targets = '" << toString(inst.targets) << "'"; } - if(server) - { - describeServer(out, communicator, server); - out << eb; - out << nl; - } - if(service) - { - describeService(out, communicator, service); - out << eb; - } - if(!server && !service) + + if(inst.descriptor) { - out << eb; + describeService(out, communicator, inst.descriptor); } + out << eb; } } @@ -358,7 +383,7 @@ Parser::usage() "application list List all deployed applications.\n" " to the application." "\n" - "server template instantiate APPLICATION TEMPLATE [NAME=VALUE ...]\n" + "server template instantiate APPLICATION NODE TEMPLATE [NAME=VALUE ...]\n" " Instantiate a server template\n" "server template describe APPLICATION TEMPLATE\n" " Describe application server template TEMPLATE.\n" @@ -551,7 +576,7 @@ Parser::describeApplication(const list<string>& args) { map<string, set<string> > servers; { - for(InstanceDescriptorSeq::const_iterator p = application->servers.begin(); + for(ServerInstanceDescriptorSeq::const_iterator p = application->servers.begin(); p != application->servers.end(); ++p) { const ServerDescriptorPtr descriptor = ServerDescriptorPtr::dynamicCast(p->descriptor); @@ -668,7 +693,6 @@ Parser::diffApplication(const list<string>& args) out << "application `" << newApp->name << "'"; out << sb; - InstanceDescriptorSeq::const_iterator p; ApplicationDescriptorHelper newAppHelper(_communicator, newApp); ApplicationDescriptorHelper origAppHelper(_communicator, origApp); @@ -791,10 +815,11 @@ Parser::diffApplication(const list<string>& args) set_difference(newSvrs.begin(), newSvrs.end(), oldSvrs.begin(), oldSvrs.end(), set_inserter(added)); set_difference(oldSvrs.begin(), oldSvrs.end(), newSvrs.begin(), newSvrs.end(), set_inserter(removed)); - for(p = newApp->servers.begin(); p != newApp->servers.end(); ++p) + for(ServerInstanceDescriptorSeq::const_iterator p = newApp->servers.begin(); p != newApp->servers.end(); ++p) { ServerDescriptorPtr desc = ServerDescriptorPtr::dynamicCast(p->descriptor); - for(InstanceDescriptorSeq::const_iterator q = origApp->servers.begin(); q != origApp->servers.end(); ++q) + for(ServerInstanceDescriptorSeq::const_iterator q = origApp->servers.begin(); + q != origApp->servers.end(); ++q) { if(desc->name == q->descriptor->name) { @@ -935,9 +960,9 @@ Parser::describeServerTemplate(const list<string>& args) void Parser::instantiateServerTemplate(const list<string>& args) { - if(args.size() < 2) + if(args.size() < 3) { - error("`server template instantiate' requires at least two arguments\n(`help' for more info)"); + error("`server template instantiate' requires at least three arguments\n(`help' for more info)"); return; } @@ -947,6 +972,7 @@ Parser::instantiateServerTemplate(const list<string>& args) list<string>::const_iterator p = args.begin(); string application = *p++; + string node = *p++; string templ = *p++; for(; p != args.end(); ++p) @@ -960,8 +986,9 @@ Parser::instantiateServerTemplate(const list<string>& args) ApplicationUpdateDescriptor update; update.name = application; - InstanceDescriptor desc; + ServerInstanceDescriptor desc; desc._cpp_template = templ; + desc.node = node; desc.parameterValues = vars; update.servers.push_back(desc); _admin->updateApplication(update); @@ -1120,10 +1147,9 @@ Parser::removeServer(const list<string>& args) try { - InstanceDescriptor server = _admin->getServerDescriptor(args.front()); ApplicationUpdateDescriptor update; - update.name = ServerDescriptorPtr::dynamicCast(server.descriptor)->application; - update.removeServers.push_back(server.descriptor->name); + update.name = _admin->getServerApplication(args.front()); + update.removeServers.push_back(args.front()); _admin->updateApplication(update); } catch(const Ice::Exception& ex) @@ -1237,9 +1263,10 @@ Parser::describeServer(const list<string>& args) try { - InstanceDescriptor desc = _admin->getServerDescriptor(args.front()); + ServerInstanceDescriptor desc = _admin->getServerDescriptor(args.front()); Output out(cout); describe(out, _communicator, desc); + out << nl; } catch(const Ice::Exception& ex) { diff --git a/cpp/src/IceGrid/ServerI.cpp b/cpp/src/IceGrid/ServerI.cpp index 93826d41e8a..b7b6ca15e3c 100644 --- a/cpp/src/IceGrid/ServerI.cpp +++ b/cpp/src/IceGrid/ServerI.cpp @@ -678,7 +678,7 @@ ServerI::update(const ServerDescriptorPtr& descriptor, StringAdapterPrxDict& ada IceBoxDescriptorPtr iceBox = IceBoxDescriptorPtr::dynamicCast(descriptor); if(iceBox) { - for(InstanceDescriptorSeq::const_iterator p = iceBox->services.begin(); p != iceBox->services.end(); ++p) + for(ServiceInstanceDescriptorSeq::const_iterator p = iceBox->services.begin(); p != iceBox->services.end(); ++p) { updateConfigFile(_serverDir, ServiceDescriptorPtr::dynamicCast(p->descriptor)); knownFiles.push_back("config_" + p->descriptor->name); @@ -751,7 +751,7 @@ ServerI::update(const ServerDescriptorPtr& descriptor, StringAdapterPrxDict& ada } if(iceBox) { - for(InstanceDescriptorSeq::const_iterator p = iceBox->services.begin(); p != iceBox->services.end(); ++p) + for(ServiceInstanceDescriptorSeq::const_iterator p = iceBox->services.begin(); p != iceBox->services.end(); ++p) { ServiceDescriptorPtr s = ServiceDescriptorPtr::dynamicCast(p->descriptor); for(AdapterDescriptorSeq::const_iterator q = s->adapters.begin(); q != s->adapters.end(); ++q) @@ -811,7 +811,8 @@ ServerI::updateConfigFile(const string& serverDir, const ComponentDescriptorPtr& IceBoxDescriptorPtr iceBox = IceBoxDescriptorPtr::dynamicCast(descriptor); if(iceBox) { - for(InstanceDescriptorSeq::const_iterator p = iceBox->services.begin(); p != iceBox->services.end(); ++p) + ServiceInstanceDescriptorSeq::const_iterator p; + for(p = iceBox->services.begin(); p != iceBox->services.end(); ++p) { ServiceDescriptorPtr s = ServiceDescriptorPtr::dynamicCast(p->descriptor); const string path = serverDir + "/config/config_" + s->name; diff --git a/cpp/src/IceGrid/Util.h b/cpp/src/IceGrid/Util.h index 2cce2497fbd..10d511f55b5 100644 --- a/cpp/src/IceGrid/Util.h +++ b/cpp/src/IceGrid/Util.h @@ -30,7 +30,13 @@ struct ForEachComponent : std::unary_function<ComponentDescriptorPtr&, void> } void - operator()(const InstanceDescriptor& instance) + operator()(const ServerInstanceDescriptor& instance) + { + operator()(instance.descriptor); + } + + void + operator()(const ServiceInstanceDescriptor& instance) { operator()(instance.descriptor); } @@ -91,14 +97,14 @@ inline getMatchingKeys(const T& m, const std::string& expression) return keys; } -struct AddServerName : std::unary_function<InstanceDescriptor&, void> +struct AddServerName : std::unary_function<ServerInstanceDescriptor&, void> { AddServerName(std::set<std::string>& names) : _names(names) { } void - operator()(const InstanceDescriptor& instance) + operator()(const ServerInstanceDescriptor& instance) { if(!_names.insert(instance.descriptor->name).second) { |