@EnableClusterAware annotation with remote GFSH started Geode server requires HTTP configuration

395 Views Asked by At

We run a GFSH managed Geode cluster with several .Net clients, and now I am incorporating a new spring boot data Geode client for rSocket web endpoints with webflux. Per this question and this question I want to properly autoconfigure the SDG client application with @EnableClusterAware and @EnableClusterDefinedRegions. When I do so like this:

package app;
.. (imports) ..
@SpringBootApplication
@ComponentScan({"admin", "region", "rsocket", "webflux"}) // scans packages for @ components
@EnableLogging(logLevel="info", logFile="geode.log")
public class Web {

and

package admin;
.. (imports) ..
@EnableClusterAware
@EnableClusterDefinedRegions(clientRegionShortcut=ClientRegionShortcut.CACHING_PROXY)
@UseMemberName("WebServer")
public class ClientCache {

with application.properties

spring.application.name=Web
spring.data.gemfire.pool.locators=1.2.3.4[10334]
spring.data.gemfire.pool.subscription-enabled=true

then the client cache application starts up and it appears to get the DEFAULT pool and connect to the remote GFSH server

INFO  [main] org.apach.geode.cache.clien.inter.PoolImpl 349 start: Pool DEFAULT started with multiuser-authentication=false
INFO  [Cache Client Updater Thread  on 1.2.3.4(UAT:12900)<v1>:41001(version:UNKNOWN[ordinal=105]) port 40404] org.apach.geode.inter.cache.tier.socke.CacheClientUpdater 1581 processMessages: Cache Client Updater Thread  on 1.2.3.4(UAT:12900)<v1>:41001(version:UNKNOWN[ordinal=105]) port 40404 (1.2.3.4:40404) : ready to process messages.

but I am not seeing the server regions being setup per @EnableClusterDefinedRegions. This means that when I navigate to http://localhost:8082/doWork the @RestController endpoint handler fails with:

Error creating bean with name 'MyRestController': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.apache.geode.cache.Region<java.lang.String, region.Object>' available: expected at least 1 bean which qualifies as autowire candidate.

Which is because the server regions are not being initialised. If I add @EnableGemFireHttpSession then I get an error [gemfirePool] is not resolvable as a Pool in the application context and so I define my own pool like @EnableGemFireHttpSession(poolName="webPool") with an additional @Bean:

@Bean("webPool")
PoolFactoryBean sessionPool() {
    PoolFactoryBean pool = new PoolFactoryBean();
    ConnectionEndpoint ce = new ConnectionEndpoint("1.2.3.4", 10334);       
    pool.setSubscriptionEnabled(true);
    pool.addLocators(ce);
    return pool;
} 

and now the @EnableClusterDefinedRegions gets to the server and instantiates all the regions I need for me. Great... but then the show fails with:

WARN  [main] org.sprin.conte.suppo.AbstractApplicationContext 558 refresh: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Failed to start bean 'gemfireClusterSchemaObjectInitializer'; nested exception is org.springframework.web.client.ResourceAccessException: I/O error on POST request for "http://localhost:7070/gemfire/v1/regions": Connection refused: connect; nested exception is java.net.ConnectException: Connection refused: connect

The only solution I can find so far is to remove @EnableClusterAware and use the annotations:

package admin;
.. (imports) ..
@EnableClusterDefinedRegions(clientRegionShortcut=ClientRegionShortcut.CACHING_PROXY)
@UseMemberName("WebServer")
@EnableGemFireHttpSession(poolName="webPool")
public class ClientCache {

which sets up all the regions for me, but then I am running into this issue

In build.gradle I'm using

implementation 'org.springframework.geode:spring-geode-starter:1.2.4.RELEASE'
implementation 'org.springframework.session:spring-session-data-geode:2.2.2.RELEASE'
1

There are 1 best solutions below

1
On

I think there is some confusion around @EnableClusterDefinedRegions. @EnableClusterDefinedRegions uses the regions that are already declared on your server to configure your client regions, not the other way around. What it sounds like you want is @EnableClusterConfiguration, which will push regions defined by your client to the server. However, you don't need to declare @EnableClusterConfiguration explicitly, because @ClusterAware is meta-annotated with @EnableClusterConfiguration.

As for why your regions are not being created, I'm guessing that your region definitions are not being found. I notice your ClientCache class is not annotated with @Component even though you are component scanning its package; is the class in which you defined your region annotate with @Component? If not, try adding it.