Search in sources :

Example 16 with TableNotFoundException

use of com.netflix.metacat.common.server.connectors.exception.TableNotFoundException in project metacat by Netflix.

the class TableServiceImpl method rename.

/**
 * {@inheritDoc}
 */
@Override
public void rename(final QualifiedName oldName, final QualifiedName newName, final boolean isMView) {
    validate(oldName);
    final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
    this.authorizationService.checkPermission(metacatRequestContext.getUserName(), oldName, MetacatOperation.RENAME);
    final TableDto oldTable = get(oldName, GetTableServiceParameters.builder().includeInfo(true).disableOnReadMetadataIntercetor(false).includeDefinitionMetadata(true).includeDataMetadata(true).build()).orElseThrow(() -> new TableNotFoundException(oldName));
    // Fail if the table is tagged not to be renamed.
    if (hasTags(oldTable, config.getNoTableRenameOnTags())) {
        throw new IllegalArgumentException(String.format("Table %s cannot be renamed because it is tagged with %s.", oldName, config.getNoTableRenameOnTags()));
    }
    if (oldTable != null) {
        // Ignore if the operation is not supported, so that we can at least go ahead and save the user metadata
        eventBus.post(new MetacatRenameTablePreEvent(oldName, metacatRequestContext, this, newName));
        connectorTableServiceProxy.rename(oldName, newName, isMView);
        userMetadataService.renameDefinitionMetadataKey(oldName, newName);
        tagService.renameTableTags(oldName, newName.getTableName());
        final TableDto dto = get(newName, GetTableServiceParameters.builder().includeInfo(true).disableOnReadMetadataIntercetor(false).includeDefinitionMetadata(true).includeDataMetadata(true).build()).orElseThrow(() -> new IllegalStateException("should exist"));
        eventBus.post(new MetacatRenameTablePostEvent(oldName, metacatRequestContext, this, oldTable, dto, isMView));
    }
}
Also used : TableNotFoundException(com.netflix.metacat.common.server.connectors.exception.TableNotFoundException) MetacatRequestContext(com.netflix.metacat.common.MetacatRequestContext) MetacatRenameTablePreEvent(com.netflix.metacat.common.server.events.MetacatRenameTablePreEvent) TableDto(com.netflix.metacat.common.dto.TableDto) MetacatRenameTablePostEvent(com.netflix.metacat.common.server.events.MetacatRenameTablePostEvent)

Example 17 with TableNotFoundException

use of com.netflix.metacat.common.server.connectors.exception.TableNotFoundException in project metacat by Netflix.

the class TagController method removeResourceTags.

private void removeResourceTags(final TagRemoveRequestDto tagRemoveRequestDto) {
    final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
    final QualifiedName name = tagRemoveRequestDto.getName();
    switch(name.getType()) {
        case CATALOG:
            // catalog service will throw exception if not found
            this.catalogService.get(name, GetCatalogServiceParameters.builder().includeDatabaseNames(false).includeUserMetadata(false).build());
            this.tagService.removeTags(name, tagRemoveRequestDto.getDeleteAll(), new HashSet<>(tagRemoveRequestDto.getTags()), true);
            break;
        case DATABASE:
            if (!this.databaseService.exists(name)) {
                throw new DatabaseNotFoundException(name);
            }
            this.tagService.removeTags(name, tagRemoveRequestDto.getDeleteAll(), new HashSet<>(tagRemoveRequestDto.getTags()), true);
            this.eventBus.post(new MetacatUpdateDatabasePostEvent(name, metacatRequestContext, this));
            break;
        case TABLE:
            if (!this.tableService.exists(name)) {
                this.tagService.delete(name, false);
                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);
            this.tagService.removeTags(name, tagRemoveRequestDto.getDeleteAll(), new HashSet<>(tagRemoveRequestDto.getTags()), 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));
            break;
        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()) {
                this.tagService.removeTags(name, tagRemoveRequestDto.getDeleteAll(), new HashSet<>(tagRemoveRequestDto.getTags()), 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())));
            }
            break;
        default:
            throw new MetacatNotFoundException("Unsupported qualifiedName type {}" + name);
    }
}
Also used : MetacatUpdateTablePostEvent(com.netflix.metacat.common.server.events.MetacatUpdateTablePostEvent) MetacatNotFoundException(com.netflix.metacat.common.exception.MetacatNotFoundException) TableNotFoundException(com.netflix.metacat.common.server.connectors.exception.TableNotFoundException) MetacatRequestContext(com.netflix.metacat.common.MetacatRequestContext) QualifiedName(com.netflix.metacat.common.QualifiedName) DatabaseNotFoundException(com.netflix.metacat.common.server.connectors.exception.DatabaseNotFoundException) MetacatUpdateDatabasePostEvent(com.netflix.metacat.common.server.events.MetacatUpdateDatabasePostEvent) TableDto(com.netflix.metacat.common.dto.TableDto)

