diff options
Diffstat (limited to 'cpp')
-rw-r--r-- | cpp/demo/IcePack/simple/app.xml | 14 | ||||
-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 | ||||
-rw-r--r-- | cpp/test/IceGrid/deployer/AllTests.cpp | 125 |
5 files changed, 214 insertions, 46 deletions
diff --git a/cpp/demo/IcePack/simple/app.xml b/cpp/demo/IcePack/simple/app.xml index bbfc093d106..7f453880ecc 100644 --- a/cpp/demo/IcePack/simple/app.xml +++ b/cpp/demo/IcePack/simple/app.xml @@ -66,6 +66,20 @@ <variable name="node1" value="test"/> <server-instance template="IceBoxTemplate" name="IceBox"/> <server-instance template="ServerTemplate" name="Server"/> + + + <server name="Server1" exe="./server"> + <adapters> + <adapter name="Hello" endpoints="tcp" register="true"> + <object identity="${server}-hello2" type="::Demo::Hello"/> + </adapter> + </adapters> + <properties> + <property name="Identity" value="${server}-hello2"/> + <property name="Prop" value="${id}"/> + </properties> + </server> + </node> </application> 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; }; diff --git a/cpp/test/IceGrid/deployer/AllTests.cpp b/cpp/test/IceGrid/deployer/AllTests.cpp index 00b423a35f8..a13de2244af 100644 --- a/cpp/test/IceGrid/deployer/AllTests.cpp +++ b/cpp/test/IceGrid/deployer/AllTests.cpp @@ -182,6 +182,8 @@ allTests(const Ice::CommunicatorPtr& communicator, bool withTemplates) InstanceDescriptor server2; InstanceDescriptor icebox1; InstanceDescriptor icebox2; + TemplateDescriptor iceBoxTmpl; + TemplateDescriptor serviceTmpl; for(InstanceDescriptorSeq::iterator p = application->servers.begin(); p != application->servers.end(); ++p) { @@ -192,8 +194,18 @@ allTests(const Ice::CommunicatorPtr& communicator, bool withTemplates) } else if(p->descriptor->name == "Server2") { - server2 = *p; - ServerDescriptorPtr server = ServerDescriptorPtr::dynamicCast(p->descriptor); + server2 = *p; + ServerDescriptorPtr server; + if(withTemplates) + { + TemplateDescriptorDict::iterator q = application->serverTemplates.find(p->_cpp_template); + assert(q != application->serverTemplates.end()); + server = ServerDescriptorPtr::dynamicCast(q->second.descriptor); + } + else + { + server = ServerDescriptorPtr::dynamicCast(p->descriptor); + } assert(server); for(PropertyDescriptorSeq::iterator r = server->properties.begin(); r != server->properties.end(); ++r) { @@ -206,33 +218,65 @@ allTests(const Ice::CommunicatorPtr& communicator, bool withTemplates) else if(p->descriptor->name == "IceBox1") { icebox1 = *p; - icebox1.descriptor = ComponentDescriptorPtr::dynamicCast(icebox1.descriptor->ice_clone()); - IceBoxDescriptorPtr iceBox = IceBoxDescriptorPtr::dynamicCast(p->descriptor); - assert(iceBox); - for(InstanceDescriptorSeq::iterator r = iceBox->services.begin(); r != iceBox->services.end(); ++r) + IceBoxDescriptorPtr iceBox; + if(withTemplates) + { + TemplateDescriptorDict::iterator q = application->serverTemplates.find(p->_cpp_template); + assert(q != application->serverTemplates.end()); + iceBoxTmpl = q->second; + q->second.descriptor = ComponentDescriptorPtr::dynamicCast(q->second.descriptor->ice_clone()); + iceBox = IceBoxDescriptorPtr::dynamicCast(q->second.descriptor); + for(InstanceDescriptorSeq::iterator r = iceBox->services.begin(); r != iceBox->services.end(); ++r) + { + if(r->parameterValues["name"] == "Service1") + { + iceBox->services.erase(r); + break; + } + } + } + else { - if(r->descriptor->name == "Service1") + p->descriptor = ComponentDescriptorPtr::dynamicCast(p->descriptor->ice_clone()); + iceBox = IceBoxDescriptorPtr::dynamicCast(p->descriptor); + for(InstanceDescriptorSeq::iterator r = iceBox->services.begin(); r != iceBox->services.end(); ++r) { - iceBox->services.erase(r); - break; + if(r->descriptor->name == "Service1") + { + iceBox->services.erase(r); + break; + } } } } else if(p->descriptor->name == "IceBox2") { icebox2 = *p; - icebox2.descriptor = ComponentDescriptorPtr::dynamicCast(icebox2.descriptor->ice_clone()); - IceBoxDescriptorPtr iceBox = IceBoxDescriptorPtr::dynamicCast(p->descriptor); - assert(iceBox); - for(InstanceDescriptorSeq::iterator r = iceBox->services.begin(); r != iceBox->services.end(); ++r) + ComponentDescriptorPtr service; + if(withTemplates) + { + TemplateDescriptorDict::iterator q = application->serviceTemplates.find("FreezeServiceTemplate"); + assert(q != application->serviceTemplates.end()); + serviceTmpl = q->second; + q->second.descriptor = ComponentDescriptorPtr::dynamicCast(q->second.descriptor->ice_clone()); + service = q->second.descriptor; + } + else { - if(r->descriptor->name == "Service2") + p->descriptor = ComponentDescriptorPtr::dynamicCast(p->descriptor->ice_clone()); + IceBoxDescriptorPtr iceBox = IceBoxDescriptorPtr::dynamicCast(p->descriptor); + assert(iceBox); + for(InstanceDescriptorSeq::iterator r = iceBox->services.begin(); r != iceBox->services.end(); ++r) { - assert(!r->descriptor->dbEnvs.empty()); - r->descriptor = ComponentDescriptorPtr::dynamicCast(r->descriptor->ice_clone()); - r->descriptor->dbEnvs.clear(); + if(r->descriptor->name == "Service2") + { + r->descriptor = ComponentDescriptorPtr::dynamicCast(r->descriptor->ice_clone()); + service = r->descriptor; + } } } + assert(!service->dbEnvs.empty()); + service->dbEnvs.clear(); } } @@ -270,11 +314,16 @@ allTests(const Ice::CommunicatorPtr& communicator, bool withTemplates) { } + // // Make sure the database environment of Service2 of IceBox2 was removed. // - obj = TestIntfPrx::checkedCast(communicator->stringToProxy("IceBox1-Service2@IceBox1Service2Adapter")); - test(!obj->getProperty("Freeze.DbEnv.Service2.DbHome").empty()); + + if(!withTemplates) + { + obj = TestIntfPrx::checkedCast(communicator->stringToProxy("IceBox1-Service2@IceBox1Service2Adapter")); + test(!obj->getProperty("Freeze.DbEnv.Service2.DbHome").empty()); + } obj = TestIntfPrx::checkedCast(communicator->stringToProxy("IceBox2-Service2@IceBox2Service2Adapter")); test(obj->getProperty("Freeze.DbEnv.Service2.DbHome").empty()); @@ -290,10 +339,20 @@ allTests(const Ice::CommunicatorPtr& communicator, bool withTemplates) ApplicationUpdateDescriptor update; update.name = "test"; - update.servers.push_back(server1); - update.removeServers.push_back(server2.descriptor->name); - update.servers.push_back(icebox1); - update.servers.push_back(icebox2); + if(withTemplates) + { + update.servers.push_back(server1); + update.removeServers.push_back(server2.descriptor->name); + update.serverTemplates["IceBoxTemplate"] = iceBoxTmpl; + update.serviceTemplates["FreezeServiceTemplate"] = serviceTmpl; + } + else + { + update.servers.push_back(server1); + update.removeServers.push_back(server2.descriptor->name); + update.servers.push_back(icebox1); + update.servers.push_back(icebox2); + } admin->updateApplication(update); @@ -310,13 +369,27 @@ allTests(const Ice::CommunicatorPtr& communicator, bool withTemplates) // // Ensure the service 1 of the IceBox1 server is back. // - obj = TestIntfPrx::checkedCast(communicator->stringToProxy("IceBox1-Service1@IceBox1.Service1.Service1")); + try + { + obj = TestIntfPrx::checkedCast(communicator->stringToProxy("IceBox1-Service1@IceBox1.Service1.Service1")); + } + catch(const Ice::LocalException&) + { + test(false); + } // // Make sure the database environment of Service2 of IceBox2 is back. // - obj = TestIntfPrx::checkedCast(communicator->stringToProxy("IceBox2-Service2@IceBox2Service2Adapter")); - test(!obj->getProperty("Freeze.DbEnv.Service2.DbHome").empty()); + try + { + obj = TestIntfPrx::checkedCast(communicator->stringToProxy("IceBox2-Service2@IceBox2Service2Adapter")); + test(!obj->getProperty("Freeze.DbEnv.Service2.DbHome").empty()); + } + catch(const Ice::LocalException&) + { + test(false); + } cout << "ok" << endl; } |