use of org.apache.servicecomb.foundation.common.net.IpPort in project incubator-servicecomb-java-chassis by apache.
the class ServiceRegistryClientImpl method getServiceCenterInfo.
@Override
public ServiceCenterInfo getServiceCenterInfo() {
Holder<ServiceCenterInfo> holder = new Holder<>();
IpPort ipPort = ipPortManager.getAvailableAddress();
CountDownLatch countDownLatch = new CountDownLatch(1);
RestUtils.get(ipPort, Const.REGISTRY_API.SERVICECENTER_VERSION, new RequestParam(), syncHandler(countDownLatch, ServiceCenterInfo.class, holder));
try {
countDownLatch.await();
if (holder.value != null) {
return holder.value;
}
} catch (Exception e) {
LOGGER.error("query servicecenter version info failed.", e);
}
return null;
}
use of org.apache.servicecomb.foundation.common.net.IpPort in project incubator-servicecomb-java-chassis by apache.
the class ServiceRegistryClientImpl method registerMicroservice.
@Override
public String registerMicroservice(Microservice microservice) {
Holder<CreateServiceResponse> holder = new Holder<>();
IpPort ipPort = ipPortManager.getAvailableAddress();
try {
CreateServiceRequest request = new CreateServiceRequest();
request.setService(microservice);
byte[] body = JsonUtils.writeValueAsBytes(request);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("register microservice: {}", new String(body, Charset.defaultCharset()));
}
CountDownLatch countDownLatch = new CountDownLatch(1);
RestUtils.post(ipPort, Const.REGISTRY_API.MICROSERVICE_OPERATION_ALL, new RequestParam().setBody(body), syncHandler(countDownLatch, CreateServiceResponse.class, holder));
countDownLatch.await();
if (holder.value != null) {
return holder.value.getServiceId();
}
} catch (Exception e) {
LOGGER.error("register microservice {}/{}/{} failed", microservice.getAppId(), microservice.getServiceName(), microservice.getVersion(), e);
}
return null;
}
use of org.apache.servicecomb.foundation.common.net.IpPort in project incubator-servicecomb-java-chassis by apache.
the class ServiceRegistryClientImpl method unregisterMicroserviceInstance.
@Override
public boolean unregisterMicroserviceInstance(String microserviceId, String microserviceInstanceId) {
Holder<HttpClientResponse> holder = new Holder<>();
IpPort ipPort = ipPortManager.getAvailableAddress();
CountDownLatch countDownLatch = new CountDownLatch(1);
RestUtils.delete(ipPort, String.format(Const.REGISTRY_API.MICROSERVICE_INSTANCE_OPERATION_ONE, microserviceId, microserviceInstanceId), new RequestParam(), syncHandler(countDownLatch, HttpClientResponse.class, holder));
try {
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("unregister microservice instance {}/{} failed", microserviceId, microserviceInstanceId, e);
}
return false;
}
use of org.apache.servicecomb.foundation.common.net.IpPort in project incubator-servicecomb-java-chassis by apache.
the class ServiceRegistryClientImpl method registerSchema.
@Override
public boolean registerSchema(String microserviceId, String schemaId, String schemaContent) {
Holder<ResponseWrapper> holder = new Holder<>();
IpPort ipPort = ipPortManager.getAvailableAddress();
try {
CreateSchemaRequest request = new CreateSchemaRequest();
request.setSchema(schemaContent);
byte[] body = JsonUtils.writeValueAsBytes(request);
CountDownLatch countDownLatch = new CountDownLatch(1);
RestUtils.put(ipPort, String.format(Const.REGISTRY_API.MICROSERVICE_SCHEMA, microserviceId, schemaId), new RequestParam().setBody(body), syncHandlerEx(countDownLatch, holder));
countDownLatch.await();
if (holder.value == null) {
LOGGER.error("Register schema {}/{} failed.", microserviceId, schemaId);
return false;
}
if (!Status.Family.SUCCESSFUL.equals(Status.Family.familyOf(holder.value.response.statusCode()))) {
LOGGER.error("Register schema {}/{} failed, statusCode: {}, statusMessage: {}, description: {}.", microserviceId, schemaId, holder.value.response.statusCode(), holder.value.response.statusMessage(), holder.value.bodyBuffer.toString());
return false;
}
LOGGER.info("register schema {}/{} success.", microserviceId, schemaId);
return true;
} catch (Exception e) {
LOGGER.error("register schema {}/{} fail.", microserviceId, schemaId, e);
}
return false;
}
use of org.apache.servicecomb.foundation.common.net.IpPort in project incubator-servicecomb-java-chassis by apache.
the class ServiceRegistryClientImpl method registerMicroserviceInstance.
@Override
public String registerMicroserviceInstance(MicroserviceInstance instance) {
Holder<RegisterInstanceResponse> holder = new Holder<>();
IpPort ipPort = ipPortManager.getAvailableAddress();
try {
RegisterInstanceRequest request = new RegisterInstanceRequest();
request.setInstance(instance);
byte[] body = JsonUtils.writeValueAsBytes(request);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("register microservice: {}", new String(body, Charset.defaultCharset()));
}
CountDownLatch countDownLatch = new CountDownLatch(1);
RestUtils.post(ipPort, String.format(Const.REGISTRY_API.MICROSERVICE_INSTANCE_OPERATION_ALL, instance.getServiceId()), new RequestParam().setBody(body), syncHandler(countDownLatch, RegisterInstanceResponse.class, holder));
countDownLatch.await();
if (holder.value != null) {
return holder.value.getInstanceId();
}
} catch (Exception e) {
LOGGER.error("register microservice instance {} failed", instance.getServiceId(), e);
}
return null;
}
Aggregations