Example 18 with TableNotFoundException

use of com.netflix.metacat.common.server.connectors.exception.TableNotFoundException in project metacat by Netflix.

the class TagController method setTableTags.

/**
 * Sets the tags on the given table.
 * TODO: remove after setTags api is adopted
 *
 * @param catalogName  catalog name
 * @param databaseName database name
 * @param tableName    table name
 * @param tags         set of tags
 * @return set of tags
 */
@RequestMapping(method = RequestMethod.POST, path = "/catalog/{catalog-name}/database/{database-name}/table/{table-name}", consumes = MediaType.APPLICATION_JSON_VALUE)
@ResponseStatus(HttpStatus.CREATED)
@ApiOperation(value = "Sets the tags on the given table", notes = "Sets the tags on the given table")
@ApiResponses({ @ApiResponse(code = HttpURLConnection.HTTP_CREATED, message = "The tags were successfully created on the table"), @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = "The requested catalog or database or table cannot be located") })
public Set<String> setTableTags(@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 name of the table", required = true) @PathVariable("table-name") final String tableName, @ApiParam(value = "Set of tags", required = true) @RequestBody final Set<String> tags) {
    final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
    final QualifiedName name = this.requestWrapper.qualifyName(() -> QualifiedName.ofTable(catalogName, databaseName, tableName));
    return this.requestWrapper.processRequest(name, "TagV1Resource.setTableTags", () -> {
        // TODO: shouldn't this be in the tag service?
        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);
        final Set<String> 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;
    });
}
Also used : MetacatUpdateTablePostEvent(com.netflix.metacat.common.server.events.MetacatUpdateTablePostEvent) TableNotFoundException(com.netflix.metacat.common.server.connectors.exception.TableNotFoundException) MetacatRequestContext(com.netflix.metacat.common.MetacatRequestContext) QualifiedName(com.netflix.metacat.common.QualifiedName) TableDto(com.netflix.metacat.common.dto.TableDto) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 19 with TableNotFoundException

use of com.netflix.metacat.common.server.connectors.exception.TableNotFoundException in project metacat by Netflix.

the class MetacatController method getTable.

/**
 * Get the table.
 *
 * @param catalogName               catalog name
 * @param databaseName              database name
 * @param tableName                 table name.
 * @param includeInfo               true if the details need to be included
 * @param includeDefinitionMetadata true if the definition metadata to be included
 * @param includeDataMetadata       true if the data metadata to be included
 * @return table
 */
@RequestMapping(method = RequestMethod.GET, path = "/catalog/{catalog-name}/database/{database-name}/table/{table-name}")
@ApiOperation(position = 1, value = "Table information", notes = "Table information for the given table name under the given catalog and database")
@ApiResponses({ @ApiResponse(code = HttpURLConnection.HTTP_OK, message = "The table is returned"), @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = "The requested catalog or database or table cannot be located") })
@Override
public TableDto getTable(@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 name of the table", required = true) @PathVariable("table-name") final String tableName, @ApiParam(value = "Whether to include the core information about the table (location, serde, columns) in " + "the response. You would only say false here if you only want metadata.") @RequestParam(name = "includeInfo", defaultValue = "true") final boolean includeInfo, @ApiParam(value = "Whether to include user definition metadata information to the response") @RequestParam(name = "includeDefinitionMetadata", defaultValue = "true") final boolean includeDefinitionMetadata, @ApiParam(value = "Whether to include user data metadata information to the response") @RequestParam(name = "includeDataMetadata", defaultValue = "true") final boolean includeDataMetadata, @ApiParam(value = "Whether to include more info details to the response. This value is considered only if " + "includeInfo is true.") @RequestParam(name = "includeInfoDetails", defaultValue = "false") final boolean includeInfoDetails) {
    final Supplier<QualifiedName> qualifiedNameSupplier = () -> QualifiedName.ofTable(catalogName, databaseName, tableName);
    final QualifiedName name = this.requestWrapper.qualifyName(qualifiedNameSupplier);
    return this.requestWrapper.processRequest(name, "getTable", () -> {
        final Optional<TableDto> table = this.tableService.get(name, GetTableServiceParameters.builder().includeInfo(includeInfo).includeDefinitionMetadata(includeDefinitionMetadata).includeDataMetadata(includeDataMetadata).disableOnReadMetadataIntercetor(false).includeMetadataFromConnector(includeInfoDetails).useCache(true).build());
        final TableDto tableDto = table.orElseThrow(() -> new TableNotFoundException(name));
        // Set the name to whatever the request was for because
        // for aliases, this could've been set to the original name
        tableDto.setName(qualifiedNameSupplier.get());
        return tableDto;
    });
}
Also used : TableNotFoundException(com.netflix.metacat.common.server.connectors.exception.TableNotFoundException) QualifiedName(com.netflix.metacat.common.QualifiedName) TableDto(com.netflix.metacat.common.dto.TableDto) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 20 with TableNotFoundException

