Commit ee9f1523 authored by Dainius Simelevicius's avatar Dainius Simelevicius
Browse files

references #143: support for providing eventing URLs explicitly for heartbeat application

parent 801720a7
......@@ -2,12 +2,12 @@
/*************************************************************************
* 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. *
*************************************************************************/
#ifndef _xmas_heartbeat_Application_h_
......@@ -118,9 +118,9 @@ namespace xmas
void addDestination(xdata::Properties & p);
void refreshSubscriptionsToEventing() ;
xdata::String subscribeGroup_; // one or more comma separated groups hosting a ws-eventing service for monitoring
std::map<std::string, xdata::Properties> subscriptions_; // indexed by topic
toolbox::BSem repositoryLock_;
......@@ -131,7 +131,12 @@ namespace xmas
xdata::String scanPeriod_;
xdata::String heartbeatExpiration_;
xdata::String subscribeExpiration_;
xdata::Vector<xdata::String> eventings_;
xdata::UnsignedInteger eventingReplicas_;
xdata::String eventingPattern_;
std::vector<std::string> eventingList_;
typedef struct
{
xdata::Properties descriptor;
......
......@@ -2,12 +2,12 @@
/*************************************************************************
* 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. *
*************************************************************************/
#ifndef _xmas_heartbeat_version_h_
......@@ -17,11 +17,10 @@
// !!! Edit this line to reflect the latest package version !!!
#define WORKSUITE_XMASHEARTBEAT_VERSION_MAJOR 2
#define WORKSUITE_XMASHEARTBEAT_VERSION_MINOR 4
#define WORKSUITE_XMASHEARTBEAT_VERSION_MINOR 5
#define WORKSUITE_XMASHEARTBEAT_VERSION_PATCH 0
// If any previous versions available E.g. #define WORKSUITE_XMASHEARTBEAT_PREVIOUS_VERSIONS "3.8.0,3.8.1"
#undef WORKSUITE_XMASHEARTBEAT_PREVIOUS_VERSIONS
#define WORKSUITE_XMASHEARTBEAT_PREVIOUS_VERSIONS "2.2.0,2.2.1,2.3.0"
//
// Template macros
......@@ -39,7 +38,7 @@ namespace xmasheartbeat
const std::string package = "xmasheartbeat";
const std::string versions = WORKSUITE_XMASHEARTBEAT_FULL_VERSION_LIST;
const std::string description = "";
const std::string authors = "Johannes Gutleber, Luciano Orsini, Penelope Roberts";
const std::string authors = "Johannes Gutleber, Luciano Orsini, Penelope Roberts, Dainius Simelevicius";
const std::string summary = "XDAQ Monitoring and Alarming System heartbeat server";
const std::string link = "http://xdaqwiki.cern.ch/index.php/Power_Pack";
config::PackageInfo getPackageInfo();
......
......@@ -2,12 +2,12 @@
/*************************************************************************
* 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 <iomanip>
......@@ -63,6 +63,8 @@
// Required for Namespace declaration used in configuration file
#include "xmas/xmas.h"
#include <string>
#include <regex>
XDAQ_INSTANTIATOR_IMPL(xmas::heartbeat::Application);
......@@ -72,7 +74,15 @@ xmas::heartbeat::Application::Application (xdaq::ApplicationStub* s)
b2in::nub::bind(this, &xmas::heartbeat::Application::onMessage );
s->getDescriptor()->setAttribute("icon", "/xmas/heartbeat/images/heartbeat-icon.png");
// direct evetings addresses
this->getApplicationInfoSpace()->fireItemAvailable("eventings", &eventings_);
// Eventing addresses by pattern
eventingReplicas_ = 0;
this->getApplicationInfoSpace()->fireItemAvailable("eventingReplicas", &eventingReplicas_);
this->getApplicationInfoSpace()->fireItemAvailable("eventingPattern", &eventingPattern_);
// In which group to search for a ws-eventing
subscribeGroup_ = "";
this->getApplicationInfoSpace()->fireItemAvailable("subscribeGroup", &subscribeGroup_);
......@@ -105,16 +115,19 @@ void xmas::heartbeat::Application::timeExpired(toolbox::task::TimerEvent& e)
{
LOG4CPLUS_DEBUG (this->getApplicationLogger(), "Timer callback");
try
{
b2inEventingProxy_->scan();
}
catch (b2in::utils::exception::Exception& e)
if (eventingList_.size() == 0)
{
LOG4CPLUS_FATAL (this->getApplicationLogger(), xcept::stdformat_exception_history(e));
// use of discovery
try
{
b2inEventingProxy_->scan();
}
catch (b2in::utils::exception::Exception& e)
{
LOG4CPLUS_FATAL (this->getApplicationLogger(), xcept::stdformat_exception_history(e));
}
}
try
{
this->refreshSubscriptionsToEventing();
......@@ -177,34 +190,52 @@ void xmas::heartbeat::Application::actionPerformed( xdata::Event& event)
void xmas::heartbeat::Application::actionPerformed(toolbox::Event& e)
{
LOG4CPLUS_DEBUG(this->getApplicationLogger(), "Received event " << e.type());
/*
if ( e.type() == "xdaq::EndpointAvailableEvent" )
if (e.type() == "urn:xdaq-event:profile-loaded")
{
// If the available endpoint is a b2in endpoint we are ready to
// discover other b2in endpoints on the network
//
std::string networkName = this->getApplicationDescriptor()->getAttribute("network");
xdaq::EndpointAvailableEvent& ie = dynamic_cast<xdaq::EndpointAvailableEvent&>(e);
// xdaq::Endpoint* endpoint = ie.getEndpoint();
xdaq::Network* network = ie.getNetwork();
LOG4CPLUS_INFO (this->getApplicationLogger(), "Received endpoint available event for network " << network->getName());
if (network->getName() == networkName)
{
LOG4CPLUS_DEBUG(this->getApplicationLogger(), "Setting proxy to b2in-eventing services " );
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
{
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(xmas::heartbeat::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_INFO (this->getApplicationLogger(), "Discover b2in endpoints on network " << networkName);
this->refreshSubscriptionsToEventing();
LOG4CPLUS_DEBUG(this->getApplicationLogger(), "Adding eventing on " << eventing);
xdata::String url(eventing);
b2inEventingProxy_->addURL(url);
}
catch (xdaq::exception::Exception& e)
catch(b2in::utils::exception::Exception & e)
{
LOG4CPLUS_FATAL (this->getApplicationLogger(), xcept::stdformat_exception_history(e));
std::stringstream msg;
msg << "Failed to add b2in-eventing address";
XCEPT_DECLARE_NESTED(xmas::heartbeat::exception::Exception, ex, msg.str(), e);
LOG4CPLUS_ERROR(this->getApplicationLogger(), xcept::stdformat_exception_history(ex));
}
}
}
*/
}
void xmas::heartbeat::Application::onMessage (toolbox::mem::Reference * msg, xdata::Properties & plist)
......
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