use of com.netflix.metacat.common.server.connectors.exception.DatabaseNotFoundException in project metacat by Netflix.
the class CassandraConnectorDatabaseService method listViewNames.
/**
* {@inheritDoc}
*/
@Override
public List<QualifiedName> listViewNames(@Nonnull @NonNull final ConnectorContext context, @Nonnull @NonNull final QualifiedName databaseName) {
final String catalogName = databaseName.getCatalogName();
final String keyspace = databaseName.getDatabaseName();
log.debug("Attempting to get materialized view names for keyspace {} due to request {}", keyspace, context);
try {
final KeyspaceMetadata keyspaceMetadata = this.getCluster().getMetadata().getKeyspace(keyspace);
if (keyspaceMetadata == null) {
throw new DatabaseNotFoundException(databaseName);
}
final ImmutableList.Builder<QualifiedName> viewsBuilder = ImmutableList.builder();
for (final MaterializedViewMetadata view : keyspaceMetadata.getMaterializedViews()) {
viewsBuilder.add(QualifiedName.ofView(catalogName, keyspace, view.getBaseTable().getName(), view.getName()));
}
final List<QualifiedName> views = viewsBuilder.build();
log.debug("Successfully found {} views for keyspace {} due to request {}", views.size(), keyspace, context);
return views;
} catch (final DriverException de) {
log.error(de.getMessage(), de);
throw this.getExceptionMapper().toConnectorException(de, databaseName);
}
}
use of com.netflix.metacat.common.server.connectors.exception.DatabaseNotFoundException in project metacat by Netflix.
the class CassandraConnectorTableService method list.
/**
* {@inheritDoc}
*/
@Override
public List<TableInfo> list(@Nonnull @NonNull final ConnectorContext context, @Nonnull @NonNull final QualifiedName name, @Nullable final QualifiedName prefix, @Nullable final Sort sort, @Nullable final Pageable pageable) {
final String keyspace = name.getDatabaseName();
log.debug("Attempting to list tables in Cassandra keyspace {} for request {}", keyspace, context);
try {
final KeyspaceMetadata keyspaceMetadata = this.getCluster().getMetadata().getKeyspace(keyspace);
if (keyspaceMetadata == null) {
throw new DatabaseNotFoundException(name);
}
// TODO: Should we include views?
final List<TableInfo> tables = Lists.newArrayList();
for (final TableMetadata tableMetadata : keyspaceMetadata.getTables()) {
if (prefix != null && !tableMetadata.getName().startsWith(prefix.getTableName())) {
continue;
}
tables.add(this.getTableInfo(name, tableMetadata));
}
// Sort
if (sort != null) {
final Comparator<TableInfo> tableComparator = Comparator.comparing((t) -> t.getName().getTableName());
ConnectorUtils.sort(tables, sort, tableComparator);
}
// Paging
final List<TableInfo> pagedTables = ConnectorUtils.paginate(tables, pageable);
log.debug("Listed {} tables in Cassandra keyspace {} for request {}", pagedTables.size(), keyspace, context);
return pagedTables;
} catch (final DriverException de) {
log.error(de.getMessage(), de);
throw this.getExceptionMapper().toConnectorException(de, name);
}
}
use of com.netflix.metacat.common.server.connectors.exception.DatabaseNotFoundException in project metacat by Netflix.
the class CassandraConnectorDatabaseService method get.
/**
* {@inheritDoc}
*/
@Override
public DatabaseInfo get(@Nonnull @NonNull final ConnectorContext context, @Nonnull @NonNull final QualifiedName name) {
final String keyspace = name.getDatabaseName();
log.debug("Attempting to get keyspace metadata for keyspace {} for request", keyspace, context);
try {
final KeyspaceMetadata keyspaceMetadata = this.getCluster().getMetadata().getKeyspace(keyspace);
if (keyspaceMetadata == null) {
throw new DatabaseNotFoundException(name);
}
log.debug("Successfully found the keyspace metadata for {} for request", name, context);
return DatabaseInfo.builder().name(name).build();
} catch (final DriverException de) {
log.error(de.getMessage(), de);
throw this.getExceptionMapper().toConnectorException(de, name);
}
}
use of com.netflix.metacat.common.server.connectors.exception.DatabaseNotFoundException in project metacat by Netflix.
the class S3ConnectorDatabaseService method delete.
@Override
public void delete(@Nonnull final ConnectorContext context, @Nonnull final QualifiedName name) {
log.debug("Start: Delete database {}", name);
final String databaseName = name.getDatabaseName();
Preconditions.checkNotNull(databaseName, "Database name is null");
final Database database = databaseDao.getBySourceDatabaseName(catalogName, databaseName);
if (database == null) {
throw new DatabaseNotFoundException(name);
} else if (database.getTables() != null && !database.getTables().isEmpty()) {
throw new ConnectorException("Database " + databaseName + " is not empty. One or more tables exist.", null);
}
databaseDao.delete(database);
log.debug("End: Delete database {}", name);
}
use of com.netflix.metacat.common.server.connectors.exception.DatabaseNotFoundException in project metacat by Netflix.
the class TagController method setResourceTags.
private Set<String> setResourceTags(@NonNull final TagCreateRequestDto tagCreateRequestDto) {
final QualifiedName name = tagCreateRequestDto.getName();
final Set<String> tags = new HashSet<>(tagCreateRequestDto.getTags());
final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
Set<String> result = new HashSet<>();
switch(name.getType()) {
case CATALOG:
// catalog service will throw exception if not found
this.catalogService.get(name, GetCatalogServiceParameters.builder().includeDatabaseNames(false).includeUserMetadata(false).build());
return this.tagService.setTags(name, tags, true);
case DATABASE:
if (!this.databaseService.exists(name)) {
throw new DatabaseNotFoundException(name);
}
result = this.tagService.setTags(name, tags, true);
this.eventBus.post(new MetacatUpdateDatabasePostEvent(name, metacatRequestContext, this));
return result;
case TABLE:
if (!this.tableService.exists(name)) {
throw new TableNotFoundException(name);
}
final TableDto oldTable = this.tableService.get(name, GetTableServiceParameters.builder().includeInfo(true).includeDataMetadata(true).includeDefinitionMetadata(true).disableOnReadMetadataIntercetor(false).build()).orElseThrow(IllegalStateException::new);
result = this.tagService.setTags(name, tags, true);
final TableDto currentTable = this.tableService.get(name, GetTableServiceParameters.builder().includeInfo(true).includeDataMetadata(true).includeDefinitionMetadata(true).disableOnReadMetadataIntercetor(false).build()).orElseThrow(IllegalStateException::new);
this.eventBus.post(new MetacatUpdateTablePostEvent(name, metacatRequestContext, this, oldTable, currentTable));
return result;
case MVIEW:
if (!this.mViewService.exists(name)) {
throw new MetacatNotFoundException(name.toString());
}
final Optional<TableDto> oldView = this.mViewService.getOpt(name, GetTableServiceParameters.builder().includeInfo(true).includeDataMetadata(true).includeDefinitionMetadata(true).disableOnReadMetadataIntercetor(false).build());
if (oldView.isPresent()) {
result = this.tagService.setTags(name, tags, true);
final Optional<TableDto> currentView = this.mViewService.getOpt(name, GetTableServiceParameters.builder().includeInfo(true).includeDataMetadata(true).includeDefinitionMetadata(true).disableOnReadMetadataIntercetor(false).build());
currentView.ifPresent(p -> this.eventBus.post(new MetacatUpdateTablePostEvent(name, metacatRequestContext, this, oldView.get(), currentView.get())));
return result;
}
break;
default:
throw new MetacatNotFoundException("Unsupported qualifiedName type {}" + name);
}
return result;
}
Aggregations