...
Public interface to emit the preview data:
Code Block
...
language
...
java public interface PreviewEmitter<V>
...
{ /**
...
Code Block | ||
---|---|---|
| ||
interface PreviewEmitter {
void emit(T record);
} |
Code Block |
---|
class DefaultPreview implements PreviewContext, PreviewEmitter {
// implementation for methods, emit, getEmittedRecords, getLogs and getMetrics.
}
|
Code Block |
---|
@Singleton
class PreviewHelper {
Map<PreviewStageId, DefaultPreview> previewStageIdToDefaultPreview;
PreviewEmitter getPreviewEmitter(PreviewStageId identifier) {
// create DefaultPreview for identifier in previewStageIdToDefaultPreview and return if doesn't exist already, else get and return.
}
PreviewContext getPreviewContext(PreviewStageId identifier) {
// create DefaultPreview for identifier in previewStageIdToDefaultPreview and return if doesn't exist already, else get and return.
}
} |
Code Block | ||
---|---|---|
| ||
class PreviewStageId {
NamespaceId namespace;
String previewId; // this could be runId ?
String stageId;
} |
Implementation:
...
* Emit the Map of properties corresponding to the given key. * @param key the key under which properties are stored * @param propertyValues the map of property values to be stored under the given key */ void emit(String key, Map<String, List<V>> propertyValues); /** * Emit the property specified by name and value for the given key. * @param key the key under which properties are stored * @param propertyName the the name of the property * @param propertyValue the value associated with the property */ void emit(String key, String propertyName, V propertyValue); }
How the application will get access to the PreviewEmitter? Similar to Metric and @UseDataSet, instance of the PreviewEmitter will be injected by CDAP in the application.
Code Block language java public class MyMapReduce extends AbstractMapReduce { private PreviewEmitter<String> emitter; @Override public void initialize() throws Exception { emitter.emit("MyMapReduce.initialize", "logical.start.time", getContext().getLogicalStartTime().toString()); emitter.emit("MyMapReduce.initialize", "actual.start.time", System.currentTimeMillis().toString()); } public MyMapper extends Mapper<byte[], Text, Text, Text> { @Override public void map(byte[] key, Text value, Context context) throws IOException { if (value.toString().startsWith("Product") { emitter.emit("MapReduce.map", "map.product", value.toString()); } } } }
How will CDAP get data from the preview?
Code Block /** * Represents the state of the preview. */ public class PreviewState { public enum Status { RUNNING, COMPLETED, DEPLOY_FAILED, RUNTIME_FAILED }; Status previewStatus; @Nullable String failureMessage; } // This is internal interface which will be used by REST handlers // to retrieve the preview information. public interface PreviewInfo { /** * Get the state of the preview represented by previewId. */ PreviewState getStatus(PreviewId previewId); /** * Get the data associated with the preview represented by previewId. */ Map<String, Map<String, List<V>> getData(PreviewId previewId); /** * Get all metrics associated with the preview represented by previewId. */ Collection<MetricTimeSeries> getMetrics(PreviewId previewId); /** * Get all logs associated with the preview represented by previewId. */ String getLogs(PreviewId previewId); } class PreviewId { NamespaceId namespace; String preview; }
SDK:
Preview Execution Isolation:
...