Search in sources :

Example 1 with MetacatCatalogConfig

use of com.netflix.metacat.common.server.spi.MetacatCatalogConfig in project metacat by Netflix.

the class CatalogServiceImpl method get.

/**
 * {@inheritDoc}
 */
@Nonnull
@Override
public CatalogDto get(final QualifiedName name) {
    final Set<MetacatCatalogConfig> configs = connectorManager.getCatalogConfigs(name.getCatalogName());
    final CatalogDto result = new CatalogDto();
    result.setName(name);
    final ConnectorRequestContext context = converterUtil.toConnectorContext(MetacatContextManager.getContext());
    final List<String> databases = Lists.newArrayList();
    configs.forEach(config -> {
        QualifiedName qName = name;
        if (config.getSchemaWhitelist().isEmpty()) {
            result.setType(config.getType());
        } else {
            qName = QualifiedName.ofDatabase(name.getCatalogName(), config.getSchemaWhitelist().get(0));
        }
        databases.addAll(connectorManager.getDatabaseService(qName).listNames(context, name, null, null, null).stream().map(QualifiedName::getDatabaseName).filter(s -> config.getSchemaBlacklist().isEmpty() || !config.getSchemaBlacklist().contains(s)).filter(s -> config.getSchemaWhitelist().isEmpty() || config.getSchemaWhitelist().contains(s)).sorted(String.CASE_INSENSITIVE_ORDER).collect(Collectors.toList()));
    });
    result.setDatabases(databases);
    userMetadataService.populateMetadata(result, false);
    return result;
}
Also used : UserMetadataService(com.netflix.metacat.common.server.usermetadata.UserMetadataService) CatalogService(com.netflix.metacat.main.services.CatalogService) CreateCatalogDto(com.netflix.metacat.common.dto.CreateCatalogDto) MetacatEventBus(com.netflix.metacat.common.server.events.MetacatEventBus) ConverterUtil(com.netflix.metacat.common.server.converter.ConverterUtil) MetacatContextManager(com.netflix.metacat.common.server.util.MetacatContextManager) MetacatUpdateDatabasePreEvent(com.netflix.metacat.common.server.events.MetacatUpdateDatabasePreEvent) Set(java.util.Set) CatalogMappingDto(com.netflix.metacat.common.dto.CatalogMappingDto) QualifiedName(com.netflix.metacat.common.QualifiedName) MetacatCatalogConfig(com.netflix.metacat.common.server.spi.MetacatCatalogConfig) MetacatUpdateDatabasePostEvent(com.netflix.metacat.common.server.events.MetacatUpdateDatabasePostEvent) Collectors(java.util.stream.Collectors) MetacatNotFoundException(com.netflix.metacat.common.exception.MetacatNotFoundException) CatalogDto(com.netflix.metacat.common.dto.CatalogDto) List(java.util.List) Lists(com.google.common.collect.Lists) MetacatRequestContext(com.netflix.metacat.common.MetacatRequestContext) ConnectorManager(com.netflix.metacat.main.manager.ConnectorManager) Nonnull(javax.annotation.Nonnull) ConnectorRequestContext(com.netflix.metacat.common.server.connectors.ConnectorRequestContext) CreateCatalogDto(com.netflix.metacat.common.dto.CreateCatalogDto) CatalogDto(com.netflix.metacat.common.dto.CatalogDto) MetacatCatalogConfig(com.netflix.metacat.common.server.spi.MetacatCatalogConfig) QualifiedName(com.netflix.metacat.common.QualifiedName) ConnectorRequestContext(com.netflix.metacat.common.server.connectors.ConnectorRequestContext) Nonnull(javax.annotation.Nonnull)

Example 2 with MetacatCatalogConfig

use of com.netflix.metacat.common.server.spi.MetacatCatalogConfig in project metacat by Netflix.

the class DatabaseServiceImpl method get.

/**
 * {@inheritDoc}
 */
@Override
public DatabaseDto get(final QualifiedName name, final GetDatabaseServiceParameters getDatabaseServiceParameters) {
    validate(name);
    final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
    final MetacatCatalogConfig config = connectorManager.getCatalogConfig(name);
    final ConnectorDatabaseService service = connectorManager.getDatabaseService(name);
    final ConnectorTableService tableService = connectorManager.getTableService(name);
    final ConnectorRequestContext connectorRequestContext = converterUtil.toConnectorContext(metacatRequestContext);
    final DatabaseDto dto = converterUtil.toDatabaseDto(service.get(connectorRequestContext, name));
    dto.setType(config.getType());
    if (getDatabaseServiceParameters.isIncludeTableNames()) {
        final List<QualifiedName> tableNames = tableService.listNames(connectorRequestContext, name, null, null, null);
        List<QualifiedName> viewNames = Collections.emptyList();
        if (config.isIncludeViewsWithTables()) {
            // TODO JdbcMetadata returns ImmutableList.of() for views.  We should change it to fetch views.
            try {
                viewNames = service.listViewNames(connectorRequestContext, name);
            } catch (UnsupportedOperationException ignored) {
            }
        }
        // Check to see if schema exists
        if (tableNames.isEmpty() && viewNames.isEmpty() && !exists(name)) {
            throw new DatabaseNotFoundException(name);
        }
        dto.setTables(Stream.concat(tableNames.stream(), viewNames.stream()).map(QualifiedName::getTableName).sorted(String.CASE_INSENSITIVE_ORDER).collect(Collectors.toList()));
    }
    if (getDatabaseServiceParameters.isIncludeUserMetadata()) {
        log.info("Populate user metadata for schema {}", name);
        userMetadataService.populateMetadata(dto, getDatabaseServiceParameters.isDisableOnReadMetadataIntercetor());
    }
    return dto;
}
Also used : MetacatRequestContext(com.netflix.metacat.common.MetacatRequestContext) ConnectorDatabaseService(com.netflix.metacat.common.server.connectors.ConnectorDatabaseService) ConnectorTableService(com.netflix.metacat.common.server.connectors.ConnectorTableService) MetacatCatalogConfig(com.netflix.metacat.common.server.spi.MetacatCatalogConfig) DatabaseDto(com.netflix.metacat.common.dto.DatabaseDto) QualifiedName(com.netflix.metacat.common.QualifiedName) DatabaseNotFoundException(com.netflix.metacat.common.server.connectors.exception.DatabaseNotFoundException) ConnectorRequestContext(com.netflix.metacat.common.server.connectors.ConnectorRequestContext)

