Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Name can't be set via programmatic configuration #19

Closed
niggoo opened this issue Sep 16, 2018 · 9 comments
Closed

Name can't be set via programmatic configuration #19

niggoo opened this issue Sep 16, 2018 · 9 comments
Labels
Milestone

Comments

@niggoo
Copy link

niggoo commented Sep 16, 2018

Hello everyone!

I'm trying to use hazelcast-eureka-one and hazelcast only programmatically, since I'm using Spring for my DI with the hazelcast-spring.jar, it's enough to configure the appropriate Config Bean and Spring would create a hazelcast instance for me. But whatever I do, I can't seem to get the name of the eureka client instance right.

My setup is: Maven Dependencies

<dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-cache</artifactId>
            <version>2.0.1.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>com.hazelcast</groupId>
            <artifactId>hazelcast</artifactId>
            <version>3.9.3</version>
        </dependency>
        <dependency>
            <groupId>com.hazelcast</groupId>
            <artifactId>hazelcast-spring</artifactId>
            <version>3.9.3</version>
        </dependency>
        <dependency>
            <groupId>com.hazelcast</groupId>
            <artifactId>hazelcast-eureka-one</artifactId>
            <version>1.0.2</version>
        </dependency>
    </dependencies>

With the following Config Bean configuration:

@Configuration
class CacheConfiguration {
    @Bean
    fun configuration(
            @Value("\${eureka.client.serviceUrl.defaultZone:http://127.0.0.1:8761/eureka/}") eurekaServiceUrl: String): Config {
        val config = Config()
        val mapConfig = MapConfig("priorities")
                .setTimeToLiveSeconds(10 * 60)
                .setEvictionPolicy(EvictionPolicy.LRU)
                .setMaxSizeConfig(MaxSizeConfig(10, MaxSizeConfig.MaxSizePolicy.FREE_HEAP_SIZE))
        config.addMapConfig(mapConfig)

        val networkConfig = NetworkConfig()
        val joinConfig = JoinConfig()
        val awsConfig = AwsConfig()
        awsConfig.isEnabled = false
        joinConfig.awsConfig = awsConfig
        val tcpIpConfig = TcpIpConfig()
        tcpIpConfig.isEnabled = false
        joinConfig.tcpIpConfig = tcpIpConfig
        val multicastConfig = MulticastConfig()
        multicastConfig.isEnabled = false
        joinConfig.multicastConfig = multicastConfig

        val eurekaDiscoveryConfig = DiscoveryConfig()
        val eurekaDiscoveryStrategyConfig = DiscoveryStrategyConfig(com.hazelcast.eureka.one.EurekaOneDiscoveryStrategyFactory(),
                mapOf(
                        "use-classpath-eureka-client-props" to false,
                        "shouldUseDns" to false,
                        "name" to "hazelcast-cache-cluster",
                        "serviceUrl.default" to eurekaServiceUrl
                ) as Map<String, Comparable<Any?>>?)
        eurekaDiscoveryConfig.discoveryStrategyConfigs.add(eurekaDiscoveryStrategyConfig)
        
        joinConfig.discoveryConfig = eurekaDiscoveryConfig
        networkConfig.join = joinConfig
        config.networkConfig = networkConfig

        config.setProperty("hazelcast.discovery.enabled", "true")

        return config
    }
}

So this setup basically works fine, its just that the name of the eureka instance is always UNKNOWN.
When i have eureka-client.properties in place, it just works as expected and the name of the eureka client instance is set correctly.

hazelcast.shouldUseDns=false
hazelcast.name=hazelcast-cache-cluster
hazelcast.serviceUrl.default=http://127.0.0.1:8761/eureka/

Now i debugged through this a little, and the cause seems to be that the name property gets filtered out as to when it gets passed down to the discovery strategy, and I also now know that the file based approach works cause when MyDataCenterInstanceConfig is instantiated, it passes the namespace to the PropertiesInstanceConfig which in turn uses the Archaius1Utils.initConfig(CommonConstants.CONFIG_FILE_NAME) method call to search for the properties file "eureka-client" on the classpath and read the data.

The problem for me now is that I would also like to set a name programmatically, but I really have no clue on how this should be fixed, or even if it is supposed to be this way?

Anyways, thanks for any help in advance!

@googlielmo googlielmo added the bug label Sep 17, 2018
@googlielmo
Copy link
Contributor

Hi @niggoo
Thank you for reporting this and especially for the additional information!
Looks like a defect. We'll take a look.

