Public Member Functions | Static Public Member Functions | Protected Attributes | Private Attributes

mif_CfgRep Class Reference
[Management Interface]

#include <mif_cfgrep.h>

Collaboration diagram for mif_CfgRep:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 mif_CfgRep (mif_ObjectTypeTable_e a_type, string a_name)
virtual ~mif_CfgRep ()
UInt32_t ShowRevisions ()
mif_ObjectTypeTable_e GetType () const
UInt32_t LastRev ()
void SetPath ()
string GenerateFilename (UInt32_t a_revision=0)
void SetLastRevNum ()
UInt32_t Upload (pf_File &a_cfgFile)
void RemoveCfg ()
cmn_File GetCfg (UInt32_t a_revision)

Static Public Member Functions

static void ReplaceVersion (pf_File &parsedFile)
static void ReplaceDate (pf_File &parsedFile)
static void ReplaceUser (pf_File &parsedFile, const string &uadString)
static void ReplaceClients (pf_File &a_parsedFile)
static void ReplaceHosts (pf_File &a_parsedFile)
static void ParseToFile (pf_File &a_pfFile, const i_DataBlock_t &a_cfgFile, string a_fileType, string a_user)

Protected Attributes

mif_ObjectTypeTable_e m_type
string m_name
cmn_Path m_repPath
UInt32_t m_lastRevision

Private Attributes

 log_CLASSID_m

Detailed Description

Definition at line 70 of file mif_cfgrep.h.


Constructor & Destructor Documentation

mif_CfgRep::mif_CfgRep ( mif_ObjectTypeTable_e  a_type,
string  a_name 
)

Definition at line 55 of file mif_cfgrep.cpp.

References cmn_CreatePath(), dbg_NORM, log_DBG_m, log_FUNC_A_m, m_lastRevision, m_name, m_repPath, SetLastRevNum(), and SetPath().

        : m_type(a_type),
          m_name(a_name){
    log_FUNC_A_m(mif_CfgRep, "a_type" << a_type <<
                                " m_name" << m_name);
    SetPath();
    log_DBG_m(dbg_NORM, "m_repPath: " << m_repPath);
    SetLastRevNum();
    if (m_lastRevision == 0)
        cmn_CreatePath(m_repPath);

} // mif_CfgRep::mif_CfgRep

Here is the call graph for this function:

virtual mif_CfgRep::~mif_CfgRep (  )  [inline, virtual]

Definition at line 78 of file mif_cfgrep.h.

{};


Member Function Documentation

string mif_CfgRep::GenerateFilename ( UInt32_t  a_revision = 0  ) 

Definition at line 95 of file mif_cfgrep.cpp.

References cmn_Num2Str(), ie_MIF_CFG_REVISION_OUT_OF_RANGE, ivd_Error, log_FUNC_m, m_lastRevision, and MIF_CFG_MAX_REVISIONS.

Referenced by GetCfg(), and Upload().

                                                       {
    log_FUNC_m(GenerateFilename);

    string revString;
    if (a_revision == 0)
        return CFG_LINK_LATEST;
    else {
        if (m_lastRevision < MIF_CFG_MAX_REVISIONS) {
            revString = cmn_Num2Str(a_revision);
            // add leading zeroes    
            while (revString.length() < MIF_CFG_REV_WIDTH)
                revString.insert(0, "0");
            
            return revString;
        }
        else {
            // if a_revision exceeds highest revision number allowed...
            throw ivd_Error(ie_MIF_CFG_REVISION_OUT_OF_RANGE);
        }
    }
} // mif_CfgRep::GenerateFilename

Here is the call graph for this function:

Here is the caller graph for this function:

cmn_File mif_CfgRep::GetCfg ( UInt32_t  a_revision  ) 

Definition at line 241 of file mif_cfgrep.cpp.

References GenerateFilename(), ivd_BaseException::GetError(), ivd_BaseException::GetFriendly(), ie_MIF_CFG_REVISION_NONEXISTENT, ie_MIF_CFG_TROUBLE_IN_REPOSITORY, ivd_Error, log_ERR_m, log_FUNC_m, m_repPath, and cmn_File::StatF().

