Github user neykov commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/425#discussion_r89302809
  
    --- Diff: 
locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/networking/JcloudsLocationSecurityGroupCustomizer.java
 ---
    @@ -219,60 +226,62 @@ private SecurityGroup getSecurityGroup(final String 
nodeId, final SecurityGroupE
          * the changes may not be picked up by later customizations, meaning 
the same rule could possibly be
          * added twice, which would fail. A finer grained mechanism would be 
preferable here, but
          * we have no access to the information required, so this brute force 
serializing is required.
    +     * TODO investigate whether this can be improved. Can the 
synchronization be moved to
    +     * the class 
org.apache.brooklyn.location.jclouds.networking.SecurityGroupEditor?
          *
          * @param location Location to gain permissions
          * @param permissions The set of permissions to be applied to the 
location
          */
    -    public JcloudsLocationSecurityGroupCustomizer 
addPermissionsToLocation(final JcloudsMachineLocation location, final 
Iterable<IpPermission> permissions) {
    -        ComputeService computeService = 
location.getParent().getComputeService();
    -        addPermissionsToLocationAndReturnSecurityGroup(computeService, 
location, permissions);
    +    public JcloudsLocationSecurityGroupCustomizer 
addPermissionsToLocation(final JcloudsMachineLocation location,
    +              final Iterable<IpPermission> permissions) {
    +        addPermissionsToLocationAndReturnSecurityGroup(location, 
permissions);
             return this;
         }
     
    -    public Collection<SecurityGroup> 
addPermissionsToLocationAndReturnSecurityGroup(ComputeService computeService, 
final JcloudsMachineLocation location, final Iterable<IpPermission> 
permissions) {
    +    public Collection<SecurityGroup> 
addPermissionsToLocationAndReturnSecurityGroup(
    +        final JcloudsMachineLocation location, final 
Iterable<IpPermission> permissions) {
    +
             synchronized (JcloudsLocationSecurityGroupCustomizer.class) {
    -            String nodeId = location.getNode().getId();
    -            return addPermissionsToLocation(permissions, nodeId, 
computeService).values();
    +            return addPermissionsInternal(permissions, location).values();
             }
         }
    +
         /**
    -     * Removes the given security group permissions from the given node 
with the given compute service.
    +     * Removes the given security group permissions from the given node.
          * <p>
          * Takes no action if the compute service does not have a security 
group extension.
    -     * @param permissions The set of permissions to be removed from the 
location
    -     * @param location Location to remove permissions from
    +     * @param location Location of the node to remove permissions from
    +     * @param permissions The set of permissions to be removed from the 
node
          */
    -    public void removePermissionsFromLocation(final JcloudsMachineLocation 
location, final Iterable<IpPermission> permissions) {
    +    public void removePermissionsFromLocation(JcloudsMachineLocation 
location, Iterable<IpPermission> permissions) {
    +
             synchronized (JcloudsLocationSecurityGroupCustomizer.class) {
    -            ComputeService computeService = 
location.getParent().getComputeService();
    -            String nodeId = location.getNode().getId();
    -            removePermissionsFromLocation(permissions, nodeId, 
computeService);
    +            removePermissionsInternal(location, permissions);
             }
         }
     
         /**
    -     * Removes the given security group permissions from the given node 
with the given compute service.
    +     * Removes the given security group permissions from the given node.
          * <p>
          * Takes no action if the compute service does not have a security 
group extension.
    +     * @param location Location of the node to remove permissions from
          * @param permissions The set of permissions to be removed from the 
node
    -     * @param nodeId The id of the node to update
    -     * @param computeService The compute service to use to apply the 
changes
          */
    -    @VisibleForTesting
    -    void removePermissionsFromLocation(Iterable<IpPermission> permissions, 
final String nodeId, ComputeService computeService) {
    -        if (!computeService.getSecurityGroupExtension().isPresent()) {
    +    private void removePermissionsInternal(JcloudsMachineLocation 
location, Iterable<IpPermission> permissions) {
    +        ComputeService computeService = 
location.getParent().getComputeService();
    +        String nodeId = location.getNode().getId();
    +
    +        final Optional<SecurityGroupExtension> securityApi = 
computeService.getSecurityGroupExtension();
    +        if (!securityApi.isPresent()) {
    --- End diff --
    
    Could check with the editor instead.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to