Search in sources :

Example 96 with QualifiedName

use of com.netflix.metacat.common.QualifiedName in project metacat by Netflix.

the class CassandraConnectorDatabaseService method list.

/**
     * {@inheritDoc}
     */
@Override
public List<DatabaseInfo> list(@Nonnull @NonNull final ConnectorContext context, @Nonnull @NonNull final QualifiedName name, @Nullable final QualifiedName prefix, @Nullable final Sort sort, @Nullable final Pageable pageable) {
    log.debug("Attempting to list keyspaces for request {}", context);
    final ImmutableList.Builder<DatabaseInfo> keyspacesBuilder = ImmutableList.builder();
    for (final QualifiedName keyspace : this.listNames(context, name, prefix, sort, pageable)) {
        keyspacesBuilder.add(DatabaseInfo.builder().name(keyspace).build());
    }
    final List<DatabaseInfo> keyspaces = keyspacesBuilder.build();
    log.debug("Successfully listed {} keyspaces for request {}", keyspaces.size(), context);
    return keyspaces;
}
Also used : DatabaseInfo(com.netflix.metacat.common.server.connectors.model.DatabaseInfo) ImmutableList(com.google.common.collect.ImmutableList) QualifiedName(com.netflix.metacat.common.QualifiedName)

Example 97 with QualifiedName

use of com.netflix.metacat.common.QualifiedName in project metacat by Netflix.

the class PartitionController method savePartitions.

/**
 * Add/update partitions to the given table.
 *
 * @param catalogName              catalog name
 * @param databaseName             database name
 * @param tableName                table name
 * @param partitionsSaveRequestDto partition request containing the list of partitions to be added/updated
 * @return Response with the number of partitions added/updated
 */
@RequestMapping(method = RequestMethod.POST, path = "/catalog/{catalog-name}/database/{database-name}/table/{table-name}", consumes = MediaType.APPLICATION_JSON_VALUE)
@ResponseStatus(HttpStatus.CREATED)
@ApiOperation(position = 5, value = "Add/update partitions to the given table", notes = "Add/update partitions to the given table")
@ApiResponses({ @ApiResponse(code = HttpURLConnection.HTTP_CREATED, message = "The partitions were successfully saved"), @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = "The requested catalog or database or table cannot be located") })
@Override
public PartitionsSaveResponseDto savePartitions(@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 = "Request containing the list of partitions", required = true) @RequestBody final PartitionsSaveRequestDto partitionsSaveRequestDto) {
    final QualifiedName name = QualifiedName.ofTable(catalogName, databaseName, tableName);
    return this.requestWrapper.processRequest(name, "saveTablePartition", () -> {
        final PartitionsSaveResponseDto result;
        if (partitionsSaveRequestDto.getPartitions() == null || partitionsSaveRequestDto.getPartitions().isEmpty()) {
            result = new PartitionsSaveResponseDto();
        } else {
            result = this.partitionService.save(name, partitionsSaveRequestDto);
            // This metadata is actually for the table, if it is present update that
            if (partitionsSaveRequestDto.getDefinitionMetadata() != null || partitionsSaveRequestDto.getDataMetadata() != null) {
                final TableDto dto = new TableDto();
                dto.setName(name);
                dto.setDefinitionMetadata(partitionsSaveRequestDto.getDefinitionMetadata());
                dto.setDataMetadata(partitionsSaveRequestDto.getDataMetadata());
                this.v1.updateTable(catalogName, databaseName, tableName, dto);
            }
        }
        return result;
    });
}
Also used : QualifiedName(com.netflix.metacat.common.QualifiedName) TableDto(com.netflix.metacat.common.dto.TableDto) PartitionsSaveResponseDto(com.netflix.metacat.common.dto.PartitionsSaveResponseDto) 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 98 with QualifiedName

use of com.netflix.metacat.common.QualifiedName in project metacat by Netflix.

the class PartitionController method deletePartitions.

/**
 * Delete named partitions from a table.
 *
 * @param catalogName  catalog name
 * @param databaseName database name
 * @param tableName    table name
 * @param partitionIds lis of partition names
 */
@RequestMapping(method = RequestMethod.DELETE, path = "/catalog/{catalog-name}/database/{database-name}/table/{table-name}", consumes = MediaType.APPLICATION_JSON_VALUE)
@ResponseStatus(HttpStatus.NO_CONTENT)
@ApiOperation(value = "Delete named partitions from a table", notes = "List of partitions names of the given table name under the given catalog and database")
@ApiResponses({ @ApiResponse(code = HttpURLConnection.HTTP_OK, message = "The partitions were deleted successfully"), @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = "The requested catalog or database or table cannot be located"), @ApiResponse(code = HttpURLConnection.HTTP_BAD_REQUEST, message = "The list of partitionNames is not present") })
@Override
public void deletePartitions(@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 = "partitionId of the partitions to be deleted from this table", required = true) @RequestBody final List<String> partitionIds) {
    final QualifiedName name = this.requestWrapper.qualifyName(() -> QualifiedName.ofTable(catalogName, databaseName, tableName));
    this.requestWrapper.processRequest(name, "deleteTablePartition", () -> {
        if (partitionIds.isEmpty()) {
            throw new IllegalArgumentException("partitionIds are required");
        }
        this.partitionService.delete(name, partitionIds);
        return null;
    });
}
Also used : QualifiedName(com.netflix.metacat.common.QualifiedName) 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 99 with QualifiedName

