Search in sources :

Example 16 with DatabaseDto

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

the class DatabaseServiceImpl method create.

/**
 * {@inheritDoc}
 */
@Override
public DatabaseDto create(final QualifiedName name, final DatabaseDto dto) {
    validate(name);
    log.info("Creating schema {}", name);
    final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
    eventBus.postSync(new MetacatCreateDatabasePreEvent(name, metacatRequestContext, this));
    final ConnectorRequestContext connectorRequestContext = converterUtil.toConnectorContext(metacatRequestContext);
    connectorManager.getDatabaseService(name).create(connectorRequestContext, converterUtil.fromDatabaseDto(dto));
    if (dto.getDefinitionMetadata() != null) {
        log.info("Saving user metadata for schema {}", name);
        userMetadataService.saveDefinitionMetadata(name, metacatRequestContext.getUserName(), Optional.of(dto.getDefinitionMetadata()), true);
    }
    final DatabaseDto createdDto = get(name, GetDatabaseServiceParameters.builder().disableOnReadMetadataIntercetor(true).includeUserMetadata(dto.getDefinitionMetadata() != null).includeTableNames(true).build());
    eventBus.postAsync(new MetacatCreateDatabasePostEvent(name, metacatRequestContext, this, createdDto));
    return createdDto;
}
Also used : MetacatRequestContext(com.netflix.metacat.common.MetacatRequestContext) DatabaseDto(com.netflix.metacat.common.dto.DatabaseDto) MetacatCreateDatabasePostEvent(com.netflix.metacat.common.server.events.MetacatCreateDatabasePostEvent) MetacatCreateDatabasePreEvent(com.netflix.metacat.common.server.events.MetacatCreateDatabasePreEvent) ConnectorRequestContext(com.netflix.metacat.common.server.connectors.ConnectorRequestContext)

Example 17 with DatabaseDto

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

the class DatabaseServiceImpl method delete.

/**
 * {@inheritDoc}
 */
@Override
public void delete(final QualifiedName name) {
    validate(name);
    log.info("Dropping schema {}", name);
    final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
    final DatabaseDto dto = get(name, GetDatabaseServiceParameters.builder().disableOnReadMetadataIntercetor(false).includeUserMetadata(true).includeTableNames(true).build());
    eventBus.postSync(new MetacatDeleteDatabasePreEvent(name, metacatRequestContext, this, dto));
    final ConnectorRequestContext connectorRequestContext = converterUtil.toConnectorContext(metacatRequestContext);
    connectorManager.getDatabaseService(name).delete(connectorRequestContext, name);
    // Delete definition metadata if it exists
    if (userMetadataService.getDefinitionMetadata(name).isPresent()) {
        log.info("Deleting user metadata for schema {}", name);
        userMetadataService.deleteDefinitionMetadata(ImmutableList.of(name));
    }
    eventBus.postAsync(new MetacatDeleteDatabasePostEvent(name, metacatRequestContext, this, dto));
}
Also used : MetacatDeleteDatabasePostEvent(com.netflix.metacat.common.server.events.MetacatDeleteDatabasePostEvent) MetacatRequestContext(com.netflix.metacat.common.MetacatRequestContext) MetacatDeleteDatabasePreEvent(com.netflix.metacat.common.server.events.MetacatDeleteDatabasePreEvent) DatabaseDto(com.netflix.metacat.common.dto.DatabaseDto) ConnectorRequestContext(com.netflix.metacat.common.server.connectors.ConnectorRequestContext)

Example 18 with DatabaseDto

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

the class CatalogThriftHiveMetastore method get_database.

/**
 * {@inheritDoc}
 */
@Override
public Database get_database(final String name) throws TException {
    return requestWrapper("get_database", new Object[] { name }, () -> {
        final String databaseName = normalizeIdentifier(name);
        final DatabaseDto dto = v1.getDatabase(catalogName, databaseName, true, false);
        return hiveConverters.metacatToHiveDatabase(dto);
    });
}
Also used : DatabaseDto(com.netflix.metacat.common.dto.DatabaseDto)

Example 19 with DatabaseDto

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

the class MetacatController method updateDatabase.

/**
 * Updates the given database in the given catalog.
 *
 * @param catalogName              catalog name.
 * @param databaseName             database name.
 * @param databaseUpdateRequestDto database
 */
@RequestMapping(method = RequestMethod.PUT, path = "/catalog/{catalog-name}/database/{database-name}", consumes = MediaType.APPLICATION_JSON_VALUE)
@ResponseStatus(HttpStatus.NO_CONTENT)
@ApiOperation(position = 3, value = "Updates the given database in the given catalog", notes = "Given a catalog and a database name, updates the database in the catalog")
@ApiResponses({ @ApiResponse(code = HttpURLConnection.HTTP_OK, message = "Database successfully updated"), @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = "The requested catalog or database cannot be located") })
public void updateDatabase(@ApiParam(value = "The name of the catalog", required = true) @PathVariable("catalog-name") final String catalogName, @ApiParam(value = "The name of the database", required = true) @PathVariable("database-name") final String databaseName, @ApiParam(value = "The database information", required = true) @RequestBody final DatabaseCreateRequestDto databaseUpdateRequestDto) {
    final QualifiedName name = this.requestWrapper.qualifyName(() -> QualifiedName.ofDatabase(catalogName, databaseName));
    this.requestWrapper.processRequest(name, "updateDatabase", () -> {
        final DatabaseDto newDto = new DatabaseDto();
        newDto.setName(name);
        newDto.setDefinitionMetadata(databaseUpdateRequestDto.getDefinitionMetadata());
        this.databaseService.update(name, newDto);
        return null;
    });
}
Also used : QualifiedName(com.netflix.metacat.common.QualifiedName) DatabaseDto(com.netflix.metacat.common.dto.DatabaseDto) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

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