geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jinmeil...@apache.org
Subject [geode] branch feature/GEODE-6574-cms-list-members updated: remove the runtime config and configure the json mapper to be able to deserialize json string without type info.
Date Mon, 01 Apr 2019 21:06:39 GMT
This is an automated email from the ASF dual-hosted git repository.

jinmeiliao pushed a commit to branch feature/GEODE-6574-cms-list-members
in repository https://gitbox.apache.org/repos/asf/geode.git


The following commit(s) were added to refs/heads/feature/GEODE-6574-cms-list-members by this
push:
     new 650c757  remove the runtime config and configure the json mapper to be able to deserialize
json string without type info.
650c757 is described below

commit 650c7572747d39f58331b6cf883c85720cd9040c
Author: Jinmei Liao <jiliao@pivotal.io>
AuthorDate: Mon Apr 1 14:05:58 2019 -0700

    remove the runtime config and configure the json mapper to be able to deserialize json
string without type info.
---
 .../integrationTest/resources/assembly_content.txt |  2 --
 geode-common/build.gradle                          |  1 +
 .../geode/util/internal/GeodeJsonMapper.java       | 27 ++++++++++++++--------
 .../cli/converters/PoolPropertyConverter.java      |  7 ++----
 .../api/LocatorClusterManagementService.java       |  3 +--
 .../cli/converters/ConfigPropertyConverter.java    |  7 ++----
 .../cli/functions/DataCommandFunction.java         |  5 ++--
 .../cache/configuration/RegionConfigTest.java      |  3 ++-
 .../geode/cache/configuration/CacheElement.java    |  6 ++++-
 .../management/api/ClusterManagementResult.java    |  8 +++----
 .../management/configuration/MemberConfig.java     |  3 ++-
 .../configuration/RuntimeCacheElement.java         | 26 ---------------------
 .../management/internal/cli/domain/ClassName.java  |  9 +++-----
 .../configuration/CacheElementJsonMappingTest.java | 18 +++++----------
 .../webapp/WEB-INF/geode-management-servlet.xml    |  1 +
 15 files changed, 48 insertions(+), 78 deletions(-)

diff --git a/geode-assembly/src/integrationTest/resources/assembly_content.txt b/geode-assembly/src/integrationTest/resources/assembly_content.txt
index 9d583ad..9b8a35f 100644
--- a/geode-assembly/src/integrationTest/resources/assembly_content.txt
+++ b/geode-assembly/src/integrationTest/resources/assembly_content.txt
@@ -706,8 +706,6 @@ javadoc/org/apache/geode/management/client/package-frame.html
 javadoc/org/apache/geode/management/client/package-summary.html
 javadoc/org/apache/geode/management/client/package-tree.html
 javadoc/org/apache/geode/management/configuration/MemberConfig.html
-javadoc/org/apache/geode/management/configuration/RegionRuntimeConfig.html
-javadoc/org/apache/geode/management/configuration/RuntimeCacheElement.html
 javadoc/org/apache/geode/management/configuration/package-frame.html
 javadoc/org/apache/geode/management/configuration/package-summary.html
 javadoc/org/apache/geode/management/configuration/package-tree.html
diff --git a/geode-common/build.gradle b/geode-common/build.gradle
index 6a2ed39..9bf17b1 100755
--- a/geode-common/build.gradle
+++ b/geode-common/build.gradle
@@ -19,6 +19,7 @@ apply from: "${project.projectDir}/../gradle/publish.gradle"
 
 dependencies {
   compile(platform(project(':boms:geode-all-bom')))
+  compile('com.fasterxml.jackson.core:jackson-databind')
   testCompile('junit:junit')
   testCompile('org.assertj:assertj-core')
 }
diff --git a/geode-management/src/main/java/org/apache/geode/management/configuration/RegionRuntimeConfig.java
b/geode-common/src/main/java/org/apache/geode/util/internal/GeodeJsonMapper.java
similarity index 51%
rename from geode-management/src/main/java/org/apache/geode/management/configuration/RegionRuntimeConfig.java
rename to geode-common/src/main/java/org/apache/geode/util/internal/GeodeJsonMapper.java
index d57591c..7fd8f91 100644
--- a/geode-management/src/main/java/org/apache/geode/management/configuration/RegionRuntimeConfig.java
+++ b/geode-common/src/main/java/org/apache/geode/util/internal/GeodeJsonMapper.java
@@ -13,18 +13,25 @@
  * the License.
  */
 
