Search in sources :

Example 1 with MetacatUpdateTablePostEvent

use of com.netflix.metacat.common.server.events.MetacatUpdateTablePostEvent in project metacat by Netflix.

the class TagV1Resource method removeTableTags.

/**
     * {@inheritDoc}
     */
@Override
public void removeTableTags(final String catalogName, final String databaseName, final String tableName, final Boolean deleteAll, final Set<String> tags) {
    final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
    final QualifiedName name = requestWrapper.qualifyName(() -> QualifiedName.ofTable(catalogName, databaseName, tableName));
    requestWrapper.processRequest(name, "TagV1Resource.removeTableTags", () -> {
        if (!tableService.exists(name)) {
            // Delete tags if exists
            tagService.delete(name, false);
            throw new TableNotFoundException(name);
        }
        final TableDto oldTable = this.tableService.get(name, true).orElseThrow(IllegalStateException::new);
        tagService.removeTableTags(name, deleteAll, tags, true);
        final TableDto currentTable = this.tableService.get(name, true).orElseThrow(IllegalStateException::new);
        eventBus.postAsync(new MetacatUpdateTablePostEvent(name, metacatRequestContext, this, oldTable, currentTable));
        return null;
    });
}
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)

Example 2 with MetacatUpdateTablePostEvent

use of com.netflix.metacat.common.server.events.MetacatUpdateTablePostEvent in project metacat by Netflix.

the class TagV1Resource method setTableTags.

/**
     * {@inheritDoc}
     */
@Override
public Set<String> setTableTags(final String catalogName, final String databaseName, final String tableName, final Set<String> tags) {
    final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
    final QualifiedName name = requestWrapper.qualifyName(() -> QualifiedName.ofTable(catalogName, databaseName, tableName));
    return requestWrapper.processRequest(name, "TagV1Resource.setTableTags", () -> {
        if (!tableService.exists(name)) {
            throw new TableNotFoundException(name);
        }
        final TableDto oldTable = this.tableService.get(name, true).orElseThrow(IllegalStateException::new);
        final Set<String> result = tagService.setTableTags(name, tags, true);
        final TableDto currentTable = this.tableService.get(name, true).orElseThrow(IllegalStateException::new);
        eventBus.postAsync(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)

Example 3 with MetacatUpdateTablePostEvent

use of com.netflix.metacat.common.server.events.MetacatUpdateTablePostEvent 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 4 with MetacatUpdateTablePostEvent

use of com.netflix.metacat.common.server.events.MetacatUpdateTablePostEvent 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 5 with MetacatUpdateTablePostEvent

use of com.netflix.metacat.common.server.events.MetacatUpdateTablePostEvent in project metacat by Netflix.

the class IcebergTableEventHandler method metacatUpdateTableEventHandler.

/**
 * The update table event handler.
 *
 * @param event The event.
 */
@EventListener
public void metacatUpdateTableEventHandler(final MetacatUpdateIcebergTablePostEvent event) {
    final QualifiedName name = event.getName();
    final TableDto tableDto = event.getRequestTable();
    TableDto updatedDto = tableDto;
    try {
        updatedDto = tableService.get(name, GetTableServiceParameters.builder().disableOnReadMetadataIntercetor(false).includeInfo(true).includeDataMetadata(true).includeDefinitionMetadata(true).build()).orElse(tableDto);
    } catch (Exception ex) {
        handleException(name, "getTable", ex);
    }
    try {
        eventBus.post(new MetacatUpdateTablePostEvent(event.getName(), event.getRequestContext(), this, event.getOldTable(), updatedDto, updatedDto != tableDto));
    } catch (Exception ex) {
        handleException(name, "postEvent", ex);
    }
}
Also used : MetacatUpdateTablePostEvent(com.netflix.metacat.common.server.events.MetacatUpdateTablePostEvent) QualifiedName(com.netflix.metacat.common.QualifiedName) TableDto(com.netflix.metacat.common.dto.TableDto) EventListener(org.springframework.context.event.EventListener)

Aggregations

TableDto (com.netflix.metacat.common.dto.TableDto)9 MetacatUpdateTablePostEvent (com.netflix.metacat.common.server.events.MetacatUpdateTablePostEvent)9 MetacatRequestContext (com.netflix.metacat.common.MetacatRequestContext)7 QualifiedName (com.netflix.metacat.common.QualifiedName)7 TableNotFoundException (com.netflix.metacat.common.server.connectors.exception.TableNotFoundException)7 MetacatUpdateDatabasePostEvent (com.netflix.metacat.common.server.events.MetacatUpdateDatabasePostEvent)3 MetacatNotFoundException (com.netflix.metacat.common.exception.MetacatNotFoundException)2 DatabaseNotFoundException (com.netflix.metacat.common.server.connectors.exception.DatabaseNotFoundException)2 ApiOperation (io.swagger.annotations.ApiOperation)2 ApiResponses (io.swagger.annotations.ApiResponses)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)2 PartitionDto (com.netflix.metacat.common.dto.PartitionDto)1 PartitionsSaveResponseDto (com.netflix.metacat.common.dto.PartitionsSaveResponseDto)1 MetacatBadRequestException (com.netflix.metacat.common.exception.MetacatBadRequestException)1 MetacatNotSupportedException (com.netflix.metacat.common.exception.MetacatNotSupportedException)1 NotFoundException (com.netflix.metacat.common.server.connectors.exception.NotFoundException)1 MetacatSaveTablePartitionPostEvent (com.netflix.metacat.common.server.events.MetacatSaveTablePartitionPostEvent)1 MetacatUpdateIcebergTablePostEvent (com.netflix.metacat.common.server.events.MetacatUpdateIcebergTablePostEvent)1 MetacatUpdateMViewPostEvent (com.netflix.metacat.common.server.events.MetacatUpdateMViewPostEvent)1