use of org.apache.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.getAvailableAddress();
CountDownLatch countDownLatch = new CountDownLatch(1);
restClientUtil.get(ipPort, Const.REGISTRY_API.MICROSERVICE_EXISTENCE, 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 && schemaId.equals(holder.value.getSchemaId());
}
use of org.apache.servicecomb.foundation.common.net.IpPort in project java-chassis by ServiceComb.
the class ServiceRegistryClientImpl method updateInstanceProperties.
@Override
public boolean updateInstanceProperties(String microserviceId, String microserviceInstanceId, Map<String, String> instanceProperties) {
Holder<HttpClientResponse> holder = new Holder<>();
IpPort ipPort = ipPortManager.getAvailableAddress();
try {
UpdatePropertiesRequest request = new UpdatePropertiesRequest();
request.setProperties(instanceProperties);
byte[] body = JsonUtils.writeValueAsBytes(request);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("update properties of microservice instance: {}", new String(body, Charset.defaultCharset()));
}
CountDownLatch countDownLatch = new CountDownLatch(1);
restClientUtil.put(ipPort, String.format(Const.REGISTRY_API.MICROSERVICE_INSTANCE_PROPERTIES, microserviceId, microserviceInstanceId), 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 instance {}/{} failed", microserviceId, microserviceInstanceId, e);
}
return false;
}
use of org.apache.servicecomb.foundation.common.net.IpPort in project java-chassis by ServiceComb.
the class ServiceRegistryClientImpl method doGetSchema.
private String doGetSchema(String microserviceId, String schemaId, boolean global) {
try {
// avoid query too many times of schema when first time loading
String cachedSchema = schemaCache.get(microserviceId).get(schemaId);
if (cachedSchema != null) {
return cachedSchema;
}
} catch (ExecutionException e) {
// ignore this error.
}
Holder<GetSchemaResponse> holder = new Holder<>();
IpPort ipPort = ipPortManager.getAvailableAddress();
CountDownLatch countDownLatch = new CountDownLatch(1);
RequestParam param = new RequestParam();
if (global) {
param.addQueryParam("global", "true");
}
restClientUtil.get(ipPort, String.format(Const.REGISTRY_API.MICROSERVICE_SCHEMA, microserviceId, schemaId), param, syncHandler(countDownLatch, GetSchemaResponse.class, holder));
try {
countDownLatch.await();
} catch (Exception e) {
LOGGER.error("query schema exist {}/{} failed", schemaId, e);
}
if (holder.value != null) {
return holder.value.getSchema();
}
return null;
}
use of org.apache.servicecomb.foundation.common.net.IpPort in project java-chassis by ServiceComb.
the class ServiceRegistryClientImpl method getSchemas.
private Holder<List<GetSchemaResponse>> getSchemas(String microserviceId, boolean withSchema, boolean global) {
Holder<GetSchemasResponse> holder = new Holder<>();
IpPort ipPort = ipPortManager.getAvailableAddress();
Holder<List<GetSchemaResponse>> resultHolder = new Holder<>();
CountDownLatch countDownLatch = new CountDownLatch(1);
String url = Const.REGISTRY_API.MICROSERVICE_ALL_SCHEMAs;
RequestParam requestParam = new RequestParam();
if (withSchema) {
url = Const.REGISTRY_API.MICROSERVICE_ALL_SCHEMAs + "?withSchema=1";
}
if (global) {
requestParam.addQueryParam("global", "true");
}
restClientUtil.get(ipPort, String.format(url, microserviceId), requestParam, syncHandler(countDownLatch, GetSchemasResponse.class, holder));
try {
countDownLatch.await();
} catch (Exception e) {
LOGGER.error("query all schemas {} failed", microserviceId, e);
}
resultHolder.setStatusCode(holder.getStatusCode()).setThrowable(holder.getThrowable());
if (holder.value != null) {
return resultHolder.setValue(holder.value.getSchema() != null ? holder.value.getSchema() : holder.value.getSchemas());
}
return resultHolder;
}
use of org.apache.servicecomb.foundation.common.net.IpPort in project java-chassis by ServiceComb.
the class ServiceRegistryClientImpl method getMicroserviceId.
@Override
public String getMicroserviceId(String appId, String microserviceName, String versionRule, String environment) {
Holder<GetExistenceResponse> holder = new Holder<>();
IpPort ipPort = ipPortManager.getAvailableAddress();
CountDownLatch countDownLatch = new CountDownLatch(1);
restClientUtil.get(ipPort, Const.REGISTRY_API.MICROSERVICE_EXISTENCE, new RequestParam().addQueryParam("type", "microservice").addQueryParam("appId", appId).addQueryParam("serviceName", microserviceName).addQueryParam("version", versionRule).addQueryParam("env", environment), syncHandler(countDownLatch, GetExistenceResponse.class, holder));
try {
countDownLatch.await();
if (holder.value != null) {
return holder.value.getServiceId();
}
} catch (Exception e) {
LOGGER.error("query microservice id {}/{}/{} fail", appId, microserviceName, versionRule, e);
}
return null;
}
Aggregations