use of org.projectnessie.model.CommitMeta in project nessie by projectnessie.
the class TreeApiImpl method commitMultipleOperations.
@Override
public Branch commitMultipleOperations(String branch, String hash, Operations operations) throws NessieNotFoundException, NessieConflictException {
List<org.projectnessie.versioned.Operation<Content>> ops = operations.getOperations().stream().map(TreeApiImpl::toOp).collect(ImmutableList.toImmutableList());
CommitMeta commitMeta = operations.getCommitMeta();
if (commitMeta.getCommitter() != null) {
throw new IllegalArgumentException("Cannot set the committer on the client side. It is set by the server.");
}
try {
Hash newHash = getStore().commit(BranchName.of(Optional.ofNullable(branch).orElse(getConfig().getDefaultBranch())), Optional.ofNullable(hash).map(Hash::of), commitMetaUpdate().apply(commitMeta), ops);
return Branch.of(branch, newHash.asString());
} catch (ReferenceNotFoundException e) {
throw new NessieReferenceNotFoundException(e.getMessage(), e);
} catch (ReferenceConflictException e) {
throw new NessieReferenceConflictException(e.getMessage(), e);
}
}
use of org.projectnessie.model.CommitMeta in project nessie by projectnessie.
the class TestStoreWorker method testCommitSerde.
@Test
void testCommitSerde() throws JsonProcessingException {
CommitMeta expectedCommit = ImmutableCommitMeta.builder().commitTime(Instant.now()).authorTime(Instant.now()).author("bill").committer("ted").hash("xyz").message("commit msg").build();
ByteString expectedBytes = ByteString.copyFrom(MAPPER.writeValueAsBytes(expectedCommit));
CommitMeta actualCommit = worker.getMetadataSerializer().fromBytes(expectedBytes);
Assertions.assertEquals(expectedCommit, actualCommit);
ByteString actualBytes = worker.getMetadataSerializer().toBytes(expectedCommit);
Assertions.assertEquals(expectedBytes, actualBytes);
actualBytes = worker.getMetadataSerializer().toBytes(expectedCommit);
Assertions.assertEquals(expectedCommit, worker.getMetadataSerializer().fromBytes(actualBytes));
actualCommit = worker.getMetadataSerializer().fromBytes(expectedBytes);
Assertions.assertEquals(expectedBytes, worker.getMetadataSerializer().toBytes(actualCommit));
}
use of org.projectnessie.model.CommitMeta in project nessie by projectnessie.
the class GenerateContent method execute.
@Override
public void execute() throws BaseNessieClientServerException {
if (runtimeDuration != null) {
if (runtimeDuration.isZero() || runtimeDuration.isNegative()) {
throw new ParameterException(spec.commandLine(), "Duration must be absent to greater than zero.");
}
}
Duration perCommitDuration = Optional.ofNullable(runtimeDuration).orElse(Duration.ZERO).dividedBy(numCommits);
ThreadLocalRandom random = ThreadLocalRandom.current();
String runStartTime = DateTimeFormatter.ofPattern("yyyy-MM-dd-HH-mm-ss").format(LocalDateTime.now());
List<ContentKey> tableNames = IntStream.range(0, numTables).mapToObj(i -> ContentKey.of(String.format("create-contents-%s", runStartTime), "contents", Integer.toString(i))).collect(Collectors.toList());
try (NessieApiV1 api = createNessieApiInstance()) {
Branch defaultBranch;
if (defaultBranchName == null) {
// Use the server's default branch.
defaultBranch = api.getDefaultBranch();
} else {
// Use the specified default branch.
try {
defaultBranch = (Branch) api.getReference().refName(defaultBranchName).get();
} catch (NessieReferenceNotFoundException e) {
// Create branch if it does not exist.
defaultBranch = api.getDefaultBranch();
defaultBranch = (Branch) api.createReference().reference(Branch.of(defaultBranchName, defaultBranch.getHash())).sourceRefName(defaultBranch.getName()).create();
}
}
List<String> branches = new ArrayList<>();
branches.add(defaultBranch.getName());
while (branches.size() < branchCount) {
// Create a new branch
String newBranchName = "branch-" + runStartTime + "_" + (branches.size() - 1);
Branch branch = Branch.of(newBranchName, defaultBranch.getHash());
spec.commandLine().getOut().printf("Creating branch '%s' from '%s' at %s%n", branch.getName(), defaultBranch.getName(), branch.getHash());
api.createReference().reference(branch).sourceRefName(defaultBranch.getName()).create();
branches.add(newBranchName);
}
spec.commandLine().getOut().printf("Starting contents generation, %d commits...%n", numCommits);
for (int i = 0; i < numCommits; i++) {
// Choose a random branch to commit to
String branchName = branches.get(random.nextInt(branches.size()));
Branch commitToBranch = (Branch) api.getReference().refName(branchName).get();
ContentKey tableName = tableNames.get(random.nextInt(tableNames.size()));
Content tableContents = api.getContent().refName(branchName).key(tableName).get().get(tableName);
Content newContents = createContents(tableContents, random);
spec.commandLine().getOut().printf("Committing content-key '%s' to branch '%s' at %s%n", tableName, commitToBranch.getName(), commitToBranch.getHash());
CommitMultipleOperationsBuilder commit = api.commitMultipleOperations().branch(commitToBranch).commitMeta(CommitMeta.builder().message(String.format("%s table %s on %s, commit #%d of %d", tableContents != null ? "Update" : "Create", tableName, branchName, i, numCommits)).author(System.getProperty("user.name")).authorTime(Instant.now()).build());
if (newContents instanceof IcebergTable || newContents instanceof IcebergView) {
commit.operation(Put.of(tableName, newContents, tableContents));
} else {
commit.operation(Put.of(tableName, newContents));
}
Branch newHead = commit.commit();
if (random.nextDouble() < newTagProbability) {
Tag tag = Tag.of("new-tag-" + random.nextLong(), newHead.getHash());
spec.commandLine().getOut().printf("Creating tag '%s' from '%s' at %s%n", tag.getName(), branchName, tag.getHash());
api.createReference().reference(tag).sourceRefName(branchName).create();
}
try {
TimeUnit.NANOSECONDS.sleep(perCommitDuration.toNanos());
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
break;
}
}
}
spec.commandLine().getOut().printf("Done creating contents.%n");
}
use of org.projectnessie.model.CommitMeta in project nessie by projectnessie.
the class AbstractRestMergeTransplant method transplant.
@ParameterizedTest
@ValueSource(booleans = { true, false })
public void transplant(boolean withDetachedCommit) throws BaseNessieClientServerException {
Branch base = createBranch("transplant-base");
Branch branch = createBranch("transplant-branch");
IcebergTable table1 = IcebergTable.of("transplant-table1", 42, 42, 42, 42);
IcebergTable table2 = IcebergTable.of("transplant-table2", 43, 43, 43, 43);
Branch committed1 = getApi().commitMultipleOperations().branchName(branch.getName()).hash(branch.getHash()).commitMeta(CommitMeta.fromMessage("test-transplant-branch1")).operation(Put.of(ContentKey.of("key1"), table1)).commit();
assertThat(committed1.getHash()).isNotNull();
Branch committed2 = getApi().commitMultipleOperations().branchName(branch.getName()).hash(committed1.getHash()).commitMeta(CommitMeta.fromMessage("test-transplant-branch2")).operation(Put.of(ContentKey.of("key1"), table1, table1)).commit();
assertThat(committed2.getHash()).isNotNull();
int commitsToTransplant = 2;
LogResponse logBranch = getApi().getCommitLog().refName(branch.getName()).untilHash(branch.getHash()).maxRecords(commitsToTransplant).get();
getApi().commitMultipleOperations().branchName(base.getName()).hash(base.getHash()).commitMeta(CommitMeta.fromMessage("test-transplant-main")).operation(Put.of(ContentKey.of("key2"), table2)).commit();
getApi().transplantCommitsIntoBranch().hashesToTransplant(ImmutableList.of(committed1.getHash(), committed2.getHash())).fromRefName(maybeAsDetachedName(withDetachedCommit, branch)).branch(base).transplant();
LogResponse log = getApi().getCommitLog().refName(base.getName()).untilHash(base.getHash()).get();
assertThat(log.getLogEntries().stream().map(LogEntry::getCommitMeta).map(CommitMeta::getMessage)).containsExactly("test-transplant-branch2", "test-transplant-branch1", "test-transplant-main");
// Verify that the commit-timestamp was updated
LogResponse logOfTransplanted = getApi().getCommitLog().refName(base.getName()).maxRecords(commitsToTransplant).get();
assertThat(logOfTransplanted.getLogEntries().stream().map(LogEntry::getCommitMeta).map(CommitMeta::getCommitTime)).isNotEqualTo(logBranch.getLogEntries().stream().map(LogEntry::getCommitMeta).map(CommitMeta::getCommitTime));
assertThat(getApi().getEntries().refName(base.getName()).get().getEntries().stream().map(e -> e.getName().getName())).containsExactlyInAnyOrder("key1", "key2");
}
use of org.projectnessie.model.CommitMeta in project nessie by projectnessie.
the class AbstractRestNamespace method testNamespaceMerge.
@Test
public void testNamespaceMerge() throws BaseNessieClientServerException {
Branch base = createBranch("merge-base");
Branch branch = createBranch("merge-branch");
Namespace ns = Namespace.parse("a.b.c");
// create the same namespace on both branches
getApi().createNamespace().namespace(ns).refName(branch.getName()).create();
getApi().createNamespace().namespace(ns).refName(base.getName()).create();
base = (Branch) getApi().getReference().refName(base.getName()).get();
branch = (Branch) getApi().getReference().refName(branch.getName()).get();
getApi().mergeRefIntoBranch().branch(base).fromRef(branch).merge();
LogResponse log = getApi().getCommitLog().refName(base.getName()).untilHash(base.getHash()).get();
String expectedCommitMsg = "create namespace a.b.c";
assertThat(log.getLogEntries().stream().map(LogEntry::getCommitMeta).map(CommitMeta::getMessage)).containsExactly(expectedCommitMsg, expectedCommitMsg);
assertThat(getApi().getEntries().refName(base.getName()).get().getEntries().stream().map(Entry::getName)).containsExactly(ContentKey.of(ns.getElements()));
assertThat(getApi().getNamespace().refName(base.getName()).namespace(ns).get()).isNotNull();
}
Aggregations