Commit 9c08da04 authored by Dainius Simelevicius's avatar Dainius Simelevicius
Browse files

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

parent 04de2696
......@@ -141,6 +141,10 @@ namespace sentinel
xdata::String topic_;
xdata::Vector<xdata::String> eventings_;
xdata::UnsignedInteger eventingReplicas_;
xdata::String eventingPattern_;
std::vector<std::string> eventingList_;
xdata::String subscribeGroup_; // one or more comma separated groups hosting a ws-eventing service for exceptions
xdata::String jelFileName_; // xml file containing junk exception filter rules
xdata::String oclFileName_;
......
......@@ -18,7 +18,7 @@
// !!! Edit this line to reflect the latest package version !!!
#define WORKSUITE_SENTINELSPOTLIGHTOCCI_VERSION_MAJOR 4
#define WORKSUITE_SENTINELSPOTLIGHTOCCI_VERSION_MINOR 0
#define WORKSUITE_SENTINELSPOTLIGHTOCCI_VERSION_MINOR 1
#define WORKSUITE_SENTINELSPOTLIGHTOCCI_VERSION_PATCH 0
// If any previous versions available E.g. #define WORKSUITE_SENTINELSPOTLIGHTOCCI_PREVIOUS_VERSIONS "3.8.0,3.8.1"
#undef WORKSUITE_SENTINELSPOTLIGHTOCCI_PREVIOUS_VERSIONS
......@@ -41,7 +41,7 @@ namespace sentinelspotlightocci
const std::string versions = WORKSUITE_SENTINELSPOTLIGHTOCCI_FULL_VERSION_LIST;
const std::string summary = "Server for exceptions and alarms";
const std::string description = "";
const std::string authors = "Johannes Gutleber, Luciano Orsini";
const std::string authors = "Johannes Gutleber, Luciano Orsini, Dainius Simelevicius";
const std::string link = "http://xdaqwiki.cern.ch/index.php/Power_Pack";
config::PackageInfo getPackageInfo();
void checkPackageDependencies() ;
......
......@@ -11,6 +11,9 @@
*************************************************************************/
#include <sstream>
#include <string>
#include <regex>
#include "cgicc/CgiDefs.h"
#include "cgicc/Cgicc.h"
#include "cgicc/HTTPHTMLHeader.h"
......@@ -73,9 +76,13 @@ sentinel::spotlightocci::Application::Application(xdaq::ApplicationStub* s)
s->getDescriptor()->setAttribute("icon16x16", "/sentinel/spotlightocci/images/spotlight-occi-icon.png");
s->getDescriptor()->setAttribute("service", "sentinelspotlight2g");
//Direct eventing addresses
// 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_);
......@@ -580,7 +587,7 @@ void sentinel::spotlightocci::Application::timeExpired(toolbox::task::TimerEvent
if (name == "discovery-staging")
{
if (eventings_.elements() == 0)
if (eventingList_.size() == 0)
{
try
{
......@@ -855,7 +862,7 @@ void sentinel::spotlightocci::Application::events(xgi::Input * in, xgi::Output *
}
}
void sentinel::spotlightocci::Application::query(xgi::Input * in, xgi::Output * out )
void sentinel::spotlightocci::Application::query(xgi::Input * in, xgi::Output * out )
{
std::cout << "Application::query" << std::endl;
std::string format = "json"; // by default output json format
......@@ -906,8 +913,6 @@ void sentinel::spotlightocci::Application::Default(xgi::Input * in, xgi::Output
this->mainPage(in,out);
}
/*
void sentinel::spotlightocci::Application::files(xgi::Input * in, xgi::Output * out )
{
......@@ -992,7 +997,7 @@ void sentinel::spotlightocci::Application::rearm(xgi::Input * in, xgi::Output *
{
exception = exceptions[i].getValue();
repository_->rearm(exception, user);
}
}
}
else
{
......@@ -1034,8 +1039,8 @@ void sentinel::spotlightocci::Application::loadOCL(const std::string & fname)
}
std::string zone = this->getApplicationContext()->getDefaultZoneName();
try
{
try
{
//LOG4CPLUS_INFO (this->getApplicationLogger(), "Load OCL from '" << files[0] << "'");
DOMDocument* doc = xoap::getDOMParserFactory()->get("configure")->loadXML( files[0] );
DOMNodeList* list = doc->getElementsByTagNameNS(xoap::XStr("http://xdaq.web.cern.ch/xdaq/xsd/2016/oraclecl"),xoap::XStr("XaasZone") );
......@@ -1108,8 +1113,8 @@ void sentinel::spotlightocci::Application::loadJEL(const std::string & fname)
return;
}
try
{
try
{
LOG4CPLUS_INFO (this->getApplicationLogger(), "Load JEL from '" << files[0] << "'");
DOMDocument* doc = xoap::getDOMParserFactory()->get("configure")->loadXML( files[0] );
DOMNodeList* list = doc->getElementsByTagNameNS(xoap::XStr("http://xdaq.web.cern.ch/xdaq/xsd/2010/spotlight"),xoap::XStr("rule") );
......@@ -1150,8 +1155,8 @@ bool sentinel::spotlightocci::Application::applyJEL( xcept::Exception & e)
size_t labelCounter = 0;
std::list<xdata::Properties>::iterator i;
std::string name = e.name();
for (i = jel_.begin(); i != jel_.end(); ++i)
{
for (i = jel_.begin(); i != jel_.end(); ++i)
{
std::stringstream label;
label << "r" << labelCounter;
......@@ -1186,29 +1191,25 @@ std::string sentinel::spotlightocci::Application::mapToAttributeName(const std::
{
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::spotlightocci::Application::match
(
xcept::Exception & e,
std::map<std::string, std::string>& filter
)
bool sentinel::spotlightocci::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);
......@@ -1216,22 +1217,21 @@ bool sentinel::spotlightocci::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::spotlightocci::Application::actionPerformed( toolbox::Event& event)
{
......@@ -1239,22 +1239,45 @@ void sentinel::spotlightocci::Application::actionPerformed( toolbox::Event& even
{
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++)
{
eventingList_.push_back(i->toString());
}
std::string eventingPattern = eventingPattern_.toString();
for (unsigned int i = 0; i < eventingReplicas_; ++i)
{
for (xdata::Vector<xdata::String>::iterator i = eventings_.begin(); i != eventings_.end(); 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::spotlightocci::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::spotlightocci::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::spotlightocci::exception::Exception, ex, msg.str(),e);
LOG4CPLUS_ERROR (this->getApplicationLogger(), xcept::stdformat_exception_history(ex));
}
}
}
......
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