in client.cpp [1863:1910]
MergeShardsResponse LOGClient::MergeShard(const string& project, const string& logstore,const int shardId)
{
if (project.empty() || logstore.empty())
throw LOGException(LOGE_PARAMETER_INVALID, "project or logstore invalid.");
string operation = LOGSTORES + string("/") + logstore + SHARDS+string("/") + std::to_string(shardId);;
string body = "";
map<string, string> parameterList;
parameterList["action"] = "merge";
SetCommonParameter(parameterList);
map<string, string> httpHeader;
httpHeader[X_LOG_BODYRAWSIZE] = std::to_string(body.length());
httpHeader[CONTENT_TYPE] = "";
HttpMessage httpResponse;
SendRequest(project, HTTP_POST, operation, body, parameterList, httpHeader, httpResponse);
rapidjson::Document document;
ExtractJsonResult(httpResponse.content, document);
ListShardsResponse ret;
ret.statusCode = httpResponse.statusCode;
ret.requestId = httpResponse.header[X_LOG_REQUEST_ID];
if (document.IsArray())
{
for (rapidjson::Value::ConstValueIterator itr = document.Begin(); itr != document.End(); ++itr)
{
if (itr->IsObject())
{
ShardItem shardItem;
ExtractJsonResult(*itr, "shardID", shardItem.shardId);
ExtractJsonResult(*itr,"status",shardItem.status);
ExtractJsonResult(*itr,"inclusiveBeginKey",shardItem.inclusiveBeginKey);
ExtractJsonResult(*itr,"exclusiveEndKey",shardItem.exclusiveEndKey);
ExtractJsonResult(*itr,"createTime",shardItem.createTime);
ret.result.push_back(shardItem);
}
else
{
throw LOGException(LOGE_BAD_RESPONSE, string("Invalid json format, value is not json object type\tbad json format:") + httpResponse.content, httpResponse.header[X_LOG_REQUEST_ID], httpResponse.statusCode);
}
}
}
return ret;
}