Referenced by i_ManagementInterface_i::ShowDrive(), i_ManagementInterface_i::ShowLibrary(), i_ManagementInterface_i::ShowPartition(), i_ManagementInterface_i::ShowPool(), and i_ManagementInterface_i::ShowSystemCfg().

                                               {
    log_FUNC_m(GetCfg);
    try {
        cmn_File cfgFile(m_repPath + GenerateFilename(a_revision));
        ivd_FileInfo_t info;
        cfgFile.StatF(info);
        return cfgFile;
    }
    catch (ivd_Error& e) {
        log_ERR_m("CfgDB repository read failed." << e);
        throw ivd_Error(ie_MIF_CFG_TROUBLE_IN_REPOSITORY, e.GetFriendly());
    }
    catch (ivd_SysError& se) {
#if TGT_OS_windows
        if (se.GetError() != ERROR_FILE_NOT_FOUND) {
#else
        if (se.GetError() != ENOENT) {
#endif
          log_ERR_m("Error accessing the configuration file " << m_repPath + GenerateFilename(a_revision) << ". " << se);
        }
        throw ivd_Error(ie_MIF_CFG_REVISION_NONEXISTENT);
    }
} // mif_CfgRep::ReadConfigRevision

Here is the call graph for this function:

Here is the caller graph for this function:

mif_ObjectTypeTable_e mif_CfgRep::GetType (  )  const [inline]

Definition at line 94 of file mif_cfgrep.h.

References m_type.

Referenced by SetPath().

                                            {
                                return m_type;
                            };

Here is the caller graph for this function:

UInt32_t mif_CfgRep::LastRev (  )  [inline]
void mif_CfgRep::ParseToFile ( pf_File a_pfFile,
const i_DataBlock_t a_cfgFile,
string  a_fileType,
string  a_user 
) [static]

Definition at line 143 of file mif_cfgrep.cpp.

References dbg_DETAIL, dbg_NORM, pf_File::GetFileType(), ie_MIF_CFG_CONFIG_FILE_UNKNOWN, ivd_Error, log_DBG_m, log_FUNC_m, pf_File::Parse(), ReplaceDate(), ReplaceUser(), ReplaceVersion(), and strcasecmp.

Referenced by i_ManagementInterface_i::AddDrive(), i_ManagementInterface_i::AddLibrary(), i_ManagementInterface_i::AddPartition(), i_ManagementInterface_i::AddPool(), i_ManagementInterface_i::UpdateDrive(), i_ManagementInterface_i::UpdateLibrary(), i_ManagementInterface_i::UpdatePartition(), i_ManagementInterface_i::UpdatePool(), and i_ManagementInterface_i::UpdateSystemCfg().

                                              {
    log_FUNC_m(ParseToFile);
    try {
        //
        // parse config buffer
        log_DBG_m(dbg_DETAIL, "block:" << endl << *(a_cfgFile.get_buffer()));
        a_pfFile.Parse(reinterpret_cast<char *>(const_cast<CORBA::Octet *>(a_cfgFile.get_buffer())), a_cfgFile.length());
        log_DBG_m(dbg_DETAIL, "a_pfFile:" << endl << a_pfFile);
    }
    catch (ivd_Exception) {
        log_DBG_m(dbg_NORM, 
            "MIF: Syntax error encountered in configuration file.");
        throw;
    }

    //
    // check if type matches
    if (strcasecmp(a_pfFile.GetFileType().c_str(), a_fileType.c_str()) != 0) {
        throw ivd_Error(ie_MIF_CFG_CONFIG_FILE_UNKNOWN);
    }
    
    mif_CfgRep::ReplaceVersion(a_pfFile);
    mif_CfgRep::ReplaceDate(a_pfFile);
    mif_CfgRep::ReplaceUser(a_pfFile, a_user);
    
}

Here is the call graph for this function:

Here is the caller graph for this function:

void mif_CfgRep::RemoveCfg (  ) 

Definition at line 216 of file mif_cfgrep.cpp.

References cmn_CleanDir(), dbg_NORM, cmn_File::DeleteDir(), ivd_BaseException::GetFriendly(), ie_MIF_CFG_TROUBLE_IN_REPOSITORY, ivd_Error, log_DBG_m, log_ERR_m, log_FUNC_m, and m_repPath.

Referenced by i_ManagementInterface_i::RemoveLibrary(), i_ManagementInterface_i::RemovePartition(), and i_ManagementInterface_i::RemovePool().

                          {
    log_FUNC_m(RemoveCfg);

    try {
        cmn_CleanDir(m_repPath);
        log_DBG_m(dbg_NORM, 
            "MIF: CfgDB repository subdirectory successfully cleared.");
        cmn_File::DeleteDir(m_repPath);
        log_DBG_m(dbg_NORM, 
            "MIF: CfgDB repository subdirectory successfully removed.");
    }
    catch (ivd_Error& e) {
        log_ERR_m("CfgDB repository removal failed." << e);
        throw ivd_Error(ie_MIF_CFG_TROUBLE_IN_REPOSITORY, e.GetFriendly());
    }
    catch (ivd_SysError& se) {
        log_ERR_m("CfgDB repository removal failed." << se);
        throw ivd_Error(ie_MIF_CFG_TROUBLE_IN_REPOSITORY, se.GetFriendly());
    }

} // mif_CfgRep::RemoveCfg

Here is the call graph for this function:

Here is the caller graph for this function:

void mif_CfgRep::ReplaceClients ( pf_File a_parsedFile  )  [static]

Definition at line 415 of file mif_cfgrep.cpp.

References cfg_FILE_VAR_CLIENT, log_FUNC_m, pf_File::m_common, pf_File::m_sections, pf_SectionList::m_vec, pf_ValueList::m_vec, mif_ResolveHostToFQDN(), PF_GROUP, and PF_SIMPLE.

Referenced by i_ManagementInterface_i::AddPartition(), and i_ManagementInterface_i::UpdatePartition().

                                                     {
    log_FUNC_m(ReplaceClients);

    string hostFqdn;

    // replace in Common section.
    for (UInt32_t ct=0; ct < a_parsedFile.m_common.m_vec.size() ; ct++) {

        if (a_parsedFile.m_common.m_vec[ct].type == PF_SIMPLE) {
            if (a_parsedFile.m_common.m_vec[ct].simple.val.compare(cfg_FILE_VAR_CLIENT) == 0) {
                mif_ResolveHostToFQDN(a_parsedFile.m_common.m_vec[ct].simple.val);
             }
        }
        else if (a_parsedFile.m_common.m_vec[ct].type == PF_GROUP) {
            if (a_parsedFile.m_common.m_vec[ct].group->grpType.compare(cfg_FILE_VAR_CLIENT) == 0){
                mif_ResolveHostToFQDN(a_parsedFile.m_common.m_vec[ct].name);
            }
        }
    }

    // replace in other sections.
    for (UInt32_t cts=0; cts < a_parsedFile.m_sections.m_vec.size(); cts++) {

        for (UInt32_t ctm=0; ctm < a_parsedFile.m_sections.m_vec[cts].size(); ctm++) {

            if (a_parsedFile.m_sections.m_vec[cts].m_vec[ctm].type == PF_SIMPLE) {
                if (a_parsedFile.m_sections.m_vec[cts].m_vec[ctm].name.compare(cfg_FILE_VAR_CLIENT) == 0) {
                    mif_ResolveHostToFQDN(a_parsedFile.m_sections.m_vec[cts].m_vec[ctm].simple.val);
                }

            }
            else if (a_parsedFile.m_sections.m_vec[cts].m_vec[ctm].type == PF_GROUP) {
                if (a_parsedFile.m_sections.m_vec[cts].m_vec[ctm].group->grpType.compare(cfg_FILE_VAR_CLIENT) == 0) {
                    mif_ResolveHostToFQDN(a_parsedFile.m_sections.m_vec[cts].m_vec[ctm].name);
                }
            }
        }
    }

} // mif_CfgRep::ReplaceClients

Here is the call graph for this function:

Here is the caller graph for this function:

void mif_CfgRep::ReplaceDate ( pf_File parsedFile  )  [static]

Definition at line 295 of file mif_cfgrep.cpp.

References pf_ValueList::Add(), pf_ValueList::At(), cfg_BASE_HEADER_FILEDATE, dbg_NORM, log_DBG_m, log_FUNC_m, log_WRN_m, pf_File::m_header, pf_ValueList::m_vec, pf_Value::simple, pf_ValueList::size(), cmn_Time::Time2YMDhms(), and pf_Elem::val.

Referenced by ParseToFile().

                                                  {
    log_FUNC_m(ReplaceDate);

    
    cmn_Time dateTime;
    bool lineFound(false);

    for (UInt32_t ct=0; ct<a_parsedFile.m_header.size(); ct++) {

        if (a_parsedFile.m_header.m_vec[ct].name == string(cfg_BASE_HEADER_FILEDATE)) {
            const_cast<string &>(a_parsedFile.m_header.At(ct).simple.val) = dateTime.Time2YMDhms();        
            //a_parsedFile.m_header.At(ct).simple.val = dateTime.Time2YMDhms();        
            log_DBG_m(dbg_NORM, 
                "MIF: DateTime value successfully replaced by current one.");
            lineFound = true;
            break;
        }
    }

    if (!lineFound) {
        pf_Value pfValue(string(cfg_BASE_HEADER_FILEDATE), dateTime.Time2YMDhms(), 3);
        a_parsedFile.m_header.Add(pfValue);
        log_WRN_m("MIF: Configuration file seems to have incomplete header (missing Date line).");
    }

} // mif_CfgRep::ReplaceDate

Here is the call graph for this function:

Here is the caller graph for this function:

void mif_CfgRep::ReplaceHosts ( pf_File a_parsedFile  )  [static]

Definition at line 372 of file mif_cfgrep.cpp.

References cfg_FILE_VAR_HOST, log_FUNC_m, pf_File::m_common, pf_File::m_sections, pf_SectionList::m_vec, pf_ValueList::m_vec, mif_ResolveHostToFQDN(), PF_GROUP, PF_SIMPLE, and strcasecmp.

Referenced by i_ManagementInterface_i::AddDrive(), i_ManagementInterface_i::AddLibrary(), i_ManagementInterface_i::UpdateDrive(), and i_ManagementInterface_i::UpdateLibrary().

                                                   {
    log_FUNC_m(ReplaceHosts);

    // replace in Common section.
    for (UInt32_t ct=0; ct < a_parsedFile.m_common.m_vec.size() ; ct++) {

        if (a_parsedFile.m_common.m_vec[ct].type == PF_SIMPLE) {
            
            if (a_parsedFile.m_common.m_vec[ct].name.compare(cfg_FILE_VAR_HOST) == 0){
                mif_ResolveHostToFQDN(a_parsedFile.m_common.m_vec[ct].simple.val);
            }
        }
        else if (a_parsedFile.m_common.m_vec[ct].type == PF_GROUP) {

            if (a_parsedFile.m_common.m_vec[ct].group->grpType.compare(cfg_FILE_VAR_HOST) == 0) {
                mif_ResolveHostToFQDN(a_parsedFile.m_common.m_vec[ct].name);
            }
        }
    }

    // replace in other sections.
    for (UInt32_t cts=0; cts < a_parsedFile.m_sections.m_vec.size(); cts++) {

        for (UInt32_t ctm=0; ctm < a_parsedFile.m_sections.m_vec[cts].size(); ctm++) {

            if (a_parsedFile.m_sections.m_vec[cts].m_vec[ctm].type == PF_SIMPLE) {

                if (strcasecmp(a_parsedFile.m_sections.m_vec[cts].m_vec[ctm].name.c_str(),cfg_FILE_VAR_HOST) == 0) {
                    mif_ResolveHostToFQDN(a_parsedFile.m_sections.m_vec[cts].m_vec[ctm].simple.val);
                }
            }
            else if (a_parsedFile.m_sections.m_vec[cts].m_vec[ctm].type == PF_GROUP) {

                if (a_parsedFile.m_sections.m_vec[cts].m_vec[ctm].group->grpType.compare(cfg_FILE_VAR_HOST) == 0) {
                    mif_ResolveHostToFQDN(a_parsedFile.m_sections.m_vec[cts].m_vec[ctm].name);
                }
            }
        }
    }

} // mif_CfgRep::ReplaceHosts

Here is the call graph for this function:

Here is the caller graph for this function:

void mif_CfgRep::ReplaceUser ( pf_File parsedFile,
const string &  uadString 
) [static]

Definition at line 325 of file mif_cfgrep.cpp.

References pf_ValueList::Add(), pf_ValueList::At(), cfg_BASE_HEADER_FILEUSER, dbg_NORM, log_DBG_m, log_FUNC_m, pf_File::m_header, pf_ValueList::m_vec, pf_Value::simple, pf_ValueList::size(), and pf_Elem::val.

Referenced by ParseToFile().

                                                         {
    log_FUNC_m(ReplaceUser);
    bool lineFound(false);
    for (UInt32_t ct=0; ct<a_parsedFile.m_header.size(); ct++) {

        if (a_parsedFile.m_header.m_vec[ct].name == string(cfg_BASE_HEADER_FILEUSER)) {
            const_cast<string &>(a_parsedFile.m_header.At(ct).simple.val) = a_uadLine;        
            log_DBG_m(dbg_NORM, 
                "MIF: User value successfully replaced by actual one.");
            lineFound = true;
            break;
        }
    }

    if (!lineFound) {
        pf_Value pfValue(string(cfg_BASE_HEADER_FILEUSER), a_uadLine, 4);
        a_parsedFile.m_header.Add(pfValue);
        
//         log_ERR_m("MIF: This configuration file seems to have incomplete header (missing User line).");
//         throw ivd_Error(ie_MIF_CFG_HEADER_ERROR, "\"User\" line is missing.");
    }
    
} // mif_CfgRep::ReplaceUser

Here is the call graph for this function:

Here is the caller graph for this function:

void mif_CfgRep::ReplaceVersion ( pf_File parsedFile  )  [static]

Definition at line 266 of file mif_cfgrep.cpp.

References pf_ValueList::Add(), pf_ValueList::At(), cfg_BASE_HEADER_FILEVERSION, cmn_Num2Str(), dbg_NORM, log_DBG_m, log_FUNC_m, pf_File::m_header, pf_ValueList::m_vec, MIF_IVD_VERSION, pf_Value::simple, pf_ValueList::size(), and pf_Elem::val.

Referenced by ParseToFile().

                                                     {
    log_FUNC_m(ReplaceVersion);


    string version = cmn_Num2Str(MIF_IVD_VERSION);
    bool lineFound(false);

    for (UInt32_t ct=0; ct<a_parsedFile.m_header.size(); ct++) {

        if (a_parsedFile.m_header.m_vec[ct].name == string(cfg_BASE_HEADER_FILEVERSION)) {
            const_cast<string &>(a_parsedFile.m_header.At(ct).simple.val) = version;        
            log_DBG_m(dbg_NORM, 
                "MIF: Version value successfully replaced by actual one.");
            lineFound = true;
            break;
        }
    }

    if (!lineFound) {

        pf_Value pfValue(string(cfg_BASE_HEADER_FILEVERSION), version, 2);
        a_parsedFile.m_header.Add(pfValue);
    }

} // mif_CfgRep::CheckInsertVersion

Here is the call graph for this function:

Here is the caller graph for this function:

void mif_CfgRep::SetLastRevNum (  ) 

Definition at line 119 of file mif_cfgrep.cpp.

References CFG_LINK_LATEST, cmn_Str2Num(), dbg_DETAIL, dbg_NORM, log_DBG_m, log_FUNC_m, m_lastRevision, m_repPath, cmn_Path::OnlyFileName(), and cmn_File::ReadLink().

Referenced by mif_CfgRep(), and Upload().

                              {
    log_FUNC_m(SetLastRevNum);

    // read target name w/ ABSOLUTE FILENAME
    try {
        cmn_Path linkName(m_repPath + CFG_LINK_LATEST);
        cmn_Path fileName = cmn_File::ReadLink(linkName);
        fileName.OnlyFileName();

        log_DBG_m(dbg_DETAIL, "lastRevision:" << cmn_Str2Num(fileName) << 
                            " fileName:" << fileName);
        
        m_lastRevision = cmn_Str2Num(fileName);
    } 
    catch (ivd_Error& e){
        log_DBG_m(dbg_NORM, e)
            m_lastRevision = 0;
    } 
    catch (ivd_SysError& se){
        log_DBG_m(dbg_NORM, se)
        m_lastRevision = 0;
    }
} // mif_CfgRep::SetLastRevNum

Here is the call graph for this function:

Here is the caller graph for this function:

void mif_CfgRep::SetPath (  ) 

Definition at line 71 of file mif_cfgrep.cpp.

References ivd_Directories::cfgDrv, ivd_Directories::cfgLib, ivd_Directories::cfgPart, ivd_Directories::cfgPool, ivd_Directories::cfgSys, cmn_Global::dirs, g_cmn, GetType(), ie_UNKNOWN_TYPE, ivd_Error, log_FUNC_m, m_name, m_repPath, mif_DRIVE, mif_LIBRARY, mif_PARTITION, mif_POOL, and mif_SYSTEM.

Referenced by mif_CfgRep().

                         {
    log_FUNC_m(SetPath);

    switch (GetType()) {
        case(mif_LIBRARY): 
            m_repPath = g_cmn.dirs.cfgLib; break;
        case(mif_DRIVE):
            m_repPath = g_cmn.dirs.cfgDrv; break;
        case(mif_POOL):
            m_repPath = g_cmn.dirs.cfgPool; break;
        case(mif_SYSTEM):
            m_repPath = g_cmn.dirs.cfgSys; break;
        case(mif_PARTITION):
            m_repPath = g_cmn.dirs.cfgPart; break;
        default:
            throw ivd_Error(ie_UNKNOWN_TYPE);
    }
    m_repPath += m_name;

} // mif_CfgRep::ComposePath

Here is the call graph for this function:

Here is the caller graph for this function:

UInt32_t mif_CfgRep::ShowRevisions (  ) 
UInt32_t mif_CfgRep::Upload ( pf_File a_cfgFile  ) 

Definition at line 173 of file mif_cfgrep.cpp.

References CFG_LINK_LATEST, cmn_File::DeleteF(), GenerateFilename(), cmn_Path::GetAbsolutePathName(), cmn_Path::GetFileName(), ivd_BaseException::GetFriendly(), ie_MIF_CFG_TROUBLE_IN_REPOSITORY, ivd_Error, LastRev(), log_ERR_m, log_FUNC_m, m_lastRevision, m_repPath, SetLastRevNum(), and pf_File::WriteFile().

Referenced by i_ManagementInterface_i::AddLibrary(), i_ManagementInterface_i::AddPartition(), i_ManagementInterface_i::UpdatePartition(), and i_ManagementInterface_i::UpdateSystemCfg().

                                             {

    log_FUNC_m(Upload);
    // copy file to directory (buffer -> repositoryPath/fileName)
    try {
        cmn_Path fileName(m_repPath + GenerateFilename(LastRev() + 1));
        a_cfgFile.WriteFile(fileName);
        //delete symlink
        cmn_Path latest(m_repPath + CFG_LINK_LATEST);
        cmn_File latestFile(latest);

        try {
            latestFile.DeleteF();
        } catch (...){
            //ignore
        }
        //make new symlink
        // Windows SymLink requires full pathname, while on UNIX we 
        // preffer relative pathnames
#if TGT_OS_windows
        cmn_File cfgFile(fileName.GetAbsolutePathName());
#else
        cmn_File cfgFile(fileName.GetFileName());
#endif
        cfgFile.SymLink(latest);

        SetLastRevNum();
    }
    catch (ivd_Error& e) {
        log_ERR_m("MIF: Creating file failed." << e);
        throw ivd_Error(ie_MIF_CFG_TROUBLE_IN_REPOSITORY, e.GetFriendly());
    }
    catch (ivd_SysError& se) {
        log_ERR_m("MIF: Creating file failed." << se);
        throw ivd_Error(ie_MIF_CFG_TROUBLE_IN_REPOSITORY, se.GetFriendly());
    }
    return m_lastRevision;

} // mif_CfgRep::Upload

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 89 of file mif_cfgrep.h.

Definition at line 86 of file mif_cfgrep.h.

Referenced by GenerateFilename(), LastRev(), mif_CfgRep(), SetLastRevNum(), and Upload().

string mif_CfgRep::m_name [protected]

Definition at line 84 of file mif_cfgrep.h.

Referenced by mif_CfgRep(), and SetPath().

Definition at line 85 of file mif_cfgrep.h.

Referenced by GetCfg(), mif_CfgRep(), RemoveCfg(), SetLastRevNum(), SetPath(), and Upload().

Definition at line 83 of file mif_cfgrep.h.

Referenced by GetType().


The documentation for this class was generated from the following files: