Search in sources :

Example 86 with MDSKey

use of io.cdap.cdap.data2.dataset2.lib.table.MDSKey in project cdap by caskdata.

the class DefaultPreviewStore method getProgramRunId.

@Override
public ProgramRunId getProgramRunId(ApplicationId applicationId) {
    // PreviewStore is a singleton and we have to create gson for each operation since gson is not thread safe.
    Gson gson = new GsonBuilder().registerTypeAdapter(EntityId.class, new EntityIdTypeAdapter()).create();
    MDSKey mdsKey = getPreviewRowKeyBuilder(META_ROW_KEY_PREFIX, applicationId).build();
    byte[] runId = null;
    try {
        runId = previewTable.getDefaultVersion(mdsKey.getKey(), RUN);
        ;
    } catch (IOException e) {
        throw new RuntimeException(String.format("Failed to get program run id for preview %s", applicationId), e);
    }
    if (runId != null) {
        return gson.fromJson(Bytes.toString(runId), ProgramRunId.class);
    }
    return null;
}
Also used : EntityId(io.cdap.cdap.proto.id.EntityId) EntityIdTypeAdapter(io.cdap.cdap.proto.codec.EntityIdTypeAdapter) GsonBuilder(com.google.gson.GsonBuilder) Gson(com.google.gson.Gson) MDSKey(io.cdap.cdap.data2.dataset2.lib.table.MDSKey) IOException(java.io.IOException)

Example 87 with MDSKey

use of io.cdap.cdap.data2.dataset2.lib.table.MDSKey in project cdap by caskdata.

the class DefaultPreviewStore method getPreviewStatus.

@Override
public PreviewStatus getPreviewStatus(ApplicationId applicationId) {
    // PreviewStore is a singleton and we have to create gson for each operation since gson is not thread safe.
    Gson gson = new GsonBuilder().registerTypeAdapter(BasicThrowable.class, new BasicThrowableCodec()).create();
    MDSKey mdsKey = getPreviewRowKeyBuilder(META_ROW_KEY_PREFIX, applicationId).build();
    byte[] status = null;
    try {
        status = previewTable.getDefaultVersion(mdsKey.getKey(), STATUS);
    } catch (IOException e) {
        throw new RuntimeException(String.format("Failed to get the preview status for preview %s", applicationId), e);
    }
    if (status != null) {
        return gson.fromJson(Bytes.toString(status), PreviewStatus.class);
    }
    return null;
}
Also used : GsonBuilder(com.google.gson.GsonBuilder) Gson(com.google.gson.Gson) MDSKey(io.cdap.cdap.data2.dataset2.lib.table.MDSKey) IOException(java.io.IOException) BasicThrowable(io.cdap.cdap.proto.BasicThrowable) BasicThrowableCodec(io.cdap.cdap.proto.codec.BasicThrowableCodec)

Example 88 with MDSKey

use of io.cdap.cdap.data2.dataset2.lib.table.MDSKey in project cdap by caskdata.

the class DefaultPreviewStore method setPollerinfo.

private void setPollerinfo(ApplicationId applicationId, byte[] pollerInfo) {
    // PreviewStore is a singleton and we have to create gson for each operation since gson is not thread safe.
    Gson gson = new GsonBuilder().registerTypeAdapter(Schema.class, new SchemaTypeAdapter()).create();
    MDSKey mdsKey = getPreviewRowKeyBuilder(META_ROW_KEY_PREFIX, applicationId).build();
    try {
        previewTable.putDefaultVersion(mdsKey.getKey(), POLLERINFO, pollerInfo);
    } catch (IOException e) {
        String msg = String.format("Error while setting the poller information %s for waiting preview application %s.", gson.toJson(pollerInfo), applicationId);
        throw new RuntimeException(msg, e);
    }
}
Also used : SchemaTypeAdapter(io.cdap.cdap.internal.io.SchemaTypeAdapter) GsonBuilder(com.google.gson.GsonBuilder) Schema(io.cdap.cdap.api.data.schema.Schema) Gson(com.google.gson.Gson) MDSKey(io.cdap.cdap.data2.dataset2.lib.table.MDSKey) IOException(java.io.IOException)

Example 89 with MDSKey

use of io.cdap.cdap.data2.dataset2.lib.table.MDSKey in project cdap by caskdata.

the class MetadataKeyTest method testGetTargetType.

@Test
public void testGetTargetType() {
    MDSKey mdsValueKey = MetadataKey.createValueRowKey(new ApplicationId("ns1", "app1").toMetadataEntity(), "key1");
    MDSKey mdsIndexKey = MetadataKey.createIndexRowKey(new ApplicationId("ns1", "app1").toMetadataEntity(), "key1", "value1");
    // assert targetType
    Assert.assertEquals(MetadataEntity.APPLICATION, MetadataKey.extractTargetType(mdsValueKey.getKey()));
    Assert.assertEquals(MetadataEntity.APPLICATION, MetadataKey.extractTargetType(mdsIndexKey.getKey()));
}
Also used : MDSKey(io.cdap.cdap.data2.dataset2.lib.table.MDSKey) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) Test(org.junit.Test)

