use of co.cask.common.http.HttpResponse in project cdap by caskdata.
the class ProgramClient method getLiveInfo.
/**
* Gets the live information of a program. In distributed CDAP,
* this will contain IDs of the YARN applications that are running the program.
*
* @param program the program
* @return {@link ProgramLiveInfo} of the program
* @throws IOException if a network error occurred
* @throws ProgramNotFoundException if the program with the specified name could not be found
* @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
*/
public DistributedProgramLiveInfo getLiveInfo(ProgramId program) throws IOException, ProgramNotFoundException, UnauthenticatedException, UnauthorizedException {
String path = String.format("apps/%s/%s/%s/live-info", program.getApplication(), program.getType().getCategoryName(), program.getProgram());
URL url = config.resolveNamespacedURLV3(program.getNamespaceId(), path);
HttpResponse response = restClient.execute(HttpMethod.GET, url, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND);
if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
throw new ProgramNotFoundException(program);
}
return ObjectResponse.fromJsonBody(response, DistributedProgramLiveInfo.class).getResponseObject();
}
use of co.cask.common.http.HttpResponse in project cdap by caskdata.
the class MetricsClient method searchMetrics.
/**
* Searches for metrics matching the given tags.
*
* @param tags the tags to match
* @return the metrics matching the given tags
* @throws IOException if a network error occurred
* @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
*/
public List<String> searchMetrics(Map<String, String> tags) throws IOException, UnauthenticatedException, UnauthorizedException {
List<String> queryParts = Lists.newArrayList();
queryParts.add("target=metric");
addTags(tags, queryParts);
URL url = config.resolveURLV3(String.format("metrics/search?%s", Joiner.on("&").join(queryParts)));
HttpResponse response = restClient.execute(HttpMethod.POST, url, config.getAccessToken());
ObjectResponse<List<String>> result = ObjectResponse.fromJsonBody(response, new TypeToken<List<String>>() {
}.getType());
return result.getResponseObject();
}
use of co.cask.common.http.HttpResponse in project cdap by caskdata.
the class MonitorClient method listSystemServices.
/**
* Lists all system services.
*
* @return list of {@link SystemServiceMeta}s.
* @throws IOException if a network error occurred
* @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
*/
public List<SystemServiceMeta> listSystemServices() throws IOException, UnauthenticatedException, UnauthorizedException {
URL url = config.resolveURL("system/services");
HttpResponse response = restClient.execute(HttpMethod.GET, url, config.getAccessToken());
return ObjectResponse.fromJsonBody(response, new TypeToken<List<SystemServiceMeta>>() {
}).getResponseObject();
}
use of co.cask.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();
}
use of co.cask.common.http.HttpResponse 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();
}
Aggregations