Search in sources :

Example 21 with InvalidMetaException

use of com.netflix.metacat.common.server.connectors.exception.InvalidMetaException 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 22 with InvalidMetaException

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

the class HiveConnectorPartitionService method getPartitionKeys.

/**
     * {@inheritDoc}.
     */
@Override
public List<String> getPartitionKeys(@Nonnull @NonNull final ConnectorContext requestContext, @Nonnull @NonNull final QualifiedName tableName, @Nonnull @NonNull final PartitionListRequest partitionsRequest) {
    final String filterExpression = partitionsRequest.getFilter();
    final List<String> partitionIds = partitionsRequest.getPartitionNames();
    List<String> names = Lists.newArrayList();
    final Pageable pageable = partitionsRequest.getPageable();
    try {
        if (filterExpression != null || (partitionIds != null && !partitionIds.isEmpty())) {
            final Table table = metacatHiveClient.getTableByName(tableName.getDatabaseName(), tableName.getTableName());
            for (Partition partition : getPartitions(tableName, filterExpression, partitionIds, partitionsRequest.getSort(), pageable)) {
                names.add(getNameOfPartition(table, partition));
            }
        } else {
            names = metacatHiveClient.getPartitionNames(tableName.getDatabaseName(), tableName.getTableName());
            return ConnectorUtils.paginate(names, pageable);
        }
    } catch (NoSuchObjectException exception) {
        throw new TableNotFoundException(tableName, exception);
    } catch (MetaException | InvalidObjectException e) {
        throw new InvalidMetaException("Invalid metadata for " + tableName, e);
    } catch (TException e) {
        throw new ConnectorException(String.format("Failed get partitions keys for hive table %s", tableName), e);
    }
    return names;
}
Also used : TException(org.apache.thrift.TException) Partition(org.apache.hadoop.hive.metastore.api.Partition) Table(org.apache.hadoop.hive.metastore.api.Table) InvalidMetaException(com.netflix.metacat.common.server.connectors.exception.InvalidMetaException) TableNotFoundException(com.netflix.metacat.common.server.connectors.exception.TableNotFoundException) Pageable(com.netflix.metacat.common.dto.Pageable) ConnectorException(com.netflix.metacat.common.server.connectors.exception.ConnectorException) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) InvalidObjectException(org.apache.hadoop.hive.metastore.api.InvalidObjectException) MetaException(org.apache.hadoop.hive.metastore.api.MetaException) InvalidMetaException(com.netflix.metacat.common.server.connectors.exception.InvalidMetaException)

Example 23 with InvalidMetaException

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

the class HiveConnectorTableService method update.

/**
     * Update a resource with the given metadata.
     *
     * @param requestContext The request context
     * @param tableInfo      The resource metadata
     */
@Override
public void update(@Nonnull @NonNull final ConnectorContext requestContext, @Nonnull @NonNull final TableInfo tableInfo) {
    final QualifiedName tableName = tableInfo.getName();
    try {
        final Table existingTable = hiveMetacatConverters.fromTableInfo(get(requestContext, tableInfo.getName()));
        if (existingTable.getTableType().equals(TableType.VIRTUAL_VIEW.name())) {
            throw new TableNotFoundException(tableName);
        }
        updateTable(requestContext, existingTable, tableInfo);
        metacatHiveClient.alterTable(tableName.getDatabaseName(), tableName.getTableName(), existingTable);
    } catch (NoSuchObjectException exception) {
        throw new TableNotFoundException(tableName, exception);
    } catch (MetaException exception) {
        throw new InvalidMetaException(tableName, exception);
    } catch (TException exception) {
        throw new ConnectorException(String.format("Failed update hive table %s", tableName), exception);
    }
}
Also used : TException(org.apache.thrift.TException) TableNotFoundException(com.netflix.metacat.common.server.connectors.exception.TableNotFoundException) Table(org.apache.hadoop.hive.metastore.api.Table) QualifiedName(com.netflix.metacat.common.QualifiedName) ConnectorException(com.netflix.metacat.common.server.connectors.exception.ConnectorException) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) 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 24 with InvalidMetaException

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

the class RequestWrapper method processRequest.

/**
 * Request wrapper to to process request.
 *
 * @param name                name
 * @param resourceRequestName request name
 * @param supplier            supplier
 * @param <R>                 response
 * @return response of supplier
 */
public <R> R processRequest(final QualifiedName name, final String resourceRequestName, final Supplier<R> supplier) {
    final long start = registry.clock().wallTime();
    final Map<String, String> tags = new HashMap<>(name.parts());
    tags.put("request", resourceRequestName);
    registry.counter(requestCounterId.withTags(tags)).increment();
    try {
        log.info("### Calling method: {} for {}", resourceRequestName, name);
        return supplier.get();
    } catch (UnsupportedOperationException e) {
        collectRequestExceptionMetrics(tags, e.getClass().getSimpleName());
        log.error(e.getMessage(), e);
        throw new MetacatNotSupportedException("Catalog does not support the operation");
    } catch (DatabaseAlreadyExistsException | TableAlreadyExistsException | PartitionAlreadyExistsException e) {
        collectRequestExceptionMetrics(tags, e.getClass().getSimpleName());
        log.error(e.getMessage(), e);
        throw new MetacatAlreadyExistsException(e.getMessage());
    } catch (NotFoundException | MetacatNotFoundException e) {
        collectRequestExceptionMetrics(tags, e.getClass().getSimpleName());
        log.error(e.getMessage(), e);
        throw new MetacatNotFoundException(String.format("Unable to locate for %s. Details: %s", name, e.getMessage()));
    } catch (InvalidMetaException | IllegalArgumentException e) {
        collectRequestExceptionMetrics(tags, e.getClass().getSimpleName());
        log.error(e.getMessage(), e);
        throw new MetacatBadRequestException(String.format("%s.%s", e.getMessage(), e.getCause() == null ? "" : e.getCause().getMessage()));
    } catch (TablePreconditionFailedException e) {
        collectRequestExceptionMetrics(tags, e.getClass().getSimpleName());
        log.error(e.getMessage(), e);
        throw new MetacatPreconditionFailedException(String.format("%s.%s", e.getMessage(), e.getCause() == null ? "" : e.getCause().getMessage()));
    } catch (ConnectorException e) {
        collectRequestExceptionMetrics(tags, e.getClass().getSimpleName());
        final String message = String.format("%s.%s -- %s failed for %s", e.getMessage(), e.getCause() == null ? "" : e.getCause().getMessage(), resourceRequestName, name);
        log.error(message, e);
        throw new MetacatException(message, e);
    } catch (UserMetadataServiceException e) {
        collectRequestExceptionMetrics(tags, e.getClass().getSimpleName());
        final String message = String.format("%s.%s -- %s usermetadata operation failed for %s", e.getMessage(), e.getCause() == null ? "" : e.getCause().getMessage(), resourceRequestName, name);
        throw new MetacatUserMetadataException(message);
    } catch (Exception e) {
        collectRequestExceptionMetrics(tags, e.getClass().getSimpleName());
        final String message = String.format("%s.%s -- %s failed for %s", e.getMessage(), e.getCause() == null ? "" : e.getCause().getMessage(), resourceRequestName, name);
        log.error(message, e);
        throw new MetacatException(message, e);
    } finally {
        final long duration = registry.clock().wallTime() - start;
        log.info("### Time taken to complete {} for {} is {} ms", resourceRequestName, name, duration);
        this.registry.timer(requestTimerId.withTags(tags)).record(duration, TimeUnit.MILLISECONDS);
    }
}
Also used : UserMetadataServiceException(com.netflix.metacat.common.server.usermetadata.UserMetadataServiceException) HashMap(java.util.HashMap) MetacatException(com.netflix.metacat.common.exception.MetacatException) NotFoundException(com.netflix.metacat.common.server.connectors.exception.NotFoundException) MetacatNotFoundException(com.netflix.metacat.common.exception.MetacatNotFoundException) MetacatNotFoundException(com.netflix.metacat.common.exception.MetacatNotFoundException) MetacatPreconditionFailedException(com.netflix.metacat.common.exception.MetacatPreconditionFailedException) PartitionAlreadyExistsException(com.netflix.metacat.common.server.connectors.exception.PartitionAlreadyExistsException) MetacatUserMetadataException(com.netflix.metacat.common.exception.MetacatUserMetadataException) TableAlreadyExistsException(com.netflix.metacat.common.server.connectors.exception.TableAlreadyExistsException) DatabaseAlreadyExistsException(com.netflix.metacat.common.server.connectors.exception.DatabaseAlreadyExistsException) TablePreconditionFailedException(com.netflix.metacat.common.server.connectors.exception.TablePreconditionFailedException) MetacatNotSupportedException(com.netflix.metacat.common.exception.MetacatNotSupportedException) InvalidMetaException(com.netflix.metacat.common.server.connectors.exception.InvalidMetaException) MetacatException(com.netflix.metacat.common.exception.MetacatException) DatabaseAlreadyExistsException(com.netflix.metacat.common.server.connectors.exception.DatabaseAlreadyExistsException) TablePreconditionFailedException(com.netflix.metacat.common.server.connectors.exception.TablePreconditionFailedException) InvalidMetaException(com.netflix.metacat.common.server.connectors.exception.InvalidMetaException) ConnectorException(com.netflix.metacat.common.server.connectors.exception.ConnectorException) MetacatBadRequestException(com.netflix.metacat.common.exception.MetacatBadRequestException) MetacatNotSupportedException(com.netflix.metacat.common.exception.MetacatNotSupportedException) UserMetadataServiceException(com.netflix.metacat.common.server.usermetadata.UserMetadataServiceException) MetacatUserMetadataException(com.netflix.metacat.common.exception.MetacatUserMetadataException) NotFoundException(com.netflix.metacat.common.server.connectors.exception.NotFoundException) MetacatPreconditionFailedException(com.netflix.metacat.common.exception.MetacatPreconditionFailedException) MetacatAlreadyExistsException(com.netflix.metacat.common.exception.MetacatAlreadyExistsException) MetacatNotFoundException(com.netflix.metacat.common.exception.MetacatNotFoundException) PartitionAlreadyExistsException(com.netflix.metacat.common.server.connectors.exception.PartitionAlreadyExistsException) TableAlreadyExistsException(com.netflix.metacat.common.server.connectors.exception.TableAlreadyExistsException) ConnectorException(com.netflix.metacat.common.server.connectors.exception.ConnectorException) MetacatAlreadyExistsException(com.netflix.metacat.common.exception.MetacatAlreadyExistsException) MetacatBadRequestException(com.netflix.metacat.common.exception.MetacatBadRequestException)

