Search in sources :

Example 6 with NessieNotFoundException

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

the class ContentApiImpl method getMultipleContents.

@Override
public GetMultipleContentsResponse getMultipleContents(String namedRef, String hashOnRef, GetMultipleContentsRequest request) throws NessieNotFoundException {
    try {
        WithHash<NamedRef> ref = namedRefWithHashOrThrow(namedRef, hashOnRef);
        List<ContentKey> externalKeys = request.getRequestedKeys();
        List<Key> internalKeys = externalKeys.stream().map(ContentApiImpl::toKey).collect(Collectors.toList());
        Map<Key, Content> values = getStore().getValues(ref.getHash(), internalKeys);
        List<ContentWithKey> output = values.entrySet().stream().map(e -> ContentWithKey.of(toContentKey(e.getKey()), e.getValue())).collect(Collectors.toList());
        return ImmutableGetMultipleContentsResponse.builder().contents(output).build();
    } catch (ReferenceNotFoundException ex) {
        throw new NessieReferenceNotFoundException(ex.getMessage(), ex);
    }
}
Also used : NamedRef(org.projectnessie.versioned.NamedRef) NessieContentNotFoundException(org.projectnessie.error.NessieContentNotFoundException) GetMultipleContentsResponse(org.projectnessie.model.GetMultipleContentsResponse) ServerConfig(org.projectnessie.services.config.ServerConfig) ContentWithKey(org.projectnessie.model.GetMultipleContentsResponse.ContentWithKey) ContentApi(org.projectnessie.api.ContentApi) GetMultipleContentsRequest(org.projectnessie.model.GetMultipleContentsRequest) Authorizer(org.projectnessie.services.authz.Authorizer) NessieReferenceNotFoundException(org.projectnessie.error.NessieReferenceNotFoundException) Key(org.projectnessie.versioned.Key) Collectors(java.util.stream.Collectors) ReferenceNotFoundException(org.projectnessie.versioned.ReferenceNotFoundException) List(java.util.List) Principal(java.security.Principal) VersionStore(org.projectnessie.versioned.VersionStore) Map(java.util.Map) Content(org.projectnessie.model.Content) ContentKey(org.projectnessie.model.ContentKey) ImmutableGetMultipleContentsResponse(org.projectnessie.model.ImmutableGetMultipleContentsResponse) CommitMeta(org.projectnessie.model.CommitMeta) NessieNotFoundException(org.projectnessie.error.NessieNotFoundException) WithHash(org.projectnessie.versioned.WithHash) NamedRef(org.projectnessie.versioned.NamedRef) ContentKey(org.projectnessie.model.ContentKey) NessieReferenceNotFoundException(org.projectnessie.error.NessieReferenceNotFoundException) ReferenceNotFoundException(org.projectnessie.versioned.ReferenceNotFoundException) NessieReferenceNotFoundException(org.projectnessie.error.NessieReferenceNotFoundException) Content(org.projectnessie.model.Content) ContentWithKey(org.projectnessie.model.GetMultipleContentsResponse.ContentWithKey) ContentWithKey(org.projectnessie.model.GetMultipleContentsResponse.ContentWithKey) Key(org.projectnessie.versioned.Key) ContentKey(org.projectnessie.model.ContentKey)

Example 7 with NessieNotFoundException

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

the class TestNessieError method nessieNotFoundException.

@Test
void nessieNotFoundException() {
    NessieNotFoundException ex = assertThrows(NessieNotFoundException.class, () -> unwrap(() -> client.newRequest().path("nessieNotFound").get()));
    assertAll(() -> assertEquals("not-there-message", ex.getMessage()), () -> assertNull(ex.getServerStackTrace()), () -> assertEquals(Response.Status.NOT_FOUND.getStatusCode(), ex.getStatus()));
}
Also used : NessieNotFoundException(org.projectnessie.error.NessieNotFoundException) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 8 with NessieNotFoundException

use of org.projectnessie.error.NessieNotFoundException in project iceberg by apache.

the class NessieCatalog method table.

private IcebergTable table(TableIdentifier tableIdentifier) {
    try {
        ContentKey key = NessieUtil.toKey(tableIdentifier);
        Content table = api.getContent().key(key).reference(reference.getReference()).get().get(key);
        return table != null ? table.unwrap(IcebergTable.class).orElse(null) : null;
    } catch (NessieNotFoundException e) {
        return null;
    }
}
Also used : ContentKey(org.projectnessie.model.ContentKey) Content(org.projectnessie.model.Content) NessieNotFoundException(org.projectnessie.error.NessieNotFoundException)

Example 9 with NessieNotFoundException

use of org.projectnessie.error.NessieNotFoundException in project iceberg by apache.

the class NessieTableOperations method doRefresh.

