Search in sources :

Example 31 with OperationException

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

the class ServiceCenterClient method getMicroserviceInstanceList.

@Override
public MicroserviceInstancesResponse getMicroserviceInstanceList(String serviceId) {
    try {
        HttpResponse response = httpClient.getHttpRequest("/registry/microservices/" + serviceId + "/instances", null, null);
        if (response.getStatusCode() == HttpStatus.SC_OK) {
            return HttpUtils.deserialize(response.getContent(), MicroserviceInstancesResponse.class);
        }
        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 : HttpResponse(org.apache.servicecomb.http.client.common.HttpResponse) IOException(java.io.IOException) OperationException(org.apache.servicecomb.service.center.client.exception.OperationException)

Example 32 with OperationException

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

the class ServiceCenterClient method registerSchema.

@Override
public boolean registerSchema(String serviceId, String schemaId, CreateSchemaRequest schema) {
    try {
        HttpResponse response = httpClient.putHttpRequest("/registry/microservices/" + serviceId + "/schemas/" + schemaId, null, HttpUtils.serialize(schema));
        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 33 with OperationException

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

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 34 with OperationException

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

the class ServiceCenterClient method queryServiceId.

@Override
public RegisteredMicroserviceResponse queryServiceId(Microservice microservice) {
    try {
        URIBuilder uriBuilder = new URIBuilder("/registry/existence");
        uriBuilder.setParameter("type", "microservice");
        uriBuilder.setParameter("appId", microservice.getAppId());
        uriBuilder.setParameter("serviceName", microservice.getServiceName());
        uriBuilder.setParameter("version", microservice.getVersion());
        uriBuilder.setParameter("env", microservice.getEnvironment());
        HttpResponse response = httpClient.getHttpRequest(uriBuilder.build().toString(), null, null);
        if (response.getStatusCode() == HttpStatus.SC_OK) {
            return HttpUtils.deserialize(response.getContent(), RegisteredMicroserviceResponse.class);
        }
        sendUnAuthorizedEvent(response);
        LOGGER.info("Query serviceId fails, statusCode = " + response.getStatusCode() + "; message = " + response.getMessage() + "; content = " + response.getContent());
        return null;
    } catch (IOException e) {
        throw new OperationException("query serviceId fails", e);
    } catch (URISyntaxException e) {
        throw new OperationException("build url failed.", e);
    }
}
Also used : HttpResponse(org.apache.servicecomb.http.client.common.HttpResponse) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) OperationException(org.apache.servicecomb.service.center.client.exception.OperationException) URIBuilder(org.apache.http.client.utils.URIBuilder)

Example 35 with OperationException

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

the class ServiceCenterClient method registerMicroservice.

@Override
public RegisteredMicroserviceResponse registerMicroservice(Microservice microservice) {
    try {
        CreateMicroserviceRequest request = new CreateMicroserviceRequest();
        request.setService(microservice);
        HttpResponse response = httpClient.postHttpRequest("/registry/microservices", null, HttpUtils.serialize(request));
        if (response.getStatusCode() == HttpStatus.SC_OK) {
            return HttpUtils.deserialize(response.getContent(), RegisteredMicroserviceResponse.class);
        }
        sendUnAuthorizedEvent(response);
        throw new OperationException("register service fails, statusCode = " + response.getStatusCode() + "; message = " + response.getMessage() + "; content = " + response.getContent());
    } catch (IOException e) {
        throw new OperationException("register service fails", e);
    }
}
Also used : CreateMicroserviceRequest(org.apache.servicecomb.service.center.client.model.CreateMicroserviceRequest) 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)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