Commit 8b867fc3 by Amir Aharon

test client

parent 9200a646
......@@ -20,6 +20,23 @@
"environment": []
},
{
"name": "C++ Client Launch (GDBSERVER)",
"type": "cppdbg",
"request": "launch",
"miDebuggerServerAddress": "localhost:2000",
"preLaunchTask": "start-gdbserver-client",
"miDebuggerPath": "/usr/bin/gdb",
"targetArchitecture": "x64",
"program": "${workspaceRoot}/build/bin/test_MicroserviceClient",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceRoot}",
"sourceFileMap":{
"/home/develop/project": "${workspaceRoot}"
},
"environment": []
},
{
"name": "C++ Launch (GDB)",
"type": "cppdbg",
"request": "launch",
......
......@@ -50,6 +50,13 @@
"problemMatcher": []
},
{
"label": "start-gdbserver-client",
"type": "shell",
// not using -it so that it can be a preLaunchTask
"command": "docker exec -d devenv gdbserver :2000 build/bin/test_MicroserviceClient",
"problemMatcher": []
},
{
"label": "build develop image",
"type": "shell",
// not using -it so that it can be a preLaunchTask
......@@ -62,8 +69,14 @@
// not using -it so that it can be a preLaunchTask
"command": "docker exec -d devenv build/bin/test_Microservice",
"problemMatcher": []
}
,
},
{
"label": "run client test",
"type": "shell",
// not using -it so that it can be a preLaunchTask
"command": "docker exec -d devenv build/bin/test_MicroserviceClient",
"problemMatcher": []
},
{
"label": "stop app",
"type": "shell",
......
......@@ -10,7 +10,9 @@
static const char *COMMAND_TIMEOUT_PARAM = "command.timeout";
static const double DEFAULT_COMMAND_TIMEOUT = 5.0;
static const char *HTTP_SCHEME = "http://";
static const char *HTTPS_SCHEME = "https://";
static const int HTTP_SCHEME_LEN = strlen(HTTP_SCHEME);
static const int HTTPS_SCHEME_LEN = strlen(HTTPS_SCHEME);
static const char *NULL_REST_RESPONSE_OBJECT = "null rest response object passed";
static const char *FAILED_BUILD_URL = "Failed to build url";
static const char* CONNECTION_FAILED_OR_REQUEST_TIMEOUT = "Connection or request timeout";
......@@ -69,36 +71,37 @@ MSRetStat MSICommandClientEvppImpl::Delete(MSCommandParams *p_cmd_params, cMicro
bool MSICommandClientEvppImpl::BuildUrl(MSCommandParams *p_cmd_params, std::string &url)
{
std::string unencoded_url;
//std::string unencoded_url;
if (p_cmd_params == nullptr)
return false;
auto entity = p_cmd_params->GetEntity().c_str();
if (strncmp(entity, HTTP_SCHEME, HTTP_SCHEME_LEN) != 0)
unencoded_url.append(HTTP_SCHEME); //.append(entity);
unencoded_url.append(entity);
const char* entity = p_cmd_params->GetEntity().c_str();
if (strncmp(entity, HTTP_SCHEME, HTTP_SCHEME_LEN) != 0 &&
strncmp(entity, HTTPS_SCHEME, HTTPS_SCHEME_LEN) != 0)
url.append(HTTP_SCHEME); //.append(entity);
url.append(entity);
// params
if (!p_cmd_params->GetParams().empty())
{
for (auto param : p_cmd_params->GetParams())
{
unencoded_url.append(1, '/').append(param.c_str());
url.append(1, '/').append(param.c_str());
}
}
else if (!p_cmd_params->GetParamsString().empty())
{
unencoded_url.append(1, '/').append(p_cmd_params->GetParamsString().c_str());
url.append(1, '/').append(p_cmd_params->GetParamsString().c_str());
}
// query params
if (!p_cmd_params->GetParamsString().empty())
if (!p_cmd_params->GetRequestParams().empty())
{
unencoded_url.append(1, '?').append(p_cmd_params->GetRequestParams());
url.append(1, '?').append(CommonUtils::urlencode(p_cmd_params->GetRequestParams()));
}
/*
* encode it
*/
url = CommonUtils::urlencode(unencoded_url);
//url = CommonUtils::urlencode(unencoded_url);
return true;
}
......@@ -112,11 +115,12 @@ void MSICommandClientEvppImpl::HandleCommandAndCallback(ICommandClient::HttpComm
auto sharedCv = std::make_shared<std::condition_variable>();
evpp::httpc::RequestPtr requestPtr = nullptr;
auto f = [this,cmdDataPtr,sharedCv](const std::shared_ptr<evpp::httpc::Response> &responsePtr) {
auto f = [&m,this,cmdDataPtr,sharedCv](const std::shared_ptr<evpp::httpc::Response> &responsePtr) {
//std::cout << "http_code=" << response->http_code() << " [" << responsePtr->body().ToString() << "]";
//std::string header = response->FindHeader("Connection");
cmdDataPtr->p_retstat->Reset();
cmdDataPtr->p_response->Reset();
std::unique_lock<std::mutex> lk(m);
register int resp_code = responsePtr->http_code();
if (resp_code == 0){
this->handleRequestFailed(cmdDataPtr,CONNECTION_FAILED_OR_REQUEST_TIMEOUT);
......@@ -125,7 +129,8 @@ void MSICommandClientEvppImpl::HandleCommandAndCallback(ICommandClient::HttpComm
} else {
this->handleRequestFailed(cmdDataPtr,nsMicroservice_Constants::REQUEST_ERROR);
}
lk.unlock();
cmdDataPtr->finished = true;
if (!cmdDataPtr->p_cmd_params->IsAsync_())
sharedCv->notify_all();
......@@ -162,7 +167,8 @@ void MSICommandClientEvppImpl::HandleCommandAndCallback(ICommandClient::HttpComm
/**
* handle to error
*/
p_logger_->warning("%s, failed on timeout, Cmnd Id: %u", __PRETTY_FUNCTION__, cmdDataPtr->p_cmd_params->GetCommandId());
p_logger_->warning("%s, failed on timeout, Cmnd Id: %u", __PRETTY_FUNCTION__, cmdDataPtr->p_cmd_params->GetCommandId());
handleRequestFailed(cmdDataPtr,CONNECTION_FAILED_OR_REQUEST_TIMEOUT);
}
}
} else {
......
......@@ -8,6 +8,7 @@
#include <impl/clients/MSZMQClientImpl.h>
#include <impl/clients/MSIPubSubClientImpl.h>
#include <impl/clients/MSICommandClientZmqImpl.h>
#include <impl/clients/MSICommandClientEvppImpl.h>
cMicroservice_Client *
ClientFactory::createHttpImplMsClient(std::string serviceName, std::string host, int port, bool cacheEnabled,
......@@ -16,6 +17,17 @@ ClientFactory::createHttpImplMsClient(std::string serviceName, std::string host,
new cMicroservice_BaseClientParams(serviceName,cacheEnabled,cacheTimeout,metricsEnabled,host,port,cacheHost));
}
cMicroservice_Client* ClientFactory::createEvppCommandImpl(std::string serviceName,
std::string host,
int port,
bool cacheEnabled,
int cacheTimeout,
bool metricsEnabled,
std::string cacheHost){
return new cMicroservice_Client(new MSICommandClientEvppImpl(),
new cMicroservice_BaseClientParams(serviceName,cacheEnabled,cacheTimeout,metricsEnabled,host,port,cacheHost));
}
cMicroservice_Client *ClientFactory::createZmqMsgQImp(std::string serviceName, std::string host,
int port, Microservice_ZMQServerParams::eProtocol protocol,
bool cacheEnabled, int cacheTimeout, bool metricsEnabled,
......
......@@ -26,6 +26,13 @@ public:
int cacheTimeout = 0,
bool metricsEnabled = false,
std::string cacheHost = "");
static cMicroservice_Client* createEvppCommandImpl(std::string serviceName,
std::string host = "",
int port = 0,
bool cacheEnabled = false,
int cacheTimeout = 0,
bool metricsEnabled = false,
std::string cacheHost = "");
static cMicroservice_Client* createRMQImplMsClient();
static cMicroservice_Client* createZmqMsgQImp(std::string serviceName,
std::string host,
......
......@@ -109,8 +109,8 @@ public:
rpj_Doc.AddMember(rapidjson::StringRef(it->first.c_str()),rapidjson::StringRef(dequeIt->c_str()),rpj_Alloc);
}
}
// ReadSync(pc_reqCtx);
ReadAsync2(pc_reqCtx);
ReadSync(pc_reqCtx);
// ReadAsync2(pc_reqCtx);
//this->WriteObjectToResponse(pc_reqCtx,rpj_Doc);
// add metric
long value = rand() % 1000 + 1;
......@@ -124,10 +124,11 @@ public:
MSCommandParams cmd_params;
cmd_params
.WithEntity("http://172.16.1.132:5000/v1")
.WithParamsString("search")
.WithRequestParams("q=base")
.WithEntity("http://localhost:50010")
.WithParamsString("_mon/_stat")
//.WithRequestParams("q=base")
.WithHeadersMap(&headers);
MSRetStat retstat = p_rest_client_->Read(&cmd_params, &rest_response);
if(retstat.IsSuccess())
WriteObjectToResponse(pc_reqCtx, rest_response);
......@@ -380,10 +381,11 @@ int main(int argc, char *argv[])
.withMonitoring() // need to add reload
.withPubSub(NULL)
.withServiceDiscovery(NULL)
.addClient(ClientFactory::createHttpImplMsClient("other-service", "localhost", 32010, true, 10, false,"localhost:6379")) //new cMicroservice_Client(new MSICommandClientHttpImpl(),&clientParams))
.addClient(ClientFactory::createEvppCommandImpl("other-service", "localhost", 32010, true, 10, false,"localhost:6379"))
// .addClient(ClientFactory::createHttpImplMsClient("other-service", "localhost", 32010, true, 10, false,"localhost:6379"))
.addClient(ClientFactory::createZmqMsgQImp("zmq-service", msApp.name(), 0,
Microservice_ZMQServerParams::eProtocol::eIpc))
//.addServer(ServerFactory::createIRestServerCivetWebImpl("", 50010, 1))
.addServer(ServerFactory::createIRestServerCivetWebImpl("", 50020, 1))
.addServer(ServerFactory::createIRestServerEvppImpl("", 50010, 8))
.addServer(ServerFactory::createIMsgQueueServerZmqImpl(msApp.name(), 0, Microservice_ZMQServerParams::eProtocol::eIpc))
.addHandler("/xxx",(Microservice_RestHandler*)new cMicroserviceHandler("hello"))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment