diff options
author | Benoit Foucher <benoit@zeroc.com> | 2006-11-17 15:04:28 +0000 |
---|---|---|
committer | Benoit Foucher <benoit@zeroc.com> | 2006-11-17 15:04:28 +0000 |
commit | aacea143855a7a09e4ba53d09150ed71c7df2a67 (patch) | |
tree | b9b291727307d586d74e5c4204decdc02c77369d /cpp/src/IceGrid/AdminSessionI.cpp | |
parent | Fixed depends Some Makefile cleanup (diff) | |
download | ice-aacea143855a7a09e4ba53d09150ed71c7df2a67.tar.bz2 ice-aacea143855a7a09e4ba53d09150ed71c7df2a67.tar.xz ice-aacea143855a7a09e4ba53d09150ed71c7df2a67.zip |
Added support for viewing stderr/stdout files from nodes, registries,
servers.
Diffstat (limited to 'cpp/src/IceGrid/AdminSessionI.cpp')
-rw-r--r-- | cpp/src/IceGrid/AdminSessionI.cpp | 165 |
1 files changed, 165 insertions, 0 deletions
diff --git a/cpp/src/IceGrid/AdminSessionI.cpp b/cpp/src/IceGrid/AdminSessionI.cpp index de31ff90996..5fe3f014d5f 100644 --- a/cpp/src/IceGrid/AdminSessionI.cpp +++ b/cpp/src/IceGrid/AdminSessionI.cpp @@ -19,6 +19,35 @@ using namespace std; using namespace IceGrid; +FileIteratorI::FileIteratorI(const AdminSessionIPtr& session, const FileReaderPrx& reader, const string& filename) : + _session(session), + _reader(reader), + _filename(filename), + _offset(0) +{ +} + +Ice::StringSeq +FileIteratorI::read(int nlines, const Ice::Current& current) +{ + try + { + return _reader->readLines(_filename, _offset, nlines, _offset); + } + catch(const Ice::LocalException& ex) + { + ostringstream os; + os << ex; + throw FileNotAvailableException(os.str()); + } +} + +void +FileIteratorI::destroy(const Ice::Current& current) +{ + _session->removeFileIterator(current.id, current); +} + AdminSessionI::AdminSessionI(const string& id, const DatabasePtr& db, int timeout, const string& replicaName) : BaseSessionI(id, "admin", db), _timeout(timeout), @@ -163,6 +192,74 @@ AdminSessionI::getReplicaName(const Ice::Current& current) const return _replicaName; } +FileIteratorPrx +AdminSessionI::openServerStdOut(const std::string& id, const Ice::Current& current) +{ + return addFileIterator(_database->getServer(id), "stdout", current); +} + +FileIteratorPrx +AdminSessionI::openServerStdErr(const std::string& id, const Ice::Current& current) +{ + return addFileIterator(_database->getServer(id), "stderr", current); +} + +FileIteratorPrx +AdminSessionI::openNodeStdOut(const std::string& name, const Ice::Current& current) +{ + return addFileIterator(_database->getNode(name), "stdout", current); +} + +FileIteratorPrx +AdminSessionI::openNodeStdErr(const std::string& name, const Ice::Current& current) +{ + return addFileIterator(_database->getNode(name), "stderr", current); +} + +FileIteratorPrx +AdminSessionI::openRegistryStdOut(const std::string& name, const Ice::Current& current) +{ + FileReaderPrx reader; + if(name == _replicaName) + { + Ice::Identity internalRegistryId; + internalRegistryId.category = _database->getInstanceName(); + internalRegistryId.name = "InternalRegistry-" + _replicaName; + + Ice::CommunicatorPtr communicator = current.adapter->getCommunicator(); + string proxyStr = communicator->identityToString(internalRegistryId); + reader = FileReaderPrx::uncheckedCast(communicator->stringToProxy(proxyStr)); + } + else + { + reader = _database->getReplica(name); + } + + return addFileIterator(reader, "stdout", current); +} + +FileIteratorPrx +AdminSessionI::openRegistryStdErr(const std::string& name, const Ice::Current& current) +{ + FileReaderPrx reader; + if(name == _replicaName) + { + Ice::Identity internalRegistryId; + internalRegistryId.category = _database->getInstanceName(); + internalRegistryId.name = "InternalRegistry-" + _replicaName; + + Ice::CommunicatorPtr communicator = current.adapter->getCommunicator(); + string proxyStr = communicator->identityToString(internalRegistryId); + reader = FileReaderPrx::uncheckedCast(communicator->stringToProxy(proxyStr)); + } + else + { + reader = _database->getReplica(name); + } + + return addFileIterator(reader, "stderr", current); +} + void AdminSessionI::destroy(const Ice::Current& current) { @@ -190,6 +287,28 @@ AdminSessionI::destroy(const Ice::Current& current) } // + // Unregister the iterators from the session servant locator or + // object adapter. + // + for(set<Ice::Identity>::const_iterator p = _iterators.begin(); p != _iterators.end(); ++p) + { + if(_servantLocator) + { + _servantLocator->remove(*p); + } + else if(current.adapter) + { + try + { + current.adapter->remove(*p); + } + catch(const Ice::LocalException&) + { + } + } + } + + // // Unsubscribe from the topics. // if(current.adapter) // Not shutting down @@ -335,3 +454,49 @@ AdminSessionI::toProxy(const Ice::Identity& id, const Ice::ConnectionPtr& connec { return id.name.empty() ? Ice::ObjectPrx() : connection->createProxy(id); } + +FileIteratorPrx +AdminSessionI::addFileIterator(const FileReaderPrx& reader, const string& filename, const Ice::Current& current) +{ + Lock sync(*this); + if(_destroyed) + { + Ice::ObjectNotExistException ex(__FILE__, __LINE__); + ex.id = current.id; + throw ex; + } + + Ice::ObjectPrx obj; + Ice::ObjectPtr servant = new FileIteratorI(this, reader, filename); + if(_servantLocator) + { + obj = _servantLocator->add(servant, current.con); + } + else + { + obj = current.adapter->addWithUUID(servant); + } + _iterators.insert(obj->ice_getIdentity()); + return FileIteratorPrx::uncheckedCast(obj); +} + +void +AdminSessionI::removeFileIterator(const Ice::Identity& id, const Ice::Current& current) +{ + Lock sync(*this); + if(_servantLocator) + { + _servantLocator->remove(id); + } + else + { + try + { + current.adapter->remove(id); + } + catch(const Ice::LocalException&) + { + } + } + _iterators.erase(id); +} |