Search in sources :

Example 1 with CreateMicroserviceInstanceRequest

use of org.apache.servicecomb.service.center.client.model.CreateMicroserviceInstanceRequest in project java-chassis by ServiceComb.

the class ServiceCenterClient method registerMicroserviceInstance.

@Override
public RegisteredMicroserviceInstanceResponse registerMicroserviceInstance(MicroserviceInstance instance) {
    try {
        CreateMicroserviceInstanceRequest request = new CreateMicroserviceInstanceRequest();
        request.setInstance(instance);
        HttpResponse response = httpClient.postHttpRequest("/registry/microservices/" + instance.getServiceId() + "/instances", null, HttpUtils.serialize(request));
        if (response.getStatusCode() == HttpStatus.SC_OK) {
            return HttpUtils.deserialize(response.getContent(), RegisteredMicroserviceInstanceResponse.class);
        }
        sendUnAuthorizedEvent(response);
        throw new OperationException("register service instance fails, statusCode = " + response.getStatusCode() + "; message = " + response.getMessage() + "; content = " + response.getContent());
    } catch (IOException e) {
        throw new OperationException("register service instance fails", e);
    }
}
Also used : CreateMicroserviceInstanceRequest(org.apache.servicecomb.service.center.client.model.CreateMicroserviceInstanceRequest) HttpResponse(org.apache.servicecomb.http.client.common.HttpResponse) IOException(java.io.IOException) OperationException(org.apache.servicecomb.service.center.client.exception.OperationException)

Aggregations

IOException (java.io.IOException)1 HttpResponse (org.apache.servicecomb.http.client.common.HttpResponse)1 OperationException (org.apache.servicecomb.service.center.client.exception.OperationException)1 CreateMicroserviceInstanceRequest (org.apache.servicecomb.service.center.client.model.CreateMicroserviceInstanceRequest)1