操纵风暴拓扑

时间:2019-01-21 09:05:35

标签: graph apache-storm

我是Apache Storm的新手。我正在尝试做一些事情,但我不知道是否有可能.. 我创建了一个直接图,我想参考我正在检查的风暴拓扑...如何将喷口和螺栓与此图连接?为了进行一些分析,例如在图形上进行模式检测...可能吗? 图形代码在这里

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class DirectGraph<V> {
private Map<V, List<Edge<V>>> neighbors = new HashMap<V,   

List<Edge<V>>>();

public String toString() {
    StringBuffer s = new StringBuffer();
    s.append("digraph G {");
    for (V v : neighbors.keySet()) {
        if (neighbors.get(v).size() > 0)
             for (Edge edge : neighbors.get(v)) {
                 s.append("\n  " + v + " -> " + edge);
             }
        else {
            continue;
        }
    }
    s.append("\n}");
    return s.toString();
}

public void add(V vertex) {

    if (neighbors.containsKey(vertex))
        return;
    neighbors.put(vertex, new ArrayList<Edge<V>>());
}

public void add(V from, V to, String label) {
    this.add(from);
    this.add(to);
    neighbors.get(from).add(new Edge<V>(to, label));
}

public static class Edge<V> {
    private V vertex;
    private String label;

    public Edge(V v, String l) {
        vertex = v;
        label = l;
    }

    @Override
    public String toString() {
        return vertex + " [label=\"" + label + "\"];";
    }
}

}

1 个答案:

答案 0 :(得分:0)

您可以通过两种方式提取拓扑DAG。

在构建拓扑时(例如使用TopologyBuilder),您将获得一个SpoutSpec实例。其中包含BoltSpecComponentCommon个对象https://github.com/apache/storm/blob/8a475696e908c53f1c06bf1a8f373d8ac0483427/storm-client/src/jvm/org/apache/storm/generated/StormTopology.java#L45。每个都包含一个inputs,其中包含streams<your-ui-host>/api/v1/topology/<your-topology-id>/visualization(输出)https://github.com/apache/storm/blob/master/storm-client/src/jvm/org/apache/storm/generated/ComponentCommon.java#L39的列表。

如果您已经提交了拓扑并且该拓扑正在运行,则可以通过单击Storm UI服务器来获取类似的信息。您要检索的URL是$ curl localhost:8080/api/v1/topology/wc-test-1-1548158863/visualization { "split": { ":link": "\/component.html?id=split&topology_id=wc-test-1-1548158863", ":capacity": 0.1895867768595, ":type": "bolt", ":inputs": [ { ":component": "spout", ":grouping": "shuffle", ":stream": "default", ":sani-stream": "default" } ], }, "spout": { ":link": "\/component.html?id=spout&topology_id=wc-test-1-1548158863", ":capacity": 0, ":type": "spout", ":inputs": [ { ":component": "__acker", ":grouping": "direct", ":stream": "__ack_reset_timeout", ":sani-stream": "_s__ack_reset_timeout" }, { ":component": "__acker", ":grouping": "direct", ":stream": "__ack_ack", ":sani-stream": "_s__ack_ack" }, { ":component": "__acker", ":grouping": "direct", ":stream": "__ack_fail", ":sani-stream": "_s__ack_fail" } ], }, "count": { ":link": "\/component.html?id=count&topology_id=wc-test-1-1548158863", ":capacity": 0.22859504132231, ":type": "bolt", ":inputs": [ { ":component": "split", ":grouping": "fields", ":stream": "default", ":sani-stream": "default" } ] } }

例如,这是我在本地运行测试拓扑时获得的输出,进行了一些清理:

function LoadMyJs(scriptName) 
{
   var docHeadObj = document.getElementsByTagName("head")[0];
   var dynamicScript = document.createElement("script");
   dynamicScript.type = "text/javascript";
   dynamicScript.src = scriptName;
   docHeadObj.appendChild(dynamicScript);
}

如您所见,我有一个喷嘴从acker螺栓上读取,一个“ split”螺栓从该喷嘴上读取,还有一个“ count”螺栓从“ split”螺栓上读取。