Commit 6eaeedd6 authored by Marco De Marco's avatar Marco De Marco
Browse files

Sql dump added, event list now vector, exception handler added

parent 4f290d05
Loading
Loading
Loading
Loading
+124 −0
Original line number Diff line number Diff line
-- MySQL dump 10.13  Distrib 5.5.31, for debian-linux-gnu (x86_64)
--
-- Host: localhost    Database: data_model
-- ------------------------------------------------------
-- Server version	5.5.31-0+wheezy1

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;

--
-- Table structure for table `destination`
--

DROP TABLE IF EXISTS `destination`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `destination` (
  `id` mediumint(9) NOT NULL AUTO_INCREMENT,
  `host` varchar(255) NOT NULL,
  `port` smallint(5) unsigned NOT NULL,
  `user` varchar(255) NOT NULL,
  `password` varchar(255) NOT NULL,
  `schema_name` varchar(255) NOT NULL,
  `table_name` varchar(255) NOT NULL,
  `storage_path` varchar(255) NOT NULL,
  `comment` text,
  `update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `destination`
--

LOCK TABLES `destination` WRITE;
/*!40000 ALTER TABLE `destination` DISABLE KEYS */;
INSERT INTO `destination` VALUES (1,'localhost',3306,'almausr','Almausr123','metadata','lucifer','/mnt/storage/lucifer',NULL,'2013-05-02 12:58:51'),(2,'localhost',3306,'almausr','Almausr123','metadata','fgs','/mnt/storage/fgs',NULL,'2013-05-02 12:59:00'),(3,'localhost',3306,'almausr','Almausr123','metadata','warning','/mnt/storage/warning',NULL,'2013-05-23 10:50:20');
/*!40000 ALTER TABLE `destination` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `instrument`
--

DROP TABLE IF EXISTS `instrument`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `instrument` (
  `id` mediumint(9) NOT NULL AUTO_INCREMENT,
  `name` varchar(255) NOT NULL,
  `fits_key` varchar(255) NOT NULL,
  `fits_value` varchar(255) NOT NULL,
  `dest_id` mediumint(9) NOT NULL,
  `comment` text,
  `update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  UNIQUE KEY `name` (`name`),
  KEY `dest_id` (`dest_id`),
  CONSTRAINT `instrument_destination_key` FOREIGN KEY (`dest_id`) REFERENCES `destination` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `instrument`
--

LOCK TABLES `instrument` WRITE;
/*!40000 ALTER TABLE `instrument` DISABLE KEYS */;
INSERT INTO `instrument` VALUES (1,'Lucifer','INSTRUME','Lucifer',1,NULL,'2013-05-13 08:18:16'),(2,'FGS','INSTRUME','FGS',2,NULL,'2013-05-02 13:31:24'),(3,'Default','Default','Default',3,NULL,'2013-05-23 10:56:06');
/*!40000 ALTER TABLE `instrument` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `mapping`
--

DROP TABLE IF EXISTS `mapping`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `mapping` (
  `id` mediumint(9) NOT NULL AUTO_INCREMENT,
  `dest_id` mediumint(9) NOT NULL,
  `column_name` varchar(255) NOT NULL,
  `column_type` varchar(255) NOT NULL,
  `fits_key_pri` varchar(255) NOT NULL,
  `fits_key_sec` varchar(255) DEFAULT NULL,
  `mandatory` tinyint(1) NOT NULL DEFAULT '0',
  `comment` text,
  `update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  UNIQUE KEY `dest_id_column_name` (`dest_id`,`column_name`),
  CONSTRAINT `mapping_destination_key` FOREIGN KEY (`dest_id`) REFERENCES `destination` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `mapping`
--

LOCK TABLES `mapping` WRITE;
/*!40000 ALTER TABLE `mapping` DISABLE KEYS */;
INSERT INTO `mapping` VALUES (1,2,'root_name','string','ROOTNAME','ROOTNAME',0,NULL,'2013-05-08 12:29:59'),(2,2,'prime','string','PRIMESI','PRIMESI',0,NULL,'2013-05-08 12:31:54'),(3,1,'date_obs','string','DATE-OBS','DATE-OBS',0,NULL,'2013-05-14 13:34:16'),(4,1,'ra_obs','string','RA','RA',0,NULL,'2013-05-14 13:34:46'),(5,1,'dec_obs','string','DEC','DEC',0,NULL,'2013-05-14 13:35:00');
/*!40000 ALTER TABLE `mapping` ENABLE KEYS */;
UNLOCK TABLES;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;

/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;

-- Dump completed on 2013-08-07 10:08:40

src/Configuration.h

0 → 100644
+116 −0
Original line number Diff line number Diff line
#ifndef CONFIGURATION_H
#define CONFIGURATION_H
/*******************************************************************************
* ALMA - Atacama Large Millimiter Array
* Copyright (c) UNSPECIFIED - FILL IN, 2013 
* 
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
* 
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
* Lesser General Public License for more details.
* 
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
*
* "@(#) $Id$"
*
* who       when      what
* --------  --------  ----------------------------------------------
* almadev  2013-03-28  created
*/

/************************************************************************
 *
 *----------------------------------------------------------------------
 */

#ifndef __cplusplus
#error This is a C++ include file and cannot be used from plain C
#endif

#include <iostream>
#include <unistd.h>
#include <vector>

#include <boost/shared_ptr.hpp>

class Configuration
{
public:
//------------------------------------------------------------------------------
//	Public shared pointer typedef	
//------------------------------------------------------------------------------
	typedef boost::shared_ptr<Configuration> SP;
	typedef std::vector< SP > SPVector;

private:
//------------------------------------------------------------------------------
//	Private constructor destructor and deleter
//------------------------------------------------------------------------------
	Configuration(std::string name, std::string watchPath, int workerNumber,
		int sleepTime, int waitTime, int connectionNumber, uint32_t iNotifyMask):
		m_name(name), m_watchPath(watchPath), m_workerNumber(workerNumber),
		m_sleepTime(sleepTime), m_waitTime(waitTime),
		m_connectionNumber(connectionNumber), m_iNotifyMask(iNotifyMask) {}
	virtual ~Configuration() {}

	class deleter;
	friend class deleter;
	class deleter
	{
	public:
		void operator()(Configuration* c) { delete c; }
	};

public:
//------------------------------------------------------------------------------
//	Public methods
//------------------------------------------------------------------------------
	static Configuration::SP create(std::string name, std::string watchPath,
		int workerNumber, int sleepTime, int waitTime, 
		int connectionNumber, uint32_t iNotifyMask)
	{
		Configuration::SP c_sp(new Configuration(name, watchPath,
			 workerNumber, sleepTime, waitTime, connectionNumber,
			 iNotifyMask), Configuration::deleter());
		return c_sp;
	}			

	std::string getName() const { return m_name; }
	std::string getWatchPath() const { return m_watchPath; }
	int getWorkerNumber() const { return m_workerNumber; }
	int getSleepTime() const { return m_sleepTime; }
	int getWaitTime() const { return m_waitTime; }
	int getConnectionNumber() const { return m_connectionNumber; }
	uint32_t getINotifyMask() const { return m_iNotifyMask; }

private:
	//Component name
	const std::string m_name;

	//INotify watch path
	const std::string m_watchPath;

	//Worker thread number	
	const int m_workerNumber;

	//Worker thread sleep time
	const int m_sleepTime;

	//Worker thread wait time
	const int m_waitTime;

	//Number of connection per destination
	const int m_connectionNumber;

	//INotify mask
	const uint32_t m_iNotifyMask;
};

#endif /*!CONFIGURATION_H*/

src/Destination.h

0 → 100644
+123 −0
Original line number Diff line number Diff line
#ifndef DESTINATION_H
#define DESTINATION_H
/*******************************************************************************
* ALMA - Atacama Large Millimiter Array
* Copyright (c) UNSPECIFIED - FILL IN, 2013 
* 
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
* 
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
* Lesser General Public License for more details.
* 
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
*
* "@(#) $Id$"
*
* who       when      what
* --------  --------  ----------------------------------------------
* almadev  2013-03-28  created
*/

/************************************************************************
 *
 *----------------------------------------------------------------------
 */

#ifndef __cplusplus
#error This is a C++ include file and cannot be used from plain C
#endif

#include <iostream>
#include <vector>

#include <boost/shared_ptr.hpp>

#include <Mapping.h>

class Destination
{
public:
//------------------------------------------------------------------------------
//	Public shared pointer typedef	
//------------------------------------------------------------------------------
	typedef boost::shared_ptr<Destination> SP;
	typedef std::vector< Destination::SP > SPVector;

private:
//------------------------------------------------------------------------------
//	Private constructor destructor and deleter
//------------------------------------------------------------------------------
	Destination(std::string host, int port, std::string user, std::string password,
		std::string schema, std::string table, std::string storagePath, 
		std::vector< boost::shared_ptr<Mapping> >& mapping_spvector) :
		m_host(host), m_port(port), m_user(user), m_password(password),
		m_schema(schema), m_table(table), m_storagePath(storagePath),
		m_mapping_spvector(mapping_spvector) {}
	~Destination() {}

	class deleter;
	friend class deleter;
	class deleter
	{
	public:
		void operator()(Destination* d) { delete d; }
	};

public:
//------------------------------------------------------------------------------
//	Public methods
//------------------------------------------------------------------------------
	static Destination::SP create( std::string host, int port,
		std::string user, std::string password, std::string schema,
		std::string table, std::string storagePath, 
		Mapping::SPVector& mapping_spvector)
	{
		Destination::SP d_sp( new Destination(host, port, user, password,
			schema, table, storagePath, mapping_spvector), 
			Destination::deleter() );
		return d_sp;
	}

	std::string getHost() const { return m_host; }
	int getPort() const { return m_port; }
	std::string getUser() const { return m_user; }
	std::string getPassword() const { return m_password; }
	std::string getSchema() const { return m_schema; }
	std::string getTable() const { return m_table; }
	std::string getStoragePath() const { return m_storagePath; }
	Mapping::SPVector getMappingSPVector() const { return m_mapping_spvector; }

private:
	//Metadata database host
	const std::string m_host;

	//Metadata database port 
	const int m_port;

	//Metadata database user
	const std::string m_user;

	//Metadata database user
	const std::string m_password;

	//Metadata database user
	const std::string m_schema;

	//Metadata database user
	const std::string m_table;

	//Metadata file storage path
	const std::string m_storagePath;

	//Mapping vector
	const Mapping::SPVector m_mapping_spvector;
};

#endif /*!DESTINATION_H*/
+26 −3
Original line number Diff line number Diff line
@@ -143,7 +143,8 @@ void FitsImporter::init_device()
	DEBUG_STREAM << "FitsImporter::init_device() create device " << device_name << endl;
	/*----- PROTECTED REGION ID(FitsImporter::init_device_before) ENABLED START -----*/
	
	//	Initialization before get_device_property() call
	set_state(Tango::INIT);
        set_status("Initializing device");
	
	/*----- PROTECTED REGION END -----*/	//	FitsImporter::init_device_before
	
@@ -393,7 +394,10 @@ void FitsImporter::always_executed_hook()
	INFO_STREAM << "FitsImporter::always_executed_hook()  " << device_name << endl;
	/*----- PROTECTED REGION ID(FitsImporter::always_executed_hook) ENABLED START -----*/
	
	//	code always executed before all requests
	if(get_state() != Tango::FAULT)
        {
            //TODO: change state and status
        }
	
	/*----- PROTECTED REGION END -----*/	//	FitsImporter::always_executed_hook
}
@@ -536,7 +540,26 @@ void FitsImporter::reset_counter()

