use of org.projectnessie.model.CommitMeta in project nessie by projectnessie.
the class AbstractRestReferences method referenceNames.
@ParameterizedTest
@ValueSource(strings = { "normal", "with-no_space", "slash/thing" })
public void referenceNames(String refNamePart) throws BaseNessieClientServerException {
String tagName = "tag" + refNamePart;
String branchName = "branch" + refNamePart;
String branchName2 = "branch2" + refNamePart;
String root = "ref_name_" + refNamePart.replaceAll("[^a-z]", "");
Branch main = createBranch(root);
IcebergTable meta = IcebergTable.of("meep", 42, 42, 42, 42);
main = getApi().commitMultipleOperations().branchName(main.getName()).hash(main.getHash()).commitMeta(CommitMeta.builder().message("common-merge-ancestor").properties(ImmutableMap.of("prop1", "val1", "prop2", "val2")).build()).operation(Operation.Put.of(ContentKey.of("meep"), meta)).commit();
String someHash = main.getHash();
Reference createdTag = getApi().createReference().sourceRefName(main.getName()).reference(Tag.of(tagName, someHash)).create();
assertEquals(Tag.of(tagName, someHash), createdTag);
Reference createdBranch1 = getApi().createReference().sourceRefName(main.getName()).reference(Branch.of(branchName, someHash)).create();
assertEquals(Branch.of(branchName, someHash), createdBranch1);
Reference createdBranch2 = getApi().createReference().sourceRefName(main.getName()).reference(Branch.of(branchName2, someHash)).create();
assertEquals(Branch.of(branchName2, someHash), createdBranch2);
Map<String, Reference> references = getApi().getAllReferences().get().getReferences().stream().filter(r -> root.equals(r.getName()) || r.getName().endsWith(refNamePart)).collect(Collectors.toMap(Reference::getName, Function.identity()));
assertThat(references).containsAllEntriesOf(ImmutableMap.of(main.getName(), main, createdTag.getName(), createdTag, createdBranch1.getName(), createdBranch1, createdBranch2.getName(), createdBranch2));
assertThat(references.get(main.getName())).isInstanceOf(Branch.class);
assertThat(references.get(createdTag.getName())).isInstanceOf(Tag.class);
assertThat(references.get(createdBranch1.getName())).isInstanceOf(Branch.class);
assertThat(references.get(createdBranch2.getName())).isInstanceOf(Branch.class);
Reference tagRef = references.get(tagName);
Reference branchRef = references.get(branchName);
Reference branchRef2 = references.get(branchName2);
String tagHash = tagRef.getHash();
String branchHash = branchRef.getHash();
String branchHash2 = branchRef2.getHash();
assertThat(getApi().getReference().refName(tagName).get()).isEqualTo(tagRef);
assertThat(getApi().getReference().refName(branchName).get()).isEqualTo(branchRef);
EntriesResponse entries = getApi().getEntries().refName(tagName).get();
assertThat(entries).isNotNull();
entries = getApi().getEntries().refName(branchName).get();
assertThat(entries).isNotNull();
LogResponse log = getApi().getCommitLog().refName(tagName).get();
assertThat(log).isNotNull();
log = getApi().getCommitLog().refName(branchName).get();
assertThat(log).isNotNull();
// Need to have at least one op, otherwise all following operations (assignTag/Branch, merge,
// delete) will fail
meta = IcebergTable.of("foo", 42, 42, 42, 42);
getApi().commitMultipleOperations().branchName(branchName).hash(branchHash).operation(Put.of(ContentKey.of("some-key"), meta)).commitMeta(CommitMeta.fromMessage("One dummy op")).commit();
log = getApi().getCommitLog().refName(branchName).get();
String newHash = log.getLogEntries().get(0).getCommitMeta().getHash();
getApi().assignTag().tagName(tagName).hash(tagHash).assignTo(Branch.of(branchName, newHash)).assign();
getApi().assignBranch().branchName(branchName).hash(newHash).assignTo(Branch.of(branchName, newHash)).assign();
getApi().mergeRefIntoBranch().branchName(branchName2).hash(branchHash2).fromRefName(branchName).fromHash(newHash).merge();
}
use of org.projectnessie.model.CommitMeta in project nessie by projectnessie.
the class PersistVersionStoreExtension method afterBeanDiscovery.
@SuppressWarnings("unused")
public void afterBeanDiscovery(@Observes AfterBeanDiscovery abd, BeanManager bm) {
TableCommitMetaStoreWorker storeWorker = new TableCommitMetaStoreWorker();
abd.addBean().addType(new TypeLiteral<VersionStore<Content, CommitMeta, Type>>() {
}).addQualifier(Default.Literal.INSTANCE).scope(ApplicationScoped.class).produceWith(i -> new PersistVersionStore<>(databaseAdapter.get(), storeWorker));
}
use of org.projectnessie.model.CommitMeta in project nessie by projectnessie.
the class ConfigurableVersionStoreFactory method getVersionStore.
/**
* Version store producer.
*/
@Produces
@Singleton
@Startup
public VersionStore<Content, CommitMeta, Content.Type> getVersionStore() {
VersionStoreType versionStoreType = storeConfig.getVersionStoreType();
try {
TableCommitMetaStoreWorker storeWorker = new TableCommitMetaStoreWorker();
VersionStore<Content, CommitMeta, Content.Type> versionStore = new PersistVersionStore<>(databaseAdapter, storeWorker);
if (storeConfig.isTracingEnabled()) {
versionStore = new TracingVersionStore<>(versionStore);
}
if (storeConfig.isMetricsEnabled()) {
versionStore = new MetricsVersionStore<>(versionStore);
}
return versionStore;
} catch (RuntimeException | IOError e) {
LOGGER.error("Failed to configure/start {} version store", versionStoreType, e);
throw e;
}
}
use of org.projectnessie.model.CommitMeta in project nessie by projectnessie.
the class TreeApiImpl method getCommitLog.
@Override
public LogResponse getCommitLog(String namedRef, CommitLogParams params) throws NessieNotFoundException {
int max = Math.min(params.maxRecords() != null ? params.maxRecords() : MAX_COMMIT_LOG_ENTRIES, MAX_COMMIT_LOG_ENTRIES);
// we should only allow named references when no paging is defined
Ref endRef = namedRefWithHashOrThrow(namedRef, null == params.pageToken() ? params.endHash() : params.pageToken()).getHash();
boolean fetchAll = FetchOption.isFetchAll(params.fetchOption());
try (Stream<Commit<CommitMeta, Content>> commits = getStore().getCommits(endRef, fetchAll)) {
Stream<LogEntry> logEntries = commits.map(commit -> {
CommitMeta commitMetaWithHash = addHashToCommitMeta(commit.getHash(), commit.getCommitMeta());
ImmutableLogEntry.Builder logEntry = LogEntry.builder();
logEntry.commitMeta(commitMetaWithHash);
if (fetchAll) {
if (commit.getParentHash() != null) {
logEntry.parentCommitHash(commit.getParentHash().asString());
}
if (commit.getOperations() != null) {
commit.getOperations().forEach(op -> {
ContentKey key = ContentKey.of(op.getKey().getElements());
if (op instanceof Put) {
Content content = ((Put<Content>) op).getValue();
logEntry.addOperations(Operation.Put.of(key, content));
}
if (op instanceof Delete) {
logEntry.addOperations(Operation.Delete.of(key));
}
});
}
}
return logEntry.build();
});
logEntries = StreamSupport.stream(StreamUtil.takeUntilIncl(logEntries.spliterator(), x -> Objects.equals(x.getCommitMeta().getHash(), params.startHash())), false);
List<LogEntry> items = filterCommitLog(logEntries, params.filter()).limit(max + 1).collect(Collectors.toList());
if (items.size() == max + 1) {
return ImmutableLogResponse.builder().addAllLogEntries(items.subList(0, max)).isHasMore(true).token(items.get(max).getCommitMeta().getHash()).build();
}
return ImmutableLogResponse.builder().addAllLogEntries(items).build();
} catch (ReferenceNotFoundException e) {
throw new NessieReferenceNotFoundException(e.getMessage(), e);
}
}
use of org.projectnessie.model.CommitMeta in project nessie by projectnessie.
the class ReadCommits method execute.
@Override
public void execute() throws NessieNotFoundException {
try (NessieApiV1 api = createNessieApiInstance()) {
spec.commandLine().getOut().printf("Reading commits for ref '%s'\n\n", ref);
FetchOption fetchOption = isVerbose() ? FetchOption.ALL : FetchOption.MINIMAL;
LogResponse logResponse = api.getCommitLog().refName(ref).fetch(fetchOption).get();
for (LogResponse.LogEntry logEntry : logResponse.getLogEntries()) {
CommitMeta commitMeta = logEntry.getCommitMeta();
spec.commandLine().getOut().printf("%s\t%s\t%s [%s]\n", Objects.requireNonNull(commitMeta.getHash()).substring(0, 8), commitMeta.getAuthorTime(), commitMeta.getMessage(), commitMeta.getAuthor());
List<Operation> operations = logEntry.getOperations();
if (operations != null) {
for (Operation op : operations) {
spec.commandLine().getOut().printf(" %s\n", op);
if (isVerbose()) {
List<String> key = op.getKey().getElements();
for (int i = 0; i < key.size(); i++) {
spec.commandLine().getOut().printf(" key[%d]: %s\n", i, key.get(i));
}
}
}
}
}
spec.commandLine().getOut().printf("\nDone reading commits for ref '%s'\n\n", ref);
}
}
Aggregations