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;
}
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;
}
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);
}
}
Aggregations