@mesutcelik mesutcelik added this to the 1.1 milestone Sep 18, 2018
@y986873c
Copy link

y986873c commented Nov 19, 2018

Hi @niggoo

I am facing the similar problem adding configs programmatically but the error I see is slightly different from OP's. When I use a eureka-client.properties file in classpath, everything works fine but when I remove the eureka-client.properties file and try to put those properties in my Java code, it keeps complaining "Cannot locate eureka-client.properties as a classpath resource.". below is my configuration code:
` // disable below discovery modes
config.getNetworkConfig().setPortAutoIncrement(true);
config.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(false);
config.getNetworkConfig().getJoin().getTcpIpConfig().setEnabled(false);
config.getNetworkConfig().getJoin().getAwsConfig().setEnabled(false);

    // enable the Eureka discovery mode
    config.setProperty("hazelcast.discovery.enabled", Boolean.TRUE.toString());
    EurekaOneDiscoveryStrategyFactory eurekaStrategyFactory = new 
                   EurekaOneDiscoveryStrategyFactory();
    Map<String, Comparable> properties = new HashMap<String, Comparable>() {
    	{
    		put("self-registration", Boolean.TRUE.toString());
    		put("use-classpath-eureka-client-props", Boolean.FALSE.toString());
    		put("shouldUseDns", "false");
    		put("name", "hazelcast-cluster");
    		put("serviceUrl.default", "http://localhost:8101/eureka");	
    	}
    };
    
    DiscoveryStrategyConfig discoveryStrategyConfig = new 
                                 DiscoveryStrategyConfig(eurekaStrategyFactory, properties);
    config.getNetworkConfig().getJoin().getDiscoveryConfig()
                  .addDiscoveryStrategyConfig(discoveryStrategyConfig);`

I stepped into the code and realised that most of my properties defined in the map were filtered out in

DefaultDiscoveryService.buildProperties(DiscoveryStrategyFactory, DiscoveryStrategyConfig, String)

where only two properties are reserved:
`public class EurekaOneDiscoveryStrategyFactory
implements DiscoveryStrategyFactory {

private static final Collection<PropertyDefinition> PROPERTY_DEFINITIONS = Lists.newArrayList(
        EurekaOneProperties.SELF_REGISTRATION,
        EurekaOneProperties.NAMESPACE);`

I did not debugger deeper and just wondered if this was a bug because whatever I put in the properties (other than the two reserved), they just got filtered out and the attribute "use-classpath-eureka-client-props" did not take effect.

Thank you and look forward your reply.

ps. my Hazelcast related dependencies:
compile group: 'com.hazelcast', name: 'hazelcast', version: '3.8.2' compile("com.hazelcast:hazelcast-eureka-one:1.0.1") { exclude group: 'com.hazelcast', module: 'hazelcast' }

ps2. I have also tried the latest Hazelcast 3.11, and that version would even throw an exception when it finds 'unknown' properties.

@leszko leszko modified the milestones: 1.1, 1.1.1 Jan 30, 2019
@OlegKuts
Copy link

Any update on this bug? Facing it too for hazelcast versions 3.9-3.11.1 and hazelcast-eureka-one 1.0.2 - 1.1. When using lower hazelcast vesrion - it does not let me set properties programmatically from Java code.
For hazelcast 3.11.1 I get next exception:

Caused by: com.hazelcast.config.InvalidConfigurationException: Unknown properties: '[name]' on discovery strategy

@googlielmo
Copy link
Contributor

Hi @OlegKuts
Looks like what @y986873c mentioned – only two properties were reserved – was already fixed in 1.0.2.
In the current release only the original issue about the name still remains to be fixed. It's next on our list, so stay tuned.

googlielmo added a commit to googlielmo/hazelcast-eureka that referenced this issue Feb 14, 2019
 - name property is now configuring App name as expected
@OlegKuts
Copy link

Good news. This fix will be available in new hazelcast-eureka-one release?

@mesutcelik
Copy link
Contributor

yes. It is available in 1.1.1 release. please see the release notes

@OlegKuts
Copy link

@mesutcelik hey, thanks for quick reply. Is 1.1.1 available in maven repository? Was not able to find it there, nor update my current version in project.

@mesutcelik
Copy link
Contributor

I see.
@googlielmo ?

@googlielmo
Copy link
Contributor

googlielmo commented Mar 25, 2019

@OlegKuts thanks for reporting! We had issues during publishing to central, should be okay now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants