Commit d6907b74 authored by Luciano Orsini's avatar Luciano Orsini
Browse files

references #1486: Creation of Spotlight OCCI for working with Oracle


git-svn-id: file:///tmp/cmsos_migration/cmsos.svndb/trunk@17050 c528359e-2999-456a-ae53-7ba8edf254b3
parent 13215bac
# $Id: Makefile,v 1.5 2008/11/13 15:08:59 lorsini Exp $
#########################################################################
# XDAQ Components for Distributed Data Acquisition #
# Copyright (C) 2000-2009, CERN. #
# All rights reserved. #
# Authors: L. Orsini #
# #
# For the licensing terms see LICENSE. #
# For the list of contributors see CREDITS. #
#########################################################################
BUILD_HOME:=$(shell pwd)/../../..
include $(XDAQ_ROOT)/config/mfAutoconf.rules
include $(XDAQ_ROOT)/config/mfDefs.$(XDAQ_OS)
include $(XDAQ_ROOT)/config/mfDefs.extern_coretools
include $(XDAQ_ROOT)/config/mfDefs.coretools
include $(XDAQ_ROOT)/config/mfDefs.extern_powerpack
include $(XDAQ_ROOT)/config/mfDefs.powerpack
#
# Packages to be built
#
Project=daq
Package=sentinel/spotlightocci
ifdef ORACLE_HOME
ORACLE_INCLUDE_PREFIX=${ORACLE_HOME}/rdbms/demo/ ${ORACLE_HOME}/rdbms/public/
ORACLE_LIB_PREFIX=${ORACLE_HOME}/lib
endif
UserCCFlags += -DORACLE__
ExternalObjects += -locci -lclntsh
Sources=\
DataBase.cc \
Repository.cc \
Application.cc \
ExceptionEvent.cc \
RevokeEvent.cc \
version.cc
Executables=
IncludeDirs = \
$(B2IN_UTILS_INCLUDE_PREFIX) \
$(B2IN_NUB_INCLUDE_PREFIX) \
$(XERCES_INCLUDE_PREFIX) \
$(LOG4CPLUS_INCLUDE_PREFIX) \
$(CGICC_INCLUDE_PREFIX) \
$(XCEPT_INCLUDE_PREFIX) \
$(CONFIG_INCLUDE_PREFIX) \
$(TOOLBOX_INCLUDE_PREFIX) \
$(PT_INCLUDE_PREFIX) \
$(XDAQ_INCLUDE_PREFIX) \
$(XDATA_INCLUDE_PREFIX) \
$(XOAP_INCLUDE_PREFIX) \
$(XGI_INCLUDE_PREFIX) \
$(I2O_INCLUDE_PREFIX) \
$(XI2O_INCLUDE_PREFIX) \
$(XMAS_INCLUDE_PREFIX) \
$(SENTINEL_INCLUDE_PREFIX) \
$(SENTINEL_UTILS_INCLUDE_PREFIX) \
$(SQLITE_INCLUDE_PREFIX) \
$(XSLP_INCLUDE_PREFIX) \
$(XPLORE_INCLUDE_PREFIX) \
$(XPLORE_UTILS_INCLUDE_PREFIX) \
$(WS_ADDRESSING_INCLUDE_PREFIX) \
$(WS_UTILS_INCLUDE_PREFIX) \
$(WS_EVENTING_INCLUDE_PREFIX) \
$(ORACLE_INCLUDE_PREFIX)
DependentLibraryDirs = $(ORACLE_LIB_PREFIX)
LibraryDirs = $(ORACLE_LIB_PREFIX)
UserSourcePath =
UserCFlags =
UserCCFlags = -DTT_64BIT
UserDynamicLinkFlags =
UserStaticLinkFlags =
UserExecutableLinkFlags =
# These libraries can be platform specific and
# potentially need conditional processing
#
Libraries =
#
# Compile the source files and create a shared library
#
DynamicLibrary=sentinelspotlightocci
StaticLibrary=
TestLibraryDirs=
TestExecutables= test.cc
TestLibraries= crypt \
config \
peer \
toolbox \
asyncresolv \
log4cplus \
xerces-c \
cgicc \
xcept \
xoap \
xdata \
xgi \
logudpappender \
logxmlappender \
mimetic \
b2inutils \
sentinelutils \
uuid xdaq sentinelspotlighttt
include $(XDAQ_ROOT)/config/Makefile.rules
include $(XDAQ_ROOT)/config/mfRPM.rules
become root
$ source ~/init.install
$ export LD_LIBRARY_PATH=/opt/xdaq/lib:lib/linux/x86_slc4/:/opt/TimesTen/tt1121/lib/
$ cd /nfshome0/mbowen/trunk/daq/sentinel/spotlighttt
$ /opt/xdaq/bin/xdaq.exe -e xml/spotlighttt.xml
export XDAQ_ROOT=/opt/xdaq
export XDAQ_DOCUMENT_ROOT=/opt/xdaq/htdocs
export XDAQ_SETTINGS_ROOT=/opt/xdaq/share
export LD_LIBRARY_PATH=/opt/xdaq/lib:lib/linux/x86_64_slc5/:/opt/TimesTen/tt1121/lib/:/nfshome0/mbowen/trunk/daq/sentinel/spotlightocci/lib/linux/x86_64_slc5
export ORACLE_HOME=/usr/local/oracle11g/product/11.2.0/dbhome_1
// $Id: Application.h,v 1.12 2008/11/25 13:21:03 lorsini Exp $
/*************************************************************************
* XDAQ Components for Distributed Data Acquisition *
* Copyright (C) 2000-2009, CERN. *
* All rights reserved. *
* Authors: J. Gutleber and L. Orsini *
* *
* For the licensing terms see LICENSE. *
* For the list of contributors see CREDITS. *
*************************************************************************/
#ifndef _sentinel_spotlightocci_Application_h_
#define _sentinel_spotlightocci_Application_h_
#include <string>
#include <map>
#include "toolbox/ActionListener.h"
#include "toolbox/task/TimerListener.h"
#include "toolbox/task/AsynchronousEventDispatcher.h"
#include "xdaq/ApplicationDescriptorImpl.h"
#include "xdaq/Application.h"
#include "xdaq/ApplicationContext.h"
#include "xdata/UnsignedInteger64.h"
#include "xdata/UnsignedInteger32.h"
#include "xdata/String.h"
#include "xdata/Vector.h"
#include "xdata/Boolean.h"
#include "xdata/ActionListener.h"
#include "xdata/Properties.h"
#include "b2in/nub/Method.h"
#include "b2in/utils/MessengerCache.h"
#include "b2in/utils/ServiceProxy.h"
#include "xgi/Method.h"
#include "xgi/Utils.h"
#include "xgi/Output.h"
#include "xgi/exception/Exception.h"
#include "sentinel/exception/Exception.h"
#include "ws/utils/WSEventingProxy.h"
#include "xplore/utils/DescriptorsCache.h"
#include "sentinel/spotlightocci/Repository.h"
namespace sentinel
{
namespace spotlightocci
{
class Application :public xdaq::Application,
public toolbox::ActionListener,
public xdata::ActionListener,
public toolbox::task::TimerListener,
public b2in::utils::MessengerCacheListener
{
public:
XDAQ_INSTANTIATOR();
Application(xdaq::ApplicationStub* s) throw (xdaq::exception::Exception);
~Application();
void actionPerformed ( xdata::Event& e );
void actionPerformed( toolbox::Event& event );
void timeExpired(toolbox::task::TimerEvent& e);
//
// XGI Interface
//
void Default(xgi::Input * in, xgi::Output * out ) throw (xgi::exception::Exception);
/*! Clear exception history
*/
void reset(xgi::Input * in, xgi::Output * out ) throw (xgi::exception::Exception);
/*! View a specific exception referenced by uuid
*/
void view(xgi::Input * in, xgi::Output * out )
throw (xgi::exception::Exception);
/*! list all available exceptions
*/
void catalog(xgi::Input * in, xgi::Output * out )
throw (xgi::exception::Exception);
void events(xgi::Input * in, xgi::Output * out )
throw (xgi::exception::Exception);
void lastStoredEvents(xgi::Input * in, xgi::Output * out )
throw (xgi::exception::Exception);
/*! generate a test exception
*/
void inject(xgi::Input * in, xgi::Output * out )
throw (xgi::exception::Exception);
void generate(xgi::Input * in, xgi::Output * out )
throw (xgi::exception::Exception);
/*! Retrieve list of spotlight database files in the configured path */
/*
void files(xgi::Input * in, xgi::Output * out )
throw (xgi::exception::Exception);
*/
/*! Retrieve list of open databases */
void databases(xgi::Input * in, xgi::Output * out )
throw (xgi::exception::Exception);
/*! Attach to an additional database file in the configured directory
parameters 'dbname' and 'filename'
*/
void attach(xgi::Input * in, xgi::Output * out )
throw (xgi::exception::Exception);
/*! Detach from an attached database
parameter 'dbname'
*/
void detach(xgi::Input * in, xgi::Output * out )
throw (xgi::exception::Exception);
//
// B2IN interface
//
void onMessage (toolbox::mem::Reference * msg, xdata::Properties & plist) throw (b2in::nub::exception::Exception);
void asynchronousExceptionNotification(xcept::Exception& e);
void rearm(xgi::Input * in, xgi::Output * out ) throw (xgi::exception::Exception);
protected:
void refreshSubscriptionsToEventing() throw (sentinel::exception::Exception);
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) throw (xgi::exception::Exception);
void HotspotTabPage(xgi::Output * out) throw (xgi::exception::Exception);
void StatisticsTabPage(xgi::Output * out) throw (xgi::exception::Exception);
private:
toolbox::task::AsynchronousEventDispatcher dispatcher_;
Repository* repository_;
xdata::UnsignedInteger64T exceptionsLostCounter_;
xdata::String topic_;
xdata::String cacheMode_; // readonly,awt,playback , readwrite
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
xdata::String exceptionsTimeWindow_;
xdata::String archiveWindow_; // determine the name of the file for storing archived exceptions (default 1H )
xdata::String jelFileName_; // xml file containing junk exception filter rules
// Connection details for Oracle database
xdata::String databaseUser_;
xdata::String databasePassword_;
xdata::String databaseTnsName_;
b2in::utils::ServiceProxy* b2inEventingProxy_;
xdata::String scanPeriod_;
xdata::String subscribeExpiration_;
std::map<std::string, xdata::Properties> subscriptions_; // indexed by topic
std::list<xdata::Properties> jel_;
std::map<std::string,std::map<std::string,size_t> > jec_;
};
}
}
#endif
// $Id: DataBase.h,v 1.10 2008/11/25 13:21:03 lorsini Exp $
/*************************************************************************
* XDAQ Components for Distributed Data Acquisition *
* Copyright (C) 2000-2009, CERN. *
* All rights reserved. *
* Authors: J. Gutleber and L. Orsini *
* *
* For the licensing terms see LICENSE. *
* For the list of contributors see CREDITS. *
*************************************************************************/
#ifndef _sentinel_spotlightocci_DataBase_h_
#define _sentinel_spotlightocci_DataBase_h_
#include <string>
#include <map>
//#include <sqlite3.h>
//#include <ttclasses/TTInclude.h>
#include <occi.h>
#include "xgi/Method.h"
#include "sentinel/spotlightocci/exception/FailedToStore.h"
#include "sentinel/spotlightocci/exception/FailedToRead.h"
#include "sentinel/spotlightocci/exception/FailedToOpen.h"
#include "sentinel/spotlightocci/exception/FailedToClose.h"
#include "sentinel/spotlightocci/exception/NotFound.h"
#include "sentinel/spotlightocci/exception/FailedToArchive.h"
#include "sentinel/spotlightocci/exception/FailedToRemove.h"
#include "sentinel/spotlightocci/exception/ConstraintViolated.h"
#include "toolbox/Properties.h"
#include "toolbox/TimeVal.h"
#include "toolbox/BSem.h"
namespace sentinel
{
namespace spotlightocci
{
class DataBase
{
public:
DataBase(const std::string& filename, const std::string& username, const std::string& password, const std::string& tnsname, bool readOnly )
throw (sentinel::spotlightocci::exception::FailedToOpen);
~DataBase();
static void hasInsertedfirstRow(bool b);
void mask (double startTime, double endTime, const std::string & exception, const std::string & source, const std::string &filter )
throw (sentinel::spotlightocci::exception::FailedToStore, sentinel::spotlightocci::exception::ConstraintViolated);
void unmask (const std::string & mask, const std::string & exception, double endTime )
throw (sentinel::spotlightocci::exception::FailedToStore, sentinel::spotlightocci::exception::ConstraintViolated);
/*! Store an exception object
This function is thread safe (read/write lock)
*/
void store (xcept::Exception& ex)
throw (sentinel::spotlightocci::exception::FailedToStore, sentinel::spotlightocci::exception::ConstraintViolated);
void rearm (const std::string & exception, const std::string & source)
throw (sentinel::spotlightocci::exception::FailedToStore, sentinel::spotlightocci::exception::ConstraintViolated);
void revoke (xcept::Exception& ex)
throw (sentinel::spotlightocci::exception::FailedToStore, sentinel::spotlightocci::exception::ConstraintViolated);
/*! Store an exception, all values are in the properties object
The function does not store a chained exception (blob)
*/
void store (toolbox::Properties& properties, const std::string & blob)
throw (sentinel::spotlightocci::exception::FailedToStore, sentinel::spotlightocci::exception::ConstraintViolated);
void event (const std::string & type, toolbox::Properties& properties)
throw (sentinel::spotlightocci::exception::FailedToStore, sentinel::spotlightocci::exception::ConstraintViolated);
/*! Check if database contain the exception for uuid
*/
bool hasException (const std::string& uuid) ;
/*! Retrieve a single exception by uuid in the format it has been stored.
The name of the format is returned in \param format.
*/
void retrieve (const std::string& uuid, const std::string& format, xgi::Output* out)
throw (sentinel::spotlightocci::exception::NotFound);
/*! Return a list of stored exceptions in the \param ex set that match the search query
This function is thread safe (read lock)*/
void catalog (xgi::Output* out, toolbox::TimeVal & start, toolbox::TimeVal & end, const std::string& format)
throw (sentinel::spotlightocci::exception::NotFound);
/*! Return a list of stored exceptions in the \param ex set that match the search query , order desc by dateTime
*/
void catalog (toolbox::TimeVal & age, int (*callback)(void*,int,char**,char**) , void * context)
throw (sentinel::spotlightocci::exception::FailedToArchive);
void events (xgi::Output* out, toolbox::TimeVal & start, toolbox::TimeVal & end, const std::string& format)
throw (sentinel::spotlightocci::exception::NotFound);
toolbox::TimeVal lastStoredEvents(xgi::Output* out, toolbox::TimeVal & since, const std::string& format)
throw (sentinel::spotlightocci::exception::NotFound);
void remove(toolbox::TimeVal & age)
throw (sentinel::spotlightocci::exception::FailedToRemove);
/*! Retrieve the time at which the last exception has been stored from the database */
toolbox::TimeVal getLatestStoreTime();
/*! Retrieve the time of the most recent event in the database */
toolbox::TimeVal getLatestEventTime() throw (sentinel::spotlightocci::exception::Exception);
/*! Retrieve the time of the most recent exception in the database */
toolbox::TimeVal getLatestExceptionTime() throw (sentinel::spotlightocci::exception::Exception);
/*! Retrieve the time of the oldest exception in the database */
toolbox::TimeVal getOldestExceptionTime();
/*! Retrieve the number of exceptions stored */
std::string getNumberOfExceptions() throw (sentinel::spotlightocci::exception::Exception);
size_t getSize();
/*! Average time to store a single exception */
double getAverageTimeToStore();
/*! Average time to retrieve a catalog */
double getAverageTimeToRetrieveCatalog();
/*! Average time to retrieve a single exception by uuid */
double getAverageTimeToRetrieveException();
void writeBlob(const std::string & zKey, const std::string & zBlob)
throw (sentinel::spotlightocci::exception::FailedToStore);
void readBlob(const std::string& zKey, std::string& pzBlob)
throw (sentinel::spotlightocci::exception::FailedToRead);
std::string getFileName();
void lock();
void unlock();
// Vacuum the database, other operations TBD
//
void maintenance() throw (sentinel::spotlightocci::exception::Exception);
private:
toolbox::TimeVal outputCatalogJSON(xgi::Output* out, size_t maxRowCounter)
throw (sentinel::spotlightocci::exception::NotFound);
void prepareDatabase (bool readOnly)
throw (sentinel::spotlightocci::exception::FailedToOpen, sentinel::spotlightocci::exception::Exception);
std::string escape(const std::string& s);
toolbox::BSem lock_; // used for db management operations
//sqlite3 *db_;
/*sqlite3_stmt* insertCatalogStmt_;
sqlite3_stmt* insertExceptionStmt_;
sqlite3_stmt* insertApplicationStmt_;
sqlite3_stmt* insertEventStmt_;
sqlite3_stmt* insertMaskStmt_;*/
std::string filename_;
double averageTimeToStore_;
double averageTimeToRetrieveCatalog_;
double averageTimeToRetrieveException_;
toolbox::TimeVal lastExceptionTime_;
toolbox::TimeVal maintenanceSinceTime_;
/*TTConnection connection_;
TTCmd ttStmt_; // For generic statements
TTCmd insertCatalogStmt_;
TTCmd insertExceptionStmt_;
TTCmd insertApplicationStmt_;
TTCmd insertEventStmt_;
TTCmd insertMaskStmt_;*/
oracle::occi::Environment* environment_;
oracle::occi::Connection* connection_;
oracle::occi::Statement* occiStmt_;
oracle::occi::Statement* insertCatalogStmt_;
oracle::occi::Statement* insertExceptionStmt_;
oracle::occi::Statement* insertApplicationStmt_;
oracle::occi::Statement* insertEventStmt_;
oracle::occi::Statement* insertMaskStmt_;
oracle::occi::ResultSet* occiResult_;
};
}
}
#endif
// $Id: ExceptionEvent.h,v 1.2 2008/07/18 15:27:26 gutleber Exp $
/*************************************************************************
* XDAQ Components for Distributed Data Acquisition *
* Copyright (C) 2000-2009, CERN. *
* All rights reserved. *
* Authors: J. Gutleber and L. Orsini *
* *
* For the licensing terms see LICENSE. *
* For the list of contributors see CREDITS. *
*************************************************************************/
#ifndef _sentinel_spotlightocci_Event_h_
#define _sentinel_spotlightocci_Event_h_
#include <string>
#include "toolbox/Event.h"
#include "xcept/Exception.h"
namespace sentinel
{
namespace spotlightocci
{
/*!
An event that encapsulates an xcept Exception.
*/
class ExceptionEvent: public toolbox::Event
{
public:
ExceptionEvent(xcept::Exception* ex, const std::string & name);
~ExceptionEvent();
//! Obtain a copy of a reference to the underlying SOAP message
/*!
The underlying exception is automatically deleted when
the last user of the event gives up using the reference to the event.
*/
xcept::Exception* getException();
std::string name();
protected:
xcept::Exception* exception_;
std::string name_;
};
}}
#endif
// $Id: Repository.h,v 1.15 2008/11/25 13:21:03 lorsini Exp $
/*************************************************************************
* XDAQ Components for Distributed Data Acquisition *
* Copyright (C) 2000-2009, CERN. *
* All rights reserved. *
* Authors: J. Gutleber and L. Orsini *
* *
* For the licensing terms see LICENSE. *
* For the list of contributors see CREDITS. *
*************************************************************************/
#ifndef _sentinel_spotlightocci_Repository_h_
#define _sentinel_spotlightocci_Repository_h_