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/05/03 21:43:49 UTC

[geode] branch develop updated: GEODE-5032: massage configuration objects for better usability. (#1894)

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 7eded7b  GEODE-5032: massage configuration objects for better usability. (#1894)
7eded7b is described below

commit 7eded7b99d3b87c23f72f8ddfc23e48848d39a2d
Author: jinmeiliao <ji...@pivotal.io>
AuthorDate: Thu May 3 14:43:44 2018 -0700

    GEODE-5032: massage configuration objects for better usability. (#1894)
---
 .../geode/cache/configuration/DeclarableType.java  |  19 ++++
 .../geode/cache/configuration/ParameterType.java   |  55 ++--------
 .../geode/cache/configuration/RegionConfig.java    | 118 ++++++---------------
 .../internal/cli/commands/ConfigurePDXCommand.java |   3 +-
 .../geode/cache/configuration/CacheConfigTest.java |  64 +++++++++--
 5 files changed, 114 insertions(+), 145 deletions(-)

diff --git a/geode-core/src/main/java/org/apache/geode/cache/configuration/DeclarableType.java b/geode-core/src/main/java/org/apache/geode/cache/configuration/DeclarableType.java
index f06b9ac..9934252 100644
--- a/geode-core/src/main/java/org/apache/geode/cache/configuration/DeclarableType.java
+++ b/geode-core/src/main/java/org/apache/geode/cache/configuration/DeclarableType.java
@@ -20,6 +20,8 @@ package org.apache.geode.cache.configuration;
 
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Properties;
+import java.util.stream.Collectors;
 
 import javax.xml.bind.annotation.XmlAccessType;
 import javax.xml.bind.annotation.XmlAccessorType;
@@ -27,6 +29,7 @@ import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlType;
 
 import org.apache.geode.annotations.Experimental;
+import org.apache.geode.management.internal.cli.domain.ClassName;
 
 
 /**
@@ -67,6 +70,22 @@ public class DeclarableType {
   @XmlElement(namespace = "http://geode.apache.org/schema/cache")
   protected List<ParameterType> parameter;
 
+  public DeclarableType() {}
+
+  public DeclarableType(String className) {
+    this.className = className;
+  }
+
+  public DeclarableType(String className, String jsonProperties) {
+    ClassName cn = new ClassName(className, jsonProperties);
+    this.className = cn.getClassName();
+    Properties properties = cn.getInitProperties();
+    parameter = properties.stringPropertyNames().stream()
+        .map(k -> new ParameterType(k, properties.getProperty(k))).collect(Collectors.toList());
+  }
+
+
+
   /**
    * Gets the value of the className property.
    *
diff --git a/geode-core/src/main/java/org/apache/geode/cache/configuration/ParameterType.java b/geode-core/src/main/java/org/apache/geode/cache/configuration/ParameterType.java
index 08c3586..c0e3e56 100644
--- a/geode-core/src/main/java/org/apache/geode/cache/configuration/ParameterType.java
+++ b/geode-core/src/main/java/org/apache/geode/cache/configuration/ParameterType.java
@@ -21,7 +21,6 @@ package org.apache.geode.cache.configuration;
 import javax.xml.bind.annotation.XmlAccessType;
 import javax.xml.bind.annotation.XmlAccessorType;
 import javax.xml.bind.annotation.XmlAttribute;
-import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlType;
 
 import org.apache.geode.annotations.Experimental;
@@ -55,60 +54,18 @@ import org.apache.geode.annotations.Experimental;
  *
  */
 @XmlAccessorType(XmlAccessType.FIELD)
-@XmlType(name = "parameter-type", namespace = "http://geode.apache.org/schema/cache",
-    propOrder = {"string", "declarable"})
+@XmlType(name = "parameter-type", namespace = "http://geode.apache.org/schema/cache")
 @Experimental
-public class ParameterType {
+public class ParameterType extends RegionConfig.Entry.Type {
 
-  @XmlElement(namespace = "http://geode.apache.org/schema/cache")
-  protected StringType string;
-  @XmlElement(namespace = "http://geode.apache.org/schema/cache")
-  protected DeclarableType declarable;
   @XmlAttribute(name = "name", required = true)
   protected String name;
 
-  /**
-   * Gets the value of the string property.
-   *
-   * possible object is
-   * {@link StringType }
-   *
-   */
-  public StringType getString() {
-    return string;
-  }
-
-  /**
-   * Sets the value of the string property.
-   *
-   * allowed object is
-   * {@link StringType }
-   *
-   */
-  public void setString(StringType value) {
-    this.string = value;
-  }
+  public ParameterType() {};
 
-  /**
-   * Gets the value of the declarable property.
-   *
-   * possible object is
-   * {@link DeclarableType }
-   *
-   */
-  public DeclarableType getDeclarable() {
-    return declarable;
-  }
-
-  /**
-   * Sets the value of the declarable property.
-   *
-   * allowed object is
-   * {@link DeclarableType }
-   *
-   */
-  public void setDeclarable(DeclarableType value) {
-    this.declarable = value;
+  public ParameterType(String name, String value) {
+    this.name = name;
+    setString(value);
   }
 
   /**
diff --git a/geode-core/src/main/java/org/apache/geode/cache/configuration/RegionConfig.java b/geode-core/src/main/java/org/apache/geode/cache/configuration/RegionConfig.java
index 629012a..eef353b 100644
--- a/geode-core/src/main/java/org/apache/geode/cache/configuration/RegionConfig.java
+++ b/geode-core/src/main/java/org/apache/geode/cache/configuration/RegionConfig.java
@@ -424,18 +424,30 @@ public class RegionConfig implements CacheElement {
   public static class Entry {
 
     @XmlElement(namespace = "http://geode.apache.org/schema/cache", required = true)
-    protected RegionConfig.Entry.Key key;
+    protected RegionConfig.Entry.Type key;
     @XmlElement(namespace = "http://geode.apache.org/schema/cache", required = true)
-    protected RegionConfig.Entry.Value value;
+    protected RegionConfig.Entry.Type value;
+
+    public Entry() {};
+
+    public Entry(String key, String value) {
+      this.key = new Type(key);
+      this.value = new Type(value);
+    }
+
+    public Entry(Type key, Type value) {
+      this.key = key;
+      this.value = value;
+    }
 
     /**
      * Gets the value of the key property.
      *
      * possible object is
-     * {@link RegionConfig.Entry.Key }
+     * {@link RegionConfig.Entry.Type }
      *
      */
-    public RegionConfig.Entry.Key getKey() {
+    public RegionConfig.Entry.Type getKey() {
       return key;
     }
 
@@ -443,10 +455,10 @@ public class RegionConfig implements CacheElement {
      * Sets the value of the key property.
      *
      * allowed object is
-     * {@link RegionConfig.Entry.Key }
+     * {@link RegionConfig.Entry.Type }
      *
      */
-    public void setKey(RegionConfig.Entry.Key value) {
+    public void setKey(RegionConfig.Entry.Type value) {
       this.key = value;
     }
 
@@ -454,10 +466,10 @@ public class RegionConfig implements CacheElement {
      * Gets the value of the value property.
      *
      * possible object is
-     * {@link RegionConfig.Entry.Value }
+     * {@link RegionConfig.Entry.Type }
      *
      */
-    public RegionConfig.Entry.Value getValue() {
+    public RegionConfig.Entry.Type getValue() {
       return value;
     }
 
@@ -465,14 +477,13 @@ public class RegionConfig implements CacheElement {
      * Sets the value of the value property.
      *
      * allowed object is
-     * {@link RegionConfig.Entry.Value }
+     * {@link RegionConfig.Entry.Type }
      *
      */
-    public void setValue(RegionConfig.Entry.Value value) {
+    public void setValue(RegionConfig.Entry.Type value) {
       this.value = value;
     }
 
-
     /**
      * <p>
      * Java class for anonymous complex type.
@@ -497,91 +508,22 @@ public class RegionConfig implements CacheElement {
      */
     @XmlAccessorType(XmlAccessType.FIELD)
     @XmlType(name = "", propOrder = {"string", "declarable"})
-    public static class Key {
-
+    public static class Type {
       @XmlElement(namespace = "http://geode.apache.org/schema/cache")
       protected StringType string;
       @XmlElement(namespace = "http://geode.apache.org/schema/cache")
       protected DeclarableType declarable;
 
-      /**
-       * Gets the value of the string property.
-       *
-       * possible object is
-       * {@link StringType }
-       *
-       */
-      public StringType getString() {
-        return string;
-      }
+      public Type() {}
 
-      /**
-       * Sets the value of the string property.
-       *
-       * allowed object is
-       * {@link StringType }
-       *
-       */
-      public void setString(StringType value) {
-        this.string = value;
+      public Type(String string) {
+        this.string = new StringType(string);
       }
 
-      /**
-       * Gets the value of the declarable property.
-       *
-       * possible object is
-       * {@link DeclarableType }
-       *
-       */
-      public DeclarableType getDeclarable() {
-        return declarable;
-      }
-
-      /**
-       * Sets the value of the declarable property.
-       *
-       * allowed object is
-       * {@link DeclarableType }
-       *
-       */
-      public void setDeclarable(DeclarableType value) {
-        this.declarable = value;
+      public Type(DeclarableType declarable) {
+        this.declarable = declarable;
       }
 
-    }
-
-
-    /**
-     * <p>
-     * Java class for anonymous complex type.
-     *
-     * <p>
-     * The following schema fragment specifies the expected content contained within this class.
-     *
-     * <pre>
-     * &lt;complexType>
-     *   &lt;complexContent>
-     *     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
-     *       &lt;choice>
-     *         &lt;element name="string" type="{http://geode.apache.org/schema/cache}string-type"/>
-     *         &lt;element name="declarable" type="{http://geode.apache.org/schema/cache}declarable-type"/>
-     *       &lt;/choice>
-     *     &lt;/restriction>
-     *   &lt;/complexContent>
-     * &lt;/complexType>
-     * </pre>
-     *
-     *
-     */
-    @XmlAccessorType(XmlAccessType.FIELD)
-    @XmlType(name = "", propOrder = {"string", "declarable"})
-    public static class Value {
-
-      @XmlElement(namespace = "http://geode.apache.org/schema/cache")
-      protected StringType string;
-      @XmlElement(namespace = "http://geode.apache.org/schema/cache")
-      protected DeclarableType declarable;
-
       /**
        * Gets the value of the string property.
        *
@@ -600,8 +542,8 @@ public class RegionConfig implements CacheElement {
        * {@link StringType }
        *
        */
-      public void setString(StringType value) {
-        this.string = value;
+      public void setString(String value) {
+        this.string = new StringType(value);
       }
 
       /**
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ConfigurePDXCommand.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ConfigurePDXCommand.java
index 7775b98..d2e5965 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ConfigurePDXCommand.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ConfigurePDXCommand.java
@@ -24,7 +24,6 @@ import org.springframework.shell.core.annotation.CliOption;
 
 import org.apache.geode.cache.configuration.ParameterType;
 import org.apache.geode.cache.configuration.PdxType;
-import org.apache.geode.cache.configuration.StringType;
 import org.apache.geode.distributed.ConfigurationPersistenceService;
 import org.apache.geode.management.cli.CliMetaData;
 import org.apache.geode.management.cli.Result;
@@ -123,7 +122,7 @@ public class ConfigurePDXCommand extends InternalGfshCommand {
                 finalAutoSerializer.getConfig().entrySet().stream().map(entry -> {
                   ParameterType parameterType = new ParameterType();
                   parameterType.setName((String) entry.getKey());
-                  parameterType.setString(new StringType((String) entry.getValue()));
+                  parameterType.setString((String) entry.getValue());
                   return parameterType;
                 }).collect(Collectors.toList());
             pdxSerializer.getParameter().addAll(parameters);
diff --git a/geode-core/src/test/java/org/apache/geode/cache/configuration/CacheConfigTest.java b/geode-core/src/test/java/org/apache/geode/cache/configuration/CacheConfigTest.java
index 16d96f0..ee0bdfa 100644
--- a/geode-core/src/test/java/org/apache/geode/cache/configuration/CacheConfigTest.java
+++ b/geode-core/src/test/java/org/apache/geode/cache/configuration/CacheConfigTest.java
@@ -17,6 +17,9 @@
 
 package org.apache.geode.cache.configuration;
 
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
@@ -30,25 +33,74 @@ public class CacheConfigTest {
 
   private CacheConfig cacheConfig;
   private JAXBService service;
+  private RegionConfig regionConfig;
 
   @Before
   public void setUp() throws Exception {
     cacheConfig = new CacheConfig("1.0");
     service = new JAXBService(CacheConfig.class);
+    service.validateWithLocalCacheXSD();
+    regionConfig = new RegionConfig();
+    regionConfig.setName("regionA");
+    regionConfig.setRefid("REPLICATE");
+  }
+
+  @After
+  public void tearDown() throws Exception {
+    System.out.println(service.marshall(cacheConfig));
   }
 
   @Test
-  public void invalidIndexType() {
-    RegionConfig regionConfig = new RegionConfig();
-    cacheConfig.getRegion().add(regionConfig);
-    regionConfig.setName("regionA");
-    regionConfig.setRefid("REPLICATE");
+  public void validateIndexType() {
     RegionConfig.Index index = new RegionConfig.Index();
+    cacheConfig.getRegion().add(regionConfig);
     index.setName("indexName");
     index.setKeyIndex(true);
     index.setExpression("expression");
     regionConfig.getIndex().add(index);
+  }
 
-    System.out.println(service.marshall(cacheConfig));
+
+  @Test
+  public void stringType() {
+    String xml =
+        "<cache version=\"1.0\" xsi:schemaLocation=\"http://geode.apache.org/schema/cache http://geode.apache.org/schema/cache/cache-1.0.xsd\" xmlns=\"http://geode.apache.org/schema/cache\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n"
+            + "    <region name=\"regionA\" refid=\"REPLICATE\">\n" + "        <entry>\n"
+            + "            <key>\n" + "                <string>myKey</string>\n"
+            + "            </key>\n" + "            <value>\n" + "                <declarable>\n"
+            + "                    <class-name>org.apache.geode.management.internal.cli.domain.MyCacheListener</class-name>\n"
+            + "                    <parameter name=\"name\">\n"
+            + "                        <string>value</string>\n"
+            + "                    </parameter>\n" + "                </declarable>\n"
+            + "            </value>\n" + "        </entry>\n" + "    </region>\n" + "</cache>";
+    cacheConfig.getRegion().add(regionConfig);
+    RegionConfig.Entry entry = new RegionConfig.Entry();
+    RegionConfig.Entry.Type key = new RegionConfig.Entry.Type("myKey");
+    RegionConfig.Entry.Type value = new RegionConfig.Entry.Type(new DeclarableType(
+        "org.apache.geode.management.internal.cli.domain.MyCacheListener", "{'name':'value'}"));
+
+    entry.setKey(key);
+    entry.setValue(value);
+    regionConfig.getEntry().add(entry);
+
+    // make sure the POJO can marshall to the expected xml
+    assertThat(service.marshall(cacheConfig)).contains(xml);
+    // make sure the xml can be unmarshalled.
+    service.unMarshall(xml);
+  }
+
+  @Test
+  public void entry() {
+    String xml =
+        "<cache version=\"1.0\" xsi:schemaLocation=\"http://geode.apache.org/schema/cache http://geode.apache.org/schema/cache/cache-1.0.xsd\" xmlns=\"http://geode.apache.org/schema/cache\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n"
+            + "    <region name=\"regionA\" refid=\"REPLICATE\">\n" + "        <entry>\n"
+            + "            <key>\n" + "                <string>key</string>\n"
+            + "            </key>\n" + "            <value>\n"
+            + "                <string>value</string>\n" + "            </value>\n"
+            + "        </entry>\n" + "    </region>\n" + "</cache>";
+    cacheConfig.getRegion().add(regionConfig);
+    regionConfig.getEntry().add(new RegionConfig.Entry("key", "value"));
+    assertThat(service.marshall(cacheConfig)).contains(xml);
+    service.unMarshall(xml);
   }
 }

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