From 2fc9a0742e957a74821584e286c21e26f9d5053c Mon Sep 17 00:00:00 2001 From: Andrea Bignamini <bignamini@oats.inaf.it> Date: Fri, 5 May 2017 12:25:54 +0200 Subject: [PATCH] Add remoteSchema and remoteTable The remoteSchema and remoteTable device properties have been added. The schema and the table names on the local machine can be different with respect to the names in the remote machine. --- src/Configuration.h | 13 ++++++++++++- src/DataImporter.cpp | 34 +++++++++++++++++++++++++++++++++- src/DataImporter.h | 4 ++++ src/DataImporter.xmi | 8 ++++++++ src/DataImporterClass.cpp | 26 ++++++++++++++++++++++++++ src/ProtocolManager.cpp | 4 ++-- 6 files changed, 85 insertions(+), 4 deletions(-) diff --git a/src/Configuration.h b/src/Configuration.h index 0ba9b20..2e41455 100644 --- a/src/Configuration.h +++ b/src/Configuration.h @@ -21,6 +21,7 @@ private: Configuration(std::string certificateFile, std::string storagePath, std::string remoteHost, unsigned int remotePort, std::string remoteUsername, std::string remotePassword, + std::string remoteSchema, std::string remoteTable, std::string databaseHost, unsigned int databasePort, std::string databaseUsername, std::string databasePassword, std::string databaseSchema, std::string databaseTable, @@ -32,6 +33,7 @@ private: m_certificateFile (certificateFile), m_storagePath(storagePath), m_remoteHost(remoteHost), m_remotePort(remotePort), m_remoteUsername(remoteUsername), m_remotePassword(remotePassword), + m_remoteSchema(remoteSchema), m_remoteTable(remoteTable), m_databaseHost(databaseHost), m_databasePort(databasePort), m_databaseUsername(databaseUsername), m_databasePassword(databasePassword), m_databaseSchema(databaseSchema), @@ -62,6 +64,7 @@ public: static Configuration::SP create(std::string certificateFile, std::string storagePath, std::string remoteHost, unsigned int remotePort, std::string remoteUsername, std::string remotePassword, + std::string remoteSchema, std::string remoteTable, std::string databaseHost, unsigned int databasePort, std::string databaseUsername, std::string databasePassword, std::string databaseSchema, std::string databaseTable, @@ -72,7 +75,7 @@ public: std::string auxDatabaseFailedTable, std::string whereCondition) { Configuration::SP c_sp(new Configuration(certificateFile, storagePath, - remoteHost, remotePort, remoteUsername, remotePassword, databaseHost, + remoteHost, remotePort, remoteUsername, remotePassword, remoteSchema, remoteTable, databaseHost, databasePort, databaseUsername, databasePassword, databaseSchema, databaseTable, refreshTime, timeout, recoveryTime, auxDatabaseHost, auxDatabasePort, auxDatabaseUsername, auxDatabasePassword, @@ -91,6 +94,8 @@ public: unsigned int getRemotePort() const { return m_remotePort; } std::string getRemoteUsername() const { return m_remoteUsername; } std::string getRemotePassword() const { return m_remotePassword; } + std::string getRemoteSchema() const { return m_remoteSchema; } + std::string getRemoteTable() const { return m_remoteTable; } std::string getDatabaseHost() const { return m_databaseHost; } unsigned int getDatabasePort() const { return m_databasePort; } std::string getDatabaseUsername() const { return m_databaseUsername; } @@ -131,6 +136,12 @@ private: //Metadata exporter remote password const std::string m_remotePassword; + //Metadata remote database schema + const std::string m_remoteSchema; + + //Metadata remote database table + const std::string m_remoteTable; + //Metadata local database host const std::string m_databaseHost; diff --git a/src/DataImporter.cpp b/src/DataImporter.cpp index 4955f0d..d2c4e51 100644 --- a/src/DataImporter.cpp +++ b/src/DataImporter.cpp @@ -220,6 +220,8 @@ void DataImporter::get_device_property() dev_prop.push_back(Tango::DbDatum("RemotePort")); dev_prop.push_back(Tango::DbDatum("RemoteUsername")); dev_prop.push_back(Tango::DbDatum("RemotePassword")); + dev_prop.push_back(Tango::DbDatum("RemoteSchema")); + dev_prop.push_back(Tango::DbDatum("RemoteTable")); dev_prop.push_back(Tango::DbDatum("EnableSSL")); dev_prop.push_back(Tango::DbDatum("DatabaseHost")); dev_prop.push_back(Tango::DbDatum("DatabasePort")); @@ -319,6 +321,28 @@ void DataImporter::get_device_property() // And try to extract RemotePassword value from database if (dev_prop[i].is_empty()==false) dev_prop[i] >> remotePassword; + // Try to initialize RemoteSchema from class property + cl_prop = ds_class->get_class_property(dev_prop[++i].name); + if (cl_prop.is_empty()==false) cl_prop >> remoteSchema; + else { + // Try to initialize RemoteSchema from default device value + def_prop = ds_class->get_default_device_property(dev_prop[i].name); + if (def_prop.is_empty()==false) def_prop >> remoteSchema; + } + // And try to extract RemoteSchema value from database + if (dev_prop[i].is_empty()==false) dev_prop[i] >> remoteSchema; + + // Try to initialize RemoteTable from class property + cl_prop = ds_class->get_class_property(dev_prop[++i].name); + if (cl_prop.is_empty()==false) cl_prop >> remoteTable; + else { + // Try to initialize RemoteTable from default device value + def_prop = ds_class->get_default_device_property(dev_prop[i].name); + if (def_prop.is_empty()==false) def_prop >> remoteTable; + } + // And try to extract RemoteTable value from database + if (dev_prop[i].is_empty()==false) dev_prop[i] >> remoteTable; + // Try to initialize EnableSSL from class property cl_prop = ds_class->get_class_property(dev_prop[++i].name); if (cl_prop.is_empty()==false) cl_prop >> enableSSL; @@ -559,6 +583,14 @@ void DataImporter::get_device_property() if(remotePassword.empty()) throw(invalid_argument("RemotePassword property is empty or not defined")); + // If remoteSchema is not set, use databaseSchema + if(remoteSchema.empty()) + remoteSchema=databaseSchema; + + // If remoteTable is not set, use databaseTable + if(remoteTable.empty()) + remoteTable=databaseTable; + if(databaseHost.empty()) throw(invalid_argument("DatabaseHost property is empty or not defined")); @@ -608,7 +640,7 @@ void DataImporter::get_device_property() throw(invalid_argument("AuxDatabaseFailedTable property is empty or not defined")); m_configuration_sp = Configuration::create(certificateFile, storagePath, - remoteHost, remotePort, remoteUsername, remotePassword, databaseHost, + remoteHost, remotePort, remoteUsername, remotePassword, remoteSchema, remoteTable, databaseHost, databasePort, databaseUsername, databasePassword, databaseSchema, databaseTable, refreshTime, timeout, recoveryTime, auxDatabaseHost, auxDatabasePort, auxDatabaseUsername, auxDatabasePassword, diff --git a/src/DataImporter.h b/src/DataImporter.h index 0e81f61..91984f3 100644 --- a/src/DataImporter.h +++ b/src/DataImporter.h @@ -107,6 +107,10 @@ public: string remoteUsername; // RemotePassword: Metadata exporter remote password string remotePassword; + // RemoteSchema: Metadata remote database schema + string remoteSchema; + // RemoteTable: Metadata remote database table + string remoteTable; // EnableSSL: Enable or disable SSL connections Tango::DevBoolean enableSSL; // DatabaseHost: Metadata local database host diff --git a/src/DataImporter.xmi b/src/DataImporter.xmi index 8866ef0..e95bad7 100644 --- a/src/DataImporter.xmi +++ b/src/DataImporter.xmi @@ -65,6 +65,14 @@ <type xsi:type="pogoDsl:StringType"/> <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> </deviceProperties> + <deviceProperties name="RemoteSchema" description="Metadata remote database schema"> + <type xsi:type="pogoDsl:StringType"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </deviceProperties> + <deviceProperties name="RemoteTable" description="Metadata remote database table"> + <type xsi:type="pogoDsl:StringType"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </deviceProperties> <deviceProperties name="EnableSSL" description="Enable or disable SSL connections"> <type xsi:type="pogoDsl:BooleanType"/> <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> diff --git a/src/DataImporterClass.cpp b/src/DataImporterClass.cpp index c4536aa..560c5fa 100644 --- a/src/DataImporterClass.cpp +++ b/src/DataImporterClass.cpp @@ -684,6 +684,19 @@ void DataImporterClass::set_default_property() 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 = "RemoteSchema"; + prop_desc = "Metadata remote database schema"; + 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 = "DatabaseSchema"; @@ -697,6 +710,19 @@ void DataImporterClass::set_default_property() 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 = "RemoteTable"; + prop_desc = "Metadata remote database table"; + 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 = "DatabaseTable"; diff --git a/src/ProtocolManager.cpp b/src/ProtocolManager.cpp index 7dd1178..24fc65c 100644 --- a/src/ProtocolManager.cpp +++ b/src/ProtocolManager.cpp @@ -382,8 +382,8 @@ RequestSP ProtocolManager::fillRequest(DBManager::FileRowset::const_iterator it) request_sp->set_username(m_configuration_sp->getDatabaseUsername()); request_sp->set_password(m_configuration_sp->getDatabasePassword()); - request_sp->set_schema(m_configuration_sp->getDatabaseSchema()); - request_sp->set_table(m_configuration_sp->getDatabaseTable()); + request_sp->set_schema(m_configuration_sp->getRemoteSchema()); + request_sp->set_table(m_configuration_sp->getRemoteTable()); if(!it->get<2>()) throw std::runtime_error("Empty file version found"); -- GitLab