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 2ad6695 GEODE-6505: add more RegionType and type validation (#3416) 2ad6695 is described below commit 2ad6695355a961c5b1d078fb4b2f64862d8bbbac Author: jinmeiliao <jil...@pivotal.io> AuthorDate: Mon Apr 8 22:55:52 2019 -0700 GEODE-6505: add more RegionType and type validation (#3416) --- .../validators/RegionConfigValidator.java | 11 +++++++++++ .../validators/RegionConfigValidatorTest.java | 9 +++++++++ .../geode/cache/configuration/RegionType.java | 21 ++++++++++++--------- .../rest/RegionManagementIntegrationTest.java | 17 +++++++++++++++++ 4 files changed, 49 insertions(+), 9 deletions(-) diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/configuration/validators/RegionConfigValidator.java b/geode-core/src/main/java/org/apache/geode/management/internal/configuration/validators/RegionConfigValidator.java index 63bc3c8..1b411e8 100644 --- a/geode-core/src/main/java/org/apache/geode/management/internal/configuration/validators/RegionConfigValidator.java +++ b/geode-core/src/main/java/org/apache/geode/management/internal/configuration/validators/RegionConfigValidator.java @@ -35,7 +35,18 @@ public class RegionConfigValidator implements ConfigurationValidator<RegionConfi if (config.getType() == null) { RegionType defaultRegion = RegionType.PARTITION; config.setType(defaultRegion); + } else { + String type = config.getType(); + // validate if the type is a valid RegionType. Only types defined in RegionType are supported + // by management v2 api. + try { + RegionType.valueOf(type); + } catch (IllegalArgumentException e) { + throw new IllegalArgumentException( + String.format("Type %s is not supported in Management V2 API.", type)); + } } + } @Override diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/configuration/validators/RegionConfigValidatorTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/configuration/validators/RegionConfigValidatorTest.java index c586a2a..e235653 100644 --- a/geode-core/src/test/java/org/apache/geode/management/internal/configuration/validators/RegionConfigValidatorTest.java +++ b/geode-core/src/test/java/org/apache/geode/management/internal/configuration/validators/RegionConfigValidatorTest.java @@ -46,6 +46,15 @@ public class RegionConfigValidatorTest { } @Test + public void invalidType() throws Exception { + config.setName("regionName"); + config.setType("LOCAL"); + assertThatThrownBy(() -> validator.validate(config)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage("Type LOCAL is not supported in Management V2 API."); + } + + @Test public void defaultsTypeToPartitioned() { config.setName("regionName"); validator.validate(config); diff --git a/geode-management/src/main/java/org/apache/geode/cache/configuration/RegionType.java b/geode-management/src/main/java/org/apache/geode/cache/configuration/RegionType.java index 5a382f0..f192403 100644 --- a/geode-management/src/main/java/org/apache/geode/cache/configuration/RegionType.java +++ b/geode-management/src/main/java/org/apache/geode/cache/configuration/RegionType.java @@ -15,18 +15,21 @@ package org.apache.geode.cache.configuration; +import org.apache.geode.annotations.Experimental; + /** - * Cluster Management V2 API supports all region shortcuts and attributes, but these are the - * recommended types by the Cluster Management V2 API + * these are the region types supported by Cluster Management V2 API. The attributes of these + * region types are the same as their namesakes in RegionShortcut */ +@Experimental public enum RegionType { - /** - * Same as RegionShortCut.PARTITION - */ PARTITION, - - /** - * Same as RegionShortCut.REPLICATE - */ + PARTITION_PROXY, + PARTITION_PROXY_REDUNDANT, + PARTITION_HEAP_LRU, + PARTITION_OVERFLOW, REPLICATE, + REPLICATE_PROXY, + REPLICATE_HEAP_LRU, + REPLICATE_OVERFLOW } diff --git a/geode-web-management/src/integrationTest/java/org/apache/geode/management/internal/rest/RegionManagementIntegrationTest.java b/geode-web-management/src/integrationTest/java/org/apache/geode/management/internal/rest/RegionManagementIntegrationTest.java index 713d6a4..1036f23 100644 --- a/geode-web-management/src/integrationTest/java/org/apache/geode/management/internal/rest/RegionManagementIntegrationTest.java +++ b/geode-web-management/src/integrationTest/java/org/apache/geode/management/internal/rest/RegionManagementIntegrationTest.java @@ -72,6 +72,23 @@ public class RegionManagementIntegrationTest { @Test @WithMockUser + public void invalidType() throws Exception { + RegionConfig regionConfig = new RegionConfig(); + regionConfig.setName("customers"); + regionConfig.setType("LOCAL"); + + ObjectMapper mapper = new ObjectMapper(); + String json = mapper.writeValueAsString(regionConfig); + + context.perform(post("/v2/regions").content(json)) + .andExpect(status().isBadRequest()) + .andExpect(jsonPath("$.statusCode", is("ILLEGAL_ARGUMENT"))) + .andExpect(jsonPath("$.statusMessage", + is("Type LOCAL is not supported in Management V2 API."))); + } + + @Test + @WithMockUser public void ping() throws Exception { context.perform(get("/v2/ping")) .andExpect(content().string("pong"));