use of org.projectnessie.model.Content in project nessie by projectnessie.
the class AbstractRestInvalidRefs method testValidHashesOnValidNamedRefs.
@Test
public void testValidHashesOnValidNamedRefs() throws BaseNessieClientServerException {
Branch branch = createBranch("testValidHashesOnValidNamedRefs");
int commits = 10;
String currentHash = branch.getHash();
createCommits(branch, 1, commits, currentHash);
LogResponse entireLog = getApi().getCommitLog().refName(branch.getName()).get();
assertThat(entireLog).isNotNull();
assertThat(entireLog.getLogEntries()).hasSize(commits);
EntriesResponse allEntries = getApi().getEntries().refName(branch.getName()).get();
assertThat(allEntries).isNotNull();
assertThat(allEntries.getEntries()).hasSize(commits);
List<ContentKey> keys = new ArrayList<>();
IntStream.range(0, commits).forEach(i -> keys.add(ContentKey.of("table" + i)));
// TODO: check where hashOnRef is set
Map<ContentKey, Content> allContent = getApi().getContent().keys(keys).refName(branch.getName()).get();
for (int i = 0; i < commits; i++) {
String hash = entireLog.getLogEntries().get(i).getCommitMeta().getHash();
LogResponse log = getApi().getCommitLog().refName(branch.getName()).hashOnRef(hash).get();
assertThat(log).isNotNull();
assertThat(log.getLogEntries()).hasSize(commits - i);
assertThat(ImmutableList.copyOf(entireLog.getLogEntries()).subList(i, commits)).containsExactlyElementsOf(log.getLogEntries());
EntriesResponse entries = getApi().getEntries().refName(branch.getName()).hashOnRef(hash).get();
assertThat(entries).isNotNull();
assertThat(entries.getEntries()).hasSize(commits - i);
int idx = commits - 1 - i;
ContentKey key = ContentKey.of("table" + idx);
Content c = getApi().getContent().key(key).refName(branch.getName()).hashOnRef(hash).get().get(key);
assertThat(c).isNotNull().isEqualTo(allContent.get(key));
}
}
use of org.projectnessie.model.Content in project nessie by projectnessie.
the class AbstractResteasyTest method testGetContent.
@Test
public void testGetContent() {
Branch branch = makeBranch("content-test");
IcebergTable table = IcebergTable.of("content-table1", 42, 42, 42, 42);
branch = commit(table.getId(), branch, "key1", table.getMetadataLocation());
Content content = rest().queryParam("ref", branch.getName()).queryParam("hashOnRef", branch.getHash()).get(String.format("contents/%s", "key1")).then().statusCode(200).extract().as(Content.class);
assertThat(content).isEqualTo(table);
}
use of org.projectnessie.model.Content 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);
}
}
use of org.projectnessie.model.Content 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;
}
}
use of org.projectnessie.model.Content 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);
}
Aggregations