prisme-flow
Version:
prisme platform flow engine
136 lines (127 loc) • 6.63 kB
HTML
<!--
Created by prisme.io on 09/06/2017.
@author <a href="mailto:hello@prisme.io">savane vamara</a> (prisme.io)
-->
<script type="text/javascript">
RED.nodes.registerType('avro',{
category: 'storage',
color: '#B0E2FF',
defaults: {
name: {value: ""},
property: {value: "payload", required: true},
schemaLiteral: {value: ""},
schemaFile: {value: ""},
schemaSelector: {value: "literal", required: true}
},
inputs:1,
outputs:1,
icon: "avro.png",
label: function() {
return this.name || "avro";
},
labelStyle: function() {
return this.name ? "node_label_italic" : "";
},
oneditprepare: function() {
var that = this;
var schemaLiteralVal = $("#node-input-schemaLiteral").val();
var editorVal = (schemaLiteralVal) ? schemaLiteralVal : '{\n\t"type" : "record",\n\t"namespace" : "NodeREDAvro",\n\t"name" : "UnivariateTimeseriesExampleSchema",\n\t"fields" : [\n\t\t{ "name" : "id" , "type" : "string" },\n\t\t{ "name" : "timestamp" , "type" : "long"},\n\t\t{ "name" : "value" , "type" : "float" }\n\t]\n}';
var initEditor = function() {
that.editor = RED.editor.createEditor({
id: 'node-input-schemaLiteral-editor',
mode: 'ace/mode/jsonata',
value: editorVal
});
that.editor.focus();
};
var setSchemaRowVisibility = function() {
var val = $("#node-input-schemaSelector").val();
if (val === "literal") {
if (!that.editor) {
initEditor();
}
$("#schemaLiteral-row").show();
$("#schemaFile-row").hide();
}
else if (val === "file") {
$("#schemaLiteral-row").hide();
$("#schemaFile-row").show();
}
};
$("#node-input-schemaSelector").on("change", function() {setSchemaRowVisibility();});
},
oneditsave: function() {
$("#node-input-schemaLiteral").val(this.editor.getValue());
delete this.editor;
},
oneditresize: function(size) {
var rows = $("#dialog-form>div:not(.node-text-editor-row)");
var height = $("#dialog-form").height();
for (var i=0;i<rows.size();i++) {
height -= $(rows[i]).outerHeight(true);
}
var editorRow = $("#dialog-form>div.node-text-editor-row");
height -= (parseInt(editorRow.css("marginTop"))+parseInt(editorRow.css("marginBottom")));
$(".node-text-editor").css("height",height+"px");
this.editor.resize();
}
});
</script>
<script type="text/x-red" data-template-name="avro">
<div class="form-row">
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="avro">
</div>
<div class="form-row">
<label for="node-input-property"><i class="icon-tasks"></i> Property</label>
msg.<input type="text" id="node-input-property" placeholder="payload">
</div>
<div class="form-row">
<label for="node-input-schemaSelector"><i class="icon-book"></i> Schema</label>
<select id="node-input-schemaSelector">
<option value="literal" selected>literal</option>
<option value="file">from file</option>
</select>
</div>
<div class="form-row" style="margin-bottom: 0px;">
<input type="hidden" id="node-input-schemaLiteral" autofocus="autofocus">
</div>
<div class="form-row node-text-editor-row" id="schemaLiteral-row">
<div class="form-tips" id="schemaLiteralEditorTip">
<span><b>Important:</b> With "literal" selected, make sure you have replaced the example Avro schema in the editor below with an Avro schema corresponding to the format of your particular objects.</span>
</div>
<div style="height: 250px; min-height:150px;" class="node-text-editor" id="node-input-schemaLiteral-editor"></div>
</div>
<div class="form-row" id="schemaFile-row">
<label for="node-input-schemaFile"><i class="icon-file"></i> Path</label>
<input type="text" id="node-input-schemaFile" placeholder="/path/to/avro/schema.avsc">
</div>
</script>
<script type="text/x-red" data-help-name="avro">
<div class="form-tips"><span>Apache Avro is a data serialization system providing a compact, fast,
binary data format for efficient use of network and storage resources.
<br><br>To learn more about Apache Avro serialization and Avro schemas,
visit the <a href="https://avro.apache.org/">Apache Avro website</a>.</span>
</div>
<h1>Overview</h1>
<p>A function node that parses the specified property of the <code>msg</code> object to convert between JavaScript Object and Apache Avro serialization
(using a user-supplied Avro schema). Places the result back in the specified property.</p>
<p>If the value of the specified property is a JavaScript Object it tries to serialize it as Avro.</p>
<p>If the value of the specified property is an Avro buffer it tries to convert it into a JavaScript Object.</p>
<h1>Configuration</h1>
<p><b>Property</b></p>
<i>
<p>Specify the target property of the <code>msg</code> object to be serialized/deserialized.</p>
<p>Default value is "payload", which attempts to serialize or deserialize the entire contents of <code>msg.payload</code>.</p>
<p>If you are attempting to deserialize Kafka message bodies output from a "kafka consumer" node, set this to "payload.value".</p>
</i>
<p><b>Schema</b></p>
<i>
<p>Specify how you will be providing your Avro schema.</p>
<p>If "literal" is selected, you must provide an Avro schema in the text editor.</p>
<p>If "from file" is selected, you must provide the path to an Avro schema on the local filesystem.</p>
<p>In either case, the schema must be a valid Avro schema and correspond to the format of the JavaScript Object in the input <code>msg.<property></code>.</p>
<p>If the schema is not valid, this node will log an error and fail to initialize properly.</p>
<p>If the schema does not match the format of the input <code>msg.<property></code>, serialization and deserialization attempts will fail.</p>
</i>
</script>