Search in sources :

Example 1 with DatasetModuleCannotBeDeletedException

use of io.cdap.cdap.common.DatasetModuleCannotBeDeletedException in project cdap by caskdata.

the class DefaultDatasetTypeService method delete.

/**
 * Deletes the specified {@link DatasetModuleId}
 */
@Override
public void delete(DatasetModuleId datasetModuleId) throws Exception {
    NamespaceId namespaceId = datasetModuleId.getParent();
    if (NamespaceId.SYSTEM.equals(namespaceId)) {
        throw new UnsupportedOperationException(String.format("Cannot delete module '%s' from '%s' namespace.", datasetModuleId.getModule(), datasetModuleId.getNamespace()));
    }
    ensureNamespaceExists(namespaceId);
    DatasetModuleMeta moduleMeta = typeManager.getModule(datasetModuleId);
    if (moduleMeta == null) {
        throw new DatasetModuleNotFoundException(datasetModuleId);
    }
    try {
        typeManager.deleteModule(datasetModuleId);
    } catch (DatasetModuleConflictException e) {
        throw new DatasetModuleCannotBeDeletedException(datasetModuleId, e.getMessage());
    }
}
Also used : DatasetModuleNotFoundException(io.cdap.cdap.common.DatasetModuleNotFoundException) DatasetModuleConflictException(io.cdap.cdap.data2.datafabric.dataset.type.DatasetModuleConflictException) DatasetModuleMeta(io.cdap.cdap.proto.DatasetModuleMeta) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) DatasetModuleCannotBeDeletedException(io.cdap.cdap.common.DatasetModuleCannotBeDeletedException)

Example 2 with DatasetModuleCannotBeDeletedException

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

Example 3 with DatasetModuleCannotBeDeletedException

use of io.cdap.cdap.common.DatasetModuleCannotBeDeletedException in project cdap by caskdata.

the class DatasetModuleClient method deleteAll.

/**
 * Deletes all dataset modules in a namespace.
 *
 * @throws DatasetModuleCannotBeDeletedException if one of the dataset modules cannot be deleted,
 * usually due to existing dataset instances using the dataset module
 * @throws IOException if a network error occurred
 * @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
 */
public void deleteAll(NamespaceId namespace) throws DatasetModuleCannotBeDeletedException, IOException, UnauthenticatedException, UnauthorizedException {
    URL url = config.resolveNamespacedURLV3(namespace, "data/modules");
    HttpResponse response = restClient.execute(HttpMethod.DELETE, url, config.getAccessToken(), HttpURLConnection.HTTP_CONFLICT);
    if (response.getResponseCode() == HttpURLConnection.HTTP_CONFLICT) {
        // TODO: exception for all modules
        throw new DatasetModuleCannotBeDeletedException(null);
    }
}
Also used : HttpResponse(io.cdap.common.http.HttpResponse) DatasetModuleCannotBeDeletedException(io.cdap.cdap.common.DatasetModuleCannotBeDeletedException) URL(java.net.URL)

Aggregations

DatasetModuleCannotBeDeletedException (io.cdap.cdap.common.DatasetModuleCannotBeDeletedException)3 DatasetModuleNotFoundException (io.cdap.cdap.common.DatasetModuleNotFoundException)2 HttpResponse (io.cdap.common.http.HttpResponse)2 URL (java.net.URL)2 DatasetModuleConflictException (io.cdap.cdap.data2.datafabric.dataset.type.DatasetModuleConflictException)1 DatasetModuleMeta (io.cdap.cdap.proto.DatasetModuleMeta)1 NamespaceId (io.cdap.cdap.proto.id.NamespaceId)1