use of io.servicecomb.foundation.common.net.IpPort in project java-chassis by ServiceComb.
the class ServiceRegistryClientImpl method updateMicroserviceProperties.
@Override
public boolean updateMicroserviceProperties(String microserviceId, Map<String, String> serviceProperties) {
Holder<HttpClientResponse> holder = new Holder<>();
IpPort ipPort = IpPortManager.INSTANCE.get();
StringBuilder url = new StringBuilder(Const.MS_API_PATH);
url.append(Const.MICROSERVICE_PATH).append("/").append(microserviceId).append(Const.PROPERTIES_PATH);
try {
UpdatePropertiesRequest request = new UpdatePropertiesRequest();
request.setProperties(serviceProperties);
byte[] body = JsonUtils.writeValueAsBytes(request);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("update properties of microservice: {}", new String(body, Charset.defaultCharset()));
}
CountDownLatch countDownLatch = new CountDownLatch(1);
RestUtils.put(ipPort, url.toString(), new RequestParam().setBody(body), syncHandler(countDownLatch, HttpClientResponse.class, holder));
countDownLatch.await();
if (holder.value != null) {
if (holder.value.statusCode() == Status.OK.getStatusCode()) {
return true;
}
LOGGER.warn(holder.value.statusMessage());
}
} catch (Exception e) {
LOGGER.error("update properties of microservice {} failed", microserviceId, e);
}
return false;
}
use of io.servicecomb.foundation.common.net.IpPort in project java-chassis by ServiceComb.
the class ServiceRegistryClientImpl method isSchemaExist.
@Override
public boolean isSchemaExist(String microserviceId, String schemaId) {
Holder<GetExistenceResponse> holder = new Holder<>();
IpPort ipPort = IpPortManager.INSTANCE.get();
CountDownLatch countDownLatch = new CountDownLatch(1);
RestUtils.get(ipPort, Const.MS_API_PATH + Const.EXISTENCE_PATH, new RequestParam().addQueryParam("type", "schema").addQueryParam("serviceId", microserviceId).addQueryParam("schemaId", schemaId), syncHandler(countDownLatch, GetExistenceResponse.class, holder));
try {
countDownLatch.await();
} catch (Exception e) {
LOGGER.error("query schema exist {}/{} fail", microserviceId, schemaId, e);
}
return holder.value != null;
}
use of io.servicecomb.foundation.common.net.IpPort in project java-chassis by ServiceComb.
the class IpPortManager method nextDefaultIpPort.
public IpPort nextDefaultIpPort() {
List<IpPort> addresses = getDefaultIpPortList();
if (addresses == null || addresses.size() == 0) {
LOGGER.warn("not exist any service center address");
return null;
}
synchronized (lockObj) {
//轮询一遍结束,暂不考虑并发场景
int id = indexForDefault.get();
if (id == addresses.size() - 1) {
indexForDefault.set(0);
LOGGER.warn("service center has no available instance");
return null;
}
indexForDefault.getAndIncrement();
LOGGER.info("service center address {}:{} is unreachable, retry another address {}:{}", addresses.get(id).getHostOrIp(), addresses.get(id).getPort(), addresses.get(indexForDefault.get()).getHostOrIp(), addresses.get(indexForDefault.get()).getPort());
return addresses.get(indexForDefault.get());
}
}
use of io.servicecomb.foundation.common.net.IpPort in project java-chassis by ServiceComb.
the class ServiceRegistryClientImpl method retry.
private static boolean retry(RequestContext requestContext, Handler<RestResponse> responseHandler) {
IpPort ipPort = IpPortManager.INSTANCE.next();
if (ipPort == null) {
return false;
}
requestContext.setIpPort(IpPortManager.INSTANCE.get());
RestUtils.httpDo(requestContext, responseHandler);
return true;
}
use of io.servicecomb.foundation.common.net.IpPort in project java-chassis by ServiceComb.
the class ServiceRegistryClientImpl method registerSchema.
@Override
public boolean registerSchema(String microserviceId, String schemaId, String schemaContent) {
Holder<HttpClientResponse> holder = new Holder<>();
IpPort ipPort = IpPortManager.INSTANCE.get();
try {
CreateSchemaRequest request = new CreateSchemaRequest();
request.setSchema(schemaContent);
byte[] body = JsonUtils.writeValueAsBytes(request);
CountDownLatch countDownLatch = new CountDownLatch(1);
RestUtils.put(ipPort, Const.MS_API_PATH + Const.MICROSERVICE_PATH + "/" + microserviceId + Const.SCHEMA_PATH + "/" + schemaId, new RequestParam().setBody(body), syncHandler(countDownLatch, HttpClientResponse.class, holder));
countDownLatch.await();
boolean result = false;
if (holder.value != null) {
result = holder.value.statusCode() == Status.OK.getStatusCode();
}
LOGGER.info("register schema {}/{}, result {}", microserviceId, schemaId, result);
return result;
} catch (Exception e) {
LOGGER.error("query schema exist {}/{} fail", microserviceId, schemaId, e);
}
return false;
}
Aggregations