use of com.netflix.metacat.common.MetacatRequestContext in project metacat by Netflix.
the class DatabaseServiceImpl method delete.
/**
* {@inheritDoc}
*/
@Override
public void delete(final QualifiedName name) {
validate(name);
final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
this.authorizationService.checkPermission(metacatRequestContext.getUserName(), name, MetacatOperation.DELETE);
log.info("Dropping schema {}", name);
final DatabaseDto dto = get(name, GetDatabaseServiceParameters.builder().disableOnReadMetadataIntercetor(false).includeUserMetadata(true).includeTableNames(true).build());
eventBus.post(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.post(new MetacatDeleteDatabasePostEvent(name, metacatRequestContext, this, dto));
}
use of com.netflix.metacat.common.MetacatRequestContext in project metacat by Netflix.
the class PartitionServiceImpl method delete.
/**
* {@inheritDoc}
*/
@Override
public void delete(final QualifiedName name, final List<String> partitionIds) {
validateDeletes(name, partitionIds != null ? partitionIds.size() : 0);
final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
registry.distributionSummary(this.partitionDeleteDistSummary.withTags(name.parts())).record(partitionIds.size());
if (!tableService.exists(name)) {
throw new TableNotFoundException(name);
}
if (!partitionIds.isEmpty()) {
final PartitionsSaveRequestDto dto = new PartitionsSaveRequestDto();
dto.setPartitionIdsForDeletes(partitionIds);
eventBus.post(new MetacatDeleteTablePartitionPreEvent(name, metacatRequestContext, this, dto));
final ConnectorPartitionService service = connectorManager.getPartitionService(name);
// Get the partitions before calling delete
final GetPartitionsRequestDto requestDto = new GetPartitionsRequestDto(null, partitionIds, false, true);
final ConnectorRequestContext connectorRequestContext = converterUtil.toConnectorContext(metacatRequestContext);
final List<PartitionInfo> partitionInfos = service.getPartitions(connectorRequestContext, name, converterUtil.toPartitionListRequest(requestDto, null, null), this.getTableInfo(name));
List<HasMetadata> partitions = Lists.newArrayList();
List<PartitionDto> partitionDtos = Lists.newArrayList();
if (partitionInfos != null) {
partitionDtos = partitionInfos.stream().map(converterUtil::toPartitionDto).collect(Collectors.toList());
partitions = new ArrayList<>(partitions);
}
log.info("Deleting partitions with names {} for {}", partitionIds, name);
service.deletePartitions(connectorRequestContext, name, partitionIds, this.getTableInfo(name));
// delete metadata
log.info("Deleting user metadata for partitions with names {} for {}", partitionIds, name);
if (!partitions.isEmpty()) {
deleteMetadatas(metacatRequestContext.getUserName(), partitions);
}
eventBus.post(new MetacatDeleteTablePartitionPostEvent(name, metacatRequestContext, this, partitionDtos));
}
}
use of com.netflix.metacat.common.MetacatRequestContext in project metacat by Netflix.
the class PartitionServiceImpl method getQualifiedNames.
/**
* {@inheritDoc}
*/
@Override
public Map<String, List<QualifiedName>> getQualifiedNames(final List<String> uris, final boolean prefixSearch) {
final Map<String, List<QualifiedName>> result = Maps.newConcurrentMap();
final List<ListenableFuture<Void>> futures = Lists.newArrayList();
final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
connectorManager.getPartitionServices().forEach(service -> {
futures.add(threadServiceManager.getExecutor().submit(() -> {
final ConnectorRequestContext connectorRequestContext = converterUtil.toConnectorContext(metacatRequestContext);
try {
final Map<String, List<QualifiedName>> partitionNames = service.getPartitionNames(connectorRequestContext, uris, prefixSearch);
partitionNames.forEach((uri, subPartitionNames) -> {
final List<QualifiedName> existingPartitionNames = result.get(uri);
if (existingPartitionNames == null) {
result.put(uri, subPartitionNames);
} else {
existingPartitionNames.addAll(subPartitionNames);
}
});
} catch (final UnsupportedOperationException uoe) {
log.debug("Partition service doesn't support getPartitionNames. Ignoring.");
}
return null;
}));
});
try {
Futures.allAsList(futures).get(1, TimeUnit.HOURS);
} catch (Exception e) {
Throwables.propagate(e);
}
return result;
}
use of com.netflix.metacat.common.MetacatRequestContext in project metacat by Netflix.
the class MetadataController method deleteDefinitionMetadata.
/**
* Delete the definition metadata for the given name.
*
* @param name Name of definition metadata to be deleted
* @param force If true, deletes the metadata without checking if the database/table/partition exists
*/
@RequestMapping(method = RequestMethod.DELETE, path = "/definition")
@ResponseStatus(HttpStatus.NO_CONTENT)
@ApiOperation(position = 4, value = "Deletes the given definition metadata")
public void deleteDefinitionMetadata(@ApiParam(value = "Name of definition metadata to be deleted", required = true) @RequestParam(name = "name") final String name, @ApiParam(value = "If true, deletes the metadata without checking if the database/table/partition exists") @RequestParam(name = "force", defaultValue = "false") final boolean force) {
final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
requestWrapper.processRequest("deleteDefinitionMetadata", () -> {
metadataService.deleteDefinitionMetadata(QualifiedName.fromString(name), force, metacatRequestContext);
return null;
});
}
use of com.netflix.metacat.common.MetacatRequestContext in project metacat by Netflix.
the class TagController method setResourceTags.
private Set<String> setResourceTags(@NonNull final TagCreateRequestDto tagCreateRequestDto) {
final QualifiedName name = tagCreateRequestDto.getName();
final Set<String> tags = new HashSet<>(tagCreateRequestDto.getTags());
final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
Set<String> result = new HashSet<>();
switch(name.getType()) {
case CATALOG:
// catalog service will throw exception if not found
this.catalogService.get(name, GetCatalogServiceParameters.builder().includeDatabaseNames(false).includeUserMetadata(false).build());
return this.tagService.setTags(name, tags, true);
case DATABASE:
if (!this.databaseService.exists(name)) {
throw new DatabaseNotFoundException(name);
}
result = this.tagService.setTags(name, tags, true);
this.eventBus.post(new MetacatUpdateDatabasePostEvent(name, metacatRequestContext, this));
return result;
case TABLE:
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);
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;
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()) {
result = this.tagService.setTags(name, tags, 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())));
return result;
}
break;
default:
throw new MetacatNotFoundException("Unsupported qualifiedName type {}" + name);
}
return result;
}
Aggregations