use of com.netflix.metacat.common.server.connectors.exception.DatabaseAlreadyExistsException in project metacat by Netflix.
the class S3ConnectorDatabaseService method rename.
@Override
public void rename(@Nonnull final ConnectorContext context, @Nonnull final QualifiedName oldName, @Nonnull final QualifiedName newName) {
log.debug("Start: Rename database {} with {}", oldName, newName);
final String newDatabaseName = newName.getDatabaseName();
Preconditions.checkNotNull(newDatabaseName, "Database name is null");
final Database oldDatabase = databaseDao.getBySourceDatabaseName(catalogName, oldName.getDatabaseName());
if (oldDatabase == null) {
throw new DatabaseNotFoundException(oldName);
}
if (databaseDao.getBySourceDatabaseName(catalogName, newDatabaseName) != null) {
throw new DatabaseAlreadyExistsException(newName);
}
oldDatabase.setName(newDatabaseName);
databaseDao.save(oldDatabase);
log.debug("End: Rename database {} with {}", oldName, newName);
}
use of com.netflix.metacat.common.server.connectors.exception.DatabaseAlreadyExistsException in project metacat by Netflix.
the class S3ConnectorDatabaseService method create.
@Override
public void create(@Nonnull final ConnectorRequestContext context, @Nonnull final DatabaseInfo databaseInfo) {
final String databaseName = databaseInfo.getName().getDatabaseName();
log.debug("Start: Create database {}", databaseInfo.getName());
Preconditions.checkNotNull(databaseName, "Database name is null");
if (databaseDao.getBySourceDatabaseName(catalogName, databaseName) != null) {
log.warn("Database {} already exists", databaseName);
throw new DatabaseAlreadyExistsException(databaseInfo.getName());
}
final Database database = new Database();
database.setName(databaseName);
database.setSource(sourceDao.getByName(catalogName));
databaseDao.save(database);
log.debug("End: Create database {}", databaseInfo.getName());
}
use of com.netflix.metacat.common.server.connectors.exception.DatabaseAlreadyExistsException in project metacat by Netflix.
the class S3ConnectorDatabaseService method rename.
@Override
public void rename(@Nonnull final ConnectorRequestContext context, @Nonnull final QualifiedName oldName, @Nonnull final QualifiedName newName) {
log.debug("Start: Rename database {} with {}", oldName, newName);
final String newDatabaseName = newName.getDatabaseName();
Preconditions.checkNotNull(newDatabaseName, "Database name is null");
final Database oldDatabase = databaseDao.getBySourceDatabaseName(catalogName, oldName.getDatabaseName());
if (oldDatabase == null) {
throw new DatabaseNotFoundException(oldName);
}
if (databaseDao.getBySourceDatabaseName(catalogName, newDatabaseName) != null) {
throw new DatabaseAlreadyExistsException(newName);
}
oldDatabase.setName(newDatabaseName);
databaseDao.save(oldDatabase);
log.debug("End: Rename database {} with {}", oldName, newName);
}
use of com.netflix.metacat.common.server.connectors.exception.DatabaseAlreadyExistsException in project metacat by Netflix.
the class PolarisConnectorDatabaseService method create.
/**
* {@inheritDoc}.
*/
@Override
public void create(final ConnectorRequestContext context, final DatabaseInfo databaseInfo) {
final QualifiedName name = databaseInfo.getName();
// check exists then create in non-transactional optimistic manner
if (exists(context, name)) {
throw new DatabaseAlreadyExistsException(name);
}
try {
final String location = databaseInfo.getUri() == null ? this.defaultLocationPrefix + name.getDatabaseName() + DEFAULT_LOCATION_SUFFIX : databaseInfo.getUri();
this.polarisStoreService.createDatabase(name.getDatabaseName(), location);
} catch (DataIntegrityViolationException exception) {
throw new InvalidMetaException(name, exception);
} catch (Exception exception) {
throw new ConnectorException(String.format("Failed creating polaris database %s", name), exception);
}
}
use of com.netflix.metacat.common.server.connectors.exception.DatabaseAlreadyExistsException in project metacat by Netflix.
the class RequestWrapper method processRequest.
/**
* Request wrapper to to process request.
*
* @param name name
* @param resourceRequestName request name
* @param requestTags tags that needs to be added to the registry
* @param supplier supplier
* @param <R> response
* @return response of supplier
*/
public <R> R processRequest(final QualifiedName name, final String resourceRequestName, final Map<String, String> requestTags, final Supplier<R> supplier) {
final long start = registry.clock().wallTime();
final Map<String, String> tags = new HashMap<>(name.parts());
if (requestTags != null) {
tags.putAll(requestTags);
}
tags.put("request", resourceRequestName);
tags.put("scheme", MetacatContextManager.getContext().getScheme());
registry.counter(requestCounterId.withTags(tags)).increment();
try {
// check rate limit in try-catch block in case ratelimiter throws exception.
// those exceptions can be tracked correctly, by the existing finally block that logs metrics.
checkRequestRateLimit(name, resourceRequestName, tags);
log.info("### Calling method: {} for {}", resourceRequestName, name);
return supplier.get();
} catch (UnsupportedOperationException e) {
collectRequestExceptionMetrics(tags, e.getClass().getSimpleName());
log.error(e.getMessage(), e);
throw new MetacatNotSupportedException("Catalog does not support the operation. " + e.getMessage());
} catch (DatabaseAlreadyExistsException | TableAlreadyExistsException | PartitionAlreadyExistsException e) {
collectRequestExceptionMetrics(tags, e.getClass().getSimpleName());
log.error(e.getMessage(), e);
throw new MetacatAlreadyExistsException(e.getMessage());
} catch (NotFoundException | MetacatNotFoundException e) {
collectRequestExceptionMetrics(tags, e.getClass().getSimpleName());
log.error(e.getMessage(), e);
throw new MetacatNotFoundException(String.format("Unable to locate for %s. Details: %s", name, e.getMessage()));
} catch (InvalidMetaException | IllegalArgumentException e) {
collectRequestExceptionMetrics(tags, e.getClass().getSimpleName());
log.error(e.getMessage(), e);
throw new MetacatBadRequestException(String.format("%s.%s", e.getMessage(), e.getCause() == null ? "" : e.getCause().getMessage()));
} catch (TablePreconditionFailedException e) {
collectRequestExceptionMetrics(tags, e.getClass().getSimpleName());
log.error(e.getMessage(), e);
throw new MetacatPreconditionFailedException(String.format("%s.%s", e.getMessage(), e.getCause() == null ? "" : e.getCause().getMessage()));
} catch (ConnectorException e) {
collectRequestExceptionMetrics(tags, e.getClass().getSimpleName());
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);
for (Throwable ex : Throwables.getCausalChain(e)) {
if (ex.getMessage().contains("too many connections") || ex.getMessage().contains("Timeout: Pool empty")) {
throw new MetacatTooManyRequestsException(ex.getMessage());
}
}
throw new MetacatException(message, e);
} catch (UserMetadataServiceException e) {
collectRequestExceptionMetrics(tags, e.getClass().getSimpleName());
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) {
collectRequestExceptionMetrics(tags, e.getClass().getSimpleName());
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);
if (e instanceof MetacatException) {
throw e;
} else {
throw new MetacatException(message, e);
}
} finally {
final long duration = registry.clock().wallTime() - start;
log.info("### Time taken to complete {} for {} is {} ms", resourceRequestName, name, duration);
tryAddTableTypeTag(tags, name);
this.registry.timer(requestTimerId.withTags(tags)).record(duration, TimeUnit.MILLISECONDS);
}
}
Aggregations