use of co.cask.cdap.common.NotFoundException in project cdap by caskdata.
the class MonitorClient method setSystemServiceInstances.
/**
* Sets the number of instances the system service is running on.
*
* @param serviceName name of the system service
* @param instances 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 UnauthenticatedException if the request is not authorized successfully in the gateway server
*/
public void setSystemServiceInstances(String serviceName, int instances) throws IOException, NotFoundException, BadRequestException, UnauthenticatedException, UnauthorizedException {
URL url = config.resolveURL(String.format("system/services/%s/instances", serviceName));
HttpRequest request = HttpRequest.put(url).withBody(GSON.toJson(new Instances(instances))).build();
HttpResponse response = restClient.execute(request, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND, HttpURLConnection.HTTP_BAD_REQUEST);
if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
throw new NotFoundException(new SystemServiceId(serviceName));
} else if (response.getResponseCode() == HttpURLConnection.HTTP_BAD_REQUEST) {
throw new BadRequestException(new String(response.getResponseBody()));
}
}
use of co.cask.cdap.common.NotFoundException in project cdap by caskdata.
the class MonitorClient method getSystemServiceLiveInfo.
/**
* Gets the live info of a system service.
*
* @param serviceName Name of the system service
* @return live info of the system service
* @throws IOException if a network error occurred
* @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
*/
public SystemServiceLiveInfo getSystemServiceLiveInfo(String serviceName) throws IOException, UnauthenticatedException, NotFoundException, UnauthorizedException {
URL url = config.resolveURLV3(String.format("system/services/%s/live-info", serviceName));
HttpResponse response = restClient.execute(HttpMethod.GET, url, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND);
String responseBody = new String(response.getResponseBody());
if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
throw new NotFoundException(new SystemServiceId(serviceName));
}
return GSON.fromJson(responseBody, SystemServiceLiveInfo.class);
}
use of co.cask.cdap.common.NotFoundException in project cdap by caskdata.
the class MonitorClient method getSystemServiceStatus.
/**
* Gets the status of a system service.
*
* @param serviceName Name of the system service
* @return status of the system service
* @throws IOException if a network error occurred
* @throws NotFoundException if the system service with the specified name could not be found
* @throws BadRequestException if the operation was not valid for the system service
* @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
*/
public String getSystemServiceStatus(String serviceName) throws IOException, NotFoundException, BadRequestException, UnauthenticatedException, UnauthorizedException {
URL url = config.resolveURL(String.format("system/services/%s/status", serviceName));
HttpResponse response = restClient.execute(HttpMethod.GET, url, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND, HttpURLConnection.HTTP_BAD_REQUEST);
String responseBody = new String(response.getResponseBody());
if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
throw new NotFoundException(new SystemServiceId(serviceName));
} else if (response.getResponseCode() == HttpURLConnection.HTTP_BAD_REQUEST) {
throw new BadRequestException(responseBody);
}
Map<String, String> status = GSON.fromJson(responseBody, new TypeToken<Map<String, String>>() {
}.getType());
return status.get("status");
}
use of co.cask.cdap.common.NotFoundException in project cdap by caskdata.
the class ServiceClient method checkAvailability.
/**
* Checks whether the {@link Service} is active.
*
* @param service ID of the service
* @throws IOException if a network error occurred
* @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
* @throws NotFoundException if the app or service could not be found
* @throws ServiceUnavailableException if the service is not available
*/
public void checkAvailability(ServiceId service) throws IOException, UnauthenticatedException, NotFoundException, ServiceUnavailableException, UnauthorizedException {
URL url = config.resolveNamespacedURLV3(service.getNamespaceId(), String.format("apps/%s/versions/%s/services/%s/available", service.getApplication(), service.getVersion(), service.getProgram()));
HttpResponse response = restClient.execute(HttpMethod.GET, url, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND, HttpURLConnection.HTTP_BAD_REQUEST, HttpURLConnection.HTTP_UNAVAILABLE);
if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
throw new NotFoundException(service);
}
if (response.getResponseCode() == HttpURLConnection.HTTP_UNAVAILABLE) {
throw new ServiceUnavailableException(service.getProgram());
}
}
use of co.cask.cdap.common.NotFoundException in project cdap by caskdata.
the class ScheduleClient method suspend.
public void suspend(ScheduleId scheduleId) throws IOException, UnauthenticatedException, NotFoundException, UnauthorizedException {
String path = String.format("apps/%s/versions/%s/schedules/%s/suspend", scheduleId.getApplication(), scheduleId.getVersion(), scheduleId.getSchedule());
URL url = config.resolveNamespacedURLV3(scheduleId.toId().getNamespace(), path);
HttpResponse response = restClient.execute(HttpMethod.POST, url, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND);
if (HttpURLConnection.HTTP_NOT_FOUND == response.getResponseCode()) {
throw new NotFoundException(scheduleId);
}
}
Aggregations