TDengine/source/dnode/mgmt/impl/test/sut/deploy.cpp

162 lines
4.4 KiB
C++
Raw Normal View History

2021-12-03 12:52:44 +00:00
/*
* 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/>.
*/
2021-12-05 11:08:08 +00:00
#include "deploy.h"
2021-12-04 02:23:39 +00:00
2021-12-06 06:38:37 +00:00
void initLog(const char* path) {
2021-12-13 06:48:10 +00:00
dDebugFlag = 143;
2021-12-06 06:38:37 +00:00
vDebugFlag = 0;
2021-12-14 10:07:29 +00:00
mDebugFlag = 207;
2021-12-06 06:38:37 +00:00
cDebugFlag = 0;
jniDebugFlag = 0;
tmrDebugFlag = 0;
2021-12-13 09:06:04 +00:00
uDebugFlag = 143;
2021-12-06 06:38:37 +00:00
rpcDebugFlag = 0;
odbcDebugFlag = 0;
qDebugFlag = 0;
wDebugFlag = 0;
sDebugFlag = 0;
tsdbDebugFlag = 0;
cqDebugFlag = 0;
2021-12-13 09:06:04 +00:00
tscEmbeddedInUtil = 1;
2021-12-06 06:38:37 +00:00
2021-12-13 09:06:04 +00:00
taosRemoveDir(path);
2021-12-13 06:48:10 +00:00
taosMkDir(path);
2021-12-04 02:23:39 +00:00
char temp[PATH_MAX];
snprintf(temp, PATH_MAX, "%s/taosdlog", path);
if (taosInitLog(temp, tsNumOfLogLines, 1) != 0) {
printf("failed to init log file\n");
}
}
2021-12-03 12:52:44 +00:00
void* runServer(void* param) {
2021-12-03 13:55:22 +00:00
SServer* pServer = (SServer*)param;
2021-12-03 12:52:44 +00:00
while (1) {
taosMsleep(100);
pthread_testcancel();
}
}
2021-12-12 06:46:31 +00:00
void initOption(SDnodeOpt* pOption, const char* path, const char* fqdn, uint16_t port, const char* firstEp) {
2021-12-03 12:52:44 +00:00
pOption->sver = 1;
pOption->numOfCores = 1;
pOption->numOfSupportMnodes = 1;
pOption->numOfSupportVnodes = 1;
pOption->numOfSupportQnodes = 1;
pOption->statusInterval = 1;
pOption->numOfThreadsPerCore = 1;
pOption->ratioOfQueryCores = 1;
pOption->maxShellConns = 1000;
pOption->shellActivityTimer = 30;
2021-12-05 12:28:27 +00:00
pOption->serverPort = port;
2021-12-04 02:23:39 +00:00
strcpy(pOption->dataDir, path);
2021-12-06 06:38:37 +00:00
snprintf(pOption->localEp, TSDB_EP_LEN, "%s:%u", fqdn, port);
2021-12-05 12:28:27 +00:00
snprintf(pOption->localFqdn, TSDB_FQDN_LEN, "%s", fqdn);
2021-12-12 06:46:31 +00:00
snprintf(pOption->firstEp, TSDB_EP_LEN, "%s", firstEp);
2021-12-06 06:38:37 +00:00
}
2021-12-04 02:23:39 +00:00
2021-12-13 09:06:04 +00:00
SServer* startServer(const char* path, const char* fqdn, uint16_t port, const char* firstEp) {
2021-12-04 02:23:39 +00:00
taosMkDir(path);
2021-12-03 12:52:44 +00:00
SDnodeOpt option = {0};
2021-12-12 06:46:31 +00:00
initOption(&option, path, fqdn, port, firstEp);
2021-12-03 12:52:44 +00:00
SDnode* pDnode = dndInit(&option);
ASSERT(pDnode);
2021-12-03 13:55:22 +00:00
SServer* pServer = (SServer*)calloc(1, sizeof(SServer));
2021-12-03 12:52:44 +00:00
ASSERT(pServer);
pServer->pDnode = pDnode;
pServer->threadId = taosCreateThread(runServer, pServer);
ASSERT(pServer->threadId);
return pServer;
}
2021-12-13 09:06:04 +00:00
SServer* createServer(const char* path, const char* fqdn, uint16_t port, const char* firstEp) {
taosRemoveDir(path);
return startServer(path, fqdn, port, firstEp);
}
void stopServer(SServer* pServer) {
if (pServer == NULL) return;
2021-12-03 12:52:44 +00:00
if (pServer->threadId != NULL) {
taosDestoryThread(pServer->threadId);
}
2021-12-13 09:06:04 +00:00
if (pServer->pDnode != NULL) {
dndCleanup(pServer->pDnode);
pServer->pDnode = NULL;
}
2021-12-03 12:52:44 +00:00
}
2021-12-04 02:23:39 +00:00
void processClientRsp(void* parent, SRpcMsg* pMsg, SEpSet* pEpSet) {
2021-12-03 13:55:22 +00:00
SClient* pClient = (SClient*)parent;
2021-12-03 12:52:44 +00:00
pClient->pRsp = pMsg;
uInfo("response:%s from dnode, pCont:%p contLen:%d code:0x%X", taosMsg[pMsg->msgType], pMsg->pCont, pMsg->contLen,
pMsg->code);
2021-12-03 13:55:22 +00:00
tsem_post(&pClient->sem);
2021-12-03 12:52:44 +00:00
}
2021-12-06 06:38:37 +00:00
SClient* createClient(const char* user, const char* pass, const char* fqdn, uint16_t port) {
2021-12-03 13:55:22 +00:00
SClient* pClient = (SClient*)calloc(1, sizeof(SClient));
2021-12-03 12:52:44 +00:00
ASSERT(pClient);
char secretEncrypt[TSDB_PASSWORD_LEN] = {0};
2021-12-03 12:52:44 +00:00
taosEncryptPass((uint8_t*)pass, strlen(pass), secretEncrypt);
SRpcInit rpcInit;
memset(&rpcInit, 0, sizeof(rpcInit));
2021-12-06 10:21:14 +00:00
rpcInit.label = (char*)"DND-C";
2021-12-03 12:52:44 +00:00
rpcInit.numOfThreads = 1;
rpcInit.cfp = processClientRsp;
rpcInit.sessions = 1024;
rpcInit.connType = TAOS_CONN_CLIENT;
rpcInit.idleTime = 30 * 1000;
2021-12-06 06:38:37 +00:00
rpcInit.user = (char*)user;
2021-12-06 10:21:14 +00:00
rpcInit.ckey = (char*)"key";
2021-12-03 13:55:22 +00:00
rpcInit.parent = pClient;
2021-12-03 12:52:44 +00:00
rpcInit.secret = (char*)secretEncrypt;
rpcInit.parent = pClient;
// rpcInit.spi = 1;
pClient->clientRpc = rpcOpen(&rpcInit);
ASSERT(pClient->clientRpc);
tsem_init(&pClient->sem, 0, 0);
2021-12-06 06:38:37 +00:00
strcpy(pClient->fqdn, fqdn);
pClient->port = port;
2021-12-04 02:23:39 +00:00
return pClient;
2021-12-03 12:52:44 +00:00
}
void dropClient(SClient* pClient) {
tsem_destroy(&pClient->sem);
rpcClose(pClient->clientRpc);
}
void sendMsg(SClient* pClient, SRpcMsg* pMsg) {
SEpSet epSet = {0};
epSet.inUse = 0;
epSet.numOfEps = 1;
2021-12-06 06:38:37 +00:00
epSet.port[0] = pClient->port;
memcpy(epSet.fqdn[0], pClient->fqdn, TSDB_FQDN_LEN);
2021-12-03 12:52:44 +00:00
2021-12-03 13:55:22 +00:00
rpcSendRequest(pClient->clientRpc, &epSet, pMsg, NULL);
tsem_wait(&pClient->sem);
2021-12-03 12:52:44 +00:00
}