use of com.netflix.metacat.common.server.connectors.exception.NotFoundException in project metacat by Netflix.
the class MViewServiceImpl method createAndSnapshotPartitions.
/**
* Creates the materialized view using the schema of the give table
* Assumes that the "franklinviews" database name already exists in the given catalog.
*/
@Override
public TableDto createAndSnapshotPartitions(@Nonnull final QualifiedName name, final boolean snapshot, final String filter) {
TableDto result;
// Get the table
log.info("Get the table {}", name);
final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
eventBus.postSync(new MetacatCreateMViewPreEvent(name, metacatRequestContext, this, snapshot, filter));
final Optional<TableDto> oTable = tableService.get(name, false);
if (oTable.isPresent()) {
final TableDto table = oTable.get();
final String viewName = createViewName(name);
final QualifiedName targetName = QualifiedName.ofTable(name.getCatalogName(), VIEW_DB_NAME, viewName);
// Get the view table if it exists
log.info("Check if the view table {} exists.", targetName);
Optional<TableDto> oViewTable = Optional.empty();
try {
oViewTable = tableService.get(targetName, false);
} catch (NotFoundException ignored) {
}
if (!oViewTable.isPresent()) {
log.info("Creating view {}.", targetName);
result = tableService.copy(table, targetName);
} else {
result = oViewTable.get();
}
if (snapshot) {
snapshotPartitions(name, filter);
}
eventBus.postAsync(new MetacatCreateMViewPostEvent(name, metacatRequestContext, this, result, snapshot, filter));
} else {
throw new TableNotFoundException(name);
}
return result;
}
use of com.netflix.metacat.common.server.connectors.exception.NotFoundException 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.server.connectors.exception.NotFoundException in project metacat by Netflix.
the class RequestWrapper method processRequest.
/**
* Request wrapper to to process request.
*
* @param name name
* @param resourceRequestName request name
* @param supplier supplier
* @param <R> response
* @return response of supplier
*/
public <R> R processRequest(final QualifiedName name, final String resourceRequestName, final Supplier<R> supplier) {
final long start = registry.clock().monotonicTime();
final Map<String, String> tags = new HashMap<String, String>(name.parts());
tags.put("request", resourceRequestName);
registry.counter(requestCounterId.withTags(tags)).increment();
try {
log.info("### Calling method: {} for {}", resourceRequestName, name);
return supplier.get();
} catch (UnsupportedOperationException e) {
log.error(e.getMessage(), e);
throw new MetacatNotSupportedException("Catalog does not support the operation");
} catch (DatabaseAlreadyExistsException | TableAlreadyExistsException | PartitionAlreadyExistsException e) {
log.error(e.getMessage(), e);
throw new MetacatAlreadyExistsException(e.getMessage());
} catch (NotFoundException | MetacatNotFoundException e) {
log.error(e.getMessage(), e);
throw new MetacatNotFoundException(String.format("Unable to locate for %s. Details: %s", name, e.getMessage()));
} catch (InvalidMetaException | IllegalArgumentException e) {
log.error(e.getMessage(), e);
throw new MetacatBadRequestException(String.format("%s.%s", e.getMessage(), e.getCause() == null ? "" : e.getCause().getMessage()));
} catch (ConnectorException e) {
final String message = String.format("%s.%s -- %s failed for %s", e.getMessage(), e.getCause() == null ? "" : e.getCause().getMessage(), resourceRequestName, name);
log.error(message, e);
registry.counter(requestFaillureCounterId.withTags(tags)).increment();
throw new MetacatException(message, Response.Status.INTERNAL_SERVER_ERROR, e);
} catch (UserMetadataServiceException e) {
final String message = String.format("%s.%s -- %s usermetadata operation failed for %s", e.getMessage(), e.getCause() == null ? "" : e.getCause().getMessage(), resourceRequestName, name);
throw new MetacatUserMetadataException(message);
} catch (Exception e) {
registry.counter(requestFaillureCounterId.withTags(tags)).increment();
final String message = String.format("%s.%s -- %s failed for %s", e.getMessage(), e.getCause() == null ? "" : e.getCause().getMessage(), resourceRequestName, name);
log.error(message, e);
throw new MetacatException(message, Response.Status.INTERNAL_SERVER_ERROR, e);
} finally {
final long duration = registry.clock().monotonicTime() - start;
log.info("### Time taken to complete {} is {} ms", resourceRequestName, duration);
this.registry.timer(requestTimerId.withTags(tags)).record(duration, TimeUnit.MILLISECONDS);
}
}
use of com.netflix.metacat.common.server.connectors.exception.NotFoundException in project metacat by Netflix.
the class MetadataV1Resource method deleteDefinitionMetadata.
/**
* {@inheritDoc}
*/
@Override
public void deleteDefinitionMetadata(final QualifiedName name, final Boolean force) {
final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
requestWrapper.processRequest("deleteDefinitionMetadata", () -> {
final MetacatService service = helper.getService(name);
BaseDto dto = null;
try {
dto = service.get(name);
} catch (NotFoundException ignored) {
}
if ((force || dto == null) && !"rds".equalsIgnoreCase(name.getCatalogName())) {
helper.postPreUpdateEvent(name, metacatRequestContext, dto);
userMetadataService.deleteDefinitionMetadatas(Lists.newArrayList(name));
if (dto instanceof HasDefinitionMetadata) {
((HasDefinitionMetadata) dto).setDefinitionMetadata(null);
}
final BaseDto newDto = service.get(name);
helper.postPostUpdateEvent(name, metacatRequestContext, dto, newDto);
}
return null;
});
}
Aggregations