Search in sources :

Example 1 with DatabaseDto

use of com.netflix.metacat.common.dto.DatabaseDto in project metacat by Netflix.

the class MetacatV1Resource method updateDatabase.

@Override
public void updateDatabase(final String catalogName, final String databaseName, final DatabaseCreateRequestDto databaseUpdateRequestDto) {
    final QualifiedName name = requestWrapper.qualifyName(() -> QualifiedName.ofDatabase(catalogName, databaseName));
    requestWrapper.processRequest(name, "updateDatabase", () -> {
        final DatabaseDto newDto = new DatabaseDto();
        newDto.setName(name);
        newDto.setDefinitionMetadata(databaseUpdateRequestDto.getDefinitionMetadata());
        databaseService.update(name, newDto);
        return null;
    });
}
Also used : QualifiedName(com.netflix.metacat.common.QualifiedName) DatabaseDto(com.netflix.metacat.common.dto.DatabaseDto)

Example 2 with DatabaseDto

use of com.netflix.metacat.common.dto.DatabaseDto in project metacat by Netflix.

the class MetacatV1Resource method createDatabase.

@Override
public void createDatabase(final String catalogName, final String databaseName, final DatabaseCreateRequestDto databaseCreateRequestDto) {
    final QualifiedName name = requestWrapper.qualifyName(() -> QualifiedName.ofDatabase(catalogName, databaseName));
    requestWrapper.processRequest(name, "createDatabase", () -> {
        final DatabaseDto newDto = new DatabaseDto();
        newDto.setName(name);
        if (databaseCreateRequestDto != null) {
            newDto.setDefinitionMetadata(databaseCreateRequestDto.getDefinitionMetadata());
        }
        databaseService.create(name, newDto);
        return null;
    });
}
Also used : QualifiedName(com.netflix.metacat.common.QualifiedName) DatabaseDto(com.netflix.metacat.common.dto.DatabaseDto)

Example 3 with DatabaseDto

use of com.netflix.metacat.common.dto.DatabaseDto in project metacat by Netflix.

the class MetacatElasticSearchEventHandlers method metacatDeleteDatabasePostEventHandler.

/**
     * Subscriber.
     *
     * @param event event
     */
@EventListener
public void metacatDeleteDatabasePostEventHandler(final MetacatDeleteDatabasePostEvent event) {
    log.debug("Received DeleteDatabaseEvent {}", event);
    registry.counter(Metrics.CounterElasticSearchDatabaseDelete.name()).increment();
    final DatabaseDto dto = event.getDatabase();
    es.softDelete(ElasticSearchDoc.Type.database.name(), dto.getName().toString(), event.getRequestContext());
}
Also used : DatabaseDto(com.netflix.metacat.common.dto.DatabaseDto) EventListener(org.springframework.context.event.EventListener)

Example 4 with DatabaseDto

use of com.netflix.metacat.common.dto.DatabaseDto in project metacat by Netflix.

the class ElasticSearchMetacatRefresh method _processDatabases.

/**
     * Process the list of databases.
     *
     * @param catalogName   catalog name
     * @param databaseNames database names
     * @return future
     */
@SuppressWarnings("checkstyle:methodname")
private ListenableFuture<Void> _processDatabases(final QualifiedName catalogName, final List<QualifiedName> databaseNames) {
    ListenableFuture<Void> resultFuture = null;
    log.info("Full refresh of catalog {} for databases({}): {}", catalogName, databaseNames.size(), databaseNames);
    final List<ListenableFuture<DatabaseDto>> getDatabaseFutures = databaseNames.stream().map(databaseName -> service.submit(() -> {
        DatabaseDto result = null;
        try {
            result = getDatabase(databaseName);
        } catch (Exception e) {
            log.error("Failed to retrieve database: {}", databaseName);
            elasticSearchUtil.log("ElasticSearchMetacatRefresh.getDatabase", ElasticSearchDoc.Type.database.name(), databaseName.toString(), null, e.getMessage(), e, true);
        }
        return result;
    })).collect(Collectors.toList());
    if (getDatabaseFutures != null && !getDatabaseFutures.isEmpty()) {
        resultFuture = Futures.transformAsync(Futures.successfulAsList(getDatabaseFutures), input -> {
            final ListenableFuture<Void> processDatabaseFuture = indexDatabaseDtos(catalogName, input);
            final List<ListenableFuture<Void>> processDatabaseFutures = input.stream().filter(NOT_NULL).map(databaseDto -> {
                final List<QualifiedName> tableNames = databaseDto.getTables().stream().map(s -> QualifiedName.ofTable(databaseDto.getName().getCatalogName(), databaseDto.getName().getDatabaseName(), s)).collect(Collectors.toList());
                log.info("Full refresh of database {} for tables({}): {}", databaseDto.getName().toString(), databaseDto.getTables().size(), databaseDto.getTables());
                return processTables(databaseDto.getName(), tableNames);
            }).filter(NOT_NULL).collect(Collectors.toList());
            processDatabaseFutures.add(processDatabaseFuture);
            return Futures.transform(Futures.successfulAsList(processDatabaseFutures), Functions.constant(null));
        });
    }
    return resultFuture;
}
Also used : UserMetadataService(com.netflix.metacat.common.server.usermetadata.UserMetadataService) CatalogService(com.netflix.metacat.main.services.CatalogService) MetacatEventBus(com.netflix.metacat.common.server.events.MetacatEventBus) SortOrder(com.netflix.metacat.common.dto.SortOrder) MetacatContextManager(com.netflix.metacat.common.server.util.MetacatContextManager) PartitionService(com.netflix.metacat.main.services.PartitionService) DatabaseDto(com.netflix.metacat.common.dto.DatabaseDto) TagService(com.netflix.metacat.common.server.usermetadata.TagService) DatabaseService(com.netflix.metacat.main.services.DatabaseService) Splitter(com.google.common.base.Splitter) NonNull(lombok.NonNull) Predicate(java.util.function.Predicate) Pageable(com.netflix.metacat.common.dto.Pageable) Set(java.util.Set) CatalogMappingDto(com.netflix.metacat.common.dto.CatalogMappingDto) QualifiedName(com.netflix.metacat.common.QualifiedName) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) CatalogDto(com.netflix.metacat.common.dto.CatalogDto) HasMetadata(com.netflix.metacat.common.dto.HasMetadata) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) PartitionDto(com.netflix.metacat.common.dto.PartitionDto) Optional(java.util.Optional) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) Sort(com.netflix.metacat.common.dto.Sort) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) MetacatDeleteTablePostEvent(com.netflix.metacat.common.server.events.MetacatDeleteTablePostEvent) TableDto(com.netflix.metacat.common.dto.TableDto) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Supplier(java.util.function.Supplier) DatabaseNotFoundException(com.netflix.metacat.common.server.connectors.exception.DatabaseNotFoundException) Strings(com.google.common.base.Strings) Lists(com.google.common.collect.Lists) TableService(com.netflix.metacat.main.services.TableService) MetacatRequestContext(com.netflix.metacat.common.MetacatRequestContext) Config(com.netflix.metacat.common.server.properties.Config) Nonnull(javax.annotation.Nonnull) ExecutorService(java.util.concurrent.ExecutorService) Metrics(com.netflix.metacat.common.server.monitoring.Metrics) Functions(com.google.common.base.Functions) Throwables(com.google.common.base.Throwables) TimeUnit(java.util.concurrent.TimeUnit) Futures(com.google.common.util.concurrent.Futures) Registry(com.netflix.spectator.api.Registry) Instant(org.joda.time.Instant) DatabaseDto(com.netflix.metacat.common.dto.DatabaseDto) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) List(java.util.List) DatabaseNotFoundException(com.netflix.metacat.common.server.connectors.exception.DatabaseNotFoundException)

