Search in sources :

Example 1 with BasicThrowableCodec

use of io.cdap.cdap.proto.codec.BasicThrowableCodec in project cdap by caskdata.

the class DefaultPreviewStore method setPreviewStatus.

@Override
public void setPreviewStatus(ApplicationId applicationId, PreviewStatus previewStatus) {
    // 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();
    try {
        previewTable.putDefaultVersion(mdsKey.getKey(), STATUS, Bytes.toBytes(gson.toJson(previewStatus)));
        previewTable.putDefaultVersion(mdsKey.getKey(), APPID, Bytes.toBytes(gson.toJson(applicationId)));
    } catch (IOException e) {
        throw new RuntimeException(String.format("Failed to put preview status %s for preview %s", previewStatus, applicationId), e);
    }
}
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 2 with BasicThrowableCodec

use of io.cdap.cdap.proto.codec.BasicThrowableCodec 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)

Aggregations

Gson (com.google.gson.Gson)2 GsonBuilder (com.google.gson.GsonBuilder)2 MDSKey (io.cdap.cdap.data2.dataset2.lib.table.MDSKey)2 BasicThrowable (io.cdap.cdap.proto.BasicThrowable)2 BasicThrowableCodec (io.cdap.cdap.proto.codec.BasicThrowableCodec)2 IOException (java.io.IOException)2