diff options
Diffstat (limited to 'cpp/src/IceGrid/ServerCache.cpp')
-rw-r--r-- | cpp/src/IceGrid/ServerCache.cpp | 126 |
1 files changed, 118 insertions, 8 deletions
diff --git a/cpp/src/IceGrid/ServerCache.cpp b/cpp/src/IceGrid/ServerCache.cpp index 7d0ceeb69cf..dd94ec2feda 100644 --- a/cpp/src/IceGrid/ServerCache.cpp +++ b/cpp/src/IceGrid/ServerCache.cpp @@ -59,6 +59,45 @@ namespace IceGrid ServerCache& _serverCache; const ServerEntryPtr _entry; }; + + +} + +CheckUpdateResult::CheckUpdateResult(const string& server, + const string& node, + bool noRestart, + const Ice::AsyncResultPtr& result) : + _server(server), _node(node), _noRestart(noRestart), _result(result) +{ +} + +bool +CheckUpdateResult::getResult() +{ + try + { + return ServerPrx::uncheckedCast(_result->getProxy())->end_checkUpdate(_result); + } + catch(const DeploymentException& ex) + { + ostringstream os; + os << "check for server `" << _server << "' update failed: " << ex.reason; + throw DeploymentException(os.str()); + } + catch(const Ice::OperationNotExistException&) + { + if(_noRestart) + { + throw DeploymentException("server `" + _server + "' doesn't support check for updates"); + } + return false; + } + catch(const Ice::Exception& ex) + { + ostringstream os; + os << ex; + throw NodeUnreachableException(_node, os.str()); + } } ServerCache::ServerCache(const Ice::CommunicatorPtr& communicator, @@ -77,7 +116,7 @@ ServerCache::ServerCache(const Ice::CommunicatorPtr& communicator, } ServerEntryPtr -ServerCache::add(const ServerInfo& info) +ServerCache::add(const ServerInfo& info, bool noRestart) { Lock sync(*this); @@ -87,7 +126,7 @@ ServerCache::add(const ServerInfo& info) entry = new ServerEntry(*this, info.descriptor->id); addImpl(info.descriptor->id, entry); } - entry->update(info); + entry->update(info, noRestart); _nodeCache.get(info.node, true)->addServer(entry); forEachCommunicator(AddCommunicator(*this, entry, info.application))(info.descriptor); @@ -209,7 +248,8 @@ ServerEntry::ServerEntry(ServerCache& cache, const string& id) : _activationTimeout(-1), _deactivationTimeout(-1), _synchronizing(false), - _updated(false) + _updated(false), + _noRestart(false) { } @@ -271,7 +311,7 @@ ServerEntry::addSyncCallback(const SynchronizationCallbackPtr& callback) } void -ServerEntry::update(const ServerInfo& info) +ServerEntry::update(const ServerInfo& info, bool noRestart) { Lock sync(*this); @@ -293,6 +333,7 @@ ServerEntry::update(const ServerInfo& info) } _load = descriptor; + _noRestart = noRestart; _loaded.reset(0); _allocatable = info.descriptor->allocatable; if(info.descriptor->activation == "session") @@ -526,6 +567,7 @@ ServerEntry::syncImpl() SessionIPtr session; ServerInfo destroy; int timeout = -1; + bool noRestart; { Lock sync(*this); @@ -552,6 +594,7 @@ ServerEntry::syncImpl() load = *_load; session = _session; timeout = _deactivationTimeout; // loadServer might block to deactivate the previous server. + noRestart = _noRestart; } else { @@ -576,7 +619,7 @@ ServerEntry::syncImpl() { try { - _cache.getNodeCache().get(load.node)->loadServer(this, load, session, timeout); + _cache.getNodeCache().get(load.node)->loadServer(this, load, session, timeout, noRestart); } catch(NodeNotExistException&) { @@ -690,6 +733,7 @@ ServerEntry::loadCallback(const ServerPrx& proxy, const AdapterPrxDict& adpts, i ServerInfo destroy; int timeout = -1; bool synced = false; + bool noRestart; { Lock sync(*this); @@ -724,6 +768,7 @@ ServerEntry::loadCallback(const ServerPrx& proxy, const AdapterPrxDict& adpts, i else if(_load.get()) { load = *_load; + noRestart = _noRestart; session = _session; timeout = _deactivationTimeout; // loadServer might block to deactivate the previous server. } @@ -752,7 +797,7 @@ ServerEntry::loadCallback(const ServerPrx& proxy, const AdapterPrxDict& adpts, i { try { - _cache.getNodeCache().get(load.node)->loadServer(this, load, session, timeout); + _cache.getNodeCache().get(load.node)->loadServer(this, load, session, timeout, noRestart); } catch(NodeNotExistException&) { @@ -765,6 +810,7 @@ void ServerEntry::destroyCallback() { ServerInfo load; + bool noRestart; SessionIPtr session; { @@ -785,6 +831,7 @@ ServerEntry::destroyCallback() { _updated = false; load = *_load; + noRestart = _noRestart; session = _session; } } @@ -793,7 +840,7 @@ ServerEntry::destroyCallback() { try { - _cache.getNodeCache().get(load.node)->loadServer(this, load, session, -1); + _cache.getNodeCache().get(load.node)->loadServer(this, load, session, -1, noRestart); } catch(NodeNotExistException&) { @@ -812,6 +859,7 @@ ServerEntry::exception(const Ice::Exception& ex) { ServerInfo load; SessionIPtr session; + bool noRestart; bool remove = false; int timeout = -1; @@ -834,6 +882,7 @@ ServerEntry::exception(const Ice::Exception& ex) _destroy.reset(0); _updated = false; load = *_load.get(); + noRestart = _noRestart; session = _session; timeout = _deactivationTimeout; // loadServer might block to deactivate the previous server. } @@ -843,7 +892,7 @@ ServerEntry::exception(const Ice::Exception& ex) { try { - _cache.getNodeCache().get(load.node)->loadServer(this, load, session, timeout); + _cache.getNodeCache().get(load.node)->loadServer(this, load, session, timeout, noRestart); } catch(NodeNotExistException&) { @@ -874,6 +923,67 @@ ServerEntry::canRemove() return !_loaded.get() && !_load.get() && !_destroy.get(); } +CheckUpdateResultPtr +ServerEntry::checkUpdate(const ServerInfo& info, bool noRestart) +{ + SessionIPtr session; + { + Lock sync(*this); + if(!_loaded.get() && !_load.get()) + { + throw ServerNotExistException(); + } + + ServerInfo oldInfo = _loaded.get() ? *_loaded : *_load; + if(noRestart && info.node != oldInfo.node) + { + throw DeploymentException("server `" + _id + "' is moving to another node"); + } + + session = _session; + } + + NodeEntryPtr node; + try + { + node = _cache.getNodeCache().get(info.node); + } + catch(NodeNotExistException&) + { + throw NodeUnreachableException(info.node, "node is not active"); + } + + ServerPrx server; + try + { + server = getProxy(true, 5); + } + catch(const SynchronizationException&) + { + ostringstream os; + os << "check for server `" << _id << "' update failed:"; + os << "timeout while waiting for the server to be loaded on the node"; + throw DeploymentException(os.str()); + } + catch(const DeploymentException&) + { + if(noRestart) + { + // If the server can't be loaded and no restart is required, we throw + // to indicate that the server update can't be checked. + throw; + } + else + { + // Otherwise, we do as if the update is valid. + return 0; + } + } + + InternalServerDescriptorPtr desc = node->getInternalServerDescriptor(info, session); + return new CheckUpdateResult(_id, info.node, noRestart, server->begin_checkUpdate(desc, noRestart)); + +} void ServerEntry::allocated(const SessionIPtr& session) |