Commit 04de2696 authored by Dainius Simelevicius's avatar Dainius Simelevicius
Browse files

references #139: support for eventing url by pattern in spotlight2g

parent 90e2cf4d
......@@ -47,9 +47,9 @@
#include "sentinel/spotlight2g/Repository.h"
#include "xgi/framework/UIManager.h"
namespace sentinel
namespace sentinel
{
namespace spotlight2g
namespace spotlight2g
{
class Application : public xdaq::Application,
public xgi::framework::UIManager,
......@@ -62,100 +62,90 @@ namespace sentinel
XDAQ_INSTANTIATOR();
Application(xdaq::ApplicationStub* s) ;
Application(xdaq::ApplicationStub* s);
~Application();
void actionPerformed ( xdata::Event& e );
void actionPerformed(xdata::Event& e);
void actionPerformed( toolbox::Event& event );
void actionPerformed(toolbox::Event& event);
void timeExpired(toolbox::task::TimerEvent& e);
//
// XGI Interface
//
void Default(xgi::Input * in, xgi::Output * out ) ;
/*! Clear exception history
*/
void reset(xgi::Input * in, xgi::Output * out ) ;
/*! View a specific exception referenced by uuid
*/
void view(xgi::Input * in, xgi::Output * out )
;
/*! list all available exceptions
*/
void catalog(xgi::Input * in, xgi::Output * out )
;
void events(xgi::Input * in, xgi::Output * out )
;
void lastStoredEvents(xgi::Input * in, xgi::Output * out )
;
/*! generate a test exception
*/
void inject(xgi::Input * in, xgi::Output * out )
;
void generate(xgi::Input * in, xgi::Output * out )
;
void Default(xgi::Input * in, xgi::Output * out);
/*! Clear exception history */
void reset(xgi::Input * in, xgi::Output * out);
/*! View a specific exception referenced by uuid */
void view(xgi::Input * in, xgi::Output * out);
/*! list all available exceptions */
void catalog(xgi::Input * in, xgi::Output * out);
void events(xgi::Input * in, xgi::Output * out);
void lastStoredEvents(xgi::Input * in, xgi::Output * out);
/*! generate a test exception */
void inject(xgi::Input * in, xgi::Output * out);
void generate(xgi::Input * in, xgi::Output * out);
/*! Retrieve list of spotlight database files in the configured path */
void files(xgi::Input * in, xgi::Output * out )
;
void files(xgi::Input * in, xgi::Output * out);
/*! Retrieve list of open databases */
void databases(xgi::Input * in, xgi::Output * out )
;
void databases(xgi::Input * in, xgi::Output * out);
/*! Attach to an additional database file in the configured directory
parameters 'dbname' and 'filename'
*/
void attach(xgi::Input * in, xgi::Output * out )
;
void attach(xgi::Input * in, xgi::Output * out);
/*! Detach from an attached database
parameter 'dbname'
*/
void detach(xgi::Input * in, xgi::Output * out )
;
void detach(xgi::Input * in, xgi::Output * out);
//
// B2IN interface
//
void onMessage (toolbox::mem::Reference * msg, xdata::Properties & plist) ;
void onMessage(toolbox::mem::Reference * msg, xdata::Properties & plist);
void asynchronousExceptionNotification(xcept::Exception& e);
void rearm(xgi::Input * in, xgi::Output * out ) ;
void rearm(xgi::Input * in, xgi::Output * out);
protected:
void refreshSubscriptionsToEventing() ;
void refreshSubscriptionsToEventing();
void loadJEL(const std::string & fname);
bool applyJEL( xcept::Exception & e);
bool match ( xcept::Exception & e, std::map<std::string, std::string>& filter);
std::string mapToAttributeName(const std::string & name);
void mainPage ( xgi::Input * in, xgi::Output * out) ;
void mainPage ( xgi::Input * in, xgi::Output * out);
void HotspotTabPage(xgi::Output * out) ;
void StatisticsTabPage(xgi::Output * out) ;
void JELTabPage(xgi::Output * out) ;
void HotspotTabPage(xgi::Output * out);
void StatisticsTabPage(xgi::Output * out);
void JELTabPage(xgi::Output * out);
private:
toolbox::task::AsynchronousEventDispatcher dispatcher_;
Repository* repository_;
Repository* repository_;
xdata::UnsignedInteger64T exceptionsLostCounter_;
xdata::String topic_;
xdata::Vector<xdata::String> eventings_;
xdata::UnsignedInteger eventingReplicas_;
xdata::String eventingPattern_;
std::vector<std::string> eventingList_;
xdata::String maintenanceInterval_; // interval at which the database switchover happens (> 1 minute)
xdata::String repositoryPath_; // folder in which to store the spotlight database files (/var/run/spotlight)
xdata::String subscribeGroup_; // one or more comma separated groups hosting a ws-eventing service for exceptions
......
......@@ -18,7 +18,7 @@
// !!! Edit this line to reflect the latest package version !!!
#define WORKSUITE_SENTINELSPOTLIGHT2G_VERSION_MAJOR 3
#define WORKSUITE_SENTINELSPOTLIGHT2G_VERSION_MINOR 0
#define WORKSUITE_SENTINELSPOTLIGHT2G_VERSION_MINOR 1
#define WORKSUITE_SENTINELSPOTLIGHT2G_VERSION_PATCH 0
// If any previous versions available E.g. #define WORKSUITE_SENTINELSPOTLIGHT2G_PREVIOUS_VERSIONS "3.8.0,3.8.1"
#undef WORKSUITE_SENTINELSPOTLIGHT2G_PREVIOUS_VERSIONS
......
......@@ -2,14 +2,17 @@
/*************************************************************************
* XDAQ Components for Distributed Data Acquisition *
* Copyright (C) 2000-2009, CERN. *
* Copyright (C) 2000-2020, CERN. *
* All rights reserved. *
* Authors: J. Gutleber and L. Orsini *
* Authors: J. Gutleber, L. Orsini and D. Simelevicius *
* *
* For the licensing terms see LICENSE. *
* For the list of contributors see CREDITS. *
* For the licensing terms see LICENSE. *
* For the list of contributors see CREDITS. *
*************************************************************************/
#include <sstream>
#include <string>
#include <regex>
#include "cgicc/CgiDefs.h"
#include "cgicc/Cgicc.h"
#include "cgicc/HTTPHTMLHeader.h"
......@@ -76,6 +79,10 @@ sentinel::spotlight2g::Application::Application(xdaq::ApplicationStub* s)
//Direct eventing addresses
this->getApplicationInfoSpace()->fireItemAvailable("eventings", &eventings_);
// Eventing addresses by pattern
this->getApplicationInfoSpace()->fireItemAvailable("eventingReplicas", &eventingReplicas_);
this->getApplicationInfoSpace()->fireItemAvailable("eventingPattern", &eventingPattern_);
subscribeGroup_ = "";
this->getApplicationInfoSpace()->fireItemAvailable("subscribeGroup", &subscribeGroup_);
......@@ -94,7 +101,7 @@ sentinel::spotlight2g::Application::Application(xdaq::ApplicationStub* s)
(void) toolbox::task::getWorkLoopFactory()->getWorkLoop("urn:xdaq-workloop:spotlight", "waiting")->activate();
repositoryPath_ = "/tmp";
this->getApplicationInfoSpace()->fireItemAvailable("repositoryPath",&repositoryPath_);
this->getApplicationInfoSpace()->fireItemAvailable("repositoryPath",&repositoryPath_);
// Which flashlist tags to retrieve from the ws-eventing
topic_ = "sentinel";
......@@ -582,7 +589,7 @@ void sentinel::spotlight2g::Application::timeExpired(toolbox::task::TimerEvent&
if (name == "discovery-staging")
{
if (eventings_.elements() == 0)
if (eventingList_.size() == 0)
{
try
{
......@@ -1083,29 +1090,25 @@ std::string sentinel::spotlight2g::Application::mapToAttributeName(const std::st
{
if ((name == "class") || ( name == "instance") || ( name == "lid") || ( name == "context")
|| ( name == "group") || ( name == "service") || ( name == "zone") )
{
{
std::string v = "urn:xdaq-application:";
v += name;
return v;
}
return v;
}
return name;
}
bool sentinel::spotlight2g::Application::match
(
xcept::Exception & e,
std::map<std::string, std::string>& filter
)
bool sentinel::spotlight2g::Application::match(xcept::Exception & e, std::map<std::string, std::string>& filter)
{
// Algorithm requires that all filter expressions match!
//
// Algorithm requires that all filter expressions match!
//
//std::cout << "apply rule" << std::endl;
std::map<std::string, std::string>::iterator i;
for (i = filter.begin(); i != filter.end(); ++i)
{
try
{
std::map<std::string, std::string>::iterator i;
for (i = filter.begin(); i != filter.end(); ++i)
{
try
{
//--
std::string name = this->mapToAttributeName((*i).first);
......@@ -1113,45 +1116,68 @@ bool sentinel::spotlight2g::Application::match
// extract property from exception
std::string value = e.getProperty(name);
//std::cout << "check attribute:" << name << " regex:" << (*i).second << " on value: " << value;
if ( ! toolbox::regx_match_nocase(value, (*i).second ) )
{
if ( ! toolbox::regx_match_nocase(value, (*i).second ) )
{
//std::cout << " -> does not match" << std::endl;
return false;
}
}
catch (xdata::exception::Exception& e)
{
// doesn't match the column name
return false;
}
}
return false;
}
}
catch (xdata::exception::Exception& e)
{
// doesn't match the column name
return false;
}
}
//std::cout << " -> it matches!" << std::endl;
return true;
}
return true;
}
void sentinel::spotlight2g::Application::actionPerformed(toolbox::Event& event)
void sentinel::spotlight2g::Application::actionPerformed(toolbox::Event& event)
{
if (event.type() == "urn:xdaq-event:profile-loaded")
{
LOG4CPLUS_DEBUG(this->getApplicationLogger(), "Setting proxy to b2in-eventing services " );
LOG4CPLUS_DEBUG(this->getApplicationLogger(), "Setting proxy to b2in-eventing services ");
if (eventings_.elements() != 0)
for (xdata::Vector<xdata::String>::iterator i = eventings_.begin(); i != eventings_.end(); i++)
{
for (xdata::Vector<xdata::String>::iterator i = eventings_.begin(); i != eventings_.end(); i++)
eventingList_.push_back(i->toString());
}
std::string eventingPattern = eventingPattern_.toString();
for (unsigned int i = 0; i < eventingReplicas_; ++i)
{
std::string s = std::to_string(i);
std::string eventing;
try
{
try
{
LOG4CPLUS_DEBUG(this->getApplicationLogger(), "Adding eventing on " << (*i).toString());
b2inEventingProxy_->addURL(*i);
}
catch(b2in::utils::exception::Exception & e)
{
std::stringstream msg;
msg << "Failed to add b2in-eventing address";
XCEPT_DECLARE_NESTED(sentinel::spotlight2g::exception::Exception, ex, msg.str(),e);
LOG4CPLUS_ERROR (this->getApplicationLogger(), xcept::stdformat_exception_history(ex));
}
eventing = std::regex_replace(eventingPattern, std::regex("#"), s);
}
catch (std::regex_error & e)
{
std::stringstream msg;
msg << "Failed to process eventing pattern: '" << eventingPattern << "'. " << e.what();
XCEPT_DECLARE(sentinel::spotlight2g::exception::Exception, ex, msg.str());
LOG4CPLUS_ERROR(this->getApplicationLogger(), xcept::stdformat_exception_history(ex));
break;
}
eventingList_.push_back(eventing);
}
for(std::string eventing : eventingList_)
{
try
{
LOG4CPLUS_DEBUG(this->getApplicationLogger(), "Adding eventing on " << eventing);
xdata::String url(eventing);
b2inEventingProxy_->addURL(url);
}
catch(b2in::utils::exception::Exception & e)
{
std::stringstream msg;
msg << "Failed to add b2in-eventing address";
XCEPT_DECLARE_NESTED(sentinel::spotlight2g::exception::Exception, ex, msg.str(),e);
LOG4CPLUS_ERROR (this->getApplicationLogger(), xcept::stdformat_exception_history(ex));
}
}
}
......@@ -1215,32 +1241,27 @@ void sentinel::spotlight2g::Application::actionPerformed(toolbox::Event& event)
}
void sentinel::spotlight2g::Application::mainPage
(
xgi::Input * in,
xgi::Output * out
)
void sentinel::spotlight2g::Application::mainPage(xgi::Input * in, xgi::Output * out)
{
// Begin of tabs
*out << "<div class=\"xdaq-tab-wrapper\">" << std::endl;
// Tab 1
*out << "<div class=\"xdaq-tab\" title=\"Hotspot\">" << std::endl;
this->HotspotTabPage(out);
*out << "</div>";
// Tab 2
*out << "<div class=\"xdaq-tab\" title=\"Statistics\">" << std::endl;
this->StatisticsTabPage(out);
*out << "</div>";
// Tab 3
*out << "<div class=\"xdaq-tab\" title=\"JEL\">" << std::endl;
this->JELTabPage(out);
*out << "</div>";
*out << "</div>"; // end of tab pane
*out << "<div class=\"xdaq-tab-wrapper\">" << std::endl;
// Tab 1
*out << "<div class=\"xdaq-tab\" title=\"Hotspot\">" << std::endl;
this->HotspotTabPage(out);
*out << "</div>";
// Tab 2
*out << "<div class=\"xdaq-tab\" title=\"Statistics\">" << std::endl;
this->StatisticsTabPage(out);
*out << "</div>";
// Tab 3
*out << "<div class=\"xdaq-tab\" title=\"JEL\">" << std::endl;
this->JELTabPage(out);
*out << "</div>";
*out << "</div>"; // end of tab pane
}
void sentinel::spotlight2g::Application::JELTabPage (xgi::Output * out)
......
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