-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
81d5fb7
commit 912d14a
Showing
7 changed files
with
230 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
...ent/src/main/java/io/quarkus/kafka/streams/deployment/devconsole/DevConsoleProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package io.quarkus.kafka.streams.deployment.devconsole; | ||
|
||
import io.quarkus.deployment.IsDevelopment; | ||
import io.quarkus.deployment.annotations.BuildStep; | ||
import io.quarkus.devconsole.spi.DevConsoleRuntimeTemplateInfoBuildItem; | ||
import io.quarkus.kafka.streams.runtime.TopologyDescriptionSupplier; | ||
|
||
public class DevConsoleProcessor { | ||
|
||
@BuildStep(onlyIf = IsDevelopment.class) | ||
public DevConsoleRuntimeTemplateInfoBuildItem collectInfos() { | ||
return new DevConsoleRuntimeTemplateInfoBuildItem("topology", new TopologyDescriptionSupplier()); | ||
} | ||
|
||
} |
3 changes: 3 additions & 0 deletions
3
extensions/kafka-streams/deployment/src/main/resources/dev-templates/embedded.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<a href="{urlbase}/kafka-streams-topology" class="badge badge-light"> | ||
<i class="fa fa-project-diagram fa-fw"></i> | ||
Topology </a> |
178 changes: 178 additions & 0 deletions
178
...ons/kafka-streams/deployment/src/main/resources/dev-templates/kafka-streams-topology.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,178 @@ | ||
{#include main fluid=true} | ||
{#style} | ||
textarea { | ||
resize: none; | ||
font-family: SFMono-Regular,Menlo,Monaco,Consolas,"Liberation Mono","Courier New",monospace; | ||
} | ||
{/style} | ||
{#scriptref} | ||
<script src="{devRootAppend}/resources/js/mermaid.min.js"></script> | ||
{/scriptref} | ||
|
||
{#script} | ||
function toMermaid(topology) { | ||
var lines = topology.split('\n'); | ||
var subTopologies = []; | ||
var outside = []; | ||
var currentGraphNodeName; | ||
var topicList = []; | ||
var storeList = []; | ||
var name = (value) => value.replaceAll("-", "-<br>"); | ||
|
||
var graph = { | ||
visit: function(lines) { | ||
for(const line of lines) { | ||
switch(true) { | ||
case subTopology.pattern.test(line): | ||
subTopology.visit(line); | ||
break; | ||
case source.pattern.test(line): | ||
source.visit(line); | ||
break; | ||
case processor.pattern.test(line): | ||
processor.visit(line); | ||
break; | ||
case sink.pattern.test(line): | ||
sink.visit(line); | ||
break; | ||
case rightArrow.pattern.test(line): | ||
rightArrow.visit(line); | ||
break; | ||
default: | ||
break; | ||
} | ||
|
||
} | ||
|
||
if(subTopologies.length) { | ||
subTopologies.push(subTopology.endFormatter()); | ||
} | ||
|
||
return ["graph TD "].concat(outside).concat(subTopologies).concat(topicList).concat(storeList).join('\n'); | ||
} | ||
} | ||
var subTopology = { | ||
pattern: /Sub-topology: ([0-9]*)/, | ||
startFormatter: (subTopology) => `subgraph Sub-Topology: $\{subTopology}`, | ||
endFormatter: () => `end`, | ||
visit: function(line) { | ||
var match = line.match(this.pattern); | ||
// Close the previous sub-topology before opening a new one; | ||
if(subTopologies.length) { | ||
subTopologies.push(this.endFormatter()); | ||
} | ||
subTopologies.push(this.startFormatter(match[1])); | ||
} | ||
} | ||
var source = { | ||
pattern: /Source:\s+(\S+)\s+\(topics:\s+\[(.*)\]\)/, | ||
formatter: (source, topic) => `$\{topic}[$\{topic}] --> $\{source}($\{name(source)})`, | ||
visit: function(line) { | ||
var match = line.match(this.pattern); | ||
currentGraphNodeName = match[1].trim(); | ||
var topics = match[2] | ||
topics.split(',').filter(String).map(topic => topic.trim()).forEach(topic => { | ||
outside.push(this.formatter(currentGraphNodeName, topic)); | ||
topicList.push(topic); | ||
}); | ||
} | ||
}; | ||
|
||
var processor = { | ||
pattern: /Processor:\s+(\S+)\s+\(stores:\s+\[(.*)\]\)/, | ||
formatter: (processor, store) => (processor.includes("JOIN")) ? `$\{store}[($\{name(store)})] --> $\{processor}($\{name(processor)})` : `$\{processor}($\{name(processor)}) --> $\{store}[($\{name(store)})]`, | ||
visit: function(line) { | ||
var match = line.match(this.pattern); | ||
currentGraphNodeName = match[1].trim(); | ||
var stores = match[2]; | ||
stores.split(',').filter(String).map(store => store.trim()).forEach(store => { | ||
outside.push(this.formatter(currentGraphNodeName, store)); | ||
storeList.push(store); | ||
}); | ||
} | ||
}; | ||
|
||
var sink = { | ||
pattern: /Sink:\s+(\S+)\s+\(topic:\s+(.*)\)/, | ||
formatter: (sink, topic) => `$\{sink}($\{name(sink)}) --> $\{topic}[$\{topic}]`, | ||
visit: function(line) { | ||
var match = line.match(this.pattern); | ||
currentGraphNodeName = match[1].trim(); | ||
var topic = match[2].trim(); | ||
outside.push(this.formatter(currentGraphNodeName, topic)); | ||
} | ||
} | ||
|
||
var rightArrow = { | ||
pattern: /\s*-->\s+(.*)/, | ||
formatter: (src, dst) => `$\{src}($\{name(src)}) --> $\{dst}($\{name(dst)})`, | ||
visit: function(line) { | ||
var match = line.match(this.pattern); | ||
match[1].split(',').filter(String).map(target => target.trim()).filter(target => target !== "none").forEach(target => { | ||
subTopologies.push(this.formatter(currentGraphNodeName, target)) | ||
}); | ||
} | ||
}; | ||
|
||
for(const line of lines) { | ||
switch(true) { | ||
case subTopology.pattern.test(line): | ||
subTopology.visit(line); | ||
break; | ||
case source.pattern.test(line): | ||
source.visit(line); | ||
break; | ||
case processor.pattern.test(line): | ||
processor.visit(line); | ||
break; | ||
case sink.pattern.test(line): | ||
sink.visit(line); | ||
break; | ||
case rightArrow.pattern.test(line): | ||
rightArrow.visit(line); | ||
break; | ||
default: | ||
break; | ||
} | ||
|
||
} | ||
|
||
if(subTopologies.length) { | ||
subTopologies.push(subTopology.endFormatter()); | ||
} | ||
|
||
return ["graph TD"].concat(outside).concat(subTopologies).concat(topicList).concat(storeList).join('\n'); | ||
} | ||
mermaid.initialize(\{startOnLoad:false}); | ||
$(function(){ | ||
var topologyDescription = $('#topology-description').val(); | ||
var mermaidGraphDefinition = toMermaid(topologyDescription); | ||
console.log(mermaidGraphDefinition); | ||
|
||
mermaid.mermaidAPI.render("mermaid-graph-" + Date.now(), mermaidGraphDefinition, function(svgCode, bindFunctions){ | ||
$('#graph').html(svgCode); | ||
}); | ||
}); | ||
{/script} | ||
{#title}Topology{/title} | ||
{#body} | ||
<div class="row"> | ||
<div class="col-5 offset-1"> | ||
<form> | ||
<div class="form-group"> | ||
<label for="topology-description" class="col-form-label h1">Kafka Streams Topology</label> | ||
<textarea id="topology-description" readonly | ||
class="form-control-plaintext p-3 mb-5 bg-white r border rounded" | ||
rows='{info:topology.toString().split("\r\n|\r|\n").length} + 1'> | ||
{info:topology.toString()} | ||
</textarea> | ||
</div> | ||
</form> | ||
</div> | ||
<div class="col-5"> | ||
<div id="graph"> | ||
</div> | ||
</div> | ||
</div> | ||
{/body} | ||
{/include} |
17 changes: 17 additions & 0 deletions
17
...s/runtime/src/main/java/io/quarkus/kafka/streams/runtime/TopologyDescriptionSupplier.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package io.quarkus.kafka.streams.runtime; | ||
|
||
import java.util.function.Supplier; | ||
|
||
import org.apache.kafka.streams.Topology; | ||
import org.apache.kafka.streams.TopologyDescription; | ||
|
||
import io.quarkus.arc.Arc; | ||
|
||
public class TopologyDescriptionSupplier implements Supplier<TopologyDescription> { | ||
|
||
@Override | ||
public TopologyDescription get() { | ||
Topology topology = Arc.container().instance(Topology.class).get(); | ||
return topology.describe(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters