Search in sources :

Example 1 with PolarisDatabaseMapper

use of com.netflix.metacat.connector.polaris.mappers.PolarisDatabaseMapper 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 2 with PolarisDatabaseMapper

use of com.netflix.metacat.connector.polaris.mappers.PolarisDatabaseMapper in project metacat by Netflix.

the class PolarisConnectorDatabaseService method list.

/**
 * {@inheritDoc}.
 */
@Override
public List<DatabaseInfo> list(final ConnectorRequestContext context, final QualifiedName name, @Nullable final QualifiedName prefix, @Nullable final Sort sort, @Nullable final Pageable pageable) {
    try {
        final PolarisDatabaseMapper mapper = new PolarisDatabaseMapper(name.getCatalogName());
        List<PolarisDatabaseEntity> dbs = polarisStoreService.getAllDatabases();
        if (prefix != null) {
            dbs = dbs.stream().filter(n -> QualifiedName.ofDatabase(name.getCatalogName(), n.getDbName()).startsWith(prefix)).collect(Collectors.toCollection(ArrayList::new));
        }
        if (sort != null) {
            ConnectorUtils.sort(dbs, sort, Comparator.comparing(p -> p.getDbName()));
        }
        return ConnectorUtils.paginate(dbs, pageable).stream().map(d -> mapper.toInfo(d)).collect(Collectors.toList());
    } catch (Exception exception) {
        throw new ConnectorException(String.format("Failed databases list polaris prefix %s", prefix), exception);
    }
}
Also used : ConnectorDatabaseService(com.netflix.metacat.common.server.connectors.ConnectorDatabaseService) DatabaseAlreadyExistsException(com.netflix.metacat.common.server.connectors.exception.DatabaseAlreadyExistsException) Pageable(com.netflix.metacat.common.dto.Pageable) PolarisDatabaseMapper(com.netflix.metacat.connector.polaris.mappers.PolarisDatabaseMapper) QualifiedName(com.netflix.metacat.common.QualifiedName) Collectors(java.util.stream.Collectors) DatabaseNotFoundException(com.netflix.metacat.common.server.connectors.exception.DatabaseNotFoundException) ArrayList(java.util.ArrayList) InvalidMetaException(com.netflix.metacat.common.server.connectors.exception.InvalidMetaException) DatabaseInfo(com.netflix.metacat.common.server.connectors.model.DatabaseInfo) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) ConnectorException(com.netflix.metacat.common.server.connectors.exception.ConnectorException) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) ConnectorContext(com.netflix.metacat.common.server.connectors.ConnectorContext) ConnectorUtils(com.netflix.metacat.common.server.connectors.ConnectorUtils) Comparator(java.util.Comparator) ConnectorRequestContext(com.netflix.metacat.common.server.connectors.ConnectorRequestContext) PolarisStoreService(com.netflix.metacat.connector.polaris.store.PolarisStoreService) PolarisDatabaseEntity(com.netflix.metacat.connector.polaris.store.entities.PolarisDatabaseEntity) Nullable(javax.annotation.Nullable) Sort(com.netflix.metacat.common.dto.Sort) ConnectorException(com.netflix.metacat.common.server.connectors.exception.ConnectorException) ArrayList(java.util.ArrayList) 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)

Aggregations

ConnectorException (com.netflix.metacat.common.server.connectors.exception.ConnectorException)2 DatabaseAlreadyExistsException (com.netflix.metacat.common.server.connectors.exception.DatabaseAlreadyExistsException)2 DatabaseNotFoundException (com.netflix.metacat.common.server.connectors.exception.DatabaseNotFoundException)2 InvalidMetaException (com.netflix.metacat.common.server.connectors.exception.InvalidMetaException)2 PolarisDatabaseMapper (com.netflix.metacat.connector.polaris.mappers.PolarisDatabaseMapper)2 PolarisDatabaseEntity (com.netflix.metacat.connector.polaris.store.entities.PolarisDatabaseEntity)2 DataIntegrityViolationException (org.springframework.dao.DataIntegrityViolationException)2 QualifiedName (com.netflix.metacat.common.QualifiedName)1 Pageable (com.netflix.metacat.common.dto.Pageable)1 Sort (com.netflix.metacat.common.dto.Sort)1 ConnectorContext (com.netflix.metacat.common.server.connectors.ConnectorContext)1 ConnectorDatabaseService (com.netflix.metacat.common.server.connectors.ConnectorDatabaseService)1 ConnectorRequestContext (com.netflix.metacat.common.server.connectors.ConnectorRequestContext)1 ConnectorUtils (com.netflix.metacat.common.server.connectors.ConnectorUtils)1 DatabaseInfo (com.netflix.metacat.common.server.connectors.model.DatabaseInfo)1 PolarisStoreService (com.netflix.metacat.connector.polaris.store.PolarisStoreService)1 ArrayList (java.util.ArrayList)1 Comparator (java.util.Comparator)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1