summaryrefslogtreecommitdiff
path: root/cpp/src
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/src')
-rw-r--r--cpp/src/IceGrid/AdminI.cpp196
-rw-r--r--cpp/src/IceGrid/AdminI.h6
-rw-r--r--cpp/src/IceGrid/Database.cpp110
-rw-r--r--cpp/src/IceGrid/Database.h15
-rw-r--r--cpp/src/IceGrid/DescriptorHelper.cpp802
-rw-r--r--cpp/src/IceGrid/DescriptorHelper.h90
-rw-r--r--cpp/src/IceGrid/DescriptorParser.cpp161
-rw-r--r--cpp/src/IceGrid/DescriptorParser.h13
-rw-r--r--cpp/src/IceGrid/Grammar.y12
-rw-r--r--cpp/src/IceGrid/IceGridNode.cpp3
-rw-r--r--cpp/src/IceGrid/Parser.cpp353
-rw-r--r--cpp/src/IceGrid/Parser.h2
-rw-r--r--cpp/src/IceGrid/Scanner.l8
-rw-r--r--cpp/src/IceGrid/ServerI.cpp63
-rw-r--r--cpp/src/IceGrid/Util.cpp395
-rw-r--r--cpp/src/IceGrid/Util.h32
16 files changed, 1145 insertions, 1116 deletions
diff --git a/cpp/src/IceGrid/AdminI.cpp b/cpp/src/IceGrid/AdminI.cpp
index 891c5d57437..8991a278714 100644
--- a/cpp/src/IceGrid/AdminI.cpp
+++ b/cpp/src/IceGrid/AdminI.cpp
@@ -61,10 +61,8 @@ void
AdminI::instantiateApplicationServer(const string& name, const string& tmpl, const StringStringDict& variables,
const Current&)
{
- StringStringDict vars = variables;
- vars.insert(make_pair("template", tmpl));
ApplicationDescriptorHelper helper(_communicator, _database->getApplicationDescriptor(name));
- auto_ptr<ServerDescriptorHelper> server(helper.addServer(vars));
+ helper.addServer(tmpl, variables);
_database->updateApplicationDescriptor(helper.getDescriptor());
}
@@ -75,107 +73,117 @@ AdminI::getAllApplicationNames(const Current&) const
}
void
-AdminI::addServer(const ServerDescriptorPtr& server, const Current&)
-{
- if(server->application.empty())
- {
- ApplicationDescriptorPtr application = new ApplicationDescriptor();
- application->name = '_' + server->name;
- application->servers.push_back(server);
- try
- {
- _database->addApplicationDescriptor(application);
- }
- catch(const ApplicationExistsException&)
- {
- ServerExistsException ex;
- ex.name = server->name;
- throw ex;
- }
- }
- else
- {
- try
- {
- ApplicationDescriptorPtr application = _database->getApplicationDescriptor(server->application);
- application->servers.push_back(server);
- _database->updateApplicationDescriptor(application);
- }
- catch(const ApplicationNotExistException&)
- {
- DeploymentException ex;
- ex.reason = "application `" + server->application + "' doesn't exist";
- throw ex;
- }
- }
+AdminI::addServer(const ApplicationDescriptorPtr& server, const Current&)
+{
+// if(server->application.empty())
+// {
+// ApplicationDescriptorPtr application = new ApplicationDescriptor();
+// application->name = '_' + server->name;
+// ApplicationDescriptorHelper helper(_communicator, application);
+// helper.addServerTemplate("_" + server->name, server);
+// helper.addServer("_" + server->name, variables);
+
+// application->servers.push_back(server);
+// try
+// {
+// _database->addApplicationDescriptor(application);
+// }
+// catch(const ApplicationExistsException&)
+// {
+// ServerExistsException ex;
+// ex.name = server->name;
+// throw ex;
+// }
+// }
+// else
+// {
+// try
+// {
+// ApplicationDescriptorPtr application = _database->getApplicationDescriptor(server->application);
+// application->servers.push_back(server);
+// _database->updateApplicationDescriptor(application);
+// }
+// catch(const ApplicationNotExistException&)
+// {
+// DeploymentException ex;
+// ex.reason = "application `" + server->application + "' doesn't exist";
+// throw ex;
+// }
+// }
}
void
-AdminI::updateServer(const ServerDescriptorPtr& newServer, const Current&)
+AdminI::updateServer(const ApplicationDescriptorPtr& desc, const Current&)
{
- ServerDescriptorPtr server = _database->getServerDescriptor(newServer->name);
- try
- {
- if(server->application.empty())
- {
- ApplicationDescriptorPtr application = new ApplicationDescriptor();
- application->name = '_' + newServer->name;
- application->servers.push_back(newServer);
- _database->updateApplicationDescriptor(application);
- }
- else
- {
- ApplicationDescriptorPtr application = _database->getApplicationDescriptor(server->application);
- for(ServerDescriptorSeq::iterator p = application->servers.begin(); p != application->servers.end(); ++p)
- {
- application->servers.erase(p);
- application->servers.push_back(newServer);
- }
- _database->updateApplicationDescriptor(application);
- }
- }
- catch(const ApplicationNotExistException&)
- {
- ServerNotExistException ex;
- ex.name = newServer->name;
- throw ex;
- }
+ //
+ // TODO
+ //
+// ServerDescriptorPtr server = _database->getServerDescriptor(newServer->name);
+// try
+// {
+// if(server->application.empty())
+// {
+// ApplicationDescriptorPtr application = new ApplicationDescriptor();
+// application->name = '_' + newServer->name;
+// application->servers.push_back(newServer);
+// _database->updateApplicationDescriptor(application);
+// }
+// else
+// {
+// ApplicationDescriptorPtr application = _database->getApplicationDescriptor(server->application);
+// for(ServerDescriptorSeq::iterator p = application->servers.begin(); p != application->servers.end(); ++p)
+// {
+// application->servers.erase(p);
+// application->servers.push_back(newServer);
+// }
+// _database->updateApplicationDescriptor(application);
+// }
+// }
+// catch(const ApplicationNotExistException&)
+// {
+// ServerNotExistException ex;
+// ex.name = newServer->name;
+// throw ex;
+// }
}
void
AdminI::removeServer(const string& name, const Current&)
{
- ServerDescriptorPtr server = _database->getServerDescriptor(name);
- try
- {
- if(server->application.empty())
- {
- _database->removeApplicationDescriptor('_' + name);
- }
- else
- {
- ApplicationDescriptorPtr application = _database->getApplicationDescriptor(server->application);
- for(ServerDescriptorSeq::iterator p = application->servers.begin(); p != application->servers.end(); ++p)
- {
- if((*p)->name == name)
- {
- application->servers.erase(p);
- break;
- }
- }
- _database->updateApplicationDescriptor(application);
- }
- }
- catch(const ApplicationNotExistException&)
- {
- ServerNotExistException ex;
- ex.name = name;
- throw ex;
- }
-}
-
-ServerDescriptorPtr
+ //
+ // TODO
+ //
+// ServerDescriptorPtr server = _database->getServerDescriptor(name);
+// try
+// {
+// if(server->application.empty())
+// {
+// _database->removeApplicationDescriptor('_' + name);
+// }
+// else
+// {
+// ApplicationDescriptorPtr application = _database->getApplicationDescriptor(server->application);
+// for(ServerDescriptorSeq::iterator p = application->servers.begin(); p != application->servers.end(); ++p)
+// {
+// if((*p)->name == name)
+// {
+// application->servers.erase(p);
+// break;
+// }
+// }
+// _database->updateApplicationDescriptor(application);
+// }
+// }
+// catch(const ApplicationNotExistException&)
+// {
+// ServerNotExistException ex;
+// ex.name = name;
+// throw ex;
+// }
+}
+
+InstanceDescriptor
AdminI::getServerDescriptor(const string& name, const Current&) const
{
return _database->getServerDescriptor(name);
diff --git a/cpp/src/IceGrid/AdminI.h b/cpp/src/IceGrid/AdminI.h
index c6ec1b7390e..182972bcd93 100644
--- a/cpp/src/IceGrid/AdminI.h
+++ b/cpp/src/IceGrid/AdminI.h
@@ -33,10 +33,10 @@ public:
const Ice::Current&);
virtual Ice::StringSeq getAllApplicationNames(const Ice::Current&) const;
- virtual void addServer(const ServerDescriptorPtr&, const Ice::Current&);
- virtual void updateServer(const ServerDescriptorPtr&, const Ice::Current&);
+ virtual void addServer(const ApplicationDescriptorPtr&, const Ice::Current&);
+ virtual void updateServer(const ApplicationDescriptorPtr&, const Ice::Current&);
virtual void removeServer(const ::std::string&, const Ice::Current&);
- virtual ServerDescriptorPtr getServerDescriptor(const ::std::string&, const Ice::Current&) const;
+ virtual InstanceDescriptor getServerDescriptor(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;
diff --git a/cpp/src/IceGrid/Database.cpp b/cpp/src/IceGrid/Database.cpp
index fd129078e62..4ae563f7b71 100644
--- a/cpp/src/IceGrid/Database.cpp
+++ b/cpp/src/IceGrid/Database.cpp
@@ -12,6 +12,7 @@
#include <IceGrid/Database.h>
#include <IceGrid/TraceLevels.h>
#include <IceGrid/Util.h>
+#include <IceGrid/DescriptorHelper.h>
#include <algorithm>
#include <functional>
@@ -44,19 +45,19 @@ struct AddComponent : std::unary_function<ComponentDescriptorPtr&, void>
const Database::ServerEntryPtr _entry;
};
-struct AddServerName : std::unary_function<ServerDescriptorPtr&, void>
+struct AddServerName : std::unary_function<InstanceDescriptor&, void>
{
AddServerName(set<string>& names) : _names(names)
{
}
void
- operator()(const ServerDescriptorPtr& desc)
+ operator()(const InstanceDescriptor& instance)
{
- if(!_names.insert(desc->name).second)
+ if(!_names.insert(instance.descriptor->name).second)
{
DeploymentException ex;
- ex.reason = "invalid descriptor: duplicated server `" + desc->name + "'";
+ ex.reason = "invalid descriptor: duplicated server `" + instance.descriptor->name + "'";
throw ex;
}
}
@@ -226,7 +227,7 @@ Database::Database(const Ice::CommunicatorPtr& communicator,
//
for(StringApplicationDescriptorDict::const_iterator p = _descriptors.begin(); p != _descriptors.end(); ++p)
{
- for(ServerDescriptorSeq::const_iterator q = p->second->servers.begin(); q != p->second->servers.end(); ++q)
+ for(InstanceDescriptorSeq::const_iterator q = p->second->servers.begin(); q != p->second->servers.end(); ++q)
{
addServer(*q);
}
@@ -413,7 +414,7 @@ Database::updateApplicationDescriptor(const ApplicationDescriptorPtr& newDesc)
// update the updated ones.
//
addServers(newDesc->servers, added, entries);
- updateServers(newDesc->servers, updated, entries);
+ updateServers(origDesc, newDesc, updated, entries);
removeServers(origDesc->servers, removed, entries);
_descriptors.put(make_pair(newDesc->name, newDesc));
@@ -612,18 +613,34 @@ Database::getAllNodes(const string& expression)
return Ice::StringSeq(nodes.begin(), nodes.end());
}
-ServerDescriptorPtr
+InstanceDescriptor
Database::getServerDescriptor(const std::string& name)
{
- Lock sync(*this);
- map<string, ServerEntryPtr>::const_iterator p = _servers.find(name);
- if(p == _servers.end())
+ ServerDescriptorPtr descriptor;
{
- ServerNotExistException ex;
- ex.name = name;
- throw ex;
+ 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();
}
- return p->second->getDescriptor();
+ assert(descriptor);
+ ApplicationDescriptorPtr app = getApplicationDescriptor(descriptor->application);
+ for(InstanceDescriptorSeq::const_iterator p = app->servers.begin(); p != app->servers.end(); ++p)
+ {
+ if(p->descriptor->name == descriptor->name)
+ {
+ return *p;
+ }
+ }
+
+ ServerNotExistException ex;
+ ex.name = name;
+ throw ex;
}
ServerPrx
@@ -638,7 +655,13 @@ Database::getServer(const string& name)
entry = p->second;
}
}
- return entry ? entry->getProxy() : ServerPrx();
+ if(!entry)
+ {
+ ServerNotExistException ex;
+ ex.name = name;
+ throw ex;
+ }
+ return entry->getProxy();
}
Ice::StringSeq
@@ -922,11 +945,11 @@ Database::checkObjectForAddition(const Ice::Identity& objectId)
}
void
-Database::addServers(const ServerDescriptorSeq& servers, const set<string>& names, ServerEntrySeq& entries)
+Database::addServers(const InstanceDescriptorSeq& servers, const set<string>& names, ServerEntrySeq& entries)
{
- for(ServerDescriptorSeq::const_iterator p = servers.begin(); p != servers.end(); ++p)
+ for(InstanceDescriptorSeq::const_iterator p = servers.begin(); p != servers.end(); ++p)
{
- if(names.find((*p)->name) == names.end())
+ if(names.find(p->descriptor->name) == names.end())
{
continue;
}
@@ -935,28 +958,40 @@ Database::addServers(const ServerDescriptorSeq& servers, const set<string>& name
}
void
-Database::updateServers(const ServerDescriptorSeq& servers, const set<string>& names, ServerEntrySeq& entries)
+Database::updateServers(const ApplicationDescriptorPtr& oldAppDesc, const ApplicationDescriptorPtr& newAppDesc,
+ const set<string>& names, ServerEntrySeq& entries)
{
- for(ServerDescriptorSeq::const_iterator p = servers.begin(); p != servers.end(); ++p)
+ ApplicationDescriptorHelper oldAppDescHelper(_communicator, oldAppDesc);
+ ApplicationDescriptorHelper newAppDescHelper(_communicator, newAppDesc);
+
+ for(InstanceDescriptorSeq::const_iterator p = newAppDesc->servers.begin(); p != newAppDesc->servers.end(); ++p)
{
- if(names.find((*p)->name) == names.end())
+ if(names.find(p->descriptor->name) == names.end())
{
continue;
}
- ServerEntryPtr entry = updateServer(*p);
- if(entry)
+
+ for(InstanceDescriptorSeq::const_iterator q = oldAppDesc->servers.begin(); q != oldAppDesc->servers.end(); ++q)
{
- entries.push_back(entry);
+ if(p->descriptor->name == q->descriptor->name)
+ {
+ if(ServerDescriptorHelper(oldAppDescHelper, ServerDescriptorPtr::dynamicCast(q->descriptor)) !=
+ ServerDescriptorHelper(newAppDescHelper, ServerDescriptorPtr::dynamicCast(p->descriptor)))
+ {
+ entries.push_back(updateServer(*p));
+ }
+ break;
+ }
}
}
}
void
-Database::removeServers(const ServerDescriptorSeq& servers, const set<string>& names, ServerEntrySeq& entries)
+Database::removeServers(const InstanceDescriptorSeq& servers, const set<string>& names, ServerEntrySeq& entries)
{
- for(ServerDescriptorSeq::const_iterator p = servers.begin(); p != servers.end(); ++p)
+ for(InstanceDescriptorSeq::const_iterator p = servers.begin(); p != servers.end(); ++p)
{
- if(names.find((*p)->name) == names.end())
+ if(names.find(p->descriptor->name) == names.end())
{
continue;
}
@@ -965,8 +1000,9 @@ Database::removeServers(const ServerDescriptorSeq& servers, const set<string>& n
}
Database::ServerEntryPtr
-Database::addServer(const ServerDescriptorPtr& descriptor)
+Database::addServer(const InstanceDescriptor& instance)
{
+ const ServerDescriptorPtr descriptor = ServerDescriptorPtr::dynamicCast(instance.descriptor);
ServerEntryPtr entry;
map<string, ServerEntryPtr>::const_iterator q = _servers.find(descriptor->name);
if(q != _servers.end())
@@ -979,7 +1015,7 @@ Database::addServer(const ServerDescriptorPtr& descriptor)
entry = new ServerEntry(*this, descriptor);
_servers.insert(make_pair(descriptor->name, entry));
}
-
+
map<string, set<string> >::iterator p = _serversByNode.find(descriptor->node);
if(p == _serversByNode.end())
{
@@ -987,27 +1023,24 @@ Database::addServer(const ServerDescriptorPtr& descriptor)
}
p->second.insert(p->second.begin(), descriptor->name);
- forEachComponent(AddComponent(*this, entry))(descriptor);
+ forEachComponent(AddComponent(*this, entry))(instance);
return entry;
}
Database::ServerEntryPtr
-Database::updateServer(const ServerDescriptorPtr& descriptor)
+Database::updateServer(const InstanceDescriptor& instance)
{
//
// Get the server entry and the current descriptor then check
// if the server descriptor really changed.
//
+ const ServerDescriptorPtr descriptor = ServerDescriptorPtr::dynamicCast(instance.descriptor);
ServerEntryPtr entry;
map<string, ServerEntryPtr>::const_iterator q = _servers.find(descriptor->name);
assert(q != _servers.end());
entry = q->second;
ServerDescriptorPtr old = entry->getDescriptor();
- if(equal(old, descriptor))
- {
- return 0;
- }
//
// If the node changed, move the server from the old node to the
@@ -1043,13 +1076,14 @@ Database::updateServer(const ServerDescriptorPtr& descriptor)
//
// Add the new object adapters and objects.
//
- forEachComponent(AddComponent(*this, entry))(descriptor);
+ forEachComponent(AddComponent(*this, entry))(instance);
return entry;
}
Database::ServerEntryPtr
-Database::removeServer(const ServerDescriptorPtr& descriptor)
+Database::removeServer(const InstanceDescriptor& instance)
{
+ const ServerDescriptorPtr descriptor = ServerDescriptorPtr::dynamicCast(instance.descriptor);
ServerEntryPtr entry;
map<string, ServerEntryPtr>::iterator q = _servers.find(descriptor->name);
assert(q != _servers.end());
@@ -1068,7 +1102,7 @@ Database::removeServer(const ServerDescriptorPtr& descriptor)
//
// Remove the object adapters and objects.
//
- forEachComponent(objFunc(*this, &Database::removeComponent))(descriptor);
+ forEachComponent(objFunc(*this, &Database::removeComponent))(instance);
return entry;
}
diff --git a/cpp/src/IceGrid/Database.h b/cpp/src/IceGrid/Database.h
index ca488bebb5e..75eabc37f7b 100644
--- a/cpp/src/IceGrid/Database.h
+++ b/cpp/src/IceGrid/Database.h
@@ -45,7 +45,7 @@ public:
void removeNode(const std::string&);
Ice::StringSeq getAllNodes(const std::string& = std::string());
- ServerDescriptorPtr getServerDescriptor(const std::string&);
+ InstanceDescriptor getServerDescriptor(const std::string&);
ServerPrx getServer(const std::string&);
Ice::StringSeq getAllServers(const std::string& = std::string());
Ice::StringSeq getAllNodeServers(const std::string&);
@@ -96,12 +96,13 @@ private:
typedef IceUtil::Handle<ServerEntry> ServerEntryPtr;
typedef std::vector<ServerEntryPtr> ServerEntrySeq;
- void addServers(const ServerDescriptorSeq&, const std::set<std::string>&, ServerEntrySeq&);
- void updateServers(const ServerDescriptorSeq&, const std::set<std::string>&, ServerEntrySeq&);
- void removeServers(const ServerDescriptorSeq&, const std::set<std::string>&, ServerEntrySeq&);
- ServerEntryPtr addServer(const ServerDescriptorPtr&);
- ServerEntryPtr updateServer(const ServerDescriptorPtr&);
- ServerEntryPtr removeServer(const ServerDescriptorPtr&);
+ void addServers(const InstanceDescriptorSeq&, 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 clearServer(const std::string&);
void addComponent(const ServerEntryPtr&, const ComponentDescriptorPtr&);
void removeComponent(const ComponentDescriptorPtr&);
diff --git a/cpp/src/IceGrid/DescriptorHelper.cpp b/cpp/src/IceGrid/DescriptorHelper.cpp
index 0439111e33d..6ff97d1fd8b 100644
--- a/cpp/src/IceGrid/DescriptorHelper.cpp
+++ b/cpp/src/IceGrid/DescriptorHelper.cpp
@@ -37,39 +37,50 @@ struct Substitute : unary_function<string&, void>
}
-DescriptorVariables::DescriptorVariables() :
- _ignoreMissing(false),
- _escape(true)
+DescriptorVariables::DescriptorVariables()
{
}
-DescriptorVariables::DescriptorVariables(const map<string, string>& variables) :
- _ignoreMissing(false),
- _escape(true)
+DescriptorVariables::DescriptorVariables(const map<string, string>& variables)
{
- reset(variables);
+ reset(variables, vector<string>());
}
string
-DescriptorVariables::substitute(const string& v) const
+DescriptorVariables::substitute(const string& v)
{
set<string> missing;
- return substituteImpl(v, _ignoreMissing, missing);
+ string value = substituteImpl(v, missing);
+ if(!missing.empty())
+ {
+ if(missing.size() == 1)
+ {
+ throw "unknown variable `" + *missing.begin() + "'";
+ }
+ else
+ {
+ ostringstream os;
+ os << "unknown variables: ";
+ copy(missing.begin(), missing.end(), ostream_iterator<string>(os, " "));
+ throw os.str();
+ }
+ }
+ return value;
}
string
-DescriptorVariables::substituteWithMissing(const string& v, set<string>& missing) const
+DescriptorVariables::substituteWithMissing(const string& v, set<string>& missing)
{
- return substituteImpl(v, true, missing);
+ return substituteImpl(v, missing);
}
void
DescriptorVariables::dumpVariables() const
{
- vector<map<string, string> >::const_reverse_iterator p = _variables.rbegin();
- while(p != _variables.rend())
+ vector<VariableScope>::const_reverse_iterator p = _scopes.rbegin();
+ while(p != _scopes.rend())
{
- for(map<string, string>::const_iterator q = p->begin(); q != p->end(); ++q)
+ for(map<string, string>::const_iterator q = p->variables.begin(); q != p->variables.end(); ++q)
{
cout << q->first << " = " << q->second << endl;
}
@@ -78,15 +89,16 @@ DescriptorVariables::dumpVariables() const
}
string
-DescriptorVariables::getVariable(const string& name) const
+DescriptorVariables::getVariable(const string& name)
{
static const string empty;
- vector<map<string, string> >::const_reverse_iterator p = _variables.rbegin();
- while(p != _variables.rend())
+ vector<VariableScope>::reverse_iterator p = _scopes.rbegin();
+ while(p != _scopes.rend())
{
- map<string, string>::const_iterator q = p->find(name);
- if(q != p->end())
+ map<string, string>::const_iterator q = p->variables.find(name);
+ if(q != p->variables.end())
{
+ p->used.insert(name);
return q->second;
}
++p;
@@ -97,11 +109,11 @@ DescriptorVariables::getVariable(const string& name) const
bool
DescriptorVariables::hasVariable(const string& name) const
{
- vector<map<string, string> >::const_reverse_iterator p = _variables.rbegin();
- while(p != _variables.rend())
+ vector<VariableScope>::const_reverse_iterator p = _scopes.rbegin();
+ while(p != _scopes.rend())
{
- map<string, string>::const_iterator q = p->find(name);
- if(q != p->end())
+ map<string, string>::const_iterator q = p->variables.find(name);
+ if(q != p->variables.end())
{
return true;
}
@@ -111,83 +123,125 @@ DescriptorVariables::hasVariable(const string& name) const
}
void
+DescriptorVariables::addVariable(const string& name, const string& value)
+{
+ if(_scopes.back().used.find(name) != _scopes.back().used.end())
+ {
+ throw "you can't redefine the variable `" + name + "' after its use";
+ }
+ _scopes.back().variables[name] = value;
+}
+
+void
DescriptorVariables::remove(const string& name)
{
- _variables.back().erase(name);
+ _scopes.back().variables.erase(name);
}
void
-DescriptorVariables::reset(const map<string, string>& vars)
+DescriptorVariables::reset(const map<string, string>& vars, const vector<string>& targets)
{
- _variables.clear();
- _variables.push_back(vars);
+ _scopes.clear();
+ push(vars);
+
+ _deploymentTargets = targets;
}
void
DescriptorVariables::push(const map<string, string>& vars)
{
- _variables.push_back(vars);
+ VariableScope scope;
+ if(!_scopes.empty())
+ {
+ scope.substitution = _scopes.back().substitution;
+ }
+ else
+ {
+ scope.substitution = true;
+ }
+ scope.variables = vars;
+ _scopes.push_back(scope);
}
void
DescriptorVariables::push()
{
- _variables.push_back(map<string, string>());
+ push(map<string, string>());
}
void
DescriptorVariables::pop()
{
- _variables.pop_back();
+ _scopes.pop_back();
+}
+
+map<string, string>
+DescriptorVariables::getCurrentScopeVariables() const
+{
+ return _scopes.back().variables;
+}
+
+vector<string>
+DescriptorVariables::getCurrentScopeParameters() const
+{
+ return vector<string>(_scopes.back().parameters.begin(), _scopes.back().parameters.end());
}
void
-DescriptorVariables::ignoreMissing(bool ignoreMissing)
+DescriptorVariables::addParameter(const string& name)
{
- _ignoreMissing = ignoreMissing;
+ _scopes.back().parameters.insert(name);
+}
+
+const vector<string>&
+DescriptorVariables::getDeploymentTargets() const
+{
+ return _deploymentTargets;
}
void
-DescriptorVariables::escape(bool escape)
+DescriptorVariables::substitution(bool substitution)
{
- _escape = escape;
+ _scopes.back().substitution = substitution;
}
-string&
-DescriptorVariables::operator[](const string& name)
+bool
+DescriptorVariables::substitution() const
{
- return _variables.back()[name];
+ return _scopes.back().substitution;
}
string
-DescriptorVariables::substituteImpl(const string& v, bool ignoreMissing, set<string>& missing) const
+DescriptorVariables::substituteImpl(const string& v, set<string>& missing)
{
+ if(!substitution())
+ {
+ return v;
+ }
+
string value(v);
string::size_type beg = 0;
string::size_type end = 0;
while((beg = value.find("${", beg)) != string::npos)
{
- if(_escape)
+ if(beg > 0 && value[beg - 1] == '$')
{
- if(beg > 0 && value[beg - 1] == '$')
+ string::size_type escape = beg - 1;
+ while(escape > 0 && value[escape - 1] == '$')
{
- string::size_type escape = beg - 1;
- while(escape > 0 && value[escape - 1] == '$')
- {
- --escape;
- }
-
- value.replace(escape, beg - escape, (beg - escape) / 2, '$');
- if((beg - escape) % 2)
- {
- ++beg;
- continue;
- }
- else
- {
- beg -= (beg - escape) / 2;
- }
+ --escape;
+ }
+
+ value.replace(escape, beg - escape, (beg - escape) / 2, '$');
+ if((beg - escape) % 2)
+ {
+ ++beg;
+ continue;
+ }
+ else
+ {
+ beg -= (beg - escape) / 2;
}
}
@@ -201,16 +255,9 @@ DescriptorVariables::substituteImpl(const string& v, bool ignoreMissing, set<str
string name = value.substr(beg + 2, end - beg - 2);
if(!hasVariable(name))
{
- if(!ignoreMissing)
- {
- throw "unknown variable `" + name + "'";
- }
- else
- {
- missing.insert(name);
- ++beg;
- continue;
- }
+ missing.insert(name);
+ ++beg;
+ continue;
}
else
{
@@ -223,34 +270,62 @@ DescriptorVariables::substituteImpl(const string& v, bool ignoreMissing, set<str
return value;
}
-DescriptorTemplates::DescriptorTemplates(const ApplicationDescriptorPtr& descriptor)
+DescriptorTemplates::DescriptorTemplates(const ApplicationDescriptorPtr& descriptor) : _application(descriptor)
{
- if(descriptor)
- {
- _serverTemplates = descriptor->templates;
- }
}
ServerDescriptorPtr
-DescriptorTemplates::instantiateServer(const DescriptorHelper& helper, const string& name,
- const map<string, string>& attrs)
+DescriptorTemplates::instantiateServer(const DescriptorHelper& helper,
+ const string& name,
+ const map<string, string>& parameters)
{
- map<string, ServerDescriptorPtr>::const_iterator p = _serverTemplates.find(name);
- if(p == _serverTemplates.end())
+ TemplateDescriptorDict::const_iterator p = _application->serverTemplates.find(name);
+ if(p == _application->serverTemplates.end())
{
throw "unknown template `" + name + "'";
}
-
+
set<string> missing;
Substitute substitute(helper.getVariables(), missing);
- map<string, string> attributes = attrs;
- for(map<string, string>::iterator p = attributes.begin(); p != attributes.end(); ++p)
+ map<string, string> params = parameters;
+
+ set<string> unknown;
+ for(map<string, string>::iterator q = params.begin(); q != params.end(); ++q)
{
- substitute(p->second);
+ if(find(p->second.parameters.begin(), p->second.parameters.end(), q->first) == p->second.parameters.end())
+ {
+ unknown.insert(q->first);
+ }
+ substitute(q->second);
+ }
+ if(!unknown.empty())
+ {
+ ostringstream os;
+ os << "server template instance unknown parameters: ";
+ copy(unknown.begin(), unknown.end(), ostream_iterator<string>(os, " "));
+ throw os.str();
}
- helper.getVariables()->push(attributes);
- ServerDescriptorPtr descriptor = ServerDescriptorHelper(helper, p->second).instantiate(missing);
+ set<string> missingParams;
+ for(vector<string>::const_iterator q = p->second.parameters.begin(); q != p->second.parameters.end(); ++q)
+ {
+ if(params.find(*q) == params.end())
+ {
+ missingParams.insert(*q);
+ }
+ }
+ if(!missingParams.empty())
+ {
+ ostringstream os;
+ os << "server template instance undefined parameters: ";
+ copy(missingParams.begin(), missingParams.end(), ostream_iterator<string>(os, " "));
+ throw os.str();
+ }
+
+ helper.getVariables()->push(params);
+ ServerDescriptorPtr tmpl = ServerDescriptorPtr::dynamicCast(p->second.descriptor);
+ assert(tmpl);
+ ServerDescriptorPtr descriptor = ServerDescriptorHelper(helper, tmpl).instantiate(missing);
helper.getVariables()->pop();
if(!missing.empty())
@@ -258,7 +333,7 @@ DescriptorTemplates::instantiateServer(const DescriptorHelper& helper, const str
ostringstream os;
os << "server template instance undefined variables: ";
copy(missing.begin(), missing.end(), ostream_iterator<string>(os, " "));
- throw os.str();
+ throw os.str();
}
return descriptor;
@@ -266,24 +341,74 @@ DescriptorTemplates::instantiateServer(const DescriptorHelper& helper, const str
ServiceDescriptorPtr
DescriptorTemplates::instantiateService(const DescriptorHelper& helper, const string& name,
- const map<string, string>& attrs)
+ const map<string, string>& parameters)
{
- map<string, ServiceDescriptorPtr>::const_iterator p = _serviceTemplates.find(name);
- if(p == _serviceTemplates.end())
+ TemplateDescriptorDict::const_iterator p = _application->serviceTemplates.find(name);
+ if(p == _application->serviceTemplates.end())
{
throw "unknown template `" + name + "'";
}
set<string> missing;
Substitute substitute(helper.getVariables(), missing);
- map<string, string> attributes = attrs;
- for(map<string, string>::iterator p = attributes.begin(); p != attributes.end(); ++p)
+ map<string, string> params = parameters;
+
+ set<string> unknown;
+ for(map<string, string>::iterator q = params.begin(); q != params.end(); ++q)
+ {
+ if(find(p->second.parameters.begin(), p->second.parameters.end(), q->first) == p->second.parameters.end())
+ {
+ unknown.insert(q->first);
+ }
+ substitute(q->second);
+ }
+ if(!unknown.empty())
+ {
+ ostringstream os;
+ os << "service template instance unknown parameters: ";
+ copy(unknown.begin(), unknown.end(), ostream_iterator<string>(os, " "));
+ throw os.str();
+ }
+
+ set<string> missingParams;
+ for(vector<string>::const_iterator q = p->second.parameters.begin(); q != p->second.parameters.end(); ++q)
+ {
+ if(params.find(*q) == params.end())
+ {
+ missingParams.insert(*q);
+ }
+ }
+ if(!missingParams.empty())
+ {
+ ostringstream os;
+ os << "service template instance undefined parameters: ";
+ copy(missingParams.begin(), missingParams.end(), ostream_iterator<string>(os, " "));
+ throw os.str();
+ }
+ for(map<string, string>::iterator q = params.begin(); q != params.end(); ++q)
{
- substitute(p->second);
+ substitute(q->second);
}
- helper.getVariables()->push(attributes);
- ServiceDescriptorPtr descriptor = ServiceDescriptorHelper(helper, p->second).instantiate(missing);
+ for(vector<string>::const_iterator q = p->second.parameters.begin(); q != p->second.parameters.end(); ++q)
+ {
+ if(params.find(*q) == params.end())
+ {
+ missing.insert(*q);
+ }
+ }
+ if(!missing.empty())
+ {
+ ostringstream os;
+ os << "service template instance undefined parameters: ";
+ copy(missing.begin(), missing.end(), ostream_iterator<string>(os, " "));
+ throw os.str();
+ }
+
+ helper.getVariables()->push(params);
+ ServiceDescriptorPtr tmpl = ServiceDescriptorPtr::dynamicCast(p->second.descriptor);
+ assert(tmpl);
+ ServiceDescriptorPtr descriptor = ServiceDescriptorHelper(helper, tmpl).instantiate(missing);
helper.getVariables()->pop();
if(!missing.empty())
@@ -291,22 +416,40 @@ DescriptorTemplates::instantiateService(const DescriptorHelper& helper, const st
ostringstream os;
os << "service template instance undefined variables: ";
copy(missing.begin(), missing.end(), ostream_iterator<string>(os, " "));
- throw os.str();
+ throw os.str();
}
return descriptor;
}
void
-DescriptorTemplates::addServerTemplate(const string& id, const ServerDescriptorPtr& descriptor)
+DescriptorTemplates::addServerTemplate(const string& id, const ServerDescriptorPtr& desc, const Ice::StringSeq& vars)
{
- _serverTemplates.insert(make_pair(id, descriptor));
+ //
+ // Add the template to the application.
+ //
+ TemplateDescriptor tmpl;
+ tmpl.descriptor = desc;
+ tmpl.parameters = vars;
+ _application->serverTemplates.insert(make_pair(id, tmpl));
}
void
-DescriptorTemplates::addServiceTemplate(const string& id, const ServiceDescriptorPtr& descriptor)
+DescriptorTemplates::addServiceTemplate(const string& id, const ServiceDescriptorPtr& desc, const Ice::StringSeq& vars)
{
- _serviceTemplates.insert(make_pair(id, descriptor));
+ //
+ // Add the template to the application.
+ //
+ TemplateDescriptor tmpl;
+ tmpl.descriptor = desc;
+ tmpl.parameters = vars;
+ _application->serviceTemplates.insert(make_pair(id, tmpl));
+}
+
+ApplicationDescriptorPtr
+DescriptorTemplates::getApplicationDescriptor() const
+{
+ return _application;
}
XmlAttributesHelper::XmlAttributesHelper(const DescriptorVariablesPtr& variables, const IceXML::Attributes& attrs) :
@@ -381,16 +524,26 @@ ApplicationDescriptorHelper::ApplicationDescriptorHelper(const Ice::Communicator
DescriptorHelper(communicator, new DescriptorVariables(), new DescriptorTemplates(descriptor)),
_descriptor(descriptor)
{
+ _variables->push(descriptor->variables);
+ _variables->addVariable("application", _descriptor->name);
}
ApplicationDescriptorHelper::ApplicationDescriptorHelper(const Ice::CommunicatorPtr& communicator,
const DescriptorVariablesPtr& variables,
const IceXML::Attributes& attrs) :
- DescriptorHelper(communicator, variables, new DescriptorTemplates()),
- _descriptor(new ApplicationDescriptor())
+ DescriptorHelper(communicator, variables, new DescriptorTemplates(new ApplicationDescriptor())),
+ _descriptor(_templates->getApplicationDescriptor())
{
XmlAttributesHelper attributes(_variables, attrs);
_descriptor->name = attributes("name");
+ _variables->addVariable("application", _descriptor->name);
+}
+
+void
+ApplicationDescriptorHelper::endParsing()
+{
+ _descriptor->variables = _variables->getCurrentScopeVariables();
+ _variables->remove("application");
}
const ApplicationDescriptorPtr&
@@ -405,58 +558,59 @@ ApplicationDescriptorHelper::setComment(const string& comment)
_descriptor->comment = comment;
}
-ServerDescriptorHelper*
-ApplicationDescriptorHelper::addServer(const IceXML::Attributes& attrs)
+void
+ApplicationDescriptorHelper::addNode(const IceXML::Attributes& attrs)
{
XmlAttributesHelper attributes(_variables, attrs);
- //
- // Check if the server element is an instantiation of a template
- // (i.e.: the `template' attribute is specified) or a definition.
- //
- auto_ptr<ServerDescriptorHelper> server;
- if(!attributes.contains("template"))
- {
- server.reset(new ServerDescriptorHelper(*this, attrs));
- }
- else
- {
- ServerDescriptorPtr desc = _templates->instantiateServer(*this, attributes("template"), attrs);
- server.reset(new ServerDescriptorHelper(*this, desc));
- }
+ NodeDescriptor node;
+ node.name = attributes("name");
- //
- // Add the server to the application.
- //
- _descriptor->servers.push_back(server->getDescriptor());
- return server.release();
+ _variables->push();
+ _variables->addVariable("node", node.name);
+
+ _descriptor->nodes.push_back(node);
}
-ServerDescriptorHelper*
-ApplicationDescriptorHelper::addServerTemplate(const IceXML::Attributes& attrs)
+void
+ApplicationDescriptorHelper::endNodeParsing()
+{
+ _descriptor->nodes.back().variables = _variables->getCurrentScopeVariables();
+ _variables->pop();
+}
+
+void
+ApplicationDescriptorHelper::addServer(const string& tmpl, const IceXML::Attributes& attrs)
{
XmlAttributesHelper attributes(_variables, attrs);
+ InstanceDescriptor instance;
+ instance._cpp_template = tmpl;
+ instance.parameterValues = attrs;
+ instance.parameterValues.erase("template");
+ instance.targets = _variables->getDeploymentTargets();
+ instance.descriptor = _templates->instantiateServer(*this, tmpl, instance.parameterValues);
+ _descriptor->servers.push_back(instance);
+}
- //
- // Add the template to the application.
- //
- auto_ptr<ServerDescriptorHelper> server(new ServerDescriptorHelper(*this, attrs));
- _descriptor->templates.insert(make_pair(attributes("id"), server->getDescriptor()));
- _templates->addServerTemplate(attributes("id"), server->getDescriptor());
- return server.release();
+void
+ApplicationDescriptorHelper::addServer(const ServerDescriptorPtr& descriptor)
+{
+ InstanceDescriptor instance;
+ instance.descriptor = descriptor;
+ instance.targets = _variables->getDeploymentTargets();
+ _descriptor->servers.push_back(instance);
}
-ServiceDescriptorHelper*
-ApplicationDescriptorHelper::addServiceTemplate(const IceXML::Attributes& attrs)
+auto_ptr<ServerDescriptorHelper>
+ApplicationDescriptorHelper::addServerTemplate(const std::string& id, const IceXML::Attributes& attrs)
{
- XmlAttributesHelper attributes(_variables, attrs);
+ return auto_ptr<ServerDescriptorHelper>(new ServerDescriptorHelper(*this, attrs, id));
+}
- //
- // Add the template to the application.
- //
- auto_ptr<ServiceDescriptorHelper> service(new ServiceDescriptorHelper(*this, attrs));
- _templates->addServiceTemplate(attributes("id"), service->getDescriptor());
- return service.release();
+auto_ptr<ServiceDescriptorHelper>
+ApplicationDescriptorHelper::addServiceTemplate(const std::string& id, const IceXML::Attributes& attrs)
+{
+ return auto_ptr<ServiceDescriptorHelper>(new ServiceDescriptorHelper(*this, attrs, id));
}
ComponentDescriptorHelper::ComponentDescriptorHelper(const DescriptorHelper& helper) : DescriptorHelper(helper)
@@ -523,6 +677,12 @@ ComponentDescriptorHelper::operator==(const ComponentDescriptorHelper& helper) c
return true;
}
+bool
+ComponentDescriptorHelper::operator!=(const ComponentDescriptorHelper& helper) const
+{
+ return !operator==(helper);
+}
+
void
ComponentDescriptorHelper::setComment(const string& comment)
{
@@ -549,9 +709,12 @@ ComponentDescriptorHelper::addAdapter(const IceXML::Attributes& attrs)
desc.id = attributes("id", "");
if(desc.id.empty())
{
- string service = _variables->getVariable("service");
- const string fqn = _variables->getVariable("server") + (service.empty() ? "" : ".") + service;
- desc.id = fqn + "." + desc.name;
+ string fqn = "${server}";
+ if(ServiceDescriptorPtr::dynamicCast(_descriptor))
+ {
+ fqn += ".${service}";
+ }
+ desc.id = _variables->substitute(fqn) + "." + desc.name;
}
desc.endpoints = attributes("endpoints");
desc.registerProcess = attributes("register", "false") == "true";
@@ -578,6 +741,7 @@ ComponentDescriptorHelper::addDbEnv(const IceXML::Attributes& attrs)
DbEnvDescriptor desc;
desc.name = attributes("name");
+
DbEnvDescriptorSeq::iterator p;
for(p = _descriptor->dbEnvs.begin(); p != _descriptor->dbEnvs.end(); ++p)
{
@@ -661,72 +825,58 @@ ServerDescriptorHelper::ServerDescriptorHelper(const DescriptorHelper& helper, c
_descriptor(descriptor)
{
ComponentDescriptorHelper::init(_descriptor);
+ _variables->push(_descriptor->variables);
}
-ServerDescriptorHelper::ServerDescriptorHelper(const DescriptorHelper& helper, const IceXML::Attributes& attrs) :
- ComponentDescriptorHelper(helper)
-{
- initFromXml(attrs);
-}
-
-ServerDescriptorHelper::ServerDescriptorHelper(const Ice::CommunicatorPtr& communicator,
- const DescriptorVariablesPtr& variables,
- const IceXML::Attributes& attrs) :
- ComponentDescriptorHelper(communicator, variables, new DescriptorTemplates())
-{
- initFromXml(attrs);
-}
-
-
-void
-ServerDescriptorHelper::initFromXml(const IceXML::Attributes& attrs)
+ServerDescriptorHelper::ServerDescriptorHelper(const DescriptorHelper& helper, const IceXML::Attributes& attrs,
+ const string& id) :
+ ComponentDescriptorHelper(helper),
+ _templateId(id)
{
XmlAttributesHelper attributes(_variables, attrs);
- string kind = attributes("kind");
- if(kind == "cpp" || kind == "cs")
+
+ _variables->push();
+ if(!_templateId.empty())
{
- _descriptor = new ServerDescriptor();
- _descriptor->exe = attributes("exe");
+ _variables->substitution(false);
}
- else if(kind == "java")
+
+ string interpreter = attributes("interpreter", "");
+ if(interpreter == "icebox")
{
- JavaServerDescriptorPtr descriptor = new JavaServerDescriptor();
- _descriptor = descriptor;
- _descriptor->exe = attributes("exe", "java");
- descriptor->className = attributes("classname");
+ _descriptor = new IceBoxDescriptor();
+ if(_descriptor->exe.empty())
+ {
+ _descriptor->exe = "icebox";
+ }
}
- else if(kind == "cpp-icebox")
+ else if(interpreter == "java-icebox")
{
- _descriptor = new CppIceBoxDescriptor();
- _descriptor->exe = attributes("exe", "icebox");
+ _descriptor = new IceBoxDescriptor();
+ _descriptor->interpreter = "java";
+ if(_descriptor->exe.empty())
+ {
+ _descriptor->exe = "IceBox.Server";
+ }
}
- else if(kind == "java-icebox")
+ else
{
- JavaIceBoxDescriptorPtr descriptor = new JavaIceBoxDescriptor();
- _descriptor = descriptor;
- _descriptor->exe = attributes("exe", "java");
- descriptor->className = attributes("classname", "IceBox.Server");
+ _descriptor = new ServerDescriptor();
+ _descriptor->exe = attributes("exe");
+ _descriptor->interpreter = interpreter;
}
ComponentDescriptorHelper::init(_descriptor, attrs);
- _descriptor->application = _variables->getVariable("application");
- _descriptor->node = _variables->getVariable("node");
+ _descriptor->application = _variables->substitute("${application}");
+ _descriptor->node = _variables->substitute("${node}");
_descriptor->pwd = attributes("pwd", "");
_descriptor->activation = attributes("activation", "manual");
- if(kind == "cpp-icebox" || kind == "java-icebox")
+ if(interpreter == "icebox" || interpreter == "java-icebox")
{
- CppIceBoxDescriptorPtr cppIceBox = CppIceBoxDescriptorPtr::dynamicCast(_descriptor);
- if(cppIceBox)
- {
- cppIceBox->endpoints = attributes("endpoints");
- }
- JavaIceBoxDescriptorPtr javaIceBox = JavaIceBoxDescriptorPtr::dynamicCast(_descriptor);
- if(javaIceBox)
- {
- javaIceBox->endpoints = attributes("endpoints");
- }
+ IceBoxDescriptorPtr iceBox = IceBoxDescriptorPtr::dynamicCast(_descriptor);
+ iceBox->endpoints = attributes("endpoints");
PropertyDescriptor prop;
prop.name = "IceBox.ServiceManager.Identity";
@@ -740,6 +890,27 @@ ServerDescriptorHelper::initFromXml(const IceXML::Attributes& attrs)
adapter.registerProcess = true;
_descriptor->adapters.push_back(adapter);
}
+
+ if(_templateId.empty())
+ {
+ _variables->addVariable("server", _descriptor->name);
+ }
+}
+
+ServerDescriptorHelper::~ServerDescriptorHelper()
+{
+ _variables->pop();
+}
+
+void
+ServerDescriptorHelper::endParsing()
+{
+ if(!_templateId.empty())
+ {
+ _descriptor->variables = _variables->getCurrentScopeVariables();
+ _templates->addServerTemplate(_templateId, _descriptor, _variables->getCurrentScopeParameters());
+ _variables->substitution(true);
+ }
}
bool
@@ -782,79 +953,51 @@ ServerDescriptorHelper::operator==(const ServerDescriptorHelper& helper) const
return false;
}
- ServiceDescriptorSeq slhs;
- ServiceDescriptorSeq srhs;
-
- if(JavaServerDescriptorPtr::dynamicCast(_descriptor))
+ if(_descriptor->interpreter != helper._descriptor->interpreter)
{
- JavaServerDescriptorPtr jlhs = JavaServerDescriptorPtr::dynamicCast(_descriptor);
- JavaServerDescriptorPtr jrhs = JavaServerDescriptorPtr::dynamicCast(helper._descriptor);
-
- if(jlhs->className != jrhs->className)
- {
- return false;
- }
-
- if(set<string>(jlhs->jvmOptions.begin(), jlhs->jvmOptions.end()) !=
- set<string>(jrhs->jvmOptions.begin(), jrhs->jvmOptions.end()))
- {
- return false;
- }
-
- if(JavaIceBoxDescriptorPtr::dynamicCast(_descriptor))
- {
- JavaIceBoxDescriptorPtr ilhs = JavaIceBoxDescriptorPtr::dynamicCast(_descriptor);
- JavaIceBoxDescriptorPtr irhs = JavaIceBoxDescriptorPtr::dynamicCast(helper._descriptor);
-
- if(ilhs->endpoints != irhs->endpoints)
- {
- return false;
- }
-
- if(ilhs->services.size() != irhs->services.size())
- {
- return false;
- }
+ return false;
+ }
- slhs = ilhs->services;
- srhs = irhs->services;
- }
+ if(set<string>(_descriptor->interpreterOptions.begin(),
+ _descriptor->interpreterOptions.end()) !=
+ set<string>(helper._descriptor->interpreterOptions.begin(),
+ helper._descriptor->interpreterOptions.end()))
+ {
+ return false;
}
- else if(CppIceBoxDescriptorPtr::dynamicCast(_descriptor))
+
+ if(IceBoxDescriptorPtr::dynamicCast(_descriptor))
{
- CppIceBoxDescriptorPtr ilhs = CppIceBoxDescriptorPtr::dynamicCast(_descriptor);
- CppIceBoxDescriptorPtr irhs = CppIceBoxDescriptorPtr::dynamicCast(helper._descriptor);
-
+ IceBoxDescriptorPtr ilhs = IceBoxDescriptorPtr::dynamicCast(_descriptor);
+ IceBoxDescriptorPtr irhs = IceBoxDescriptorPtr::dynamicCast(helper._descriptor);
+
if(ilhs->endpoints != irhs->endpoints)
{
return false;
}
-
+
if(ilhs->services.size() != irhs->services.size())
{
return false;
}
-
- slhs = ilhs->services;
- srhs = irhs->services;
- }
- if(!slhs.empty())
- {
- for(ServiceDescriptorSeq::const_iterator p = slhs.begin(); p != slhs.end(); ++p)
+ for(InstanceDescriptorSeq::const_iterator p = ilhs->services.begin(); p != ilhs->services.end(); ++p)
{
bool found = false;
- for(ServiceDescriptorSeq::const_iterator q = srhs.begin(); q != srhs.end(); ++q)
+ for(InstanceDescriptorSeq::const_iterator q = irhs->services.begin(); q != irhs->services.end(); ++q)
{
- if((*p)->name == (*q)->name)
+ if(p->descriptor->name != q->descriptor->name)
+ {
+ continue;
+ }
+
+ found = true;
+ if(ServiceDescriptorHelper(*this, ServiceDescriptorPtr::dynamicCast(p->descriptor)) !=
+ ServiceDescriptorHelper(*this, ServiceDescriptorPtr::dynamicCast(q->descriptor)))
{
- if(ServiceDescriptorHelper(*this, *p) == ServiceDescriptorHelper(*this, *q))
- {
return false;
- }
- found = true;
- break;
}
+ break;
}
if(!found)
{
@@ -862,52 +1005,64 @@ ServerDescriptorHelper::operator==(const ServerDescriptorHelper& helper) const
}
}
}
-
return true;
}
+bool
+ServerDescriptorHelper::operator!=(const ServerDescriptorHelper& helper) const
+{
+ return !operator==(helper);
+}
+
const ServerDescriptorPtr&
ServerDescriptorHelper::getDescriptor() const
{
return _descriptor;
}
-ServiceDescriptorHelper*
-ServerDescriptorHelper::addService(const IceXML::Attributes& attrs)
+const string&
+ServerDescriptorHelper::getTemplateId() const
+{
+ return _templateId;
+}
+
+auto_ptr<ServiceDescriptorHelper>
+ServerDescriptorHelper::addServiceTemplate(const std::string& id, const IceXML::Attributes& attrs)
+{
+ return auto_ptr<ServiceDescriptorHelper>(new ServiceDescriptorHelper(*this, attrs, id));
+}
+
+void
+ServerDescriptorHelper::addService(const string& tmpl, const IceXML::Attributes& attrs)
{
XmlAttributesHelper attributes(_variables, attrs);
-
- if(!CppIceBoxDescriptorPtr::dynamicCast(_descriptor) && !JavaIceBoxDescriptorPtr::dynamicCast(_descriptor))
+ IceBoxDescriptorPtr iceBox = IceBoxDescriptorPtr::dynamicCast(_descriptor);
+ if(!iceBox)
{
throw "element <service> can only be a child of an IceBox <server> element";
}
- //
- // Check if this is a service instantiation (i.e.: the template
- // attribute is specified) or definition.
- //
- auto_ptr<ServiceDescriptorHelper> service;
- if(!attributes.contains("template"))
- {
- service.reset(new ServiceDescriptorHelper(*this, attrs));
- }
- else
- {
- ServiceDescriptorPtr desc = _templates->instantiateService(*this, attributes("template"), attrs);
- service.reset(new ServiceDescriptorHelper(*this, desc));
- }
+ InstanceDescriptor instance;
+ instance._cpp_template = tmpl;
+ instance.parameterValues = attrs;
+ instance.parameterValues.erase("template");
+ instance.targets = _variables->getDeploymentTargets();
+ iceBox->services.push_back(instance);
+}
- CppIceBoxDescriptorPtr cppIceBox = CppIceBoxDescriptorPtr::dynamicCast(_descriptor);
- if(cppIceBox)
- {
- cppIceBox->services.push_back(service->getDescriptor());
- }
- JavaIceBoxDescriptorPtr javaIceBox = JavaIceBoxDescriptorPtr::dynamicCast(_descriptor);
- if(javaIceBox)
+void
+ServerDescriptorHelper::addService(const ServiceDescriptorPtr& descriptor)
+{
+ IceBoxDescriptorPtr iceBox = IceBoxDescriptorPtr::dynamicCast(_descriptor);
+ if(!iceBox)
{
- javaIceBox->services.push_back(service->getDescriptor());
+ throw "element <service> can only be a child of an IceBox <server> element";
}
- return service.release();
+
+ InstanceDescriptor instance;
+ instance.descriptor = descriptor;
+ instance.targets = _variables->getDeploymentTargets();
+ iceBox->services.push_back(instance);
}
void
@@ -923,14 +1078,15 @@ ServerDescriptorHelper::addEnv(const string& env)
}
void
-ServerDescriptorHelper::addJvmOption(const string& option)
+ServerDescriptorHelper::addInterpreterOption(const string& option)
{
- JavaServerDescriptorPtr descriptor = JavaServerDescriptorPtr::dynamicCast(_descriptor);
- if(!descriptor)
+ if(_descriptor->interpreter.empty())
{
- throw "element <jvm-option> can only be the child of a Java <server> element";
+ throw "element <interpreter-option> can only be specified if the interpreter attribute of the <server> "
+ "element is not empty";
}
- descriptor->jvmOptions.push_back(option);
+
+ _descriptor->interpreterOptions.push_back(option);
}
ServerDescriptorPtr
@@ -944,40 +1100,39 @@ ServerDescriptorHelper::instantiate(set<string>& missing) const
void
ServerDescriptorHelper::instantiateImpl(const ServerDescriptorPtr& desc, set<string>& missing) const
{
+ Substitute substitute(_variables, missing);
+ substitute(desc->name);
+ _variables->addVariable("server", desc->name);
+
ComponentDescriptorHelper::instantiateImpl(desc, missing);
- Substitute substitute(_variables, missing);
+ substitute(desc->application);
substitute(desc->node);
substitute(desc->exe);
substitute(desc->pwd);
for_each(desc->options.begin(), desc->options.end(), substitute);
for_each(desc->envs.begin(), desc->envs.end(), substitute);
- if(JavaServerDescriptorPtr::dynamicCast(desc))
- {
- JavaServerDescriptorPtr javaDesc = JavaServerDescriptorPtr::dynamicCast(desc);
- substitute(javaDesc->className);
- for_each(javaDesc->jvmOptions.begin(), javaDesc->jvmOptions.end(), substitute);
- }
+ substitute(desc->interpreter);
+ for_each(desc->interpreterOptions.begin(), desc->interpreterOptions.end(), substitute);
- ServiceDescriptorSeq services = IceGrid::getServices(desc);
- if(!services.empty())
+ IceBoxDescriptorPtr iceBox = IceBoxDescriptorPtr::dynamicCast(desc);
+ if(iceBox)
{
- ServiceDescriptorSeq newServices;
- for(ServiceDescriptorSeq::const_iterator p = services.begin(); p != services.end(); ++p)
- {
- newServices.push_back(ServiceDescriptorHelper(*this, *p).instantiate(missing));
- }
- CppIceBoxDescriptorPtr cppIceBox = CppIceBoxDescriptorPtr::dynamicCast(desc);
- if(cppIceBox)
- {
- cppIceBox->services.swap(newServices);
- }
- JavaIceBoxDescriptorPtr javaIceBox = JavaIceBoxDescriptorPtr::dynamicCast(desc);
- if(javaIceBox)
- {
- javaIceBox->services.swap(newServices);
- }
- }
+ ServiceDescriptorDict newServices;
+ for(InstanceDescriptorSeq::iterator p = iceBox->services.begin(); p != iceBox->services.end(); ++p)
+ {
+ if(p->_cpp_template.empty())
+ {
+ ServiceDescriptorPtr service = ServiceDescriptorPtr::dynamicCast(p->descriptor);
+ assert(service);
+ p->descriptor = ServiceDescriptorHelper(*this, service).instantiate(missing);
+ }
+ else
+ {
+ p->descriptor = _templates->instantiateService(*this, p->_cpp_template, p->parameterValues);
+ }
+ }
+ }
}
ServiceDescriptorHelper::ServiceDescriptorHelper(const DescriptorHelper& helper, const ServiceDescriptorPtr& desc) :
@@ -985,16 +1140,46 @@ ServiceDescriptorHelper::ServiceDescriptorHelper(const DescriptorHelper& helper,
_descriptor(desc)
{
init(_descriptor);
+ _variables->push(_descriptor->variables);
}
-ServiceDescriptorHelper::ServiceDescriptorHelper(const DescriptorHelper& helper, const IceXML::Attributes& attrs) :
+ServiceDescriptorHelper::ServiceDescriptorHelper(const DescriptorHelper& helper, const IceXML::Attributes& attrs,
+ const string& id) :
ComponentDescriptorHelper(helper),
- _descriptor(new ServiceDescriptor())
+ _descriptor(new ServiceDescriptor()),
+ _templateId(id)
{
XmlAttributesHelper attributes(_variables, attrs);
+
+ _variables->push();
+ if(!_templateId.empty())
+ {
+ _variables->substitution(false);
+ }
+
init(_descriptor, attrs);
_descriptor->entry = attributes("entry");
+ if(_templateId.empty())
+ {
+ _variables->addVariable("service", _descriptor->name);
+ }
+}
+
+ServiceDescriptorHelper::~ServiceDescriptorHelper()
+{
+ _variables->pop();
+}
+
+void
+ServiceDescriptorHelper::endParsing()
+{
+ if(!_templateId.empty())
+ {
+ _descriptor->variables = _variables->getCurrentScopeVariables();
+ _templates->addServiceTemplate(_templateId, _descriptor, _variables->getCurrentScopeParameters());
+ _variables->substitution(true);
+ }
}
bool
@@ -1013,6 +1198,12 @@ ServiceDescriptorHelper::operator==(const ServiceDescriptorHelper& helper) const
return true;
}
+bool
+ServiceDescriptorHelper::operator!=(const ServiceDescriptorHelper& helper) const
+{
+ return !operator==(helper);
+}
+
ServiceDescriptorPtr
ServiceDescriptorHelper::instantiate(set<string>& missing) const
{
@@ -1027,11 +1218,20 @@ ServiceDescriptorHelper::getDescriptor() const
return _descriptor;
}
+const string&
+ServiceDescriptorHelper::getTemplateId() const
+{
+ return _templateId;
+}
+
void
ServiceDescriptorHelper::instantiateImpl(const ServiceDescriptorPtr& desc, set<string>& missing) const
{
+ Substitute substitute(_variables, missing);
+ substitute(desc->name);
+ _variables->addVariable("service", desc->name);
+
ComponentDescriptorHelper::instantiateImpl(desc, missing);
- Substitute substitute(_variables, missing);
substitute(desc->entry);
}
diff --git a/cpp/src/IceGrid/DescriptorHelper.h b/cpp/src/IceGrid/DescriptorHelper.h
index d06da6224ee..262923a8287 100644
--- a/cpp/src/IceGrid/DescriptorHelper.h
+++ b/cpp/src/IceGrid/DescriptorHelper.h
@@ -23,38 +23,52 @@ public:
DescriptorVariables();
DescriptorVariables(const std::map<std::string, std::string>&);
- std::string substitute(const std::string&) const;
- std::string substituteWithMissing(const std::string&, std::set<std::string>&) const;
- std::string getVariable(const std::string&) const;
+ std::string substitute(const std::string&);
+ std::string substituteWithMissing(const std::string&, std::set<std::string>&);
+ std::string getVariable(const std::string&);
+ void addVariable(const std::string&, const std::string&);
bool hasVariable(const std::string&) const;
void remove(const std::string&);
void dumpVariables() const;
- void reset(const std::map<std::string, std::string>&);
+ void reset(const std::map<std::string, std::string>&, const std::vector<std::string>&);
void push(const std::map<std::string, std::string>&);
void push();
void pop();
- std::string& operator[](const std::string&);
+ std::map<std::string, std::string> getCurrentScopeVariables() const;
+ std::vector<std::string> getCurrentScopeParameters() const;
+ void addParameter(const std::string&);
- void ignoreMissing(bool);
- void escape(bool);
+ const std::vector<std::string>& getDeploymentTargets() const;
-private:
+ void substitution(bool);
+ bool substitution() const;
- std::string substituteImpl(const std::string&, bool, std::set<std::string>&) const;
+private:
- std::vector<std::map<std::string, std::string> > _variables;
- bool _ignoreMissing;
- bool _escape;
+ std::string substituteImpl(const std::string&, std::set<std::string>&);
+
+ struct VariableScope
+ {
+ std::map<std::string, std::string> variables;
+ std::set<std::string> used;
+ std::set<std::string> parameters;
+ bool substitution;
+ };
+ std::vector<VariableScope> _scopes;
+ std::vector<std::string> _deploymentTargets;
};
typedef IceUtil::Handle<DescriptorVariables> DescriptorVariablesPtr;
class DescriptorHelper;
+class ServerDescriptorHelper;
+class ServiceDescriptorHelper;
+
class DescriptorTemplates : public IceUtil::SimpleShared
{
public:
- DescriptorTemplates(const ApplicationDescriptorPtr& = ApplicationDescriptorPtr());
+ DescriptorTemplates(const ApplicationDescriptorPtr&);
ServerDescriptorPtr instantiateServer(const DescriptorHelper&, const std::string&,
const std::map<std::string, std::string>&);
@@ -62,13 +76,14 @@ public:
ServiceDescriptorPtr instantiateService(const DescriptorHelper&, const std::string&,
const std::map<std::string, std::string>&);
- void addServerTemplate(const std::string&, const ServerDescriptorPtr&);
- void addServiceTemplate(const std::string&, const ServiceDescriptorPtr&);
+ void addServerTemplate(const std::string&, const ServerDescriptorPtr&, const Ice::StringSeq&);
+ void addServiceTemplate(const std::string&, const ServiceDescriptorPtr&, const Ice::StringSeq&);
+
+ ApplicationDescriptorPtr getApplicationDescriptor() const;
private:
- std::map<std::string, ServerDescriptorPtr> _serverTemplates;
- std::map<std::string, ServiceDescriptorPtr> _serviceTemplates;
+ const ApplicationDescriptorPtr _application;
};
typedef IceUtil::Handle<DescriptorTemplates> DescriptorTemplatesPtr;
@@ -116,11 +131,18 @@ public:
ApplicationDescriptorHelper(const Ice::CommunicatorPtr&, const ApplicationDescriptorPtr&);
ApplicationDescriptorHelper(const Ice::CommunicatorPtr&, const DescriptorVariablesPtr&, const IceXML::Attributes&);
+ void endParsing();
+
const ApplicationDescriptorPtr& getDescriptor() const;
void setComment(const std::string&);
- ServerDescriptorHelper* addServer(const IceXML::Attributes&);
- ServerDescriptorHelper* addServerTemplate(const IceXML::Attributes&);
- ServiceDescriptorHelper* addServiceTemplate(const IceXML::Attributes&);
+
+ void addNode(const IceXML::Attributes&);
+ void endNodeParsing();
+
+ void addServer(const std::string&, const IceXML::Attributes&);
+ void addServer(const ServerDescriptorPtr&);
+ std::auto_ptr<ServerDescriptorHelper> addServerTemplate(const std::string&, const IceXML::Attributes&);
+ std::auto_ptr<ServiceDescriptorHelper> addServiceTemplate(const std::string&, const IceXML::Attributes&);
private:
@@ -136,6 +158,7 @@ public:
const DescriptorTemplatesPtr&);
bool operator==(const ComponentDescriptorHelper&) const;
+ bool operator!=(const ComponentDescriptorHelper&) const;
void setComment(const std::string&);
void addProperty(const IceXML::Attributes&);
@@ -159,24 +182,32 @@ class ServerDescriptorHelper : public ComponentDescriptorHelper
public:
ServerDescriptorHelper(const DescriptorHelper&, const ServerDescriptorPtr&);
- ServerDescriptorHelper(const DescriptorHelper&, const IceXML::Attributes&);
- ServerDescriptorHelper(const Ice::CommunicatorPtr&, const DescriptorVariablesPtr&, const IceXML::Attributes&);
+ ServerDescriptorHelper(const DescriptorHelper&, const IceXML::Attributes&, const std::string&);
+ ~ServerDescriptorHelper();
+
+ void endParsing();
bool operator==(const ServerDescriptorHelper&) const;
+ bool operator!=(const ServerDescriptorHelper&) const;
+
virtual ServerDescriptorPtr instantiate(std::set<std::string>&) const;
const ServerDescriptorPtr& getDescriptor() const;
+ const std::string& getTemplateId() const;
+
+ void addService(const std::string&, const IceXML::Attributes&);
+ void addService(const ServiceDescriptorPtr&);
+ std::auto_ptr<ServiceDescriptorHelper> addServiceTemplate(const std::string&, const IceXML::Attributes&);
- ServiceDescriptorHelper* addService(const IceXML::Attributes&);
void addOption(const std::string&);
void addEnv(const std::string&);
- void addJvmOption(const std::string&);
+ void addInterpreterOption(const std::string&);
private:
- void initFromXml(const IceXML::Attributes&);
virtual void instantiateImpl(const ServerDescriptorPtr&, std::set<std::string>&) const;
ServerDescriptorPtr _descriptor;
+ std::string _templateId;
};
class ServiceDescriptorHelper : public ComponentDescriptorHelper
@@ -184,17 +215,24 @@ class ServiceDescriptorHelper : public ComponentDescriptorHelper
public:
ServiceDescriptorHelper(const DescriptorHelper&, const ServiceDescriptorPtr&);
- ServiceDescriptorHelper(const DescriptorHelper&, const IceXML::Attributes&);
+ ServiceDescriptorHelper(const DescriptorHelper&, const IceXML::Attributes&, const std::string&);
+ ~ServiceDescriptorHelper();
+
+ void endParsing();
bool operator==(const ServiceDescriptorHelper&) const;
+ bool operator!=(const ServiceDescriptorHelper&) const;
+
virtual ServiceDescriptorPtr instantiate(std::set<std::string>&) const;
const ServiceDescriptorPtr& getDescriptor() const;
+ const std::string& getTemplateId() const;
private:
virtual void instantiateImpl(const ServiceDescriptorPtr&, std::set<std::string>&) const;
ServiceDescriptorPtr _descriptor;
+ std::string _templateId;
};
}
diff --git a/cpp/src/IceGrid/DescriptorParser.cpp b/cpp/src/IceGrid/DescriptorParser.cpp
index f18f4fd8bdc..aff1fc7e6a8 100644
--- a/cpp/src/IceGrid/DescriptorParser.cpp
+++ b/cpp/src/IceGrid/DescriptorParser.cpp
@@ -31,8 +31,7 @@ public:
DescriptorHandler(const string&);
void setCommunicator(const Ice::CommunicatorPtr&);
- void setVariables(const std::map<std::string, std::string>&);
- void setTargets(const std::vector<std::string>&);
+ void setVariables(const std::map<std::string, std::string>&, const std::vector<std::string>&);
virtual void startElement(const string&, const IceXML::Attributes&, int, int);
virtual void endElement(const string&, int, int);
@@ -40,7 +39,6 @@ public:
virtual void error(const string&, int, int);
const ApplicationDescriptorPtr& getApplicationDescriptor() const;
- const ServerDescriptorPtr& getServerDescriptor() const;
private:
@@ -57,9 +55,6 @@ private:
std::vector<std::string> _targets;
DescriptorVariablesPtr _variables;
std::stack<std::string> _elements;
- std::map<std::string, ServerDescriptorPtr> _serverTemplates;
- std::map<std::string, ServiceDescriptorPtr> _serviceTemplates;
- std::map<std::string, ComponentDescriptorPtr> _templates;
int _targetCounter;
bool _isCurrentTargetDeployable;
int _line;
@@ -101,14 +96,9 @@ DescriptorHandler::setCommunicator(const Ice::CommunicatorPtr& communicator)
}
void
-DescriptorHandler::setVariables(const std::map<std::string, std::string>& variables)
-{
- _variables->reset(variables);
-}
-
-void
-DescriptorHandler::setTargets(const vector<string>& targets)
+DescriptorHandler::setVariables(const std::map<std::string, std::string>& variables, const vector<string>& targets)
{
+ _variables->reset(variables, targets);
_targets = targets;
}
@@ -159,8 +149,7 @@ DescriptorHandler::startElement(const string& name, const IceXML::Attributes& at
_variables->push();
string file;
- string targets;
-
+ string targets;
for(IceXML::Attributes::const_iterator p = attrs.begin(); p != attrs.end(); ++p)
{
if(p->first == "descriptor")
@@ -173,8 +162,7 @@ DescriptorHandler::startElement(const string& name, const IceXML::Attributes& at
}
else
{
- string v = _variables->substitute(p->second);
- (*_variables)[p->first] = v;
+ _variables->addVariable(p->first, _variables->substitute(p->second));
}
}
@@ -212,14 +200,17 @@ DescriptorHandler::startElement(const string& name, const IceXML::Attributes& at
}
_currentApplication.reset(new ApplicationDescriptorHelper(_communicator, _variables, attrs));
- (*_variables)["application"] = _currentApplication->getDescriptor()->name;
}
else if(name == "node")
{
- (*_variables)["node"] = attributes("name");
+ _currentApplication->addNode(attrs);
}
else if(name == "server")
{
+ if(!_currentApplication.get())
+ {
+ error("the <server> element can only be a child of a <application> element");
+ }
if(_currentServer.get())
{
error("element <server> inside a server definition");
@@ -229,18 +220,15 @@ DescriptorHandler::startElement(const string& name, const IceXML::Attributes& at
error("the <server> element can only be a child of a <node> element");
}
- _variables->push();
-
- if(!_currentApplication.get())
+ if(attributes.contains("template"))
{
- _currentServer.reset(new ServerDescriptorHelper(_communicator, _variables, attrs));
+ _currentApplication->addServer(attributes("template"), attrs);
}
else
{
- _currentServer.reset(_currentApplication->addServer(attrs));
+ _currentServer = _currentApplication->addServerTemplate("", attrs);
+ _currentComponent = _currentServer.get();
}
- _currentComponent = _currentServer.get();
- (*_variables)["server"] = _currentServer->getDescriptor()->name;
}
else if(name == "server-template")
{
@@ -249,27 +237,29 @@ DescriptorHandler::startElement(const string& name, const IceXML::Attributes& at
error("element <server-template> inside a server definition");
}
- _variables->push();
- _variables->ignoreMissing(true);
- _variables->escape(false);
- (*_variables)["node"] = "${node}";
-
- _currentServer.reset(_currentApplication->addServerTemplate(attrs));
+ _currentServer = _currentApplication->addServerTemplate(attributes("id"), attrs);
_currentComponent = _currentServer.get();
- (*_variables)["server"] = _currentServer->getDescriptor()->name;
}
else if(name == "service")
{
+ if(!_currentServer.get())
+ {
+ error("the <service> element can only be a child of a <server> element");
+ }
if(_currentService.get())
{
error("element <service> inside a service definition");
}
- _variables->push();
-
- _currentService.reset(_currentServer->addService(attrs));
- _currentComponent = _currentService.get();
- (*_variables)["service"] = _currentService->getDescriptor()->name;
+ if(attributes.contains("template"))
+ {
+ _currentServer->addService(attributes("template"), attrs);
+ }
+ else
+ {
+ _currentService = _currentServer->addServiceTemplate("", attrs);
+ _currentComponent = _currentService.get();
+ }
}
else if(name == "service-template")
{
@@ -278,20 +268,16 @@ DescriptorHandler::startElement(const string& name, const IceXML::Attributes& at
error("element <service-template> inside a service definition");
}
- _variables->push();
- _variables->ignoreMissing(true);
- _variables->escape(false);
-
- (*_variables)["node"] = "${node}";
- (*_variables)["server"] = "${server}";
-
- _currentService.reset(_currentApplication->addServiceTemplate(attrs));
+ _currentService = _currentApplication->addServiceTemplate(attributes("id"), attrs);
_currentComponent = _currentService.get();
- (*_variables)["service"] = _currentService->getDescriptor()->name;
}
else if(name == "variable")
{
- (*_variables)[attributes("name")] = attributes("value", "");
+ _variables->addVariable(attributes("name"), attributes("value", ""));
+ }
+ else if(name == "parameter")
+ {
+ _variables->addParameter(attributes("name"));
}
else if(name == "properties")
{
@@ -384,7 +370,7 @@ DescriptorHandler::endElement(const string& name, int line, int column)
}
else if(name == "application")
{
- _variables->remove("application");
+ _currentApplication->endParsing();
}
else if(name == "node")
{
@@ -392,28 +378,29 @@ DescriptorHandler::endElement(const string& name, int line, int column)
}
else if(name == "server" || name == "server-template")
{
- if(_currentApplication.get())
+ if(_currentServer.get())
{
+ _currentServer->endParsing();
+ if(name == "server")
+ {
+ _currentApplication->addServer(_currentServer->getDescriptor());
+ }
_currentServer.reset(0);
+ _currentComponent = 0;
}
- _currentComponent = 0;
- if(name == "server-template")
- {
- _variables->ignoreMissing(false);
- _variables->escape(true);
- }
- _variables->pop();
}
else if(name == "service" || name == "service-template")
{
- _currentService.reset(0);
- _currentComponent = _currentServer.get();
- if(name == "service-template")
+ if(_currentService.get())
{
- _variables->ignoreMissing(false);
- _variables->escape(true);
+ _currentService->endParsing();
+ if(name == "service")
+ {
+ _currentServer->addService(_currentService->getDescriptor());
+ }
+ _currentService.reset(0);
+ _currentComponent = _currentServer.get();
}
- _variables->pop();
}
else if(name == "comment")
{
@@ -425,6 +412,10 @@ DescriptorHandler::endElement(const string& name, int line, int column)
{
_currentApplication->setComment(elementValue());
}
+ else
+ {
+ error("element <comment> can only be the child of an <application>, <server> or <service> element");
+ }
}
else if(name == "option")
{
@@ -442,13 +433,16 @@ DescriptorHandler::endElement(const string& name, int line, int column)
}
_currentServer->addEnv(elementValue());
}
- else if(name == "jvm-option")
+ else if(name == "interpreter-option" ||
+ _currentServer.get() &&
+ !_currentServer->getDescriptor()->interpreter.empty() &&
+ name == (_currentServer->getDescriptor()->interpreter + "-option"))
{
if(!_currentServer.get())
{
- error("element <env> can only be the child of a <server> element");
+ error("element " + name + " can only be the child of a <server> element");
}
- _currentServer->addJvmOption(elementValue());
+ _currentServer->addInterpreterOption(elementValue());
}
else if(name == "properties")
{
@@ -494,16 +488,6 @@ DescriptorHandler::getApplicationDescriptor() const
return _currentApplication->getDescriptor();
}
-const ServerDescriptorPtr&
-DescriptorHandler::getServerDescriptor() const
-{
- if(!_currentServer.get())
- {
- error("no server descriptor defined in this file");
- }
- return _currentServer->getDescriptor();
-}
-
string
DescriptorHandler::getAttributeValue(const IceXML::Attributes& attrs, const string& name) const
{
@@ -660,29 +644,14 @@ DescriptorHandler::isTargetDeployable(const string& target) const
}
ApplicationDescriptorPtr
-DescriptorParser::parseApplicationDescriptor(const string& descriptor,
- const Ice::StringSeq& targets,
- const map<string, string>& variables,
- const Ice::CommunicatorPtr& communicator)
+DescriptorParser::parseDescriptor(const string& descriptor,
+ const Ice::StringSeq& targets,
+ const map<string, string>& variables,
+ const Ice::CommunicatorPtr& communicator)
{
DescriptorHandler handler(descriptor);
handler.setCommunicator(communicator);
- handler.setTargets(targets);
- handler.setVariables(variables);
+ handler.setVariables(variables, targets);
IceXML::Parser::parse(descriptor, handler);
return handler.getApplicationDescriptor();
}
-
-ServerDescriptorPtr
-DescriptorParser::parseServerDescriptor(const string& descriptor,
- const Ice::StringSeq& targets,
- const map<string, string>& variables,
- const Ice::CommunicatorPtr& communicator)
-{
- DescriptorHandler handler(descriptor);
- handler.setCommunicator(communicator);
- handler.setTargets(targets);
- handler.setVariables(variables);
- IceXML::Parser::parse(descriptor, handler);
- return handler.getServerDescriptor();
-}
diff --git a/cpp/src/IceGrid/DescriptorParser.h b/cpp/src/IceGrid/DescriptorParser.h
index e448abf2aa2..e61e9ce3dd5 100644
--- a/cpp/src/IceGrid/DescriptorParser.h
+++ b/cpp/src/IceGrid/DescriptorParser.h
@@ -17,15 +17,10 @@ class DescriptorParser
{
public:
- static ApplicationDescriptorPtr parseApplicationDescriptor(const std::string&,
- const Ice::StringSeq&,
- const std::map<std::string, std::string>&,
- const Ice::CommunicatorPtr&);
-
- static ServerDescriptorPtr parseServerDescriptor(const std::string&,
- const Ice::StringSeq&,
- const std::map<std::string, std::string>&,
- const Ice::CommunicatorPtr&);
+ static ApplicationDescriptorPtr parseDescriptor(const std::string&,
+ const Ice::StringSeq&,
+ const std::map<std::string, std::string>&,
+ const Ice::CommunicatorPtr&);
};
diff --git a/cpp/src/IceGrid/Grammar.y b/cpp/src/IceGrid/Grammar.y
index e693787e489..b0598b3f876 100644
--- a/cpp/src/IceGrid/Grammar.y
+++ b/cpp/src/IceGrid/Grammar.y
@@ -64,6 +64,8 @@ yyerror(const char* s)
%token ICE_GRID_DIFF
%token ICE_GRID_UPDATE
%token ICE_GRID_INSTANTIATE
+%token ICE_GRID_TEMPLATE
+%token ICE_GRID_SERVICE
%%
@@ -120,7 +122,15 @@ command
{
parser->describeApplication($3);
}
-| ICE_GRID_APPLICATION ICE_GRID_INSTANTIATE strings ';'
+| ICE_GRID_APPLICATION ICE_GRID_SERVER ICE_GRID_TEMPLATE ICE_GRID_DESCRIBE strings ';'
+{
+ parser->describeApplicationServerTemplate($5);
+}
+| ICE_GRID_APPLICATION ICE_GRID_SERVICE ICE_GRID_TEMPLATE ICE_GRID_DESCRIBE strings ';'
+{
+ parser->describeApplicationServiceTemplate($5);
+}|
+ ICE_GRID_APPLICATION ICE_GRID_INSTANTIATE strings ';'
{
parser->instantiateApplication($3);
}
diff --git a/cpp/src/IceGrid/IceGridNode.cpp b/cpp/src/IceGrid/IceGridNode.cpp
index 255a9ab90bd..e67f5840605 100644
--- a/cpp/src/IceGrid/IceGridNode.cpp
+++ b/cpp/src/IceGrid/IceGridNode.cpp
@@ -485,8 +485,7 @@ NodeService::start(int argc, char* argv[])
try
{
map<string, string> vars;
- admin->addApplication(
- DescriptorParser::parseApplicationDescriptor(descriptor, targets, vars, communicator()));
+ admin->addApplication(DescriptorParser::parseDescriptor(descriptor, targets, vars, communicator()));
}
catch(const DeploymentException& ex)
{
diff --git a/cpp/src/IceGrid/Parser.cpp b/cpp/src/IceGrid/Parser.cpp
index c9b31f21949..de2067cafa5 100644
--- a/cpp/src/IceGrid/Parser.cpp
+++ b/cpp/src/IceGrid/Parser.cpp
@@ -40,8 +40,25 @@ namespace IceGrid
Parser* parser;
+string
+toString(const vector<string>& v)
+{
+ ostringstream os;
+ Ice::StringSeq::const_iterator p = v.begin();
+ while(p != v.end())
+ {
+ os << *p;
+ ++p;
+ if(p != v.end())
+ {
+ os << " ";
+ }
+ }
+ return os.str();
+}
+
void
-describeDbEnv(IceUtil::Output& out, const DbEnvDescriptor& dbEnv)
+describeDbEnv(Output& out, const DbEnvDescriptor& dbEnv)
{
//
// Database environments
@@ -60,7 +77,7 @@ describeDbEnv(IceUtil::Output& out, const DbEnvDescriptor& dbEnv)
out << sb;
for(PropertyDescriptorSeq::const_iterator p = dbEnv.properties.begin(); p != dbEnv.properties.end(); ++p)
{
- out << nl << p->name << "=" << p->value;
+ out << nl << p->name << " = " << p->value;
}
out << eb;
}
@@ -69,7 +86,7 @@ describeDbEnv(IceUtil::Output& out, const DbEnvDescriptor& dbEnv)
}
void
-describeObjectAdapter(IceUtil::Output& out, const Ice::CommunicatorPtr& communicator, const AdapterDescriptor& adapter)
+describeObjectAdapter(Output& out, const Ice::CommunicatorPtr& communicator, const AdapterDescriptor& adapter)
{
out << nl << "adapter '" << adapter.name << "'";
out << sb;
@@ -91,19 +108,19 @@ describeObjectAdapter(IceUtil::Output& out, const Ice::CommunicatorPtr& communic
}
void
-describeProperties(IceUtil::Output& out, const PropertyDescriptorSeq& properties)
+describeProperties(Output& out, const PropertyDescriptorSeq& properties)
{
out << nl << "properties";
out << sb;
for(PropertyDescriptorSeq::const_iterator p = properties.begin(); p != properties.end(); ++p)
{
- out << nl << p->name << "=" << p->value;
+ out << nl << p->name << " = " << p->value;
}
out << eb;
}
void
-describeComponent(IceUtil::Output& out, const Ice::CommunicatorPtr& communicator, const ComponentDescriptorPtr& desc)
+describeComponent(Output& out, const Ice::CommunicatorPtr& communicator, const ComponentDescriptorPtr& desc)
{
if(!desc->comment.empty())
{
@@ -131,28 +148,23 @@ describeComponent(IceUtil::Output& out, const Ice::CommunicatorPtr& communicator
}
void
-describe(IceUtil::Output& out, const Ice::CommunicatorPtr& communicator, const ServerDescriptorPtr& server)
+describeService(Output& out, const Ice::CommunicatorPtr& communicator, const ServiceDescriptorPtr& service)
{
- out << "server '" << server->name << "' ";
- if(JavaServerDescriptorPtr::dynamicCast(server))
- {
- if(JavaIceBoxDescriptorPtr::dynamicCast(server))
- {
- out << " (Java IceBox)";
- }
- else
- {
- out << " (Java)";
- }
- }
- else if(CppIceBoxDescriptorPtr::dynamicCast(server))
- {
- out << " (IceBox)";
- }
+ out << nl << "entry = '" << service->entry << "'";
+ describeComponent(out, communicator, service);
+}
- out << sb;
+void describe(Output& out, const Ice::CommunicatorPtr&, const InstanceDescriptor&);
+
+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 << "'";
+ }
out << nl << "exe = '" << server->exe << "'";
if(!server->pwd.empty())
{
@@ -160,82 +172,114 @@ describe(IceUtil::Output& out, const Ice::CommunicatorPtr& communicator, const S
}
out << nl << "activation = '" << server->activation << "'";
- if(JavaServerDescriptorPtr::dynamicCast(server))
+ if(!server->interpreterOptions.empty())
+ {
+ out << nl << "interpreterOptions = '" << toString(server->interpreterOptions) << "'";
+ }
+ IceBoxDescriptorPtr iceBox = IceBoxDescriptorPtr::dynamicCast(server);
+ if(iceBox)
+ {
+ out << nl << "service manager endpoints = '" << iceBox->endpoints << "'";
+ }
+ if(!server->options.empty())
+ {
+ out << nl << "options = '" << toString(server->options) << "'";
+ }
+ if(!server->envs.empty())
+ {
+ out << nl << "envs = '" << toString(server->envs) << "'";
+ }
+
+ describeComponent(out, communicator, server);
+
+ //
+ // Services
+ //
+ if(iceBox)
{
- JavaServerDescriptorPtr s = JavaServerDescriptorPtr::dynamicCast(server);
- out << nl << "className = '" << s->className << "'";
- if(!s->jvmOptions.empty())
+ for(InstanceDescriptorSeq::const_iterator p = iceBox->services.begin(); p != iceBox->services.end(); ++p)
{
- out << nl << "jvmOptions = '";
- Ice::StringSeq::const_iterator p = s->jvmOptions.begin();
- while(p != s->jvmOptions.end())
- {
- out << *p;
- ++p;
- if(p != s->jvmOptions.end())
- {
- out << " ";
- }
- else
- {
- out << "'";
- }
- }
+ describe(out, communicator, *p);
+ }
+ }
+}
+
+void
+describe(Output& out, const Ice::CommunicatorPtr& communicator, const string& id, const TemplateDescriptor& templ)
+{
+ ServerDescriptorPtr server = ServerDescriptorPtr::dynamicCast(templ.descriptor);
+ if(server)
+ {
+ out << "server template '" << id << "'";
+ IceBoxDescriptorPtr iceBox = IceBoxDescriptorPtr::dynamicCast(server);
+ if(iceBox)
+ {
+ out << " (IceBox)";
}
}
- if(JavaIceBoxDescriptorPtr::dynamicCast(server))
+ ServiceDescriptorPtr service = ServiceDescriptorPtr::dynamicCast(templ.descriptor);
+ if(service)
{
- JavaIceBoxDescriptorPtr s = JavaIceBoxDescriptorPtr::dynamicCast(server);
- out << nl << "service manager endpoints = '" << s->endpoints << "'";
+ out << nl << "service template '" << id << "'";
}
- if(CppIceBoxDescriptorPtr::dynamicCast(server))
+
+ out << sb;
+ if(!templ.parameters.empty())
{
- CppIceBoxDescriptorPtr s = CppIceBoxDescriptorPtr::dynamicCast(server);
- out << nl << "service manager endpoints = '" << s->endpoints << "'";
+ out << nl << "parameters = '" << toString(templ.parameters) << "'";
}
- if(!server->options.empty())
+ if(!server->variables.empty())
{
- out << nl << "options = '";
- Ice::StringSeq::const_iterator p = server->options.begin();
- while(p != server->options.end())
+ out << nl << "variables";
+ out << sb;
+ for(StringStringDict::const_iterator p = server->variables.begin(); p != server->variables.end(); ++p)
{
- out << *p;
- ++p;
- if(p != server->options.end())
- {
- out << " ";
- }
- else
- {
- out << "'";
- }
+ out << nl << p->first << " = " << p->second;
}
+ out << eb;
}
- if(!server->envs.empty())
+
+ out << nl << "name = '" << server->name << "'";
+ if(server)
+ {
+ describeServer(out, communicator, server);
+ out << eb;
+ out << nl;
+ }
+ if(service)
+ {
+ describeService(out, communicator, service);
+ out << eb;
+ }
+}
+
+
+void
+describe(Output& out, const Ice::CommunicatorPtr& communicator, const InstanceDescriptor& inst)
+{
+ ServerDescriptorPtr server = ServerDescriptorPtr::dynamicCast(inst.descriptor);
+ if(server)
{
- out << nl << "envs = '";
- for(Ice::StringSeq::const_iterator p = server->envs.begin(); p != server->envs.end(); ++p)
+ out << "server '" << server->name << "' ";
+ IceBoxDescriptorPtr iceBox = IceBoxDescriptorPtr::dynamicCast(server);
+ if(iceBox)
{
- out << *p << " ";
+ out << " (IceBox)";
}
+ out << sb;
+ describeServer(out, communicator, server);
+ out << eb;
}
- describeComponent(out, communicator, server);
-
- //
- // Services
- //
- ServiceDescriptorSeq services = getServices(server);
- for(ServiceDescriptorSeq::const_iterator p = services.begin(); p != services.end(); ++p)
+ ServiceDescriptorPtr service = ServiceDescriptorPtr::dynamicCast(inst.descriptor);
+ if(service)
{
- out << nl << "service '" << (*p)->name << "'";
+ out << nl << "service '" << service->name << "'";
out << sb;
- out << nl << "entry = '" << (*p)->entry << "'";
- describeComponent(out, communicator, *p);
+ describeService(out, communicator, service);
out << eb;
}
- out << eb;
out << nl;
}
@@ -259,6 +303,11 @@ Parser::usage()
" the optional targets TARGET will be deployed.\n"
"application remove NAME Remove application NAME.\n"
"application describe NAME Describe application NAME.\n"
+ "application server template describe NAME TEMPLATE\n"
+ " Describe application NAME server template TEMPLATE.\n"
+ "application service template describe NAME TEMPLATE\n"
+ " Describe application NAME service template TEMPLATE.\n"
+ "application describe NAME Describe application NAME.\n"
"application diff DESC [TARGET ... ] [NAME=VALUE ... ]\n"
" Print the differences betwen the application\n"
" described in DESC and the current deployment.\n"
@@ -352,7 +401,7 @@ Parser::addApplication(const list<string>& args)
}
}
- _admin->addApplication(DescriptorParser::parseApplicationDescriptor(descriptor, targets, vars, _communicator));
+ _admin->addApplication(DescriptorParser::parseDescriptor(descriptor, targets, vars, _communicator));
}
catch(const IceXML::ParserException& ex)
{
@@ -422,27 +471,53 @@ Parser::describeApplication(const list<string>& args)
ApplicationDescriptorPtr application = _admin->getApplicationDescriptor(name);
- IceUtil::Output out(cout);
+ Output out(cout);
out << "application '" << application->name << "'";
out << sb;
if(!application->comment.empty())
{
out << nl << "comment = " << application->comment;
}
+
+ if(!application->serverTemplates.empty())
+ {
+ out << nl << "server templates";
+ out << sb;
+ for(TemplateDescriptorDict::const_iterator p = application->serverTemplates.begin();
+ p != application->serverTemplates.end();
+ ++p)
+ {
+ out << nl << p->first;
+ }
+ out << eb;
+ }
+ if(!application->serviceTemplates.empty())
+ {
+ out << nl << "service templates";
+ out << sb;
+ for(TemplateDescriptorDict::const_iterator p = application->serviceTemplates.begin();
+ p != application->serviceTemplates.end();
+ ++p)
+ {
+ out << nl << p->first;
+ }
+ out << eb;
+ }
if(!application->servers.empty())
{
map<string, set<string> > servers;
{
- for(ServerDescriptorSeq::const_iterator p = application->servers.begin();
+ for(InstanceDescriptorSeq::const_iterator p = application->servers.begin();
p != application->servers.end();
++p)
{
- map<string, set<string> >::iterator q = servers.find((*p)->node);
+ const ServerDescriptorPtr descriptor = ServerDescriptorPtr::dynamicCast(p->descriptor);
+ map<string, set<string> >::iterator q = servers.find(descriptor->node);
if(q == servers.end())
{
- q = servers.insert(make_pair((*p)->node, set<string>())).first;
+ q = servers.insert(make_pair(descriptor->node, set<string>())).first;
}
- q->second.insert((*p)->name);
+ q->second.insert(descriptor->name);
}
}
{
@@ -476,6 +551,81 @@ Parser::describeApplication(const list<string>& args)
}
void
+Parser::describeApplicationServerTemplate(const list<string>& args)
+{
+ if(args.size() != 2)
+ {
+ error("`application server template describe' requires exactly two arguments\n(`help' for more info)");
+ return;
+ }
+
+ try
+ {
+ list<string>::const_iterator p = args.begin();
+
+ string name = *p++;
+ string templ = *p++;
+
+ ApplicationDescriptorPtr application = _admin->getApplicationDescriptor(name);
+
+ Output out(cout);
+ TemplateDescriptorDict::const_iterator q = application->serverTemplates.find(templ);
+ if(q != application->serverTemplates.end())
+ {
+ describe(out, _communicator, templ, q->second);
+ }
+ else
+ {
+ error("no server template with id `" + templ + "'");
+ }
+ }
+ catch(const Ice::Exception& ex)
+ {
+ ostringstream s;
+ s << ex;
+ error(s.str());
+ }
+}
+
+void
+Parser::describeApplicationServiceTemplate(const list<string>& args)
+{
+ if(args.size() != 2)
+ {
+ error("`application service template describe' requires exactly two arguments\n(`help' for more info)");
+ return;
+ }
+
+ try
+ {
+ list<string>::const_iterator p = args.begin();
+
+ string name = *p++;
+ string templ = *p++;
+
+ ApplicationDescriptorPtr application = _admin->getApplicationDescriptor(name);
+
+ Output out(cout);
+ TemplateDescriptorDict::const_iterator q = application->serviceTemplates.find(templ);
+ if(q != application->serviceTemplates.end())
+ {
+ describe(out, _communicator, templ, q->second);
+ }
+ else
+ {
+ error("no service template with id `" + templ + "'");
+ }
+ }
+ catch(const Ice::Exception& ex)
+ {
+ ostringstream s;
+ s << ex;
+ error(s.str());
+ }
+}
+
+
+void
Parser::diffApplication(const list<string>& args)
{
if(args.size() < 1)
@@ -508,7 +658,7 @@ Parser::diffApplication(const list<string>& args)
}
}
- newApp = DescriptorParser::parseApplicationDescriptor(descriptor, targets, vars, _communicator);
+ newApp = DescriptorParser::parseDescriptor(descriptor, targets, vars, _communicator);
origApp = _admin->getApplicationDescriptor(newApp->name);
}
catch(const DeploymentException& ex)
@@ -530,47 +680,49 @@ Parser::diffApplication(const list<string>& args)
out << "application `" << newApp->name << "'";
out << sb;
- ServerDescriptorSeq::const_iterator p;
+ InstanceDescriptorSeq::const_iterator p;
+ ApplicationDescriptorHelper newAppHelper(_communicator, newApp);
+ ApplicationDescriptorHelper origAppHelper(_communicator, origApp);
for(p = newApp->servers.begin(); p != newApp->servers.end(); ++p)
{
+ ServerDescriptorPtr desc = ServerDescriptorPtr::dynamicCast(p->descriptor);
ServerDescriptorPtr orig;
- for(ServerDescriptorSeq::const_iterator q = origApp->servers.begin(); q != origApp->servers.end(); ++q)
+ for(InstanceDescriptorSeq::const_iterator q = origApp->servers.begin(); q != origApp->servers.end(); ++q)
{
- if((*q)->name == (*p)->name)
+ if(desc->name == q->descriptor->name)
{
- orig = *q;
+ orig = ServerDescriptorPtr::dynamicCast(q->descriptor);
break;
}
}
if(orig)
{
- if(!equal(orig, *p))
+ if(ServerDescriptorHelper(newAppHelper, desc) != ServerDescriptorHelper(origAppHelper, orig))
{
out << nl << "server `" << orig->name << "' updated";
}
}
else
{
- out << nl << "server `" << (*p)->name << "' added";
+ out << nl << "server `" << desc->name << "' added";
}
}
for(p = origApp->servers.begin(); p != origApp->servers.end(); ++p)
{
bool found = false;
- for(ServerDescriptorSeq::const_iterator q = newApp->servers.begin(); q != newApp->servers.end(); ++q)
+ for(InstanceDescriptorSeq::const_iterator q = newApp->servers.begin(); q != newApp->servers.end(); ++q)
{
- if((*q)->name == (*p)->name)
+ if(p->descriptor->name == q->descriptor->name)
{
found = true;
break;
}
}
-
if(!found)
{
- out << nl << "server `" << (*p)->name << "' removed";
+ out << nl << "server `" << p->descriptor->name << "' removed";
}
}
@@ -608,8 +760,7 @@ Parser::updateApplication(const list<string>& args)
}
}
- _admin->updateApplication(
- DescriptorParser::parseApplicationDescriptor(descriptor, targets, vars, _communicator));
+ _admin->updateApplication(DescriptorParser::parseDescriptor(descriptor, targets, vars, _communicator));
}
catch(const IceXML::ParserException& ex)
{
@@ -812,7 +963,7 @@ Parser::addServer(const list<string>& args)
}
}
- _admin->addServer(DescriptorParser::parseServerDescriptor(descriptor, targets, vars, _communicator));
+ _admin->addServer(DescriptorParser::parseDescriptor(descriptor, targets, vars, _communicator));
}
catch(const DeploymentException& ex)
{
@@ -859,7 +1010,7 @@ Parser::updateServer(const list<string>& args)
}
}
- _admin->updateServer(DescriptorParser::parseServerDescriptor(descriptor, targets, vars, _communicator));
+ _admin->updateServer(DescriptorParser::parseDescriptor(descriptor, targets, vars, _communicator));
}
catch(const DeploymentException& ex)
{
@@ -978,8 +1129,8 @@ Parser::describeServer(const list<string>& args)
try
{
- ServerDescriptorPtr desc = _admin->getServerDescriptor(args.front());
- IceUtil::Output out(cout);
+ InstanceDescriptor desc = _admin->getServerDescriptor(args.front());
+ Output out(cout);
describe(out, _communicator, desc);
}
catch(const Ice::Exception& ex)
diff --git a/cpp/src/IceGrid/Parser.h b/cpp/src/IceGrid/Parser.h
index 3d9493226fd..c9db686d181 100644
--- a/cpp/src/IceGrid/Parser.h
+++ b/cpp/src/IceGrid/Parser.h
@@ -70,6 +70,8 @@ public:
void addApplication(const std::list<std::string>&);
void removeApplication(const std::list<std::string>&);
void describeApplication(const std::list<std::string>&);
+ void describeApplicationServerTemplate(const std::list<std::string>&);
+ void describeApplicationServiceTemplate(const std::list<std::string>&);
void diffApplication(const std::list<std::string>&);
void updateApplication(const std::list<std::string>&);
void instantiateApplication(const std::list<std::string>&);
diff --git a/cpp/src/IceGrid/Scanner.l b/cpp/src/IceGrid/Scanner.l
index 967e6de47b0..2eebcafef56 100644
--- a/cpp/src/IceGrid/Scanner.l
+++ b/cpp/src/IceGrid/Scanner.l
@@ -209,6 +209,14 @@ NL [\n]
return ICE_GRID_INSTANTIATE;
}
+"template" {
+ return ICE_GRID_TEMPLATE;
+}
+
+"service" {
+ return ICE_GRID_SERVICE;
+}
+
{WS}*(\\{WS}*{NL})? {
size_t len = strlen(yytext);
for(size_t i = 0; i < len; ++i)
diff --git a/cpp/src/IceGrid/ServerI.cpp b/cpp/src/IceGrid/ServerI.cpp
index b1bbc53f033..522fbda1f92 100644
--- a/cpp/src/IceGrid/ServerI.cpp
+++ b/cpp/src/IceGrid/ServerI.cpp
@@ -110,11 +110,14 @@ ServerI::load(const ServerDescriptorPtr& descriptor, StringAdapterPrxDict& adapt
Ice::StringSeq knownFiles;
updateConfigFile(_serverDir, descriptor);
knownFiles.push_back("config");
- ServiceDescriptorSeq services = getServices(descriptor);
- for(ServiceDescriptorSeq::const_iterator p = services.begin(); p != services.end(); ++p)
+ IceBoxDescriptorPtr iceBox = IceBoxDescriptorPtr::dynamicCast(descriptor);
+ if(iceBox)
{
- updateConfigFile(_serverDir, *p);
- knownFiles.push_back("config_" + (*p)->name);
+ for(InstanceDescriptorSeq::const_iterator p = iceBox->services.begin(); p != iceBox->services.end(); ++p)
+ {
+ updateConfigFile(_serverDir, ServiceDescriptorPtr::dynamicCast(p->descriptor));
+ knownFiles.push_back("config_" + p->descriptor->name);
+ }
}
//
@@ -181,12 +184,16 @@ ServerI::load(const ServerDescriptorPtr& descriptor, StringAdapterPrxDict& adapt
addAdapter(*p, self, current);
oldAdapters.erase(p->id);
}
- for(ServiceDescriptorSeq::const_iterator p = services.begin(); p != services.end(); ++p)
+ if(iceBox)
{
- for(AdapterDescriptorSeq::const_iterator q = (*p)->adapters.begin(); q != (*p)->adapters.end(); ++q)
+ for(InstanceDescriptorSeq::const_iterator p = iceBox->services.begin(); p != iceBox->services.end(); ++p)
{
- addAdapter(*q, self, current);
- oldAdapters.erase(q->id);
+ ServiceDescriptorPtr s = ServiceDescriptorPtr::dynamicCast(p->descriptor);
+ for(AdapterDescriptorSeq::const_iterator q = s->adapters.begin(); q != s->adapters.end(); ++q)
+ {
+ addAdapter(*q, self, current);
+ oldAdapters.erase(q->id);
+ }
}
}
for(StringAdapterPrxDict::const_iterator p = oldAdapters.begin(); p != oldAdapters.end(); ++p)
@@ -218,11 +225,6 @@ ServerI::addAdapter(const AdapterDescriptor& descriptor, const ServerPrx& self,
bool
ServerI::start(ServerActivation act, const Ice::Current& current)
{
- string exe;
- string wd;
- Ice::StringSeq opts;
- Ice::StringSeq evs;
-
ServerDescriptorPtr desc;
while(true)
{
@@ -273,20 +275,27 @@ ServerI::start(ServerActivation act, const Ice::Current& current)
// Compute the server command line options.
//
Ice::StringSeq options;
- JavaServerDescriptorPtr javaDesc = JavaServerDescriptorPtr::dynamicCast(desc);
- if(javaDesc)
+ string exe;
+ if(!desc->interpreter.empty())
{
- copy(javaDesc->jvmOptions.begin(), javaDesc->jvmOptions.end(), back_inserter(options));
- options.push_back("-ea");
- options.push_back(javaDesc->className);
+ exe = desc->interpreter;
+ copy(desc->interpreterOptions.begin(), desc->interpreterOptions.end(), back_inserter(options));
+ options.push_back(desc->exe);
+ }
+ else
+ {
+ exe = desc->exe;
}
copy(desc->options.begin(), desc->options.end(), back_inserter(options));
options.push_back("--Ice.Config=" + _serverDir + "/config/config");
+ Ice::StringSeq envs;
+ copy(desc->envs.begin(), desc->envs.end(), back_inserter(envs));
+
try
{
ServerPrx self = ServerPrx::uncheckedCast(current.adapter->createProxy(current.id));
- bool active = _node->getActivator()->activate(desc->name, desc->exe, desc->pwd, options, desc->envs, self);
+ bool active = _node->getActivator()->activate(desc->name, exe, desc->pwd, options, envs, self);
setState(active ? Active : Inactive, current);
return active;
}
@@ -749,14 +758,18 @@ ServerI::updateConfigFile(const string& serverDir, const ComponentDescriptorPtr&
// Add service properties.
//
string servicesStr;
- ServiceDescriptorSeq services = getServices(descriptor);
- for(ServiceDescriptorSeq::const_iterator p = services.begin(); p != services.end(); ++p)
+ IceBoxDescriptorPtr iceBox = IceBoxDescriptorPtr::dynamicCast(descriptor);
+ if(iceBox)
{
- const string path = serverDir + "/config/config_" + (*p)->name;
- props.push_back(createProperty("IceBox.Service." + (*p)->name, (*p)->entry + " --Ice.Config=" + path));
- servicesStr += (*p)->name + " ";
+ for(InstanceDescriptorSeq::const_iterator p = iceBox->services.begin(); p != iceBox->services.end(); ++p)
+ {
+ ServiceDescriptorPtr s = ServiceDescriptorPtr::dynamicCast(p->descriptor);
+ const string path = serverDir + "/config/config_" + s->name;
+ props.push_back(createProperty("IceBox.Service." + s->name, s->entry + " --Ice.Config=" + path));
+ servicesStr += s->name + " ";
+ }
+ props.push_back(createProperty("IceBox.LoadOrder", servicesStr));
}
- props.push_back(createProperty("IceBox.LoadOrder", servicesStr));
}
else
{
diff --git a/cpp/src/IceGrid/Util.cpp b/cpp/src/IceGrid/Util.cpp
index 83f9e8111bf..31e64f03cb9 100644
--- a/cpp/src/IceGrid/Util.cpp
+++ b/cpp/src/IceGrid/Util.cpp
@@ -18,398 +18,3 @@ using namespace std;
using namespace Ice;
using namespace IceGrid;
-namespace IceGrid
-{
-
-bool equal(const ServiceDescriptorPtr&, const ServiceDescriptorPtr&);
-void instantiateComponentTemplate(const ComponentDescriptorPtr&, const vector<map<string, string> >&, vector<string>&);
-
-}
-
-struct Substitute : std::unary_function<string&, void>
-{
- Substitute(const vector<map<string, string> >& variables, vector<string>& missing) :
- _variables(variables), _missing(missing)
- {
- }
-
- void operator()(string& v)
- {
- v.assign(substitute(v, _variables, true, _missing));
- }
-
- const vector<map<string, string> >& _variables;
- vector<string>& _missing;
-};
-
-ServiceDescriptorSeq
-IceGrid::getServices(const ComponentDescriptorPtr& descriptor)
-{
- CppIceBoxDescriptorPtr cppIceBox = CppIceBoxDescriptorPtr::dynamicCast(descriptor);
- if(cppIceBox)
- {
- return cppIceBox->services;
- }
-
- JavaIceBoxDescriptorPtr javaIceBox = JavaIceBoxDescriptorPtr::dynamicCast(descriptor);
- if(javaIceBox)
- {
- return javaIceBox->services;
- }
-
- return ServiceDescriptorSeq();
-}
-
-bool
-IceGrid::equal(const ServiceDescriptorPtr& lhs, const ServiceDescriptorPtr& rhs)
-{
- if(lhs->ice_id() != rhs->ice_id())
- {
- return false;
- }
-
- if(lhs->name != rhs->name)
- {
- return false;
- }
-
- if(lhs->comment != rhs->comment)
- {
- return false;
- }
-
- if(lhs->entry != rhs->entry)
- {
- return false;
- }
-
- if(set<AdapterDescriptor>(lhs->adapters.begin(), lhs->adapters.end()) !=
- set<AdapterDescriptor>(rhs->adapters.begin(), rhs->adapters.end()))
- {
- return false;
- }
-
- if(set<PropertyDescriptor>(lhs->properties.begin(), lhs->properties.end()) !=
- set<PropertyDescriptor>(rhs->properties.begin(), rhs->properties.end()))
- {
- return false;
- }
-
- if(set<DbEnvDescriptor>(lhs->dbEnvs.begin(), lhs->dbEnvs.end()) !=
- set<DbEnvDescriptor>(rhs->dbEnvs.begin(), rhs->dbEnvs.end()))
- {
- return false;
- }
-
- return true;
-}
-
-bool
-IceGrid::equal(const ServerDescriptorPtr& lhs, const ServerDescriptorPtr& rhs)
-{
- if(lhs->ice_id() != rhs->ice_id())
- {
- return false;
- }
-
- if(lhs->name != rhs->name)
- {
- return false;
- }
-
- if(lhs->comment != rhs->comment)
- {
- return false;
- }
-
- if(lhs->exe != rhs->exe)
- {
- return false;
- }
-
- if(lhs->pwd != rhs->pwd)
- {
- return false;
- }
-
- if(lhs->node != rhs->node)
- {
- return false;
- }
-
- if(lhs->application != rhs->application)
- {
- return false;
- }
-
- if(set<AdapterDescriptor>(lhs->adapters.begin(), lhs->adapters.end()) !=
- set<AdapterDescriptor>(rhs->adapters.begin(), rhs->adapters.end()))
- {
- return false;
- }
-
- if(set<PropertyDescriptor>(lhs->properties.begin(), lhs->properties.end()) !=
- set<PropertyDescriptor>(rhs->properties.begin(), rhs->properties.end()))
- {
- return false;
- }
-
- if(set<DbEnvDescriptor>(lhs->dbEnvs.begin(), lhs->dbEnvs.end()) !=
- set<DbEnvDescriptor>(rhs->dbEnvs.begin(), rhs->dbEnvs.end()))
- {
- return false;
- }
-
- if(set<string>(lhs->options.begin(), lhs->options.end()) != set<string>(rhs->options.begin(), rhs->options.end()))
- {
- return false;
- }
-
- if(set<string>(lhs->envs.begin(), lhs->envs.end()) != set<string>(rhs->envs.begin(), rhs->envs.end()))
- {
- return false;
- }
-
- //
- // TODO: perhaps if would be better to define an equal operation on the Slice class?
- //
- ServiceDescriptorSeq slhs;
- ServiceDescriptorSeq srhs;
-
- if(JavaServerDescriptorPtr::dynamicCast(lhs))
- {
- JavaServerDescriptorPtr jlhs = JavaServerDescriptorPtr::dynamicCast(lhs);
- JavaServerDescriptorPtr jrhs = JavaServerDescriptorPtr::dynamicCast(rhs);
-
- if(jlhs->className != jrhs->className)
- {
- return false;
- }
-
- if(set<string>(jlhs->jvmOptions.begin(), jlhs->jvmOptions.end()) !=
- set<string>(jrhs->jvmOptions.begin(), jrhs->jvmOptions.end()))
- {
- return false;
- }
-
- if(JavaIceBoxDescriptorPtr::dynamicCast(lhs))
- {
- JavaIceBoxDescriptorPtr ilhs = JavaIceBoxDescriptorPtr::dynamicCast(lhs);
- JavaIceBoxDescriptorPtr irhs = JavaIceBoxDescriptorPtr::dynamicCast(rhs);
-
- if(ilhs->endpoints != irhs->endpoints)
- {
- return false;
- }
-
- if(ilhs->services.size() != irhs->services.size())
- {
- return false;
- }
-
- slhs = ilhs->services;
- srhs = irhs->services;
- }
- }
- else if(CppIceBoxDescriptorPtr::dynamicCast(lhs))
- {
- CppIceBoxDescriptorPtr ilhs = CppIceBoxDescriptorPtr::dynamicCast(lhs);
- CppIceBoxDescriptorPtr irhs = CppIceBoxDescriptorPtr::dynamicCast(rhs);
-
- if(ilhs->endpoints != irhs->endpoints)
- {
- return false;
- }
-
- if(ilhs->services.size() != irhs->services.size())
- {
- return false;
- }
-
- slhs = ilhs->services;
- srhs = irhs->services;
- }
-
- if(!slhs.empty())
- {
- for(ServiceDescriptorSeq::const_iterator p = slhs.begin(); p != slhs.end(); ++p)
- {
- bool found = false;
- for(ServiceDescriptorSeq::const_iterator q = srhs.begin(); q != srhs.end(); ++q)
- {
- if((*p)->name == (*q)->name)
- {
- if(!equal(*p, *q))
- {
- return false;
- }
- found = true;
- break;
- }
- }
- if(!found)
- {
- return false;
- }
- }
- }
-
- return true;
-}
-
-string
-IceGrid::getVariable(const vector<map<string, string> >& variables, const string& name)
-{
- static const string empty;
- vector<map<string, string> >::const_reverse_iterator p = variables.rbegin();
- while(p != variables.rend())
- {
- map<string, string>::const_iterator q = p->find(name);
- if(q != p->end())
- {
- return q->second;
- }
- ++p;
- }
- return empty;
-}
-
-bool
-IceGrid::hasVariable(const vector<map<string, string> >& variables, const string& name)
-{
- vector<map<string, string> >::const_reverse_iterator p = variables.rbegin();
- while(p != variables.rend())
- {
- map<string, string>::const_iterator q = p->find(name);
- if(q != p->end())
- {
- return true;
- }
- ++p;
- }
- return false;
-}
-
-string
-IceGrid::substitute(const string& v, const vector<map<string, string> >& vars, bool ignore, vector<string>& missing)
-{
- string value(v);
- string::size_type beg = 0;
- string::size_type end = 0;
-
- while((beg = value.find("${", beg)) != string::npos)
- {
- if(beg > 0 && value[beg - 1] == '$')
- {
- string::size_type escape = beg - 1;
- while(escape > 0 && value[escape - 1] == '$')
- {
- --escape;
- }
-
- value.replace(escape, beg - escape, (beg - escape) / 2, '$');
- if((beg - escape) % 2)
- {
- ++beg;
- continue;
- }
- else
- {
- beg -= (beg - escape) / 2;
- }
- }
-
- end = value.find("}", beg);
-
- if(end == string::npos)
- {
- throw "malformed variable name in the '" + value + "' value";
- }
-
- string name = value.substr(beg + 2, end - beg - 2);
- if(!hasVariable(vars, name))
- {
- if(!ignore)
- {
- throw "unknown variable `" + name + "'";
- }
- else
- {
- missing.push_back(name);
- ++beg;
- continue;
- }
- }
- else
- {
- value.replace(beg, end - beg + 1, getVariable(vars, name));
- }
- }
-
- return value;
-}
-
-void
-IceGrid::instantiateComponentTemplate(const ComponentDescriptorPtr& desc, const vector<map<string, string> >& vars,
- vector<string>& missing)
-{
- Substitute substitute(vars, missing);
- substitute(desc->name);
- substitute(desc->comment);
- for(AdapterDescriptorSeq::iterator p = desc->adapters.begin(); p != desc->adapters.end(); ++p)
- {
- substitute(p->name);
- substitute(p->id);
- substitute(p->endpoints);
- for(ObjectDescriptorSeq::iterator q = p->objects.begin(); q != p->objects.end(); ++q)
- {
- //q->proxy = ; TODO!
- substitute(q->type);
- substitute(q->adapterId);
- }
- }
- for(PropertyDescriptorSeq::iterator p = desc->properties.begin(); p != desc->properties.end(); ++p)
- {
- substitute(p->name);
- substitute(p->value);
- }
- for(DbEnvDescriptorSeq::iterator p = desc->dbEnvs.begin(); p != desc->dbEnvs.end(); ++p)
- {
- substitute(p->name);
- substitute(p->dbHome);
- for(PropertyDescriptorSeq::iterator q = p->properties.begin(); q != p->properties.end(); ++q)
- {
- substitute(q->name);
- substitute(q->value);
- }
- }
-}
-
-ServerDescriptorPtr
-IceGrid::instantiateTemplate(const ServerDescriptorPtr& descriptor,
- const map<string, string>& vars,
- vector<string>& missing)
-{
- ServerDescriptorPtr desc = ServerDescriptorPtr::dynamicCast(descriptor->ice_clone());
- vector<map<string, string> > variables;
- variables.push_back(vars);
- instantiateComponentTemplate(desc, variables, missing);
- Substitute substitute(variables, missing);
- substitute(desc->exe);
- substitute(desc->pwd);
- for_each(desc->options.begin(), desc->options.end(), substitute);
- for_each(desc->envs.begin(), desc->envs.end(), substitute);
-// if(JavaServerDescriptorPtr::dynamicCast(desc))
-// {
-// desc->className = substitute(desc->className, variables, true, missing);
-// for_each(desc->jvmOptions.begin(), desc->jvmOptions.end(), Substitute(variables, missing));
-// }
- return desc;
-}
-
-ServiceDescriptorPtr
-IceGrid::instantiateTemplate(const ServiceDescriptorPtr& descriptor, const map<string, string>& vars,
- vector<string>& missing)
-{
- return descriptor;
-}
diff --git a/cpp/src/IceGrid/Util.h b/cpp/src/IceGrid/Util.h
index 38dc0ff45f2..67cadf1d6db 100644
--- a/cpp/src/IceGrid/Util.h
+++ b/cpp/src/IceGrid/Util.h
@@ -16,19 +16,6 @@
namespace IceGrid
{
-ServiceDescriptorSeq getServices(const ComponentDescriptorPtr&);
-PropertyDescriptor createProperty(const std::string&, const std::string&);
-bool equal(const ServerDescriptorPtr&, const ServerDescriptorPtr&);
-std::string getVariable(const std::vector<std::map<std::string, std::string> >&, const std::string&);
-bool hasVariable(const std::vector<std::map<std::string, std::string> >&, const std::string&);
-std::string substitute(const std::string&, const std::vector<std::map<std::string, std::string> >&, bool,
- std::vector<std::string>&);
-
-ServerDescriptorPtr instantiateTemplate(const ServerDescriptorPtr&, const std::map<std::string, std::string>&,
- std::vector<std::string>&);
-ServiceDescriptorPtr instantiateTemplate(const ServiceDescriptorPtr&, const std::map<std::string, std::string>&,
- std::vector<std::string>&);
-
template<typename T> std::insert_iterator<T>
inline set_inserter(T& container)
{
@@ -36,18 +23,27 @@ inline set_inserter(T& container)
}
template<class Function>
-struct ForEachComponent : std::unary_function<ServerDescriptorPtr&, void>
+struct ForEachComponent : std::unary_function<ComponentDescriptorPtr&, void>
{
ForEachComponent(Function f) : _function(f)
{
}
void
- operator()(const ServerDescriptorPtr& desc)
+ operator()(const InstanceDescriptor& instance)
{
- _function(desc);
- ServiceDescriptorSeq services = getServices(desc);
- for_each(services.begin(), services.end(), _function);
+ operator()(instance.descriptor);
+ }
+
+ void
+ operator()(const ComponentDescriptorPtr& descriptor)
+ {
+ _function(descriptor);
+ IceBoxDescriptorPtr iceBox = IceBoxDescriptorPtr::dynamicCast(descriptor);
+ if(iceBox)
+ {
+ for_each(iceBox->services.begin(), iceBox->services.end(), forEachComponent(_function));
+ }
}
Function _function;