Search in sources :

Example 11 with BaseNessieClientServerException

use of org.projectnessie.error.BaseNessieClientServerException in project nessie by projectnessie.

the class NessieExceptionMapper method toResponse.

@Override
public Response toResponse(Exception exception) {
    ErrorCode errorCode;
    String message;
    if (exception instanceof BaseNessieClientServerException) {
        BaseNessieClientServerException e = (BaseNessieClientServerException) exception;
        errorCode = e.getErrorCode();
        message = exception.getMessage();
    } else if (exception.getCause() instanceof BaseNessieClientServerException) {
        BaseNessieClientServerException e = (BaseNessieClientServerException) exception.getCause();
        errorCode = e.getErrorCode();
        message = exception.getCause().getMessage();
    } else if (exception instanceof JsonParseException || exception instanceof JsonMappingException || exception instanceof IllegalArgumentException) {
        errorCode = ErrorCode.BAD_REQUEST;
        message = exception.getMessage();
    } else if (exception instanceof BackendLimitExceededException) {
        LOGGER.warn("Backend throttled/refused the request: {}", exception.toString());
        errorCode = ErrorCode.TOO_MANY_REQUESTS;
        message = "Backend store refused to process the request: " + exception;
    } else if (exception instanceof AccessControlException) {
        errorCode = ErrorCode.FORBIDDEN;
        message = exception.getMessage();
    } else {
        LOGGER.warn("Unhandled exception returned as HTTP/500 to client", exception);
        errorCode = ErrorCode.UNKNOWN;
        message = Throwables.getCausalChain(exception).stream().map(Throwable::toString).collect(Collectors.joining(", caused by"));
    }
    return buildExceptionResponse(errorCode, message, exception);
}
Also used : BackendLimitExceededException(org.projectnessie.versioned.BackendLimitExceededException) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) AccessControlException(java.security.AccessControlException) ErrorCode(org.projectnessie.error.ErrorCode) JsonParseException(com.fasterxml.jackson.core.JsonParseException) BaseNessieClientServerException(org.projectnessie.error.BaseNessieClientServerException)

Example 12 with BaseNessieClientServerException

use of org.projectnessie.error.BaseNessieClientServerException in project nessie by projectnessie.

the class NessieViewOperations method drop.

@Override
public void drop(String viewIdentifier) {
    reference.checkMutable();
    IcebergView existingView = view(toCatalogTableIdentifier(viewIdentifier));
    if (existingView == null) {
        return;
    }
    CommitMultipleOperationsBuilder commitBuilderBase = api.commitMultipleOperations().commitMeta(NessieUtil.buildCommitMetadata(String.format("Iceberg delete view %s", viewIdentifier), catalogOptions)).operation(Operation.Delete.of(NessieUtil.toKey(toCatalogTableIdentifier(viewIdentifier))));
    // We try to drop the view. Simple retry after ref update.
    try {
        Tasks.foreach(commitBuilderBase).retry(5).stopRetryOn(NessieNotFoundException.class).throwFailureWhenFinished().onFailure((o, exception) -> refresh()).run(commitBuilder -> {
            Branch branch = commitBuilder.branch(reference.getAsBranch()).commit();
            reference.updateReference(branch);
        }, BaseNessieClientServerException.class);
    } catch (NessieConflictException e) {
        LOG.error("Cannot drop view: failed after retry (update ref and retry)", e);
    } catch (NessieNotFoundException e) {
        LOG.error("Cannot drop view: ref is no longer valid.", e);
    } catch (BaseNessieClientServerException e) {
        LOG.error("Cannot drop view: unknown error", e);
    }
}
Also used : ImmutableIcebergView(org.projectnessie.model.ImmutableIcebergView) CommitStateUnknownException(org.apache.iceberg.exceptions.CommitStateUnknownException) LoggerFactory(org.slf4j.LoggerFactory) HttpClientException(org.projectnessie.client.http.HttpClientException) NessieConflictException(org.projectnessie.error.NessieConflictException) ViewVersionMetadata(org.apache.iceberg.view.ViewVersionMetadata) ImmutableCommitMeta(org.projectnessie.model.ImmutableCommitMeta) Map(java.util.Map) NoSuchTableException(org.apache.iceberg.exceptions.NoSuchTableException) Content(org.projectnessie.model.Content) CommitFailedException(org.apache.iceberg.exceptions.CommitFailedException) Operation(org.projectnessie.model.Operation) Logger(org.slf4j.Logger) TableIdentifier(org.apache.iceberg.catalog.TableIdentifier) Predicate(java.util.function.Predicate) Branch(org.projectnessie.model.Branch) NessieApiV1(org.projectnessie.client.api.NessieApiV1) IcebergView(org.projectnessie.model.IcebergView) Tasks(org.apache.iceberg.util.Tasks) BaseNessieClientServerException(org.projectnessie.error.BaseNessieClientServerException) ContentKey(org.projectnessie.model.ContentKey) ViewUtils.toCatalogTableIdentifier(org.apache.iceberg.view.ViewUtils.toCatalogTableIdentifier) FileIO(org.apache.iceberg.io.FileIO) CommitMultipleOperationsBuilder(org.projectnessie.client.api.CommitMultipleOperationsBuilder) NessieNotFoundException(org.projectnessie.error.NessieNotFoundException) BaseMetastoreViewOperations(org.apache.iceberg.view.BaseMetastoreViewOperations) CommitMultipleOperationsBuilder(org.projectnessie.client.api.CommitMultipleOperationsBuilder) Branch(org.projectnessie.model.Branch) ImmutableIcebergView(org.projectnessie.model.ImmutableIcebergView) IcebergView(org.projectnessie.model.IcebergView) NessieConflictException(org.projectnessie.error.NessieConflictException) NessieNotFoundException(org.projectnessie.error.NessieNotFoundException) BaseNessieClientServerException(org.projectnessie.error.BaseNessieClientServerException)

Aggregations

BaseNessieClientServerException (org.projectnessie.error.BaseNessieClientServerException)12 Branch (org.projectnessie.model.Branch)11 ContentKey (org.projectnessie.model.ContentKey)11 List (java.util.List)10 Collectors (java.util.stream.Collectors)10 IcebergTable (org.projectnessie.model.IcebergTable)10 CommitMeta (org.projectnessie.model.CommitMeta)8 Map (java.util.Map)7 Stream (java.util.stream.Stream)7 Operation (org.projectnessie.model.Operation)7 Reference (org.projectnessie.model.Reference)7 CommitMultipleOperationsBuilder (org.projectnessie.client.api.CommitMultipleOperationsBuilder)6 Content (org.projectnessie.model.Content)6 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)5 IcebergView (org.projectnessie.model.IcebergView)5 Put (org.projectnessie.model.Operation.Put)5 Optional (java.util.Optional)4 Function (java.util.function.Function)4 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)4 Test (org.junit.jupiter.api.Test)4