Example 3 with MetacatCatalogConfig

use of com.netflix.metacat.common.server.spi.MetacatCatalogConfig in project metacat by Netflix.

the class ConnectorManager method createConnection.

/**
 * Creates a connection for the given catalog.
 *
 * @param connectorContext metacat connector properties
 */
public synchronized void createConnection(final ConnectorContext connectorContext) {
    Preconditions.checkState(!stopped.get(), "ConnectorManager is stopped");
    final String connectorType = connectorContext.getConnectorType();
    final String catalogName = connectorContext.getCatalogName();
    final String catalogShardName = connectorContext.getCatalogShardName();
    final ConnectorPlugin connectorPlugin = plugins.get(connectorType);
    if (connectorPlugin != null) {
        final MetacatCatalogConfig catalogConfig = MetacatCatalogConfig.createFromMapAndRemoveProperties(connectorType, catalogName, connectorContext.getConfiguration());
        final List<String> databaseNames = catalogConfig.getSchemaWhitelist();
        if (databaseNames.isEmpty()) {
            Preconditions.checkState(!catalogs.contains(catalogName, EMPTY_STRING), "A catalog with name %s already exists", catalogName);
        } else {
            databaseNames.forEach(databaseName -> {
                Preconditions.checkState(!catalogs.contains(catalogName, databaseName), "A catalog with name %s for database %s already exists", catalogName, databaseName);
            });
        }
        catalogConfigs.add(catalogConfig);
        final ConnectorFactory connectorFactory = connectorPlugin.create(connectorContext);
        try {
            databaseServices.add(connectorFactory.getDatabaseService());
        } catch (UnsupportedOperationException e) {
            log.debug("Catalog {}:{} doesn't support getDatabaseService. Ignoring.", catalogName, catalogShardName);
        }
        try {
            tableServices.add(connectorFactory.getTableService());
        } catch (UnsupportedOperationException e) {
            log.debug("Catalog {}:{} doesn't support getTableService. Ignoring.", catalogName, catalogShardName);
        }
        try {
            partitionServices.add(connectorFactory.getPartitionService());
        } catch (UnsupportedOperationException e) {
            log.debug("Catalog {}:{} doesn't support getPartitionService. Ignoring.", catalogName, catalogShardName);
        }
        final CatalogHolder catalogHolder = new CatalogHolder(catalogConfig, connectorFactory);
        if (databaseNames.isEmpty()) {
            catalogs.put(catalogName, EMPTY_STRING, catalogHolder);
        } else {
            databaseNames.forEach(databaseName -> {
                catalogs.put(catalogName, databaseName, catalogHolder);
            });
        }
    } else {
        log.warn("No plugin for connector with type {}", connectorType);
    }
}
Also used : ConnectorPlugin(com.netflix.metacat.common.server.connectors.ConnectorPlugin) ConnectorFactory(com.netflix.metacat.common.server.connectors.ConnectorFactory) MetacatCatalogConfig(com.netflix.metacat.common.server.spi.MetacatCatalogConfig)

Aggregations

MetacatCatalogConfig (com.netflix.metacat.common.server.spi.MetacatCatalogConfig)3 MetacatRequestContext (com.netflix.metacat.common.MetacatRequestContext)2 QualifiedName (com.netflix.metacat.common.QualifiedName)2 ConnectorRequestContext (com.netflix.metacat.common.server.connectors.ConnectorRequestContext)2 Lists (com.google.common.collect.Lists)1 CatalogDto (com.netflix.metacat.common.dto.CatalogDto)1 CatalogMappingDto (com.netflix.metacat.common.dto.CatalogMappingDto)1 CreateCatalogDto (com.netflix.metacat.common.dto.CreateCatalogDto)1 DatabaseDto (com.netflix.metacat.common.dto.DatabaseDto)1 MetacatNotFoundException (com.netflix.metacat.common.exception.MetacatNotFoundException)1 ConnectorDatabaseService (com.netflix.metacat.common.server.connectors.ConnectorDatabaseService)1 ConnectorFactory (com.netflix.metacat.common.server.connectors.ConnectorFactory)1 ConnectorPlugin (com.netflix.metacat.common.server.connectors.ConnectorPlugin)1 ConnectorTableService (com.netflix.metacat.common.server.connectors.ConnectorTableService)1 DatabaseNotFoundException (com.netflix.metacat.common.server.connectors.exception.DatabaseNotFoundException)1 ConverterUtil (com.netflix.metacat.common.server.converter.ConverterUtil)1 MetacatEventBus (com.netflix.metacat.common.server.events.MetacatEventBus)1 MetacatUpdateDatabasePostEvent (com.netflix.metacat.common.server.events.MetacatUpdateDatabasePostEvent)1 MetacatUpdateDatabasePreEvent (com.netflix.metacat.common.server.events.MetacatUpdateDatabasePreEvent)1 UserMetadataService (com.netflix.metacat.common.server.usermetadata.UserMetadataService)1