Search in sources :

Example 1 with HttpResponse

use of org.apache.servicecomb.http.client.common.HttpResponse in project java-chassis by ServiceComb.

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 2 with HttpResponse

use of org.apache.servicecomb.http.client.common.HttpResponse in project java-chassis by ServiceComb.

the class ServiceCenterClient method getMicroserviceList.

@Override
public MicroservicesResponse getMicroserviceList() {
    try {
        HttpResponse response = httpClient.getHttpRequest("/registry/microservices", null, null);
        if (response.getStatusCode() == HttpStatus.SC_OK) {
            return HttpUtils.deserialize(response.getContent(), MicroservicesResponse.class);
        }
        sendUnAuthorizedEvent(response);
        throw new OperationException("get service List fails, statusCode = " + response.getStatusCode() + "; message = " + response.getMessage() + "; content = " + response.getContent());
    } catch (IOException e) {
        throw new OperationException("get service List 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 3 with HttpResponse

use of org.apache.servicecomb.http.client.common.HttpResponse in project java-chassis by ServiceComb.

the class ServiceCenterClient method findMicroserviceInstance.

@Override
public FindMicroserviceInstancesResponse findMicroserviceInstance(String consumerId, String appId, String serviceName, String versionRule, String revision) {
    try {
        Map<String, String> headers = new HashMap<>();
        headers.put("X-ConsumerId", consumerId);
        HttpResponse response = httpClient.getHttpRequest("/registry/instances?appId=" + URLEncoder.encode(appId, "UTF-8") + "&serviceName=" + HttpUtils.encodeURLParam(serviceName) + "&version=" + HttpUtils.encodeURLParam(versionRule) + "&rev=" + HttpUtils.encodeURLParam(revision), headers, null);
        FindMicroserviceInstancesResponse result = new FindMicroserviceInstancesResponse();
        if (response.getStatusCode() == HttpStatus.SC_OK) {
            result.setModified(true);
            result.setRevision(response.getHeader("X-Resource-Revision"));
            result.setMicroserviceInstancesResponse(HttpUtils.deserialize(response.getContent(), MicroserviceInstancesResponse.class));
            return result;
        }
        if (response.getStatusCode() == HttpStatus.SC_NOT_MODIFIED) {
            result.setModified(false);
            return result;
        }
        sendUnAuthorizedEvent(response);
        throw new OperationException("get service instances list fails, statusCode = " + response.getStatusCode() + "; message = " + response.getMessage() + "; content = " + response.getContent());
    } catch (IOException e) {
        throw new OperationException("get service instances list fails", e);
    }
}
Also used : MicroserviceInstancesResponse(org.apache.servicecomb.service.center.client.model.MicroserviceInstancesResponse) FindMicroserviceInstancesResponse(org.apache.servicecomb.service.center.client.model.FindMicroserviceInstancesResponse) HashMap(java.util.HashMap) HttpResponse(org.apache.servicecomb.http.client.common.HttpResponse) FindMicroserviceInstancesResponse(org.apache.servicecomb.service.center.client.model.FindMicroserviceInstancesResponse) IOException(java.io.IOException) OperationException(org.apache.servicecomb.service.center.client.exception.OperationException)

Example 4 with HttpResponse

use of org.apache.servicecomb.http.client.common.HttpResponse in project java-chassis by ServiceComb.

the class ServiceCenterClient method deleteMicroserviceInstance.

@Override
public void deleteMicroserviceInstance(String serviceId, String instanceId) {
    try {
        HttpResponse response = httpClient.deleteHttpRequest("/registry/microservices/" + serviceId + "/instances/" + instanceId, null, null);
        if (response.getStatusCode() == HttpStatus.SC_OK) {
            LOGGER.info("Delete service instance successfully.");
            return;
        }
        sendUnAuthorizedEvent(response);
        throw new OperationException("delete service instance fails, statusCode = " + response.getStatusCode() + "; message = " + response.getMessage() + "; content = " + response.getContent());
    } catch (IOException e) {
        throw new OperationException("delete service instance 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 5 with HttpResponse

use of org.apache.servicecomb.http.client.common.HttpResponse in project java-chassis by ServiceComb.

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)

Aggregations

HttpResponse (org.apache.servicecomb.http.client.common.HttpResponse)37 IOException (java.io.IOException)21 OperationException (org.apache.servicecomb.service.center.client.exception.OperationException)19 Test (org.junit.Test)15 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 Microservice (org.apache.servicecomb.service.center.client.model.Microservice)4 HttpRequest (org.apache.servicecomb.http.client.common.HttpRequest)3 MicroserviceInstancesResponse (org.apache.servicecomb.service.center.client.model.MicroserviceInstancesResponse)3 RegisteredMicroserviceResponse (org.apache.servicecomb.service.center.client.model.RegisteredMicroserviceResponse)3 HashMap (java.util.HashMap)2 MicroserviceInstance (org.apache.servicecomb.service.center.client.model.MicroserviceInstance)2 RegisteredMicroserviceInstanceResponse (org.apache.servicecomb.service.center.client.model.RegisteredMicroserviceInstanceResponse)2 SchemaInfo (org.apache.servicecomb.service.center.client.model.SchemaInfo)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 EventBus (com.google.common.eventbus.EventBus)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 URIBuilder (org.apache.http.client.utils.URIBuilder)1 OperationException (org.apache.servicecomb.config.center.client.exception.OperationException)1