Example 90 with MDSKey

use of io.cdap.cdap.data2.dataset2.lib.table.MDSKey in project cdap by caskdata.

the class MetadataKeyTest method testVersionedEntitiesKey.

@Test
public void testVersionedEntitiesKey() {
    // CDAP-13597 Metadata for versioned entity is version independent i.e if there are two application version v1
    // and v2 and a tag 'tag1' is added to either one it will be be reflected to both as we don't store the
    // application/schedule/programs with it's version. Following tests test that for such versioned entity the keys
    // are the same i.e default version
    // Key for versioned application/schedule/program should be the same
    // application
    // default version
    ApplicationId applicationId1 = new ApplicationId("ns", "app");
    // custom version
    ApplicationId applicationId2 = new ApplicationId("ns", "app", "2");
    // non-version Application metadata entity
    MDSKey mdsValueKey = MetadataKey.createValueRowKey(applicationId1.toMetadataEntity(), "key1");
    MetadataEntity actual = MetadataKey.extractMetadataEntityFromKey(mdsValueKey.getKey());
    Assert.assertEquals(applicationId1.toMetadataEntity(), actual);
    mdsValueKey = MetadataKey.createValueRowKey(applicationId2.toMetadataEntity(), "key1");
    actual = MetadataKey.extractMetadataEntityFromKey(mdsValueKey.getKey());
    Assert.assertEquals(applicationId1.toMetadataEntity(), actual);
    // program
    // default version
    ProgramId programId1 = new ApplicationId("ns", "app").program(ProgramType.SERVICE, "s");
    // custom version
    ProgramId programId2 = new ApplicationId("ns", "app", "2").program(ProgramType.SERVICE, "s");
    mdsValueKey = MetadataKey.createValueRowKey(programId1.toMetadataEntity(), "key1");
    actual = MetadataKey.extractMetadataEntityFromKey(mdsValueKey.getKey());
    Assert.assertEquals(programId1.toMetadataEntity(), actual);
    mdsValueKey = MetadataKey.createValueRowKey(programId2.toMetadataEntity(), "key1");
    actual = MetadataKey.extractMetadataEntityFromKey(mdsValueKey.getKey());
    Assert.assertEquals(programId1.toMetadataEntity(), actual);
    // schedule
    // default version
    ScheduleId scheduleId1 = new ApplicationId("ns", "app").schedule("s");
    // custom version
    ScheduleId scheduleId2 = new ApplicationId("ns", "app", "2").schedule("s");
    mdsValueKey = MetadataKey.createValueRowKey(scheduleId1.toMetadataEntity(), "key1");
    actual = MetadataKey.extractMetadataEntityFromKey(mdsValueKey.getKey());
    Assert.assertEquals(scheduleId1.toMetadataEntity(), actual);
    mdsValueKey = MetadataKey.createValueRowKey(scheduleId2.toMetadataEntity(), "key1");
    actual = MetadataKey.extractMetadataEntityFromKey(mdsValueKey.getKey());
    Assert.assertEquals(scheduleId1.toMetadataEntity(), actual);
}
Also used : MetadataEntity(io.cdap.cdap.api.metadata.MetadataEntity) MDSKey(io.cdap.cdap.data2.dataset2.lib.table.MDSKey) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) ProgramId(io.cdap.cdap.proto.id.ProgramId) ScheduleId(io.cdap.cdap.proto.id.ScheduleId) Test(org.junit.Test)

Aggregations

MDSKey (co.cask.cdap.data2.dataset2.lib.table.MDSKey)66 MDSKey (io.cdap.cdap.data2.dataset2.lib.table.MDSKey)31 GsonBuilder (com.google.gson.GsonBuilder)22 IOException (java.io.IOException)16 Gson (com.google.gson.Gson)14 HashMap (java.util.HashMap)12 ProgramRunId (co.cask.cdap.proto.id.ProgramRunId)11 ApplicationId (io.cdap.cdap.proto.id.ApplicationId)9 Row (co.cask.cdap.api.dataset.table.Row)8 ProgramId (co.cask.cdap.proto.id.ProgramId)8 Nullable (javax.annotation.Nullable)8 ImmutableMap (com.google.common.collect.ImmutableMap)7 Test (org.junit.Test)7 Scanner (co.cask.cdap.api.dataset.table.Scanner)6 MetadataStoreDataset (co.cask.cdap.data2.dataset2.lib.table.MetadataStoreDataset)6 ArrayList (java.util.ArrayList)6 WorkflowNodeStateDetail (co.cask.cdap.proto.WorkflowNodeStateDetail)5 ApplicationId (co.cask.cdap.proto.id.ApplicationId)5 Row (io.cdap.cdap.api.dataset.table.Row)5 Scanner (io.cdap.cdap.api.dataset.table.Scanner)5