private string requestNewToken() { string extendUrl = "/api/auth/token?username="******"&password="******"", AUTH_CONTENT_TYPE); if (response.isSuccess()) { log.Debug("Request new Inspur TSDB token"); Dictionary <string, string> token = JsonConvert.DeserializeObject <Dictionary <string, string> >(response.getContent()); return(token["token"]); } else { log.ErrorFormat("获取TSDB token失败,response error:" + response.getContent()); throw new Exception("Response error:" + response.getContent()); } } catch (Exception e) { log.ErrorFormat("获取TSDB token失败:{0},{1}", e.Message, e.StackTrace); throw; } }
private Response getResponse(SimpleHttpResponse httpResponse) { Response response = new Response(httpResponse.getStatusCode()); string content = httpResponse.getContent(); if (!string.IsNullOrEmpty(content)) { if (response.isSuccess()) { ErrorDetail errorDetail = JsonConvert.DeserializeObject <ErrorDetail>(content); response.setErrorDetail(errorDetail); } else { //logger.error("request failed!" + httpResponse); //获取数据失败了,可能是auth 过期,把缓存清掉 deleteCurrentToken(); } } return(response); }
public override SimpleHttpResponse pushLastQueries(String content, ExpectResponse expectResponse) { if (content == null) { throw new Exception("content 不能为空"); } int tryTime = 1; SimpleHttpResponse response = null; while (tryTime <= maxTryTimes) { response = httpClient.doPost(buildUrl(serviceUrl, GetAuthUrl(QUERY_POST_LAST_API), expectResponse), content); if (response.isSuccess()) { break; } else { log.ErrorFormat("[InspurTSDB]Get Response Error,Try Times:{0} ,Status Code: {1},Content: {2}", tryTime, response.getStatusCode(), response.getContent()); if (response.getStatusCode() == 401) { deleteCurrentToken(); } tryTime++; } } return(response); }
public override Response pushMetrics(MetricBuilder builder, ExpectResponse expectResponse) { if (builder == null) { throw new Exception("QueryBuilder 不能为空"); } int tryTime = 1; SimpleHttpResponse response = null; while (tryTime <= maxTryTimes) { response = httpClient.doPost(buildUrl(serviceUrl, GetAuthUrl(PUT_POST_API), expectResponse), builder.build()); if (response.isSuccess()) { break; } else { log.ErrorFormat("[InspurTSDB]Get Response Error,Try Times:{0} ,Status Code: {1},Content: {2}", tryTime, response.getStatusCode(), response.getContent()); if (response.getStatusCode() == 401) { deleteCurrentToken(); } tryTime++; } } return(getResponse(response)); }