brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rich...@apache.org
Subject [46/50] [abbrv] git commit: Fix use of service command with iptables and deprecate old methods
Date Fri, 23 May 2014 14:52:17 GMT
Fix use of service command with iptables and deprecate old methods


Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/803f9f13
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/803f9f13
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/803f9f13

Branch: refs/heads/master
Commit: 803f9f1397c1ade033e570fdb5ac1d47d811dfeb
Parents: f54024f
Author: Andrew Kennedy <andrew.kennedy@cloudsoftcorp.com>
Authored: Thu May 22 23:11:12 2014 +0100
Committer: Andrew Kennedy <andrew.kennedy@cloudsoftcorp.com>
Committed: Fri May 23 00:14:27 2014 +0100

----------------------------------------------------------------------
 .../location/jclouds/JcloudsLocationConfig.java |  1 +
 .../brooklyn/util/ssh/IptablesCommands.java     | 97 +++++++++++---------
 2 files changed, 54 insertions(+), 44 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/803f9f13/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsLocationConfig.java
----------------------------------------------------------------------
diff --git a/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsLocationConfig.java
b/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsLocationConfig.java
index 49729a1..5f4a6ff 100644
--- a/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsLocationConfig.java
+++ b/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsLocationConfig.java
@@ -118,6 +118,7 @@ public interface JcloudsLocationConfig extends CloudLocationConfig {
             "Tags to be applied when creating a VM, on supported clouds " +
             "(either a single tag as a String, or an Iterable<String> or String[];"
+
             "note this is not key-value pairs (e.g. what AWS calls 'tags'), for that see
userMetadata)", null);
+
     @Deprecated /** @deprecated since 0.7.0 use #STRING_TAGS */
     public static final ConfigKey<Object> TAGS = STRING_TAGS;
 

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/803f9f13/utils/common/src/main/java/brooklyn/util/ssh/IptablesCommands.java
----------------------------------------------------------------------
diff --git a/utils/common/src/main/java/brooklyn/util/ssh/IptablesCommands.java b/utils/common/src/main/java/brooklyn/util/ssh/IptablesCommands.java
index 2fac2a6..6f971a0 100644
--- a/utils/common/src/main/java/brooklyn/util/ssh/IptablesCommands.java
+++ b/utils/common/src/main/java/brooklyn/util/ssh/IptablesCommands.java
@@ -15,9 +15,7 @@ public class IptablesCommands {
         ACCEPT, REJECT, DROP, LOG
     }
 
