Search in sources :

Example 1 with ServiceNotEnabledException

use of io.cdap.cdap.common.ServiceNotEnabledException in project cdap by cdapio.

the class MonitorClient method getSystemServiceInstances.

/**
 * Gets the number of instances the system service is running on.
 *
 * @param serviceName name of the system service
 * @return number of instances the system service is running on
 * @throws IOException if a network error occurred
 * @throws NotFoundException if the system service with the specified name was not found
 * @throws ServiceNotEnabledException if the system service is not currently enabled
 * @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
 */
public int getSystemServiceInstances(String serviceName) throws IOException, NotFoundException, ServiceNotEnabledException, UnauthenticatedException, UnauthorizedException {
    URL url = config.resolveURL(String.format("system/services/%s/instances", serviceName));
    HttpResponse response = restClient.execute(HttpMethod.GET, url, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND, HttpURLConnection.HTTP_FORBIDDEN);
    if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
        throw new NotFoundException(new SystemServiceId(serviceName));
    } else if (response.getResponseCode() == HttpURLConnection.HTTP_FORBIDDEN) {
        throw new ServiceNotEnabledException(serviceName);
    }
    return ObjectResponse.fromJsonBody(response, Instances.class).getResponseObject().getInstances();
}
Also used : SystemServiceId(io.cdap.cdap.proto.id.SystemServiceId) ServiceNotEnabledException(io.cdap.cdap.common.ServiceNotEnabledException) HttpResponse(io.cdap.common.http.HttpResponse) NotFoundException(io.cdap.cdap.common.NotFoundException) URL(java.net.URL)

Example 2 with ServiceNotEnabledException

use of io.cdap.cdap.common.ServiceNotEnabledException in project cdap by caskdata.

the class MonitorClient method getSystemServiceInstances.

/**
 * Gets the number of instances the system service is running on.
 *
 * @param serviceName name of the system service
 * @return number of instances the system service is running on
 * @throws IOException if a network error occurred
 * @throws NotFoundException if the system service with the specified name was not found
 * @throws ServiceNotEnabledException if the system service is not currently enabled
 * @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
 */
public int getSystemServiceInstances(String serviceName) throws IOException, NotFoundException, ServiceNotEnabledException, UnauthenticatedException, UnauthorizedException {
    URL url = config.resolveURL(String.format("system/services/%s/instances", serviceName));
    HttpResponse response = restClient.execute(HttpMethod.GET, url, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND, HttpURLConnection.HTTP_FORBIDDEN);
    if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
        throw new NotFoundException(new SystemServiceId(serviceName));
    } else if (response.getResponseCode() == HttpURLConnection.HTTP_FORBIDDEN) {
        throw new ServiceNotEnabledException(serviceName);
    }
    return ObjectResponse.fromJsonBody(response, Instances.class).getResponseObject().getInstances();
}
Also used : SystemServiceId(io.cdap.cdap.proto.id.SystemServiceId) ServiceNotEnabledException(io.cdap.cdap.common.ServiceNotEnabledException) HttpResponse(io.cdap.common.http.HttpResponse) NotFoundException(io.cdap.cdap.common.NotFoundException) URL(java.net.URL)

Aggregations

NotFoundException (io.cdap.cdap.common.NotFoundException)2 ServiceNotEnabledException (io.cdap.cdap.common.ServiceNotEnabledException)2 SystemServiceId (io.cdap.cdap.proto.id.SystemServiceId)2 HttpResponse (io.cdap.common.http.HttpResponse)2 URL (java.net.URL)2