Search in sources :

Example 1 with CreateSchemaRequest

use of io.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<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;
}
Also used : CreateSchemaRequest(io.servicecomb.serviceregistry.api.request.CreateSchemaRequest) Holder(javax.xml.ws.Holder) HttpClientResponse(io.vertx.core.http.HttpClientResponse) IpPort(io.servicecomb.foundation.common.net.IpPort) CountDownLatch(java.util.concurrent.CountDownLatch) ClientException(io.servicecomb.serviceregistry.client.ClientException)

Aggregations

IpPort (io.servicecomb.foundation.common.net.IpPort)1 CreateSchemaRequest (io.servicecomb.serviceregistry.api.request.CreateSchemaRequest)1 ClientException (io.servicecomb.serviceregistry.client.ClientException)1 HttpClientResponse (io.vertx.core.http.HttpClientResponse)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Holder (javax.xml.ws.Holder)1