diff options
author | Benoit Foucher <benoit@zeroc.com> | 2005-06-14 08:10:49 +0000 |
---|---|---|
committer | Benoit Foucher <benoit@zeroc.com> | 2005-06-14 08:10:49 +0000 |
commit | d5e2d2bc732ca46ac26bc8c3aefdf9c4755e44be (patch) | |
tree | 9422b67834be0be1672f50325b11e1a80e298c76 /cpp/src | |
parent | fix for bug 257: removing finalizer in SslConnector (diff) | |
download | ice-d5e2d2bc732ca46ac26bc8c3aefdf9c4755e44be.tar.bz2 ice-d5e2d2bc732ca46ac26bc8c3aefdf9c4755e44be.tar.xz ice-d5e2d2bc732ca46ac26bc8c3aefdf9c4755e44be.zip |
Fixed bug in application update code.
Diffstat (limited to 'cpp/src')
-rw-r--r-- | cpp/src/IceGrid/Database.cpp | 13 | ||||
-rw-r--r-- | cpp/src/IceGrid/DescriptorHelper.cpp | 101 | ||||
-rw-r--r-- | cpp/src/IceGrid/DescriptorHelper.h | 7 |
3 files changed, 101 insertions, 20 deletions
diff --git a/cpp/src/IceGrid/Database.cpp b/cpp/src/IceGrid/Database.cpp index 30d7e7be165..f33e788bdc0 100644 --- a/cpp/src/IceGrid/Database.cpp +++ b/cpp/src/IceGrid/Database.cpp @@ -243,6 +243,10 @@ Database::addApplicationDescriptor(const ApplicationDescriptorPtr& descriptor) throw ex; } + ApplicationDescriptorHelper helper(_communicator, descriptor); + helper.instantiate(); + descriptor = helper.getDescriptor(); + // // Ensure that the application servers, adapters and objects // aren't already registered. @@ -369,12 +373,15 @@ Database::syncApplicationDescriptor(const ApplicationDescriptorPtr& newDesc) ex.name = newDesc->name; throw ex; } - ApplicationDescriptorPtr origDesc = p->second; + ApplicationDescriptorHelper helper(_communicator, newDesc); + helper.instantiate(); + + // // Synchronize the application descriptor. // - syncApplicationDescriptorNoSync(origDesc, newDesc, entries); + syncApplicationDescriptorNoSync(p->second, helper.getDescriptor(), entries); } // @@ -440,7 +447,7 @@ Database::syncApplicationDescriptorNoSync(const ApplicationDescriptorPtr& origDe DeploymentException ex; ex.reason = "adapter `" + e.id + "' is already registered"; throw ex; - } + } // // Ensure that the new application objects aren't already diff --git a/cpp/src/IceGrid/DescriptorHelper.cpp b/cpp/src/IceGrid/DescriptorHelper.cpp index 984d9c300cd..55a42b49ff0 100644 --- a/cpp/src/IceGrid/DescriptorHelper.cpp +++ b/cpp/src/IceGrid/DescriptorHelper.cpp @@ -296,6 +296,12 @@ DescriptorTemplates::DescriptorTemplates(const ApplicationDescriptorPtr& descrip { } +void +DescriptorTemplates::setDescriptor(const ApplicationDescriptorPtr& desc) +{ + _application = desc; +} + ServerDescriptorPtr DescriptorTemplates::instantiateServer(const DescriptorHelper& helper, const string& name, @@ -585,39 +591,47 @@ void ApplicationDescriptorHelper::addNode(const IceXML::Attributes& attrs) { XmlAttributesHelper attributes(_variables, attrs); - - NodeDescriptor node; - node.name = attributes("name"); - + + string node = attributes("name"); _variables->push(); - _variables->addVariable("node", node.name); - - _descriptor->nodes.push_back(node); + _variables->addVariable("node", node); + for(NodeDescriptorSeq::const_iterator p = _descriptor->nodes.begin(); p != _descriptor->nodes.end(); ++p) + { + if(p->name == node) + { + _variables->push(p->variables); + break; + } + } } void ApplicationDescriptorHelper::endNodeParsing() { - _descriptor->nodes.back().variables = _variables->getCurrentScopeVariables(); + NodeDescriptor node; + node.name = _variables->getVariable("node"); + node.variables = _variables->getCurrentScopeVariables(); + _descriptor->nodes.push_back(node); _variables->pop(); } + void ApplicationDescriptorHelper::addServer(const string& tmpl, const IceXML::Attributes& attrs) { - XmlAttributesHelper attributes(_variables, attrs); + assert(_variables->hasVariable("node")); InstanceDescriptor instance; instance._cpp_template = tmpl; instance.parameterValues = attrs; instance.parameterValues["node"] = _variables->getVariable("node"); instance.parameterValues.erase("template"); - instance.descriptor = _templates->instantiateServer(*this, tmpl, instance.parameterValues); _descriptor->servers.push_back(instance); } void ApplicationDescriptorHelper::addServer(const ServerDescriptorPtr& descriptor) { + assert(_variables->hasVariable("node")); InstanceDescriptor instance; instance.descriptor = descriptor; instance.targets = _variables->getDeploymentTargets(descriptor->name + "."); @@ -671,6 +685,9 @@ ApplicationDescriptorHelper::update(const ApplicationUpdateDescriptor& update) newApp->serviceTemplates.erase(*p); } + // + // Update the node descriptors. + // newApp->nodes = update.nodes; for(NodeDescriptorSeq::const_iterator q = _descriptor->nodes.begin(); q != _descriptor->nodes.end(); ++q) { @@ -688,11 +705,6 @@ ApplicationDescriptorHelper::update(const ApplicationUpdateDescriptor& update) } } - // - // TODO: This isn't correct we need to check that the instances - // are valid, we can't just add them like this! - // - newApp->servers = update.servers; set<string> remove(update.removeServers.begin(), update.removeServers.end()); set<string> updated; @@ -706,6 +718,63 @@ ApplicationDescriptorHelper::update(const ApplicationUpdateDescriptor& update) } _descriptor = newApp; + _templates->setDescriptor(newApp); + + // + // Re-instantiate the servers based on a template. + // + instantiate(); +} + +void +ApplicationDescriptorHelper::addServerInstance(const string& tmpl, const map<string, string>& parameters) +{ + XmlAttributesHelper attributes(_variables, parameters); + pushNodeVariables(attributes("node")); + + InstanceDescriptor instance; + instance._cpp_template = tmpl; + instance.parameterValues = parameters; + instance.descriptor = _templates->instantiateServer(*this, tmpl, instance.parameterValues); + _descriptor->servers.push_back(instance); + + _variables->pop(); +} + +void +ApplicationDescriptorHelper::instantiate() +{ + for(InstanceDescriptorSeq::iterator p = _descriptor->servers.begin(); p != _descriptor->servers.end(); ++p) + { + if(p->_cpp_template.empty()) + { + continue; + } + + XmlAttributesHelper attributes(_variables, p->parameterValues); + pushNodeVariables(attributes("node")); + p->descriptor = _templates->instantiateServer(*this, p->_cpp_template, p->parameterValues); + _variables->pop(); + } +} + +void +ApplicationDescriptorHelper::pushNodeVariables(const string& node) +{ + NodeDescriptorSeq::const_iterator q; + for(q = _descriptor->nodes.begin(); q != _descriptor->nodes.end(); ++q) + { + if(q->name == node) + { + _variables->push(q->variables); + break; + } + } + if(q == _descriptor->nodes.end()) + { + _variables->push(); + } + _variables->addVariable("node", node); } ComponentDescriptorHelper::ComponentDescriptorHelper(const DescriptorHelper& helper) : DescriptorHelper(helper) @@ -958,7 +1027,7 @@ ServerDescriptorHelper::ServerDescriptorHelper(const DescriptorHelper& helper, c ComponentDescriptorHelper::init(_descriptor, attrs); _descriptor->application = _variables->substitute("${application}"); - _descriptor->node = "${node}"; + _descriptor->node = _variables->substitute("${node}"); _descriptor->pwd = attributes("pwd", ""); _descriptor->activation = attributes("activation", "manual"); diff --git a/cpp/src/IceGrid/DescriptorHelper.h b/cpp/src/IceGrid/DescriptorHelper.h index 643bc5de4db..d035160ec4d 100644 --- a/cpp/src/IceGrid/DescriptorHelper.h +++ b/cpp/src/IceGrid/DescriptorHelper.h @@ -69,6 +69,7 @@ class DescriptorTemplates : public IceUtil::SimpleShared public: DescriptorTemplates(const ApplicationDescriptorPtr&); + void setDescriptor(const ApplicationDescriptorPtr&); ServerDescriptorPtr instantiateServer(const DescriptorHelper&, const std::string&, const std::map<std::string, std::string>&); @@ -83,7 +84,7 @@ public: private: - const ApplicationDescriptorPtr _application; + ApplicationDescriptorPtr _application; }; typedef IceUtil::Handle<DescriptorTemplates> DescriptorTemplatesPtr; @@ -145,9 +146,13 @@ public: std::auto_ptr<ServiceDescriptorHelper> addServiceTemplate(const std::string&, const IceXML::Attributes&); void update(const ApplicationUpdateDescriptor&); + void addServerInstance(const std::string&, const std::map<std::string, std::string>&); + void instantiate(); private: + void pushNodeVariables(const std::string&); + ApplicationDescriptorPtr _descriptor; }; |