use of co.cask.common.http.HttpResponse 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 co.cask.common.http.HttpResponse 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 co.cask.common.http.HttpResponse in project cdap by caskdata.
the class DatasetClient method delete.
/**
* Deletes a dataset.
*
* @param instance the dataset to delete
* @throws DatasetNotFoundException if the dataset with the specified name could not be found
* @throws IOException if a network error occurred
* @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
*/
public void delete(DatasetId instance) throws DatasetNotFoundException, IOException, UnauthenticatedException, UnauthorizedException {
URL url = config.resolveNamespacedURLV3(instance.getParent(), String.format("data/datasets/%s", instance.getDataset()));
HttpResponse response = restClient.execute(HttpMethod.DELETE, url, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND);
if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
throw new DatasetNotFoundException(instance);
}
}
use of co.cask.common.http.HttpResponse in project cdap by caskdata.
the class ProgramClient method stop.
/**
* Stops a program.
*
* @param programId the program to stop
* @throws IOException if a network error occurred
* @throws ProgramNotFoundException if the program with specified name could not be found
* @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
*/
public void stop(ProgramId programId) throws IOException, ProgramNotFoundException, UnauthenticatedException, UnauthorizedException {
String path = String.format("apps/%s/versions/%s/%s/%s/stop", programId.getApplication(), programId.getVersion(), programId.getType().getCategoryName(), programId.getProgram());
URL url = config.resolveNamespacedURLV3(programId.getNamespaceId(), path);
HttpResponse response = restClient.execute(HttpMethod.POST, url, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND);
if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
throw new ProgramNotFoundException(programId);
}
}
use of co.cask.common.http.HttpResponse 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();
}
Aggregations