Example 25 with InvalidMetaException

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

the class PartitionUtil method getPartValuesFromPartName.

/**
 * Retrieves the partition values from the partition name. This method also validates the partition keys to that
 * of the table.
 *
 * @param tableQName  table name
 * @param table       table
 * @param partName    partition name
 * @return list of partition values
 */
public static List<String> getPartValuesFromPartName(final QualifiedName tableQName, final Table table, final String partName) {
    if (Strings.isNullOrEmpty(partName)) {
        throw new InvalidMetaException(tableQName, partName, null);
    }
    final LinkedHashMap<String, String> partSpec = new LinkedHashMap<>();
    Warehouse.makeSpecFromName(partSpec, new Path(partName));
    final List<String> values = new ArrayList<>();
    for (FieldSchema field : table.getPartitionKeys()) {
        final String key = field.getName();
        final String val = partSpec.get(key);
        if (val == null) {
            throw new InvalidMetaException(tableQName, partName, null);
        }
        values.add(val);
    }
    return values;
}
Also used : Path(org.apache.hadoop.fs.Path) FieldSchema(org.apache.hadoop.hive.metastore.api.FieldSchema) ArrayList(java.util.ArrayList) InvalidMetaException(com.netflix.metacat.common.server.connectors.exception.InvalidMetaException) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

InvalidMetaException (com.netflix.metacat.common.server.connectors.exception.InvalidMetaException)33 ConnectorException (com.netflix.metacat.common.server.connectors.exception.ConnectorException)28 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)21 TException (org.apache.thrift.TException)21 QualifiedName (com.netflix.metacat.common.QualifiedName)18 NoSuchObjectException (org.apache.hadoop.hive.metastore.api.NoSuchObjectException)17 TableNotFoundException (com.netflix.metacat.common.server.connectors.exception.TableNotFoundException)16 InvalidObjectException (org.apache.hadoop.hive.metastore.api.InvalidObjectException)14 Table (org.apache.hadoop.hive.metastore.api.Table)13 Partition (org.apache.hadoop.hive.metastore.api.Partition)9 Pageable (com.netflix.metacat.common.dto.Pageable)8 DatabaseNotFoundException (com.netflix.metacat.common.server.connectors.exception.DatabaseNotFoundException)8 AlreadyExistsException (org.apache.hadoop.hive.metastore.api.AlreadyExistsException)7 Lists (com.google.common.collect.Lists)6 DatabaseAlreadyExistsException (com.netflix.metacat.common.server.connectors.exception.DatabaseAlreadyExistsException)6 TablePreconditionFailedException (com.netflix.metacat.common.server.connectors.exception.TablePreconditionFailedException)6 TableInfo (com.netflix.metacat.common.server.connectors.model.TableInfo)6 ArrayList (java.util.ArrayList)6 Sort (com.netflix.metacat.common.dto.Sort)5 ConnectorContext (com.netflix.metacat.common.server.connectors.ConnectorContext)5