Search in sources :

Example 1 with DatasetModuleAlreadyExistsException

use of io.cdap.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);
    }
}
Also used : HttpRequest(io.cdap.common.http.HttpRequest) HttpResponse(io.cdap.common.http.HttpResponse) BadRequestException(io.cdap.cdap.common.BadRequestException) URL(java.net.URL) DatasetModuleAlreadyExistsException(io.cdap.cdap.common.DatasetModuleAlreadyExistsException)

Example 2 with DatasetModuleAlreadyExistsException

use of io.cdap.cdap.common.DatasetModuleAlreadyExistsException in project cdap by cdapio.

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);
    }
}
Also used : HttpRequest(io.cdap.common.http.HttpRequest) HttpResponse(io.cdap.common.http.HttpResponse) BadRequestException(io.cdap.cdap.common.BadRequestException) URL(java.net.URL) DatasetModuleAlreadyExistsException(io.cdap.cdap.common.DatasetModuleAlreadyExistsException)

Aggregations

BadRequestException (io.cdap.cdap.common.BadRequestException)2 DatasetModuleAlreadyExistsException (io.cdap.cdap.common.DatasetModuleAlreadyExistsException)2 HttpRequest (io.cdap.common.http.HttpRequest)2 HttpResponse (io.cdap.common.http.HttpResponse)2 URL (java.net.URL)2