Search in sources :

Example 21 with DatabaseNotFoundException

use of com.netflix.metacat.common.server.connectors.exception.DatabaseNotFoundException in project metacat by Netflix.

the class CassandraConnectorDatabaseService method listViewNames.

/**
     * {@inheritDoc}
     */
@Override
public List<QualifiedName> listViewNames(@Nonnull @NonNull final ConnectorContext context, @Nonnull @NonNull final QualifiedName databaseName) {
    final String catalogName = databaseName.getCatalogName();
    final String keyspace = databaseName.getDatabaseName();
    log.debug("Attempting to get materialized view names for keyspace {} due to request {}", keyspace, context);
    try {
        final KeyspaceMetadata keyspaceMetadata = this.getCluster().getMetadata().getKeyspace(keyspace);
        if (keyspaceMetadata == null) {
            throw new DatabaseNotFoundException(databaseName);
        }
        final ImmutableList.Builder<QualifiedName> viewsBuilder = ImmutableList.builder();
        for (final MaterializedViewMetadata view : keyspaceMetadata.getMaterializedViews()) {
            viewsBuilder.add(QualifiedName.ofView(catalogName, keyspace, view.getBaseTable().getName(), view.getName()));
        }
        final List<QualifiedName> views = viewsBuilder.build();
        log.debug("Successfully found {} views for keyspace {} due to request {}", views.size(), keyspace, context);
        return views;
    } catch (final DriverException de) {
        log.error(de.getMessage(), de);
        throw this.getExceptionMapper().toConnectorException(de, databaseName);
    }
}
Also used : MaterializedViewMetadata(com.datastax.driver.core.MaterializedViewMetadata) ImmutableList(com.google.common.collect.ImmutableList) DatabaseNotFoundException(com.netflix.metacat.common.server.connectors.exception.DatabaseNotFoundException) QualifiedName(com.netflix.metacat.common.QualifiedName) DriverException(com.datastax.driver.core.exceptions.DriverException) KeyspaceMetadata(com.datastax.driver.core.KeyspaceMetadata)

Example 22 with DatabaseNotFoundException

use of com.netflix.metacat.common.server.connectors.exception.DatabaseNotFoundException in project metacat by Netflix.

the class CassandraConnectorTableService method list.

/**
     * {@inheritDoc}
     */
@Override
public List<TableInfo> list(@Nonnull @NonNull final ConnectorContext context, @Nonnull @NonNull final QualifiedName name, @Nullable final QualifiedName prefix, @Nullable final Sort sort, @Nullable final Pageable pageable) {
    final String keyspace = name.getDatabaseName();
    log.debug("Attempting to list tables in Cassandra keyspace {} for request {}", keyspace, context);
    try {
        final KeyspaceMetadata keyspaceMetadata = this.getCluster().getMetadata().getKeyspace(keyspace);
        if (keyspaceMetadata == null) {
            throw new DatabaseNotFoundException(name);
        }
        // TODO: Should we include views?
        final List<TableInfo> tables = Lists.newArrayList();
        for (final TableMetadata tableMetadata : keyspaceMetadata.getTables()) {
            if (prefix != null && !tableMetadata.getName().startsWith(prefix.getTableName())) {
                continue;
            }
            tables.add(this.getTableInfo(name, tableMetadata));
        }
        // Sort
        if (sort != null) {
            final Comparator<TableInfo> tableComparator = Comparator.comparing((t) -> t.getName().getTableName());
            ConnectorUtils.sort(tables, sort, tableComparator);
        }
        // Paging
        final List<TableInfo> pagedTables = ConnectorUtils.paginate(tables, pageable);
        log.debug("Listed {} tables in Cassandra keyspace {} for request {}", pagedTables.size(), keyspace, context);
        return pagedTables;
    } catch (final DriverException de) {
        log.error(de.getMessage(), de);
        throw this.getExceptionMapper().toConnectorException(de, name);
    }
}
Also used : TableMetadata(com.datastax.driver.core.TableMetadata) DatabaseNotFoundException(com.netflix.metacat.common.server.connectors.exception.DatabaseNotFoundException) TableInfo(com.netflix.metacat.common.server.connectors.model.TableInfo) DriverException(com.datastax.driver.core.exceptions.DriverException) KeyspaceMetadata(com.datastax.driver.core.KeyspaceMetadata)

