This is an automated email from the ASF dual-hosted git repository. dschneider pushed a commit to branch feature/GEODE-5968 in repository https://gitbox.apache.org/repos/asf/geode.git
commit eb2a06cde29ab630c07eca47e3f680ca5ba77a66 Author: Darrel Schneider <dschnei...@pivotal.io> AuthorDate: Thu Nov 1 15:52:19 2018 -0700 removed gfsh alter jdbc-mapping command --- .../internal/cli/AlterMappingCommandDUnitTest.java | 147 ----------- .../cli/AlterMappingCommandIntegrationTest.java | 86 ------ .../cli/JDBCConnectorFunctionsSecurityTest.java | 1 - .../jdbc/internal/cli/AlterMappingCommand.java | 120 --------- .../jdbc/internal/cli/AlterMappingFunction.java | 79 ------ .../org.springframework.shell.core.CommandMarker | 1 - .../sanctioned-geode-connectors-serializables.txt | 1 - .../jdbc/internal/cli/AlterMappingCommandTest.java | 116 --------- .../internal/cli/AlterMappingFunctionTest.java | 288 --------------------- 9 files changed, 839 deletions(-) diff --git a/geode-connectors/src/distributedTest/java/org/apache/geode/connectors/jdbc/internal/cli/AlterMappingCommandDUnitTest.java b/geode-connectors/src/distributedTest/java/org/apache/geode/connectors/jdbc/internal/cli/AlterMappingCommandDUnitTest.java deleted file mode 100644 index f93dc9d..0000000 --- a/geode-connectors/src/distributedTest/java/org/apache/geode/connectors/jdbc/internal/cli/AlterMappingCommandDUnitTest.java +++ /dev/null @@ -1,147 +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.connectors.jdbc.internal.cli; - -import static org.apache.geode.connectors.jdbc.internal.cli.AlterMappingCommand.ALTER_MAPPING; -import static org.apache.geode.connectors.jdbc.internal.cli.AlterMappingCommand.ALTER_MAPPING__CONNECTION_NAME; -import static org.apache.geode.connectors.jdbc.internal.cli.AlterMappingCommand.ALTER_MAPPING__FIELD_MAPPING; -import static org.apache.geode.connectors.jdbc.internal.cli.AlterMappingCommand.ALTER_MAPPING__PDX_CLASS_NAME; -import static org.apache.geode.connectors.jdbc.internal.cli.AlterMappingCommand.ALTER_MAPPING__PRIMARY_KEY_IN_VALUE; -import static org.apache.geode.connectors.jdbc.internal.cli.AlterMappingCommand.ALTER_MAPPING__REGION_NAME; -import static org.apache.geode.connectors.jdbc.internal.cli.AlterMappingCommand.ALTER_MAPPING__TABLE_NAME; -import static org.apache.geode.connectors.jdbc.internal.cli.CreateMappingCommand.CREATE_MAPPING; -import static org.apache.geode.connectors.jdbc.internal.cli.CreateMappingCommand.CREATE_MAPPING__CONNECTION_NAME; -import static org.apache.geode.connectors.jdbc.internal.cli.CreateMappingCommand.CREATE_MAPPING__FIELD_MAPPING; -import static org.apache.geode.connectors.jdbc.internal.cli.CreateMappingCommand.CREATE_MAPPING__PDX_CLASS_NAME; -import static org.apache.geode.connectors.jdbc.internal.cli.CreateMappingCommand.CREATE_MAPPING__REGION_NAME; -import static org.apache.geode.connectors.jdbc.internal.cli.CreateMappingCommand.CREATE_MAPPING__TABLE_NAME; -import static org.apache.geode.connectors.jdbc.internal.cli.CreateMappingCommand.CREATE_MAPPING__VALUE_CONTAINS_PRIMARY_KEY; -import static org.assertj.core.api.Assertions.assertThat; - -import java.util.List; - -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.experimental.categories.Category; - -import org.apache.geode.connectors.jdbc.internal.JdbcConnectorService; -import org.apache.geode.connectors.jdbc.internal.configuration.RegionMapping; -import org.apache.geode.distributed.internal.InternalLocator; -import org.apache.geode.internal.cache.InternalCache; -import org.apache.geode.management.internal.cli.util.CommandStringBuilder; -import org.apache.geode.test.dunit.rules.ClusterStartupRule; -import org.apache.geode.test.dunit.rules.MemberVM; -import org.apache.geode.test.junit.categories.JDBCConnectorTest; -import org.apache.geode.test.junit.rules.GfshCommandRule; -import org.apache.geode.test.junit.rules.serializable.SerializableTestName; - -@Category({JDBCConnectorTest.class}) -public class AlterMappingCommandDUnitTest { - private static final String REGION_NAME = "testRegion"; - - @Rule - public transient GfshCommandRule gfsh = new GfshCommandRule(); - - @Rule - public ClusterStartupRule startupRule = new ClusterStartupRule(); - - @Rule - public SerializableTestName testName = new SerializableTestName(); - - private MemberVM locator; - private MemberVM server; - - @Before - public void before() throws Exception { - locator = startupRule.startLocatorVM(0); - server = startupRule.startServerVM(1, locator.getPort()); - - gfsh.connectAndVerify(locator); - gfsh.executeAndAssertThat("create region --name=" + REGION_NAME + " --type=REPLICATE") - .statusIsSuccess(); - CommandStringBuilder csb = new CommandStringBuilder(CREATE_MAPPING); - csb.addOption(CREATE_MAPPING__REGION_NAME, REGION_NAME); - csb.addOption(CREATE_MAPPING__CONNECTION_NAME, "connection"); - csb.addOption(CREATE_MAPPING__TABLE_NAME, "myTable"); - csb.addOption(CREATE_MAPPING__PDX_CLASS_NAME, "myPdxClass"); - csb.addOption(CREATE_MAPPING__VALUE_CONTAINS_PRIMARY_KEY, "true"); - csb.addOption(CREATE_MAPPING__FIELD_MAPPING, "field1:column1,field2:column2"); - - gfsh.executeAndAssertThat(csb.toString()).statusIsSuccess(); - } - - @Test - public void altersMappingWithNewValues() throws Exception { - CommandStringBuilder csb = new CommandStringBuilder(ALTER_MAPPING); - csb.addOption(ALTER_MAPPING__REGION_NAME, REGION_NAME); - csb.addOption(ALTER_MAPPING__CONNECTION_NAME, "newConnection"); - csb.addOption(ALTER_MAPPING__TABLE_NAME, "newTable"); - csb.addOption(ALTER_MAPPING__PDX_CLASS_NAME, "newPdxClass"); - csb.addOption(ALTER_MAPPING__PRIMARY_KEY_IN_VALUE, "false"); - csb.addOption(ALTER_MAPPING__FIELD_MAPPING, "field3:column3,field4:column4"); - gfsh.executeAndAssertThat(csb.toString()).statusIsSuccess(); - - - locator.invoke(() -> { - String xml = InternalLocator.getLocator().getConfigurationPersistenceService() - .getConfiguration("cluster").getCacheXmlContent(); - assertThat(xml).isNotNull().contains("jdbc:mapping"); - }); - - server.invoke(() -> { - InternalCache cache = ClusterStartupRule.getCache(); - RegionMapping mapping = - cache.getService(JdbcConnectorService.class).getMappingForRegion(REGION_NAME); - assertThat(mapping.getConnectionConfigName()).isEqualTo("newConnection"); - assertThat(mapping.getTableName()).isEqualTo("newTable"); - assertThat(mapping.getPdxClassName()).isEqualTo("newPdxClass"); - assertThat(mapping.isPrimaryKeyInValue()).isEqualTo(false); - List<RegionMapping.FieldMapping> fieldMappings = mapping.getFieldMapping(); - assertThat(fieldMappings).hasSize(2); - assertThat(fieldMappings.get(0).getFieldName()).isEqualTo("field3"); - assertThat(fieldMappings.get(0).getColumnName()).isEqualTo("column3"); - assertThat(fieldMappings.get(1).getFieldName()).isEqualTo("field4"); - assertThat(fieldMappings.get(1).getColumnName()).isEqualTo("column4"); - }); - } - - @Test - public void altersMappingByRemovingValues() { - CommandStringBuilder csb = new CommandStringBuilder(ALTER_MAPPING); - csb.addOption(ALTER_MAPPING__REGION_NAME, REGION_NAME); - csb.addOption(ALTER_MAPPING__TABLE_NAME, ""); - csb.addOption(ALTER_MAPPING__PDX_CLASS_NAME, ""); - csb.addOption(ALTER_MAPPING__FIELD_MAPPING, ""); - - gfsh.executeAndAssertThat(csb.toString()).statusIsSuccess(); - - locator.invoke(() -> { - String xml = InternalLocator.getLocator().getConfigurationPersistenceService() - .getConfiguration("cluster").getCacheXmlContent(); - assertThat(xml).isNotNull().contains("jdbc:mapping"); - }); - - server.invoke(() -> { - InternalCache cache = ClusterStartupRule.getCache(); - RegionMapping mapping = - cache.getService(JdbcConnectorService.class).getMappingForRegion(REGION_NAME); - assertThat(mapping.getConnectionConfigName()).isEqualTo("connection"); - assertThat(mapping.getTableName()).isNull(); - assertThat(mapping.getPdxClassName()).isNull(); - assertThat(mapping.getFieldMapping()).isEmpty(); - }); - } -} diff --git a/geode-connectors/src/integrationTest/java/org/apache/geode/connectors/jdbc/internal/cli/AlterMappingCommandIntegrationTest.java b/geode-connectors/src/integrationTest/java/org/apache/geode/connectors/jdbc/internal/cli/AlterMappingCommandIntegrationTest.java deleted file mode 100644 index f142b4f..0000000 --- a/geode-connectors/src/integrationTest/java/org/apache/geode/connectors/jdbc/internal/cli/AlterMappingCommandIntegrationTest.java +++ /dev/null @@ -1,86 +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.connectors.jdbc.internal.cli; - -import static org.apache.geode.distributed.ConfigurationProperties.ENABLE_CLUSTER_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; - -import org.apache.geode.cache.CacheFactory; -import org.apache.geode.cache.RegionShortcut; -import org.apache.geode.connectors.jdbc.internal.JdbcConnectorService; -import org.apache.geode.connectors.jdbc.internal.configuration.RegionMapping; -import org.apache.geode.internal.cache.InternalCache; -import org.apache.geode.management.cli.Result; -import org.apache.geode.management.internal.cli.result.model.ResultModel; -import org.apache.geode.test.junit.categories.JDBCConnectorTest; - -@Category({JDBCConnectorTest.class}) -public class AlterMappingCommandIntegrationTest { - - private InternalCache cache; - private AlterMappingCommand alterRegionMappingCommand; - - private String regionName; - - @Before - public void setup() { - regionName = "regionName"; - String connectionName = "connection"; - String tableName = "testTable"; - String pdxClass = "myPdxClass"; - Boolean keyInValue = true; - String[] fieldMappings = new String[] {"field1:column1", "field2:column2"}; - - cache = (InternalCache) new CacheFactory().set("locators", "").set("mcast-port", "0") - .set(ENABLE_CLUSTER_CONFIGURATION, "true").create(); - cache.createRegionFactory(RegionShortcut.LOCAL).create(regionName); - CreateMappingCommand create = new CreateMappingCommand(); - create.setCache(cache); - assertThat(create.createMapping(regionName, connectionName, tableName, pdxClass, keyInValue, - fieldMappings).isSuccessful()).isTrue(); - - alterRegionMappingCommand = new AlterMappingCommand(); - alterRegionMappingCommand.setCache(cache); - } - - @After - public void tearDown() { - cache.close(); - } - - @Test - public void altersRegionMappingInService() { - String[] newMappings = new String[] {"field3:column3", "field4:column4"}; - ResultModel result = alterRegionMappingCommand.alterMapping(regionName, "newConnection", - "newTable", "newPdxClass", false, newMappings); - - assertThat(result.getStatus()).isSameAs(Result.Status.OK); - - JdbcConnectorService service = cache.getService(JdbcConnectorService.class); - RegionMapping regionMapping = service.getMappingForRegion(regionName); - - assertThat(regionMapping).isNotNull(); - assertThat(regionMapping.getConnectionConfigName()).isEqualTo("newConnection"); - assertThat(regionMapping.getTableName()).isEqualTo("newTable"); - assertThat(regionMapping.getPdxClassName()).isEqualTo("newPdxClass"); - assertThat(regionMapping.isPrimaryKeyInValue()).isFalse(); - } - -} diff --git a/geode-connectors/src/integrationTest/java/org/apache/geode/connectors/jdbc/internal/cli/JDBCConnectorFunctionsSecurityTest.java b/geode-connectors/src/integrationTest/java/org/apache/geode/connectors/jdbc/internal/cli/JDBCConnectorFunctionsSecurityTest.java index 42b6be7..abf8bf6 100644 --- a/geode-connectors/src/integrationTest/java/org/apache/geode/connectors/jdbc/internal/cli/JDBCConnectorFunctionsSecurityTest.java +++ b/geode-connectors/src/integrationTest/java/org/apache/geode/connectors/jdbc/internal/cli/JDBCConnectorFunctionsSecurityTest.java @@ -61,7 +61,6 @@ public class JDBCConnectorFunctionsSecurityTest { @BeforeClass public static void setupClass() { - functionStringMap.put(new AlterMappingFunction(), "*"); functionStringMap.put(new CreateMappingFunction(), "*"); functionStringMap.put(new DestroyMappingFunction(), "*"); functionStringMap.put(new InheritsDefaultPermissionsJDBCFunction(), "*"); diff --git a/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/cli/AlterMappingCommand.java b/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/cli/AlterMappingCommand.java deleted file mode 100644 index b095915..0000000 --- a/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/cli/AlterMappingCommand.java +++ /dev/null @@ -1,120 +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.connectors.jdbc.internal.cli; - - -import java.util.List; -import java.util.Set; - -import org.springframework.shell.core.annotation.CliCommand; -import org.springframework.shell.core.annotation.CliOption; - -import org.apache.geode.annotations.Experimental; -import org.apache.geode.cache.configuration.CacheConfig; -import org.apache.geode.connectors.jdbc.internal.configuration.RegionMapping; -import org.apache.geode.distributed.DistributedMember; -import org.apache.geode.management.cli.CliMetaData; -import org.apache.geode.management.cli.SingleGfshCommand; -import org.apache.geode.management.internal.cli.functions.CliFunctionResult; -import org.apache.geode.management.internal.cli.i18n.CliStrings; -import org.apache.geode.management.internal.cli.result.model.ResultModel; -import org.apache.geode.management.internal.security.ResourceOperation; -import org.apache.geode.security.ResourcePermission; - -@Experimental -public class AlterMappingCommand extends SingleGfshCommand { - static final String ALTER_MAPPING = "alter jdbc-mapping"; - static final String ALTER_MAPPING__HELP = - EXPERIMENTAL + "Alter properties for an existing jdbc mapping."; - - static final String ALTER_MAPPING__REGION_NAME = "region"; - static final String ALTER_MAPPING__REGION_NAME__HELP = - "Name of the region the mapping to be altered."; - static final String ALTER_MAPPING__PDX_CLASS_NAME = "pdx-class-name"; - static final String ALTER_MAPPING__PDX_CLASS_NAME__HELP = - "Name of new pdx class for which values with be written to the database."; - static final String ALTER_MAPPING__TABLE_NAME = "table"; - static final String ALTER_MAPPING__TABLE_NAME__HELP = - "Name of new database table for values to be written to."; - static final String ALTER_MAPPING__CONNECTION_NAME = "connection"; - static final String ALTER_MAPPING__CONNECTION_NAME__HELP = "Name of new JDBC connection to use."; - static final String ALTER_MAPPING__PRIMARY_KEY_IN_VALUE = "primary-key-in-value"; - static final String ALTER_MAPPING__PRIMARY_KEY_IN_VALUE__HELP = - "If false, the entry value does not contain the data used for the database table's primary key, instead the entry key will be used for the primary key column value."; - static final String ALTER_MAPPING__FIELD_MAPPING = "field-mapping"; - static final String ALTER_MAPPING__FIELD_MAPPING__HELP = - "New key value pairs of entry value fields to database columns."; - - @CliCommand(value = ALTER_MAPPING, help = ALTER_MAPPING__HELP) - @CliMetaData(relatedTopic = CliStrings.DEFAULT_TOPIC_GEODE) - @ResourceOperation(resource = ResourcePermission.Resource.CLUSTER, - operation = ResourcePermission.Operation.MANAGE) - public ResultModel alterMapping( - @CliOption(key = ALTER_MAPPING__REGION_NAME, mandatory = true, - help = ALTER_MAPPING__REGION_NAME__HELP) String regionName, - @CliOption(key = ALTER_MAPPING__CONNECTION_NAME, specifiedDefaultValue = "", - help = ALTER_MAPPING__CONNECTION_NAME__HELP) String connectionName, - @CliOption(key = ALTER_MAPPING__TABLE_NAME, help = ALTER_MAPPING__TABLE_NAME__HELP, - specifiedDefaultValue = "") String table, - @CliOption(key = ALTER_MAPPING__PDX_CLASS_NAME, help = ALTER_MAPPING__PDX_CLASS_NAME__HELP, - specifiedDefaultValue = "") String pdxClassName, - @CliOption(key = ALTER_MAPPING__PRIMARY_KEY_IN_VALUE, - help = ALTER_MAPPING__PRIMARY_KEY_IN_VALUE__HELP, - specifiedDefaultValue = "true") Boolean keyInValue, - @CliOption(key = ALTER_MAPPING__FIELD_MAPPING, help = ALTER_MAPPING__FIELD_MAPPING__HELP, - specifiedDefaultValue = "") String[] fieldMappings) { - // input - Set<DistributedMember> targetMembers = getMembers(null, null); - RegionMapping newMapping = new RegionMapping(regionName, - pdxClassName, table, connectionName, keyInValue); - newMapping.setFieldMapping(fieldMappings); - - // action - List<CliFunctionResult> results = - executeAndGetFunctionResult(new AlterMappingFunction(), newMapping, targetMembers); - ResultModel result = - ResultModel.createMemberStatusResult(results, EXPERIMENTAL, null, false, true); - if (!result.isSuccessful()) { - return result; - } - // find the merged regionMapping from the function result - CliFunctionResult successResult = - results.stream().filter(CliFunctionResult::isSuccessful).findAny().get(); - RegionMapping mergedMapping = - (RegionMapping) successResult.getResultObject(); - result.setConfigObject(mergedMapping); - return result; - } - - @Override - public void updateClusterConfig(String group, CacheConfig cacheConfig, Object element) { - RegionMapping newCacheElement = (RegionMapping) element; - RegionMapping existingCacheElement = cacheConfig.findCustomRegionElement( - newCacheElement.getRegionName(), newCacheElement.getId(), RegionMapping.class); - - cacheConfig - .getRegions() - .stream() - .filter(regionConfig -> regionConfig.getName().equals(newCacheElement.getRegionName())) - .forEach( - regionConfig -> regionConfig.getCustomRegionElements().remove(existingCacheElement)); - - cacheConfig - .getRegions() - .stream() - .filter(regionConfig -> regionConfig.getName().equals(newCacheElement.getRegionName())) - .forEach(regionConfig -> regionConfig.getCustomRegionElements().add(newCacheElement)); - } -} diff --git a/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/cli/AlterMappingFunction.java b/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/cli/AlterMappingFunction.java deleted file mode 100644 index e0b182d..0000000 --- a/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/cli/AlterMappingFunction.java +++ /dev/null @@ -1,79 +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.connectors.jdbc.internal.cli; - -import java.util.List; - -import org.apache.geode.annotations.Experimental; -import org.apache.geode.cache.execute.FunctionContext; -import org.apache.geode.connectors.jdbc.internal.JdbcConnectorService; -import org.apache.geode.connectors.jdbc.internal.RegionMappingNotFoundException; -import org.apache.geode.connectors.jdbc.internal.configuration.RegionMapping; -import org.apache.geode.management.cli.CliFunction; -import org.apache.geode.management.internal.cli.functions.CliFunctionResult; - -@Experimental -public class AlterMappingFunction extends CliFunction<RegionMapping> { - - @Override - public CliFunctionResult executeFunction(FunctionContext<RegionMapping> context) - throws Exception { - JdbcConnectorService service = FunctionContextArgumentProvider.getJdbcConnectorService(context); - RegionMapping mapping = context.getArguments(); - RegionMapping existingMapping = - service.getMappingForRegion(mapping.getRegionName()); - if (existingMapping == null) { - throw new RegionMappingNotFoundException( - "RegionMapping for region " + mapping.getRegionName() + " was not found"); - } - - // action - RegionMapping alteredMapping = alterRegionMapping(mapping, existingMapping); - service.replaceRegionMapping(alteredMapping); - - // output - return new CliFunctionResult(context.getMemberName(), alteredMapping, null); - } - - RegionMapping alterRegionMapping(RegionMapping regionMapping, - RegionMapping existingMapping) { - String connectionName = getValue(regionMapping.getConnectionConfigName(), - existingMapping.getConnectionConfigName()); - String table = getValue(regionMapping.getTableName(), existingMapping.getTableName()); - String pdxClassName = - getValue(regionMapping.getPdxClassName(), existingMapping.getPdxClassName()); - Boolean keyInValue = regionMapping.isPrimaryKeyInValue() == null - ? existingMapping.isPrimaryKeyInValue() : regionMapping.isPrimaryKeyInValue(); - - List<RegionMapping.FieldMapping> fieldMappings = - regionMapping.getFieldMapping(); - if (!regionMapping.isFieldMappingModified()) { - fieldMappings = existingMapping.getFieldMapping(); - } - RegionMapping alteredMapping = new RegionMapping( - existingMapping.getRegionName(), pdxClassName, table, connectionName, keyInValue); - alteredMapping.getFieldMapping().addAll(fieldMappings); - return alteredMapping; - } - - private String getValue(String newValue, String existingValue) { - // if newValue is null use the value already in the config - // if newValue is the empty string, then "unset" it by returning null - if (newValue == null) { - return existingValue; - } - return newValue.isEmpty() ? null : newValue; - } -} diff --git a/geode-connectors/src/main/resources/META-INF/services/org.springframework.shell.core.CommandMarker b/geode-connectors/src/main/resources/META-INF/services/org.springframework.shell.core.CommandMarker index 27742b3..bf3e1eb 100644 --- a/geode-connectors/src/main/resources/META-INF/services/org.springframework.shell.core.CommandMarker +++ b/geode-connectors/src/main/resources/META-INF/services/org.springframework.shell.core.CommandMarker @@ -16,7 +16,6 @@ # # JDBC Connector Extension commands org.apache.geode.connectors.jdbc.internal.cli.CreateMappingCommand -org.apache.geode.connectors.jdbc.internal.cli.AlterMappingCommand org.apache.geode.connectors.jdbc.internal.cli.DestroyMappingCommand org.apache.geode.connectors.jdbc.internal.cli.DescribeMappingCommand org.apache.geode.connectors.jdbc.internal.cli.ListMappingCommand diff --git a/geode-connectors/src/main/resources/org/apache/geode/internal/sanctioned-geode-connectors-serializables.txt b/geode-connectors/src/main/resources/org/apache/geode/internal/sanctioned-geode-connectors-serializables.txt index 0e719ef..5fd7867 100755 --- a/geode-connectors/src/main/resources/org/apache/geode/internal/sanctioned-geode-connectors-serializables.txt +++ b/geode-connectors/src/main/resources/org/apache/geode/internal/sanctioned-geode-connectors-serializables.txt @@ -1,7 +1,6 @@ org/apache/geode/connectors/jdbc/JdbcConnectorException,true,1 org/apache/geode/connectors/jdbc/internal/RegionMappingExistsException,false org/apache/geode/connectors/jdbc/internal/RegionMappingNotFoundException,false -org/apache/geode/connectors/jdbc/internal/cli/AlterMappingFunction,false org/apache/geode/connectors/jdbc/internal/cli/CreateMappingFunction,false org/apache/geode/connectors/jdbc/internal/cli/DescribeMappingFunction,false org/apache/geode/connectors/jdbc/internal/cli/DestroyMappingFunction,false diff --git a/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/AlterMappingCommandTest.java b/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/AlterMappingCommandTest.java deleted file mode 100644 index ccb3e32..0000000 --- a/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/AlterMappingCommandTest.java +++ /dev/null @@ -1,116 +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.connectors.jdbc.internal.cli; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Test; - -import org.apache.geode.connectors.jdbc.internal.configuration.RegionMapping; -import org.apache.geode.management.internal.cli.GfshParseResult; -import org.apache.geode.management.internal.cli.functions.CliFunctionResult; -import org.apache.geode.test.junit.rules.GfshParserRule; - -public class AlterMappingCommandTest { - public static final String COMMAND = "alter jdbc-mapping --region='region' "; - private AlterMappingCommand command; - private List<CliFunctionResult> results; - private CliFunctionResult result; - private RegionMapping mapping; - private List<RegionMapping> mappings; - - @ClassRule - public static GfshParserRule gfsh = new GfshParserRule(); - - @Before - public void setUp() throws Exception { - command = spy(AlterMappingCommand.class); - results = new ArrayList<>(); - doReturn(Collections.EMPTY_SET).when(command).getMembers(any(), any()); - doReturn(results).when(command).executeAndGetFunctionResult(any(), any(), any()); - result = mock(CliFunctionResult.class); - when(result.isSuccessful()).thenReturn(true); - when(result.getMemberIdOrName()).thenReturn("memberName"); - when(result.getStatusMessage()).thenReturn("message"); - mappings = new ArrayList<>(); - mapping = new RegionMapping(); - mapping.setRegionName("region"); - } - - @Test - public void requiredParameter() { - gfsh.executeAndAssertThat(command, "alter jdbc-mapping").statusIsError() - .containsOutput("Invalid command"); - } - - @Test - public void valuesAreParsedAsExpected() { - GfshParseResult parseResult = gfsh.parse("alter jdbc-mapping --region='region' --connection='' " - + "--table='' --pdx-class-name='' " + "--field-mapping=''"); - - String[] mappings = (String[]) parseResult.getParamValue("field-mapping"); - assertThat(mappings).hasSize(1); - assertThat(mappings[0]).isEqualTo(""); - assertThat(parseResult.getParamValue("region")).isEqualTo("region"); - assertThat(parseResult.getParamValue("connection")).isEqualTo(""); - assertThat(parseResult.getParamValue("table")).isEqualTo(""); - assertThat(parseResult.getParamValue("pdx-class-name")).isEqualTo(""); - - parseResult = gfsh.parse("alter jdbc-mapping --region=testRegion-1 --connection=connection " - + "--table=myTable --pdx-class-name=myPdxClass " + "--field-mapping"); - mappings = (String[]) parseResult.getParamValue("field-mapping"); - assertThat(mappings).hasSize(1); - assertThat(mappings[0]).isEqualTo(""); - - parseResult = gfsh.parse("alter jdbc-mapping --region=testRegion-1 --connection=connection " - + "--table=myTable --pdx-class-name=myPdxClass "); - mappings = (String[]) parseResult.getParamValue("field-mapping"); - assertThat(mappings).isNull(); - } - - @Test - public void noSuccessfulResult() { - mappings.add(mapping); - // result is not successful - when(result.isSuccessful()).thenReturn(false); - results.add(result); - - gfsh.executeAndAssertThat(command, COMMAND).statusIsError(); - verify(command).executeAndGetFunctionResult(any(), any(), any()); - } - - @Test - public void successfulResult() { - mappings.add(mapping); - // result is successful - when(result.isSuccessful()).thenReturn(true); - results.add(result); - - gfsh.executeAndAssertThat(command, COMMAND).statusIsSuccess(); - verify(command).executeAndGetFunctionResult(any(), any(), any()); - } -} diff --git a/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/AlterMappingFunctionTest.java b/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/AlterMappingFunctionTest.java deleted file mode 100644 index 7b94ad7..0000000 --- a/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/AlterMappingFunctionTest.java +++ /dev/null @@ -1,288 +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.connectors.jdbc.internal.cli; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.doAnswer; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import java.io.Serializable; -import java.util.List; - -import org.apache.commons.lang.SerializationUtils; -import org.junit.Before; -import org.junit.Test; -import org.mockito.ArgumentCaptor; - -import org.apache.geode.cache.execute.FunctionContext; -import org.apache.geode.cache.execute.ResultSender; -import org.apache.geode.connectors.jdbc.internal.JdbcConnectorService; -import org.apache.geode.connectors.jdbc.internal.RegionMappingNotFoundException; -import org.apache.geode.connectors.jdbc.internal.configuration.RegionMapping; -import org.apache.geode.distributed.DistributedMember; -import org.apache.geode.distributed.DistributedSystem; -import org.apache.geode.internal.cache.InternalCache; -import org.apache.geode.management.internal.cli.functions.CliFunctionResult; - -public class AlterMappingFunctionTest { - - private static final String REGION_NAME = "testRegion"; - - private RegionMapping regionMapping; - private RegionMapping existingMapping; - private RegionMapping mappingToAlter; - private FunctionContext<RegionMapping> context; - private ResultSender<Object> resultSender; - private JdbcConnectorService service; - - private AlterMappingFunction function; - - @Before - public void setUp() { - context = mock(FunctionContext.class); - resultSender = mock(ResultSender.class); - InternalCache cache = mock(InternalCache.class); - DistributedSystem system = mock(DistributedSystem.class); - DistributedMember distributedMember = mock(DistributedMember.class); - service = mock(JdbcConnectorService.class); - - regionMapping = new RegionMapping(REGION_NAME, null, null, null, null); - existingMapping = new RegionMapping(REGION_NAME, null, null, null, null); - mappingToAlter = - new RegionMapping(REGION_NAME, "pdxClass", "myTable", "connection", true); - mappingToAlter.setFieldMapping(new String[] {"field1:column1", "field2:column2"}); - - when(context.getResultSender()).thenReturn(resultSender); - when(context.getCache()).thenReturn(cache); - when(cache.getDistributedSystem()).thenReturn(system); - when(system.getDistributedMember()).thenReturn(distributedMember); - when(context.getArguments()).thenReturn(regionMapping); - when(cache.getService(eq(JdbcConnectorService.class))).thenReturn(service); - function = new AlterMappingFunction(); - } - - @Test - public void isHAReturnsFalse() { - assertThat(function.isHA()).isFalse(); - } - - @Test - public void getIdReturnsNameOfClass() { - assertThat(function.getId()).isEqualTo(function.getClass().getName()); - } - - @Test - public void serializes() { - Serializable original = function; - - Object copy = SerializationUtils.clone(original); - - assertThat(copy).isNotSameAs(original).isInstanceOf(AlterMappingFunction.class); - } - - @Test - public void alterMissingRegionMappingThrowsRegionMappingNotFound() { - AlterMappingFunction alterFunction = mock(AlterMappingFunction.class); - doAnswer((m) -> { - throw new RegionMappingNotFoundException(); - }).when(alterFunction).alterRegionMapping(any(), - any()); - - assertThatThrownBy(() -> alterFunction.alterRegionMapping(regionMapping, existingMapping)) - .isInstanceOf(RegionMappingNotFoundException.class); - } - - @Test - public void executeInvokesReplaceOnService() throws Exception { - when(service.getMappingForRegion(REGION_NAME)).thenReturn(existingMapping); - - AlterMappingFunction function = spy(new AlterMappingFunction()); - function.execute(context); - - verify(service, times(1)).replaceRegionMapping(any()); - } - - @Test - public void executeReportsErrorIfRegionMappingNotFound() throws Exception { - doAnswer((m) -> { - throw new RegionMappingNotFoundException(); - }).when(service) - .replaceRegionMapping(eq(regionMapping)); - - function.execute(context); - - ArgumentCaptor<CliFunctionResult> argument = ArgumentCaptor.forClass(CliFunctionResult.class); - verify(resultSender, times(1)).lastResult(argument.capture()); - assertThat(argument.getValue().getStatusMessage()).contains(REGION_NAME); - } - - @Test - public void alterMappingPdxClassName() { - RegionMapping newConfigValues = - new RegionMapping(REGION_NAME, "newClassName", null, null, null); - - RegionMapping alteredConfig = - function.alterRegionMapping(newConfigValues, mappingToAlter); - - assertThat(alteredConfig.getRegionName()).isEqualTo(REGION_NAME); - assertThat(alteredConfig.getPdxClassName()).isEqualTo("newClassName"); - assertThat(alteredConfig.getTableName()).isEqualTo("myTable"); - assertThat(alteredConfig.getConnectionConfigName()).isEqualTo("connection"); - assertThat(alteredConfig.isPrimaryKeyInValue()).isTrue(); - - assertFieldMapping(alteredConfig); - } - - private void assertFieldMapping(RegionMapping alteredConfig) { - List<RegionMapping.FieldMapping> fieldMappings = - alteredConfig.getFieldMapping(); - assertThat(fieldMappings).hasSize(2); - assertThat(fieldMappings.get(0).getFieldName()).isEqualTo("field1"); - assertThat(fieldMappings.get(0).getColumnName()).isEqualTo("column1"); - assertThat(fieldMappings.get(1).getFieldName()).isEqualTo("field2"); - assertThat(fieldMappings.get(1).getColumnName()).isEqualTo("column2"); - } - - @Test - public void alterRegionMappingTable() { - RegionMapping newConfigValues = - new RegionMapping(REGION_NAME, null, "newTable", null, null); - - RegionMapping alteredConfig = - function.alterRegionMapping(newConfigValues, mappingToAlter); - - assertThat(alteredConfig.getRegionName()).isEqualTo(REGION_NAME); - assertThat(alteredConfig.getPdxClassName()).isEqualTo("pdxClass"); - assertThat(alteredConfig.getTableName()).isEqualTo("newTable"); - assertThat(alteredConfig.getConnectionConfigName()).isEqualTo("connection"); - assertThat(alteredConfig.isPrimaryKeyInValue()).isTrue(); - assertFieldMapping(alteredConfig); - } - - @Test - public void alterRegionMappingPrimaryKeyInValue() { - RegionMapping newConfigValues = - new RegionMapping(REGION_NAME, null, null, null, false); - - RegionMapping alteredConfig = - function.alterRegionMapping(newConfigValues, mappingToAlter); - - assertThat(alteredConfig.getRegionName()).isEqualTo(REGION_NAME); - assertThat(alteredConfig.getPdxClassName()).isEqualTo("pdxClass"); - assertThat(alteredConfig.getTableName()).isEqualTo("myTable"); - assertThat(alteredConfig.getConnectionConfigName()).isEqualTo("connection"); - assertThat(alteredConfig.isPrimaryKeyInValue()).isFalse(); - assertFieldMapping(alteredConfig); - } - - @Test - public void alterRegionMappingConnectionName() { - RegionMapping newConfigValues = - new RegionMapping(REGION_NAME, null, null, "newConnection", null); - - RegionMapping alteredConfig = - function.alterRegionMapping(newConfigValues, mappingToAlter); - - assertThat(alteredConfig.getRegionName()).isEqualTo(REGION_NAME); - assertThat(alteredConfig.getPdxClassName()).isEqualTo("pdxClass"); - assertThat(alteredConfig.getTableName()).isEqualTo("myTable"); - assertThat(alteredConfig.getConnectionConfigName()).isEqualTo("newConnection"); - assertThat(alteredConfig.isPrimaryKeyInValue()).isTrue(); - assertFieldMapping(alteredConfig); - } - - @Test - public void alterRegionMappingFieldMappings() { - RegionMapping newConfigValues = - new RegionMapping(REGION_NAME, null, null, null, null); - newConfigValues.setFieldMapping(new String[] {"field5:column5", "field6:column6"}); - - - RegionMapping alteredConfig = - function.alterRegionMapping(newConfigValues, mappingToAlter); - - assertThat(alteredConfig.getRegionName()).isEqualTo(REGION_NAME); - assertThat(alteredConfig.getPdxClassName()).isEqualTo("pdxClass"); - assertThat(alteredConfig.getTableName()).isEqualTo("myTable"); - assertThat(alteredConfig.getConnectionConfigName()).isEqualTo("connection"); - assertThat(alteredConfig.isPrimaryKeyInValue()).isTrue(); - List<RegionMapping.FieldMapping> fieldMappings = - alteredConfig.getFieldMapping(); - assertThat(fieldMappings).hasSize(2); - assertThat(fieldMappings) - .contains(new RegionMapping.FieldMapping("field5", "column5")); - assertThat(fieldMappings) - .contains(new RegionMapping.FieldMapping("field6", "column6")); - } - - @Test - public void alterRegionMappingRemoveFieldMappings() { - RegionMapping newConfigValues = - new RegionMapping(REGION_NAME, null, null, null, null); - newConfigValues.setFieldMapping(new String[0]); - RegionMapping alteredConfig = - function.alterRegionMapping(newConfigValues, mappingToAlter); - - assertThat(alteredConfig.getRegionName()).isEqualTo(REGION_NAME); - assertThat(alteredConfig.getPdxClassName()).isEqualTo("pdxClass"); - assertThat(alteredConfig.getTableName()).isEqualTo("myTable"); - assertThat(alteredConfig.getConnectionConfigName()).isEqualTo("connection"); - assertThat(alteredConfig.isPrimaryKeyInValue()).isTrue(); - List<RegionMapping.FieldMapping> fieldMappings = - alteredConfig.getFieldMapping(); - assertThat(fieldMappings).hasSize(0); - } - - @Test - public void alterRegionMappingWithEmptyString() { - RegionMapping newConfigValues = - new RegionMapping(REGION_NAME, null, null, null, null); - newConfigValues.setFieldMapping(new String[] {""}); - RegionMapping alteredConfig = - function.alterRegionMapping(newConfigValues, mappingToAlter); - - assertThat(alteredConfig.getRegionName()).isEqualTo(REGION_NAME); - assertThat(alteredConfig.getPdxClassName()).isEqualTo("pdxClass"); - assertThat(alteredConfig.getTableName()).isEqualTo("myTable"); - assertThat(alteredConfig.getConnectionConfigName()).isEqualTo("connection"); - assertThat(alteredConfig.isPrimaryKeyInValue()).isTrue(); - List<RegionMapping.FieldMapping> fieldMappings = - alteredConfig.getFieldMapping(); - assertThat(fieldMappings).hasSize(0); - } - - @Test - public void alterRegionMappingWithNothingToAlter() { - RegionMapping newConfigValues = - new RegionMapping(REGION_NAME, null, null, null, null); - - RegionMapping alteredConfig = - function.alterRegionMapping(newConfigValues, mappingToAlter); - - assertThat(alteredConfig.getRegionName()).isEqualTo(REGION_NAME); - assertThat(alteredConfig.getPdxClassName()).isEqualTo("pdxClass"); - assertThat(alteredConfig.getTableName()).isEqualTo("myTable"); - assertThat(alteredConfig.getConnectionConfigName()).isEqualTo("connection"); - assertThat(alteredConfig.isPrimaryKeyInValue()).isTrue(); - assertFieldMapping(alteredConfig); - } -}