Search in sources :

Example 21 with Content

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

the class AbstractResteasyTest method testBasic.

@Test
public void testBasic() {
    int preSize = rest().get("trees").then().statusCode(200).extract().as(ReferencesResponse.class).getReferences().size();
    rest().get("trees/tree/mainx").then().statusCode(404);
    rest().body(Branch.of("mainx", null)).post("trees/tree").then().statusCode(200);
    ReferencesResponse references = rest().get("trees").then().statusCode(200).extract().as(ReferencesResponse.class);
    Assertions.assertEquals(preSize + 1, references.getReferences().size());
    Reference reference = rest().get("trees/tree/mainx").then().statusCode(200).extract().as(Reference.class);
    assertEquals("mainx", reference.getName());
    Branch newReference = ImmutableBranch.builder().hash(reference.getHash()).name("test").build();
    rest().queryParam("expectedHash", reference.getHash()).body(Branch.of("test", null)).post("trees/tree").then().statusCode(200);
    assertEquals(newReference, rest().get("trees/tree/test").then().statusCode(200).extract().as(Branch.class));
    IcebergTable table = IcebergTable.of("/the/directory/over/there", 42, 42, 42, 42);
    Branch commitResponse = rest().body(ImmutableOperations.builder().addOperations(ImmutablePut.builder().key(ContentKey.of("xxx", "test")).content(table).build()).commitMeta(CommitMeta.fromMessage("")).build()).queryParam("expectedHash", newReference.getHash()).post("trees/branch/{branch}/commit", newReference.getName()).then().statusCode(200).extract().as(Branch.class);
    Assertions.assertNotEquals(newReference.getHash(), commitResponse.getHash());
    Put[] updates = new Put[11];
    for (int i = 0; i < 10; i++) {
        updates[i] = ImmutablePut.builder().key(ContentKey.of("item", Integer.toString(i))).content(IcebergTable.of("/the/directory/over/there/" + i, 42, 42, 42, 42)).build();
    }
    updates[10] = ImmutablePut.builder().key(ContentKey.of("xxx", "test")).content(IcebergTable.of("/the/directory/over/there/has/been/moved", 42, 42, 42, 42)).build();
    Reference branch = rest().get("trees/tree/test").as(Reference.class);
    Operations contents = ImmutableOperations.builder().addOperations(updates).commitMeta(CommitMeta.fromMessage("")).build();
    commitResponse = rest().body(contents).queryParam("expectedHash", branch.getHash()).post("trees/branch/{branch}/commit", branch.getName()).then().statusCode(200).extract().as(Branch.class);
    Assertions.assertNotEquals(branch.getHash(), commitResponse.getHash());
    Response res = rest().queryParam("ref", "test").get("contents/xxx.test").then().extract().response();
    Assertions.assertEquals(updates[10].getContent(), res.body().as(Content.class));
    IcebergTable currentTable = table;
    table = IcebergTable.of("/the/directory/over/there/has/been/moved/again", 42, 42, 42, 42, table.getId());
    Branch b2 = rest().get("trees/tree/test").as(Branch.class);
    rest().body(ImmutableOperations.builder().addOperations(ImmutablePut.builder().key(ContentKey.of("xxx", "test")).content(table).expectedContent(currentTable).build()).commitMeta(CommitMeta.fromMessage("")).build()).queryParam("expectedHash", b2.getHash()).post("trees/branch/{branch}/commit", b2.getName()).then().statusCode(200).extract().as(Branch.class);
    Content returned = rest().queryParam("ref", "test").get("contents/xxx.test").then().statusCode(200).extract().as(Content.class);
    Assertions.assertEquals(table, returned);
    Branch b3 = rest().get("trees/tree/test").as(Branch.class);
    rest().body(Tag.of("tagtest", b3.getHash())).queryParam("sourceRefName", b3.getName()).post("trees/tree").then().statusCode(200);
    assertThat(rest().get("trees/tree/tagtest").then().statusCode(200).extract().body().as(Tag.class).getHash()).isEqualTo(b3.getHash());
    rest().queryParam("expectedHash", "0011223344556677889900112233445566778899001122334455667788990011".substring(0, b2.getHash().length())).delete("trees/tag/tagtest").then().statusCode(409);
    rest().queryParam("expectedHash", b3.getHash()).delete("trees/tag/tagtest").then().statusCode(204);
    LogResponse log = rest().get("trees/tree/test/log").then().statusCode(200).extract().as(LogResponse.class);
    Assertions.assertEquals(3, log.getLogEntries().size());
    Branch b1 = rest().get("trees/tree/test").as(Branch.class);
    rest().queryParam("expectedHash", b1.getHash()).delete("trees/branch/test").then().statusCode(204);
    Branch bx = rest().get("trees/tree/mainx").as(Branch.class);
    rest().queryParam("expectedHash", bx.getHash()).delete("trees/branch/mainx").then().statusCode(204);
}
Also used : LogResponse(org.projectnessie.model.LogResponse) RefLogResponse(org.projectnessie.model.RefLogResponse) ReferencesResponse(org.projectnessie.model.ReferencesResponse) Response(io.restassured.response.Response) DiffResponse(org.projectnessie.model.DiffResponse) LogResponse(org.projectnessie.model.LogResponse) RefLogResponse(org.projectnessie.model.RefLogResponse) Reference(org.projectnessie.model.Reference) ImmutableBranch(org.projectnessie.model.ImmutableBranch) Branch(org.projectnessie.model.Branch) Content(org.projectnessie.model.Content) IcebergTable(org.projectnessie.model.IcebergTable) ReferencesResponse(org.projectnessie.model.ReferencesResponse) Tag(org.projectnessie.model.Tag) ImmutableOperations(org.projectnessie.model.ImmutableOperations) Operations(org.projectnessie.model.Operations) Put(org.projectnessie.model.Operation.Put) ImmutablePut(org.projectnessie.model.ImmutablePut) Test(org.junit.jupiter.api.Test)

