Search in sources :

Example 1 with Topology

use of org.apache.kafka.trogdor.common.Topology in project apache-kafka-on-k8s by banzaicloud.

the class NetworkPartitionFaultWorker method runIptablesCommands.

private void runIptablesCommands(Platform platform, String iptablesAction) throws Exception {
    Node curNode = platform.curNode();
    Topology topology = platform.topology();
    TreeSet<String> toBlock = new TreeSet<>();
    for (Set<String> partitionSet : partitionSets) {
        if (!partitionSet.contains(curNode.name())) {
            for (String nodeName : partitionSet) {
                toBlock.add(nodeName);
            }
        }
    }
    for (String nodeName : toBlock) {
        Node node = topology.node(nodeName);
        InetAddress addr = InetAddress.getByName(node.hostname());
        platform.runCommand(new String[] { "sudo", "iptables", iptablesAction, "INPUT", "-p", "tcp", "-s", addr.getHostAddress(), "-j", "DROP", "-m", "comment", "--comment", nodeName });
    }
}
Also used : TreeSet(java.util.TreeSet) Node(org.apache.kafka.trogdor.common.Node) Topology(org.apache.kafka.trogdor.common.Topology) InetAddress(java.net.InetAddress)

Example 2 with Topology

use of org.apache.kafka.trogdor.common.Topology in project kafka by apache.

the class NetworkPartitionFaultWorker method runIptablesCommands.

private void runIptablesCommands(Platform platform, String iptablesAction) throws Exception {
    Node curNode = platform.curNode();
    Topology topology = platform.topology();
    TreeSet<String> toBlock = new TreeSet<>();
    for (Set<String> partitionSet : partitionSets) {
        if (!partitionSet.contains(curNode.name())) {
            for (String nodeName : partitionSet) {
                toBlock.add(nodeName);
            }
        }
    }
    for (String nodeName : toBlock) {
        Node node = topology.node(nodeName);
        InetAddress addr = InetAddress.getByName(node.hostname());
        platform.runCommand(new String[] { "sudo", "iptables", iptablesAction, "INPUT", "-p", "tcp", "-s", addr.getHostAddress(), "-j", "DROP", "-m", "comment", "--comment", nodeName });
    }
}
Also used : TreeSet(java.util.TreeSet) Node(org.apache.kafka.trogdor.common.Node) TextNode(com.fasterxml.jackson.databind.node.TextNode) Topology(org.apache.kafka.trogdor.common.Topology) InetAddress(java.net.InetAddress)

Aggregations

InetAddress (java.net.InetAddress)2 TreeSet (java.util.TreeSet)2 Node (org.apache.kafka.trogdor.common.Node)2 Topology (org.apache.kafka.trogdor.common.Topology)2 TextNode (com.fasterxml.jackson.databind.node.TextNode)1