Mercurial > hg > orthanc-transfers
changeset 5:5e6de82bb10f
use of user properties instead of BidirectionalPeers option
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 18 Sep 2018 15:39:02 +0200 |
parents | 1ed03945c057 |
children | 6f504d862494 |
files | Framework/HttpQueries/DetectTransferPlugin.cpp Framework/HttpQueries/DetectTransferPlugin.h Framework/HttpQueries/HttpQueriesQueue.cpp Framework/PullMode/PullJob.cpp Framework/TransferToolbox.h Plugin/Plugin.cpp Plugin/PluginContext.cpp Plugin/PluginContext.h |
diffstat | 8 files changed, 36 insertions(+), 87 deletions(-) [+] |
line wrap: on
line diff
--- a/Framework/HttpQueries/DetectTransferPlugin.cpp Mon Sep 17 14:42:57 2018 +0200 +++ b/Framework/HttpQueries/DetectTransferPlugin.cpp Tue Sep 18 15:39:02 2018 +0200 @@ -29,13 +29,13 @@ namespace OrthancPlugins { - DetectTransferPlugin::DetectTransferPlugin(Peers& target, + DetectTransferPlugin::DetectTransferPlugin(Result& result, const std::string& peer) : - target_(target), + result_(result), peer_(peer), uri_(URI_PLUGINS) { - target_[peer_] = PeerCapabilities_Disabled; + result_[peer_] = false; } @@ -60,16 +60,14 @@ if (value[i].type() == Json::stringValue && value[i].asString() == PLUGIN_NAME) { - // The "Bidirectional" status is set in "Plugin.cpp", given - // the configuration file - target_[peer_] = PeerCapabilities_Installed; + result_[peer_] = true; } } } } - void DetectTransferPlugin::Apply(Peers& peers, + void DetectTransferPlugin::Apply(Result& result, OrthancPluginContext* context, size_t threadsCount, unsigned int timeout) @@ -82,7 +80,7 @@ for (size_t i = 0; i < queue.GetOrthancPeers().GetPeersCount(); i++) { queue.Enqueue(new OrthancPlugins::DetectTransferPlugin - (peers, queue.GetOrthancPeers().GetPeerName(i))); + (result, queue.GetOrthancPeers().GetPeerName(i))); } {
--- a/Framework/HttpQueries/DetectTransferPlugin.h Mon Sep 17 14:42:57 2018 +0200 +++ b/Framework/HttpQueries/DetectTransferPlugin.h Tue Sep 18 15:39:02 2018 +0200 @@ -31,15 +31,15 @@ class DetectTransferPlugin : public IHttpQuery { public: - typedef std::map<std::string, PeerCapabilities> Peers; + typedef std::map<std::string, bool> Result; private: - Peers& target_; + Result& result_; std::string peer_; std::string uri_; public: - DetectTransferPlugin(Peers& target, + DetectTransferPlugin(Result& result, const std::string& peer); virtual Orthanc::HttpMethod GetMethod() const @@ -62,7 +62,7 @@ virtual void HandleAnswer(const void* answer, size_t size); - static void Apply(Peers& peers, + static void Apply(Result& result, OrthancPluginContext* context, size_t threadsCount, unsigned int timeout);
--- a/Framework/HttpQueries/HttpQueriesQueue.cpp Mon Sep 17 14:42:57 2018 +0200 +++ b/Framework/HttpQueries/HttpQueriesQueue.cpp Tue Sep 18 15:39:02 2018 +0200 @@ -223,7 +223,7 @@ } else { - LOG(ERROR) << "Reached the maximum number of retries for a HTTP query"; + LOG(INFO) << "Reached the maximum number of retries for a HTTP query"; { boost::mutex::scoped_lock lock(mutex_);
--- a/Framework/PullMode/PullJob.cpp Mon Sep 17 14:42:57 2018 +0200 +++ b/Framework/PullMode/PullJob.cpp Tue Sep 18 15:39:02 2018 +0200 @@ -193,9 +193,8 @@ if (job_.query_.HasOriginator() && job_.query_.GetOriginator() != answer[KEY_ORIGINATOR_UUID].asString()) { - LOG(ERROR) << "Invalid originator, check out the \"" - << KEY_PLUGIN_CONFIGURATION << "." << KEY_BIDIRECTIONAL_PEERS - << "\" configuration option"; + LOG(ERROR) << "Invalid originator, check out the \"" << KEY_REMOTE_SELF + << "\" configuration option of peer: " << job_.query_.GetPeer(); return StateUpdate::Failure(); }
--- a/Framework/TransferToolbox.h Mon Sep 17 14:42:57 2018 +0200 +++ b/Framework/TransferToolbox.h Tue Sep 18 15:39:02 2018 +0200 @@ -30,7 +30,6 @@ static const char* const PLUGIN_NAME = "transfers"; -static const char* const KEY_BIDIRECTIONAL_PEERS = "BidirectionalPeers"; static const char* const KEY_BUCKETS = "Buckets"; static const char* const KEY_COMPRESSION = "Compression"; static const char* const KEY_ID = "ID"; @@ -43,6 +42,7 @@ static const char* const KEY_PLUGIN_CONFIGURATION = "Transfers"; static const char* const KEY_PRIORITY = "Priority"; static const char* const KEY_REMOTE_JOB = "RemoteJob"; +static const char* const KEY_REMOTE_SELF = "RemoteSelf"; static const char* const KEY_RESOURCES = "Resources"; static const char* const KEY_SIZE = "Size"; static const char* const KEY_URL = "URL"; @@ -65,13 +65,6 @@ BucketCompression_Gzip }; - enum PeerCapabilities - { - PeerCapabilities_Disabled, - PeerCapabilities_Installed, - PeerCapabilities_Bidirectional - }; - unsigned int ConvertToMegabytes(uint64_t value); unsigned int ConvertToKilobytes(uint64_t value);
--- a/Plugin/Plugin.cpp Mon Sep 17 14:42:57 2018 +0200 +++ b/Plugin/Plugin.cpp Tue Sep 18 15:39:02 2018 +0200 @@ -438,16 +438,16 @@ OrthancPlugins::TransferQuery query(body); + OrthancPlugins::OrthancPeers peers(context.GetOrthanc()); + std::string remoteSelf; // For pull mode - bool pullMode = context.LookupBidirectionalPeer(remoteSelf, query.GetPeer()); + bool pullMode = peers.LookupUserProperty(remoteSelf, query.GetPeer(), KEY_REMOTE_SELF); LOG(INFO) << "Sending resources to peer \"" << query.GetPeer() << "\" using " << (pullMode ? "pull" : "push") << " mode"; if (pullMode) { - OrthancPlugins::OrthancPeers peers(context.GetOrthanc()); - Json::Value lookup = Json::objectValue; lookup[KEY_RESOURCES] = query.GetResources(); lookup[KEY_COMPRESSION] = OrthancPlugins::EnumerationToString(query.GetCompression()); @@ -579,38 +579,33 @@ return; } - OrthancPlugins::DetectTransferPlugin::Peers peers; + OrthancPlugins::DetectTransferPlugin::Result detection; OrthancPlugins::DetectTransferPlugin::Apply - (peers, context.GetOrthanc(), context.GetThreadsCount(), 2 /* timeout */); + (detection, context.GetOrthanc(), context.GetThreadsCount(), 2 /* timeout */); Json::Value result = Json::objectValue; - for (OrthancPlugins::DetectTransferPlugin::Peers::const_iterator - it = peers.begin(); it != peers.end(); ++it) + OrthancPlugins::OrthancPeers peers(context.GetOrthanc()); + + for (OrthancPlugins::DetectTransferPlugin::Result::const_iterator + it = detection.begin(); it != detection.end(); ++it) { - switch (it->second) + if (it->second) { - case OrthancPlugins::PeerCapabilities_Disabled: - result[it->first] = "disabled"; - break; - - case OrthancPlugins::PeerCapabilities_Installed: - { - std::string remoteSelf; + std::string remoteSelf; - if (context.LookupBidirectionalPeer(remoteSelf, it->first)) - { - result[it->first] = "installed"; - } - else - { - result[it->first] = "bidirectional"; - } - break; + if (peers.LookupUserProperty(remoteSelf, it->first, KEY_REMOTE_SELF)) + { + result[it->first] = "bidirectional"; } - - default: - throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); + else + { + result[it->first] = "installed"; + } + } + else + { + result[it->first] = "disabled"; } } @@ -658,7 +653,6 @@ OrthancPlugins::OrthancConfiguration plugin; config.GetSection(plugin, KEY_PLUGIN_CONFIGURATION); - plugin.GetDictionary(bidirectionalPeers, KEY_BIDIRECTIONAL_PEERS); threadsCount = plugin.GetUnsignedIntegerValue("Threads", threadsCount); targetBucketSize = plugin.GetUnsignedIntegerValue("BucketSize", targetBucketSize); memoryCacheSize = plugin.GetUnsignedIntegerValue("CacheSize", memoryCacheSize); @@ -669,7 +663,6 @@ OrthancPlugins::PluginContext::Initialize (context, threadsCount, targetBucketSize * KB, maxPushTransactions, memoryCacheSize * MB); - OrthancPlugins::PluginContext::GetInstance().LoadBidirectionalPeers(bidirectionalPeers); OrthancPlugins::RegisterRestCallback<ServeChunks> (context, std::string(URI_CHUNKS) + "/([.0-9a-f-]+)", true);
--- a/Plugin/PluginContext.cpp Mon Sep 17 14:42:57 2018 +0200 +++ b/Plugin/PluginContext.cpp Tue Sep 18 15:39:02 2018 +0200 @@ -58,23 +58,6 @@ } - bool PluginContext::LookupBidirectionalPeer(std::string& remoteSelf, - const std::string& remotePeer) const - { - BidirectionalPeers::const_iterator found = bidirectionalPeers_.find(remotePeer); - - if (found == bidirectionalPeers_.end()) - { - return false; - } - else - { - remoteSelf = found->second; - return true; - } - } - - void PluginContext::Initialize(OrthancPluginContext* context, size_t threadsCount, size_t targetBucketSize,
--- a/Plugin/PluginContext.h Mon Sep 17 14:42:57 2018 +0200 +++ b/Plugin/PluginContext.h Tue Sep 18 15:39:02 2018 +0200 @@ -31,8 +31,6 @@ class PluginContext : public boost::noncopyable { private: - typedef std::map<std::string, std::string> BidirectionalPeers; - // Runtime structures OrthancPluginContext* context_; OrthancInstancesCache cache_; @@ -43,7 +41,6 @@ // Configuration size_t threadsCount_; size_t targetBucketSize_; - BidirectionalPeers bidirectionalPeers_; PluginContext(OrthancPluginContext* context, @@ -90,20 +87,6 @@ return targetBucketSize_; } - void AddBidirectionalPeer(const std::string& remotePeer, - const std::string& remoteSelf) - { - bidirectionalPeers_[remotePeer] = remoteSelf; - } - - void LoadBidirectionalPeers(const BidirectionalPeers& peers) - { - bidirectionalPeers_ = peers; - } - - bool LookupBidirectionalPeer(std::string& remoteSelf, - const std::string& remotePeer) const; - static void Initialize(OrthancPluginContext* context, size_t threadsCount, size_t targetBucketSize,