use of org.apache.servicecomb.foundation.common.net.IpPort in project java-chassis by ServiceComb.
the class ServiceRegistryConfigBuilder method getIpPort.
public ArrayList<IpPort> getIpPort() {
List<String> uriList = Objects.requireNonNull(Deployment.getSystemBootStrapInfo(ServiceCenterDefaultDeploymentProvider.SYSTEM_KEY_SERVICE_CENTER), "no sc address found!").getAccessURL();
ArrayList<IpPort> ipPortList = new ArrayList<>();
uriList.forEach(anUriList -> {
try {
URI uri = new URI(anUriList.trim());
this.ssl = "https".equals(uri.getScheme());
ipPortList.add(NetUtils.parseIpPort(uri));
} catch (Exception e) {
LOGGER.error("servicecomb.service.registry.address invalid : {}", anUriList, e);
}
});
return ipPortList;
}
use of org.apache.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<ResponseWrapper> holder = new Holder<>();
IpPort ipPort = ipPortManager.getAvailableAddress();
try {
CreateSchemaRequest request = new CreateSchemaRequest();
request.setSchema(schemaContent);
request.setSummary(RegistryUtils.calcSchemaSummary(schemaContent));
byte[] body = JsonUtils.writeValueAsBytes(request);
CountDownLatch countDownLatch = new CountDownLatch(1);
restClientUtil.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 java-chassis by ServiceComb.
the class ServiceRegistryClientImpl method getMicroserviceInstance.
@Override
public List<MicroserviceInstance> getMicroserviceInstance(String consumerId, String providerId) {
Holder<GetInstancesResponse> holder = new Holder<>();
IpPort ipPort = ipPortManager.getAvailableAddress();
CountDownLatch countDownLatch = new CountDownLatch(1);
restClientUtil.get(ipPort, String.format(Const.REGISTRY_API.MICROSERVICE_INSTANCE_OPERATION_ALL, providerId), new RequestParam().addHeader("X-ConsumerId", consumerId), syncHandler(countDownLatch, GetInstancesResponse.class, holder));
try {
countDownLatch.await();
if (holder.value != null) {
return holder.value.getInstances();
}
} catch (Exception e) {
LOGGER.error("query microservice instances {} failed", providerId, e);
}
return null;
}
use of org.apache.servicecomb.foundation.common.net.IpPort in project java-chassis by ServiceComb.
the class ServiceRegistryClientImpl method heartbeat.
@Override
public HeartbeatResponse heartbeat(String microserviceId, String microserviceInstanceId) {
Holder<HttpClientResponse> holder = new Holder<>();
IpPort ipPort = ipPortManager.getAvailableAddress();
CountDownLatch countDownLatch = new CountDownLatch(1);
restClientUtil.put(ipPort, String.format(Const.REGISTRY_API.MICROSERVICE_HEARTBEAT, microserviceId, microserviceInstanceId), new RequestParam().setTimeout(ServiceRegistryConfig.INSTANCE.getHeartBeatRequestTimeout()), syncHandler(countDownLatch, HttpClientResponse.class, holder));
try {
countDownLatch.await();
if (holder.value != null) {
HeartbeatResponse response = new HeartbeatResponse();
response.setMessage(holder.value.statusMessage());
if (holder.value.statusCode() == Status.OK.getStatusCode()) {
response.setOk(true);
return response;
}
ipPortManager.recordState(ipPort.toString());
LOGGER.warn(holder.value.statusMessage());
return response;
}
} catch (Exception e) {
LOGGER.error("update microservice instance {}/{} heartbeat failed", microserviceId, microserviceInstanceId, e);
}
return null;
}
Aggregations