@Test public void runOneIteration_addAndRemoveFromMultipleRings() throws Exception { expect(securityGroupService.exists("cassandra_ringName", "dc1")).andReturn(true); expect(securityGroupService.exists("cassandra_ringName", "dc2")).andReturn(true); expect(securityGroupService.exists("cassandra_ringName", "dc3")).andReturn(true); expect(securityGroupService.exists("cassandra_otherRing", "dc1")).andReturn(true); expect(securityGroupService.exists("cassandra_otherRing", "dc2")).andReturn(true); expect(securityGroupService.exists("cassandra_otherRing", "dc4")).andReturn(true); securityGroupStartingRules("ringName", "dc1", groupPermission(7000, "1.1.1.1/32"), groupPermission(7000, "2.2.2.2/32"), groupPermission(7000, "4.4.4.4/32")); securityGroupStartingRules("ringName", "dc2", groupPermission(7000, "1.1.1.1/32"), groupPermission(7000, "2.2.2.2/32"), groupPermission(7000, "3.3.3.3/32"), groupPermission(7000, "4.4.4.4/32")); securityGroupStartingRules("ringName", "dc3", groupPermission(7000, "1.1.1.1/32"), groupPermission(7000, "2.2.2.2/32"), groupPermission(7000, "3.3.3.3/32")); securityGroupStartingRules("otherRing", "dc1", groupPermission(7000, "5.5.5.5/32"), groupPermission(7000, "6.6.6.6/32"), groupPermission(7000, "8.8.8.8/32")); securityGroupStartingRules("otherRing", "dc2", groupPermission(7000, "5.5.5.5/32"), groupPermission(7000, "6.6.6.6/32"), groupPermission(7000, "7.7.7.7/32"), groupPermission(7000, "8.8.8.8/32")); securityGroupStartingRules("otherRing", "dc4", groupPermission(7000, "5.5.5.5/32"), groupPermission(7000, "6.6.6.6/32"), groupPermission(7000, "7.7.7.7/32")); expect(cassandraRingService.findAll()).andReturn(ImmutableSet.of( ringWithInstances("ringName", instance("1.1.1.1", "dc1"), instance("2.2.2.2", "dc2"), instance("3.3.3.3", "dc3")), ringWithInstances("otherRing", instance("5.5.5.5", "dc1"), instance("6.6.6.6", "dc2"), instance("7.7.7.7", "dc4")))); securityGroupService.authorizeIngressRules("cassandra_ringName", "dc1", groupPermission(7000, "3.3.3.3/32")); securityGroupService.revokeIngressRules("cassandra_ringName", "dc1", groupPermission(7000, "4.4.4.4/32")); securityGroupService.revokeIngressRules("cassandra_ringName", "dc2", groupPermission(7000, "4.4.4.4/32")); securityGroupService.authorizeIngressRules("cassandra_otherRing", "dc1", groupPermission(7000, "7.7.7.7/32")); securityGroupService.revokeIngressRules("cassandra_otherRing", "dc1", groupPermission(7000, "8.8.8.8/32")); securityGroupService.revokeIngressRules("cassandra_otherRing", "dc2", groupPermission(7000, "8.8.8.8/32")); replayAll(); service().runOneIteration(); }
@Override public void runOneIteration() { try { for (CassandraRing ring : cassandraRingService.findAll()) { for (String dataCenter : findDataCenters(ring)) { int port = Boolean.TRUE.equals(sslEnabledRings.contains(ring.getName())) ? sslListenPort : listenPort; String securityGroupName = securityGroupForRing(ring); ensureSecurityGroupExists(securityGroupName, dataCenter); updateSecurityGroupRules(securityGroupName, dataCenter, ring.getInstances(), port); } } } catch (ServiceUnavailableException e) { LOG.warn("Unable to update the Cassandra security groups", e); } }
SecurityGroupUpdaterService extends AbstractScheduledService implements ScheduledServiceMBean { @Override public void runOneIteration() { try { for (CassandraRing ring : cassandraRingService.findAll()) { for (String dataCenter : findDataCenters(ring)) { int port = Boolean.TRUE.equals(sslEnabledRings.contains(ring.getName())) ? sslListenPort : listenPort; String securityGroupName = securityGroupForRing(ring); ensureSecurityGroupExists(securityGroupName, dataCenter); updateSecurityGroupRules(securityGroupName, dataCenter, ring.getInstances(), port); } } } catch (ServiceUnavailableException e) { LOG.warn("Unable to update the Cassandra security groups", e); } } }
SecurityGroupUpdaterService extends AbstractScheduledService implements ScheduledServiceMBean { @Override public void runOneIteration() { try { for (CassandraRing ring : cassandraRingService.findAll()) { for (String dataCenter : findDataCenters(ring)) { int port = Boolean.TRUE.equals(sslEnabledRings.contains(ring.getName())) ? sslListenPort : listenPort; String securityGroupName = securityGroupForRing(ring); ensureSecurityGroupExists(securityGroupName, dataCenter); updateSecurityGroupRules(securityGroupName, dataCenter, ring.getInstances(), port); } } } catch (ServiceUnavailableException e) { LOG.warn("Unable to update the Cassandra security groups", e); } } @Inject  SecurityGroupUpdaterService(
      CassandraRingService cassandraRingService,
      SecurityGroupService securityGroupService,
      @Named(SecurityGroupModule.SECURITY_GROUP_DATACENTERS_PROPERTY)
          Function<CassandraInstance, String> dataCenterTransformFunction,
      @Named(SecurityGroupModule.CASSANDRA_GOSSIP_PORT_PROPERTY) int listenPort,
      @Named(SecurityGroupModule.CASSANDRA_SSL_GOSSIP_PORT_PROPERTY) int sslListenPort,
      @Named(SecurityGroupModule.CASSANDRA_RING_SSL_ENABLED) Set<String> sslEnabledRings,
      @Named(SecurityGroupModule.SECURITY_GROUP_UPDATE_PERIOD_PROPERTY) Duration updatePeriod,
      @Named(SecurityGroupModule.SECURITY_GROUP_NAME_PREFIX_PROPERTY) String securityGroupNamePrefix); }