-    /**
-     * @deprecated since 0.7; use {@link brooklyn.util.net.Protocol}
-     */
+    /*** @deprecated since 0.7; use {@link brooklyn.util.net.Protocol} */
     @Deprecated
     public enum Protocol {
         TCP("tcp"), UDP("udp"), ALL("all");
@@ -32,18 +30,25 @@ public class IptablesCommands {
         public String toString() {
             return protocol;
         }
-        
+
         brooklyn.util.net.Protocol convert() {
             switch (this) {
-                case TCP : return brooklyn.util.net.Protocol.TCP;
-                case UDP : return brooklyn.util.net.Protocol.UDP;
-                case ALL : return brooklyn.util.net.Protocol.ALL;
-                default:   throw new IllegalStateException("Unexpected protocol "+this);
+                case TCP: return brooklyn.util.net.Protocol.TCP;
+                case UDP: return brooklyn.util.net.Protocol.UDP;
+                case ALL: return brooklyn.util.net.Protocol.ALL;
+                default: throw new IllegalStateException("Unexpected protocol "+this);
             }
         }
     }
 
     @Beta // implementation not portable across distros
+    public static String iptablesService(String cmd) {
+        return sudo(BashCommands.alternatives(
+                BashCommands.ifExecutableElse1("service", "service iptables "+cmd),
+                "/sbin/service iptables " + cmd));
+    }
+
+    @Beta // implementation not portable across distros
     public static String iptablesServiceStop() {
         return iptablesService("stop");
     }
@@ -63,32 +68,29 @@ public class IptablesCommands {
         return iptablesService("status");
     }
 
-    @Beta // implementation not portable across distros
-    public static String iptablesService(String cmd) {
-        return sudo("/sbin/service iptables "+cmd);
+    /**
+     * Returns the command that saves on disk iptables rules, to make them resilient to reboot.
+     *
+     * @return Returns the command that saves on disk iptables rules.
+     */
+    public static String saveIptablesRules() {
+        return BashCommands.alternatives(
+                BashCommands.ifExecutableElse1("iptables-save", sudo("iptables-save")),
+                iptablesService("save"));
     }
 
     /**
      * Returns the command that cleans up iptables rules.
-     * 
+     *
      * @return Returns the command that cleans up iptables rules.
      */
     public static String cleanUpIptablesRules() {
        return sudo("/sbin/iptables -F");
     }
-    
-    /**
-     * Returns the command that saves on disk iptables rules, to make them resilient to reboot.
-     * 
-     * @return Returns the command that saves on disk iptables rules.
-     */
-    public static String saveIptablesRules() {
-       return sudo("/sbin/service iptables save");
-    }
-    
+
     /**
      * Returns the iptables rules.
-     * 
+     *
      * @return Returns the command that list all the iptables rules.
      */
     public static String listIptablesRule() {
@@ -97,77 +99,84 @@ public class IptablesCommands {
 
     /**
      * Returns the command that inserts a rule on top of the iptables' rules to all interfaces.
-     * 
+     *
      * @return Returns the command that inserts a rule on top of the iptables'
      *         rules.
      */
     public static String insertIptablesRule(Chain chain, brooklyn.util.net.Protocol protocol,
int port, Policy policy) {
         return addIptablesRule("-I", chain, Optional.<String> absent(), protocol, port,
policy);
     }
-    
+
+    /** @deprecated since 0.7.0; use {@link #insertIptablesRule(Chain, brooklyn.util.net.Protocol,
int, Policy)} */
+    @Deprecated
     public static String insertIptablesRule(Chain chain, Protocol protocol, int port, Policy
policy) {
         return insertIptablesRule(chain, protocol.convert(), port, policy);
     }
-    
+
     /**
      * Returns the command that inserts a rule on top of the iptables' rules.
-     * 
+     *
      * @return Returns the command that inserts a rule on top of the iptables'
      *         rules.
      */
     public static String insertIptablesRule(Chain chain, String networkInterface, brooklyn.util.net.Protocol
protocol, int port, Policy policy) {
         return addIptablesRule("-I", chain, Optional.of(networkInterface), protocol, port,
policy);
     }
-    
+
+    /** @deprecated since 0.7.0; use {@link #insertIptablesRule(Chain, String, brooklyn.util.net.Protocol,
int, Policy)} */
+    @Deprecated
     public static String insertIptablesRule(Chain chain, String networkInterface, Protocol
protocol, int port, Policy policy) {
         return insertIptablesRule(chain, networkInterface, protocol.convert(), port, policy);
     }
 
     /**
      * Returns the command that appends a rule to iptables to all interfaces.
-     * 
+     *
      * @return Returns the command that appends a rule to iptables.
      */
     public static String appendIptablesRule(Chain chain, brooklyn.util.net.Protocol protocol,
int port, Policy policy) {
         return addIptablesRule("-A", chain, Optional.<String> absent(), protocol, port,
policy);
     }
-    
+
+    /** @deprecated since 0.7.0; use {@link #appendIptablesRule(Chain, brooklyn.util.net.Protocol,
int, Policy)} */
+    @Deprecated
     public static String appendIptablesRule(Chain chain, Protocol protocol, int port, Policy
policy) {
         return appendIptablesRule(chain, protocol.convert(), port, policy);
     }
-    
+
     /**
      * Returns the command that appends a rule to iptables.
-     * 
+     *
      * @return Returns the command that appends a rule to iptables.
      */
     public static String appendIptablesRule(Chain chain, String networkInterface, brooklyn.util.net.Protocol
protocol, int port, Policy policy) {
         return addIptablesRule("-A", chain, Optional.of(networkInterface), protocol, port,
policy);
     }
-    
+
+    /** @deprecated since 0.7.0; use {@link #appendIptablesRule(Chain, String, brooklyn.util.net.Protocol,
int, Policy)} */
+    @Deprecated
     public static String appendIptablesRule(Chain chain, String networkInterface, Protocol
protocol, int port, Policy policy) {
         return appendIptablesRule(chain, networkInterface, protocol.convert(), port, policy);
     }
 
     /**
      * Returns the command that creates a rule to iptables.
-     * 
-     * @return Returns the command that creates a rule to iptables.
+     *
+     * @return Returns the command that creates a rule for iptables.
      */
-    private static String addIptablesRule(String direction, Chain chain, Optional<String>
networkInterface, brooklyn.util.net.Protocol protocol, int port,
-            Policy policy) {
-        String addIptablesRule; 
-        if(networkInterface.isPresent()) {  
+    public static String addIptablesRule(String direction, Chain chain, Optional<String>
networkInterface, brooklyn.util.net.Protocol protocol, int port, Policy policy) {
+        String addIptablesRule;
+        if(networkInterface.isPresent()) {
            addIptablesRule = String.format("/sbin/iptables %s %s -i %s -p %s --dport %d -j
%s", direction, chain, networkInterface.get(), protocol, port, policy);
         } else {
-           addIptablesRule = String.format("/sbin/iptables %s %s -p %s --dport %d -j %s",
direction, chain,
-                 protocol, port, policy);
+           addIptablesRule = String.format("/sbin/iptables %s %s -p %s --dport %d -j %s",
direction, chain, protocol, port, policy);
         }
         return sudo(addIptablesRule);
     }
-    
-    private static String addIptablesRule(String direction, Chain chain, Optional<String>
networkInterface, Protocol protocol, int port,
-            Policy policy) {
+
+    /** @deprecated since 0.7.0; use {@link #addIptablesRule(String, Chain, Optional, brooklyn.util.net.Protocol,
int, Policy)} */
+    @Deprecated
+    public static String addIptablesRule(String direction, Chain chain, Optional<String>
networkInterface, Protocol protocol, int port, Policy policy) {
         return addIptablesRule(direction, chain, networkInterface, protocol.convert(), port,
policy);
     }
 


Mime
View raw message