You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by us...@apache.org on 2015/06/07 18:44:30 UTC

svn commit: r1684046 - in /lucene/dev/branches/branch_5x: ./ solr/ solr/test-framework/ solr/test-framework/src/java/org/apache/solr/cloud/IpTables.java

Author: uschindler
Date: Sun Jun  7 16:44:30 2015
New Revision: 1684046

URL: http://svn.apache.org/r1684046
Log:
Merged revision(s) 1684045 from lucene/dev/trunk:
LUCENE-6530: Fix iptables helper (was broken because of more strict error checking, sorry!). I tested it on my linux box, works fine!

Modified:
    lucene/dev/branches/branch_5x/   (props changed)
    lucene/dev/branches/branch_5x/solr/   (props changed)
    lucene/dev/branches/branch_5x/solr/test-framework/   (props changed)
    lucene/dev/branches/branch_5x/solr/test-framework/src/java/org/apache/solr/cloud/IpTables.java

Modified: lucene/dev/branches/branch_5x/solr/test-framework/src/java/org/apache/solr/cloud/IpTables.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/test-framework/src/java/org/apache/solr/cloud/IpTables.java?rev=1684046&r1=1684045&r2=1684046&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/test-framework/src/java/org/apache/solr/cloud/IpTables.java (original)
+++ lucene/dev/branches/branch_5x/solr/test-framework/src/java/org/apache/solr/cloud/IpTables.java Sun Jun  7 16:44:30 2015
@@ -30,15 +30,13 @@ import org.slf4j.LoggerFactory;
  * To use, tests must be able to run iptables, eg sudo chmod u+s iptables
  */
 public class IpTables {
-  static final Logger log = LoggerFactory
-      .getLogger(IpTables.class);
+  static final Logger log = LoggerFactory.getLogger(IpTables.class);
   
-  private static boolean ENABLED = Boolean.getBoolean("solr.tests.use.iptables");
+  private static final boolean ENABLED = Boolean.getBoolean("solr.tests.use.iptables");
   
-  private static Set<Integer> BLOCK_PORTS = Collections.synchronizedSet(new HashSet<Integer>());
+  private static final Set<Integer> BLOCK_PORTS = Collections.synchronizedSet(new HashSet<Integer>());
   
-  public static void blockPort(int port) throws IOException,
-      InterruptedException {
+  public static void blockPort(int port) throws IOException, InterruptedException {
     if (ENABLED) {
       log.info("Block port with iptables: " + port);
       BLOCK_PORTS.add(port);
@@ -49,21 +47,22 @@ public class IpTables {
     }
   }
   
-  public static void unblockPort(int port) throws IOException,
-      InterruptedException {
-    if (ENABLED) {
+  public static void unblockPort(int port) throws IOException, InterruptedException {
+    if (ENABLED && BLOCK_PORTS.contains(port)) {
       log.info("Unblock port with iptables: " + port);
       runCmd(("iptables -D INPUT -p tcp --dport " + port + " -j DROP")
           .split("\\s"));
       runCmd(("iptables -D OUTPUT -p tcp --dport " + port + " -j DROP")
           .split("\\s"));
+      BLOCK_PORTS.remove(port);
     }
   }
   
   public static void unblockAllPorts() throws IOException, InterruptedException {
     if (ENABLED) {
       log.info("Unblocking any ports previously blocked with iptables...");
-      for (Integer port : BLOCK_PORTS) {
+      final Integer[] ports = BLOCK_PORTS.toArray(new Integer[BLOCK_PORTS.size()]);
+      for (Integer port : ports) {
         IpTables.unblockPort(port);
       }
     }