SecurityGroupUpdaterService extends AbstractScheduledService implements ScheduledServiceMBean { @Override public void runOneIteration() { try { for (CassandraRing ring : cassandraRingService.findAll()) { for (String dataCenter : findDataCenters(ring)) { int port = Boolean.TRUE.equals(sslEnabledRings.contains(ring.getName())) ? sslListenPort : listenPort; String securityGroupName = securityGroupForRing(ring); ensureSecurityGroupExists(securityGroupName, dataCenter); updateSecurityGroupRules(securityGroupName, dataCenter, ring.getInstances(), port); } } } catch (ServiceUnavailableException e) { LOG.warn("Unable to update the Cassandra security groups", e); } } @Inject  SecurityGroupUpdaterService(
      CassandraRingService cassandraRingService,
      SecurityGroupService securityGroupService,
      @Named(SecurityGroupModule.SECURITY_GROUP_DATACENTERS_PROPERTY)
          Function<CassandraInstance, String> dataCenterTransformFunction,
      @Named(SecurityGroupModule.CASSANDRA_GOSSIP_PORT_PROPERTY) int listenPort,
      @Named(SecurityGroupModule.CASSANDRA_SSL_GOSSIP_PORT_PROPERTY) int sslListenPort,
      @Named(SecurityGroupModule.CASSANDRA_RING_SSL_ENABLED) Set<String> sslEnabledRings,
      @Named(SecurityGroupModule.SECURITY_GROUP_UPDATE_PERIOD_PROPERTY) Duration updatePeriod,
      @Named(SecurityGroupModule.SECURITY_GROUP_NAME_PREFIX_PROPERTY) String securityGroupNamePrefix); @Override void runOneIteration(); }
SecurityGroupUpdaterService extends AbstractScheduledService implements ScheduledServiceMBean { @Override public void runOneIteration() { try { for (CassandraRing ring : cassandraRingService.findAll()) { for (String dataCenter : findDataCenters(ring)) { int port = Boolean.TRUE.equals(sslEnabledRings.contains(ring.getName())) ? sslListenPort : listenPort; String securityGroupName = securityGroupForRing(ring); ensureSecurityGroupExists(securityGroupName, dataCenter); updateSecurityGroupRules(securityGroupName, dataCenter, ring.getInstances(), port); } } } catch (ServiceUnavailableException e) { LOG.warn("Unable to update the Cassandra security groups", e); } } @Inject  SecurityGroupUpdaterService(
      CassandraRingService cassandraRingService,
      SecurityGroupService securityGroupService,
      @Named(SecurityGroupModule.SECURITY_GROUP_DATACENTERS_PROPERTY)
          Function<CassandraInstance, String> dataCenterTransformFunction,
      @Named(SecurityGroupModule.CASSANDRA_GOSSIP_PORT_PROPERTY) int listenPort,
      @Named(SecurityGroupModule.CASSANDRA_SSL_GOSSIP_PORT_PROPERTY) int sslListenPort,
      @Named(SecurityGroupModule.CASSANDRA_RING_SSL_ENABLED) Set<String> sslEnabledRings,
      @Named(SecurityGroupModule.SECURITY_GROUP_UPDATE_PERIOD_PROPERTY) Duration updatePeriod,
      @Named(SecurityGroupModule.SECURITY_GROUP_NAME_PREFIX_PROPERTY) String securityGroupNamePrefix); @Override void runOneIteration();  }