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 38
  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;
  debugFlag = 0;

S
Shengliang Guan 已提交
39 40 41 42 43 44
  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 已提交
45 46

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

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

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

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

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

S
Shengliang Guan 已提交
84
  SServer* pServer = (SServer*)calloc(1, sizeof(SServer));
S
Shengliang Guan 已提交
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
  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 已提交
100
void processClientRsp(void* parent, SRpcMsg* pMsg, SEpSet* pEpSet) {
S
Shengliang Guan 已提交
101
  SClient* pClient = (SClient*)parent;
S
Shengliang Guan 已提交
102
  pClient->pRsp = pMsg;
S
Shengliang Guan 已提交
103
  // taosMsleep(1000000);
S
Shengliang Guan 已提交
104
  tsem_post(&pClient->sem);
S
Shengliang Guan 已提交
105 106
}

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

S
Shengliang Guan 已提交
111
  char secretEncrypt[32] = {0};
S
Shengliang Guan 已提交
112 113 114 115 116 117 118 119 120 121
  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;
S
Shengliang Guan 已提交
122
  rpcInit.user = (char*)user;
S
Shengliang Guan 已提交
123
  rpcInit.ckey = "key";
S
Shengliang Guan 已提交
124
  rpcInit.parent = pClient;
S
Shengliang Guan 已提交
125 126 127 128 129 130 131 132
  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 已提交
133 134
  strcpy(pClient->fqdn, fqdn);
  pClient->port = port;
S
Shengliang Guan 已提交
135 136

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

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

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