From 7ed762430635b18bbb519399040de1eec587a1ab Mon Sep 17 00:00:00 2001 From: slzhou Date: Fri, 15 Apr 2022 18:31:57 +0800 Subject: [PATCH] after trying to retrive udf info from mnode --- source/dnode/mnode/impl/test/func/func.cpp | 2 +- source/libs/function/CMakeLists.txt | 1 + source/libs/function/src/udfd.c | 74 ++++++++++++++++++++++ 3 files changed, 76 insertions(+), 1 deletion(-) diff --git a/source/dnode/mnode/impl/test/func/func.cpp b/source/dnode/mnode/impl/test/func/func.cpp index f34f77de0c..ef1027c24b 100644 --- a/source/dnode/mnode/impl/test/func/func.cpp +++ b/source/dnode/mnode/impl/test/func/func.cpp @@ -230,7 +230,7 @@ TEST_F(MndTestFunc, 03_Retrieve_Func) { EXPECT_EQ(retrieveRsp.numOfFuncs, 1); EXPECT_EQ(retrieveRsp.numOfFuncs, (int32_t)taosArrayGetSize(retrieveRsp.pFuncInfos)); - SFuncInfo* pFuncInfo = (SFuncInfo*)taosArrayGet(retrieveRsp.pFuncInfos, 0); + * pFuncInfo = (SFuncInfo*)taosArrayGet(retrieveRsp.pFuncInfos, 0); EXPECT_STREQ(pFuncInfo->name, "f1"); EXPECT_EQ(pFuncInfo->funcType, 1); diff --git a/source/libs/function/CMakeLists.txt b/source/libs/function/CMakeLists.txt index 2ed8db589a..19a0897e20 100644 --- a/source/libs/function/CMakeLists.txt +++ b/source/libs/function/CMakeLists.txt @@ -57,6 +57,7 @@ target_include_directories( "${TD_SOURCE_DIR}/contrib/libuv/include" "${TD_SOURCE_DIR}/include/util" "${TD_SOURCE_DIR}/include/common" + "${TD_SOURCE_DIR}/include/libs/transport" "${TD_SOURCE_DIR}/include/client" PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc" ) diff --git a/source/libs/function/src/udfd.c b/source/libs/function/src/udfd.c index 477054abe8..27b99625fe 100644 --- a/source/libs/function/src/udfd.c +++ b/source/libs/function/src/udfd.c @@ -20,6 +20,10 @@ #include "tudf.h" #include "tudfInt.h" +#include "tdataformat.h" +#include "tglobal.h" +#include "tmsg.h" +#include "trpc.h" static uv_loop_t *loop; @@ -319,6 +323,76 @@ void removeListeningPipe(int sig) { exit(0); } +typedef struct SServerContext { + void *clientRpc; +} SUdfdContext; + + +void udfdProcessRpcRsp(void* parent, SRpcMsg* pMsg, SEpSet* pEpSet) { + + return; +} + +int32_t fetchUdfFuncInfo(void *clientRpc, SEpSet* pEpSet, char* udfNames[], int32_t numOfUdfs) { + SRetrieveFuncReq retrieveReq = {0}; + retrieveReq.numOfFuncs = 1; + retrieveReq.pFuncNames = taosArrayInit(1, TSDB_FUNC_NAME_LEN); + for (int32_t i = 0; i < numOfUdfs; ++i) { + taosArrayPush(retrieveReq.pFuncNames, udfNames[i]); + } + + int32_t contLen = tSerializeSRetrieveFuncReq(NULL, 0, &retrieveReq); + void* pReq = rpcMallocCont(contLen); + tSerializeSRetrieveFuncReq(pReq, contLen, &retrieveReq); + taosArrayDestroy(retrieveReq.pFuncNames); + + SRpcMsg rpcMsg = {0}; + rpcMsg.pCont = pReq; + rpcMsg.contLen = contLen; + rpcMsg.msgType = TDMT_MND_RETRIEVE_FUNC; + + SRpcMsg rpcRsp = {0}; + rpcSendRecv(clientRpc, pEpSet, &rpcMsg, &rpcRsp); + SRetrieveFuncRsp retrieveRsp = {0}; + tDeserializeSRetrieveFuncRsp(rpcRsp.pCont, rpcRsp.contLen, &retrieveRsp); + + SFuncInfo* pFuncInfo = (SFuncInfo*)taosArrayGet(retrieveRsp.pFuncInfos, 0); + + taosArrayDestroy(retrieveRsp.pFuncInfos); + + rpcFreeCont(rpcRsp.pCont); + return 0; +} + +int32_t openUdfdClientRpc(SUdfdContext *ctx) { + char *pass = "taosdata"; + char *user = "root"; + char secretEncrypt[TSDB_PASSWORD_LEN + 1] = {0}; + taosEncryptPass_c((uint8_t*)pass, strlen(pass), secretEncrypt); + SRpcInit rpcInit = {0}; + rpcInit.label = (char*)"UDFD"; + rpcInit.numOfThreads = 1; + rpcInit.cfp = udfdProcessRpcRsp; + rpcInit.sessions = 1024; + rpcInit.connType = TAOS_CONN_CLIENT; + rpcInit.idleTime = 30 * 1000; + rpcInit.parent = ctx; + + rpcInit.user = (char*)user; + rpcInit.ckey = (char*)"key"; + rpcInit.secret = (char*)secretEncrypt; + rpcInit.spi = 1; + + ctx->clientRpc = rpcOpen(&rpcInit); + + return 0; +} + +int32_t closeUdfdClientRpc(SUdfdContext *ctx) { + rpcClose(ctx->clientRpc); + + return 0; +} int main() { debugPrint("libuv version: %x", UV_VERSION_HEX);