brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aleds...@apache.org
Subject [1/2] brooklyn-server git commit: Add disable flag to shared sg customizer
Date Fri, 30 Sep 2016 15:36:35 GMT
Repository: brooklyn-server
Updated Branches:
  refs/heads/master 2e30f0820 -> 420ad7a4d


Add disable flag to shared sg customizer

This flag allows the shared sg to be disabled in yaml


Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/7184d675
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/7184d675
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/7184d675

Branch: refs/heads/master
Commit: 7184d6750b2b8614c4049c6a7a991e41743673c1
Parents: 438e746
Author: Duncan Grant <duncan.grant@cloudsoftcorp.com>
Authored: Fri Sep 30 13:45:39 2016 +0100
Committer: Duncan Grant <duncan.grant@cloudsoftcorp.com>
Committed: Fri Sep 30 15:32:30 2016 +0100

----------------------------------------------------------------------
 .../SharedLocationSecurityGroupCustomizer.java  | 20 ++++++++++++++++++++
 ...aredLocationSecurityGroupCustomizerTest.java | 12 ++++++++++++
 2 files changed, 32 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/7184d675/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/networking/SharedLocationSecurityGroupCustomizer.java
----------------------------------------------------------------------
diff --git a/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/networking/SharedLocationSecurityGroupCustomizer.java
b/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/networking/SharedLocationSecurityGroupCustomizer.java
index edac91d..6dc7906 100644
--- a/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/networking/SharedLocationSecurityGroupCustomizer.java
+++ b/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/networking/SharedLocationSecurityGroupCustomizer.java
@@ -76,6 +76,15 @@ public class SharedLocationSecurityGroupCustomizer extends BasicJcloudsLocationC
     private RangeSet<Integer> udpPortRanges;
 
     /**
+     * Add a flag that disables this customizer.  It's isn't currently possible to add a
customizer
+     * based on a flag.  This flag makes it possible to write blueprints using the customizer
but still
+     * be able to disable it for clouds (e.g. bluebox) where the SG implementation has known
issues.
+     *
+     * Default: true
+     */
+    private boolean enabled = true;
+
+    /**
      * The location name is appended to the name of the shared SG - use if you need distinct
shared SGs within the same location
      *
      * @param locationName appended to the name of the SG
@@ -106,8 +115,17 @@ public class SharedLocationSecurityGroupCustomizer extends BasicJcloudsLocationC
         this.cidr = cidr;
     }
 
+    /**
+     * @param enabled set to false to disable this customizer
+     */
+    public void setEnabled(boolean enabled) {
+        this.enabled = enabled;
+    }
+
     @Override
     public void customize(JcloudsLocation location, ComputeService computeService, Template
template) {
+        if(!enabled) return;
+
         super.customize(location, computeService, template);
 
         inboundPorts = template.getOptions().getInboundPorts();
@@ -121,6 +139,8 @@ public class SharedLocationSecurityGroupCustomizer extends BasicJcloudsLocationC
     public void customize(JcloudsLocation location, ComputeService computeService, JcloudsMachineLocation
machine) {
         super.customize(location, computeService, machine);
 
+        if(!enabled) return;
+
         final JcloudsLocationSecurityGroupCustomizer instance = getInstance(getSharedGroupId(location));
 
         ImmutableList.Builder<IpPermission> builder = ImmutableList.<IpPermission>builder();

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/7184d675/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/networking/SharedLocationSecurityGroupCustomizerTest.java
----------------------------------------------------------------------
diff --git a/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/networking/SharedLocationSecurityGroupCustomizerTest.java
b/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/networking/SharedLocationSecurityGroupCustomizerTest.java
index 565bd7b..7c7de4b 100644
--- a/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/networking/SharedLocationSecurityGroupCustomizerTest.java
+++ b/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/networking/SharedLocationSecurityGroupCustomizerTest.java
@@ -119,6 +119,18 @@ public class SharedLocationSecurityGroupCustomizerTest {
         assertPermissionsAdded(5, 5, IpProtocol.TCP);
     }
 
+    @Test
+    public  void testDisableFlagDisableCustomizer() {
+        customizer.setEnabled(false);
+        customizer.setUdpPortRanges(ImmutableList.of("55-78"));
+
+        customizer.customize(jcloudsLocation, computeService, mockTemplate);
+        customizer.customize(jcloudsLocation, computeService, mock(JcloudsMachineLocation.class));
+
+        verify(sgCustomizer, never()).customize(jcloudsLocation, computeService, mockTemplate);
+        verify(sgCustomizer, never()).addPermissionsToLocation(any(JcloudsMachineLocation.class),
any(Iterable.class));
+    }
+
     private void assertPermissionsAdded(int expectedFrom, int expectedTo, IpProtocol expectedProtocol)
{
         ArgumentCaptor<List> listArgumentCaptor = ArgumentCaptor.forClass(List.class);
         verify(sgCustomizer).addPermissionsToLocation(any(JcloudsMachineLocation.class),
listArgumentCaptor.capture());


Mime
View raw message