Search in sources :

Example 1 with DatabaseInfo

use of com.netflix.metacat.common.server.connectors.model.DatabaseInfo in project metacat by Netflix.

the class JdbcConnectorDatabaseService method list.

/**
     * {@inheritDoc}
     */
@Override
public List<DatabaseInfo> list(@Nonnull final ConnectorContext context, @Nonnull final QualifiedName name, @Nullable final QualifiedName prefix, @Nullable final Sort sort, @Nullable final Pageable pageable) {
    final String catalogName = name.getCatalogName();
    log.debug("Beginning to list database metadata for catalog {} for request {}", catalogName, context);
    final ImmutableList.Builder<DatabaseInfo> builder = ImmutableList.builder();
    for (final QualifiedName dbName : this.listNames(context, name, prefix, sort, pageable)) {
        builder.add(this.get(context, dbName));
    }
    log.debug("Finished listing database metadata for catalog {} for request {}", catalogName, context);
    return builder.build();
}
Also used : DatabaseInfo(com.netflix.metacat.common.server.connectors.model.DatabaseInfo) ImmutableList(com.google.common.collect.ImmutableList) QualifiedName(com.netflix.metacat.common.QualifiedName)

Example 2 with DatabaseInfo

use of com.netflix.metacat.common.server.connectors.model.DatabaseInfo in project metacat by Netflix.

the class HiveConnectorDatabaseService method list.

/**
     * {@inheritDoc}.
     */
@Override
public List<DatabaseInfo> list(@Nonnull @NonNull final ConnectorContext requestContext, @Nonnull @NonNull final QualifiedName name, @Nullable final QualifiedName prefix, @Nullable final Sort sort, @Nullable final Pageable pageable) {
    try {
        final List<DatabaseInfo> databaseInfos = Lists.newArrayList();
        for (String databaseName : metacatHiveClient.getAllDatabases()) {
            final QualifiedName qualifiedName = QualifiedName.ofDatabase(name.getCatalogName(), databaseName);
            if (!qualifiedName.toString().startsWith(prefix.toString())) {
                continue;
            }
            databaseInfos.add(DatabaseInfo.builder().name(qualifiedName).build());
        }
        //supporting sort by name only
        if (sort != null) {
            ConnectorUtils.sort(databaseInfos, sort, Comparator.comparing(p -> p.getName().getDatabaseName()));
        }
        return ConnectorUtils.paginate(databaseInfos, pageable);
    } catch (MetaException exception) {
        throw new InvalidMetaException(name, exception);
    } catch (TException exception) {
        throw new ConnectorException(String.format("Failed list hive database %s", name), exception);
    }
}
Also used : MetaException(org.apache.hadoop.hive.metastore.api.MetaException) DatabaseAlreadyExistsException(com.netflix.metacat.common.server.connectors.exception.DatabaseAlreadyExistsException) DatabaseNotFoundException(com.netflix.metacat.common.server.connectors.exception.DatabaseNotFoundException) AlreadyExistsException(org.apache.hadoop.hive.metastore.api.AlreadyExistsException) Inject(javax.inject.Inject) InvalidMetaException(com.netflix.metacat.common.server.connectors.exception.InvalidMetaException) DatabaseInfo(com.netflix.metacat.common.server.connectors.model.DatabaseInfo) Lists(com.google.common.collect.Lists) ConnectorException(com.netflix.metacat.common.server.connectors.exception.ConnectorException) MetacatNotSupportedException(com.netflix.metacat.common.exception.MetacatNotSupportedException) ConnectorContext(com.netflix.metacat.common.server.connectors.ConnectorContext) Named(javax.inject.Named) HiveConnectorInfoConverter(com.netflix.metacat.connector.hive.converters.HiveConnectorInfoConverter) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) ConnectorDatabaseService(com.netflix.metacat.common.server.connectors.ConnectorDatabaseService) NonNull(lombok.NonNull) Pageable(com.netflix.metacat.common.dto.Pageable) TException(org.apache.thrift.TException) QualifiedName(com.netflix.metacat.common.QualifiedName) InvalidObjectException(org.apache.hadoop.hive.metastore.api.InvalidObjectException) List(java.util.List) ConnectorUtils(com.netflix.metacat.common.server.connectors.ConnectorUtils) Comparator(java.util.Comparator) Database(org.apache.hadoop.hive.metastore.api.Database) InvalidOperationException(org.apache.hadoop.hive.metastore.api.InvalidOperationException) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) Sort(com.netflix.metacat.common.dto.Sort) TException(org.apache.thrift.TException) DatabaseInfo(com.netflix.metacat.common.server.connectors.model.DatabaseInfo) QualifiedName(com.netflix.metacat.common.QualifiedName) ConnectorException(com.netflix.metacat.common.server.connectors.exception.ConnectorException) InvalidMetaException(com.netflix.metacat.common.server.connectors.exception.InvalidMetaException) MetaException(org.apache.hadoop.hive.metastore.api.MetaException) InvalidMetaException(com.netflix.metacat.common.server.connectors.exception.InvalidMetaException)