-package org.apache.geode.management.configuration;
+package org.apache.geode.util.internal;
 
-import org.apache.geode.cache.configuration.RegionConfig;
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.databind.MapperFeature;
+import com.fasterxml.jackson.databind.ObjectMapper;
 
-public class RegionRuntimeConfig extends RegionConfig implements RuntimeCacheElement {
-  private int entryCount;
-
-  public int getEntryCount() {
-    return entryCount;
-  }
+/**
+ * helper class for creating various json mappers used by Geode Project
+ */
+public class GeodeJsonMapper {
 
-  public void setEntryCount(int entryCount) {
-    this.entryCount = entryCount;
+  /**
+   * @return a jackson json mapper that allows single quotes and is able to deserialize json
+   *         string without @JsonTypeInfo if base class is a concrete implementation.
+   */
+  public static ObjectMapper getMapper() {
+    ObjectMapper mapper = new ObjectMapper();
+    mapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);
+    mapper.configure(MapperFeature.USE_BASE_TYPE_AS_DEFAULT_IMPL, true);
+    return mapper;
   }
 }
diff --git a/geode-connectors/src/main/java/org/apache/geode/management/internal/cli/converters/PoolPropertyConverter.java
b/geode-connectors/src/main/java/org/apache/geode/management/internal/cli/converters/PoolPropertyConverter.java
index d99709c..6127a18 100644
--- a/geode-connectors/src/main/java/org/apache/geode/management/internal/cli/converters/PoolPropertyConverter.java
+++ b/geode-connectors/src/main/java/org/apache/geode/management/internal/cli/converters/PoolPropertyConverter.java
@@ -17,13 +17,13 @@ package org.apache.geode.management.internal.cli.converters;
 import java.io.IOException;
 import java.util.List;
 
-import com.fasterxml.jackson.core.JsonParser;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import org.springframework.shell.core.Completion;
 import org.springframework.shell.core.Converter;
 import org.springframework.shell.core.MethodTarget;
 
 import org.apache.geode.connectors.jdbc.internal.cli.CreateDataSourceCommand;
+import org.apache.geode.util.internal.GeodeJsonMapper;
 
 /***
  * Converter for CreateDataSourceCommand's --pool-properties option.
@@ -32,10 +32,7 @@ import org.apache.geode.connectors.jdbc.internal.cli.CreateDataSourceCommand;
 public class PoolPropertyConverter
     implements Converter<CreateDataSourceCommand.PoolProperty> {
 
-  private static final ObjectMapper mapper = new ObjectMapper();
-  static {
-    mapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);
-  }
+  private static final ObjectMapper mapper = GeodeJsonMapper.getMapper();
 
   @Override
   public boolean supports(Class<?> type, String optionContext) {
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/api/LocatorClusterManagementService.java
b/geode-core/src/main/java/org/apache/geode/management/internal/api/LocatorClusterManagementService.java
index 318b4fe..511cc3f 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/api/LocatorClusterManagementService.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/api/LocatorClusterManagementService.java
@@ -38,7 +38,6 @@ import org.apache.geode.internal.logging.LogService;
 import org.apache.geode.management.api.ClusterManagementResult;
 import org.apache.geode.management.api.ClusterManagementService;
 import org.apache.geode.management.configuration.MemberConfig;
-import org.apache.geode.management.configuration.RuntimeCacheElement;
 import org.apache.geode.management.internal.cli.CliUtil;
 import org.apache.geode.management.internal.cli.functions.CliFunctionResult;
 import org.apache.geode.management.internal.cli.functions.UpdateCacheFunction;
@@ -154,7 +153,7 @@ public class LocatorClusterManagementService implements ClusterManagementService
   @Override
   public ClusterManagementResult list(CacheElement filter) {
     ConfigurationManager manager = managers.get(filter.getClass());
-    List<RuntimeCacheElement> listResults = manager.list(filter, null);
+    List<CacheElement> listResults = manager.list(filter, null);
 
     ClusterManagementResult result = new ClusterManagementResult();
     result.setResult(listResults);
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/converters/ConfigPropertyConverter.java
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/converters/ConfigPropertyConverter.java
index 8a17f3c..adff1ea 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/converters/ConfigPropertyConverter.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/converters/ConfigPropertyConverter.java
@@ -17,7 +17,6 @@ package org.apache.geode.management.internal.cli.converters;
 import java.io.IOException;
 import java.util.List;
 
-import com.fasterxml.jackson.core.JsonParser;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import org.springframework.shell.core.Completion;
 import org.springframework.shell.core.Converter;
@@ -25,6 +24,7 @@ import org.springframework.shell.core.MethodTarget;
 
 import org.apache.geode.annotations.Immutable;
 import org.apache.geode.cache.configuration.JndiBindingsType;
+import org.apache.geode.util.internal.GeodeJsonMapper;
 
 /***
  * Added converter to enable auto-completion for index-type
@@ -34,10 +34,7 @@ public class ConfigPropertyConverter
     implements Converter<JndiBindingsType.JndiBinding.ConfigProperty> {
 
   @Immutable
-  private static final ObjectMapper mapper = new ObjectMapper();
-  static {
-    mapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);
-  }
+  private static final ObjectMapper mapper = GeodeJsonMapper.getMapper();
 
   @Override
   public boolean supports(Class<?> type, String optionContext) {
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/DataCommandFunction.java
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/DataCommandFunction.java
index 3da2b6a..95c4caa 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/DataCommandFunction.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/DataCommandFunction.java
@@ -22,7 +22,6 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
-import com.fasterxml.jackson.core.JsonParser;
 import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import org.apache.commons.lang3.StringUtils;
@@ -59,6 +58,7 @@ import org.apache.geode.management.internal.cli.i18n.CliStrings;
 import org.apache.geode.management.internal.cli.util.JsonUtil;
 import org.apache.geode.pdx.JSONFormatter;
 import org.apache.geode.pdx.PdxInstance;
+import org.apache.geode.util.internal.GeodeJsonMapper;
 
 /**
  * @since GemFire 7.0
@@ -586,8 +586,7 @@ public class DataCommandFunction implements InternalFunction {
 
     Object resultObject;
     try {
-      ObjectMapper mapper = new ObjectMapper();
-      mapper.enable(JsonParser.Feature.ALLOW_SINGLE_QUOTES);
+      ObjectMapper mapper = GeodeJsonMapper.getMapper();
       resultObject = mapper.readValue(string, klass);
     } catch (IOException e) {
       throw new IllegalArgumentException(
diff --git a/geode-core/src/test/java/org/apache/geode/cache/configuration/RegionConfigTest.java
b/geode-core/src/test/java/org/apache/geode/cache/configuration/RegionConfigTest.java
index 3948abe..62dd8c3 100644
--- a/geode-core/src/test/java/org/apache/geode/cache/configuration/RegionConfigTest.java
+++ b/geode-core/src/test/java/org/apache/geode/cache/configuration/RegionConfigTest.java
@@ -27,6 +27,7 @@ import org.junit.Test;
 
 import org.apache.geode.cache.RegionShortcut;
 import org.apache.geode.internal.config.JAXBService;
+import org.apache.geode.util.internal.GeodeJsonMapper;
 
 public class RegionConfigTest {
 
@@ -76,7 +77,7 @@ public class RegionConfigTest {
   @Test
   public void correctJsonAndXml() throws Exception {
     String json = "{\"name\":\"test\", \"type\":\"REPLICATE\"}";
-    ObjectMapper mapper = new ObjectMapper();
+    ObjectMapper mapper = GeodeJsonMapper.getMapper();
     regionConfig = mapper.readValue(json, RegionConfig.class);
     assertThat(regionConfig.getName()).isEqualTo("test");
     assertThat(regionConfig.getType()).isEqualTo("REPLICATE");
diff --git a/geode-management/src/main/java/org/apache/geode/cache/configuration/CacheElement.java
b/geode-management/src/main/java/org/apache/geode/cache/configuration/CacheElement.java
index 1144d0a..6ab7173 100644
--- a/geode-management/src/main/java/org/apache/geode/cache/configuration/CacheElement.java
+++ b/geode-management/src/main/java/org/apache/geode/cache/configuration/CacheElement.java
@@ -20,9 +20,13 @@ package org.apache.geode.cache.configuration;
 import java.io.Serializable;
 import java.util.List;
 
-import org.apache.geode.lang.Identifiable;
+import com.fasterxml.jackson.annotation.JsonTypeInfo;
 
+import org.apache.geode.annotations.Experimental;
+import org.apache.geode.lang.Identifiable;
 
+@Experimental
+@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, property = "class")
 public interface CacheElement extends Identifiable<String>, Serializable {
 
   static <T extends CacheElement> boolean exists(List<T> list, String id) {
diff --git a/geode-management/src/main/java/org/apache/geode/management/api/ClusterManagementResult.java
b/geode-management/src/main/java/org/apache/geode/management/api/ClusterManagementResult.java
index 53351ce..2f61e8d 100644
--- a/geode-management/src/main/java/org/apache/geode/management/api/ClusterManagementResult.java
+++ b/geode-management/src/main/java/org/apache/geode/management/api/ClusterManagementResult.java
@@ -21,7 +21,7 @@ import java.util.Map;
 
 import com.fasterxml.jackson.annotation.JsonIgnore;
 
-import org.apache.geode.management.configuration.RuntimeCacheElement;
+import org.apache.geode.cache.configuration.CacheElement;
 
 
 public class ClusterManagementResult {
@@ -58,7 +58,7 @@ public class ClusterManagementResult {
   private StatusCode statusCode = StatusCode.OK;
   private String statusMessage;
 
-  private List<RuntimeCacheElement> result = new ArrayList<>();
+  private List<CacheElement> result = new ArrayList<>();
 
   public ClusterManagementResult() {}
 
@@ -108,11 +108,11 @@ public class ClusterManagementResult {
     return statusCode;
   }
 
-  public List<RuntimeCacheElement> getResult() {
+  public List<CacheElement> getResult() {
     return result;
   }
 
-  public void setResult(List<RuntimeCacheElement> result) {
+  public void setResult(List<CacheElement> result) {
     this.result = result;
   }
 }
diff --git a/geode-management/src/main/java/org/apache/geode/management/configuration/MemberConfig.java
b/geode-management/src/main/java/org/apache/geode/management/configuration/MemberConfig.java
index 5ddc856..174d79a 100644
--- a/geode-management/src/main/java/org/apache/geode/management/configuration/MemberConfig.java
+++ b/geode-management/src/main/java/org/apache/geode/management/configuration/MemberConfig.java
@@ -18,10 +18,11 @@ package org.apache.geode.management.configuration;
 import java.util.List;
 
 import org.apache.geode.annotations.Experimental;
+import org.apache.geode.cache.configuration.CacheElement;
 import org.apache.geode.management.api.RestfulEndpoint;
 
 @Experimental
-public class MemberConfig implements RuntimeCacheElement, RestfulEndpoint {
+public class MemberConfig implements CacheElement, RestfulEndpoint {
 
   private static final long serialVersionUID = -6262538068604902018L;
 
diff --git a/geode-management/src/main/java/org/apache/geode/management/configuration/RuntimeCacheElement.java
b/geode-management/src/main/java/org/apache/geode/management/configuration/RuntimeCacheElement.java
deleted file mode 100644
index 0d0b6b6..0000000
--- a/geode-management/src/main/java/org/apache/geode/management/configuration/RuntimeCacheElement.java
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
- * agreements. See the NOTICE file distributed with this work for additional information
regarding
- * copyright ownership. The ASF licenses this file to You under the Apache License, Version
2.0 (the
- * "License"); you may not use this file except in compliance with the License. You may obtain
a
- * copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software distributed under
the License
- * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
express
- * or implied. See the License for the specific language governing permissions and limitations
under
- * the License.
- */
-
-package org.apache.geode.management.configuration;
-
-import com.fasterxml.jackson.annotation.JsonTypeInfo;
-
-import org.apache.geode.annotations.Experimental;
-import org.apache.geode.cache.configuration.CacheElement;
-
-@Experimental
-@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, property = "class")
-public interface RuntimeCacheElement extends CacheElement {
-}
diff --git a/geode-management/src/main/java/org/apache/geode/management/internal/cli/domain/ClassName.java
b/geode-management/src/main/java/org/apache/geode/management/internal/cli/domain/ClassName.java
index 362a4ce..8510c81 100644
--- a/geode-management/src/main/java/org/apache/geode/management/internal/cli/domain/ClassName.java
+++ b/geode-management/src/main/java/org/apache/geode/management/internal/cli/domain/ClassName.java
@@ -21,10 +21,11 @@ import java.util.Objects;
 import java.util.Properties;
 import java.util.regex.Pattern;
 
