Search in sources :

Example 36 with Reference

use of org.projectnessie.model.Reference in project nessie by projectnessie.

the class TreeApiImplWithAuthorization method getAllReferences.

@Override
public ReferencesResponse getAllReferences(ReferencesParams params) {
    ImmutableReferencesResponse.Builder resp = ReferencesResponse.builder();
    BatchAccessChecker check = startAccessCheck();
    List<Reference> refs = super.getAllReferences(params).getReferences().stream().peek(ref -> check.canViewReference(RefUtil.toNamedRef(ref))).collect(Collectors.toList());
    Set<NamedRef> notAllowed = check.check().keySet().stream().map(Check::ref).filter(Objects::nonNull).collect(Collectors.toSet());
    refs.stream().filter(ref -> !notAllowed.contains(RefUtil.toNamedRef(ref))).forEach(resp::addReferences);
    return resp.build();
}
Also used : LogResponse(org.projectnessie.model.LogResponse) Put(org.projectnessie.model.Operation.Put) ServerConfig(org.projectnessie.services.config.ServerConfig) Authorizer(org.projectnessie.services.authz.Authorizer) BatchAccessChecker(org.projectnessie.services.authz.BatchAccessChecker) Reference(org.projectnessie.model.Reference) NessieConflictException(org.projectnessie.error.NessieConflictException) VersionStore(org.projectnessie.versioned.VersionStore) GetReferenceParams(org.projectnessie.api.params.GetReferenceParams) ReferencesParams(org.projectnessie.api.params.ReferencesParams) Merge(org.projectnessie.model.Merge) Type(org.projectnessie.model.Content.Type) Content(org.projectnessie.model.Content) CommitMeta(org.projectnessie.model.CommitMeta) Check(org.projectnessie.services.authz.Check) Nullable(javax.annotation.Nullable) NamedRef(org.projectnessie.versioned.NamedRef) CommitLogParams(org.projectnessie.api.params.CommitLogParams) ReferencesResponse(org.projectnessie.model.ReferencesResponse) Branch(org.projectnessie.model.Branch) Set(java.util.Set) EntriesResponse(org.projectnessie.model.EntriesResponse) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) BranchName(org.projectnessie.versioned.BranchName) List(java.util.List) EntriesParams(org.projectnessie.api.params.EntriesParams) Principal(java.security.Principal) Delete(org.projectnessie.model.Operation.Delete) Operations(org.projectnessie.model.Operations) Transplant(org.projectnessie.model.Transplant) ImmutableReferencesResponse(org.projectnessie.model.ImmutableReferencesResponse) NessieNotFoundException(org.projectnessie.error.NessieNotFoundException) BatchAccessChecker(org.projectnessie.services.authz.BatchAccessChecker) Reference(org.projectnessie.model.Reference) Check(org.projectnessie.services.authz.Check) ImmutableReferencesResponse(org.projectnessie.model.ImmutableReferencesResponse) NamedRef(org.projectnessie.versioned.NamedRef)

Example 37 with Reference

use of org.projectnessie.model.Reference in project nessie by projectnessie.

the class AbstractContentGeneratorTest method makeCommit.

protected Branch makeCommit(NessieApiV1 api, String contentId) throws NessieConflictException, NessieNotFoundException {
    String branchName = "test-" + UUID.randomUUID();
    Branch main = api.getDefaultBranch();
    Reference branch = api.createReference().sourceRefName(main.getName()).reference(Branch.of(branchName, main.getHash())).create();
    return api.commitMultipleOperations().branchName(branch.getName()).hash(branch.getHash()).commitMeta(CommitMeta.fromMessage(COMMIT_MSG)).operation(Operation.Put.of(CONTENT_KEY, IcebergTable.of("testMeta", 123, 456, 789, 321, contentId))).commit();
}
Also used : Branch(org.projectnessie.model.Branch) Reference(org.projectnessie.model.Reference)

Example 38 with Reference

use of org.projectnessie.model.Reference in project nessie by projectnessie.

the class ITDeltaLog method testCommitRetry.

@Test
void testCommitRetry() throws Exception {
    String csvSalaries1 = ITDeltaLog.class.getResource("/salaries1.csv").getPath();
    String csvSalaries2 = ITDeltaLog.class.getResource("/salaries2.csv").getPath();
    String csvSalaries3 = ITDeltaLog.class.getResource("/salaries3.csv").getPath();
    String pathSalaries = new File(tempPath, "salaries").getAbsolutePath();
    spark.sql(String.format("CREATE TABLE IF NOT EXISTS test_commit_retry (Season STRING, Team STRING, Salary STRING, " + "Player STRING) USING delta LOCATION '%s'", pathSalaries));
    Dataset<Row> salariesDf1 = spark.read().option("header", true).csv(csvSalaries1);
    salariesDf1.write().format("delta").mode("overwrite").save(pathSalaries);
    Dataset<Row> count1 = spark.sql("SELECT COUNT(*) FROM test_commit_retry");
    Assertions.assertEquals(15L, count1.collectAsList().get(0).getLong(0));
    Reference mainBranch = api.getReference().refName("main").get();
    Reference devBranch = api.createReference().sourceRefName(mainBranch.getName()).reference(Branch.of("testCommitRetry", mainBranch.getHash())).create();
    spark.sparkContext().conf().set("spark.sql.catalog.spark_catalog.ref", devBranch.getName());
    Dataset<Row> salariesDf2 = spark.read().option("header", true).csv(csvSalaries2);
    salariesDf2.write().format("delta").mode("append").save(pathSalaries);
    Dataset<Row> count2 = spark.sql("SELECT COUNT(*) FROM test_commit_retry");
    Assertions.assertEquals(30L, count2.collectAsList().get(0).getLong(0));
    Reference to = api.getReference().refName("main").get();
    Reference from = api.getReference().refName("testCommitRetry").get();
    api.mergeRefIntoBranch().branch((Branch) to).fromRef(from).merge();
    spark.sparkContext().conf().set("spark.sql.catalog.spark_catalog.ref", "main");
    Dataset<Row> salariesDf3 = spark.read().option("header", true).csv(csvSalaries3);
    salariesDf3.write().format("delta").mode("append").save(pathSalaries);
    Dataset<Row> count3 = spark.sql("SELECT COUNT(*) FROM test_commit_retry");
    Assertions.assertEquals(50L, count3.collectAsList().get(0).getLong(0));
}
Also used : Reference(org.projectnessie.model.Reference) Row(org.apache.spark.sql.Row) File(java.io.File) Test(org.junit.jupiter.api.Test)

Aggregations

Reference (org.projectnessie.model.Reference)38 Branch (org.projectnessie.model.Branch)19 Test (org.junit.jupiter.api.Test)17 ContentKey (org.projectnessie.model.ContentKey)11 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)10 NessieNotFoundException (org.projectnessie.error.NessieNotFoundException)10 CommitMeta (org.projectnessie.model.CommitMeta)10 IcebergTable (org.projectnessie.model.IcebergTable)10 List (java.util.List)9 Collectors (java.util.stream.Collectors)9 LogResponse (org.projectnessie.model.LogResponse)9 Tag (org.projectnessie.model.Tag)9 Put (org.projectnessie.model.Operation.Put)8 Map (java.util.Map)7 Stream (java.util.stream.Stream)7 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)7 BaseNessieClientServerException (org.projectnessie.error.BaseNessieClientServerException)7 Content (org.projectnessie.model.Content)7 NessieApiV1 (org.projectnessie.client.api.NessieApiV1)6 Operation (org.projectnessie.model.Operation)6