use of io.cdap.common.http.HttpResponse in project cdap by caskdata.
the class DatasetTypeClient method exists.
/**
* Checks if a dataset type exists.
*
* @param type the dataset type to check
* @return true if the dataset type exists
* @throws IOException if a network error occurred
* @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
*/
public boolean exists(DatasetTypeId type) throws DatasetTypeNotFoundException, IOException, UnauthenticatedException, UnauthorizedException {
URL url = config.resolveNamespacedURLV3(type.getParent(), String.format("data/types/%s", type.getType()));
HttpResponse response = restClient.execute(HttpMethod.GET, url, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND);
return response.getResponseCode() != HttpURLConnection.HTTP_NOT_FOUND;
}
use of io.cdap.common.http.HttpResponse in project cdap by caskdata.
the class LineageClient method getLineage.
private <T> T getLineage(NamespacedEntityId namespacedId, String path, Class<T> type) throws IOException, UnauthenticatedException, NotFoundException, BadRequestException, UnauthorizedException {
URL lineageURL = config.resolveNamespacedURLV3(new NamespaceId(namespacedId.getNamespace()), path);
HttpResponse response = restClient.execute(HttpRequest.get(lineageURL).build(), config.getAccessToken(), HttpURLConnection.HTTP_BAD_REQUEST, HttpURLConnection.HTTP_NOT_FOUND);
if (response.getResponseCode() == HttpURLConnection.HTTP_BAD_REQUEST) {
throw new BadRequestException(response.getResponseBodyAsString());
}
if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
throw new NotFoundException(response.getResponseBodyAsString());
}
return GSON.fromJson(response.getResponseBodyAsString(), type);
}
use of io.cdap.common.http.HttpResponse in project cdap by caskdata.
the class MetricsClient method query.
/**
* Gets the value of the given metrics.
*
* @param tags tags for the request
* @param metrics names of the metrics
* @param groupBys groupBys for the request
* @param timeRangeParams parameters specifying the time range
* @return values of the metrics
* @throws IOException if a network error occurred
* @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
*/
// TODO: take in query object shared by MetricsHandler
public MetricQueryResult query(Map<String, String> tags, List<String> metrics, List<String> groupBys, Map<String, String> timeRangeParams) throws IOException, UnauthenticatedException, UnauthorizedException {
List<String> queryParts = Lists.newArrayList();
queryParts.add("target=tag");
add("metric", metrics, queryParts);
add("groupBy", groupBys, queryParts);
addTags(tags, queryParts);
addTimeRangeParametersToQuery(timeRangeParams, queryParts);
URL url = config.resolveURLV3(String.format("metrics/query?%s", Joiner.on("&").join(queryParts)));
// Required to add body even if runtimeArgs is null to avoid 411 error for Http POST
HttpRequest.Builder request = HttpRequest.post(url).withBody("");
HttpResponse response = restClient.execute(request.build(), config.getAccessToken());
return ObjectResponse.fromJsonBody(response, MetricQueryResult.class).getResponseObject();
}
use of io.cdap.common.http.HttpResponse 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 io.cdap.common.http.HttpResponse in project cdap by caskdata.
the class MonitorClient method getAllSystemServiceStatus.
/**
* Gets the status of all system services.
*
* @return map from service name to service status
* @throws IOException if a network error occurred
* @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
*/
public Map<String, String> getAllSystemServiceStatus() throws IOException, UnauthenticatedException, UnauthorizedException {
URL url = config.resolveURL("system/services/status");
HttpResponse response = restClient.execute(HttpMethod.GET, url, config.getAccessToken());
return ObjectResponse.fromJsonBody(response, new TypeToken<Map<String, String>>() {
}).getResponseObject();
}
Aggregations