use of com.netflix.metacat.common.MetacatRequestContext in project metacat by Netflix.
the class TableServiceImpl method get.
@Override
public Optional<TableDto> get(@Nonnull final QualifiedName name, final boolean includeInfo, final boolean includeDefinitionMetadata, final boolean includeDataMetadata) {
validate(name);
final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
final ConnectorContext connectorContext = converterUtil.toConnectorContext(metacatRequestContext);
final ConnectorTableService service = connectorManager.getTableService(name.getCatalogName());
final TableDto table;
if (includeInfo) {
try {
table = converterUtil.toTableDto(service.get(connectorContext, name));
} catch (NotFoundException ignored) {
return Optional.empty();
}
} else {
table = new TableDto();
table.setName(name);
}
if (includeDefinitionMetadata) {
final Optional<ObjectNode> definitionMetadata = userMetadataService.getDefinitionMetadata(name);
if (definitionMetadata.isPresent()) {
table.setDefinitionMetadata(definitionMetadata.get());
}
}
if (includeDataMetadata) {
TableDto dto = table;
if (!includeInfo) {
try {
dto = converterUtil.toTableDto(service.get(connectorContext, name));
} catch (NotFoundException ignored) {
}
}
if (dto != null && dto.getSerde() != null) {
final Optional<ObjectNode> dataMetadata = userMetadataService.getDataMetadata(dto.getSerde().getUri());
if (dataMetadata.isPresent()) {
table.setDataMetadata(dataMetadata.get());
}
}
}
return Optional.of(table);
}
use of com.netflix.metacat.common.MetacatRequestContext in project metacat by Netflix.
the class TableServiceImpl method getQualifiedNames.
@Override
public List<QualifiedName> getQualifiedNames(final String uri, final boolean prefixSearch) {
final List<QualifiedName> result = Lists.newArrayList();
connectorManager.getCatalogs().keySet().forEach(catalogName -> {
final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
final ConnectorTableService service = connectorManager.getTableService(catalogName);
final ConnectorContext connectorContext = converterUtil.toConnectorContext(metacatRequestContext);
try {
final Map<String, List<QualifiedName>> names = service.getTableNames(connectorContext, Lists.newArrayList(uri), prefixSearch);
final List<QualifiedName> qualifiedNames = names.values().stream().flatMap(Collection::stream).collect(Collectors.toList());
result.addAll(qualifiedNames);
} catch (final UnsupportedOperationException uoe) {
log.debug("Catalog {} doesn't support getting table names by URI. Skipping", catalogName);
}
});
return result;
}
use of com.netflix.metacat.common.MetacatRequestContext in project metacat by Netflix.
the class MetadataService method processDeletedDataMetadata.
/**
* Deletes all the data metadata marked for deletion.
*/
public void processDeletedDataMetadata() {
// Get the data metadata that were marked deleted a number of days back
// Check if the uri is being used
// If uri is not used then delete the entry from data_metadata
log.info("Start deleting data metadata");
try {
final DateTime priorTo = DateTime.now().minusDays(config.getDataMetadataDeleteMarkerLifetimeInDays());
final int limit = 100000;
final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
while (true) {
final List<String> urisToDelete = userMetadataService.getDeletedDataMetadataUris(priorTo.toDate(), 0, limit);
log.info("Count of deleted marked data metadata: {}", urisToDelete.size());
if (urisToDelete.size() > 0) {
final List<String> uris = urisToDelete.parallelStream().filter(uri -> !uri.contains("=")).map(uri -> userMetadataService.getDescendantDataUris(uri)).flatMap(Collection::stream).collect(Collectors.toList());
uris.addAll(urisToDelete);
log.info("Count of deleted marked data metadata (including descendants) : {}", uris.size());
final List<List<String>> subListsUris = Lists.partition(uris, 1000);
subListsUris.parallelStream().forEach(subUris -> {
MetacatContextManager.setContext(metacatRequestContext);
final Map<String, List<QualifiedName>> uriPartitionQualifiedNames = partitionService.getQualifiedNames(subUris, false);
final Map<String, List<QualifiedName>> uriTableQualifiedNames = tableService.getQualifiedNames(subUris, false);
final Map<String, List<QualifiedName>> uriQualifiedNames = Stream.concat(uriPartitionQualifiedNames.entrySet().stream(), uriTableQualifiedNames.entrySet().stream()).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (a, b) -> {
final List<QualifiedName> subNames = Lists.newArrayList(a);
subNames.addAll(b);
return subNames;
}));
final List<String> canDeleteMetadataForUris = subUris.parallelStream().filter(s -> !Strings.isNullOrEmpty(s)).filter(s -> uriQualifiedNames.get(s) == null || uriQualifiedNames.get(s).size() == 0).collect(Collectors.toList());
log.info("Start deleting data metadata: {}", canDeleteMetadataForUris.size());
userMetadataService.deleteDataMetadatas(canDeleteMetadataForUris);
userMetadataService.deleteDataMetadataDeletes(subUris);
MetacatContextManager.removeContext();
});
}
if (urisToDelete.size() < limit) {
break;
}
}
} catch (Exception e) {
registry.counter(Metrics.CounterDeleteMetaData.name()).increment();
log.warn("Failed deleting data metadata", e);
}
log.info("End deleting data metadata");
}
use of com.netflix.metacat.common.MetacatRequestContext in project metacat by Netflix.
the class DatabaseServiceImpl method delete.
@Override
public void delete(@Nonnull final QualifiedName name) {
validate(name);
log.info("Dropping schema {}", name);
final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
final DatabaseDto dto = get(name, true);
eventBus.postSync(new MetacatDeleteDatabasePreEvent(name, metacatRequestContext, this, dto));
final ConnectorContext connectorContext = converterUtil.toConnectorContext(metacatRequestContext);
connectorManager.getDatabaseService(name.getCatalogName()).delete(connectorContext, name);
// Delete definition metadata if it exists
if (userMetadataService.getDefinitionMetadata(name).isPresent()) {
log.info("Deleting user metadata for schema {}", name);
userMetadataService.deleteDefinitionMetadatas(ImmutableList.of(name));
}
eventBus.postAsync(new MetacatDeleteDatabasePostEvent(name, metacatRequestContext, this, dto));
}
use of com.netflix.metacat.common.MetacatRequestContext in project metacat by Netflix.
the class DatabaseServiceImpl method create.
@Override
public DatabaseDto create(@Nonnull final QualifiedName name, @Nonnull final DatabaseDto dto) {
validate(name);
log.info("Creating schema {}", name);
final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
eventBus.postSync(new MetacatCreateDatabasePreEvent(name, metacatRequestContext, this));
final ConnectorContext connectorContext = converterUtil.toConnectorContext(metacatRequestContext);
connectorManager.getDatabaseService(name.getCatalogName()).create(connectorContext, converterUtil.fromDatabaseDto(dto));
if (dto.getDefinitionMetadata() != null) {
log.info("Saving user metadata for schema {}", name);
userMetadataService.saveDefinitionMetadata(name, metacatRequestContext.getUserName(), Optional.of(dto.getDefinitionMetadata()), true);
}
final DatabaseDto createdDto = get(name, dto.getDefinitionMetadata() != null);
eventBus.postAsync(new MetacatCreateDatabasePostEvent(name, metacatRequestContext, this, createdDto));
return createdDto;
}
Aggregations