Example 5 with DatabaseDto

use of com.netflix.metacat.common.dto.DatabaseDto in project metacat by Netflix.

the class TableServiceImpl method copy.

@Override
public TableDto copy(@Nonnull final TableDto tableDto, @Nonnull final QualifiedName targetName) {
    final QualifiedName databaseName = QualifiedName.ofDatabase(targetName.getCatalogName(), targetName.getDatabaseName());
    if (!databaseService.exists(databaseName)) {
        final DatabaseDto databaseDto = new DatabaseDto();
        databaseDto.setName(databaseName);
        databaseService.create(databaseName, databaseDto);
    }
    final TableDto targetTableDto = new TableDto();
    targetTableDto.setName(targetName);
    targetTableDto.setFields(tableDto.getFields());
    targetTableDto.setPartition_keys(tableDto.getPartition_keys());
    final StorageDto storageDto = tableDto.getSerde();
    if (storageDto != null) {
        final StorageDto targetStorageDto = new StorageDto();
        targetStorageDto.setInputFormat(storageDto.getInputFormat());
        targetStorageDto.setOwner(storageDto.getOwner());
        targetStorageDto.setOutputFormat(storageDto.getOutputFormat());
        targetStorageDto.setParameters(storageDto.getParameters());
        targetStorageDto.setUri(storageDto.getUri());
        targetStorageDto.setSerializationLib(storageDto.getSerializationLib());
        targetTableDto.setSerde(targetStorageDto);
    }
    create(targetName, targetTableDto);
    return targetTableDto;
}
Also used : QualifiedName(com.netflix.metacat.common.QualifiedName) DatabaseDto(com.netflix.metacat.common.dto.DatabaseDto) TableDto(com.netflix.metacat.common.dto.TableDto) StorageDto(com.netflix.metacat.common.dto.StorageDto)

Aggregations

DatabaseDto (com.netflix.metacat.common.dto.DatabaseDto)11 QualifiedName (com.netflix.metacat.common.QualifiedName)6 MetacatRequestContext (com.netflix.metacat.common.MetacatRequestContext)5 TableDto (com.netflix.metacat.common.dto.TableDto)3 ConnectorContext (com.netflix.metacat.common.server.connectors.ConnectorContext)3 DatabaseNotFoundException (com.netflix.metacat.common.server.connectors.exception.DatabaseNotFoundException)3 Functions (com.google.common.base.Functions)2 Splitter (com.google.common.base.Splitter)2 Strings (com.google.common.base.Strings)2 Throwables (com.google.common.base.Throwables)2 Lists (com.google.common.collect.Lists)2 Sets (com.google.common.collect.Sets)2 Futures (com.google.common.util.concurrent.Futures)2 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)2 ListeningExecutorService (com.google.common.util.concurrent.ListeningExecutorService)2 MoreExecutors (com.google.common.util.concurrent.MoreExecutors)2 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)2 CatalogDto (com.netflix.metacat.common.dto.CatalogDto)2 CatalogMappingDto (com.netflix.metacat.common.dto.CatalogMappingDto)2 HasMetadata (com.netflix.metacat.common.dto.HasMetadata)2