summaryrefslogtreecommitdiff
path: root/cpp/src
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/src')
-rw-r--r--cpp/src/IceGrid/Database.cpp4
-rw-r--r--cpp/src/IceGrid/DescriptorHelper.cpp166
-rw-r--r--cpp/src/IceGrid/DescriptorHelper.h1
-rw-r--r--cpp/src/IceGrid/IceGridObserver.cpp6
-rw-r--r--cpp/src/IceGrid/NodeI.cpp4
-rw-r--r--cpp/src/IceGrid/Parser.cpp157
-rw-r--r--cpp/src/IceGrid/ServerI.cpp6
-rw-r--r--cpp/src/IceGrid/Topics.cpp18
-rw-r--r--cpp/src/IceGrid/Topics.h1
9 files changed, 218 insertions, 145 deletions
diff --git a/cpp/src/IceGrid/Database.cpp b/cpp/src/IceGrid/Database.cpp
index 75b9a7eab14..16f5e868aef 100644
--- a/cpp/src/IceGrid/Database.cpp
+++ b/cpp/src/IceGrid/Database.cpp
@@ -448,6 +448,7 @@ Database::syncApplicationDescriptor(ObserverSessionI* session, const Application
{
ServerEntrySeq entries;
int serial;
+ ApplicationUpdateDescriptor update;
{
Lock sync(*this);
checkSessionLock(session);
@@ -465,6 +466,7 @@ Database::syncApplicationDescriptor(ObserverSessionI* session, const Application
{
ApplicationDescriptorHelper helper(_communicator, newDesc);
helper.instantiate();
+ update = helper.diff(p->second);
descriptor = helper.getDescriptor();
}
catch(const string& msg)
@@ -485,7 +487,7 @@ Database::syncApplicationDescriptor(ObserverSessionI* session, const Application
//
// Notify the observers.
//
- _registryObserver->applicationSynced(serial, newDesc);
+ _registryObserver->applicationUpdated(serial, update);
if(_traceLevels->application > 0)
{
diff --git a/cpp/src/IceGrid/DescriptorHelper.cpp b/cpp/src/IceGrid/DescriptorHelper.cpp
index fe972055156..65dfa8afbba 100644
--- a/cpp/src/IceGrid/DescriptorHelper.cpp
+++ b/cpp/src/IceGrid/DescriptorHelper.cpp
@@ -743,6 +743,171 @@ ApplicationDescriptorHelper::update(const ApplicationUpdateDescriptor& update)
return newUpdate;
}
+ApplicationUpdateDescriptor
+ApplicationDescriptorHelper::diff(const ApplicationDescriptorPtr& orig)
+{
+ ApplicationUpdateDescriptor update;
+ update.comment = _descriptor->comment != orig->comment ? new BoxedComment(_descriptor->comment) : BoxedCommentPtr();
+ update.targets = _descriptor->targets != orig->targets ? new BoxedTargets(_descriptor->targets) : BoxedTargetsPtr();
+
+ update.variables = _descriptor->variables;
+ map<string, string>::iterator p = update.variables.begin();
+ while(p != update.variables.end())
+ {
+ map<string, string>::const_iterator q = orig->variables.find(p->first);
+ if(q != orig->variables.end() && q->second == p->second)
+ {
+ map<string, string>::iterator tmp = p++;
+ update.variables.erase(tmp);
+ }
+ else
+ {
+ ++p;
+ }
+ }
+ for(map<string, string>::const_iterator q = orig->variables.begin(); q != orig->variables.end(); ++q)
+ {
+ if(_descriptor->variables.find(q->first) == _descriptor->variables.end())
+ {
+ update.removeVariables.push_back(q->first);
+ }
+ }
+
+ update.serverTemplates = _descriptor->serverTemplates;
+ TemplateDescriptorDict::iterator t = update.serverTemplates.begin();
+ while(t != update.serverTemplates.end())
+ {
+ TemplateDescriptorDict::const_iterator q = orig->serverTemplates.find(t->first);
+ if(q != orig->serverTemplates.end() &&
+ q->second.parameters == t->second.parameters &&
+ ServerDescriptorHelper(*this, ServerDescriptorPtr::dynamicCast(q->second.descriptor)) ==
+ ServerDescriptorHelper(*this, ServerDescriptorPtr::dynamicCast(t->second.descriptor)))
+ {
+ TemplateDescriptorDict::iterator tmp = t++;
+ update.serverTemplates.erase(tmp);
+ }
+ else
+ {
+ ++t;
+ }
+ }
+ for(t = orig->serverTemplates.begin(); t != orig->serverTemplates.end(); ++t)
+ {
+ if(_descriptor->serverTemplates.find(t->first) == _descriptor->serverTemplates.end())
+ {
+ update.removeServerTemplates.push_back(t->first);
+ }
+ }
+
+ update.serviceTemplates = _descriptor->serviceTemplates;
+ t = update.serviceTemplates.begin();
+ while(t != update.serviceTemplates.end())
+ {
+ TemplateDescriptorDict::const_iterator q = orig->serviceTemplates.find(t->first);
+ if(q != orig->serviceTemplates.end() &&
+ q->second.parameters == t->second.parameters &&
+ ServiceDescriptorHelper(*this, ServiceDescriptorPtr::dynamicCast(q->second.descriptor)) ==
+ ServiceDescriptorHelper(*this, ServiceDescriptorPtr::dynamicCast(t->second.descriptor)))
+ {
+ TemplateDescriptorDict::iterator tmp = t++;
+ update.serviceTemplates.erase(tmp);
+ }
+ else
+ {
+ ++t;
+ }
+ }
+ for(t = orig->serviceTemplates.begin(); t != orig->serviceTemplates.end(); ++t)
+ {
+ if(_descriptor->serviceTemplates.find(t->first) == _descriptor->serviceTemplates.end())
+ {
+ update.removeServiceTemplates.push_back(t->first);
+ }
+ }
+
+ update.nodes = _descriptor->nodes;
+ NodeDescriptorSeq::iterator n = update.nodes.begin();
+ while(n != update.nodes.end())
+ {
+ NodeDescriptorSeq::const_iterator q;
+ for(q = orig->nodes.begin(); q != orig->nodes.end(); ++q)
+ {
+ if(n->name == q->name)
+ {
+ break;
+ }
+ }
+ if(q != orig->nodes.end() && *n == *q)
+ {
+ n = update.nodes.erase(n);
+ }
+ else
+ {
+ ++n;
+ }
+ }
+ for(n = orig->nodes.begin(); n != orig->nodes.end(); ++n)
+ {
+ bool found = false;
+ for(NodeDescriptorSeq::const_iterator q = orig->nodes.begin(); q != orig->nodes.end(); ++q)
+ {
+ if(n->name == q->name)
+ {
+ found = true;
+ break;
+ }
+ }
+ if(!found)
+ {
+ update.removeNodes.push_back(n->name);
+ }
+ }
+
+ update.servers = _descriptor->servers;
+ ServerInstanceDescriptorSeq::iterator i = update.servers.begin();
+ while(i != update.servers.end())
+ {
+ ServerInstanceDescriptorSeq::const_iterator q;
+ for(q = orig->servers.begin(); q != orig->servers.end(); ++q)
+ {
+ if(i->descriptor->name == q->descriptor->name)
+ {
+ break;
+ }
+ }
+
+ if(q != orig->servers.end() &&
+ i->_cpp_template == q->_cpp_template &&
+ i->parameterValues == q->parameterValues &&
+ i->targets == q->targets &&
+ ServerDescriptorHelper(*this, q->descriptor) == ServerDescriptorHelper(*this, i->descriptor))
+ {
+ i = update.servers.erase(i);
+ }
+ else
+ {
+ ++i;
+ }
+ }
+ for(i = orig->servers.begin(); i != orig->servers.end(); ++i)
+ {
+ ServerInstanceDescriptorSeq::const_iterator q;
+ for(q = _descriptor->servers.begin(); q != _descriptor->servers.end(); ++q)
+ {
+ if(i->descriptor->name == q->descriptor->name)
+ {
+ break;
+ }
+ }
+ if(q == _descriptor->servers.end())
+ {
+ update.removeServers.push_back(i->descriptor->name);
+ }
+ }
+
+ return update;
+}
+
void
ApplicationDescriptorHelper::addServerInstance(const string& tmpl,
const string& node,
@@ -1339,7 +1504,6 @@ ServerDescriptorHelper::instantiateImpl(const ServerDescriptorPtr& desc, set<str
IceBoxDescriptorPtr iceBox = IceBoxDescriptorPtr::dynamicCast(desc);
if(iceBox)
{
- ServiceDescriptorDict newServices;
for(ServiceInstanceDescriptorSeq::iterator p = iceBox->services.begin(); p != iceBox->services.end(); ++p)
{
if(p->_cpp_template.empty())
diff --git a/cpp/src/IceGrid/DescriptorHelper.h b/cpp/src/IceGrid/DescriptorHelper.h
index 30767621e92..824a9ce0d61 100644
--- a/cpp/src/IceGrid/DescriptorHelper.h
+++ b/cpp/src/IceGrid/DescriptorHelper.h
@@ -146,6 +146,7 @@ public:
std::auto_ptr<ServiceDescriptorHelper> addServiceTemplate(const std::string&, const IceXML::Attributes&);
ApplicationUpdateDescriptor update(const ApplicationUpdateDescriptor&);
+ ApplicationUpdateDescriptor diff(const ApplicationDescriptorPtr&);
void addServerInstance(const std::string&, const std::string&, const std::map<std::string, std::string>&);
void instantiate();
diff --git a/cpp/src/IceGrid/IceGridObserver.cpp b/cpp/src/IceGrid/IceGridObserver.cpp
index 2cbb659c054..b11109efaf3 100644
--- a/cpp/src/IceGrid/IceGridObserver.cpp
+++ b/cpp/src/IceGrid/IceGridObserver.cpp
@@ -97,12 +97,6 @@ public:
{
cout << "application `" << desc.name << "' updated (serial = " << serial << ")" << endl;
}
-
- virtual void
- applicationSynced(int serial, const ApplicationDescriptorPtr& app, const Ice::Current&)
- {
- cout << "application `" << app->name << "' synced (serial = " << serial << ")" << endl;
- }
};
class NodeObserverI : public NodeObserver
diff --git a/cpp/src/IceGrid/NodeI.cpp b/cpp/src/IceGrid/NodeI.cpp
index 575c974202a..90357e98f58 100644
--- a/cpp/src/IceGrid/NodeI.cpp
+++ b/cpp/src/IceGrid/NodeI.cpp
@@ -436,6 +436,10 @@ NodeI::initObserver(const Ice::StringSeq& servers)
server.name = *p;
server.pid = proxy->getPid();
server.state = proxy->getState();
+ if(server.state == Inactive)
+ {
+ continue;
+ }
serverInfos.push_back(server);
StringAdapterPrxDict adapters = proxy->getAdapters();
diff --git a/cpp/src/IceGrid/Parser.cpp b/cpp/src/IceGrid/Parser.cpp
index d0f23c31f9f..90ff363e2ee 100644
--- a/cpp/src/IceGrid/Parser.cpp
+++ b/cpp/src/IceGrid/Parser.cpp
@@ -693,157 +693,84 @@ Parser::diffApplication(const list<string>& args)
out << sb;
ApplicationDescriptorHelper newAppHelper(_communicator, newApp);
- ApplicationDescriptorHelper origAppHelper(_communicator, origApp);
-
- if(!origApp->serverTemplates.empty() || !newApp->serverTemplates.empty())
+ ApplicationUpdateDescriptor update = newAppHelper.diff(origApp);
+ if(!update.serverTemplates.empty() || !update.removeServerTemplates.empty())
{
out << nl << "server templates";
out << sb;
-
- set<string> oldTmpls;
- set<string> newTmpls;
- for(TemplateDescriptorDict::const_iterator p = origApp->serverTemplates.begin();
- p != origApp->serverTemplates.end(); ++p)
- {
- oldTmpls.insert(p->first);
- }
- for(TemplateDescriptorDict::const_iterator p = newApp->serverTemplates.begin();
- p != newApp->serverTemplates.end(); ++p)
+ TemplateDescriptorDict::const_iterator p;
+ for(p = update.serverTemplates.begin(); p != update.serverTemplates.end(); ++p)
{
- newTmpls.insert(p->first);
- }
-
- set<string> added, removed, updated;
- set_difference(newTmpls.begin(), newTmpls.end(), oldTmpls.begin(), oldTmpls.end(), set_inserter(added));
- set_difference(oldTmpls.begin(), oldTmpls.end(), newTmpls.begin(), newTmpls.end(), set_inserter(removed));
-
- for(TemplateDescriptorDict::const_iterator p = newApp->serverTemplates.begin();
- p != newApp->serverTemplates.end(); ++p)
- {
- ServerDescriptorPtr desc = ServerDescriptorPtr::dynamicCast(p->second.descriptor);
- TemplateDescriptorDict::const_iterator q = origApp->serverTemplates.find(p->first);
- if(q != origApp->serverTemplates.end())
+ if(newApp->serverTemplates.find(p->first) == newApp->serverTemplates.end())
{
- ServerDescriptorPtr orig = ServerDescriptorPtr::dynamicCast(q->second.descriptor);
- if(ServerDescriptorHelper(newAppHelper, desc) != ServerDescriptorHelper(origAppHelper, orig))
- {
- updated.insert(p->first);
- }
+ out << nl << "server template `" << p->first << "' added";
+ }
+ else
+ {
+ out << nl << "server template `" << p->first << "' updated";
}
}
-
- for(set<string>::const_iterator p = added.begin(); p != added.end(); ++p)
- {
- out << nl << "server template `" << *p << "' added";
- }
- for(set<string>::const_iterator p = updated.begin(); p != updated.end(); ++p)
- {
- out << nl << "server template `" << *p << "' updated";
- }
- for(set<string>::const_iterator p = removed.begin(); p != removed.end(); ++p)
+ Ice::StringSeq::const_iterator q;
+ for(q = update.removeServerTemplates.begin(); q != update.removeServerTemplates.end(); ++q)
{
- out << nl << "server template `" << *p << "' removed";
+ out << nl << "server template `" << *q << "' removed";
}
out << eb;
}
- if(!origApp->serviceTemplates.empty() || !newApp->serviceTemplates.empty())
+ if(!update.serviceTemplates.empty() || !update.removeServiceTemplates.empty())
{
out << nl << "service templates";
out << sb;
-
- set<string> oldTmpls;
- set<string> newTmpls;
- for(TemplateDescriptorDict::const_iterator p = origApp->serviceTemplates.begin();
- p != origApp->serviceTemplates.end(); ++p)
- {
- oldTmpls.insert(p->first);
- }
- for(TemplateDescriptorDict::const_iterator p = newApp->serviceTemplates.begin();
- p != newApp->serviceTemplates.end(); ++p)
- {
- newTmpls.insert(p->first);
- }
-
- set<string> added, removed, updated;
- set_difference(newTmpls.begin(), newTmpls.end(), oldTmpls.begin(), oldTmpls.end(), set_inserter(added));
- set_difference(oldTmpls.begin(), oldTmpls.end(), newTmpls.begin(), newTmpls.end(), set_inserter(removed));
-
- for(TemplateDescriptorDict::const_iterator p = newApp->serviceTemplates.begin();
- p != newApp->serviceTemplates.end(); ++p)
+ TemplateDescriptorDict::const_iterator p;
+ for(p = update.serviceTemplates.begin(); p != update.serviceTemplates.end(); ++p)
{
- ServiceDescriptorPtr desc = ServiceDescriptorPtr::dynamicCast(p->second.descriptor);
- TemplateDescriptorDict::const_iterator q = origApp->serviceTemplates.find(p->first);
- if(q != origApp->serviceTemplates.end())
+ if(origApp->serviceTemplates.find(p->first) == origApp->serviceTemplates.end())
{
- ServiceDescriptorPtr orig = ServiceDescriptorPtr::dynamicCast(q->second.descriptor);
- if(ServiceDescriptorHelper(newAppHelper, desc) != ServiceDescriptorHelper(origAppHelper, orig))
- {
- updated.insert(p->first);
- }
+ out << nl << "service template `" << p->first << "' added";
+ }
+ else
+ {
+ out << nl << "service template `" << p->first << "' updated";
}
}
-
- for(set<string>::const_iterator p = added.begin(); p != added.end(); ++p)
- {
- out << nl << "service template `" << *p << "' added";
- }
- for(set<string>::const_iterator p = updated.begin(); p != updated.end(); ++p)
- {
- out << nl << "service template `" << *p << "' updated";
- }
- for(set<string>::const_iterator p = removed.begin(); p != removed.end(); ++p)
+ Ice::StringSeq::const_iterator q;
+ for(q = update.removeServiceTemplates.begin(); q != update.removeServiceTemplates.end(); ++q)
{
- out << nl << "service template `" << *p << "' removed";
+ out << nl << "service template `" << *q << "' removed";
}
-
out << eb;
}
- if(!origApp->servers.empty() || !newApp->servers.empty())
+ if(!update.servers.empty() || !update.removeServers.empty())
{
out << nl << "servers";
out << sb;
- set<string> oldSvrs;
- set<string> newSvrs;
- for_each(origApp->servers.begin(), origApp->servers.end(), AddServerName(oldSvrs));
- for_each(newApp->servers.begin(), newApp->servers.end(), AddServerName(newSvrs));
-
- set<string> added, removed, updated;
- set_difference(newSvrs.begin(), newSvrs.end(), oldSvrs.begin(), oldSvrs.end(), set_inserter(added));
- set_difference(oldSvrs.begin(), oldSvrs.end(), newSvrs.begin(), newSvrs.end(), set_inserter(removed));
-
- for(ServerInstanceDescriptorSeq::const_iterator p = newApp->servers.begin(); p != newApp->servers.end(); ++p)
+ ServerInstanceDescriptorSeq::const_iterator p;
+ for(p = update.servers.begin(); p != update.servers.end(); ++p)
{
- ServerDescriptorPtr desc = ServerDescriptorPtr::dynamicCast(p->descriptor);
- for(ServerInstanceDescriptorSeq::const_iterator q = origApp->servers.begin();
- q != origApp->servers.end(); ++q)
+ ServerInstanceDescriptorSeq::const_iterator q;
+ for(q = origApp->servers.begin(); q != origApp->servers.end(); ++q)
{
- if(desc->name == q->descriptor->name)
+ if(p->descriptor->name == q->descriptor->name)
{
- ServerDescriptorPtr orig = q->descriptor;
- if(q->node != p->node ||
- ServerDescriptorHelper(newAppHelper, desc) != ServerDescriptorHelper(origAppHelper, orig))
- {
- updated.insert(orig->name);
- }
break;
}
}
+ if(q == origApp->servers.end())
+ {
+ out << nl << "server `" << p->descriptor->name << "' added";
+ }
+ else
+ {
+ out << nl << "server `" << p->descriptor->name << "' updated";
+ }
}
-
- for(set<string>::const_iterator p = added.begin(); p != added.end(); ++p)
- {
- out << nl << "server `" << *p << "' added";
- }
- for(set<string>::const_iterator p = updated.begin(); p != updated.end(); ++p)
- {
- out << nl << "server `" << *p << "' updated";
- }
- for(set<string>::const_iterator p = removed.begin(); p != removed.end(); ++p)
+ Ice::StringSeq::const_iterator q;
+ for(q = update.removeServers.begin(); q != update.removeServers.end(); ++q)
{
- out << nl << "server `" << *p << "' removed";
+ out << nl << "server `" << *q << "' removed";
}
out << eb;
}
diff --git a/cpp/src/IceGrid/ServerI.cpp b/cpp/src/IceGrid/ServerI.cpp
index d4cb62ab9bf..2fddb91959f 100644
--- a/cpp/src/IceGrid/ServerI.cpp
+++ b/cpp/src/IceGrid/ServerI.cpp
@@ -579,10 +579,10 @@ ServerI::setStateNoSync(ServerState st, const Ice::Current& current)
ServerDynamicInfo info;
info.name = _name;
info.state = st;
+
//
- // NOTE: this must be done only for the active state.
- // Otherwise, we could get a deadlock since getPid()
- // will lock the activator and since this method might
+ // NOTE: this must be done only for the active state. Otherwise, we could get a
+ // deadlock since getPid() will lock the activator and since this method might
// be called from the activator locked.
//
info.pid = st == Active ? getPid(current) : 0;
diff --git a/cpp/src/IceGrid/Topics.cpp b/cpp/src/IceGrid/Topics.cpp
index 1d4372cb370..5c591bf64bb 100644
--- a/cpp/src/IceGrid/Topics.cpp
+++ b/cpp/src/IceGrid/Topics.cpp
@@ -263,24 +263,6 @@ RegistryObserverTopic::applicationRemoved(int serial, const string& name, const
}
void
-RegistryObserverTopic::applicationSynced(int serial, const ApplicationDescriptorPtr& desc, const Ice::Current&)
-{
- Lock sync(*this);
-
- updateSerial(serial);
- for(ApplicationDescriptorSeq::iterator p = _applications.begin(); p != _applications.end(); ++p)
- {
- if((*p)->name == desc->name)
- {
- *p = desc;
- break;
- }
- }
-
- _publisher->applicationSynced(serial, desc);
-}
-
-void
RegistryObserverTopic::applicationUpdated(int serial, const ApplicationUpdateDescriptor& desc, const Ice::Current& c)
{
Lock sync(*this);
diff --git a/cpp/src/IceGrid/Topics.h b/cpp/src/IceGrid/Topics.h
index fb18519e579..247dc930fc1 100644
--- a/cpp/src/IceGrid/Topics.h
+++ b/cpp/src/IceGrid/Topics.h
@@ -55,7 +55,6 @@ public:
virtual void applicationAdded(int, const ApplicationDescriptorPtr&, const Ice::Current&);
virtual void applicationRemoved(int, const std::string&, const Ice::Current&);
- virtual void applicationSynced(int, const ApplicationDescriptorPtr&, const Ice::Current&);
virtual void applicationUpdated(int, const ApplicationUpdateDescriptor&, const Ice::Current&);
void subscribe(const RegistryObserverPrx&, int = -1);