Read spring-integration graph data from arbitrary url
This commit is contained in:
@@ -21,6 +21,13 @@
|
||||
color: #888;
|
||||
}
|
||||
|
||||
#refresh {
|
||||
width: 20%;
|
||||
}
|
||||
#target-url {
|
||||
width: 80%;
|
||||
}
|
||||
|
||||
.help {
|
||||
margin-top: 24px;
|
||||
text-align: right;
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
<div class="col-md-10">
|
||||
<h1>Spring Integration Graph</h1>
|
||||
<p>
|
||||
<button id="refresh">Refresh</button>
|
||||
<input id="target-url" type="text" value="http://localhost:8080/integration"><button id="refresh">Refresh</button>
|
||||
</p>
|
||||
</div>
|
||||
<div class="help col-md-2">
|
||||
|
||||
@@ -55,7 +55,6 @@ export default function runStandalone() {
|
||||
dispatcher.dispatch(requestModelAction());
|
||||
});
|
||||
|
||||
|
||||
function getOptionFromDom(att: string) : string | null {
|
||||
const appDiv = document.getElementById('sprotty-app');
|
||||
if (appDiv) {
|
||||
@@ -65,7 +64,9 @@ export default function runStandalone() {
|
||||
}
|
||||
|
||||
function getTarget() : string {
|
||||
return getOptionFromDom('target') || 'target-missing';
|
||||
const input = <HTMLInputElement>document.getElementById('target-url');
|
||||
const target = input && input.value;
|
||||
return target || 'target-missing';
|
||||
}
|
||||
|
||||
function requestModelAction() : RequestModelAction {
|
||||
|
||||
@@ -2,15 +2,13 @@ package org.springframework.ide.si.view;
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.eclipse.sprotty.RequestModelAction;
|
||||
import org.springframework.ide.si.view.json.SpringIntegrationGraphJson;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface GraphDataProvider {
|
||||
SpringIntegrationGraphJson getGraph() throws Exception;
|
||||
SpringIntegrationGraphJson getGraph(RequestModelAction modelRequest) throws Exception;
|
||||
|
||||
static GraphDataProvider fromClasspathResource(String path) {
|
||||
if (!path.startsWith("/")) {
|
||||
@@ -22,9 +20,17 @@ public interface GraphDataProvider {
|
||||
}
|
||||
|
||||
static GraphDataProvider fromUrl(URL resource) {
|
||||
return () -> {
|
||||
String jsonString = IOUtils.toString(resource);
|
||||
return new Gson().fromJson(jsonString, SpringIntegrationGraphJson.class);
|
||||
return (RequestModelAction modelRequest) -> {
|
||||
return SpringIntegrationGraphJson.readFrom(resource);
|
||||
};
|
||||
}
|
||||
|
||||
static GraphDataProvider fromUrlOption(String propName) {
|
||||
return (RequestModelAction modelRequest) -> {
|
||||
String urlStr = modelRequest.getOptions().get(propName);
|
||||
Assert.hasText(urlStr, "Url must be provided in modelRequest.options."+propName);
|
||||
URL url = new URL(modelRequest.getOptions().get(propName));
|
||||
return SpringIntegrationGraphJson.readFrom(url);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,333 +0,0 @@
|
||||
package org.springframework.ide.si.view;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.springframework.ide.si.view.json.SpringIntegrationGraphJson;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
public class MockGraphData implements GraphDataProvider {
|
||||
|
||||
public static String data = "{\n" +
|
||||
"contentDescriptor: {\n" +
|
||||
"providerVersion: \"5.1.6.RELEASE\",\n" +
|
||||
"providerFormatVersion: 1,\n" +
|
||||
"provider: \"spring-integration\"\n" +
|
||||
"},\n" +
|
||||
"nodes: [\n" +
|
||||
"{\n" +
|
||||
"nodeId: 1,\n" +
|
||||
"name: \"news\",\n" +
|
||||
"stats: {\n" +
|
||||
"countsEnabled: true,\n" +
|
||||
"statsEnabled: true,\n" +
|
||||
"loggingEnabled: true,\n" +
|
||||
"sendCount: 20,\n" +
|
||||
"sendErrorCount: 0,\n" +
|
||||
"timeSinceLastSend: 3017590.1150589883,\n" +
|
||||
"meanSendRate: 0.006416917317469066,\n" +
|
||||
"meanErrorRate: 0,\n" +
|
||||
"meanErrorRatio: 0,\n" +
|
||||
"meanSendDuration: 0.6229622172698512,\n" +
|
||||
"minSendDuration: 0.36042,\n" +
|
||||
"maxSendDuration: 5.398724,\n" +
|
||||
"standardDeviationSendDuration: 0.6248008418287394,\n" +
|
||||
"sendDuration: {\n" +
|
||||
"count: 20,\n" +
|
||||
"min: 0.36042,\n" +
|
||||
"max: 5.398724,\n" +
|
||||
"mean: 0.6229622172698512,\n" +
|
||||
"standardDeviation: 0.6248008418287394,\n" +
|
||||
"countLong: 20\n" +
|
||||
"},\n" +
|
||||
"sendRate: {\n" +
|
||||
"count: 20,\n" +
|
||||
"min: 4.519030865997076,\n" +
|
||||
"max: 5.000686829984188,\n" +
|
||||
"mean: 0.006416915226255189,\n" +
|
||||
"standardDeviation: 0.003059182339655441,\n" +
|
||||
"countLong: 20\n" +
|
||||
"},\n" +
|
||||
"errorRate: {\n" +
|
||||
"count: 0,\n" +
|
||||
"min: 0,\n" +
|
||||
"max: 0,\n" +
|
||||
"mean: 0,\n" +
|
||||
"standardDeviation: 0,\n" +
|
||||
"countLong: 0\n" +
|
||||
"}\n" +
|
||||
"},\n" +
|
||||
"componentType: \"channel\",\n" +
|
||||
"properties: { }\n" +
|
||||
"},\n" +
|
||||
"{\n" +
|
||||
"nodeId: 2,\n" +
|
||||
"name: \"file\",\n" +
|
||||
"stats: {\n" +
|
||||
"countsEnabled: true,\n" +
|
||||
"statsEnabled: true,\n" +
|
||||
"loggingEnabled: true,\n" +
|
||||
"sendCount: 20,\n" +
|
||||
"sendErrorCount: 0,\n" +
|
||||
"timeSinceLastSend: 3017591.1391609907,\n" +
|
||||
"meanSendRate: 0.006416922929073101,\n" +
|
||||
"meanErrorRate: 0,\n" +
|
||||
"meanErrorRatio: 0,\n" +
|
||||
"meanSendDuration: 0.35330047484316307,\n" +
|
||||
"minSendDuration: 0.208864,\n" +
|
||||
"maxSendDuration: 2.849803,\n" +
|
||||
"standardDeviationSendDuration: 0.33755534347541105,\n" +
|
||||
"sendDuration: {\n" +
|
||||
"count: 20,\n" +
|
||||
"min: 0.208864,\n" +
|
||||
"max: 2.849803,\n" +
|
||||
"mean: 0.35330047484316307,\n" +
|
||||
"standardDeviation: 0.33755534347541105,\n" +
|
||||
"countLong: 20\n" +
|
||||
"},\n" +
|
||||
"sendRate: {\n" +
|
||||
"count: 20,\n" +
|
||||
"min: 4.516921804994345,\n" +
|
||||
"max: 5.000899210005999,\n" +
|
||||
"mean: 0.00641692253069279,\n" +
|
||||
"standardDeviation: 0.003073929309381288,\n" +
|
||||
"countLong: 20\n" +
|
||||
"},\n" +
|
||||
"errorRate: {\n" +
|
||||
"count: 0,\n" +
|
||||
"min: 0,\n" +
|
||||
"max: 0,\n" +
|
||||
"mean: 0,\n" +
|
||||
"standardDeviation: 0,\n" +
|
||||
"countLong: 0\n" +
|
||||
"}\n" +
|
||||
"},\n" +
|
||||
"componentType: \"channel\",\n" +
|
||||
"properties: { }\n" +
|
||||
"},\n" +
|
||||
"{\n" +
|
||||
"nodeId: 3,\n" +
|
||||
"name: \"nullChannel\",\n" +
|
||||
"stats: {\n" +
|
||||
"countsEnabled: true,\n" +
|
||||
"statsEnabled: true,\n" +
|
||||
"loggingEnabled: true,\n" +
|
||||
"sendCount: 0,\n" +
|
||||
"sendErrorCount: 0,\n" +
|
||||
"timeSinceLastSend: 0,\n" +
|
||||
"meanSendRate: 0,\n" +
|
||||
"meanErrorRate: 0,\n" +
|
||||
"meanErrorRatio: 0,\n" +
|
||||
"meanSendDuration: 0,\n" +
|
||||
"minSendDuration: 0,\n" +
|
||||
"maxSendDuration: 0,\n" +
|
||||
"standardDeviationSendDuration: 0,\n" +
|
||||
"sendDuration: {\n" +
|
||||
"count: 0,\n" +
|
||||
"min: 0,\n" +
|
||||
"max: 0,\n" +
|
||||
"mean: 0,\n" +
|
||||
"standardDeviation: 0,\n" +
|
||||
"countLong: 0\n" +
|
||||
"},\n" +
|
||||
"sendRate: {\n" +
|
||||
"count: 0,\n" +
|
||||
"min: 0,\n" +
|
||||
"max: 0,\n" +
|
||||
"mean: 0,\n" +
|
||||
"standardDeviation: 0,\n" +
|
||||
"countLong: 0\n" +
|
||||
"},\n" +
|
||||
"errorRate: {\n" +
|
||||
"count: 0,\n" +
|
||||
"min: 0,\n" +
|
||||
"max: 0,\n" +
|
||||
"mean: 0,\n" +
|
||||
"standardDeviation: 0,\n" +
|
||||
"countLong: 0\n" +
|
||||
"}\n" +
|
||||
"},\n" +
|
||||
"componentType: \"null-channel\",\n" +
|
||||
"properties: { }\n" +
|
||||
"},\n" +
|
||||
"{\n" +
|
||||
"nodeId: 4,\n" +
|
||||
"name: \"errorChannel\",\n" +
|
||||
"stats: {\n" +
|
||||
"countsEnabled: true,\n" +
|
||||
"statsEnabled: true,\n" +
|
||||
"loggingEnabled: true,\n" +
|
||||
"sendCount: 0,\n" +
|
||||
"sendErrorCount: 0,\n" +
|
||||
"timeSinceLastSend: 0,\n" +
|
||||
"meanSendRate: 0,\n" +
|
||||
"meanErrorRate: 0,\n" +
|
||||
"meanErrorRatio: 0,\n" +
|
||||
"meanSendDuration: 0,\n" +
|
||||
"minSendDuration: 0,\n" +
|
||||
"maxSendDuration: 0,\n" +
|
||||
"standardDeviationSendDuration: 0,\n" +
|
||||
"sendDuration: {\n" +
|
||||
"count: 0,\n" +
|
||||
"min: 0,\n" +
|
||||
"max: 0,\n" +
|
||||
"mean: 0,\n" +
|
||||
"standardDeviation: 0,\n" +
|
||||
"countLong: 0\n" +
|
||||
"},\n" +
|
||||
"sendRate: {\n" +
|
||||
"count: 0,\n" +
|
||||
"min: 0,\n" +
|
||||
"max: 0,\n" +
|
||||
"mean: 0,\n" +
|
||||
"standardDeviation: 0,\n" +
|
||||
"countLong: 0\n" +
|
||||
"},\n" +
|
||||
"errorRate: {\n" +
|
||||
"count: 0,\n" +
|
||||
"min: 0,\n" +
|
||||
"max: 0,\n" +
|
||||
"mean: 0,\n" +
|
||||
"standardDeviation: 0,\n" +
|
||||
"countLong: 0\n" +
|
||||
"}\n" +
|
||||
"},\n" +
|
||||
"componentType: \"publish-subscribe-channel\",\n" +
|
||||
"properties: { }\n" +
|
||||
"},\n" +
|
||||
"{\n" +
|
||||
"nodeId: 5,\n" +
|
||||
"name: \"news.adapter\",\n" +
|
||||
"stats: {\n" +
|
||||
"messageCount: 20\n" +
|
||||
"},\n" +
|
||||
"componentType: \"feed:inbound-channel-adapter\",\n" +
|
||||
"properties: { },\n" +
|
||||
"output: \"news\",\n" +
|
||||
"errors: null\n" +
|
||||
"},\n" +
|
||||
"{\n" +
|
||||
"nodeId: 6,\n" +
|
||||
"name: \"org.springframework.integration.config.ConsumerEndpointFactoryBean#0\",\n" +
|
||||
"stats: {\n" +
|
||||
"activeCount: 0,\n" +
|
||||
"duration: {\n" +
|
||||
"count: 20,\n" +
|
||||
"min: 0.346117,\n" +
|
||||
"max: 4.516881,\n" +
|
||||
"mean: 0.585700683679285,\n" +
|
||||
"standardDeviation: 0.5242315172537475,\n" +
|
||||
"countLong: 20\n" +
|
||||
"},\n" +
|
||||
"countsEnabled: true,\n" +
|
||||
"statsEnabled: true,\n" +
|
||||
"loggingEnabled: true,\n" +
|
||||
"maxDuration: 4.516881,\n" +
|
||||
"minDuration: 0.346117,\n" +
|
||||
"meanDuration: 0.585700683679285,\n" +
|
||||
"errorCount: 0,\n" +
|
||||
"handleCount: 20,\n" +
|
||||
"standardDeviationDuration: 0.5242315172537475\n" +
|
||||
"},\n" +
|
||||
"componentType: \"transformer\",\n" +
|
||||
"properties: {\n" +
|
||||
"expression: \"payload.title + ' @ ' + payload.link + ' '\"\n" +
|
||||
"},\n" +
|
||||
"output: \"file\",\n" +
|
||||
"input: \"news\"\n" +
|
||||
"},\n" +
|
||||
"{\n" +
|
||||
"nodeId: 7,\n" +
|
||||
"name: \"file.adapter\",\n" +
|
||||
"stats: {\n" +
|
||||
"activeCount: 0,\n" +
|
||||
"duration: {\n" +
|
||||
"count: 20,\n" +
|
||||
"min: 0.192626,\n" +
|
||||
"max: 2.602112,\n" +
|
||||
"mean: 0.3295736390049931,\n" +
|
||||
"standardDeviation: 0.31151136752438835,\n" +
|
||||
"countLong: 20\n" +
|
||||
"},\n" +
|
||||
"countsEnabled: true,\n" +
|
||||
"statsEnabled: true,\n" +
|
||||
"loggingEnabled: true,\n" +
|
||||
"maxDuration: 2.602112,\n" +
|
||||
"minDuration: 0.192626,\n" +
|
||||
"meanDuration: 0.3295736390049931,\n" +
|
||||
"errorCount: 0,\n" +
|
||||
"handleCount: 20,\n" +
|
||||
"standardDeviationDuration: 0.31151136752438835\n" +
|
||||
"},\n" +
|
||||
"componentType: \"message-handler\",\n" +
|
||||
"properties: { },\n" +
|
||||
"output: null,\n" +
|
||||
"input: \"file\"\n" +
|
||||
"},\n" +
|
||||
"{\n" +
|
||||
"nodeId: 8,\n" +
|
||||
"name: \"_org.springframework.integration.errorLogger\",\n" +
|
||||
"stats: {\n" +
|
||||
"activeCount: 0,\n" +
|
||||
"duration: {\n" +
|
||||
"count: 0,\n" +
|
||||
"min: 0,\n" +
|
||||
"max: 0,\n" +
|
||||
"mean: 0,\n" +
|
||||
"standardDeviation: 0,\n" +
|
||||
"countLong: 0\n" +
|
||||
"},\n" +
|
||||
"countsEnabled: true,\n" +
|
||||
"statsEnabled: true,\n" +
|
||||
"loggingEnabled: true,\n" +
|
||||
"maxDuration: 0,\n" +
|
||||
"minDuration: 0,\n" +
|
||||
"meanDuration: 0,\n" +
|
||||
"errorCount: 0,\n" +
|
||||
"handleCount: 0,\n" +
|
||||
"standardDeviationDuration: 0\n" +
|
||||
"},\n" +
|
||||
"componentType: \"logging-channel-adapter\",\n" +
|
||||
"properties: { },\n" +
|
||||
"output: null,\n" +
|
||||
"input: \"errorChannel\"\n" +
|
||||
"}\n" +
|
||||
"],\n" +
|
||||
"links: [\n" +
|
||||
"{\n" +
|
||||
"from: 5,\n" +
|
||||
"to: 1,\n" +
|
||||
"type: \"output\"\n" +
|
||||
"},\n" +
|
||||
"{\n" +
|
||||
"from: 1,\n" +
|
||||
"to: 6,\n" +
|
||||
"type: \"input\"\n" +
|
||||
"},\n" +
|
||||
"{\n" +
|
||||
"from: 6,\n" +
|
||||
"to: 2,\n" +
|
||||
"type: \"output\"\n" +
|
||||
"},\n" +
|
||||
"{\n" +
|
||||
"from: 2,\n" +
|
||||
"to: 7,\n" +
|
||||
"type: \"input\"\n" +
|
||||
"},\n" +
|
||||
"{\n" +
|
||||
"from: 4,\n" +
|
||||
"to: 8,\n" +
|
||||
"type: \"input\"\n" +
|
||||
"}\n" +
|
||||
"]\n" +
|
||||
"}";
|
||||
|
||||
@Override
|
||||
public SpringIntegrationGraphJson getGraph() throws IOException {
|
||||
Gson gson = new Gson().newBuilder().setPrettyPrinting().create();
|
||||
JsonObject json = gson.fromJson(data, JsonObject.class);
|
||||
System.out.println(gson.toJson(json));
|
||||
return gson.fromJson(json, SpringIntegrationGraphJson.class);
|
||||
}
|
||||
}
|
||||
@@ -76,7 +76,7 @@ public class SIDiagramGenerator implements DiagramGenerator {
|
||||
public synchronized SModelRoot generateModel(String clientId, RequestModelAction modelRequest) {
|
||||
nodesById.clear();
|
||||
try {
|
||||
SpringIntegrationGraphJson jsonData = graphDataProvider.getGraph();
|
||||
SpringIntegrationGraphJson jsonData = graphDataProvider.getGraph(modelRequest);
|
||||
return toSprottyGraph(jsonData);
|
||||
} catch (Exception e) {
|
||||
log.error("", e);
|
||||
@@ -166,7 +166,7 @@ public class SIDiagramGenerator implements DiagramGenerator {
|
||||
centerNode(compartment);
|
||||
|
||||
SLabel label = new SLabel();
|
||||
label.setId(id + "-lanbel");
|
||||
label.setId(id + "-label");
|
||||
label.setType("node:label");
|
||||
label.setText(labelText);
|
||||
centerNode(label);
|
||||
|
||||
@@ -8,6 +8,7 @@ import org.eclipse.sprotty.layout.SprottyLayoutConfigurator;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.ide.si.view.json.SpringIntegrationGraphJson;
|
||||
|
||||
@SpringBootApplication
|
||||
public class SprottySiViewApplication {
|
||||
@@ -15,7 +16,9 @@ public class SprottySiViewApplication {
|
||||
@Bean
|
||||
GraphDataProvider graphDataProvider() {
|
||||
// return new MockGraphData();
|
||||
return GraphDataProvider.fromClasspathResource("/sample.json");
|
||||
// return GraphDataProvider.fromClasspathResource("/sample.json");
|
||||
|
||||
return GraphDataProvider.fromUrlOption("target");
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
package org.springframework.ide.si.view.json;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
public class SpringIntegrationGraphJson extends PrettyJson {
|
||||
@@ -26,4 +32,8 @@ public class SpringIntegrationGraphJson extends PrettyJson {
|
||||
public void setLinks(SpringIntegrationEdgeJson[] links) {
|
||||
this.links = links;
|
||||
}
|
||||
public static SpringIntegrationGraphJson readFrom(URL resource) throws IOException {
|
||||
String jsonString = IOUtils.toString(resource);
|
||||
return new Gson().fromJson(jsonString, SpringIntegrationGraphJson.class);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user