/*----- PROTECTED REGION ID(FitsImporter::namespace_ending) ENABLED START -----*/

//	Additional Methods
void FitsImporter::exception_handler(Tango::DevFailed& ex, 
        Tango::DevState new_state, const std::string base_msg)
{
    DEBUG_STREAM << "FitsImporter::ExceptionHandler()  - " << device_name << endl;

    std::stringstream error_msg;
    error_msg << base_msg << " : " << std::endl;
    
    for(unsigned int i=0; i<ex.errors.length(); i++)
    {
        error_msg << ex.errors[i].reason.in() << std::endl;
        error_msg << ex.errors[i].desc.in() << std::endl;
        error_msg << ex.errors[i].origin.in() << std::endl;
    }
    
    error_msg << std::endl;
    
    set_state(new_state);
    set_status(error_msg.str());
}

/*----- PROTECTED REGION END -----*/	//	FitsImporter::namespace_ending
} //	namespace
+2 −2
Original line number Diff line number Diff line
@@ -92,7 +92,7 @@ public:
	//	WaitTime:	Time fits importer has to sleep between new time event and ingestion
	Tango::DevULong	waitTime;
	//	InstrumentList:	List of instrument used by fits importer when ingesting file
	string	instrumentList;
	vector<string>	instrumentList;
	//	DefaultInstrument:	Default instrument used by fits importer when:
	//  1) no instrument match with file
	//  2) an error occurs during metadata extraction
@@ -246,7 +246,7 @@ public:

/*----- PROTECTED REGION ID(FitsImporter::Additional Method prototypes) ENABLED START -----*/

//	Additional Method prototypes
        void exception_handler(Tango::DevFailed&, Tango::DevState, const std::string);

/*----- PROTECTED REGION END -----*/	//	FitsImporter::Additional Method prototypes
};
Loading