TDengine/source/dnode/mgmt/impl/test/util/dndTestDeploy.cpp

132 lines
3.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-04 02:23:39 +00:00
#include "dndTestDeploy.h"
void initLog(char *path) {
mDebugFlag = 207;
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-04 02:23:39 +00:00
void initOption(SDnodeOpt* pOption, char *path) {
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->mnodeEqualVnodeNum = 1;
pOption->numOfThreadsPerCore = 1;
pOption->ratioOfQueryCores = 1;
pOption->maxShellConns = 1000;
pOption->shellActivityTimer = 30;
pOption->serverPort = 9527;
2021-12-04 02:23:39 +00:00
strcpy(pOption->dataDir, path);
2021-12-03 13:55:22 +00:00
strcpy(pOption->localEp, "localhost:9527");
strcpy(pOption->localFqdn, "localhost");
strcpy(pOption->firstEp, "localhost:9527");
2021-12-04 02:23:39 +00:00
taosRemoveDir(path);
taosMkDir(path);
2021-12-03 12:52:44 +00:00
}
2021-12-04 02:23:39 +00:00
SServer* createServer(char *path) {
2021-12-03 12:52:44 +00:00
SDnodeOpt option = {0};
2021-12-04 02:23:39 +00:00
initOption(&option, path);
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;
}
void dropServer(SServer* pServer) {
if (pServer->threadId != NULL) {
taosDestoryThread(pServer->threadId);
}
}
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;
2021-12-05 10:37:54 +00:00
//taosMsleep(1000000);
2021-12-03 13:55:22 +00:00
tsem_post(&pClient->sem);
2021-12-03 12:52:44 +00:00
}
2021-12-04 02:23:39 +00:00
SClient* createClient(char *user, char *pass) {
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);
2021-12-04 02:23:39 +00:00
char secretEncrypt[32] = {0};
2021-12-03 12:52:44 +00:00
taosEncryptPass((uint8_t*)pass, strlen(pass), secretEncrypt);
SRpcInit rpcInit;
memset(&rpcInit, 0, sizeof(rpcInit));
rpcInit.label = "DND-C";
rpcInit.numOfThreads = 1;
rpcInit.cfp = processClientRsp;
rpcInit.sessions = 1024;
rpcInit.connType = TAOS_CONN_CLIENT;
rpcInit.idleTime = 30 * 1000;
2021-12-04 02:23:39 +00:00
rpcInit.user = user;
2021-12-03 12:52:44 +00:00
rpcInit.ckey = "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-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;
epSet.port[0] = 9527;
strcpy(epSet.fqdn[0], "localhost");
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
}