use of org.projectnessie.client.api.CommitMultipleOperationsBuilder in project nessie by projectnessie.
the class AbstractRestContents method verifyAllContentAndOperationTypes.
@Test
public void verifyAllContentAndOperationTypes() throws BaseNessieClientServerException {
Branch branch = createBranch("contentAndOperationAll");
CommitMultipleOperationsBuilder commit = getApi().commitMultipleOperations().branch(branch).commitMeta(CommitMeta.fromMessage("verifyAllContentAndOperationTypes"));
contentAndOperationTypes().flatMap(c -> c.globalOperation == null ? Stream.of(c.operation) : Stream.of(c.operation, c.globalOperation)).forEach(commit::operation);
commit.commit();
List<Entry> entries = getApi().getEntries().refName(branch.getName()).get().getEntries();
List<Entry> expect = contentAndOperationTypes().filter(c -> c.operation instanceof Put).map(c -> Entry.builder().type(c.type).name(c.operation.getKey()).build()).collect(Collectors.toList());
assertThat(entries).containsExactlyInAnyOrderElementsOf(expect);
}
use of org.projectnessie.client.api.CommitMultipleOperationsBuilder in project nessie by projectnessie.
the class AbstractRestContents method verifyContentAndOperationTypesIndividually.
@ParameterizedTest
@MethodSource("contentAndOperationTypes")
public void verifyContentAndOperationTypesIndividually(ContentAndOperationType contentAndOperationType) throws BaseNessieClientServerException {
Branch branch = createBranch("contentAndOperation_" + contentAndOperationType);
CommitMultipleOperationsBuilder commit = getApi().commitMultipleOperations().branch(branch).commitMeta(CommitMeta.fromMessage("commit " + contentAndOperationType)).operation(contentAndOperationType.operation);
if (contentAndOperationType.globalOperation != null) {
commit.operation(contentAndOperationType.globalOperation);
}
commit.commit();
List<Entry> entries = getApi().getEntries().refName(branch.getName()).get().getEntries();
// Oh, yea - this is weird. The property ContentAndOperationType.operation.key.namespace is null
// (!!!)
// here, because somehow JUnit @MethodSource implementation re-constructs the objects returned
// from
// the source-method contentAndOperationTypes.
ContentKey fixedContentKey = ContentKey.of(contentAndOperationType.operation.getKey().getElements());
List<Entry> expect = contentAndOperationType.operation instanceof Put ? singletonList(Entry.builder().name(fixedContentKey).type(contentAndOperationType.type).build()) : emptyList();
assertThat(entries).containsExactlyInAnyOrderElementsOf(expect);
}
use of org.projectnessie.client.api.CommitMultipleOperationsBuilder 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);
}
}
Aggregations