Search in sources :

Example 1 with NamespaceCannotBeDeletedException

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()));
}
Also used : HttpResponse(co.cask.common.http.HttpResponse) IOException(java.io.IOException) NamespaceCannotBeDeletedException(co.cask.cdap.common.NamespaceCannotBeDeletedException) URL(java.net.URL) NamespaceNotFoundException(co.cask.cdap.common.NamespaceNotFoundException)

Example 2 with NamespaceCannotBeDeletedException

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()));
}
Also used : HttpResponse(co.cask.common.http.HttpResponse) IOException(java.io.IOException) NamespaceCannotBeDeletedException(co.cask.cdap.common.NamespaceCannotBeDeletedException) URL(java.net.URL) NamespaceNotFoundException(co.cask.cdap.common.NamespaceNotFoundException)

Example 3 with NamespaceCannotBeDeletedException

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);
    }
}
Also used : NamespaceMeta(co.cask.cdap.proto.NamespaceMeta) NamespaceCannotBeDeletedException(co.cask.cdap.common.NamespaceCannotBeDeletedException) NamespaceCannotBeCreatedException(co.cask.cdap.common.NamespaceCannotBeCreatedException) NamespaceNotFoundException(co.cask.cdap.common.NamespaceNotFoundException) BadRequestException(co.cask.cdap.common.BadRequestException) UnauthorizedException(co.cask.cdap.security.spi.authorization.UnauthorizedException) NamespaceCannotBeDeletedException(co.cask.cdap.common.NamespaceCannotBeDeletedException) DatasetManagementException(co.cask.cdap.api.dataset.DatasetManagementException) IOException(java.io.IOException) NamespaceAlreadyExistsException(co.cask.cdap.common.NamespaceAlreadyExistsException) AuthEnforce(co.cask.cdap.common.security.AuthEnforce)

Aggregations

NamespaceCannotBeDeletedException (co.cask.cdap.common.NamespaceCannotBeDeletedException)3 NamespaceNotFoundException (co.cask.cdap.common.NamespaceNotFoundException)3 IOException (java.io.IOException)3 HttpResponse (co.cask.common.http.HttpResponse)2 URL (java.net.URL)2 DatasetManagementException (co.cask.cdap.api.dataset.DatasetManagementException)1 BadRequestException (co.cask.cdap.common.BadRequestException)1 NamespaceAlreadyExistsException (co.cask.cdap.common.NamespaceAlreadyExistsException)1 NamespaceCannotBeCreatedException (co.cask.cdap.common.NamespaceCannotBeCreatedException)1 AuthEnforce (co.cask.cdap.common.security.AuthEnforce)1 NamespaceMeta (co.cask.cdap.proto.NamespaceMeta)1 UnauthorizedException (co.cask.cdap.security.spi.authorization.UnauthorizedException)1