Search in sources :

Example 31 with DatabaseNotFoundException

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

the class PolarisConnectorDatabaseService method get.

/**
 * {@inheritDoc}.
 */
@Override
public DatabaseInfo get(final ConnectorRequestContext context, final QualifiedName name) {
    try {
        final PolarisDatabaseMapper mapper = new PolarisDatabaseMapper(name.getCatalogName());
        final PolarisDatabaseEntity db = polarisStoreService.getDatabase(name.getDatabaseName()).orElseThrow(() -> new DatabaseNotFoundException(name));
        return mapper.toInfo(db);
    } catch (DatabaseNotFoundException exception) {
        log.error(String.format("Not found exception for polaris database %s", name), exception);
        throw exception;
    } catch (Exception exception) {
        throw new ConnectorException(String.format("Failed get polaris database %s", name), exception);
    }
}
Also used : DatabaseNotFoundException(com.netflix.metacat.common.server.connectors.exception.DatabaseNotFoundException) ConnectorException(com.netflix.metacat.common.server.connectors.exception.ConnectorException) PolarisDatabaseMapper(com.netflix.metacat.connector.polaris.mappers.PolarisDatabaseMapper) PolarisDatabaseEntity(com.netflix.metacat.connector.polaris.store.entities.PolarisDatabaseEntity) DatabaseAlreadyExistsException(com.netflix.metacat.common.server.connectors.exception.DatabaseAlreadyExistsException) DatabaseNotFoundException(com.netflix.metacat.common.server.connectors.exception.DatabaseNotFoundException) InvalidMetaException(com.netflix.metacat.common.server.connectors.exception.InvalidMetaException) ConnectorException(com.netflix.metacat.common.server.connectors.exception.ConnectorException) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException)

Example 32 with DatabaseNotFoundException

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

the class S3ConnectorTableService method create.

@Override
public void create(@Nonnull final ConnectorRequestContext context, @Nonnull final TableInfo tableInfo) {
    log.debug("Start: Create table {}", tableInfo.getName());
    Preconditions.checkArgument(tableInfo.getSerde() == null || !Strings.isNullOrEmpty(tableInfo.getSerde().getOwner()), "Table owner is null or empty");
    final QualifiedName tableName = tableInfo.getName();
    if (tableDao.getBySourceDatabaseTableName(catalogName, tableName.getDatabaseName(), tableName.getTableName()) != null) {
        throw new TableAlreadyExistsException(tableName);
    }
    final Database database = databaseDao.getBySourceDatabaseName(catalogName, tableName.getDatabaseName());
    if (database == null) {
        throw new DatabaseNotFoundException(QualifiedName.ofDatabase(catalogName, tableName.getDatabaseName()));
    }
    tableDao.save(infoConverter.fromTableInfo(database, tableInfo));
    log.debug("End: Create table {}", tableInfo.getName());
}
Also used : TableAlreadyExistsException(com.netflix.metacat.common.server.connectors.exception.TableAlreadyExistsException) QualifiedName(com.netflix.metacat.common.QualifiedName) DatabaseNotFoundException(com.netflix.metacat.common.server.connectors.exception.DatabaseNotFoundException) Database(com.netflix.metacat.connector.s3.model.Database)

Example 33 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 ConnectorRequestContext 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)

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