deploy.cpp 4.0 KB
Newer Older
S
Shengliang Guan 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/*
 * 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/>.
 */

S
Shengliang Guan 已提交
16
#include "deploy.h"
S
Shengliang Guan 已提交
17

S
Shengliang Guan 已提交
18 19 20
void initLog(const char* path) {
  dDebugFlag = 0;
  vDebugFlag = 0;
S
Shengliang Guan 已提交
21
  mDebugFlag = 207;
S
Shengliang Guan 已提交
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
  cDebugFlag = 0;
  jniDebugFlag = 0;
  tmrDebugFlag = 0;
  sdbDebugFlag = 0;
  httpDebugFlag = 0;
  mqttDebugFlag = 0;
  monDebugFlag = 0;
  uDebugFlag = 0;
  rpcDebugFlag = 0;
  odbcDebugFlag = 0;
  qDebugFlag = 0;
  wDebugFlag = 0;
  sDebugFlag = 0;
  tsdbDebugFlag = 0;
  cqDebugFlag = 0;

S
Shengliang Guan 已提交
38 39 40 41 42 43
  char temp[PATH_MAX];
  snprintf(temp, PATH_MAX, "%s/taosdlog", path);
  if (taosInitLog(temp, tsNumOfLogLines, 1) != 0) {
    printf("failed to init log file\n");
  }
}
S
Shengliang Guan 已提交
44 45

void* runServer(void* param) {
S
Shengliang Guan 已提交
46
  SServer* pServer = (SServer*)param;
S
Shengliang Guan 已提交
47 48 49 50 51 52
  while (1) {
    taosMsleep(100);
    pthread_testcancel();
  }
}

S
Shengliang Guan 已提交
53
void initOption(SDnodeOpt* pOption, const char* path, const char* fqdn, uint16_t port) {
S
Shengliang Guan 已提交
54 55 56 57 58 59 60 61 62 63
  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;
S
Shengliang Guan 已提交
64
  pOption->serverPort = port;
S
Shengliang Guan 已提交
65
  strcpy(pOption->dataDir, path);
S
Shengliang Guan 已提交
66
  snprintf(pOption->localEp, TSDB_EP_LEN, "%s:%u", fqdn, port);
S
Shengliang Guan 已提交
67
  snprintf(pOption->localFqdn, TSDB_FQDN_LEN, "%s", fqdn);
S
Shengliang Guan 已提交
68 69
  snprintf(pOption->firstEp, TSDB_EP_LEN, "%s:%u", fqdn, port);
}
S
Shengliang Guan 已提交
70

S
Shengliang Guan 已提交
71
SServer* createServer(const char* path, const char* fqdn, uint16_t port) {
S
Shengliang Guan 已提交
72 73
  taosRemoveDir(path);
  taosMkDir(path);
S
Shengliang Guan 已提交
74
  initLog(path);
S
Shengliang Guan 已提交
75 76

  SDnodeOpt option = {0};
S
Shengliang Guan 已提交
77
  initOption(&option, path, fqdn, port);
S
Shengliang Guan 已提交
78 79 80 81

  SDnode* pDnode = dndInit(&option);
  ASSERT(pDnode);

S
Shengliang Guan 已提交
82
  SServer* pServer = (SServer*)calloc(1, sizeof(SServer));
S
Shengliang Guan 已提交
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
  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);
  }
}

S
Shengliang Guan 已提交
98
void processClientRsp(void* parent, SRpcMsg* pMsg, SEpSet* pEpSet) {
S
Shengliang Guan 已提交
99
  SClient* pClient = (SClient*)parent;
S
Shengliang Guan 已提交
100
  pClient->pRsp = pMsg;
S
Shengliang Guan 已提交
101
  // taosMsleep(1000000);
S
Shengliang Guan 已提交
102
  tsem_post(&pClient->sem);
S
Shengliang Guan 已提交
103 104
}

S
Shengliang Guan 已提交
105
SClient* createClient(const char* user, const char* pass, const char* fqdn, uint16_t port) {
S
Shengliang Guan 已提交
106
  SClient* pClient = (SClient*)calloc(1, sizeof(SClient));
S
Shengliang Guan 已提交
107 108
  ASSERT(pClient);

S
Shengliang Guan 已提交
109
  char secretEncrypt[32] = {0};
S
Shengliang Guan 已提交
110 111 112 113
  taosEncryptPass((uint8_t*)pass, strlen(pass), secretEncrypt);

  SRpcInit rpcInit;
  memset(&rpcInit, 0, sizeof(rpcInit));
S
Shengliang Guan 已提交
114
  rpcInit.label = (char*)"DND-C";
S
Shengliang Guan 已提交
115 116 117 118 119
  rpcInit.numOfThreads = 1;
  rpcInit.cfp = processClientRsp;
  rpcInit.sessions = 1024;
  rpcInit.connType = TAOS_CONN_CLIENT;
  rpcInit.idleTime = 30 * 1000;
S
Shengliang Guan 已提交
120
  rpcInit.user = (char*)user;
S
Shengliang Guan 已提交
121
  rpcInit.ckey = (char*)"key";
S
Shengliang Guan 已提交
122
  rpcInit.parent = pClient;
S
Shengliang Guan 已提交
123 124 125 126 127 128 129 130
  rpcInit.secret = (char*)secretEncrypt;
  rpcInit.parent = pClient;
  // rpcInit.spi = 1;

  pClient->clientRpc = rpcOpen(&rpcInit);
  ASSERT(pClient->clientRpc);

  tsem_init(&pClient->sem, 0, 0);
S
Shengliang Guan 已提交
131 132
  strcpy(pClient->fqdn, fqdn);
  pClient->port = port;
S
Shengliang Guan 已提交
133 134

  return pClient;
S
Shengliang Guan 已提交
135 136 137 138 139 140 141 142 143 144 145
}

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;
S
Shengliang Guan 已提交
146 147
  epSet.port[0] = pClient->port;
  strcpy(epSet.fqdn[0], pClient->fqdn);
S
Shengliang Guan 已提交
148

S
Shengliang Guan 已提交
149 150
  rpcSendRequest(pClient->clientRpc, &epSet, pMsg, NULL);
  tsem_wait(&pClient->sem);
S
Shengliang Guan 已提交
151
}