Example 22 with Content

use of org.projectnessie.model.Content 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 23 with Content

use of org.projectnessie.model.Content 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 24 with Content

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

the class TableCommitMetaStoreWorker method toStoreGlobalState.

@Override
public ByteString toStoreGlobalState(Content content) {
    ObjectTypes.Content.Builder builder = ObjectTypes.Content.newBuilder().setId(content.getId());
    if (content instanceof IcebergTable) {
        IcebergTable state = (IcebergTable) content;
        ObjectTypes.IcebergMetadataPointer.Builder stateBuilder = ObjectTypes.IcebergMetadataPointer.newBuilder().setMetadataLocation(state.getMetadataLocation());
        builder.setIcebergMetadataPointer(stateBuilder);
    } else if (content instanceof IcebergView) {
        IcebergView state = (IcebergView) content;
        ObjectTypes.IcebergMetadataPointer.Builder stateBuilder = ObjectTypes.IcebergMetadataPointer.newBuilder().setMetadataLocation(state.getMetadataLocation());
        builder.setIcebergMetadataPointer(stateBuilder);
    } else {
        throw new IllegalArgumentException("Unknown type " + content);
    }
    return builder.build().toByteString();
}
Also used : Content(org.projectnessie.model.Content) Builder(org.projectnessie.model.ImmutableDeltaLakeTable.Builder) ImmutableIcebergTable(org.projectnessie.model.ImmutableIcebergTable) IcebergTable(org.projectnessie.model.IcebergTable) ImmutableIcebergView(org.projectnessie.model.ImmutableIcebergView) IcebergView(org.projectnessie.model.IcebergView) ObjectTypes(org.projectnessie.store.ObjectTypes)

Example 25 with Content

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

the class TableCommitMetaStoreWorker method valueFromStore.

@Override
public Content valueFromStore(ByteString onReferenceValue, Optional<ByteString> globalState) {
    ObjectTypes.Content content = parse(onReferenceValue);
    Optional<ObjectTypes.Content> globalContent = globalState.map(TableCommitMetaStoreWorker::parse);
    switch(content.getObjectTypeCase()) {
        case DELTA_LAKE_TABLE:
            Builder builder = ImmutableDeltaLakeTable.builder().id(content.getId()).addAllMetadataLocationHistory(content.getDeltaLakeTable().getMetadataLocationHistoryList()).addAllCheckpointLocationHistory(content.getDeltaLakeTable().getCheckpointLocationHistoryList());
            if (content.getDeltaLakeTable().getLastCheckpoint() != null) {
                builder.lastCheckpoint(content.getDeltaLakeTable().getLastCheckpoint());
            }
            return builder.build();
        case ICEBERG_REF_STATE:
            ObjectTypes.Content global = globalContent.orElseThrow(TableCommitMetaStoreWorker::noIcebergMetadataPointer);
            if (!global.hasIcebergMetadataPointer()) {
                throw noIcebergMetadataPointer();
            }
            return ImmutableIcebergTable.builder().metadataLocation(global.getIcebergMetadataPointer().getMetadataLocation()).snapshotId(content.getIcebergRefState().getSnapshotId()).schemaId(content.getIcebergRefState().getSchemaId()).specId(content.getIcebergRefState().getSpecId()).sortOrderId(content.getIcebergRefState().getSortOrderId()).id(content.getId()).build();
        case ICEBERG_VIEW_STATE:
            ObjectTypes.Content globalView = globalContent.orElseThrow(TableCommitMetaStoreWorker::noIcebergMetadataPointer);
            if (!globalView.hasIcebergMetadataPointer()) {
                throw noIcebergMetadataPointer();
            }
            ObjectTypes.IcebergViewState view = content.getIcebergViewState();
            return ImmutableIcebergView.builder().metadataLocation(globalView.getIcebergMetadataPointer().getMetadataLocation()).versionId(view.getVersionId()).schemaId(view.getSchemaId()).dialect(view.getDialect()).sqlText(view.getSqlText()).id(content.getId()).build();
        case NAMESPACE:
            ObjectTypes.Namespace namespace = content.getNamespace();
            return ImmutableNamespace.builder().id(content.getId()).name(namespace.getName()).build();
        case OBJECTTYPE_NOT_SET:
        default:
            throw new IllegalArgumentException("Unknown type " + content.getObjectTypeCase());
    }
}
Also used : Content(org.projectnessie.model.Content) Builder(org.projectnessie.model.ImmutableDeltaLakeTable.Builder) ObjectTypes(org.projectnessie.store.ObjectTypes)

Aggregations

Content (org.projectnessie.model.Content)32 ContentKey (org.projectnessie.model.ContentKey)16 CommitMeta (org.projectnessie.model.CommitMeta)11 IcebergTable (org.projectnessie.model.IcebergTable)11 Test (org.junit.jupiter.api.Test)9 NessieNotFoundException (org.projectnessie.error.NessieNotFoundException)9 Branch (org.projectnessie.model.Branch)8 Map (java.util.Map)7 ByteString (com.google.protobuf.ByteString)6 IcebergView (org.projectnessie.model.IcebergView)6 HashMap (java.util.HashMap)5 List (java.util.List)5 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5 NessieApiV1 (org.projectnessie.client.api.NessieApiV1)5 Reference (org.projectnessie.model.Reference)5 Instant (java.time.Instant)4 ArrayList (java.util.ArrayList)4 LogResponse (org.projectnessie.model.LogResponse)4 Put (org.projectnessie.model.Operation.Put)4 HashSet (java.util.HashSet)3