diff --git a/src/Configuration.h b/src/Configuration.h index 6267484974c490f9bbc25456fa56b6dec7b728e0..8a37bf1791ebeab3db53046d0b5df79ca5a95c84 100644 --- a/src/Configuration.h +++ b/src/Configuration.h @@ -28,20 +28,22 @@ private: std::string auxDatabaseHost, unsigned int auxDatabasePort, std::string auxDatabaseUsername, std::string auxDatabasePassword, std::string auxDatabaseSchema, std::string auxDatabaseTimestampTable, - std::string auxDatabaseFailedTable) : - m_certificateFile (certificateFile), m_storagePath(storagePath), - m_remoteHost(remoteHost), m_remotePort(remotePort), - m_remoteUsername(remoteUsername), m_remotePassword(remotePassword), - m_databaseHost(databaseHost), m_databasePort(databasePort), - m_databaseUsername(databaseUsername), m_databasePassword(databasePassword), - m_databaseSchema(databaseSchema), m_databaseTable(databaseTable), - m_refreshTime(refreshTime), m_timeout(timeout), m_recoveryTime(recoveryTime), + std::string auxDatabaseFailedTable, std::string selectKey, + std::string selectValue) : m_certificateFile (certificateFile), + m_storagePath(storagePath), m_remoteHost(remoteHost), + m_remotePort(remotePort), m_remoteUsername(remoteUsername), + m_remotePassword(remotePassword), m_databaseHost(databaseHost), + m_databasePort(databasePort), m_databaseUsername(databaseUsername), + m_databasePassword(databasePassword), m_databaseSchema(databaseSchema), + m_databaseTable(databaseTable), m_refreshTime(refreshTime), + m_timeout(timeout), m_recoveryTime(recoveryTime), m_auxDatabaseHost(auxDatabaseHost), m_auxDatabasePort(auxDatabasePort), m_auxDatabaseUsername(auxDatabaseUsername), m_auxDatabasePassword(auxDatabasePassword), m_auxDatabaseSchema(auxDatabaseSchema), m_auxDatabaseTimestampTable(auxDatabaseTimestampTable), - m_auxDatabaseFailedTable(auxDatabaseFailedTable) { }; + m_auxDatabaseFailedTable(auxDatabaseFailedTable), + m_selectKey(selectKey), m_selectValue(selectValue) { }; virtual ~Configuration() {} @@ -67,15 +69,16 @@ public: std::string auxDatabaseHost, unsigned int auxDatabasePort, std::string auxDatabaseUsername, std::string auxDatabasePassword, std::string auxDatabaseSchema, std::string auxDatabaseTimestampTable, - std::string auxDatabaseFailedTable) + std::string auxDatabaseFailedTable, std::string selectKey, + std::string selectValue) { Configuration::SP c_sp(new Configuration(certificateFile, storagePath, remoteHost, remotePort, remoteUsername, remotePassword, databaseHost, databasePort, databaseUsername, databasePassword, databaseSchema, databaseTable, refreshTime, timeout, recoveryTime, auxDatabaseHost, auxDatabasePort, auxDatabaseUsername, auxDatabasePassword, - auxDatabaseSchema, auxDatabaseTimestampTable, auxDatabaseFailedTable), - Configuration::Deleter()); + auxDatabaseSchema, auxDatabaseTimestampTable, auxDatabaseFailedTable, + selectKey, selectValue), Configuration::Deleter()); return c_sp; } @@ -105,6 +108,8 @@ public: std::string getAuxDatabaseSchema() const { return m_auxDatabaseSchema; } std::string getAuxDatabaseTimestampTable() const { return m_auxDatabaseTimestampTable; } std::string getAuxDatabaseFailedTable() const { return m_auxDatabaseFailedTable; } + std::string getSelectKey() const { return m_selectKey; } + std::string getSelectValue() const { return m_selectValue; } private: //------------------------------------------------------------------------------ @@ -175,6 +180,12 @@ private: //Auxiliary database failed table const std::string m_auxDatabaseFailedTable; + + //Files selection key + const std::string m_selectKey; + + //File selection value + const std::string m_selectValue; }; } //End of namespace diff --git a/src/DBManager.cpp b/src/DBManager.cpp index 80dad75e89f40e9d54ecb9f76e39a9033bd76a3b..44ea6f4b1abe0b36dcbec9afaa670e6f978b6f03 100644 --- a/src/DBManager.cpp +++ b/src/DBManager.cpp @@ -202,12 +202,30 @@ DBManager::FileRowsetSP DBManager::retrieveNewFiles(boost::posix_time::ptime pti if(m_mainSession_sp->get_backend() == NULL) m_mainSession_sp->reconnect(); - FileRowsetSP newFileRowset_sp(new FileRowset(m_mainSession_sp->prepare - << "select storage_path, file_path, file_version, file_name, update_time " - << "from " << m_configuration_sp->getDatabaseSchema() << "." - << m_configuration_sp->getDatabaseTable() << " where update_time>'" - << boost::posix_time::to_iso_string(ptime) << "' order by update_time asc")); - + std::string selectKey = m_configuration_sp->getSelectKey(); + std::string selectValue = m_configuration_sp->getSelectValue(); + + FileRowsetSP newFileRowset_sp; + + if(selectKey.empty()) + { + newFileRowset_sp.reset(new FileRowset(m_mainSession_sp->prepare + << "select storage_path, file_path, file_version, file_name, update_time " + << "from " << m_configuration_sp->getDatabaseSchema() << "." + << m_configuration_sp->getDatabaseTable() << " where update_time>'" + << boost::posix_time::to_iso_string(ptime) << "' order by update_time asc")); + } + else + { + newFileRowset_sp.reset(new FileRowset(m_mainSession_sp->prepare + << "select storage_path, file_path, file_version, file_name, update_time " + << "from " << m_configuration_sp->getDatabaseSchema() << "." + << m_configuration_sp->getDatabaseTable() << " where update_time>'" + << boost::posix_time::to_iso_string(ptime) << "' and " + << selectKey << " like '%" << selectValue << "%' " + << "order by update_time asc")); + } + return newFileRowset_sp; } @@ -289,7 +307,7 @@ DBManager::FileRowsetSP DBManager::retrieveFailedFiles() FileRowsetSP failedFileRowset_sp(new FileRowset( m_auxSession_sp->prepare << "select m.storage_path, m.file_path, " << " m.file_version, m.file_name, m.update_time from " - << m_configuration_sp->getDatabaseSchema() << "." + << m_configuration_sp->getDatabaseSchema() << "." << m_configuration_sp->getDatabaseTable() << " as m join " << m_configuration_sp->getAuxDatabaseSchema() << "." << m_configuration_sp->getAuxDatabaseFailedTable() << " as f " diff --git a/src/DataImporter.cpp b/src/DataImporter.cpp index b4618cd25d19ec26d97582c60b5da88bbceecd10..4e95977e4d98c8a8e989767c188175dfc7ec5b08 100644 --- a/src/DataImporter.cpp +++ b/src/DataImporter.cpp @@ -238,6 +238,8 @@ void DataImporter::get_device_property() dev_prop.push_back(Tango::DbDatum("AuxDatabaseSchema")); dev_prop.push_back(Tango::DbDatum("AuxDatabaseTimestampTable")); dev_prop.push_back(Tango::DbDatum("AuxDatabaseFailedTable")); + dev_prop.push_back(Tango::DbDatum("SelectKey")); + dev_prop.push_back(Tango::DbDatum("SelectValue")); // is there at least one property to be read ? if (dev_prop.size()>0) @@ -516,6 +518,28 @@ void DataImporter::get_device_property() // And try to extract AuxDatabaseFailedTable value from database if (dev_prop[i].is_empty()==false) dev_prop[i] >> auxDatabaseFailedTable; + // Try to initialize SelectKey from class property + cl_prop = ds_class->get_class_property(dev_prop[++i].name); + if (cl_prop.is_empty()==false) cl_prop >> selectKey; + else { + // Try to initialize SelectKey from default device value + def_prop = ds_class->get_default_device_property(dev_prop[i].name); + if (def_prop.is_empty()==false) def_prop >> selectKey; + } + // And try to extract SelectKey value from database + if (dev_prop[i].is_empty()==false) dev_prop[i] >> selectKey; + + // Try to initialize SelectValue from class property + cl_prop = ds_class->get_class_property(dev_prop[++i].name); + if (cl_prop.is_empty()==false) cl_prop >> selectValue; + else { + // Try to initialize SelectValue from default device value + def_prop = ds_class->get_default_device_property(dev_prop[i].name); + if (def_prop.is_empty()==false) def_prop >> selectValue; + } + // And try to extract SelectValue value from database + if (dev_prop[i].is_empty()==false) dev_prop[i] >> selectValue; + } /*----- PROTECTED REGION ID(DataImporter::get_device_property_after) ENABLED START -----*/ @@ -595,12 +619,16 @@ void DataImporter::get_device_property() if(auxDatabaseFailedTable.empty()) throw(invalid_argument("AuxDatabaseFailedTable property is empty or not defined")); + if(!selectKey.empty() && selectValue.empty()) + throw(invalid_argument("SelectValue property is empty or not defined, but SelectKey is defined")); + m_configuration_sp = Configuration::create(certificateFile, storagePath, remoteHost, remotePort, remoteUsername, remotePassword, databaseHost, databasePort, databaseUsername, databasePassword, databaseSchema, databaseTable, refreshTime, timeout, recoveryTime, auxDatabaseHost, auxDatabasePort, auxDatabaseUsername, auxDatabasePassword, - auxDatabaseSchema, auxDatabaseTimestampTable, auxDatabaseFailedTable); + auxDatabaseSchema, auxDatabaseTimestampTable, + auxDatabaseFailedTable, selectKey, selectValue); } catch(invalid_argument& ex) { @@ -621,7 +649,7 @@ void DataImporter::get_device_property() //-------------------------------------------------------- void DataImporter::always_executed_hook() { - DEBUG_STREAM << "DataImporter::always_executed_hook() " << device_name << endl; + INFO_STREAM << "DataImporter::always_executed_hook() " << device_name << endl; /*----- PROTECTED REGION ID(DataImporter::always_executed_hook) ENABLED START -----*/ if(get_state() != Tango::FAULT) diff --git a/src/DataImporter.h b/src/DataImporter.h index dbdb4f59d670ccefc47a74f3d5da687283a721a9..7c4b3911d5d394248c81c6838fc0378dae0ca7d3 100644 --- a/src/DataImporter.h +++ b/src/DataImporter.h @@ -48,7 +48,7 @@ /** * DataImporter class description: - * + * */ namespace DataImporter_ns @@ -95,173 +95,177 @@ class DataImporter : public TANGO_BASE_CLASS // Device property data members public: - // CertificateFile: Absolute path to certificate chain file - string certificateFile; - // StoragePath: Absolute path to storage - string storagePath; - // RemoteHost: Metadata exporter remote host - string remoteHost; - // RemotePort: Metadata exporter remote port - Tango::DevULong remotePort; - // RemoteUsername: Metadata exporter login username - string remoteUsername; - // RemotePassword: Metadata exporter remote password - string remotePassword; - // EnableSSL: Enable or disable SSL connections - Tango::DevBoolean enableSSL; - // DatabaseHost: Metadata local database host - string databaseHost; - // DatabasePort: Metadata local database port - Tango::DevULong databasePort; - // DatabaseUsername: Metadata local database username - string databaseUsername; - // DatabasePassword: Metadata local database password - string databasePassword; - // DatabaseSchema: Metadata local database schema - string databaseSchema; - // DatabaseTable: Metadata local database table - string databaseTable; - // RefreshTime: Local database request period (seconds) - Tango::DevULong refreshTime; - // Timeout: Connection timeout (seconds) - Tango::DevULong timeout; - // RecoveryTime: Time between failed file download attempt - Tango::DevULong recoveryTime; - // AutoStart: Exec On command after init if state is not fault - Tango::DevBoolean autoStart; - // AuxDatabaseHost: File transfer auxiliary database host - string auxDatabaseHost; - // AuxDatabasePort: File transfer auxiliary database port - Tango::DevULong auxDatabasePort; - // AuxDatabaseUsername: File transfer auxiliary database username - string auxDatabaseUsername; - // AuxDatabasePassword: File transfer auxiliary database password - string auxDatabasePassword; - // AuxDatabaseSchema: File transfer auxiliary database schema - string auxDatabaseSchema; - // AuxDatabaseTimestampTable: File transfer auxiliary database device timestamp table - string auxDatabaseTimestampTable; - // AuxDatabaseFailedTable: File transfer auxiliary database failed transfer table - string auxDatabaseFailedTable; - -// Attribute data members + // CertificateFile: Absolute path to certificate chain file + string certificateFile; + // StoragePath: Absolute path to storage + string storagePath; + // RemoteHost: Metadata exporter remote host + string remoteHost; + // RemotePort: Metadata exporter remote port + Tango::DevULong remotePort; + // RemoteUsername: Metadata exporter login username + string remoteUsername; + // RemotePassword: Metadata exporter remote password + string remotePassword; + // EnableSSL: Enable or disable SSL connections + Tango::DevBoolean enableSSL; + // DatabaseHost: Metadata local database host + string databaseHost; + // DatabasePort: Metadata local database port + Tango::DevULong databasePort; + // DatabaseUsername: Metadata local database username + string databaseUsername; + // DatabasePassword: Metadata local database password + string databasePassword; + // DatabaseSchema: Metadata local database schema + string databaseSchema; + // DatabaseTable: Metadata local database table + string databaseTable; + // RefreshTime: Local database request period (seconds) + Tango::DevULong refreshTime; + // Timeout: Connection timeout (seconds) + Tango::DevULong timeout; + // RecoveryTime: Time between failed file download attempt + Tango::DevULong recoveryTime; + // AutoStart: Exec On command after init if state is not fault + Tango::DevBoolean autoStart; + // AuxDatabaseHost: File transfer auxiliary database host + string auxDatabaseHost; + // AuxDatabasePort: File transfer auxiliary database port + Tango::DevULong auxDatabasePort; + // AuxDatabaseUsername: File transfer auxiliary database username + string auxDatabaseUsername; + // AuxDatabasePassword: File transfer auxiliary database password + string auxDatabasePassword; + // AuxDatabaseSchema: File transfer auxiliary database schema + string auxDatabaseSchema; + // AuxDatabaseTimestampTable: File transfer auxiliary database device timestamp table + string auxDatabaseTimestampTable; + // AuxDatabaseFailedTable: File transfer auxiliary database failed transfer table + string auxDatabaseFailedTable; + // SelectKey: Files delivery selection key + string selectKey; + // SelectValue: Files delivery selection value + string selectValue; + +// Attribute data members public: - Tango::DevULong *attr_RegularFileCounter_read; - Tango::DevULong *attr_FailedFileCounter_read; + Tango::DevULong *attr_RegularFileCounter_read; + Tango::DevULong *attr_FailedFileCounter_read; -// Constructors and destructors +// Constructors and destructors public: - /** - * Constructs a newly device object. - * - * @param cl Class. - * @param s Device Name - */ - DataImporter(Tango::DeviceClass *cl,string &s); - /** - * Constructs a newly device object. - * - * @param cl Class. - * @param s Device Name - */ - DataImporter(Tango::DeviceClass *cl,const char *s); - /** - * Constructs a newly device object. - * - * @param cl Class. - * @param s Device name - * @param d Device description. - */ - DataImporter(Tango::DeviceClass *cl,const char *s,const char *d); - /** - * The device object destructor. - */ - ~DataImporter() {delete_device();}; - - -// Miscellaneous methods + /** + * Constructs a newly device object. + * + * @param cl Class. + * @param s Device Name + */ + DataImporter(Tango::DeviceClass *cl,string &s); + /** + * Constructs a newly device object. + * + * @param cl Class. + * @param s Device Name + */ + DataImporter(Tango::DeviceClass *cl,const char *s); + /** + * Constructs a newly device object. + * + * @param cl Class. + * @param s Device name + * @param d Device description. + */ + DataImporter(Tango::DeviceClass *cl,const char *s,const char *d); + /** + * The device object destructor. + */ + ~DataImporter() {delete_device();}; + + +// Miscellaneous methods public: - /* - * will be called at device destruction or at init command. - */ - void delete_device(); - /* - * Initialize the device - */ - virtual void init_device(); - /* - * Read the device properties from database - */ - void get_device_property(); - /* - * Always executed method before execution command method. - */ - virtual void always_executed_hook(); - - -// Attribute methods + /* + * will be called at device destruction or at init command. + */ + void delete_device(); + /* + * Initialize the device + */ + virtual void init_device(); + /* + * Read the device properties from database + */ + void get_device_property(); + /* + * Always executed method before execution command method. + */ + virtual void always_executed_hook(); + + +// Attribute methods public: - //-------------------------------------------------------- - /* - * Method : DataImporter::read_attr_hardware() - * Description : Hardware acquisition for attributes. - */ - //-------------------------------------------------------- - virtual void read_attr_hardware(vector<long> &attr_list); - - /** - * Attribute RegularFileCounter related methods - * Description: - * - * Data type: Tango::DevULong - * Attr type: Scalar - */ - virtual void read_RegularFileCounter(Tango::Attribute &attr); - virtual bool is_RegularFileCounter_allowed(Tango::AttReqType type); - /** - * Attribute FailedFileCounter related methods - * Description: - * - * Data type: Tango::DevULong - * Attr type: Scalar - */ - virtual void read_FailedFileCounter(Tango::Attribute &attr); - virtual bool is_FailedFileCounter_allowed(Tango::AttReqType type); - - - //-------------------------------------------------------- - /** - * Method : DataImporter::add_dynamic_attributes() - * Description : Add dynamic attributes if any. - */ - //-------------------------------------------------------- - void add_dynamic_attributes(); - - - -// Command related methods + //-------------------------------------------------------- + /* + * Method : DataImporter::read_attr_hardware() + * Description : Hardware acquisition for attributes. + */ + //-------------------------------------------------------- + virtual void read_attr_hardware(vector<long> &attr_list); + +/** + * Attribute RegularFileCounter related methods + * Description: + * + * Data type: Tango::DevULong + * Attr type: Scalar + */ + virtual void read_RegularFileCounter(Tango::Attribute &attr); + virtual bool is_RegularFileCounter_allowed(Tango::AttReqType type); +/** + * Attribute FailedFileCounter related methods + * Description: + * + * Data type: Tango::DevULong + * Attr type: Scalar + */ + virtual void read_FailedFileCounter(Tango::Attribute &attr); + virtual bool is_FailedFileCounter_allowed(Tango::AttReqType type); + + + //-------------------------------------------------------- + /** + * Method : DataImporter::add_dynamic_attributes() + * Description : Add dynamic attributes if any. + */ + //-------------------------------------------------------- + void add_dynamic_attributes(); + + + +// Command related methods public: - /** - * Command On related method - * Description: Activate data importer - * - */ - virtual void on(); - virtual bool is_On_allowed(const CORBA::Any &any); - /** - * Command Off related method - * Description: Deactivate data importer - * - */ - virtual void off(); - virtual bool is_Off_allowed(const CORBA::Any &any); - /** - * Command ResetCounter related method - * Description: - * - */ - virtual void reset_counter(); - virtual bool is_ResetCounter_allowed(const CORBA::Any &any); + /** + * Command On related method + * Description: Activate data importer + * + */ + virtual void on(); + virtual bool is_On_allowed(const CORBA::Any &any); + /** + * Command Off related method + * Description: Deactivate data importer + * + */ + virtual void off(); + virtual bool is_Off_allowed(const CORBA::Any &any); + /** + * Command ResetCounter related method + * Description: + * + */ + virtual void reset_counter(); + virtual bool is_ResetCounter_allowed(const CORBA::Any &any); /*----- PROTECTED REGION ID(DataImporter::Additional Method prototypes) ENABLED START -----*/ diff --git a/src/DataImporter.xmi b/src/DataImporter.xmi index 496f8db25965936f9760b13404c334a1e47e9891..b627143ba5371b85e464bcf238c84b06890fa1ee 100644 --- a/src/DataImporter.xmi +++ b/src/DataImporter.xmi @@ -141,6 +141,14 @@ <type xsi:type="pogoDsl:StringType"/> <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> </deviceProperties> + <deviceProperties name="SelectKey" description="Files delivery selection key"> + <type xsi:type="pogoDsl:StringType"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </deviceProperties> + <deviceProperties name="SelectValue" description="Files delivery selection value"> + <type xsi:type="pogoDsl:StringType"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </deviceProperties> <commands name="State" description="This command gets the device state (stored in its device_state data member) and returns it to the caller." execMethod="dev_state" displayLevel="OPERATOR" polledPeriod="0"> <argin description="none"> <type xsi:type="pogoDsl:VoidType"/> diff --git a/src/DataImporterClass.cpp b/src/DataImporterClass.cpp index e5852054b28dd8eea5a7040b0472da0d0b75f7bb..ff07739147977f71f9a89d98893975c9e008b975 100644 --- a/src/DataImporterClass.cpp +++ b/src/DataImporterClass.cpp @@ -859,6 +859,32 @@ void DataImporterClass::set_default_property() } else add_wiz_dev_prop(prop_name, prop_desc); + prop_name = "SelectKey"; + prop_desc = "Files delivery selection key"; + prop_def = ""; + vect_data.clear(); + if (prop_def.length()>0) + { + Tango::DbDatum data(prop_name); + data << vect_data ; + dev_def_prop.push_back(data); + add_wiz_dev_prop(prop_name, prop_desc, prop_def); + } + else + add_wiz_dev_prop(prop_name, prop_desc); + prop_name = "SelectValue"; + prop_desc = "Files delivery selection value"; + prop_def = ""; + vect_data.clear(); + if (prop_def.length()>0) + { + Tango::DbDatum data(prop_name); + data << vect_data ; + dev_def_prop.push_back(data); + add_wiz_dev_prop(prop_name, prop_desc, prop_def); + } + else + add_wiz_dev_prop(prop_name, prop_desc); } //--------------------------------------------------------