use of com.google.common.reflect.TypeToken in project cdap by caskdata.
the class ProgramClient method getRuntimeArgs.
/**
* Gets the runtime args of a program.
*
* @param program the program
* @return runtime args of the program
* @throws IOException if a network error occurred
* @throws ProgramNotFoundException if the application or program could not be found
* @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
*/
public Map<String, String> getRuntimeArgs(ProgramId program) throws IOException, UnauthenticatedException, ProgramNotFoundException, UnauthorizedException {
String path = String.format("apps/%s/versions/%s/%s/%s/runtimeargs", program.getApplication(), program.getVersion(), 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, new TypeToken<Map<String, String>>() {
}).getResponseObject();
}
use of com.google.common.reflect.TypeToken in project cdap by caskdata.
the class DatasetClient method getProperties.
/**
* Retrieve the properties with which a dataset was created or updated.
* @param instance the dataset instance
* @return the properties as a map
*/
public Map<String, String> getProperties(DatasetId instance) throws IOException, UnauthenticatedException, NotFoundException, UnauthorizedException {
URL url = config.resolveNamespacedURLV3(instance.getParent(), String.format("data/datasets/%s/properties", instance.getDataset()));
HttpRequest request = HttpRequest.get(url).build();
HttpResponse response = restClient.execute(request, config.getAccessToken());
if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
throw new NotFoundException(instance);
}
return ObjectResponse.fromJsonBody(response, new TypeToken<Map<String, String>>() {
}).getResponseObject();
}
use of com.google.common.reflect.TypeToken in project cdap by caskdata.
the class DatasetClient method list.
/**
* Lists all datasets.
*
* @return list of {@link DatasetSpecificationSummary}.
* @throws IOException if a network error occurred
* @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
*/
public List<DatasetSpecificationSummary> list(NamespaceId namespace) throws IOException, UnauthenticatedException, UnauthorizedException {
URL url = config.resolveNamespacedURLV3(namespace, "data/datasets");
HttpResponse response = restClient.execute(HttpMethod.GET, url, config.getAccessToken());
return ObjectResponse.fromJsonBody(response, new TypeToken<List<DatasetSpecificationSummary>>() {
}).getResponseObject();
}
use of com.google.common.reflect.TypeToken in project cdap by caskdata.
the class ProgramClient method getWorkflowCurrent.
/**
* Get the current run information for the Workflow based on the runid
*
* @param workflowId ID of the workflow
* @param runId ID of the run for which the details are to be returned
* @return list of {@link WorkflowActionNode} currently running for the given runid
* @throws IOException if a network error occurred
* @throws NotFoundException if the application, workflow, or runid could not be found
* @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
*/
public List<WorkflowActionNode> getWorkflowCurrent(WorkflowId workflowId, String runId) throws IOException, NotFoundException, UnauthenticatedException, UnauthorizedException {
String path = String.format("/apps/%s/workflows/%s/runs/%s/current", workflowId.getApplication(), workflowId.getProgram(), runId);
URL url = config.resolveNamespacedURLV3(workflowId.getNamespaceId(), path);
HttpResponse response = restClient.execute(HttpMethod.GET, url, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND);
if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
throw new NotFoundException(workflowId.run(runId));
}
ObjectResponse<List<WorkflowActionNode>> objectResponse = ObjectResponse.fromJsonBody(response, new TypeToken<List<WorkflowActionNode>>() {
}.getType(), GSON);
return objectResponse.getResponseObject();
}
use of com.google.common.reflect.TypeToken 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();
}
Aggregations