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;
}
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;
}
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);
}
}
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()));
}
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);
}
Aggregations