summaryrefslogtreecommitdiff
path: root/cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cpp')
-rw-r--r--cpp/src/IceGrid/Database.cpp26
-rw-r--r--cpp/src/IceGrid/DescriptorHelper.cpp93
-rw-r--r--cpp/src/IceGrid/Parser.cpp21
-rw-r--r--cpp/src/IceGrid/ServerI.cpp1
-rw-r--r--cpp/src/IceGrid/Topics.cpp4
-rw-r--r--cpp/test/IceGrid/update/AllTests.cpp868
6 files changed, 520 insertions, 493 deletions
diff --git a/cpp/src/IceGrid/Database.cpp b/cpp/src/IceGrid/Database.cpp
index da8b3f4ad96..3a362feb35a 100644
--- a/cpp/src/IceGrid/Database.cpp
+++ b/cpp/src/IceGrid/Database.cpp
@@ -172,6 +172,11 @@ Database::Database(const Ice::ObjectAdapterPtr& adapter,
Ice::Warning warn(_traceLevels->logger);
warn << "invalid application `" << p->first << "':\n" << reason;
}
+ catch(const char* reason)
+ {
+ Ice::Warning warn(_traceLevels->logger);
+ warn << "invalid application `" << p->first << "':\n" << reason;
+ }
}
}
@@ -346,6 +351,12 @@ Database::updateApplicationDescriptor(ObserverSessionI* session, const Applicati
ex.reason = reason;
throw ex;
}
+ catch(const char* reason)
+ {
+ DeploymentException ex;
+ ex.reason = reason;
+ throw ex;
+ }
serial = ++_serial;
}
@@ -400,6 +411,12 @@ Database::syncApplicationDescriptor(ObserverSessionI* session, const Application
ex.reason = reason;
throw ex;
}
+ catch(const char* reason)
+ {
+ DeploymentException ex;
+ ex.reason = reason;
+ throw ex;
+ }
serial = ++_serial;
}
@@ -446,6 +463,12 @@ Database::removeApplicationDescriptor(ObserverSessionI* session, const std::stri
ex.reason = reason;
throw ex;
}
+ catch(const char* reason)
+ {
+ DeploymentException ex;
+ ex.reason = reason;
+ throw ex;
+ }
serial = ++_serial;
}
@@ -1074,7 +1097,8 @@ Database::reload(const ApplicationHelper& oldApp, const ApplicationHelper& newAp
{
load.push_back(p->second);
}
- else if(ServerHelper(p->second.descriptor) != ServerHelper(q->second.descriptor))
+ else if(p->second.node != q->second.node ||
+ ServerHelper(p->second.descriptor) != ServerHelper(q->second.descriptor))
{
entries.push_back(_serverCache.remove(p->first, false)); // Don't destroy the server if it was updated.
load.push_back(p->second);
diff --git a/cpp/src/IceGrid/DescriptorHelper.cpp b/cpp/src/IceGrid/DescriptorHelper.cpp
index 04965a46929..ecb85d5aec7 100644
--- a/cpp/src/IceGrid/DescriptorHelper.cpp
+++ b/cpp/src/IceGrid/DescriptorHelper.cpp
@@ -202,10 +202,26 @@ Resolver::Resolver(const ApplicationHelper& app, const string& name, const map<s
_context("application `" + name + "'"),
_variables(variables)
{
+ //
+ // Add allowed reserved variables (reserved variables can't be
+ // overrided, in this implementation an empty reserved variable is
+ // considered to be undefined (see getVariable))
+ //
_reserved["application"] = name;
_reserved["node"] = "";
_reserved["server"] = "";
_reserved["service"] = "";
+
+ //
+ // Make sure the variables don't override reserved variables.
+ //
+ for(map<string, string>::const_iterator p = _variables.begin(); p != _variables.end(); ++p)
+ {
+ if(_reserved.find(p->first) != _reserved.end())
+ {
+ throw "invalid variable `" + p->first + "' in " + _context + ":\nreserved variable name";
+ }
+ }
}
Resolver::Resolver(const Resolver& resolve, const map<string, string>& values, bool params) :
@@ -217,11 +233,25 @@ Resolver::Resolver(const Resolver& resolve, const map<string, string>& values, b
if(params)
{
_parameters = values;
+ for(map<string, string>::const_iterator p = _parameters.begin(); p != _parameters.end(); ++p)
+ {
+ if(_reserved.find(p->first) != _reserved.end())
+ {
+ throw "invalid parameter `" + p->first + "' in " + _context + ":\nreserved variable name";
+ }
+ }
}
else
{
for(map<string, string>::const_iterator p = values.begin(); p != values.end(); ++p)
{
+ //
+ // Make sure the variables don't override reserved variables.
+ //
+ if(_reserved.find(p->first) != _reserved.end())
+ {
+ throw "invalid variable `" + p->first + "' in " + _context + ":\nreserved variable name";
+ }
_variables[p->first] = p->second;
}
}
@@ -315,7 +345,13 @@ Resolver::substitute(const string& v, bool first) const
{
throw "malformed variable name in the value `" + value + "'";
}
-
+
+ //
+ // Get the name of the variable and get its value. If the name
+ // refered to a parameter we don't do any recursive
+ // substitution: the parameter value is computed at the point
+ // of definition.
+ //
string name = value.substr(beg + 2, end - beg - 2);
bool param;
string val = getVariable(name, first, param);
@@ -333,6 +369,11 @@ Resolver::substitute(const string& v, bool first) const
string
Resolver::getVariable(const string& name, bool checkParams, bool& param) const
{
+ //
+ // We first check the reserved variables, then the parameters if
+ // necessary and finally the variables.
+ //
+
param = false;
map<string, string>::const_iterator p = _reserved.find(name);
if(p != _reserved.end())
@@ -430,6 +471,8 @@ CommunicatorHelper::instantiateImpl(const CommunicatorDescriptorPtr& instance, c
AdapterDescriptor adapter;
adapter.name = resolve(p->name, "object adapter name");
adapter.id = resolve(p->id, "object adapter id");
+ adapter.registerProcess = p->registerProcess;
+ adapter.waitForActivation = p->waitForActivation;
for(ObjectDescriptorSeq::const_iterator q = p->objects.begin(); q != p->objects.end(); ++q)
{
ObjectDescriptor obj;
@@ -525,6 +568,7 @@ CommunicatorHelper::printObjectAdapter(Output& out, const AdapterDescriptor& ada
out << nl << "id = '" << adapter.id << "'";
// TODO out << nl << "endpoints = '" << adapter.endpoints << "'";
out << nl << "register process = '" << (adapter.registerProcess ? "true" : "false") << "'";
+ out << nl << "wait for activation = '" << (adapter.waitForActivation ? "true" : "false") << "'";
for(ObjectDescriptorSeq::const_iterator p = adapter.objects.begin(); p != adapter.objects.end(); ++p)
{
out << nl << "object";
@@ -706,7 +750,7 @@ ServerHelper::instantiateImpl(const ServerDescriptorPtr& instance, const Resolve
throw "invalid server `" + instance->id + "': unknown activation `" + instance->activation + "'";
}
instance->activationTimeout = resolve.asInt(_desc->activationTimeout, "activation timeout");
- instance->deactivationTimeout = resolve(_desc->deactivationTimeout, "deactivation timeout");
+ instance->deactivationTimeout = resolve.asInt(_desc->deactivationTimeout, "deactivation timeout");
for(Ice::StringSeq::const_iterator p = _desc->options.begin(); p != _desc->options.end(); ++p)
{
instance->options.push_back(resolve(*p, "option"));
@@ -784,6 +828,16 @@ IceBoxHelper::IceBoxHelper(const IceBoxDescriptorPtr& descriptor, const Resolver
// TODO: Add validation (e.g.: ensure that service names are unique.)
//
+ //
+ // This IceBoxHelper constructor is called for IceBox server
+ // instances. Here, we populate the server helper sequence and
+ // also update the IceBox descriptor service instances. The
+ // service instances of the descriptor contain instances of the
+ // services: the ServiceInstanceDescriptor::descriptor attribute
+ // is set with the instance descriptor of the service even for
+ // template instances.
+ //
+
for(ServiceInstanceDescriptorSeq::iterator p = _desc->services.begin(); p != _desc->services.end(); ++p)
{
_services.push_back(ServiceInstanceHelper(*p, resolve));
@@ -1256,9 +1310,6 @@ void
NodeHelper::update(const NodeUpdateDescriptor& update, const Resolver& appResolve)
{
assert(update.name == _name);
- Resolver resolve(appResolve, _desc.variables, false);
- resolve.setReserved("node", _name);
- resolve.setContext("node `" + _name + "'");
//
// Remove the variables, the servers and server instances.
@@ -1280,10 +1331,19 @@ NodeHelper::update(const NodeUpdateDescriptor& update, const Resolver& appResolv
}
//
+ // NOTE: It's important to create the resolver *after* updating the node variables!
+ //
+ Resolver resolve(appResolve, _desc.variables, false);
+ resolve.setReserved("node", _name);
+ resolve.setContext("node `" + _name + "'");
+
+ //
// Update the server instances, first we instantiate the server
// instances from the update, remove the old server instances that
// were updated, and then we re-instantiate the server instances
- // that were not updated.
+ // that were not updated. We also ensure that the re-instantiation
+ // isn't changing the id: this is not allowed, instead the old
+ // server should be removed first.
//
ServerInstanceHelperDict serverInstances;
serverInstances.swap(_serverInstances);
@@ -1300,6 +1360,11 @@ NodeHelper::update(const NodeUpdateDescriptor& update, const Resolver& appResolv
for(ServerInstanceHelperDict::const_iterator q = serverInstances.begin(); q != serverInstances.end(); ++q)
{
ServerInstanceHelper helper(q->second.getDescriptor(), resolve); // Re-instantiate the server.
+ if(helper.getId() != q->first)
+ {
+ throw "invalid update in node `" + _name + "':\n" +
+ "server instance id `" + q->first + "' changed to `" + helper.getId() + "'";
+ }
if(!_serverInstances.insert(make_pair(helper.getId(), helper)).second)
{
throw "duplicate server `" + helper.getId() + "' in node `" + _name + "'";
@@ -1309,7 +1374,9 @@ NodeHelper::update(const NodeUpdateDescriptor& update, const Resolver& appResolv
//
// Update the servers, first we instantiate the servers from the
// update, remove the old servers that were updated, and then we
- // re-instantiate the servers that were not updated.
+ // re-instantiate the servers that were not updated. We also
+ // ensure that the re-instantiation isn't changing the id: this is
+ // not allowed, instead the old server should be removed first.
//
ServerInstanceHelperDict servers;
servers.swap(_servers);
@@ -1325,6 +1392,11 @@ NodeHelper::update(const NodeUpdateDescriptor& update, const Resolver& appResolv
for(ServerInstanceHelperDict::const_iterator q = servers.begin(); q != servers.end(); ++q)
{
ServerInstanceHelper helper(q->second.getDefinition(), resolve); // Re-instantiate the server.
+ if(helper.getId() != q->first)
+ {
+ throw "invalid update in node `" + _name + "':\n" +
+ "server instance id `" + q->first + "' changed to `" + helper.getId() + "'";
+ }
if(!_servers.insert(make_pair(helper.getId(), helper)).second)
{
throw "duplicate server `" + helper.getId() + "' in node `" + _name + "'";
@@ -1566,13 +1638,18 @@ ApplicationHelper::update(const ApplicationUpdateDescriptor& update)
_desc.serviceTemplates = updateDictElts(_desc.serviceTemplates, update.serviceTemplates,
update.removeServiceTemplates);
- Resolver resolve(*this, _desc.name, _desc.variables);
+
for(Ice::StringSeq::const_iterator p = update.removeNodes.begin(); p != update.removeNodes.end(); ++p)
{
_nodes.erase(*p);
}
//
+ // NOTE: It's important to create the resolver *after* updating the application variables!
+ //
+ Resolver resolve(*this, _desc.name, _desc.variables);
+
+ //
// We first update or add the nodes from the update descriptor and
// then we re-instantiate the nodes which were not updated to make
// sure that their server instances are up to date.
diff --git a/cpp/src/IceGrid/Parser.cpp b/cpp/src/IceGrid/Parser.cpp
index 238c2e1b6a8..37354769302 100644
--- a/cpp/src/IceGrid/Parser.cpp
+++ b/cpp/src/IceGrid/Parser.cpp
@@ -254,9 +254,6 @@ Parser::diffApplication(const list<string>& args)
return;
}
- ApplicationDescriptor newApp;
- ApplicationDescriptor origApp;
-
try
{
StringSeq targets;
@@ -278,8 +275,15 @@ Parser::diffApplication(const list<string>& args)
}
}
- newApp = DescriptorParser::parseDescriptor(descriptor, targets, vars, _communicator);
- origApp = _admin->getApplicationDescriptor(newApp.name);
+ ApplicationDescriptor newApp = DescriptorParser::parseDescriptor(descriptor, targets, vars, _communicator);
+ ApplicationDescriptor origApp = _admin->getApplicationDescriptor(newApp.name);
+
+ ApplicationHelper newAppHelper(newApp);
+ ApplicationHelper oldAppHelper(origApp);
+
+ Output out(cout);
+ newAppHelper.printDiff(out, oldAppHelper);
+ out << nl;
}
catch(const DeploymentException& ex)
{
@@ -295,13 +299,6 @@ Parser::diffApplication(const list<string>& args)
error(s.str());
return;
}
-
- ApplicationHelper newAppHelper(newApp);
- ApplicationHelper oldAppHelper(origApp);
-
- Output out(cout);
- newAppHelper.printDiff(out, oldAppHelper);
- out << nl;
}
void
diff --git a/cpp/src/IceGrid/ServerI.cpp b/cpp/src/IceGrid/ServerI.cpp
index 97e1ea4e657..28d377823fe 100644
--- a/cpp/src/IceGrid/ServerI.cpp
+++ b/cpp/src/IceGrid/ServerI.cpp
@@ -607,6 +607,7 @@ ServerI::checkActivation()
return;
}
}
+
setStateNoSync(ServerI::Active);
notifyAll();
}
diff --git a/cpp/src/IceGrid/Topics.cpp b/cpp/src/IceGrid/Topics.cpp
index 621607a53a4..c6581c8d923 100644
--- a/cpp/src/IceGrid/Topics.cpp
+++ b/cpp/src/IceGrid/Topics.cpp
@@ -283,8 +283,8 @@ RegistryObserverTopic::applicationUpdated(int serial, const ApplicationUpdateDes
}
catch(const std::string& msg)
{
- //cerr << msg << endl;
- assert(false);
+ cerr << msg << endl;
+ //assert(false);
}
catch(...)
{
diff --git a/cpp/test/IceGrid/update/AllTests.cpp b/cpp/test/IceGrid/update/AllTests.cpp
index 18ab341972a..31f541b0671 100644
--- a/cpp/test/IceGrid/update/AllTests.cpp
+++ b/cpp/test/IceGrid/update/AllTests.cpp
@@ -46,7 +46,6 @@ allTests(const Ice::CommunicatorPtr& communicator)
server->exe = properties->getProperty("TestDir") + "/server";
AdapterDescriptor adapter;
adapter.name = "Server";
- //adapter.endpoints = "default";
adapter.id = "ServerAdapter";
adapter.registerProcess = true;
ObjectDescriptor object;
@@ -108,7 +107,6 @@ allTests(const Ice::CommunicatorPtr& communicator)
server->exe = "${test.dir}/server";
adapter = AdapterDescriptor();
adapter.name = "Server";
-// adapter.endpoints = "default";
adapter.id = "${server}";
adapter.registerProcess = true;
object = ObjectDescriptor();
@@ -370,13 +368,17 @@ allTests(const Ice::CommunicatorPtr& communicator)
ApplicationDescriptor testApp;
testApp.name = "TestApp";
NodeDescriptor node;
- node.variables["node"] = "node1";
+ node.variables["nodename"] = "node1";
testApp.nodes["node1"] = node;
try
{
admin->addApplication(testApp);
}
+ catch(const DeploymentException& ex)
+ {
+ cerr << ex.reason << endl;
+ }
catch(const Ice::Exception& ex)
{
cerr << ex << endl;
@@ -387,7 +389,7 @@ allTests(const Ice::CommunicatorPtr& communicator)
update.name = "TestApp";
NodeUpdateDescriptor nodeUpdate;
nodeUpdate.name = "node2";
- nodeUpdate.variables["node"] = "node2";
+ nodeUpdate.variables["nodename"] = "node2";
update.nodes.push_back(nodeUpdate);
try
@@ -402,14 +404,14 @@ allTests(const Ice::CommunicatorPtr& communicator)
testApp = admin->getApplicationDescriptor("TestApp");
test(testApp.nodes.size() == 2);
- test(testApp.nodes["node1"].variables["node"] == "node1");
- test(testApp.nodes["node2"].variables["node"] == "node2");
+ test(testApp.nodes["node1"].variables["nodename"] == "node1");
+ test(testApp.nodes["node2"].variables["nodename"] == "node2");
cout << "ok" << endl;
cout << "testing node update... " << flush;
nodeUpdate.name = "node2";
- nodeUpdate.variables["node"] = "node2updated";
+ nodeUpdate.variables["nodename"] = "node2updated";
update.nodes.back() = nodeUpdate;
try
{
@@ -423,8 +425,8 @@ allTests(const Ice::CommunicatorPtr& communicator)
testApp = admin->getApplicationDescriptor("TestApp");
test(testApp.nodes.size() == 2);
- test(testApp.nodes["node1"].variables["node"] == "node1");
- test(testApp.nodes["node2"].variables["node"] == "node2updated");
+ test(testApp.nodes["node1"].variables["nodename"] == "node1");
+ test(testApp.nodes["node2"].variables["nodename"] == "node2updated");
cout << "ok" << endl;
@@ -444,480 +446,406 @@ allTests(const Ice::CommunicatorPtr& communicator)
testApp = admin->getApplicationDescriptor("TestApp");
test(testApp.nodes.size() == 1);
- test(testApp.nodes["node2"].variables["node"] == "node2updated");
+ test(testApp.nodes["node2"].variables["nodename"] == "node2updated");
admin->removeApplication("TestApp");
cout << "ok" << endl;
}
-// {
-// cout << "testing variable update... " << flush;
-
-// PropertyDescriptorSeq properties;
-// PropertyDescriptor property;
-// property.name = "ApplicationVar";
-// property.value = "${appvar}";
-// properties.push_back(property);
-// property.name = "NodeVar";
-// property.value = "${nodevar}";
-// properties.push_back(property);
-// property.name = "ServerParamVar";
-// property.value = "${serverparamvar}";
-// properties.push_back(property);
-// property.name = "ServerVar";
-// property.value = "${servervar}";
-// properties.push_back(property);
-// property.name = "ServiceParamVar";
-// property.value = "${serviceparamvar}";
-// properties.push_back(property);
-// property.name = "ServiceVar";
-// property.value = "${servicevar}";
-// properties.push_back(property);
-
-// TemplateDescriptor serviceTempl;
-// serviceTempl.parameters.push_back("serviceparamvar");
-// serviceTempl.descriptor = new ServiceDescriptor();
-// ServiceDescriptorPtr::dynamicCast(serviceTempl.descriptor)->name = "Service";
-// serviceTempl.descriptor->properties = properties;
-
-// ServiceInstanceDescriptor service;
-// service._cpp_template = "ServiceTemplate";
-// service.parameterValues["serviceparamvar"] = "ServiceParamValue";
-
-// IceBoxDescriptorPtr icebox = new IceBoxDescriptor();
-// icebox->services.push_back(service);
-// icebox->exe = "icebox";
-
-// TemplateDescriptor templ;
-// templ.parameters.push_back("name");
-// templ.parameters.push_back("serverparamvar");
-// templ.descriptor = icebox;
-
-// ApplicationDescriptor testApp;
-// testApp.name = "TestApp";
-// testApp.variables["appvar"] = "AppValue";
-// testApp.serviceTemplates["ServiceTemplate"] = serviceTempl;
-// testApp.serverTemplates["IceBoxTemplate"] = templ;
-
-// NodeDescriptor node;
-// node.variables["nodevar"] = "NodeValue";
-
-// ServerInstanceDescriptor server;
-// server._cpp_template = "IceBoxTemplate";
-// server.parameterValues["name"] = "Server";
-// server.parameterValues["serverparamvar"] = "ServerParamValue";
-// node.serverInstances.push_back(server);
-
-// testApp.nodes["node1"] = node;
-
-// try
-// {
-// admin->addApplication(testApp);
-// }
-// catch(const Ice::Exception& ex)
-// {
-// cerr << ex << endl;
-// test(false);
-// }
-
-// ApplicationUpdateDescriptor empty;
-// empty.name = "TestApp";
-// ApplicationUpdateDescriptor update = empty;
-// update.removeVariables.push_back("appvar");
-// try
-// {
-// admin->updateApplication(update);
-// test(false);
-// }
-// catch(const DeploymentException& ex)
-// {
-// // Missing app variable
-// //cerr << ex.reason << endl;
-// }
-// catch(const Ice::Exception& ex)
-// {
-// cerr << ex << endl;
-// test(false);
-// }
-
-// update = empty;
-// node.variables.clear();
-// update.nodes.push_back(node);
-// try
-// {
-// admin->updateApplication(update);
-// test(false);
-// }
-// catch(const DeploymentException& ex)
-// {
-// // Missing node variable
-// //cerr << ex.reason << endl;
-// }
-// catch(const Ice::Exception& ex)
-// {
-// cerr << ex << endl;
-// test(false);
-// }
-
-// update = empty;
-// server = ServerInstanceDescriptor();
-// server._cpp_template = "IceBoxTemplate";
-// server.parameterValues["name"] = "Server";
-// server.node = "node1";
-// update.nodes[0].serverInstances.push_back(server);
-// try
-// {
-// admin->updateApplication(update);
-// test(false);
-// }
-// catch(const DeploymentException& ex)
-// {
-// // Missing parameter
-// //cerr << ex.reason << endl;
-// }
-// catch(const Ice::Exception& ex)
-// {
-// cerr << ex << endl;
-// test(false);
-// }
-
-// update = empty;
-// templ.descriptor->variables.erase("servervar");
-// update.serverTemplates["IceBoxTemplate"] = templ;
-// try
-// {
-// admin->updateApplication(update);
-// test(false);
-// }
-// catch(const DeploymentException& ex)
-// {
-// // Missing server variable
-// //cerr << ex.reason << endl;
-// }
-// catch(const Ice::Exception& ex)
-// {
-// cerr << ex << endl;
-// test(false);
-// }
-
-// update = empty;
-// templ.descriptor->variables["servervar"] = "ServerValue";
-// IceBoxDescriptorPtr::dynamicCast(templ.descriptor)->services[0].parameterValues.erase("serviceparamvar");
-// update.serverTemplates["IceBoxTemplate"] = templ;
-// try
-// {
-// admin->updateApplication(update);
-// test(false);
-// }
-// catch(const DeploymentException& ex)
-// {
-// // Missing service param variable
-// //cerr << ex.reason << endl;
-// }
-// catch(const Ice::Exception& ex)
-// {
-// cerr << ex << endl;
-// test(false);
-// }
-
-// update = empty;
-// IceBoxDescriptorPtr::dynamicCast(templ.descriptor)->services[0].parameterValues["serviceparamvar"] =
-// "ServiceParamValue";
-// update.serverTemplates["IceBoxTemplate"] = templ;
-// serviceTempl.descriptor->variables.erase("servicevar");
-// update.serviceTemplates["ServiceTemplate"] = serviceTempl;
-// try
-// {
-// admin->updateApplication(update);
-// test(false);
-// }
-// catch(const DeploymentException& ex)
-// {
-// // Missing service variable
-// //cerr << ex.reason << endl;
-// }
-// catch(const Ice::Exception& ex)
-// {
-// cerr << ex << endl;
-// test(false);
-// }
-
-// testApp = admin->getApplicationDescriptor("TestApp");
-
-// update = empty;
-// update.variables["nodevar"] = "appoverride";
-// node = testApp.nodes[0];
-// node.variables["serverparamvar"] = "nodeoverride";
-// node.variables["servervar"] = "nodeoverride";
-// update.nodes.push_back(node);
-// templ = testApp.serverTemplates["IceBoxTemplate"];
-// templ.descriptor->variables["serviceparamvar"] = "serveroverride";
-// templ.descriptor->variables["servicevar"] = "serveroverride";
-// update.serverTemplates["IceBoxTemplate"] = templ;
-// try
-// {
-// admin->updateApplication(update);
-// }
-// catch(const Ice::Exception& ex)
-// {
-// cerr << ex << endl;
-// test(false);
-// }
+ {
+ cout << "testing variable update... " << flush;
+
+ PropertyDescriptorSeq properties;
+ PropertyDescriptor property;
+ property.name = "ApplicationVar";
+ property.value = "${appvar}";
+ properties.push_back(property);
+ property.name = "NodeVar";
+ property.value = "${nodevar}";
+ properties.push_back(property);
+ property.name = "ServerParamVar";
+ property.value = "${serverparamvar}";
+ properties.push_back(property);
+
+ TemplateDescriptor serviceTempl;
+
+ ServerDescriptorPtr server = new ServerDescriptor();
+ server->id = "${name}";
+ server->exe = "server";
+ server->properties = properties;
+
+ TemplateDescriptor templ;
+ templ.parameters.push_back("name");
+ templ.parameters.push_back("serverparamvar");
+ templ.descriptor = server;
+
+ ApplicationDescriptor testApp;
+ testApp.name = "TestApp";
+ testApp.variables["appvar"] = "AppValue";
+ testApp.serverTemplates["ServerTemplate"] = templ;
+
+ NodeDescriptor node;
+ node.variables["nodevar"] = "NodeValue";
+
+ ServerInstanceDescriptor serverInstance;
+ serverInstance._cpp_template = "ServerTemplate";
+ serverInstance.parameterValues["name"] = "Server";
+ serverInstance.parameterValues["serverparamvar"] = "ServerParamValue";
+ node.serverInstances.push_back(serverInstance);
+
+ testApp.nodes["node1"] = node;
+
+ try
+ {
+ admin->addApplication(testApp);
+ }
+ catch(const DeploymentException& ex)
+ {
+ cerr << ex.reason << endl;
+ test(false);
+ }
+ catch(const Ice::Exception& ex)
+ {
+ cerr << ex << endl;
+ test(false);
+ }
+
+ ApplicationUpdateDescriptor empty;
+ empty.name = "TestApp";
+ ApplicationUpdateDescriptor update = empty;
+ update.removeVariables.push_back("appvar");
+ try
+ {
+ admin->updateApplication(update);
+ test(false);
+ }
+ catch(const DeploymentException& ex)
+ {
+ // Missing app variable
+ //cerr << ex.reason << endl;
+ }
+ catch(const Ice::Exception& ex)
+ {
+ cerr << ex << endl;
+ test(false);
+ }
+
+ update = empty;
+ NodeUpdateDescriptor nodeUpdate;
+ nodeUpdate.name = "node1";
+ nodeUpdate.removeVariables.push_back("nodevar");
+ update.nodes.push_back(nodeUpdate);
+ try
+ {
+ admin->updateApplication(update);
+ test(false);
+ }
+ catch(const DeploymentException& ex)
+ {
+ // Missing node variable
+ //cerr << ex.reason << endl;
+ }
+ catch(const Ice::Exception& ex)
+ {
+ cerr << ex << endl;
+ test(false);
+ }
+
+ update = empty;
+ serverInstance = ServerInstanceDescriptor();
+ serverInstance._cpp_template = "ServerTemplate";
+ serverInstance.parameterValues["name"] = "Server";
+ nodeUpdate = NodeUpdateDescriptor();
+ nodeUpdate.name = "node1";
+ nodeUpdate.serverInstances.push_back(serverInstance);
+ update.nodes.push_back(nodeUpdate);
+ try
+ {
+ admin->updateApplication(update);
+ test(false);
+ }
+ catch(const DeploymentException& ex)
+ {
+ // Missing parameter
+ //cerr << ex.reason << endl;
+ }
+ catch(const Ice::Exception& ex)
+ {
+ cerr << ex << endl;
+ test(false);
+ }
+
+ ServerInfo serverBefore = admin->getServerInfo("Server");
+ ApplicationDescriptor origApp = admin->getApplicationDescriptor("TestApp");
+
+ update = empty;
+ update.variables["nodevar"] = "appoverride";
+ nodeUpdate = NodeUpdateDescriptor();
+ nodeUpdate.name = "node1";
+ nodeUpdate.variables["serverparamvar"] = "nodeoverride";
+ update.nodes.push_back(nodeUpdate);
+ try
+ {
+ admin->updateApplication(update);
+ }
+ catch(const Ice::Exception& ex)
+ {
+ cerr << ex << endl;
+ test(false);
+ }
-// ApplicationDescriptor previousApp = testApp;
-// icebox = IceBoxDescriptorPtr::dynamicCast(testApp.servers[0].descriptor);
-// PropertyDescriptorSeq previousProps = icebox->services[0].descriptor->properties;
-
-// testApp = admin->getApplicationDescriptor("TestApp");
-// icebox = IceBoxDescriptorPtr::dynamicCast(testApp.servers[0].descriptor);
-// PropertyDescriptorSeq newProps = icebox->services[0].descriptor->properties;
-// test(newProps.size() == previousProps.size());
-// test(newProps == previousProps);
+ ServerInfo serverAfter = admin->getServerInfo("Server");
+ test(serverBefore.descriptor->properties.size() == serverAfter.descriptor->properties.size());
+ test(serverBefore.descriptor->properties == serverAfter.descriptor->properties);
-// update = empty;
-// node = previousApp->nodes[0];
-// node.variables["appvar"] = "nodeoverride";
-// update.nodes.push_back(node);
-// templ = previousApp->serverTemplates["IceBoxTemplate"];
-// templ.descriptor->variables["nodevar"] = "serveroverride";
-// update.serverTemplates["IceBoxTemplate"] = templ;
-// serviceTempl = previousApp->serviceTemplates["ServiceTemplate"];
-// serviceTempl.descriptor->variables["servervar"] = "serviceoverride";
-// update.serviceTemplates["ServiceTemplate"] = serviceTempl;
-// try
-// {
-// admin->updateApplication(update);
-// }
-// catch(const Ice::Exception& ex)
-// {
-// cerr << ex << endl;
-// test(false);
-// }
-
-// testApp = admin->getApplicationDescriptor("TestApp");
-// icebox = IceBoxDescriptorPtr::dynamicCast(testApp.servers[0].descriptor);
-// newProps = icebox->services[0].descriptor->properties;
-// for(PropertyDescriptorSeq::const_iterator p = newProps.begin(); p != newProps.end(); ++p)
-// {
-// if(p->name == "ApplicationVar")
-// {
-// test(p->value == "nodeoverride");
-// }
-// else if(p->name == "NodeVar")
-// {
-// test(p->value == "serveroverride");
-// }
-// else if(p->name == "ServerVar")
-// {
-// test(p->value == "serviceoverride");
-// }
-// else if(p->name == "ServiceVar")
-// {
-// test(p->value == "ServiceValue");
-// }
-// else if(p->name == "ServerParamVar")
-// {
-// test(p->value == "ServerParamValue");
-// }
-// else if(p->name == "ServiceParamVar")
-// {
-// test(p->value == "ServiceParamValue");
-// }
-// else
-// {
-// test(false);
-// }
-// }
-// admin->removeApplication("TestApp");
-// cout << "ok" << endl;
-// }
-
-// {
-// cout << "testing comment update... " << flush;
-
-// ApplicationDescriptor testApp;
-// testApp.name = "TestApp";
-// testApp.comment = "Comment";
-// try
-// {
-// admin->addApplication(testApp);
-// }
-// catch(const Ice::Exception& ex)
-// {
-// cerr << ex << endl;
-// test(false);
-// }
-// testApp = admin->getApplicationDescriptor("TestApp");
-// test(testApp.comment == "Comment");
+ update = empty;
+ nodeUpdate = NodeUpdateDescriptor();
+ nodeUpdate.name = "node1";
+ nodeUpdate.variables["appvar"] = "nodeoverride";
+ update.nodes.push_back(nodeUpdate);
+ try
+ {
+ admin->updateApplication(update);
+ }
+ catch(const Ice::Exception& ex)
+ {
+ cerr << ex << endl;
+ test(false);
+ }
+
+ serverAfter = admin->getServerInfo("Server");
+ PropertyDescriptorSeq newProps = serverAfter.descriptor->properties;
+ for(PropertyDescriptorSeq::const_iterator p = newProps.begin(); p != newProps.end(); ++p)
+ {
+ if(p->name == "ApplicationVar")
+ {
+ test(p->value == "nodeoverride");
+ }
+ else if(p->name == "NodeVar")
+ {
+ test(p->value == "NodeValue");
+ }
+ else if(p->name == "ServerParamVar")
+ {
+ test(p->value == "ServerParamValue");
+ }
+ else
+ {
+ test(false);
+ }
+ }
+ admin->removeApplication("TestApp");
+ cout << "ok" << endl;
+ }
+
+ {
+ cout << "testing description update... " << flush;
+
+ ApplicationDescriptor testApp;
+ testApp.name = "TestApp";
+ testApp.description = "Description";
+ try
+ {
+ admin->addApplication(testApp);
+ }
+ catch(const Ice::Exception& ex)
+ {
+ cerr << ex << endl;
+ test(false);
+ }
+ testApp = admin->getApplicationDescriptor("TestApp");
+ test(testApp.description == "Description");
-// ApplicationUpdateDescriptor update;
-// update.name = "TestApp";
-// try
-// {
-// admin->updateApplication(update);
-// }
-// catch(const Ice::Exception& ex)
-// {
-// cerr << ex << endl;
-// test(false);
-// }
-// testApp = admin->getApplicationDescriptor("TestApp");
-// test(testApp.comment == "Comment");
-
-// update.comment = new BoxedComment("updatedComment");
-// try
-// {
-// admin->updateApplication(update);
-// }
-// catch(const Ice::Exception& ex)
-// {
-// cerr << ex << endl;
-// test(false);
-// }
-// testApp = admin->getApplicationDescriptor("TestApp");
-// test(testApp.comment == "updatedComment");
+ ApplicationUpdateDescriptor update;
+ update.name = "TestApp";
+ try
+ {
+ admin->updateApplication(update);
+ }
+ catch(const Ice::Exception& ex)
+ {
+ cerr << ex << endl;
+ test(false);
+ }
+ testApp = admin->getApplicationDescriptor("TestApp");
+ test(testApp.description == "Description");
+
+ update.description = new BoxedDescription("updatedDescription");
+ try
+ {
+ admin->updateApplication(update);
+ }
+ catch(const Ice::Exception& ex)
+ {
+ cerr << ex << endl;
+ test(false);
+ }
+ testApp = admin->getApplicationDescriptor("TestApp");
+ test(testApp.description == "updatedDescription");
-// update.comment = new BoxedComment("");
-// try
-// {
-// admin->updateApplication(update);
-// }
-// catch(const Ice::Exception& ex)
-// {
-// cerr << ex << endl;
-// test(false);
-// }
-// testApp = admin->getApplicationDescriptor("TestApp");
-// test(testApp.comment == "");
-
-// admin->removeApplication("TestApp");
+ update.description = new BoxedDescription("");
+ try
+ {
+ admin->updateApplication(update);
+ }
+ catch(const Ice::Exception& ex)
+ {
+ cerr << ex << endl;
+ test(false);
+ }
+ testApp = admin->getApplicationDescriptor("TestApp");
+ test(testApp.description == "");
+
+ admin->removeApplication("TestApp");
-// cout << "ok" << endl;
-// }
+ cout << "ok" << endl;
+ }
-// {
-// cout << "testing server node move... " << flush;
+ {
+ cout << "testing server node move... " << flush;
-// ApplicationDescriptor nodeApp;
-// nodeApp.name = "NodeApp";
-
-// ServerDescriptorPtr server = new ServerDescriptor();
-// server->id = "node-${index}";
-// server->exe = properties->getProperty("IceDir") + "/bin/icegridnode";
-// AdapterDescriptor adapter;
-// adapter.name = "IceGrid.Node";
-// adapter.endpoints = "default";
-// adapter.id = "IceGrid.Node.node-${index}";
-// adapter.registerProcess = true;
-// adapter.waitForActivation = false;
-// server->adapters.push_back(adapter);
-// PropertyDescriptor prop;
-// prop.name = "IceGrid.Node.Name";
-// prop.value = "node-${index}";
-// server->properties.push_back(prop);
-// prop.name = "IceGrid.Node.Data";
-// prop.value = properties->getProperty("TestDir") + "/db/node-${index}";
-// server->properties.push_back(prop);
-// prop.name = "IceGrid.Node.PropertiesOverride";
-// prop.value = "Ice.Default.Host=127.0.0.1";
-// server->properties.push_back(prop);
-// nodeApp.serverTemplates["nodeTemplate"].descriptor = server;
-// nodeApp.serverTemplates["nodeTemplate"].parameters.push_back("index");
-
-// ServerInstanceDescriptor instance;
-// instance.node = "localnode";
-// instance._cpp_template = "nodeTemplate";
-
-// instance.parameterValues["index"] = "1";
-// nodeApp.servers.push_back(instance);
-
-// instance.parameterValues["index"] = "2";
-// nodeApp.servers.push_back(instance);
+ ApplicationDescriptor nodeApp;
+ nodeApp.name = "NodeApp";
+
+ ServerDescriptorPtr server = new ServerDescriptor();
+ server->id = "node-${index}";
+ server->exe = properties->getProperty("IceDir") + "/bin/icegridnode";
+ AdapterDescriptor adapter;
+ adapter.name = "IceGrid.Node";
+ adapter.id = "IceGrid.Node.node-${index}";
+ adapter.registerProcess = true;
+ adapter.waitForActivation = false;
+ server->adapters.push_back(adapter);
+ PropertyDescriptor prop;
+ prop.name = "IceGrid.Node.Name";
+ prop.value = "node-${index}";
+ server->properties.push_back(prop);
+ prop.name = "IceGrid.Node.Data";
+ prop.value = properties->getProperty("TestDir") + "/db/node-${index}";
+ server->properties.push_back(prop);
+ prop.name = "IceGrid.Node.Endpoints";
+ prop.value = "default";
+ server->properties.push_back(prop);
+ prop.name = "IceGrid.Node.PropertiesOverride";
+ prop.value = "Ice.Default.Host=127.0.0.1";
+ server->properties.push_back(prop);
+ nodeApp.serverTemplates["nodeTemplate"].descriptor = server;
+ nodeApp.serverTemplates["nodeTemplate"].parameters.push_back("index");
+
+ ServerInstanceDescriptor instance;
+ instance._cpp_template = "nodeTemplate";
+ instance.parameterValues["index"] = "1";
+ nodeApp.nodes["localnode"].serverInstances.push_back(instance);
+ instance.parameterValues["index"] = "2";
+ nodeApp.nodes["localnode"].serverInstances.push_back(instance);
+
+ try
+ {
+ admin->addApplication(nodeApp);
+ }
+ catch(const Ice::Exception& ex)
+ {
+ cerr << ex << endl;
+ test(false);
+ }
+
+ admin->startServer("node-1");
+ admin->startServer("node-2");
+ IceUtil::ThreadControl::sleep(IceUtil::Time::seconds(3));
+ test(admin->pingNode("node-1"));
+ test(admin->pingNode("node-2"));
+
+ ApplicationDescriptor testApp;
+ testApp.name = "TestApp";
+ server = new ServerDescriptor();
+ server->id = "Server";
+ server->exe = properties->getProperty("TestDir") + "/server";
+ adapter.name = "Server";
+ adapter.id = "ServerAdapter";
+ adapter.registerProcess = true;
+ adapter.waitForActivation = true;
+ server->adapters.push_back(adapter);
+ prop.name = "Server.Endpoints";
+ prop.value = "default";
+ server->properties.push_back(prop);
+ testApp.nodes["node-1"].servers.push_back(server);
+
+ admin->addApplication(testApp);
+ try
+ {
+ admin->startServer("Server");
+ test(admin->getServerState("Server") == Active);
+ }
+ catch(const Ice::Exception& ex)
+ {
+ cerr << ex << endl;
+ test(false);
+ }
-// try
-// {
-// admin->addApplication(nodeApp);
-// }
-// catch(const Ice::Exception& ex)
-// {
-// cerr << ex << endl;
-// test(false);
-// }
-
-// admin->startServer("node-1");
-// admin->startServer("node-2");
-// IceUtil::ThreadControl::sleep(IceUtil::Time::seconds(3));
-// test(admin->pingNode("node-1"));
-// test(admin->pingNode("node-2"));
-
-// ApplicationDescriptor testApp;
-// testApp.name = "TestApp";
-// instance = ServerInstanceDescriptor();
-// instance.node = "node-1";
-// instance.descriptor = new ServerDescriptor();
-// instance.descriptor->id = "Server";
-// instance.descriptor->exe = properties->getProperty("TestDir") + "/server";
-// adapter.name = "Server";
-// adapter.endpoints = "default";
-// adapter.id = "ServerAdapter";
-// adapter.registerProcess = true;
-// adapter.waitForActivation = true;
-// instance.descriptor->adapters.push_back(adapter);
-// testApp.servers.push_back(instance);
-
-// admin->addApplication(testApp);
-// try
-// {
-// admin->startServer("Server");
-// test(admin->getServerState("Server") == Active);
-// }
-// catch(const Ice::Exception& ex)
-// {
-// cerr << ex << endl;
-// test(false);
-// }
+ ApplicationUpdateDescriptor update;
+ update.name = "TestApp";
-// ApplicationUpdateDescriptor update;
-// update.name = "TestApp";
-// instance.node = "node-2";
-// update.nodes[0].serverInstances.push_back(instance);
-// admin->updateApplication(update);
-// test(admin->getServerState("Server") == Inactive);
-
-// admin->startServer("Server");
-// test(admin->getServerState("Server") == Active);
-// IceUtil::ThreadControl::sleep(IceUtil::Time::seconds(1));
-
-// update = ApplicationUpdateDescriptor();
-// update.name = "TestApp";
-// instance.node = "anUnknownNode";
-// update.nodes[0].serverInstances.push_back(instance);
-// admin->updateApplication(update);
-// try
-// {
-// admin->getServerState("Server");
-// test(false);
-// }
-// catch(const NodeUnreachableException&)
-// {
-// }
-
-// admin->removeApplication("TestApp");
-
-// admin->stopServer("node-1");
-// admin->stopServer("node-2");
-
-// try
-// {
-// admin->removeApplication("NodeApp");
-// }
-// catch(const Ice::Exception& ex)
-// {
-// cerr << ex << endl;
-// test(false);
-// }
-
-// cout << "ok" << endl;
-// }
+ NodeUpdateDescriptor nodeUpdate;
+ nodeUpdate.name = "node-1";
+ nodeUpdate.removeServers.push_back("Server");
+ update.nodes.push_back(nodeUpdate);
+ nodeUpdate.name = "node-2";
+ nodeUpdate.servers.push_back(server);
+ update.nodes.push_back(nodeUpdate);
+
+ admin->updateApplication(update);
+ test(admin->getServerInfo("Server").node == "node-2" && admin->getServerState("Server") == Inactive);
+
+ admin->startServer("Server");
+ test(admin->getServerState("Server") == Active);
+ IceUtil::ThreadControl::sleep(IceUtil::Time::seconds(1));
+
+ update = ApplicationUpdateDescriptor();
+ update.name = "TestApp";
+ nodeUpdate = NodeUpdateDescriptor();
+ nodeUpdate.name = "node-2";
+ nodeUpdate.removeServers.push_back("Server");
+ update.nodes.push_back(nodeUpdate);
+ nodeUpdate = NodeUpdateDescriptor();
+ nodeUpdate.name = "unknownNode";
+ nodeUpdate.servers.push_back(server);
+ update.nodes.push_back(nodeUpdate);
+
+ try
+ {
+ admin->updateApplication(update);
+ }
+ catch(const DeploymentException& ex)
+ {
+ cerr << ex.reason << endl;
+ test(false);
+ }
+
+ try
+ {
+ admin->getServerState("Server");
+ test(false);
+ }
+ catch(const NodeUnreachableException&)
+ {
+ }
+
+ admin->removeApplication("TestApp");
+
+ admin->stopServer("node-1");
+ admin->stopServer("node-2");
+
+ try
+ {
+ admin->removeApplication("NodeApp");
+ }
+ catch(const Ice::Exception& ex)
+ {
+ cerr << ex << endl;
+ test(false);
+ }
+
+ cout << "ok" << endl;
+ }
}