Search in sources :

Example 26 with OperationException

use of org.apache.servicecomb.service.center.client.exception.OperationException in project incubator-servicecomb-java-chassis by apache.

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)

Example 27 with OperationException

use of org.apache.servicecomb.service.center.client.exception.OperationException in project incubator-servicecomb-java-chassis by apache.

the class ServiceCenterClient method batchUpdateServiceSchemaContext.

@Override
public boolean batchUpdateServiceSchemaContext(String serviceId, ModifySchemasRequest modifySchemasRequest) {
    try {
        HttpResponse response = httpClient.postHttpRequest("/registry/microservices/" + serviceId + "/schemas", null, HttpUtils.serialize(modifySchemasRequest));
        if (response.getStatusCode() == HttpStatus.SC_OK) {
            return true;
        }
        sendUnAuthorizedEvent(response);
        throw new OperationException("update service schema fails, statusCode = " + response.getStatusCode() + "; message = " + response.getMessage() + "; content = " + response.getContent());
    } catch (IOException e) {
        throw new OperationException("update service schema fails", e);
    }
}
Also used : HttpResponse(org.apache.servicecomb.http.client.common.HttpResponse) IOException(java.io.IOException) OperationException(org.apache.servicecomb.service.center.client.exception.OperationException)

Example 28 with OperationException

use of org.apache.servicecomb.service.center.client.exception.OperationException in project incubator-servicecomb-java-chassis by apache.

the class ServiceCenterClient method sendHeartBeats.

@Override
public void sendHeartBeats(HeartbeatsRequest heartbeatsRequest) {
    try {
        HttpResponse response = httpClient.putHttpRequest("/registry/heartbeats", null, HttpUtils.serialize(heartbeatsRequest));
        if (response.getStatusCode() == HttpStatus.SC_OK) {
            return;
        }
        sendUnAuthorizedEvent(response);
        throw new OperationException("heartbeats fails, statusCode = " + response.getStatusCode() + "; message = " + response.getMessage() + "; content = " + response.getContent());
    } catch (IOException e) {
        throw new OperationException("heartbeats fails ", e);
    }
}
Also used : HttpResponse(org.apache.servicecomb.http.client.common.HttpResponse) IOException(java.io.IOException) OperationException(org.apache.servicecomb.service.center.client.exception.OperationException)

Example 29 with OperationException

use of org.apache.servicecomb.service.center.client.exception.OperationException in project incubator-servicecomb-java-chassis by apache.

the class ServiceCenterClient method updateMicroserviceInstanceStatus.

@Override
public boolean updateMicroserviceInstanceStatus(String serviceId, String instanceId, MicroserviceInstanceStatus status) {
    try {
        HttpResponse response = httpClient.putHttpRequest("/registry/microservices/" + serviceId + "/instances/" + instanceId + "/status?value=" + status, null, null);
        if (response.getStatusCode() == HttpStatus.SC_OK) {
            return true;
        }
        sendUnAuthorizedEvent(response);
        throw new OperationException("update service instance status fails, statusCode = " + response.getStatusCode() + "; message = " + response.getMessage() + "; content = " + response.getContent());
    } catch (IOException e) {
        throw new OperationException("update service instance status fails", e);
    }
}
Also used : HttpResponse(org.apache.servicecomb.http.client.common.HttpResponse) IOException(java.io.IOException) OperationException(org.apache.servicecomb.service.center.client.exception.OperationException)

Example 30 with OperationException

use of org.apache.servicecomb.service.center.client.exception.OperationException in project incubator-servicecomb-java-chassis by apache.

the class ServiceCenterClient method getMicroserviceInstance.

@Override
public MicroserviceInstance getMicroserviceInstance(String serviceId, String instanceId) {
    try {
        HttpResponse response = httpClient.getHttpRequest("/registry/microservices/" + serviceId + "/instances/" + instanceId, null, null);
        if (response.getStatusCode() == HttpStatus.SC_OK) {
            MicroserviceInstanceResponse instanceResponse = HttpUtils.deserialize(response.getContent(), MicroserviceInstanceResponse.class);
            return instanceResponse.getInstance();
        }
        sendUnAuthorizedEvent(response);
        throw new OperationException("get service instance message fails, statusCode = " + response.getStatusCode() + "; message = " + response.getMessage() + "; content = " + response.getContent());
    } catch (IOException e) {
        throw new OperationException("get service instance message fails", e);
    }
}
Also used : HttpResponse(org.apache.servicecomb.http.client.common.HttpResponse) IOException(java.io.IOException) OperationException(org.apache.servicecomb.service.center.client.exception.OperationException) RegisteredMicroserviceInstanceResponse(org.apache.servicecomb.service.center.client.model.RegisteredMicroserviceInstanceResponse) MicroserviceInstanceResponse(org.apache.servicecomb.service.center.client.model.MicroserviceInstanceResponse)

Aggregations

IOException (java.io.IOException)38 HttpResponse (org.apache.servicecomb.http.client.common.HttpResponse)38 OperationException (org.apache.servicecomb.service.center.client.exception.OperationException)38 URISyntaxException (java.net.URISyntaxException)2 HashMap (java.util.HashMap)2 URIBuilder (org.apache.http.client.utils.URIBuilder)2 CreateMicroserviceInstanceRequest (org.apache.servicecomb.service.center.client.model.CreateMicroserviceInstanceRequest)2 CreateMicroserviceRequest (org.apache.servicecomb.service.center.client.model.CreateMicroserviceRequest)2 CreateSchemaRequest (org.apache.servicecomb.service.center.client.model.CreateSchemaRequest)2 ErrorMessage (org.apache.servicecomb.service.center.client.model.ErrorMessage)2 FindMicroserviceInstancesResponse (org.apache.servicecomb.service.center.client.model.FindMicroserviceInstancesResponse)2 GetSchemaListResponse (org.apache.servicecomb.service.center.client.model.GetSchemaListResponse)2 GetSchemaResponse (org.apache.servicecomb.service.center.client.model.GetSchemaResponse)2 MicroserviceInstanceResponse (org.apache.servicecomb.service.center.client.model.MicroserviceInstanceResponse)2 MicroserviceInstancesResponse (org.apache.servicecomb.service.center.client.model.MicroserviceInstancesResponse)2 MicroserviceResponse (org.apache.servicecomb.service.center.client.model.MicroserviceResponse)2 RbacTokenResponse (org.apache.servicecomb.service.center.client.model.RbacTokenResponse)2 RegisteredMicroserviceInstanceResponse (org.apache.servicecomb.service.center.client.model.RegisteredMicroserviceInstanceResponse)2 RegisteredMicroserviceResponse (org.apache.servicecomb.service.center.client.model.RegisteredMicroserviceResponse)2