Commit 4d0a3d0d authored by Dainius Simelevicius's avatar Dainius Simelevicius
Browse files

references #137: configurable tstore list in xmas-store profile

parent 743e032b
......@@ -123,6 +123,7 @@ namespace xmas
// Application parameters
//
xdata::Vector<xdata::String> eventings_;
xdata::Vector<xdata::String> tstores_;
xdata::String subscribeGroup_; // one or more comma separated groups hosting a ws-eventing service for monitoring
xdata::String storeGroup_; // one or more comma separated groups hosting a tstore service for storage
xdata::String storeView_; // view for tstore service for storage
......
......@@ -24,7 +24,6 @@
#include "xdaq/ApplicationContext.h"
#include "xdaq/ContextTable.h"
namespace xmas
{
namespace store2g
......@@ -33,19 +32,16 @@ namespace xmas
{
public:
DescriptorsCache(xdaq::Application* owner);
void actionPerformed( toolbox::Event& event );
void actionPerformed(toolbox::Event& event);
void addURL(const std::string & url);
std::list<xdaq::ApplicationDescriptorImpl> getDescriptors(std::set<std::string>& groups, const std::string & service);
private:
std::list<xdaq::ApplicationDescriptor*> services_;
xdaq::ContextTable discoveredContexts_;
std::list<xdaq::ApplicationDescriptor*> services_;
xdaq::ContextTable discoveredContexts_;
toolbox::BSem mutex_;
};
......
......@@ -16,12 +16,11 @@
#include "config/PackageInfo.h"
// !!! Edit this line to reflect the latest package version !!!
#define WORKSUITE_XMASSTORE2G_VERSION_MAJOR 2
#define WORKSUITE_XMASSTORE2G_VERSION_MINOR 1
#define WORKSUITE_XMASSTORE2G_VERSION_PATCH 5
#define WORKSUITE_XMASSTORE2G_VERSION_MAJOR 3
#define WORKSUITE_XMASSTORE2G_VERSION_MINOR 0
#define WORKSUITE_XMASSTORE2G_VERSION_PATCH 0
// If any previous versions available E.g. #define WORKSUITE_XMASSTORE2G_PREVIOUS_VERSIONS "3.8.0,3.8.1"
#define WORKSUITE_XMASSTORE2G_PREVIOUS_VERSIONS "2.0.0,2.0.1,2.0.2,2.1.0,2.1.1,2.1.2,2.1.3,2.1.4"
#undef WORKSUITE_XMASSTORE2G_PREVIOUS_VERSIONS
//
// Template macros
......
......@@ -78,6 +78,7 @@ xmas::store2g::Application::Application (xdaq::ApplicationStub* s)
period_ = "PT15S";
subscribeExpiration_ = "PT30S";
this->getApplicationInfoSpace()->fireItemAvailable("eventings", &eventings_); //direct eventing addresses
this->getApplicationInfoSpace()->fireItemAvailable("tstores", &tstores_); //direct tstore addresses
this->getApplicationInfoSpace()->fireItemAvailable("oclFileName", &oclFileName_);
this->getApplicationInfoSpace()->fireItemAvailable("db", &db_);
this->getApplicationInfoSpace()->fireItemAvailable("authentication", &authentication_);
......@@ -222,6 +223,25 @@ void xmas::store2g::Application::actionPerformed (toolbox::Event& event)
}
}
}
if (tstores_.elements() != 0)
{
for (xdata::Vector<xdata::String>::iterator i = tstores_.begin(); i != tstores_.end(); i++)
{
try
{
LOG4CPLUS_DEBUG(this->getApplicationLogger(), "Adding tstore: " << (*i).toString());
descriptorsCache_.addURL(*i);
}
catch(xmas::store2g::exception::Exception & e)
{
std::stringstream msg;
msg << "Failed to add tstore address";
XCEPT_DECLARE_NESTED(xmas::store2g::exception::Exception, ex, msg.str(), e);
LOG4CPLUS_ERROR (this->getApplicationLogger(), xcept::stdformat_exception_history(ex));
}
}
}
}
if (event.type() == "xplore::DiscoveryEvent")
......
......@@ -20,14 +20,11 @@
#include "xplore/exception/Exception.h"
#include "xplore/DiscoveryEvent.h"
xmas::store2g::DescriptorsCache::DescriptorsCache(xdaq::Application* owner): xdaq::Object(owner)
, mutex_(toolbox::BSem::FULL)
xmas::store2g::DescriptorsCache::DescriptorsCache(xdaq::Application* owner): xdaq::Object(owner), mutex_(toolbox::BSem::FULL)
{
}
void xmas::store2g::DescriptorsCache::actionPerformed( toolbox::Event& event)
{
xplore::DiscoveryEvent& de = dynamic_cast<xplore::DiscoveryEvent&>(event);
......@@ -101,10 +98,79 @@ void xmas::store2g::DescriptorsCache::actionPerformed( toolbox::Event& event)
LOG4CPLUS_ERROR(this->getOwnerApplication()->getApplicationLogger(),xcept::stdformat_exception_history(e));
}
}
mutex_.give();
mutex_.give();
}
void xmas::store2g::DescriptorsCache::addURL(const std::string & url)
{
mutex_.take();
toolbox::net::URL urlobj(url);
//Extracting context URL, e.g. http://example.com:9939
std::string contextURL = urlobj.getScheme() + "://" + urlobj.getAuthority();
std::cout << "************* url = " << url << std::endl;
//Extracting lid
std::string path = urlobj.getPath();
std::string::size_type pos = path.find("lid=");
std::string idNumberString = "";
if (pos != std::string::npos)
{
idNumberString = path.substr(pos + 4);
}
else
{
LOG4CPLUS_ERROR(this->getOwnerApplication()->getApplicationLogger(), "TStore URL: " << url << " does not specify lid.");
}
xdata::UnsignedIntegerT lid = 0;
try
{
xdata::UnsignedInteger idNumber(idNumberString);
lid = static_cast<xdata::UnsignedIntegerT>(idNumber);
}
catch (xdata::exception::Exception & e)
{
LOG4CPLUS_ERROR(this->getOwnerApplication()->getApplicationLogger(), "Incorrect lid value: " << idNumberString);
}
const xdaq::ContextDescriptor* cd = 0;
if (discoveredContexts_.hasContextDescriptor(contextURL))
{
cd = discoveredContexts_.getContextDescriptor(contextURL);
}
else
{
cd = discoveredContexts_.createContextDescriptor(contextURL);
}
xdaq::ApplicationDescriptorImpl* descriptor = 0;
try
{
descriptor = new xdaq::ApplicationDescriptorImpl(cd, "tstore::TStore", lid, "");
}
catch (xdaq::exception::Exception & e)
{
LOG4CPLUS_ERROR(this->getOwnerApplication()->getApplicationLogger(), xcept::stdformat_exception_history(e));
}
try
{
services_.push_back(descriptor);
LOG4CPLUS_DEBUG(this->getOwnerApplication()->getApplicationLogger(), "created descriptor for service at: " << urlobj.toString());
}
catch(xdaq::exception::Exception & e)
{
delete descriptor;
LOG4CPLUS_ERROR(this->getOwnerApplication()->getApplicationLogger(),xcept::stdformat_exception_history(e));
}
mutex_.give();
}
std::list<xdaq::ApplicationDescriptorImpl> xmas::store2g::DescriptorsCache::getDescriptors(std::set<std::string>& groups, const std::string & service)
{
std::list<xdaq::ApplicationDescriptorImpl> destinations;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment