Search in sources :

Example 1 with CreateSchemaRequest

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;
}
Also used : CreateSchemaRequest(org.apache.servicecomb.serviceregistry.api.request.CreateSchemaRequest) Holder(javax.xml.ws.Holder) IpPort(org.apache.servicecomb.foundation.common.net.IpPort) CountDownLatch(java.util.concurrent.CountDownLatch) ClientException(org.apache.servicecomb.serviceregistry.client.ClientException)

Example 2 with CreateSchemaRequest

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;
}
Also used : CreateSchemaRequest(org.apache.servicecomb.serviceregistry.api.request.CreateSchemaRequest) IpPort(org.apache.servicecomb.foundation.common.net.IpPort) CountDownLatch(java.util.concurrent.CountDownLatch) ClientException(org.apache.servicecomb.serviceregistry.client.ClientException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

CountDownLatch (java.util.concurrent.CountDownLatch)2 IpPort (org.apache.servicecomb.foundation.common.net.IpPort)2 CreateSchemaRequest (org.apache.servicecomb.serviceregistry.api.request.CreateSchemaRequest)2 ClientException (org.apache.servicecomb.serviceregistry.client.ClientException)2 IOException (java.io.IOException)1 ExecutionException (java.util.concurrent.ExecutionException)1 Holder (javax.xml.ws.Holder)1