use of com.netflix.metacat.common.QualifiedName in project metacat by Netflix.

the class TagController method removeTableTags.

/**
 * Remove the tags from the given table.
 *
 * @param catalogName  catalog name
 * @param databaseName database name
 * @param tableName    table name
 * @param deleteAll    True if all tags need to be removed
 * @param tags         Tags to be removed from the given table
 */
@RequestMapping(method = RequestMethod.DELETE, path = "/catalog/{catalog-name}/database/{database-name}/table/{table-name}", consumes = MediaType.APPLICATION_JSON_VALUE)
@ResponseStatus(HttpStatus.NO_CONTENT)
@ApiOperation(position = 4, value = "Remove the tags from the given table", notes = "Remove the tags from the given table")
@ApiResponses({ @ApiResponse(code = HttpURLConnection.HTTP_NO_CONTENT, message = "The tags were successfully deleted from the table"), @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = "The requested catalog or database or table cannot be located") })
public void removeTableTags(@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 = "True if all tags need to be removed") @RequestParam(name = "all", defaultValue = "false") final boolean deleteAll, @ApiParam(value = "Tags to be removed from the given table") @Nullable @RequestBody(required = false) final Set<String> tags) {
    final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
    final QualifiedName name = this.requestWrapper.qualifyName(() -> QualifiedName.ofTable(catalogName, databaseName, tableName));
    this.requestWrapper.processRequest(name, "TagV1Resource.removeTableTags", () -> {
        // TODO: Business logic in API tier...
        if (!this.tableService.exists(name)) {
            // Delete tags if exists
            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.removeTableTags(name, deleteAll, 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.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) 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 100 with QualifiedName

use of com.netflix.metacat.common.QualifiedName in project metacat by Netflix.

the class MViewServiceImpl method deletePartitions.

/**
 * {@inheritDoc}
 */
@Override
public void deletePartitions(final QualifiedName name, final List<String> partitionIds) {
    final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
    final PartitionsSaveRequestDto dto = new PartitionsSaveRequestDto();
    dto.setPartitionIdsForDeletes(partitionIds);
    eventBus.postSync(new MetacatDeleteMViewPartitionPreEvent(name, metacatRequestContext, this, dto));
    final QualifiedName viewQName = QualifiedName.ofTable(name.getCatalogName(), VIEW_DB_NAME, createViewName(name));
    partitionService.delete(viewQName, partitionIds);
    eventBus.postAsync(new MetacatDeleteMViewPartitionPostEvent(name, metacatRequestContext, this, partitionIds));
}
Also used : PartitionsSaveRequestDto(com.netflix.metacat.common.dto.PartitionsSaveRequestDto) MetacatRequestContext(com.netflix.metacat.common.MetacatRequestContext) MetacatDeleteMViewPartitionPreEvent(com.netflix.metacat.common.server.events.MetacatDeleteMViewPartitionPreEvent) MetacatDeleteMViewPartitionPostEvent(com.netflix.metacat.common.server.events.MetacatDeleteMViewPartitionPostEvent) QualifiedName(com.netflix.metacat.common.QualifiedName)

Aggregations

QualifiedName (com.netflix.metacat.common.QualifiedName)144 List (java.util.List)52 Lists (com.google.common.collect.Lists)44 Collectors (java.util.stream.Collectors)41 Map (java.util.Map)38 Slf4j (lombok.extern.slf4j.Slf4j)36 Strings (com.google.common.base.Strings)35 Nullable (javax.annotation.Nullable)33 Pageable (com.netflix.metacat.common.dto.Pageable)29 Sort (com.netflix.metacat.common.dto.Sort)29 Nonnull (javax.annotation.Nonnull)29 MetacatRequestContext (com.netflix.metacat.common.MetacatRequestContext)28 TableDto (com.netflix.metacat.common.dto.TableDto)27 Maps (com.google.common.collect.Maps)25 ConnectorException (com.netflix.metacat.common.server.connectors.exception.ConnectorException)25 DatabaseNotFoundException (com.netflix.metacat.common.server.connectors.exception.DatabaseNotFoundException)24 TableNotFoundException (com.netflix.metacat.common.server.connectors.exception.TableNotFoundException)24 Optional (java.util.Optional)22 Registry (com.netflix.spectator.api.Registry)21 Set (java.util.Set)21