use of org.apache.servicecomb.serviceregistry.api.request.CreateSchemaRequest 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.serviceregistry.api.request.CreateSchemaRequest 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;
}
Aggregations