use of com.alibaba.nacos.common.http.param.Query in project nacos by alibaba.
the class NacosRestTemplate_ITCase method test_url_get.
@Test
public void test_url_get() throws Exception {
String url = IP + INSTANCE_PATH + "/instance/list";
Query query = Query.newInstance().addParam("serviceName", "app-test");
HttpRestResult<Map> restResult = nacosRestTemplate.get(url, Header.newInstance(), query, Map.class);
Assert.assertTrue(restResult.ok());
Assert.assertEquals(restResult.getData().get("name"), "DEFAULT_GROUP@@app-test");
System.out.println(restResult.getData());
}
use of com.alibaba.nacos.common.http.param.Query in project nacos by alibaba.
the class NacosAsyncRestTemplate_ITCase method test_url_delete.
@Test
public void test_url_delete() throws Exception {
String url = IP + CONFIG_INSTANCE_PATH + "/instance";
Query query = Query.newInstance().addParam("ip", "11.11.11.11").addParam("port", "8080").addParam("serviceName", "app-test");
CallbackMap<String> callbackMap = new CallbackMap<>();
nacosRestTemplate.delete(url, Header.newInstance(), query, String.class, callbackMap);
Thread.sleep(2000);
HttpRestResult<String> restResult = callbackMap.getRestResult();
System.out.println(restResult.getData());
System.out.println(restResult.getHeader());
Assert.assertTrue(restResult.ok());
}
use of com.alibaba.nacos.common.http.param.Query in project nacos by alibaba.
the class ServerListManager method getServerListFromEndpoint.
private List<String> getServerListFromEndpoint() {
try {
String urlString = HTTP_PREFIX + endpoint + "/nacos/serverlist";
Header header = NamingHttpUtil.builderHeader();
Query query = StringUtils.isNotBlank(namespace) ? Query.newInstance().addParam("namespace", namespace) : Query.EMPTY;
HttpRestResult<String> restResult = nacosRestTemplate.get(urlString, header, query, String.class);
if (!restResult.ok()) {
throw new IOException("Error while requesting: " + urlString + "'. Server returned: " + restResult.getCode());
}
String content = restResult.getData();
List<String> list = new ArrayList<String>();
for (String line : IoUtils.readLines(new StringReader(content))) {
if (!line.trim().isEmpty()) {
list.add(line.trim());
}
}
return list;
} catch (Exception e) {
NAMING_LOGGER.error("[SERVER-LIST] failed to update server list.", e);
}
return null;
}
use of com.alibaba.nacos.common.http.param.Query in project nacos by alibaba.
the class ClientMetricsController method metric.
/**
* get client metric.
*
* @param ip client ip .
* @return ResponseEntity
*/
@GetMapping("/cluster")
public ResponseEntity metric(@RequestParam("ip") String ip, @RequestParam(value = "dataId", required = false) String dataId, @RequestParam(value = "group", required = false) String group, @RequestParam(value = "tenant", required = false) String tenant) {
Loggers.CORE.info("Get cluster config metrics received, ip={},dataId={},group={},tenant={}", ip, dataId, group, tenant);
Map<String, Object> responseMap = new HashMap<>(3);
Collection<Member> members = serverMemberManager.allMembers();
final NacosAsyncRestTemplate nacosAsyncRestTemplate = HttpClientBeanHolder.getNacosAsyncRestTemplate(Loggers.CLUSTER);
CountDownLatch latch = new CountDownLatch(members.size());
for (Member member : members) {
String url = HttpUtils.buildUrl(false, member.getAddress(), EnvUtil.getContextPath(), Constants.METRICS_CONTROLLER_PATH, "current");
Query query = Query.newInstance().addParam("ip", ip).addParam("dataId", dataId).addParam("group", group).addParam("tenant", tenant);
nacosAsyncRestTemplate.get(url, Header.EMPTY, query, new GenericType<Map>() {
}.getType(), new Callback<Map>() {
@Override
public void onReceive(RestResult<Map> result) {
if (result.ok()) {
responseMap.putAll(result.getData());
}
latch.countDown();
}
@Override
public void onError(Throwable throwable) {
Loggers.CORE.error("Get config metrics error from member address={}, ip={},dataId={},group={},tenant={},error={}", member.getAddress(), ip, dataId, group, tenant, throwable);
latch.countDown();
}
@Override
public void onCancel() {
latch.countDown();
}
});
}
try {
latch.await(3L, TimeUnit.SECONDS);
} catch (InterruptedException e) {
e.printStackTrace();
}
return ResponseEntity.ok().body(responseMap);
}
use of com.alibaba.nacos.common.http.param.Query in project nacos by alibaba.
the class NacosRestTemplate_ITCase method test_url_get_return_restResult.
@Test
public void test_url_get_return_restResult() throws Exception {
String url = IP + CONFIG_PATH + "/configs";
Query query = Query.newInstance().addParam("beta", true).addParam("dataId", "test-1").addParam("group", "DEFAULT_GROUP");
HttpRestResult<ConfigInfo4Beta> restResult = nacosRestTemplate.get(url, Header.newInstance(), query, new TypeReference<RestResult<ConfigInfo4Beta>>() {
}.getType());
Assert.assertTrue(restResult.ok());
System.out.println(restResult.getData());
System.out.println(restResult.getHeader());
}
Aggregations