use of io.cdap.common.http.HttpRequest in project cdap by caskdata.
the class ProgramClient method setServiceInstances.
/**
* Sets the number of instances of a service.
*
* @param service the service
* @param instances number of instances for the service
* @throws IOException if a network error occurred
* @throws NotFoundException if the application or service could not be found
* @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
*/
public void setServiceInstances(ServiceId service, int instances) throws IOException, NotFoundException, UnauthenticatedException, UnauthorizedException {
URL url = config.resolveNamespacedURLV3(service.getNamespaceId(), String.format("apps/%s/services/%s/instances", service.getApplication(), service.getProgram()));
HttpRequest request = HttpRequest.put(url).withBody(GSON.toJson(new Instances(instances))).build();
HttpResponse response = restClient.execute(request, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND);
if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
throw new NotFoundException(service);
}
}
use of io.cdap.common.http.HttpRequest in project cdap by caskdata.
the class ProgramClient method setWorkerInstances.
/**
* Sets the number of instances that a worker will run on.
*
* @param instances number of instances for the worker to run on
* @throws IOException if a network error occurred
* @throws NotFoundException if the application or worker could not be found
* @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
*/
public void setWorkerInstances(ProgramId worker, int instances) throws IOException, NotFoundException, UnauthenticatedException, UnauthorizedException {
URL url = config.resolveNamespacedURLV3(worker.getNamespaceId(), String.format("apps/%s/workers/%s/instances", worker.getApplication(), worker.getProgram()));
HttpRequest request = HttpRequest.put(url).withBody(GSON.toJson(new Instances(instances))).build();
HttpResponse response = restClient.execute(request, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND);
if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
throw new NotFoundException(worker);
}
}
use of io.cdap.common.http.HttpRequest 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 io.cdap.common.http.HttpRequest in project cdap by caskdata.
the class ServiceClient method storeRouteConfig.
/**
* Stores RouteConfig of a service with different application versions.
*
* @param serviceId {@link ServiceId} of the service with the application version part ignored
* @param routeConfig a Map of {@link String} application version and {@link Integer} percentage of
* traffic routed to the version.
*/
public void storeRouteConfig(ServiceId serviceId, Map<String, Integer> routeConfig) throws IOException, UnauthorizedException, UnauthenticatedException {
URL url = buildRouteConfigUrl(serviceId);
HttpRequest request = HttpRequest.put(url).withBody(GSON.toJson(routeConfig, MAP_STRING_INTEGER_TYPE)).build();
restClient.upload(request, config.getAccessToken());
}
use of io.cdap.common.http.HttpRequest in project cdap by caskdata.
the class OAuthServiceTest method makeGetCall.
private HttpResponse makeGetCall(String endpoint) throws IOException {
URL url = serviceURI.resolve(String.format("v1/oauth/%s", endpoint)).toURL();
HttpRequest request = HttpRequest.builder(HttpMethod.GET, url).build();
return HttpRequests.execute(request, new DefaultHttpRequestConfig(false));
}
Aggregations