Search in sources :

Example 1 with CreateServiceRequest

use of org.apache.servicecomb.serviceregistry.api.request.CreateServiceRequest in project incubator-servicecomb-java-chassis by apache.

the class ServiceRegistryClientImpl method registerMicroservice.

@Override
public String registerMicroservice(Microservice microservice) {
    Holder<CreateServiceResponse> holder = new Holder<>();
    IpPort ipPort = ipPortManager.getAvailableAddress();
    try {
        CreateServiceRequest request = new CreateServiceRequest();
        request.setService(microservice);
        byte[] body = JsonUtils.writeValueAsBytes(request);
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("register microservice: {}", new String(body, Charset.defaultCharset()));
        }
        CountDownLatch countDownLatch = new CountDownLatch(1);
        RestUtils.post(ipPort, Const.REGISTRY_API.MICROSERVICE_OPERATION_ALL, new RequestParam().setBody(body), syncHandler(countDownLatch, CreateServiceResponse.class, holder));
        countDownLatch.await();
        if (holder.value != null) {
            return holder.value.getServiceId();
        }
    } catch (Exception e) {
        LOGGER.error("register microservice {}/{}/{} failed", microservice.getAppId(), microservice.getServiceName(), microservice.getVersion(), e);
    }
    return null;
}
Also used : CreateServiceRequest(org.apache.servicecomb.serviceregistry.api.request.CreateServiceRequest) Holder(javax.xml.ws.Holder) CreateServiceResponse(org.apache.servicecomb.serviceregistry.api.response.CreateServiceResponse) IpPort(org.apache.servicecomb.foundation.common.net.IpPort) CountDownLatch(java.util.concurrent.CountDownLatch) ClientException(org.apache.servicecomb.serviceregistry.client.ClientException)

Example 2 with CreateServiceRequest

use of org.apache.servicecomb.serviceregistry.api.request.CreateServiceRequest in project java-chassis by ServiceComb.

the class ServiceRegistryClientImpl method registerMicroservice.

@Override
public String registerMicroservice(Microservice microservice) {
    Holder<CreateServiceResponse> holder = new Holder<>();
    IpPort ipPort = ipPortManager.getAvailableAddress();
    try {
        CreateServiceRequest request = new CreateServiceRequest();
        request.setService(microservice);
        byte[] body = JsonUtils.writeValueAsBytes(request);
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("register microservice: {}", new String(body, Charset.defaultCharset()));
        }
        CountDownLatch countDownLatch = new CountDownLatch(1);
        restClientUtil.post(ipPort, Const.REGISTRY_API.MICROSERVICE_OPERATION_ALL, new RequestParam().setBody(body), syncHandler(countDownLatch, CreateServiceResponse.class, holder));
        countDownLatch.await();
        if (holder.value != null) {
            return holder.value.getServiceId();
        }
    } catch (Exception e) {
        LOGGER.error("register microservice {}/{}/{} failed", microservice.getAppId(), microservice.getServiceName(), microservice.getVersion(), e);
    }
    return null;
}
Also used : CreateServiceRequest(org.apache.servicecomb.serviceregistry.api.request.CreateServiceRequest) CreateServiceResponse(org.apache.servicecomb.serviceregistry.api.response.CreateServiceResponse) 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 CreateServiceRequest (org.apache.servicecomb.serviceregistry.api.request.CreateServiceRequest)2 CreateServiceResponse (org.apache.servicecomb.serviceregistry.api.response.CreateServiceResponse)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