Example 23 with DatabaseNotFoundException

use of com.netflix.metacat.common.server.connectors.exception.DatabaseNotFoundException in project metacat by Netflix.

the class CassandraConnectorDatabaseService method get.

/**
     * {@inheritDoc}
     */
@Override
public DatabaseInfo get(@Nonnull @NonNull final ConnectorContext context, @Nonnull @NonNull final QualifiedName name) {
    final String keyspace = name.getDatabaseName();
    log.debug("Attempting to get keyspace metadata for keyspace {} for request", keyspace, context);
    try {
        final KeyspaceMetadata keyspaceMetadata = this.getCluster().getMetadata().getKeyspace(keyspace);
        if (keyspaceMetadata == null) {
            throw new DatabaseNotFoundException(name);
        }
        log.debug("Successfully found the keyspace metadata for {} for request", name, context);
        return DatabaseInfo.builder().name(name).build();
    } catch (final DriverException de) {
        log.error(de.getMessage(), de);
        throw this.getExceptionMapper().toConnectorException(de, name);
    }
}
Also used : DatabaseNotFoundException(com.netflix.metacat.common.server.connectors.exception.DatabaseNotFoundException) DriverException(com.datastax.driver.core.exceptions.DriverException) KeyspaceMetadata(com.datastax.driver.core.KeyspaceMetadata)

Example 24 with DatabaseNotFoundException

use of com.netflix.metacat.common.server.connectors.exception.DatabaseNotFoundException in project metacat by Netflix.

the class S3ConnectorDatabaseService method delete.

@Override
public void delete(@Nonnull final ConnectorContext context, @Nonnull final QualifiedName name) {
    log.debug("Start: Delete database {}", name);
    final String databaseName = name.getDatabaseName();
    Preconditions.checkNotNull(databaseName, "Database name is null");
    final Database database = databaseDao.getBySourceDatabaseName(catalogName, databaseName);
    if (database == null) {
        throw new DatabaseNotFoundException(name);
    } else if (database.getTables() != null && !database.getTables().isEmpty()) {
        throw new ConnectorException("Database " + databaseName + " is not empty. One or more tables exist.", null);
    }
    databaseDao.delete(database);
    log.debug("End: Delete database {}", name);
}
Also used : DatabaseNotFoundException(com.netflix.metacat.common.server.connectors.exception.DatabaseNotFoundException) ConnectorException(com.netflix.metacat.common.server.connectors.exception.ConnectorException) Database(com.netflix.metacat.connector.s3.model.Database)

Example 25 with DatabaseNotFoundException

use of com.netflix.metacat.common.server.connectors.exception.DatabaseNotFoundException in project metacat by Netflix.

the class TagController method setResourceTags.