-import com.fasterxml.jackson.core.JsonParser;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import org.apache.commons.lang3.StringUtils;
 
+import org.apache.geode.util.internal.GeodeJsonMapper;
+
 /**
  * This is mostly used for Gfsh command options that need to specify a className for instantiation.
  *
@@ -35,11 +36,7 @@ public class ClassName<T> implements Serializable {
 
   private String className = "";
   private Properties initProperties = new Properties();
-  private static ObjectMapper mapper = new ObjectMapper();
-
-  static {
-    mapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);
-  }
+  private static ObjectMapper mapper = GeodeJsonMapper.getMapper();
 
   // used to remove a Declarable through gfsh command
   // e.g. alter region --name=regionA --cache-loader=''
diff --git a/geode-management/src/test/java/org/apache/geode/cache/configuration/CacheElementJsonMappingTest.java
b/geode-management/src/test/java/org/apache/geode/cache/configuration/CacheElementJsonMappingTest.java
index c3acfa5..297fd47 100644
--- a/geode-management/src/test/java/org/apache/geode/cache/configuration/CacheElementJsonMappingTest.java
+++ b/geode-management/src/test/java/org/apache/geode/cache/configuration/CacheElementJsonMappingTest.java
@@ -20,25 +20,19 @@ import static org.assertj.core.api.Assertions.assertThat;
 import java.util.ArrayList;
 import java.util.List;
 
-import com.fasterxml.jackson.core.JsonParser;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import org.junit.BeforeClass;
 import org.junit.Test;
 
 import org.apache.geode.management.api.ClusterManagementResult;
 import org.apache.geode.management.configuration.MemberConfig;
-import org.apache.geode.management.configuration.RegionRuntimeConfig;
-import org.apache.geode.management.configuration.RuntimeCacheElement;
+import org.apache.geode.util.internal.GeodeJsonMapper;
 
 public class CacheElementJsonMappingTest {
-  private static ObjectMapper mapper;
-  static {
-    mapper = new ObjectMapper();
-    mapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);
-  }
+  private static ObjectMapper mapper = GeodeJsonMapper.getMapper();
 
   private static MemberConfig member;
-  private static RegionRuntimeConfig region;
+  private static RegionConfig region;
 
   @BeforeClass
   public static void beforeClass() throws Exception {
@@ -46,7 +40,7 @@ public class CacheElementJsonMappingTest {
     member.setId("server");
     member.setPid("123");
 
-    region = new RegionRuntimeConfig();
+    region = new RegionConfig();
     region.setName("test");
   }
 
@@ -56,7 +50,7 @@ public class CacheElementJsonMappingTest {
     System.out.println(json);
     assertThat(json).contains("class").contains("\"name\":\"test\"");
 
-    RegionConfig config = mapper.readValue(json, RegionRuntimeConfig.class);
+    RegionConfig config = mapper.readValue(json, RegionConfig.class);
     assertThat(config.getName()).isEqualTo(region.getName());
   }
 
@@ -73,7 +67,7 @@ public class CacheElementJsonMappingTest {
   @Test
   public void serializeResult() throws Exception {
     ClusterManagementResult result = new ClusterManagementResult();
-    List<RuntimeCacheElement> elements = new ArrayList<>();
+    List<CacheElement> elements = new ArrayList<>();
     elements.add(region);
     elements.add(member);
     result.setResult(elements);
diff --git a/geode-web-management/src/main/webapp/WEB-INF/geode-management-servlet.xml b/geode-web-management/src/main/webapp/WEB-INF/geode-management-servlet.xml
index 22cae8e..a2cc948 100644
--- a/geode-web-management/src/main/webapp/WEB-INF/geode-management-servlet.xml
+++ b/geode-web-management/src/main/webapp/WEB-INF/geode-management-servlet.xml
@@ -65,6 +65,7 @@
       <array>
         <util:constant static-field="com.fasterxml.jackson.core.JsonParser.Feature.ALLOW_COMMENTS"/>
         <util:constant static-field="com.fasterxml.jackson.core.JsonParser.Feature.ALLOW_SINGLE_QUOTES"/>
+        <util:constant static-field="com.fasterxml.jackson.databind.MapperFeature.USE_BASE_TYPE_AS_DEFAULT_IMPL"/>
         <util:constant static-field="com.fasterxml.jackson.databind.DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT"/>
       </array>
     </property>


Mime
View raw message