You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by ds...@apache.org on 2018/11/15 19:35:43 UTC
[geode] branch feature/GEODE-6025 updated: command now shows the
regions that are using the data source
This is an automated email from the ASF dual-hosted git repository.
dschneider pushed a commit to branch feature/GEODE-6025
in repository https://gitbox.apache.org/repos/asf/geode.git
The following commit(s) were added to refs/heads/feature/GEODE-6025 by this push:
new 8ccb444 command now shows the regions that are using the data source
8ccb444 is described below
commit 8ccb444368f581cb56ef17884f1dc6e0f3dc7728
Author: Darrel Schneider <ds...@pivotal.io>
AuthorDate: Thu Nov 15 11:35:09 2018 -0800
command now shows the regions that are using the data source
---
.../internal/cli/DescribeDataSourceCommand.java | 17 +++++--
.../cli/DescribeDataSourceCommandTest.java | 55 ++++++++++++++++++++++
2 files changed, 68 insertions(+), 4 deletions(-)
diff --git a/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/cli/DescribeDataSourceCommand.java b/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/cli/DescribeDataSourceCommand.java
index 102ba87..ecc29e9 100644
--- a/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/cli/DescribeDataSourceCommand.java
+++ b/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/cli/DescribeDataSourceCommand.java
@@ -18,7 +18,6 @@ package org.apache.geode.connectors.jdbc.internal.cli;
import java.util.List;
import java.util.stream.Collectors;
-import org.apache.logging.log4j.Logger;
import org.springframework.shell.core.annotation.CliCommand;
import org.springframework.shell.core.annotation.CliOption;
@@ -29,10 +28,10 @@ import org.apache.geode.cache.configuration.JndiBindingsType;
import org.apache.geode.cache.configuration.RegionConfig;
import org.apache.geode.connectors.jdbc.internal.configuration.RegionMapping;
import org.apache.geode.distributed.internal.InternalConfigurationPersistenceService;
-import org.apache.geode.internal.logging.LogService;
import org.apache.geode.management.cli.CliMetaData;
import org.apache.geode.management.internal.cli.commands.CreateJndiBindingCommand.DATASOURCE_TYPE;
import org.apache.geode.management.internal.cli.commands.InternalGfshCommand;
+import org.apache.geode.management.internal.cli.result.model.InfoResultModel;
import org.apache.geode.management.internal.cli.result.model.ResultModel;
import org.apache.geode.management.internal.cli.result.model.TabularResultModel;
import org.apache.geode.management.internal.security.ResourceOperation;
@@ -40,12 +39,13 @@ import org.apache.geode.security.ResourcePermission;
@Experimental
public class DescribeDataSourceCommand extends InternalGfshCommand {
- public static final String DATA_SOURCE_PROPERTIES_SECTION = "data-source-properties";
- private static final Logger logger = LogService.getLogger();
static final String DESCRIBE_DATA_SOURCE = "describe data-source";
private static final String DESCRIBE_DATA_SOURCE__HELP =
"Describe the configuration of the given data source.";
+ static final String DATA_SOURCE_PROPERTIES_SECTION = "data-source-properties";
+ static final String REGIONS_USING_DATA_SOURCE_SECTION = "regions-using-data-source";
+
@CliCommand(value = DESCRIBE_DATA_SOURCE, help = DESCRIBE_DATA_SOURCE__HELP)
@CliMetaData
@ResourceOperation(resource = ResourcePermission.Resource.CLUSTER,
@@ -93,6 +93,15 @@ public class DescribeDataSourceCommand extends InternalGfshCommand {
}
}
+ InfoResultModel regionsUsingSection = resultModel.addInfo(REGIONS_USING_DATA_SOURCE_SECTION);
+ List<String> regionsUsing = getRegionsThatUseDataSource(cacheConfig, dataSourceName);
+ regionsUsingSection.setHeader("Regions Using Data Source:");
+ if (regionsUsing.isEmpty()) {
+ regionsUsingSection.addLine("no regions are using " + dataSourceName);
+ } else {
+ regionsUsingSection.setContent(regionsUsing);
+ }
+
return resultModel;
}
diff --git a/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/DescribeDataSourceCommandTest.java b/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/DescribeDataSourceCommandTest.java
index 1417320..b85e47c 100644
--- a/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/DescribeDataSourceCommandTest.java
+++ b/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/DescribeDataSourceCommandTest.java
@@ -39,6 +39,7 @@ import org.apache.geode.connectors.jdbc.internal.configuration.RegionMapping;
import org.apache.geode.distributed.internal.InternalConfigurationPersistenceService;
import org.apache.geode.management.cli.Result.Status;
import org.apache.geode.management.internal.cli.commands.CreateJndiBindingCommand.DATASOURCE_TYPE;
+import org.apache.geode.management.internal.cli.result.model.InfoResultModel;
import org.apache.geode.management.internal.cli.result.model.ResultModel;
import org.apache.geode.management.internal.cli.result.model.TabularResultModel;
import org.apache.geode.test.junit.rules.GfshParserRule;
@@ -324,4 +325,58 @@ public class DescribeDataSourceCommandTest {
assertThat(result).isEqualTo(Arrays.asList("regionName1", "regionName3"));
}
+
+ @Test
+ public void describeDataSourceWithRegionsUsingItReturnsResultWithNoRegionsUsingIt() {
+ RegionConfig regionConfig = mock(RegionConfig.class);
+ when(regionConfig.getCustomRegionElements())
+ .thenReturn(Collections.singletonList(mock(RegionMapping.class)));
+ regionConfigs.add(regionConfig);
+
+ ResultModel result = command.describeDataSource(DATA_SOURCE_NAME);
+
+ InfoResultModel regionsUsingSection = (InfoResultModel) result
+ .getSection(DescribeDataSourceCommand.REGIONS_USING_DATA_SOURCE_SECTION);
+ assertThat(regionsUsingSection.getContent())
+ .isEqualTo(Arrays.asList("no regions are using " + DATA_SOURCE_NAME));
+ }
+
+ @Test
+ public void describeDataSourceWithRegionsUsingItReturnsResultWithRegionNames() {
+ RegionMapping regionMapping;
+ {
+ RegionConfig regionConfig1 = mock(RegionConfig.class, "regionConfig1");
+ when(regionConfig1.getName()).thenReturn("regionName1");
+ regionMapping = mock(RegionMapping.class, "regionMapping1");
+ when(regionMapping.getDataSourceName()).thenReturn(DATA_SOURCE_NAME);
+ when(regionConfig1.getCustomRegionElements())
+ .thenReturn(Arrays.asList(regionMapping));
+ regionConfigs.add(regionConfig1);
+ }
+ {
+ RegionConfig regionConfig2 = mock(RegionConfig.class, "regionConfig2");
+ when(regionConfig2.getName()).thenReturn("regionName2");
+ regionMapping = mock(RegionMapping.class, "regionMapping2");
+ when(regionMapping.getDataSourceName()).thenReturn("otherDataSourceName");
+ when(regionConfig2.getCustomRegionElements())
+ .thenReturn(Arrays.asList(regionMapping));
+ regionConfigs.add(regionConfig2);
+ }
+ {
+ RegionConfig regionConfig3 = mock(RegionConfig.class, "regionConfig3");
+ when(regionConfig3.getName()).thenReturn("regionName3");
+ regionMapping = mock(RegionMapping.class, "regionMapping3");
+ when(regionMapping.getDataSourceName()).thenReturn(DATA_SOURCE_NAME);
+ when(regionConfig3.getCustomRegionElements())
+ .thenReturn(Arrays.asList(regionMapping));
+ regionConfigs.add(regionConfig3);
+ }
+
+ ResultModel result = command.describeDataSource(DATA_SOURCE_NAME);
+
+ InfoResultModel regionsUsingSection = (InfoResultModel) result
+ .getSection(DescribeDataSourceCommand.REGIONS_USING_DATA_SOURCE_SECTION);
+ assertThat(regionsUsingSection.getContent())
+ .isEqualTo(Arrays.asList("regionName1", "regionName3"));
+ }
}