use of co.cask.cdap.common.DatasetModuleAlreadyExistsException 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);
}
}
Aggregations