@Bean public DiscoveryStrategyFactory discoveryStrategyFactory () { return new DiscoveryStrategyFactory() { @Override public Class<? extends DiscoveryStrategy> getDiscoveryStrategyType () { return EurekaDiscoveryStrategy.class; } @Override public DiscoveryStrategy newDiscoveryStrategy (DiscoveryNode discoveryNode, ILogger logger, Map<String, Comparable> properties ) { val eurekaDiscoveryStrategy = new EurekaDiscoveryStrategy(logger, emptyMap()); eurekaDiscoveryStrategy.setDiscoveryClient(discoveryClient); eurekaDiscoveryStrategy.setHaselcastNodeServiceId(applicationName); return eurekaDiscoveryStrategy; } @Override public Collection<PropertyDefinition> getConfigurationProperties () { return null; } }; }
protected <T extends Comparable> T getOrDefault(Map<String, Comparable> properties, String prefix, PropertyDefinition property, T defaultValue) { if (property == null) { return defaultValue; } Comparable value = readProperty(prefix, property); if (value == null) { value = properties.get(property.key()); } if (value == null) { return defaultValue; } return (T) value; }
private Comparable readProperty(String prefix, PropertyDefinition property) { if (prefix != null) { String p = getProperty(prefix, property); String v = System.getProperty(p); if (StringUtil.isNullOrEmpty(v)) { v = System.getenv(p); if (StringUtil.isNullOrEmpty(v)) { v = System.getenv(cIdentifierLike(p)); } } if (!StringUtil.isNullOrEmpty(v)) { return property.typeConverter().convert(v); } } return null; }
@Override public Collection<PropertyDefinition> getConfigurationProperties() { final AwsProperties[] props = AwsProperties.values(); final ArrayList<PropertyDefinition> definitions = new ArrayList<PropertyDefinition>(props.length); for (AwsProperties prop : props) { definitions.add(prop.getDefinition()); } return definitions; }
@Test public void parseDiscoveryStrategyConfigPasses() { final AwsDiscoveryStrategyFactory factory = new AwsDiscoveryStrategyFactory(); final Config config = createConfig("test-aws-config.xml"); final JoinConfig joinConfig = config.getNetworkConfig().getJoin(); assertFalse(joinConfig.getAwsConfig().isEnabled()); assertFalse(joinConfig.getTcpIpConfig().isEnabled()); assertFalse(joinConfig.getMulticastConfig().isEnabled()); final DiscoveryConfig discoveryConfig = joinConfig.getDiscoveryConfig(); assertTrue(discoveryConfig.isEnabled()); assertEquals(1, discoveryConfig.getDiscoveryStrategyConfigs().size()); final DiscoveryStrategyConfig providerConfig = discoveryConfig.getDiscoveryStrategyConfigs().iterator().next(); final Map<String, Comparable> providerProperties = providerConfig.getProperties(); final Collection<PropertyDefinition> factoryConfigProperties = factory.getConfigurationProperties(); assertEquals(factory.getDiscoveryStrategyType(), AwsDiscoveryStrategy.class); assertEquals(AwsDiscoveryStrategy.class.getName(), providerConfig.getClassName()); assertEquals(factoryConfigProperties.size(), providerProperties.size()); for (AwsProperties prop : AwsProperties.values()) { assertTrue(factoryConfigProperties.contains(prop.getDefinition())); } assertEquals("test-access-key", providerProperties.get("access-key")); assertEquals("test-secret-key", providerProperties.get("secret-key")); assertEquals("test-region", providerProperties.get("region")); assertEquals("test-iam-role", providerProperties.get("iam-role")); assertEquals("ec2.test-host-header", providerProperties.get("host-header")); assertEquals("test-security-group-name", providerProperties.get("security-group-name")); assertEquals("test-tag-key", providerProperties.get("tag-key")); assertEquals("test-tag-value", providerProperties.get("tag-value")); assertEquals("10", providerProperties.get("connection-timeout-seconds")); assertEquals("5702", providerProperties.get("hz-port")); }
private <T extends Comparable> T getOrDefault(PropertyDefinition property, T defaultValue) { if (properties == null || property == null) { return defaultValue; } Comparable value = properties.get(property.key()); if (value == null) { return defaultValue; } return (T) value; }
public ConsulDiscoveryFactory() { List<PropertyDefinition> properties = new ArrayList<>(); properties.add(new SimplePropertyDefinition("host", PropertyTypeConverter.STRING)); properties.add(new SimplePropertyDefinition("port", PropertyTypeConverter.INTEGER)); properties.add(new SimplePropertyDefinition("name", PropertyTypeConverter.STRING)); this.propertyDefinitions = Collections.unmodifiableCollection(properties); }
private String getProperty(String prefix, PropertyDefinition property) { StringBuilder sb = new StringBuilder(prefix); if (prefix.charAt(prefix.length() - 1) != '.') { sb.append('.'); } return sb.append(property.key()).toString(); }
@Test public void checkProperties() { HazelcastKubernetesDiscoveryStrategyFactory factory = new HazelcastKubernetesDiscoveryStrategyFactory(); Collection<PropertyDefinition> propertyDefinitions = factory.getConfigurationProperties(); assertTrue(propertyDefinitions.contains(KubernetesProperties.SERVICE_DNS)); assertTrue(propertyDefinitions.contains(KubernetesProperties.SERVICE_PORT)); }
public Collection<PropertyDefinition> getConfigurationProperties() { return PROPERTIES; }
private static PropertyDefinition property(String key, PropertyTypeConverter typeConverter) { return property(key, typeConverter, null); }
private static PropertyDefinition property(String key, PropertyTypeConverter typeConverter, ValueValidator valueValidator) { return new SimplePropertyDefinition(key, true, typeConverter, valueValidator); }
public Collection<PropertyDefinition> getConfigurationProperties() { return PROPERTY_DEFINITIONS; }
@Override public Collection<PropertyDefinition> getConfigurationProperties() { return PROPERTY_DEFINITIONS; }
private static PropertyDefinition property(String key, TypeConverter typeConverter) { return new SimplePropertyDefinition(key, true, typeConverter); }
public HerokuDiscoveryStrategyFactory() { this.propertyDefinitions = Collections.unmodifiableCollection( new ArrayList<PropertyDefinition>() ); }
@Override public Collection<PropertyDefinition> getConfigurationProperties() { return propertyDefinitions; }
private <T extends Comparable> T getOrNull(PropertyDefinition property) { return getOrDefault(property, null); }
@Override public Collection<PropertyDefinition> configurationProperties() { return propertyDefinitions; }
protected <T extends Comparable> T getOrNull(Map<String, Comparable> properties, String prefix, PropertyDefinition property) { return getOrDefault(properties, prefix, property, null); }
@Override public Collection<PropertyDefinition> getConfigurationProperties() { return Collections.emptySet(); }