Search in sources :

Example 1 with AuthEnforce

use of io.cdap.cdap.common.security.AuthEnforce 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, permissions = StandardPermission.DELETE)
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 {
        // if needed, run master environment specific logic if it is a non-default namespace (see below for more info)
        MasterEnvironment masterEnv = MasterEnvironments.getMasterEnvironment();
        if (masterEnv != null && !NamespaceId.DEFAULT.equals(namespaceId)) {
            masterEnv.onNamespaceDeletion(namespaceId.getNamespace(), namespaceMeta.getConfig().getConfigs());
        }
        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);
    }
    emitNamespaceCountMetric();
}
Also used : MasterEnvironment(io.cdap.cdap.master.spi.environment.MasterEnvironment) NamespaceMeta(io.cdap.cdap.proto.NamespaceMeta) NamespaceCannotBeDeletedException(io.cdap.cdap.common.NamespaceCannotBeDeletedException) UnauthorizedException(io.cdap.cdap.security.spi.authorization.UnauthorizedException) NamespaceCannotBeDeletedException(io.cdap.cdap.common.NamespaceCannotBeDeletedException) NamespaceNotFoundException(io.cdap.cdap.common.NamespaceNotFoundException) NamespaceCannotBeCreatedException(io.cdap.cdap.common.NamespaceCannotBeCreatedException) NamespaceAlreadyExistsException(io.cdap.cdap.common.NamespaceAlreadyExistsException) DatasetManagementException(io.cdap.cdap.api.dataset.DatasetManagementException) IOException(java.io.IOException) BadRequestException(io.cdap.cdap.common.BadRequestException) AuthEnforce(io.cdap.cdap.common.security.AuthEnforce)

Aggregations

DatasetManagementException (io.cdap.cdap.api.dataset.DatasetManagementException)1 BadRequestException (io.cdap.cdap.common.BadRequestException)1 NamespaceAlreadyExistsException (io.cdap.cdap.common.NamespaceAlreadyExistsException)1 NamespaceCannotBeCreatedException (io.cdap.cdap.common.NamespaceCannotBeCreatedException)1 NamespaceCannotBeDeletedException (io.cdap.cdap.common.NamespaceCannotBeDeletedException)1 NamespaceNotFoundException (io.cdap.cdap.common.NamespaceNotFoundException)1 AuthEnforce (io.cdap.cdap.common.security.AuthEnforce)1 MasterEnvironment (io.cdap.cdap.master.spi.environment.MasterEnvironment)1 NamespaceMeta (io.cdap.cdap.proto.NamespaceMeta)1 UnauthorizedException (io.cdap.cdap.security.spi.authorization.UnauthorizedException)1 IOException (java.io.IOException)1