Search in sources :

Example 1 with MetacatUpdateTablePreEvent

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

the class MetacatServiceHelper method postPreUpdateEvent.

/**
     * Calls the right method of the event bus for the given qualified name.
     *
     * @param name                  name
     * @param metacatRequestContext context
     * @param dto                   dto
     */
public void postPreUpdateEvent(final QualifiedName name, final MetacatRequestContext metacatRequestContext, final BaseDto dto) {
    if (name.isPartitionDefinition()) {
        final PartitionsSaveRequestDto partitionsSaveRequestDto = new PartitionsSaveRequestDto();
        if (dto != null) {
            partitionsSaveRequestDto.setPartitions(ImmutableList.of((PartitionDto) dto));
        }
        this.eventBus.postSync(new MetacatSaveTablePartitionPreEvent(name, metacatRequestContext, this, partitionsSaveRequestDto));
    } else if (name.isTableDefinition()) {
        this.eventBus.postSync(new MetacatUpdateTablePreEvent(name, metacatRequestContext, this, (TableDto) dto, (TableDto) dto));
    } else if (name.isDatabaseDefinition()) {
        eventBus.postSync(new MetacatUpdateDatabasePreEvent(name, metacatRequestContext, this));
    } else {
        throw new IllegalArgumentException(String.format("Invalid name %s", name));
    }
}
Also used : PartitionsSaveRequestDto(com.netflix.metacat.common.dto.PartitionsSaveRequestDto) MetacatUpdateDatabasePreEvent(com.netflix.metacat.common.server.events.MetacatUpdateDatabasePreEvent) MetacatSaveTablePartitionPreEvent(com.netflix.metacat.common.server.events.MetacatSaveTablePartitionPreEvent) PartitionDto(com.netflix.metacat.common.dto.PartitionDto) MetacatUpdateTablePreEvent(com.netflix.metacat.common.server.events.MetacatUpdateTablePreEvent)

Example 2 with MetacatUpdateTablePreEvent

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

the class TableServiceImpl method updateAndReturn.

@Override
public TableDto updateAndReturn(@Nonnull final QualifiedName name, @Nonnull final TableDto tableDto) {
    validate(name);
    final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
    final ConnectorTableService service = connectorManager.getTableService(name.getCatalogName());
    final TableDto oldTable = get(name, true).orElseThrow(() -> new TableNotFoundException(name));
    eventBus.postSync(new MetacatUpdateTablePreEvent(name, metacatRequestContext, this, oldTable, tableDto));
    //Ignore if the operation is not supported, so that we can at least go ahead and save the user metadata
    if (isTableInfoProvided(tableDto)) {
        try {
            log.info("Updating table {}", name);
            final ConnectorContext connectorContext = converterUtil.toConnectorContext(metacatRequestContext);
            service.update(connectorContext, converterUtil.fromTableDto(tableDto));
        } catch (UnsupportedOperationException ignored) {
        }
    }
    // Merge in metadata if the user sent any
    if (tableDto.getDataMetadata() != null || tableDto.getDefinitionMetadata() != null) {
        log.info("Saving user metadata for table {}", name);
        userMetadataService.saveMetadata(metacatRequestContext.getUserName(), tableDto, true);
    }
    final TableDto updatedDto = get(name, true).orElseThrow(() -> new IllegalStateException("should exist"));
    eventBus.postAsync(new MetacatUpdateTablePostEvent(name, metacatRequestContext, this, oldTable, updatedDto));
    return updatedDto;
}
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) ConnectorTableService(com.netflix.metacat.common.server.connectors.ConnectorTableService) ConnectorContext(com.netflix.metacat.common.server.connectors.ConnectorContext) TableDto(com.netflix.metacat.common.dto.TableDto) MetacatUpdateTablePreEvent(com.netflix.metacat.common.server.events.MetacatUpdateTablePreEvent)

Aggregations

MetacatUpdateTablePreEvent (com.netflix.metacat.common.server.events.MetacatUpdateTablePreEvent)2 MetacatRequestContext (com.netflix.metacat.common.MetacatRequestContext)1 PartitionDto (com.netflix.metacat.common.dto.PartitionDto)1 PartitionsSaveRequestDto (com.netflix.metacat.common.dto.PartitionsSaveRequestDto)1 TableDto (com.netflix.metacat.common.dto.TableDto)1 ConnectorContext (com.netflix.metacat.common.server.connectors.ConnectorContext)1 ConnectorTableService (com.netflix.metacat.common.server.connectors.ConnectorTableService)1 TableNotFoundException (com.netflix.metacat.common.server.connectors.exception.TableNotFoundException)1 MetacatSaveTablePartitionPreEvent (com.netflix.metacat.common.server.events.MetacatSaveTablePartitionPreEvent)1 MetacatUpdateDatabasePreEvent (com.netflix.metacat.common.server.events.MetacatUpdateDatabasePreEvent)1 MetacatUpdateTablePostEvent (com.netflix.metacat.common.server.events.MetacatUpdateTablePostEvent)1