@Test public void runOneIteration_missingNecessaryRulesInOnlyOneRegion() throws Exception { securityGroupStartingRules("dc1", groupPermission(7000, "1.1.1.1/32"), groupPermission(7000, "2.2.2.2/32")); securityGroupStartingRules("dc2", groupPermission(7000, "2.2.2.2/32")); expect(securityGroupService.exists("cassandra_ringName", "dc1")).andReturn(true); expect(securityGroupService.exists("cassandra_ringName", "dc2")).andReturn(true); expect(cassandraRingService.findAll()).andReturn(ImmutableSet.of(ringWithInstances( instance("1.1.1.1", "dc1"), instance("2.2.2.2", "dc2")))); securityGroupService.authorizeIngressRules("cassandra_ringName", "dc2", groupPermission(7000, "1.1.1.1/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();  }