You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by ji...@apache.org on 2018/04/06 15:23:12 UTC

[geode] branch develop updated: GEODE-5000: do not request/apply cluster config when creating client … (#1739)

This is an automated email from the ASF dual-hosted git repository.

jinmeiliao pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode.git


The following commit(s) were added to refs/heads/develop by this push:
     new 514b1d3  GEODE-5000: do not request/apply cluster config when creating client … (#1739)
514b1d3 is described below

commit 514b1d3f074421041e593a02bbfae831ab320ea8
Author: jinmeiliao <ji...@pivotal.io>
AuthorDate: Fri Apr 6 08:23:08 2018 -0700

    GEODE-5000: do not request/apply cluster config when creating client … (#1739)
    
    * do not request/apply cluster config when creating client cache.
    * give client cache a no-op security service to avoid NPE.
---
 .../internal/cache/ClusterConfigurationLoader.java |  2 +-
 .../geode/internal/cache/GemFireCacheImpl.java     | 41 ++++++++++++++--------
 .../geode/internal/cache/GemFireCacheImplTest.java | 26 ++++++++++++--
 3 files changed, 51 insertions(+), 18 deletions(-)

diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/ClusterConfigurationLoader.java b/geode-core/src/main/java/org/apache/geode/internal/cache/ClusterConfigurationLoader.java
index 0423964..1a18270 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/ClusterConfigurationLoader.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/ClusterConfigurationLoader.java
@@ -83,7 +83,7 @@ public class ClusterConfigurationLoader {
    */
   public void deployJarsReceivedFromClusterConfiguration(ConfigurationResponse response)
       throws IOException, ClassNotFoundException {
-    logger.info("Requesting cluster configuration");
+    logger.info("deploying jars received from cluster configuration");
     if (response == null) {
       return;
     }
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/GemFireCacheImpl.java b/geode-core/src/main/java/org/apache/geode/internal/cache/GemFireCacheImpl.java
index bac76c8..9ec44f1 100755
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/GemFireCacheImpl.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/GemFireCacheImpl.java
@@ -848,16 +848,21 @@ public class GemFireCacheImpl implements InternalCache, InternalClientCache, Has
       this.system = system;
       this.dm = this.system.getDistributionManager();
 
-      this.configurationResponse = requestSharedConfiguration();
+      if (!isClient) {
+        this.configurationResponse = requestSharedConfiguration();
 
-      // apply the cluster's properties configuration and initialize security using that
-      // configuration
-      ccLoader.applyClusterPropertiesConfiguration(this.configurationResponse,
-          this.system.getConfig());
+        // apply the cluster's properties configuration and initialize security using that
+        // configuration
+        ccLoader.applyClusterPropertiesConfiguration(this.configurationResponse,
+            this.system.getConfig());
 
-      this.securityService =
-          SecurityServiceFactory.create(this.system.getConfig().getSecurityProps(), cacheConfig);
-      this.system.setSecurityService(this.securityService);
+        this.securityService =
+            SecurityServiceFactory.create(this.system.getConfig().getSecurityProps(), cacheConfig);
+        this.system.setSecurityService(this.securityService);
+      } else {
+        // create a no-op security service for client
+        this.securityService = SecurityServiceFactory.create();
+      }
 
       if (!this.isClient && PoolManager.getAll().isEmpty()) {
         // We only support management on members of a distributed system
@@ -1034,7 +1039,7 @@ public class GemFireCacheImpl implements InternalCache, InternalClientCache, Has
    * Request the shared configuration from the locator(s) which have the Cluster config service
    * running
    */
-  private ConfigurationResponse requestSharedConfiguration() {
+  ConfigurationResponse requestSharedConfiguration() {
     final DistributionConfig config = this.system.getConfig();
 
     if (!(this.dm instanceof ClusterDistributionManager)) {
@@ -1216,12 +1221,9 @@ public class GemFireCacheImpl implements InternalCache, InternalClientCache, Has
 
     boolean completedCacheXml = false;
     try {
-      if (this.configurationResponse == null) {
-        // Deploy all the jars from the deploy working dir.
-        ClassPathLoader.getLatest().getJarDeployer().loadPreviouslyDeployedJarsFromDisk();
+      if (!isClient) {
+        applyJarAndXmlFromClusterConfig();
       }
-      ccLoader.applyClusterXmlConfiguration(this, this.configurationResponse,
-          this.system.getConfig().getGroups());
       initializeDeclarativeCache();
       completedCacheXml = true;
     } catch (RuntimeException e) {
@@ -1251,6 +1253,15 @@ public class GemFireCacheImpl implements InternalCache, InternalClientCache, Has
     this.isInitialized = true;
   }
 
+  void applyJarAndXmlFromClusterConfig() {
+    if (this.configurationResponse == null) {
+      // Deploy all the jars from the deploy working dir.
+      ClassPathLoader.getLatest().getJarDeployer().loadPreviouslyDeployedJarsFromDisk();
+    }
+    ccLoader.applyClusterXmlConfiguration(this, this.configurationResponse,
+        this.system.getConfig().getGroups());
+  }
+
   /**
    * Initialize any services that provided as extensions to the cache using the service loader
    * mechanism.
@@ -2114,7 +2125,7 @@ public class GemFireCacheImpl implements InternalCache, InternalClientCache, Has
 
   public void close(String reason, Throwable systemFailureCause, boolean keepAlive,
       boolean keepDS) {
-    this.securityService.close();
+    securityService.close();
 
     if (isClosed()) {
       return;
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/GemFireCacheImplTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/GemFireCacheImplTest.java
index c2233df..b323bd4 100644
--- a/geode-core/src/test/java/org/apache/geode/internal/cache/GemFireCacheImplTest.java
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/GemFireCacheImplTest.java
@@ -16,8 +16,13 @@ package org.apache.geode.internal.cache;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.*;
-import static org.mockito.Mockito.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
 
 import java.io.NotSerializableException;
 import java.util.Properties;
@@ -322,4 +327,21 @@ public class GemFireCacheImplTest {
     serverProps.setProperty("key", "");
     assertFalse(GemFireCacheImpl.isMisConfigured(clusterProps, serverProps, "key"));
   }
+
+  @Test
+  public void clientCacheWouldNotRequestClusterConfig() {
+    // we will need to set the value to true so that we can use a mock cache
+    boolean oldValue = InternalDistributedSystem.ALLOW_MULTIPLE_SYSTEMS;
+    InternalDistributedSystem.ALLOW_MULTIPLE_SYSTEMS = true;
+
+    cache = mock(GemFireCacheImpl.class);
+    when(distributedSystem.getCache()).thenReturn(cache);
+    GemFireCacheImpl.createClient(distributedSystem, null, cacheConfig);
+
+    verify(cache, times(0)).requestSharedConfiguration();
+    verify(cache, times(0)).applyJarAndXmlFromClusterConfig();
+
+    // reset it back to the old value
+    InternalDistributedSystem.ALLOW_MULTIPLE_SYSTEMS = oldValue;
+  }
 }

-- 
To stop receiving notification emails like this one, please contact
jinmeiliao@apache.org.