Browse Source

#IQRV #comment [ResourceWatcher] 实体兼容改造

gifur 2 years ago
parent
commit
40a9094256
1 changed files with 27 additions and 110 deletions
  1. 27 110
      Module/mod_ResourceWatcher/ResourceWatcherFSM.cpp

+ 27 - 110
Module/mod_ResourceWatcher/ResourceWatcherFSM.cpp

@@ -446,16 +446,12 @@ bool ResourceWatcherFSM::GetMonitorInfo(CSimpleStringA& outInfo)
 
 
 void ResourceWatcherFSM::readVideoStoreData()
 void ResourceWatcherFSM::readVideoStoreData()
 {
 {
-    LOG_FUNCTION();
-
     CSmartPointer<IConfigInfo> spCtSettingConfig;
     CSmartPointer<IConfigInfo> spCtSettingConfig;
-    CSmartPointer<IConfigInfo> spConfig;
     GetEntityBase()->GetFunction()->OpenConfig(Config_CenterSetting, spCtSettingConfig);
     GetEntityBase()->GetFunction()->OpenConfig(Config_CenterSetting, spCtSettingConfig);
-    GetEntityBase()->GetFunction()->OpenConfig(Config_Software, spConfig);
     // From CenterSetting --Josephus at 10:02:10 201759
     // From CenterSetting --Josephus at 10:02:10 201759
     spCtSettingConfig->ReadConfigValueInt(GetEntityBase()->GetEntityName(), "BackwardDays", m_nDayOfBackward);
     spCtSettingConfig->ReadConfigValueInt(GetEntityBase()->GetEntityName(), "BackwardDays", m_nDayOfBackward);
     if (m_nDayOfBackward <= 0) {
     if (m_nDayOfBackward <= 0) {
-        spConfig->ReadConfigValueInt("Video", "BackwardDays", m_nDayOfBackward);
+        m_nDayOfBackward = 90;
     } else {
     } else {
         Dbg("Detect BackwardDays from CentralSetting %d", m_nDayOfBackward);
         Dbg("Detect BackwardDays from CentralSetting %d", m_nDayOfBackward);
     }
     }
@@ -507,16 +503,18 @@ ErrorCodeEnum ResourceWatcherFSM::OnInit()
     InitializeCriticalSection(&g_csVideoMoreClear);
     InitializeCriticalSection(&g_csVideoMoreClear);
 
 
     CSmartPointer<IConfigInfo> spConfig;
     CSmartPointer<IConfigInfo> spConfig;
-    GetEntityBase()->GetFunction()->OpenConfig(Config_Software, spConfig);
+    GetEntityBase()->GetFunction()->OpenConfig(Config_CenterSetting, spConfig);
     cpuTop = 0;
     cpuTop = 0;
     erroCode = spConfig->ReadConfigValueInt("TOPProcess", "cpu", cpuTop);    //读取需要监控的CPU进程个数
     erroCode = spConfig->ReadConfigValueInt("TOPProcess", "cpu", cpuTop);    //读取需要监控的CPU进程个数
     if (erroCode != Error_Succeed) {
     if (erroCode != Error_Succeed) {
         Dbg("Get CPU TOP NUM failed: %s.", SpStrError(erroCode));
         Dbg("Get CPU TOP NUM failed: %s.", SpStrError(erroCode));
         return Error_Unexpect;
         return Error_Unexpect;
     }
     }
-    if (cpuTop == 0)
-    {
+    if (cpuTop == 0) {
+        cpuTop = 10; //From static config
+    } else if (cpuTop == -1) {
         Dbg("No need for TOP PROCESS!");
         Dbg("No need for TOP PROCESS!");
+        cpuTop = 0;
     }
     }
 
 
     if (!m_bIsConfigMode) {
     if (!m_bIsConfigMode) {
@@ -994,23 +992,9 @@ BOOL ResourceWatcherFSM::GetCPUBrand(CSimpleStringA & csCpuBrand)
 
 
 void ResourceWatcherFSM::InitialCPUMarkInfor()
 void ResourceWatcherFSM::InitialCPUMarkInfor()
 {
 {
-    ErrorCodeEnum erroCode = Error_Succeed;
-    CSmartPointer<IConfigInfo> spConfig;
-    erroCode = GetEntityBase()->GetFunction()->OpenConfig(Config_Software, spConfig);
-    if (erroCode != Error_Succeed) {
-        Dbg("Open Config_Software failed %s.", SpStrError(erroCode));
-        return;
-    }
-
-    int nTmpValue1, nTmpValue2 = 0;
-    erroCode = spConfig->ReadConfigValueInt("CPUMarkLevel", "High", nTmpValue1);
-    if (erroCode == Error_Succeed/* && nTmpValue1 > 0*/)
-        m_highPart = nTmpValue1;
-    erroCode = spConfig->ReadConfigValueInt("CPUMarkLevel", "Low", nTmpValue2);
-    if (erroCode == Error_Succeed/* && nTmpValue2 > 0*/)
-        m_lowPart = nTmpValue2;
+    m_highPart = 4000;
+    m_lowPart = 2000;
     Dbg("hight:%d > value >low:%d.", m_highPart, m_lowPart);
     Dbg("hight:%d > value >low:%d.", m_highPart, m_lowPart);
-
     return;
     return;
 }
 }
 
 
@@ -1019,58 +1003,12 @@ void ResourceWatcherFSM::InitialCPUMarkInfor()
 ErrorCodeEnum ResourceWatcherFSM::GetCpuType(
 ErrorCodeEnum ResourceWatcherFSM::GetCpuType(
     SpReqAnsContext<ResourceWatcherService_GetCpuType_Req, ResourceWatcherService_GetCpuType_Ans>::Pointer ctx)
     SpReqAnsContext<ResourceWatcherService_GetCpuType_Req, ResourceWatcherService_GetCpuType_Ans>::Pointer ctx)
 {
 {
-    LOG_FUNCTION();
-    ErrorCodeEnum ec = Error_Succeed;
-#if defined(RVC_OS_WIN)
-
-    ErrorCodeEnum erroCode = Error_Succeed;
-    CSimpleStringA csCPUBrand;
-    if (!GetCPUBrand(csCPUBrand)) {
-        if (ctx != NULL)
-            ctx->Answer(Error_Unexpect);
-        return Error_Unexpect;
-    }
-    CSmartPointer<IConfigInfo> spConfig;
-    erroCode = GetEntityBase()->GetFunction()->OpenConfig(Config_Software, spConfig);
-    if (erroCode != Error_Succeed) {
-        Dbg("Open Config_Software failed 0x%x.", erroCode);
-        if (ctx != NULL)
-            ctx->Answer(Error_DevLoadFileFailed);
-        return Error_DevLoadFileFailed;
-    }
-    int nMark = 0;
-    int level = 0;
-    erroCode = spConfig->ReadConfigValueInt("CPUMark", (LPCTSTR)csCPUBrand, nMark);
-    if (erroCode != Error_Succeed || nMark == 0) {
-        Dbg("There are no level information about %s(mark:%d)(code:%d).",
-            (LPCTSTR)csCPUBrand, nMark, erroCode);
-        if (ctx != NULL) {
-            ctx->Ans.brand = csCPUBrand;
-            ctx->Ans.level = 0;
-            ctx->Ans.reserved1 = nMark;
-            ctx->Ans.reserved2 = "";
-            ctx->Answer(Error_Succeed);
-        }
-    } else {
-        level = SelectMarkLevel(nMark);
-        Dbg("Result: %s : %d(%d).", (LPCTSTR)csCPUBrand, nMark, level);
-        if (ctx != NULL) {
-            ctx->Ans.brand = csCPUBrand;
-            ctx->Ans.level = level;
-            ctx->Ans.reserved1 = nMark;
-            ctx->Ans.reserved2 = "";
-            ctx->Answer(Error_Succeed);
-        }
-    }
-    return Error_Succeed;
-#else
-    ec = Error_NotSupport;
+    ErrorCodeEnum ec = Error_NotSupport;
     LogWarn(Severity_Middle, ec, 0, CSimpleStringA::Format("%s is not supported!", __FUNCTION__));
     LogWarn(Severity_Middle, ec, 0, CSimpleStringA::Format("%s is not supported!", __FUNCTION__));
     if (ctx != NULL) {
     if (ctx != NULL) {
         ctx->Answer(ec);
         ctx->Answer(ec);
     }
     }
     return ec;
     return ec;
-#endif //RVC_OS_WIN
 }
 }
 
 
 
 
@@ -1858,13 +1796,11 @@ BOOL ResourceWatcherFSM::DeleteVersionPackage()
     int tmpSaved = 0;
     int tmpSaved = 0;
     CSmartPointer<IEntityFunction> spFunction = this->GetEntityBase()->GetFunction();
     CSmartPointer<IEntityFunction> spFunction = this->GetEntityBase()->GetFunction();
     CSmartPointer<IConfigInfo> spConfig;
     CSmartPointer<IConfigInfo> spConfig;
-    spFunction->OpenConfig(Config_Software, spConfig);
+    spFunction->OpenConfig(Config_CenterSetting, spConfig);
     spConfig->ReadConfigValueInt("VersionSaved", "default", tmpSaved);
     spConfig->ReadConfigValueInt("VersionSaved", "default", tmpSaved);
-    if (tmpSaved > DEFAULT_VERSION_SAVED_COUNT)
-    {
+    if (tmpSaved > DEFAULT_VERSION_SAVED_COUNT) {
         verSaved = tmpSaved;
         verSaved = tmpSaved;
     }
     }
-
     int nPackCount = intallInfoVects.size();
     int nPackCount = intallInfoVects.size();
     Dbg("Install Package's count: %d", nPackCount);
     Dbg("Install Package's count: %d", nPackCount);
     bool bFailFlag = false;
     bool bFailFlag = false;
@@ -4069,20 +4005,18 @@ string ResourceWatcherFSM::MemoryProcessStatus()
     CSmartPointer<IEntityFunction> spFunction = this->GetEntityBase()->GetFunction();
     CSmartPointer<IEntityFunction> spFunction = this->GetEntityBase()->GetFunction();
     CSmartPointer<IConfigInfo> spConfig;
     CSmartPointer<IConfigInfo> spConfig;
     ErrorCodeEnum erroCode = Error_Unexpect;
     ErrorCodeEnum erroCode = Error_Unexpect;
-    spFunction->OpenConfig(Config_Software, spConfig);
+    spFunction->OpenConfig(Config_CenterSetting, spConfig);
     int memTop = 0;
     int memTop = 0;
     erroCode = spConfig->ReadConfigValueInt("TOPProcess", "mem", memTop);
     erroCode = spConfig->ReadConfigValueInt("TOPProcess", "mem", memTop);
-
-    if (memTop == 0)
-    {
+    if (memTop == 0) {
+        memTop = 10;
+    } else if (memTop == -1) {
         return "";
         return "";
     }
     }
 
 
     map<string, string> nameProcess;
     map<string, string> nameProcess;
-
     CSystemRunInfo runInfo = { 0 };
     CSystemRunInfo runInfo = { 0 };
     GetEntityBase()->GetFunction()->GetSystemRunInfo(runInfo);
     GetEntityBase()->GetFunction()->GetSystemRunInfo(runInfo);
-
     for (int i = 0; i < runInfo.strRunningEntityNames.GetCount(); i++)
     for (int i = 0; i < runInfo.strRunningEntityNames.GetCount(); i++)
     {
     {
         string entityName = runInfo.strRunningEntityNames[i].GetData();
         string entityName = runInfo.strRunningEntityNames[i].GetData();
@@ -4946,50 +4880,33 @@ void ResourceWatcherFSM::ConfirmDNSConfigHasSet()
 {
 {
     LOG_FUNCTION();
     LOG_FUNCTION();
 
 
-    CSimpleStringA dns1, dns2;
+    CSimpleStringA dns1(true), dns2(true);
 
 
-#if 1
     CSmartPointer<IConfigInfo> spConfig;
     CSmartPointer<IConfigInfo> spConfig;
-    GetEntityBase()->GetFunction()->OpenConfig(Config_Software, spConfig);
-#ifdef UNDER_PRODUCT_ENV
+    GetEntityBase()->GetFunction()->OpenConfig(Config_CenterSetting, spConfig);
     spConfig->ReadConfigValue("DNS", "dns1", dns1);
     spConfig->ReadConfigValue("DNS", "dns1", dns1);
     spConfig->ReadConfigValue("DNS", "dns2", dns2);
     spConfig->ReadConfigValue("DNS", "dns2", dns2);
-    Dbg("prd enviromemt");
-#else
-    spConfig->ReadConfigValue("DNSTest", "dns1", dns1);
-    spConfig->ReadConfigValue("DNSTest", "dns2", dns2);
-    Dbg("test enviromemt");
-#endif // UNDER_PRODUCT_ENV
-
-#else
-    dns1 = m_strDefaultDns;
-    dns2 = m_strBackupDns;
-
-    if (!m_nEnableSetDns) {
-        Dbg("no enable set dns server.");
-        return;
-    }
-#endif
-
-    if (dns1.IsNullOrEmpty() && dns2.IsNullOrEmpty()) {
-        Dbg("not any dns set at entity config.");
-        return;
-    }
-    if (dns2.IsNullOrEmpty()) dns2 = dns1;
-    if (dns1.IsNullOrEmpty()) dns1 = dns2;
 
 
     CSimpleStringA str;
     CSimpleStringA str;
     readDNSConfigFile(str);
     readDNSConfigFile(str);
-
     do {
     do {
         std::string a(str.GetData());
         std::string a(str.GetData());
         SP::Utility::replaceInPlace(a, "\n", "|");
         SP::Utility::replaceInPlace(a, "\n", "|");
         LogWarn(Severity_Low, Error_Unexpect, LOG_RESOURCEWATCHER_DNS_INFO_UPLOAD,
         LogWarn(Severity_Low, Error_Unexpect, LOG_RESOURCEWATCHER_DNS_INFO_UPLOAD,
                 CSimpleStringA::Format("%s $$ %s|%s", a.c_str(), m_strDefaultDns.GetData(), m_strBackupDns.GetData()));
                 CSimpleStringA::Format("%s $$ %s|%s", a.c_str(), m_strDefaultDns.GetData(), m_strBackupDns.GetData()));
-        //SetLocalDNSWithNetworkManager(dns1, dns2);
     } while (false);
     } while (false);
+
+    if (dns1.IsNullOrEmpty() && dns2.IsNullOrEmpty()) {
+        Dbg("not any dns set at entity config.");
+        return;
+    }
+    if (dns2.IsNullOrEmpty()) dns2 = dns1;
+    if (dns1.IsNullOrEmpty()) dns1 = dns2;
     return;
     return;
 
 
+    //////////////////////////////////////////////////////////////////////////
+    /** 下面的代码验证暂不可行 [Gifur@202319]*/
+
     if (!str.IsNullOrEmpty()) {
     if (!str.IsNullOrEmpty()) {
         CAutoArray<CSimpleStringA> arr = str.Split('\n');
         CAutoArray<CSimpleStringA> arr = str.Split('\n');
         CSimpleStringA check1("nameserver ");
         CSimpleStringA check1("nameserver ");