use of co.cask.cdap.common.NamespaceCannotBeDeletedException in project cdap by caskdata.
the class AbstractNamespaceClient method delete.
@Override
public void delete(NamespaceId namespaceId) throws Exception {
URL url = resolve(String.format("unrecoverable/namespaces/%s", namespaceId.getNamespace()));
HttpResponse response = execute(HttpRequest.delete(url).build());
if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
throw new NamespaceNotFoundException(namespaceId);
} else if (HttpURLConnection.HTTP_FORBIDDEN == response.getResponseCode()) {
throw new NamespaceCannotBeDeletedException(namespaceId, response.getResponseBodyAsString());
} else if (response.getResponseCode() == HttpURLConnection.HTTP_OK) {
return;
}
throw new IOException(String.format("Cannot delete namespace %s. Reason: %s", namespaceId, response.getResponseBodyAsString()));
}
use of co.cask.cdap.common.NamespaceCannotBeDeletedException in project cdap by caskdata.
the class AbstractNamespaceClient method deleteDatasets.
@Override
public void deleteDatasets(NamespaceId namespaceId) throws Exception {
URL url = resolve(String.format("unrecoverable/namespaces/%s/datasets", namespaceId.getNamespace()));
HttpResponse response = execute(HttpRequest.delete(url).build());
if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
throw new NamespaceNotFoundException(namespaceId);
} else if (HttpURLConnection.HTTP_FORBIDDEN == response.getResponseCode()) {
String msg = String.format("Datasets in the namespace '%s' cannot be deleted. Reason: '%s'.", namespaceId, response.getResponseBodyAsString());
throw new NamespaceCannotBeDeletedException(namespaceId, msg);
} else if (response.getResponseCode() == HttpURLConnection.HTTP_OK) {
return;
}
throw new IOException(String.format("Cannot delete datasets in namespace %s. Reason: %s", namespaceId, response.getResponseBodyAsString()));
}
use of co.cask.cdap.common.NamespaceCannotBeDeletedException in project cdap by caskdata.
the class DefaultNamespaceAdmin method delete.
/**
* Deletes the specified namespace
*
* @param namespaceId the {@link Id.Namespace} of the specified namespace
* @throws NamespaceCannotBeDeletedException if the specified namespace cannot be deleted
* @throws NamespaceNotFoundException if the specified namespace does not exist
*/
@Override
@AuthEnforce(entities = "namespaceId", enforceOn = NamespaceId.class, actions = Action.ADMIN)
public synchronized void delete(@Name("namespaceId") final NamespaceId namespaceId) throws Exception {
// TODO: CDAP-870, CDAP-1427: Delete should be in a single transaction.
NamespaceMeta namespaceMeta = get(namespaceId);
if (checkProgramsRunning(namespaceId)) {
throw new NamespaceCannotBeDeletedException(namespaceId, String.format("Some programs are currently running in namespace " + "'%s', please stop them before deleting namespace", namespaceId));
}
LOG.info("Deleting namespace '{}'.", namespaceId);
try {
resourceDeleter.get().deleteResources(namespaceMeta);
// namespace in the storage provider (Hive, HBase, etc), since we re-use their default namespace.
if (!NamespaceId.DEFAULT.equals(namespaceId)) {
// Finally delete namespace from MDS and remove from cache
deleteNamespaceMeta(namespaceId);
LOG.info("Namespace '{}' deleted", namespaceId);
} else {
LOG.info("Keeping the '{}' namespace after removing all data.", NamespaceId.DEFAULT);
}
} catch (Exception e) {
LOG.warn("Error while deleting namespace {}", namespaceId, e);
throw new NamespaceCannotBeDeletedException(namespaceId, e);
}
}
Aggregations