Commit ee388f40 authored by Marco De Marco's avatar Marco De Marco
Browse files

Mandatory check added to DMDBVerifier

parent 5a42cc7d
Loading
Loading
Loading
Loading
+34 −27
Original line number Diff line number Diff line
@@ -67,8 +67,9 @@ void DMDBVerifier::testInstrumentMapping(Instrument::SP instrument_sp)
    Destination::SP destination_sp = instrument_sp->getDestination();
  
#ifdef VERBOSE_DEBUG
    INFO_STREAM << destination_sp->getHost() << ":" << destination_sp->getPort() << " "
        << destination_sp->getSchema() << "." << destination_sp->getTable() << endl;
    INFO_STREAM << "Table: " << destination_sp->getHost() << ":" 
        << destination_sp->getPort() << " " << destination_sp->getSchema() << "."
        << destination_sp->getTable() << endl;
    INFO_STREAM << "-------------------------------------------------" << endl;
#endif    
    
@@ -77,9 +78,9 @@ void DMDBVerifier::testInstrumentMapping(Instrument::SP instrument_sp)
	ConnectionManager::SessionSP session_sp = 
		m_connectionManager_sp->getSession(destination_sp);
    
    soci::rowset< ColumnTuple > rows = (session_sp->prepare <<
        "SELECT column_name, column_type from information_schema.columns where "
        "table_schema like :schema and table_name like :table", 
    soci::rowset< ColumnTuple > rows = (session_sp->prepare << "SELECT "
        "column_name, column_type, is_nullable FROM information_schema.columns "
        "WHERE table_schema LIKE :schema AND table_name LIKE :table", 
        soci::use(destination_sp->getSchema(), "schema"), 
        soci::use(destination_sp->getTable(), "table"));
    
@@ -88,16 +89,16 @@ void DMDBVerifier::testInstrumentMapping(Instrument::SP instrument_sp)
    
    try
    {
        testColumnDefinition(columnTuple_vector, "id", "mediumint");
        testColumnDefinition(columnTuple_vector,"file_path","varchar");
        testColumnDefinition(columnTuple_vector,"file_version","smallint");
        testColumnDefinition(columnTuple_vector,"file_name","varchar");
        testColumnDefinition(columnTuple_vector,"update_time","timestamp");
        testColumnDefinition(columnTuple_vector, "id", "mediumint", true);
        testColumnDefinition(columnTuple_vector,"file_path","varchar", true);
        testColumnDefinition(columnTuple_vector,"file_version","smallint", true);
        testColumnDefinition(columnTuple_vector,"file_name","varchar", true);
        testColumnDefinition(columnTuple_vector,"update_time","timestamp", true);
                
        Mapping::SPVector::iterator it;
        for(it=mapping_spvector.begin(); it!=mapping_spvector.end(); ++it)
            testColumnDefinition(columnTuple_vector, 
                (*it)->getColumnName(), (*it)->getColumnType());
            testColumnDefinition(columnTuple_vector, (*it)->getColumnName(),
                 (*it)->getColumnType(), (*it)->isMandatory());
    }
    catch(std::runtime_error& ex)
    {
@@ -113,12 +114,12 @@ void DMDBVerifier::testInstrumentMapping(Instrument::SP instrument_sp)
//      DMDBVerifier::testColumnDefinition()
//==============================================================================
void DMDBVerifier::testColumnDefinition(ColumnTupleVector& columnTuple_vector, 
    std::string columnName, std::string columnType) throw(std::runtime_error)    
    std::string columnName, std::string columnType, bool mandatory)
    throw(std::runtime_error)    
{
    DEBUG_STREAM << "testColumnDefinition::testColumn()" << endl;
    
    ColumnTupleVector::iterator it;    
    
    it = std::find_if(columnTuple_vector.begin(), columnTuple_vector.end(),
        boost::bind(&DMDBVerifier::isEqual, this, _1, columnName));
    
@@ -130,30 +131,35 @@ void DMDBVerifier::testColumnDefinition(ColumnTupleVector& columnTuple_vector,
    }
    
    if(!it->get<1>())
        throw std::runtime_error("empty column_type retrieved from information_schema");
    
    if(it->get<1>().get().find(columnType) == std::string::npos)
    {
        std::stringstream error_stream;
        error_stream << "\"" << columnName << "\" empty column type "
            "retrieved from information schema";
        error_stream << "\"" << columnName << "\" column with "
            << columnType << "\" type differs form information schema";
        throw std::runtime_error(error_stream.str());
    }
    
#ifdef VERBOSE_DEBUG
    INFO_STREAM << "Column name: " << it->get<0>().get() 
        << " column type: " << it->get<1>().get() << endl;
    INFO_STREAM << "-------------------------------------------------" << endl;
#endif    
    if(!it->get<2>())   
        throw std::runtime_error("empty is_nullable retrieved from information_schema");

    if(it->get<1>().get().find(columnType) == std::string::npos)
    std::string isNullable("NO");
    
    if(!mandatory)
        isNullable = "YES";        

    if(it->get<2>().get().compare(isNullable) != 0)
    {
        std::stringstream error_stream;
        error_stream << "\"" << columnName << "\" column with "
            << columnType << "\" type differs form information schema";
        error_stream << "\"" << columnName << "\" column with is nullable "
            << isNullable << "\" type differs form information schema";
        throw std::runtime_error(error_stream.str());
    }
    
#ifdef VERBOSE_DEBUG
    INFO_STREAM << "Column name: " << columnName << " column type: " 
        << columnType << " OK" << endl;
        << columnType << " is nullable: " << isNullable << " -> OK" << endl;
    INFO_STREAM << "-------------------------------------------------" << endl;
#endif    
}
@@ -162,11 +168,12 @@ void DMDBVerifier::testColumnDefinition(ColumnTupleVector& columnTuple_vector,
//      DMDBVerifier::isEqual()
//==============================================================================
bool DMDBVerifier::isEqual(ColumnTuple columnTuple, std::string columnName)
    throw(std::runtime_error)
{
    DEBUG_STREAM << "DMDBVerifier::isEqual()" << endl;
    
    if(!columnTuple.get<0>())
        return false;
        throw std::runtime_error("empty column_name retrieved from information_schema");
         
    return columnTuple.get<0>().get().compare(columnName) == 0;
}
+4 −3
Original line number Diff line number Diff line
@@ -56,7 +56,7 @@ protected:
//  [Protected] Columns tuple typedef
//------------------------------------------------------------------------------    
    typedef boost::tuple< boost::optional<std::string>, 
        boost::optional<std::string> > ColumnTuple;
        boost::optional<std::string>, boost::optional<std::string> > ColumnTuple;        
    
    typedef std::vector< ColumnTuple > ColumnTupleVector;
    
@@ -64,9 +64,10 @@ protected:
//  [Protected] Utilities methods
//------------------------------------------------------------------------------
    virtual void testColumnDefinition(ColumnTupleVector&, 
        std::string, std::string) throw(std::runtime_error);
        std::string, std::string, bool) throw(std::runtime_error);
    
    virtual bool isEqual(ColumnTuple, std::string);
    virtual bool isEqual(ColumnTuple, std::string)
        throw(std::runtime_error);
    
//------------------------------------------------------------------------------
//	[Protected] Class variables
+6 −4
Original line number Diff line number Diff line
@@ -85,6 +85,8 @@ void WorkerThread::workerLoop()
                    
                    completed = true;
                    m_fitsImporter_p->incrementRegularCounter();
                    INFO_STREAM << "WorkerThread::workerLoop() \"" << fileName 
                        << "\" archived regularly" << endl;                    
                }
                catch(CCfits::FitsException& ex)
                {
@@ -102,6 +104,8 @@ void WorkerThread::workerLoop()
    
                    completed = true;
                    m_fitsImporter_p->incrementWarningCounter();
                    WARN_STREAM << "WorkerThread::workerLoop() \"" << fileName 
                        << "\" archived in default instrument" << endl;                    
                }                
            }
            catch(CCfits::FitsException& ex)
@@ -115,11 +119,9 @@ void WorkerThread::workerLoop()

            if(!completed)
            {
                //Cannot ingest file, notify the error
                m_fitsImporter_p->incrementErrorCounter();
                ERROR_STREAM << "WorkerThread::workerLoop() \"" << fileName 
                    << "\" not archived" << endl;                                    

                m_fitsImporter_p->incrementErrorCounter();
            }

            m_eventBuffer_sp->removeProcessed(origPath);