Example 3 with DatabaseInfo

use of com.netflix.metacat.common.server.connectors.model.DatabaseInfo in project metacat by Netflix.

the class CassandraConnectorDatabaseService method list.

/**
     * {@inheritDoc}
     */
@Override
public List<DatabaseInfo> list(@Nonnull @NonNull final ConnectorContext context, @Nonnull @NonNull final QualifiedName name, @Nullable final QualifiedName prefix, @Nullable final Sort sort, @Nullable final Pageable pageable) {
    log.debug("Attempting to list keyspaces for request {}", context);
    final ImmutableList.Builder<DatabaseInfo> keyspacesBuilder = ImmutableList.builder();
    for (final QualifiedName keyspace : this.listNames(context, name, prefix, sort, pageable)) {
        keyspacesBuilder.add(DatabaseInfo.builder().name(keyspace).build());
    }
    final List<DatabaseInfo> keyspaces = keyspacesBuilder.build();
    log.debug("Successfully listed {} keyspaces for request {}", keyspaces.size(), context);
    return keyspaces;
}
Also used : DatabaseInfo(com.netflix.metacat.common.server.connectors.model.DatabaseInfo) ImmutableList(com.google.common.collect.ImmutableList) QualifiedName(com.netflix.metacat.common.QualifiedName)

Aggregations

QualifiedName (com.netflix.metacat.common.QualifiedName)3 DatabaseInfo (com.netflix.metacat.common.server.connectors.model.DatabaseInfo)3 ImmutableList (com.google.common.collect.ImmutableList)2 Lists (com.google.common.collect.Lists)1 Pageable (com.netflix.metacat.common.dto.Pageable)1 Sort (com.netflix.metacat.common.dto.Sort)1 MetacatNotSupportedException (com.netflix.metacat.common.exception.MetacatNotSupportedException)1 ConnectorContext (com.netflix.metacat.common.server.connectors.ConnectorContext)1 ConnectorDatabaseService (com.netflix.metacat.common.server.connectors.ConnectorDatabaseService)1 ConnectorUtils (com.netflix.metacat.common.server.connectors.ConnectorUtils)1 ConnectorException (com.netflix.metacat.common.server.connectors.exception.ConnectorException)1 DatabaseAlreadyExistsException (com.netflix.metacat.common.server.connectors.exception.DatabaseAlreadyExistsException)1 DatabaseNotFoundException (com.netflix.metacat.common.server.connectors.exception.DatabaseNotFoundException)1 InvalidMetaException (com.netflix.metacat.common.server.connectors.exception.InvalidMetaException)1 HiveConnectorInfoConverter (com.netflix.metacat.connector.hive.converters.HiveConnectorInfoConverter)1 Comparator (java.util.Comparator)1 List (java.util.List)1 Nonnull (javax.annotation.Nonnull)1 Nullable (javax.annotation.Nullable)1 Inject (javax.inject.Inject)1