use of com.netflix.metacat.common.server.connectors.exception.TableNotFoundException in project metacat by Netflix.

the class PartitionServiceImpl method save.

/**
 * {@inheritDoc}
 */
@Override
public PartitionsSaveResponseDto save(final QualifiedName name, final PartitionsSaveRequestDto dto) {
    final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
    final ConnectorPartitionService service = connectorManager.getPartitionService(name);
    final List<PartitionDto> partitionDtos = dto.getPartitions();
    // If no partitions are passed, then return
    if (partitionDtos == null || partitionDtos.isEmpty()) {
        return new PartitionsSaveResponseDto();
    }
    if (!tableService.exists(name)) {
        throw new TableNotFoundException(name);
    }
    // optimization for metadata only updates (e.g. squirrel) , assuming only validate partitions are requested
    if (dto.getSaveMetadataOnly()) {
        return savePartitionMetadataOnly(metacatRequestContext, dto, name, partitionDtos);
    } else {
        return updatePartitions(service, metacatRequestContext, dto, name, partitionDtos);
    }
}
Also used : TableNotFoundException(com.netflix.metacat.common.server.connectors.exception.TableNotFoundException) MetacatRequestContext(com.netflix.metacat.common.MetacatRequestContext) PartitionDto(com.netflix.metacat.common.dto.PartitionDto) ConnectorPartitionService(com.netflix.metacat.common.server.connectors.ConnectorPartitionService) PartitionsSaveResponseDto(com.netflix.metacat.common.dto.PartitionsSaveResponseDto)

Aggregations

TableNotFoundException (com.netflix.metacat.common.server.connectors.exception.TableNotFoundException)40 QualifiedName (com.netflix.metacat.common.QualifiedName)17 ConnectorException (com.netflix.metacat.common.server.connectors.exception.ConnectorException)16 InvalidMetaException (com.netflix.metacat.common.server.connectors.exception.InvalidMetaException)15 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)12 NoSuchObjectException (org.apache.hadoop.hive.metastore.api.NoSuchObjectException)12 TException (org.apache.thrift.TException)12 MetacatRequestContext (com.netflix.metacat.common.MetacatRequestContext)11 TableInfo (com.netflix.metacat.common.server.connectors.model.TableInfo)11 Table (org.apache.hadoop.hive.metastore.api.Table)11 TableDto (com.netflix.metacat.common.dto.TableDto)10 InvalidObjectException (org.apache.hadoop.hive.metastore.api.InvalidObjectException)9 Partition (org.apache.hadoop.hive.metastore.api.Partition)9 Table (com.netflix.metacat.connector.s3.model.Table)8 MetacatUpdateTablePostEvent (com.netflix.metacat.common.server.events.MetacatUpdateTablePostEvent)7 Pageable (com.netflix.metacat.common.dto.Pageable)6 PartitionInfo (com.netflix.metacat.common.server.connectors.model.PartitionInfo)6 ConnectorPartitionService (com.netflix.metacat.common.server.connectors.ConnectorPartitionService)5 ArrayList (java.util.ArrayList)4 Strings (com.google.common.base.Strings)3