Search in sources :

Example 31 with CommitMeta

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();
}
Also used : ReferenceMetadata(org.projectnessie.model.ReferenceMetadata) NessieBadRequestException(org.projectnessie.error.NessieBadRequestException) LogResponse(org.projectnessie.model.LogResponse) Put(org.projectnessie.model.Operation.Put) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) NessieReferenceNotFoundException(org.projectnessie.error.NessieReferenceNotFoundException) Function(java.util.function.Function) Reference(org.projectnessie.model.Reference) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) Map(java.util.Map) Assertions.assertAll(org.junit.jupiter.api.Assertions.assertAll) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) CommitMeta(org.projectnessie.model.CommitMeta) ValueSource(org.junit.jupiter.params.provider.ValueSource) Operation(org.projectnessie.model.Operation) ImmutableMap(com.google.common.collect.ImmutableMap) Validation(org.projectnessie.model.Validation) ReferencesResponse(org.projectnessie.model.ReferencesResponse) Branch(org.projectnessie.model.Branch) LogEntry(org.projectnessie.model.LogResponse.LogEntry) EntriesResponse(org.projectnessie.model.EntriesResponse) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) List(java.util.List) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) FetchOption(org.projectnessie.api.params.FetchOption) Stream(java.util.stream.Stream) IcebergView(org.projectnessie.model.IcebergView) IcebergTable(org.projectnessie.model.IcebergTable) Optional(java.util.Optional) Tag(org.projectnessie.model.Tag) BaseNessieClientServerException(org.projectnessie.error.BaseNessieClientServerException) ContentKey(org.projectnessie.model.ContentKey) NessieNotFoundException(org.projectnessie.error.NessieNotFoundException) EntriesResponse(org.projectnessie.model.EntriesResponse) LogResponse(org.projectnessie.model.LogResponse) Branch(org.projectnessie.model.Branch) Reference(org.projectnessie.model.Reference) IcebergTable(org.projectnessie.model.IcebergTable) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 32 with CommitMeta

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));
}
Also used : Type(org.projectnessie.model.Content.Type) TypeLiteral(javax.enterprise.util.TypeLiteral) TableCommitMetaStoreWorker(org.projectnessie.server.store.TableCommitMetaStoreWorker) Content(org.projectnessie.model.Content) CommitMeta(org.projectnessie.model.CommitMeta) ApplicationScoped(javax.enterprise.context.ApplicationScoped)

Example 33 with CommitMeta

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;
    }
}
Also used : PersistVersionStore(org.projectnessie.versioned.persist.store.PersistVersionStore) VersionStoreType(org.projectnessie.quarkus.config.VersionStoreConfig.VersionStoreType) VersionStoreType(org.projectnessie.quarkus.config.VersionStoreConfig.VersionStoreType) TableCommitMetaStoreWorker(org.projectnessie.server.store.TableCommitMetaStoreWorker) IOError(java.io.IOError) Content(org.projectnessie.model.Content) CommitMeta(org.projectnessie.model.CommitMeta) Produces(javax.enterprise.inject.Produces) Singleton(javax.inject.Singleton) Startup(io.quarkus.runtime.Startup)

Example 34 with CommitMeta

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);
    }
}
Also used : Delete(org.projectnessie.versioned.Delete) ImmutableLogEntry(org.projectnessie.model.ImmutableLogEntry) Put(org.projectnessie.versioned.Put) ContentKey(org.projectnessie.model.ContentKey) Ref(org.projectnessie.versioned.Ref) NamedRef(org.projectnessie.versioned.NamedRef) RefUtil.toNamedRef(org.projectnessie.services.impl.RefUtil.toNamedRef) Commit(org.projectnessie.versioned.Commit) NessieReferenceNotFoundException(org.projectnessie.error.NessieReferenceNotFoundException) ReferenceNotFoundException(org.projectnessie.versioned.ReferenceNotFoundException) NessieReferenceNotFoundException(org.projectnessie.error.NessieReferenceNotFoundException) Content(org.projectnessie.model.Content) CommitMeta(org.projectnessie.model.CommitMeta) LogEntry(org.projectnessie.model.LogResponse.LogEntry) ImmutableLogEntry(org.projectnessie.model.ImmutableLogEntry)

Example 35 with CommitMeta

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);
    }
}
Also used : LogResponse(org.projectnessie.model.LogResponse) Operation(org.projectnessie.model.Operation) CommitMeta(org.projectnessie.model.CommitMeta) NessieApiV1(org.projectnessie.client.api.NessieApiV1) FetchOption(org.projectnessie.api.params.FetchOption)

Aggregations

CommitMeta (org.projectnessie.model.CommitMeta)37 Branch (org.projectnessie.model.Branch)17 LogEntry (org.projectnessie.model.LogResponse.LogEntry)15 Test (org.junit.jupiter.api.Test)14 IcebergTable (org.projectnessie.model.IcebergTable)14 ContentKey (org.projectnessie.model.ContentKey)13 LogResponse (org.projectnessie.model.LogResponse)13 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)11 Content (org.projectnessie.model.Content)10 List (java.util.List)9 Collectors (java.util.stream.Collectors)9 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)8 BaseNessieClientServerException (org.projectnessie.error.BaseNessieClientServerException)8 NessieReferenceNotFoundException (org.projectnessie.error.NessieReferenceNotFoundException)8 Reference (org.projectnessie.model.Reference)7 ArrayList (java.util.ArrayList)6 Entry (org.projectnessie.model.EntriesResponse.Entry)6 Operation (org.projectnessie.model.Operation)6 Put (org.projectnessie.model.Operation.Put)6 Stream (java.util.stream.Stream)5