integrate cfg
This commit is contained in:
parent
7d4ae77521
commit
1244bbe49a
|
@ -26,7 +26,7 @@ extern "C" {
|
|||
typedef enum {
|
||||
CFG_TYPE_DEFAULT,
|
||||
CFG_TYPE_CFG_FILE,
|
||||
CFG_TYPE_DOT_ENV,
|
||||
CFG_TYPE_ENV_FILE,
|
||||
CFG_TYPE_ENV_VAR,
|
||||
CFG_TYPE_APOLLO_URL,
|
||||
CFG_TYPE_CONSOLE_PARA
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
aux_source_directory(src DAEMON_SRC)
|
||||
add_executable(taosd ${DAEMON_SRC})
|
||||
target_link_libraries(
|
||||
|
||||
target_include_directories(
|
||||
taosd
|
||||
PUBLIC dnode
|
||||
PUBLIC config
|
||||
PUBLIC util
|
||||
PUBLIC os
|
||||
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc"
|
||||
)
|
||||
|
||||
target_link_libraries(taosd dnode config util os)
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
|
||||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _TD_DMN_INT_H_
|
||||
#define _TD_DMN_INT_H_
|
||||
|
||||
#include "config.h"
|
||||
#include "dnode.h"
|
||||
#include "tconfig.h"
|
||||
#include "tglobal.h"
|
||||
#include "tnote.h"
|
||||
#include "ulog.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int32_t dnmInitCfg(SDnodeEnvCfg *pEnvCfg, SDnodeObjCfg *pObjCfg, const char *configFile, const char *envFile,
|
||||
const char *apolloUrl);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_DMN_INT_H_*/
|
|
@ -15,11 +15,7 @@
|
|||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "dnode.h"
|
||||
#include "os.h"
|
||||
#include "tconfig.h"
|
||||
#include "tglobal.h"
|
||||
#include "tnote.h"
|
||||
#include "ulog.h"
|
||||
#include "dmnInt.h"
|
||||
|
||||
static struct {
|
||||
bool stop;
|
||||
|
@ -136,38 +132,14 @@ void dmnWaitSignal() {
|
|||
}
|
||||
}
|
||||
|
||||
void dnmInitEnvCfg(SDnodeEnvCfg *pCfg) {
|
||||
pCfg->sver = 30000000; // 3.0.0.0
|
||||
pCfg->numOfCores = tsNumOfCores;
|
||||
pCfg->numOfCommitThreads = tsNumOfCommitThreads;
|
||||
pCfg->enableTelem = 0;
|
||||
tstrncpy(pCfg->timezone, tsTimezone, TSDB_TIMEZONE_LEN);
|
||||
tstrncpy(pCfg->locale, tsLocale, TSDB_LOCALE_LEN);
|
||||
tstrncpy(pCfg->charset, tsCharset, TSDB_LOCALE_LEN);
|
||||
tstrncpy(pCfg->buildinfo, buildinfo, 64);
|
||||
tstrncpy(pCfg->gitinfo, gitinfo, 48);
|
||||
}
|
||||
|
||||
void dmnInitObjCfg(SDnodeObjCfg *pCfg) {
|
||||
pCfg->numOfSupportVnodes = tsNumOfSupportVnodes;
|
||||
pCfg->statusInterval = tsStatusInterval;
|
||||
pCfg->numOfThreadsPerCore = tsNumOfThreadsPerCore;
|
||||
pCfg->ratioOfQueryCores = tsRatioOfQueryCores;
|
||||
pCfg->maxShellConns = tsMaxShellConns;
|
||||
pCfg->shellActivityTimer = tsShellActivityTimer;
|
||||
pCfg->serverPort = tsServerPort;
|
||||
tstrncpy(pCfg->dataDir, tsDataDir, TSDB_FILENAME_LEN);
|
||||
tstrncpy(pCfg->localEp, tsLocalEp, TSDB_EP_LEN);
|
||||
tstrncpy(pCfg->localFqdn, tsLocalFqdn, TSDB_FQDN_LEN);
|
||||
tstrncpy(pCfg->firstEp, tsFirst, TSDB_EP_LEN);
|
||||
}
|
||||
|
||||
int dmnRunDnode() {
|
||||
SDnodeEnvCfg envCfg = {0};
|
||||
SDnodeObjCfg objCfg = {0};
|
||||
|
||||
dnmInitEnvCfg(&envCfg);
|
||||
dmnInitObjCfg(&objCfg);
|
||||
if (dnmInitCfg(&envCfg, &objCfg, "", "", "") != 0) {
|
||||
uInfo("Failed to start TDengine since load config error");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (dndInit(&envCfg) != 0) {
|
||||
uInfo("Failed to start TDengine, please check the log at %s", tsLogDir);
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "dmnInt.h"
|
||||
|
||||
static void dmnInitEnvCfg(SDnodeEnvCfg *pCfg) {
|
||||
pCfg->sver = 30000000; // 3.0.0.0
|
||||
pCfg->numOfCores = tsNumOfCores;
|
||||
pCfg->numOfCommitThreads = tsNumOfCommitThreads;
|
||||
pCfg->enableTelem = 0;
|
||||
tstrncpy(pCfg->timezone, tsTimezone, TSDB_TIMEZONE_LEN);
|
||||
tstrncpy(pCfg->locale, tsLocale, TSDB_LOCALE_LEN);
|
||||
tstrncpy(pCfg->charset, tsCharset, TSDB_LOCALE_LEN);
|
||||
tstrncpy(pCfg->buildinfo, buildinfo, 64);
|
||||
tstrncpy(pCfg->gitinfo, gitinfo, 48);
|
||||
}
|
||||
|
||||
static void dmnInitObjCfg(SDnodeObjCfg *pCfg) {
|
||||
pCfg->numOfSupportVnodes = tsNumOfSupportVnodes;
|
||||
pCfg->statusInterval = tsStatusInterval;
|
||||
pCfg->numOfThreadsPerCore = tsNumOfThreadsPerCore;
|
||||
pCfg->ratioOfQueryCores = tsRatioOfQueryCores;
|
||||
pCfg->maxShellConns = tsMaxShellConns;
|
||||
pCfg->shellActivityTimer = tsShellActivityTimer;
|
||||
pCfg->serverPort = tsServerPort;
|
||||
tstrncpy(pCfg->dataDir, tsDataDir, TSDB_FILENAME_LEN);
|
||||
tstrncpy(pCfg->localEp, tsLocalEp, TSDB_EP_LEN);
|
||||
tstrncpy(pCfg->localFqdn, tsLocalFqdn, TSDB_FQDN_LEN);
|
||||
tstrncpy(pCfg->firstEp, tsFirst, TSDB_EP_LEN);
|
||||
}
|
||||
|
||||
int32_t dnmInitCfg(SDnodeEnvCfg *pEnvCfg, SDnodeObjCfg *pObjCfg, const char *configFile, const char *envFile,
|
||||
const char *apolloUrl) {
|
||||
dmnInitEnvCfg(pEnvCfg);
|
||||
dmnInitObjCfg(pObjCfg);
|
||||
return 0;
|
||||
}
|
|
@ -32,8 +32,8 @@ typedef struct SConfig {
|
|||
} SConfig;
|
||||
|
||||
int32_t cfgLoadFromCfgFile(SConfig *pConfig, const char *filepath);
|
||||
int32_t cfgLoadFromDotEnvFile(SConfig *pConfig, const char *filepath);
|
||||
int32_t cfgLoadFromGlobalEnvVariable(SConfig *pConfig);
|
||||
int32_t cfgLoadFromEnvFile(SConfig *pConfig, const char *filepath);
|
||||
int32_t cfgLoadFromEnvVar(SConfig *pConfig);
|
||||
int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
#define _DEFAULT_SOURCE
|
||||
#include "cfgInt.h"
|
||||
|
||||
int32_t cfgLoadFromDotEnvFile(SConfig *pConfig, const char *filepath) {
|
||||
uInfo("load from .env file %s", filepath);
|
||||
int32_t cfgLoadFromEnvFile(SConfig *pConfig, const char *filepath) {
|
||||
uInfo("load from env file %s", filepath);
|
||||
return 0;
|
||||
}
|
|
@ -16,7 +16,7 @@
|
|||
#define _DEFAULT_SOURCE
|
||||
#include "cfgInt.h"
|
||||
|
||||
int32_t cfgLoadFromGlobalEnvVariable(SConfig *pConfig) {
|
||||
int32_t cfgLoadFromEnvVar(SConfig *pConfig) {
|
||||
uInfo("load from global env variables");
|
||||
return 0;
|
||||
}
|
|
@ -37,10 +37,10 @@ int32_t cfgLoad(SConfig *pConfig, ECfgSrcType cfgType, const char *sourceStr) {
|
|||
switch (cfgType) {
|
||||
case CFG_TYPE_CFG_FILE:
|
||||
return cfgLoadFromCfgFile(pConfig, sourceStr);
|
||||
case CFG_TYPE_DOT_ENV:
|
||||
return cfgLoadFromDotEnvFile(pConfig, sourceStr);
|
||||
case CFG_TYPE_ENV_FILE:
|
||||
return cfgLoadFromEnvFile(pConfig, sourceStr);
|
||||
case CFG_TYPE_ENV_VAR:
|
||||
return cfgLoadFromGlobalEnvVariable(pConfig);
|
||||
return cfgLoadFromEnvVar(pConfig);
|
||||
case CFG_TYPE_APOLLO_URL:
|
||||
return cfgLoadFromApollUrl(pConfig, sourceStr);
|
||||
default:
|
||||
|
@ -206,13 +206,13 @@ const char *cfgStypeStr(ECfgSrcType type) {
|
|||
case CFG_TYPE_DEFAULT:
|
||||
return "default";
|
||||
case CFG_TYPE_CFG_FILE:
|
||||
return "cfg";
|
||||
case CFG_TYPE_DOT_ENV:
|
||||
return ".env";
|
||||
return "cfg_file";
|
||||
case CFG_TYPE_ENV_FILE:
|
||||
return "env_file";
|
||||
case CFG_TYPE_ENV_VAR:
|
||||
return "env";
|
||||
return "env_var";
|
||||
case CFG_TYPE_APOLLO_URL:
|
||||
return "apollo";
|
||||
return "apollo_url";
|
||||
default:
|
||||
return "invalid";
|
||||
}
|
||||
|
|
|
@ -30,10 +30,10 @@ const char *CfgTest::pConfig;
|
|||
|
||||
TEST_F(CfgTest, 02_Str) {
|
||||
EXPECT_STREQ(cfgStypeStr(CFG_TYPE_DEFAULT), "default");
|
||||
EXPECT_STREQ(cfgStypeStr(CFG_TYPE_CFG_FILE), "cfg");
|
||||
EXPECT_STREQ(cfgStypeStr(CFG_TYPE_DOT_ENV), ".env");
|
||||
EXPECT_STREQ(cfgStypeStr(CFG_TYPE_ENV_VAR), "env");
|
||||
EXPECT_STREQ(cfgStypeStr(CFG_TYPE_APOLLO_URL), "apollo");
|
||||
EXPECT_STREQ(cfgStypeStr(CFG_TYPE_CFG_FILE), "cfg_file");
|
||||
EXPECT_STREQ(cfgStypeStr(CFG_TYPE_ENV_FILE), "env_file");
|
||||
EXPECT_STREQ(cfgStypeStr(CFG_TYPE_ENV_VAR), "env_var");
|
||||
EXPECT_STREQ(cfgStypeStr(CFG_TYPE_APOLLO_URL), "apollo_url");
|
||||
EXPECT_STREQ(cfgStypeStr(ECfgSrcType(1024)), "invalid");
|
||||
|
||||
EXPECT_STREQ(cfgDtypeStr(CFG_DTYPE_NONE), "none");
|
||||
|
|
Loading…
Reference in New Issue