@Override
protected void doRefresh() {
    try {
        reference.refresh(api);
    } catch (NessieNotFoundException e) {
        throw new RuntimeException("Failed to refresh as ref is no longer valid.", e);
    }
    String metadataLocation = null;
    try {
        Content content = api.getContent().key(key).reference(reference.getReference()).get().get(key);
        LOG.debug("Content '{}' at '{}': {}", key, reference.getReference(), content);
        if (content == null) {
            if (currentMetadataLocation() != null) {
                throw new NoSuchTableException("No such table %s in %s", key, reference.getReference());
            }
        } else {
            this.table = content.unwrap(IcebergTable.class).orElseThrow(() -> new IllegalStateException("Cannot refresh iceberg table: " + String.format("Nessie points to a non-Iceberg object for path: %s.", key)));
            metadataLocation = table.getMetadataLocation();
        }
    } catch (NessieNotFoundException ex) {
        if (currentMetadataLocation() != null) {
            throw new NoSuchTableException(ex, "No such table %s", key);
        }
    }
    refreshFromMetadataLocation(metadataLocation, 2);
}
Also used : Content(org.projectnessie.model.Content) NoSuchTableException(org.apache.iceberg.exceptions.NoSuchTableException) NessieNotFoundException(org.projectnessie.error.NessieNotFoundException)

Example 10 with NessieNotFoundException

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

the class IdentifyContentsPerExecutor method walkLiveCommitsInReference.

private Map<String, ContentBloomFilter> walkLiveCommitsInReference(GCStateParamsPerTask gcStateParamsPerTask) {
    Map<String, ContentBloomFilter> bloomFilterMap = new HashMap<>();
    Set<ContentKey> liveContentKeys = new HashSet<>();
    try (Stream<LogResponse.LogEntry> commits = StreamingUtil.getCommitLogStream(gcStateParamsPerTask.getApi(), builder -> builder.hashOnRef(gcStateParamsPerTask.getReference().getHash()).refName(Detached.REF_NAME).fetch(FetchOption.ALL), OptionalInt.empty())) {
        MutableBoolean foundAllLiveCommitHeadsBeforeCutoffTime = new MutableBoolean(false);
        // commit handler for the spliterator
        Consumer<LogResponse.LogEntry> commitHandler = logEntry -> handleLiveCommit(gcStateParamsPerTask, logEntry, bloomFilterMap, foundAllLiveCommitHeadsBeforeCutoffTime, liveContentKeys);
        // traverse commits using the spliterator
        GCUtil.traverseLiveCommits(foundAllLiveCommitHeadsBeforeCutoffTime, commits, commitHandler);
    } catch (NessieNotFoundException e) {
        throw new RuntimeException(e);
    }
    return bloomFilterMap;
}
Also used : Operation(org.projectnessie.model.Operation) Detached(org.projectnessie.model.Detached) LogResponse(org.projectnessie.model.LogResponse) Predicate(java.util.function.Predicate) Set(java.util.Set) HashMap(java.util.HashMap) Instant(java.time.Instant) OptionalInt(java.util.OptionalInt) Reference(org.projectnessie.model.Reference) Serializable(java.io.Serializable) NessieApiV1(org.projectnessie.client.api.NessieApiV1) HashSet(java.util.HashSet) Consumer(java.util.function.Consumer) FetchOption(org.projectnessie.api.params.FetchOption) Stream(java.util.stream.Stream) StreamingUtil(org.projectnessie.client.StreamingUtil) Map(java.util.Map) Content(org.projectnessie.model.Content) ContentKey(org.projectnessie.model.ContentKey) Function(org.apache.spark.api.java.function.Function) CommitMeta(org.projectnessie.model.CommitMeta) MutableBoolean(org.apache.commons.lang3.mutable.MutableBoolean) NessieNotFoundException(org.projectnessie.error.NessieNotFoundException) SparkSession(org.apache.spark.sql.SparkSession) HashMap(java.util.HashMap) MutableBoolean(org.apache.commons.lang3.mutable.MutableBoolean) NessieNotFoundException(org.projectnessie.error.NessieNotFoundException) ContentKey(org.projectnessie.model.ContentKey) HashSet(java.util.HashSet)

Aggregations

NessieNotFoundException (org.projectnessie.error.NessieNotFoundException)19 Content (org.projectnessie.model.Content)12 ContentKey (org.projectnessie.model.ContentKey)10 Map (java.util.Map)8 Branch (org.projectnessie.model.Branch)8 Reference (org.projectnessie.model.Reference)8 NessieConflictException (org.projectnessie.error.NessieConflictException)7 List (java.util.List)5 Stream (java.util.stream.Stream)5 CommitFailedException (org.apache.iceberg.exceptions.CommitFailedException)5 CommitStateUnknownException (org.apache.iceberg.exceptions.CommitStateUnknownException)5 NoSuchTableException (org.apache.iceberg.exceptions.NoSuchTableException)5 HttpClientException (org.projectnessie.client.http.HttpClientException)5 Operation (org.projectnessie.model.Operation)5 Instant (java.time.Instant)4 Set (java.util.Set)4 FetchOption (org.projectnessie.api.params.FetchOption)4 CommitMultipleOperationsBuilder (org.projectnessie.client.api.CommitMultipleOperationsBuilder)4 CommitMeta (org.projectnessie.model.CommitMeta)4 HashMap (java.util.HashMap)3