use of co.cask.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);
}
}
use of co.cask.cdap.common.DatasetModuleCannotBeDeletedException in project cdap by caskdata.
the class DatasetTypeService method delete.
/**
* Deletes the specified {@link DatasetModuleId}
*/
void delete(DatasetModuleId datasetModuleId) throws Exception {
NamespaceId namespaceId = datasetModuleId.getParent();
if (NamespaceId.SYSTEM.equals(namespaceId)) {
throw new UnauthorizedException(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);
}
Principal principal = authenticationContext.getPrincipal();
authorizationEnforcer.enforce(datasetModuleId, principal, Action.ADMIN);
try {
typeManager.deleteModule(datasetModuleId);
} catch (DatasetModuleConflictException e) {
throw new DatasetModuleCannotBeDeletedException(datasetModuleId, e.getMessage());
}
// revoke all privileges on the module to be deleted
revokeAllPrivilegesOnModule(datasetModuleId, moduleMeta);
}
use of co.cask.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);
}
}
Aggregations