private Set<String> setResourceTags(@NonNull final TagCreateRequestDto tagCreateRequestDto) {
    final QualifiedName name = tagCreateRequestDto.getName();
    final Set<String> tags = new HashSet<>(tagCreateRequestDto.getTags());
    final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
    Set<String> result = new HashSet<>();
    switch(name.getType()) {
        case CATALOG:
            // catalog service will throw exception if not found
            this.catalogService.get(name, GetCatalogServiceParameters.builder().includeDatabaseNames(false).includeUserMetadata(false).build());
            return this.tagService.setTags(name, tags, true);
        case DATABASE:
            if (!this.databaseService.exists(name)) {
                throw new DatabaseNotFoundException(name);
            }
            result = this.tagService.setTags(name, tags, true);
            this.eventBus.post(new MetacatUpdateDatabasePostEvent(name, metacatRequestContext, this));
            return result;
        case TABLE:
            if (!this.tableService.exists(name)) {
                throw new TableNotFoundException(name);
            }
            final TableDto oldTable = this.tableService.get(name, GetTableServiceParameters.builder().includeInfo(true).includeDataMetadata(true).includeDefinitionMetadata(true).disableOnReadMetadataIntercetor(false).build()).orElseThrow(IllegalStateException::new);
            result = this.tagService.setTags(name, tags, true);
            final TableDto currentTable = this.tableService.get(name, GetTableServiceParameters.builder().includeInfo(true).includeDataMetadata(true).includeDefinitionMetadata(true).disableOnReadMetadataIntercetor(false).build()).orElseThrow(IllegalStateException::new);
            this.eventBus.post(new MetacatUpdateTablePostEvent(name, metacatRequestContext, this, oldTable, currentTable));
            return result;
        case MVIEW:
            if (!this.mViewService.exists(name)) {
                throw new MetacatNotFoundException(name.toString());
            }
            final Optional<TableDto> oldView = this.mViewService.getOpt(name, GetTableServiceParameters.builder().includeInfo(true).includeDataMetadata(true).includeDefinitionMetadata(true).disableOnReadMetadataIntercetor(false).build());
            if (oldView.isPresent()) {
                result = this.tagService.setTags(name, tags, true);
                final Optional<TableDto> currentView = this.mViewService.getOpt(name, GetTableServiceParameters.builder().includeInfo(true).includeDataMetadata(true).includeDefinitionMetadata(true).disableOnReadMetadataIntercetor(false).build());
                currentView.ifPresent(p -> this.eventBus.post(new MetacatUpdateTablePostEvent(name, metacatRequestContext, this, oldView.get(), currentView.get())));
                return result;
            }
            break;
        default:
            throw new MetacatNotFoundException("Unsupported qualifiedName type {}" + name);
    }
    return result;
}
Also used : MetacatRequestContext(com.netflix.metacat.common.MetacatRequestContext) QualifiedName(com.netflix.metacat.common.QualifiedName) MetacatUpdateDatabasePostEvent(com.netflix.metacat.common.server.events.MetacatUpdateDatabasePostEvent) TableDto(com.netflix.metacat.common.dto.TableDto) MetacatUpdateTablePostEvent(com.netflix.metacat.common.server.events.MetacatUpdateTablePostEvent) MetacatNotFoundException(com.netflix.metacat.common.exception.MetacatNotFoundException) TableNotFoundException(com.netflix.metacat.common.server.connectors.exception.TableNotFoundException) DatabaseNotFoundException(com.netflix.metacat.common.server.connectors.exception.DatabaseNotFoundException) HashSet(java.util.HashSet)

Aggregations

DatabaseNotFoundException (com.netflix.metacat.common.server.connectors.exception.DatabaseNotFoundException)33 QualifiedName (com.netflix.metacat.common.QualifiedName)19 KeyspaceMetadata (com.datastax.driver.core.KeyspaceMetadata)10 DriverException (com.datastax.driver.core.exceptions.DriverException)10 ConnectorException (com.netflix.metacat.common.server.connectors.exception.ConnectorException)10 InvalidMetaException (com.netflix.metacat.common.server.connectors.exception.InvalidMetaException)8 Database (com.netflix.metacat.connector.s3.model.Database)8 TableMetadata (com.datastax.driver.core.TableMetadata)6 MetacatRequestContext (com.netflix.metacat.common.MetacatRequestContext)6 TableNotFoundException (com.netflix.metacat.common.server.connectors.exception.TableNotFoundException)6 TableInfo (com.netflix.metacat.common.server.connectors.model.TableInfo)6 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)6 TException (org.apache.thrift.TException)6 TableAlreadyExistsException (com.netflix.metacat.common.server.connectors.exception.TableAlreadyExistsException)5 NoSuchObjectException (org.apache.hadoop.hive.metastore.api.NoSuchObjectException)5 Strings (com.google.common.base.Strings)4 ImmutableList (com.google.common.collect.ImmutableList)4 Lists (com.google.common.collect.Lists)4 DatabaseDto (com.netflix.metacat.common.dto.DatabaseDto)4 Pageable (com.netflix.metacat.common.dto.Pageable)4