use of co.cask.common.http.HttpResponse in project cdap by caskdata.
the class DatasetClient method create.
/**
* Creates a dataset.
*
* @param instance ID of the dataset instance
* @param properties properties of the dataset to create
* @throws DatasetTypeNotFoundException if the desired dataset type was not found
* @throws DatasetAlreadyExistsException if a dataset by the same name already exists
* @throws IOException if a network error occurred
* @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
*/
public void create(DatasetId instance, DatasetInstanceConfiguration properties) throws DatasetTypeNotFoundException, DatasetAlreadyExistsException, IOException, UnauthenticatedException, UnauthorizedException {
URL url = config.resolveNamespacedURLV3(instance.getParent(), String.format("data/datasets/%s", instance.getDataset()));
HttpRequest request = HttpRequest.put(url).withBody(GSON.toJson(properties)).build();
HttpResponse response = restClient.execute(request, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND, HttpURLConnection.HTTP_CONFLICT);
if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
throw new DatasetTypeNotFoundException(instance.getParent().datasetType(properties.getTypeName()));
} else if (response.getResponseCode() == HttpURLConnection.HTTP_CONFLICT) {
throw new DatasetAlreadyExistsException(instance);
}
}
use of co.cask.common.http.HttpResponse in project cdap by caskdata.
the class DatasetModuleClient method delete.
/**
* Deletes a dataset module.
*
* @param module the dataset module to delete
* @throws DatasetModuleCannotBeDeletedException if the dataset module cannot be deleted,
* usually due to other dataset modules or dataset instances using the dataset module
* @throws DatasetModuleNotFoundException if the dataset module with the specified name was not found
* @throws IOException if a network error occurred
* @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
*/
public void delete(DatasetModuleId module) throws DatasetModuleCannotBeDeletedException, DatasetModuleNotFoundException, IOException, UnauthenticatedException, UnauthorizedException {
URL url = config.resolveNamespacedURLV3(module.getParent(), String.format("data/modules/%s", module.getModule()));
HttpResponse response = restClient.execute(HttpMethod.DELETE, url, config.getAccessToken(), HttpURLConnection.HTTP_CONFLICT, HttpURLConnection.HTTP_NOT_FOUND);
if (response.getResponseCode() == HttpURLConnection.HTTP_CONFLICT) {
throw new DatasetModuleCannotBeDeletedException(module);
} else if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
throw new DatasetModuleNotFoundException(module);
}
}
use of co.cask.common.http.HttpResponse in project cdap by caskdata.
the class DatasetModuleClient method exists.
/**
* Checks if a dataset module exists.
*
* @param module the dataset module to check
* @throws IOException if a network error occurred
* @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
*/
public boolean exists(DatasetModuleId module) throws IOException, UnauthenticatedException, UnauthorizedException {
URL url = config.resolveNamespacedURLV3(module.getParent(), String.format("data/modules/%s", module.getModule()));
HttpResponse response = restClient.execute(HttpMethod.GET, url, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND);
return response.getResponseCode() != HttpURLConnection.HTTP_NOT_FOUND;
}
use of co.cask.common.http.HttpResponse in project cdap by caskdata.
the class DatasetModuleClient method add.
/**
* Adds a new dataset module.
*
* @param module the new dataset module
* @param className name of the dataset module class within the moduleJarFile
* @param moduleJarFile Jar file containing the dataset module class and dependencies
* @throws BadRequestException if the moduleJarFile does not exist
* @throws AlreadyExistsException if a dataset module with the same name already exists
* @throws IOException if a network error occurred
*/
public void add(DatasetModuleId module, String className, File moduleJarFile) throws BadRequestException, AlreadyExistsException, IOException, UnauthenticatedException {
URL url = config.resolveNamespacedURLV3(module.getParent(), String.format("data/modules/%s", module.getModule()));
Map<String, String> headers = ImmutableMap.of("X-Class-Name", className);
HttpRequest request = HttpRequest.put(url).addHeaders(headers).withBody(moduleJarFile).build();
HttpResponse response = restClient.upload(request, config.getAccessToken(), HttpURLConnection.HTTP_BAD_REQUEST, HttpURLConnection.HTTP_CONFLICT);
if (response.getResponseCode() == HttpURLConnection.HTTP_BAD_REQUEST) {
throw new BadRequestException(String.format("Module jar file does not exist: %s", moduleJarFile));
} else if (response.getResponseCode() == HttpURLConnection.HTTP_CONFLICT) {
throw new DatasetModuleAlreadyExistsException(module);
}
}
use of co.cask.common.http.HttpResponse 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();
}
Aggregations