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 2017/01/11 17:16:28 UTC
[1/4] geode git commit: GEODE-2261: rename SharedConfig to
ClusterConfigurationService
Repository: geode
Updated Branches:
refs/heads/develop dfb77d7e0 -> e79e0103a
http://git-wip-us.apache.org/repos/asf/geode/blob/e79e0103/geode-core/src/test/resources/org/apache/geode/management/internal/configuration/cluster-region.xml
----------------------------------------------------------------------
diff --git a/geode-core/src/test/resources/org/apache/geode/management/internal/configuration/cluster-region.xml b/geode-core/src/test/resources/org/apache/geode/management/internal/configuration/cluster-region.xml
index 02cb4bc..c97f7dc 100644
--- a/geode-core/src/test/resources/org/apache/geode/management/internal/configuration/cluster-region.xml
+++ b/geode-core/src/test/resources/org/apache/geode/management/internal/configuration/cluster-region.xml
@@ -16,7 +16,7 @@
limitations under the License.
-->
<!--
- Used by org/apache/geode/management/internal/configuration/SharedConfigurationUsingDirDUnitTest.java
+ Used by org/apache/geode/management/internal/configuration/ClusterConfigurationServiceUsingDirDUnitTest.java
-->
<cache xsi:schemaLocation="http://schema.pivotal.io/gemfire/cache http://schema.pivotal.io/gemfire/cache/cache-8.1.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
http://git-wip-us.apache.org/repos/asf/geode/blob/e79e0103/geode-web/src/test/java/org/apache/geode/management/internal/cli/commands/CommandOverHttpDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-web/src/test/java/org/apache/geode/management/internal/cli/commands/CommandOverHttpDUnitTest.java b/geode-web/src/test/java/org/apache/geode/management/internal/cli/commands/CommandOverHttpDUnitTest.java
index 882d8d8..a1810b6 100644
--- a/geode-web/src/test/java/org/apache/geode/management/internal/cli/commands/CommandOverHttpDUnitTest.java
+++ b/geode-web/src/test/java/org/apache/geode/management/internal/cli/commands/CommandOverHttpDUnitTest.java
@@ -36,7 +36,7 @@ import org.apache.geode.test.junit.runner.SuiteRunner;
MiscellaneousCommandsExportLogsPart2DUnitTest.class,
MiscellaneousCommandsExportLogsPart3DUnitTest.class,
MiscellaneousCommandsExportLogsPart4DUnitTest.class, QueueCommandsDUnitTest.class,
- SharedConfigurationCommandsDUnitTest.class, ShellCommandsDUnitTest.class,
+ ClusterConfigurationServiceCommandsDUnitTest.class, ShellCommandsDUnitTest.class,
ShowDeadlockDUnitTest.class, ShowMetricsDUnitTest.class, ShowStackTraceDUnitTest.class,
UserCommandsDUnitTest.class})
public class CommandOverHttpDUnitTest {
[4/4] geode git commit: GEODE-2261: rename SharedConfig to
ClusterConfigurationService
Posted by ji...@apache.org.
GEODE-2261: rename SharedConfig to ClusterConfigurationService
Project: http://git-wip-us.apache.org/repos/asf/geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/geode/commit/e79e0103
Tree: http://git-wip-us.apache.org/repos/asf/geode/tree/e79e0103
Diff: http://git-wip-us.apache.org/repos/asf/geode/diff/e79e0103
Branch: refs/heads/develop
Commit: e79e0103a25ed9c01f5ac551d402c1be314cdd9a
Parents: dfb77d7
Author: Jinmei Liao <ji...@pivotal.io>
Authored: Tue Jan 10 08:55:12 2017 -0800
Committer: Jinmei Liao <ji...@pivotal.io>
Committed: Wed Jan 11 09:15:18 2017 -0800
----------------------------------------------------------------------
...erConfigurationServiceEndToEndDUnitTest.java | 476 ++++++++++++
.../SharedConfigurationEndToEndDUnitTest.java | 464 ------------
.../internal/AbstractDistributionConfig.java | 27 +-
.../internal/ClusterConfigurationService.java | 748 +++++++++++++++++++
.../distributed/internal/InternalLocator.java | 11 +-
.../distributed/internal/ServerLocator.java | 2 +-
.../internal/SharedConfiguration.java | 747 ------------------
.../membership/gms/locator/GMSLocator.java | 5 +-
.../internal/tcpserver/TcpHandler.java | 5 +-
.../internal/tcpserver/TcpServer.java | 4 +-
.../cache/ClusterConfigurationLoader.java | 8 +-
.../geode/internal/cache/GemFireCacheImpl.java | 4 +-
.../management/internal/JmxManagerLocator.java | 4 +-
.../cli/commands/AbstractCommandsSupport.java | 6 +-
...ExportImportSharedConfigurationCommands.java | 6 +-
.../internal/cli/i18n/CliStrings.java | 4 +-
.../cli/remote/RemoteExecutionStrategy.java | 8 +-
.../callbacks/ConfigurationChangeListener.java | 6 +-
.../functions/UploadJarFunction.java | 4 +-
.../handlers/ConfigurationRequestHandler.java | 8 +-
...SharedConfigurationStatusRequestHandler.java | 5 +-
.../AutoConnectionSourceImplJUnitTest.java | 6 +-
...tractLocatorLauncherIntegrationTestCase.java | 4 +-
.../internal/tcpserver/TcpServerJUnitTest.java | 6 +-
...erConfigurationServiceCommandsDUnitTest.java | 344 +++++++++
.../cli/commands/ConfigCommandsDUnitTest.java | 4 +-
...eateAlterDestroyRegionCommandsDUnitTest.java | 10 +-
.../cli/commands/DeployCommandsDUnitTest.java | 6 +-
.../commands/DiskStoreCommandsDUnitTest.java | 6 +-
.../cli/commands/IndexCommandsDUnitTest.java | 6 +-
.../cli/commands/QueueCommandsDUnitTest.java | 4 +-
.../SharedConfigurationCommandsDUnitTest.java | 343 ---------
.../internal/configuration/ClusterConfig.java | 4 +-
.../ClusterConfigurationServiceDUnitTest.java | 407 ++++++++++
...erConfigurationServiceUsingDirDUnitTest.java | 334 +++++++++
.../SharedConfigurationDUnitTest.java | 407 ----------
.../SharedConfigurationTestUtils.java | 4 +-
.../SharedConfigurationUsingDirDUnitTest.java | 334 ---------
.../utils/XmlUtilsAddNewNodeJUnitTest.java | 8 +-
.../internal/configuration/cluster-region.xml | 2 +-
.../cli/commands/CommandOverHttpDUnitTest.java | 2 +-
41 files changed, 2401 insertions(+), 2392 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/geode/blob/e79e0103/geode-assembly/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigurationServiceEndToEndDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-assembly/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigurationServiceEndToEndDUnitTest.java b/geode-assembly/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigurationServiceEndToEndDUnitTest.java
new file mode 100644
index 0000000..a96f8af
--- /dev/null
+++ b/geode-assembly/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigurationServiceEndToEndDUnitTest.java
@@ -0,0 +1,476 @@
+/*
+ * 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.internal.configuration;
+
+import static org.apache.geode.cache.RegionShortcut.PARTITION;
+import static org.apache.geode.cache.RegionShortcut.REPLICATE;
+import static org.apache.geode.distributed.ConfigurationProperties.ENABLE_CLUSTER_CONFIGURATION;
+import static org.apache.geode.distributed.ConfigurationProperties.HTTP_SERVICE_PORT;
+import static org.apache.geode.distributed.ConfigurationProperties.JMX_MANAGER;
+import static org.apache.geode.distributed.ConfigurationProperties.JMX_MANAGER_BIND_ADDRESS;
+import static org.apache.geode.distributed.ConfigurationProperties.JMX_MANAGER_PORT;
+import static org.apache.geode.distributed.ConfigurationProperties.JMX_MANAGER_START;
+import static org.apache.geode.distributed.ConfigurationProperties.LOCATORS;
+import static org.apache.geode.distributed.ConfigurationProperties.LOG_LEVEL;
+import static org.apache.geode.distributed.ConfigurationProperties.MCAST_PORT;
+import static org.apache.geode.distributed.ConfigurationProperties.NAME;
+import static org.apache.geode.internal.AvailablePortHelper.getRandomAvailableTCPPorts;
+import static org.apache.geode.internal.FileUtil.delete;
+import static org.apache.geode.internal.FileUtil.deleteMatching;
+import static org.apache.geode.internal.lang.StringUtils.isBlank;
+import static org.apache.geode.management.internal.cli.CliUtil.getAllNormalMembers;
+import static org.apache.geode.test.dunit.Assert.assertEquals;
+import static org.apache.geode.test.dunit.Assert.assertFalse;
+import static org.apache.geode.test.dunit.Assert.assertNotNull;
+import static org.apache.geode.test.dunit.Assert.assertTrue;
+import static org.apache.geode.test.dunit.Host.getHost;
+import static org.apache.geode.test.dunit.IgnoredException.addIgnoredException;
+import static org.apache.geode.test.dunit.LogWriterUtils.getLogWriter;
+import static org.apache.geode.test.dunit.Wait.waitForCriterion;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.CacheFactory;
+import org.apache.geode.cache.RegionShortcut;
+import org.apache.geode.cache.wan.GatewaySender.OrderPolicy;
+import org.apache.geode.distributed.Locator;
+import org.apache.geode.distributed.internal.InternalLocator;
+import org.apache.geode.internal.ClassBuilder;
+import org.apache.geode.internal.JarDeployer;
+import org.apache.geode.internal.admin.remote.ShutdownAllRequest;
+import org.apache.geode.internal.cache.GemFireCacheImpl;
+import org.apache.geode.management.cli.Result.Status;
+import org.apache.geode.management.internal.cli.HeadlessGfsh;
+import org.apache.geode.management.internal.cli.commands.CliCommandTestBase;
+import org.apache.geode.management.internal.cli.i18n.CliStrings;
+import org.apache.geode.management.internal.cli.result.CommandResult;
+import org.apache.geode.management.internal.cli.util.CommandStringBuilder;
+import org.apache.geode.test.dunit.SerializableCallable;
+import org.apache.geode.test.dunit.VM;
+import org.apache.geode.test.dunit.WaitCriterion;
+import org.apache.geode.test.junit.categories.DistributedTest;
+import org.apache.geode.test.junit.categories.FlakyTest;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.HashSet;
+import java.util.Properties;
+import java.util.Set;
+
+@Category(DistributedTest.class)
+public class ClusterConfigurationServiceEndToEndDUnitTest extends CliCommandTestBase {
+
+ private static final int TIMEOUT = 10000;
+ private static final int INTERVAL = 500;
+
+ private static final String REGION1 = "R1";
+ private static final String REGION2 = "R2";
+ private static final String INDEX1 = "ID1";
+
+ private static Set<String> serverNames;
+ private static Set<String> jarFileNames;
+
+ private transient ClassBuilder classBuilder;
+ private transient String jmxHost;
+ private transient int jmxPort;
+ private transient int httpPort;
+ private transient String locatorString;
+
+ @Override
+ public final void postSetUpCliCommandTestBase() throws Exception {
+ disconnectAllFromDS();
+
+ addIgnoredException("EntryDestroyedException");
+
+ serverNames = new HashSet<>();
+ jarFileNames = new HashSet<>();
+
+ this.classBuilder = new ClassBuilder();
+
+ Object[] result = setup();
+ int locatorPort = (Integer) result[0];
+
+ this.jmxHost = (String) result[1];
+ this.jmxPort = (Integer) result[2];
+ this.httpPort = (Integer) result[3];
+ this.locatorString = "localHost[" + locatorPort + "]";
+ }
+
+ @Override
+ public final void preTearDownCliCommandTestBase() throws Exception {
+ // shutdown everything
+ shutdownAll();
+
+ serverNames.clear();
+ jarFileNames.clear();
+
+ serverNames = null;
+ jarFileNames = null;
+ }
+
+ @Category(FlakyTest.class) // GEODE-1606
+ @Test
+ public void testStartServerAndExecuteCommands() throws Exception {
+ final HeadlessGfsh gfsh = new HeadlessGfsh("gfsh2", 300, this.gfshDir);
+ assertNotNull(gfsh);
+ connect(jmxHost, jmxPort, httpPort, gfsh);
+
+ serverNames.addAll(startServers(gfsh, locatorString, 2, "Server", 1));
+ doCreateCommands();
+ serverNames.addAll(startServers(gfsh, locatorString, 1, "NewMember", 4));
+
+ verifyRegionCreateOnAllMembers(REGION1);
+ verifyRegionCreateOnAllMembers(REGION2);
+ verifyIndexCreationOnAllMembers(INDEX1);
+ verifyAsyncEventQueueCreation();
+ }
+
+ private Set<String> startServers(final HeadlessGfsh gfsh, final String locatorString,
+ final int numServers, final String serverNamePrefix, final int startNum)
+ throws ClassNotFoundException, IOException {
+ Set<String> serverNames = new HashSet<>();
+
+ final int[] serverPorts = getRandomAvailableTCPPorts(numServers);
+ for (int i = 0; i < numServers; i++) {
+ int port = serverPorts[i];
+ String serverName = serverNamePrefix + Integer.toString(i + startNum) + "-" + port;
+
+ CommandStringBuilder csb = new CommandStringBuilder(CliStrings.START_SERVER);
+ csb.addOption(CliStrings.START_SERVER__NAME, serverName);
+ csb.addOption(CliStrings.START_SERVER__LOCATORS, locatorString);
+ csb.addOption(CliStrings.START_SERVER__SERVER_PORT, Integer.toString(port));
+
+ CommandResult cmdResult = executeCommand(gfsh, csb.getCommandString());
+
+ assertEquals(Status.OK, cmdResult.getStatus());
+ }
+ return serverNames;
+ }
+
+ private void doCreateCommands() throws IOException {
+ createRegion(REGION1, REPLICATE, null);
+ createRegion(REGION2, PARTITION, null);
+ createIndex(INDEX1, "AAPL", REGION1, null);
+ createAndDeployJar(
+ this.temporaryFolder.getRoot().getCanonicalPath() + File.separator + "Deploy1.jar");
+ createAsyncEventQueue("q1");
+ final String autoCompact = "true";
+ final String allowForceCompaction = "true";
+ final String compactionThreshold = "50";
+ final String duCritical = "90";
+ final String duWarning = "85";
+ final String maxOplogSize = "1000";
+ final String queueSize = "300";
+ final String timeInterval = "10";
+ final String writeBufferSize = "100";
+ final String diskStoreName = "ds1";
+ final String diskDirs = "ds1";
+
+ createDiskStore(diskStoreName, diskDirs, autoCompact, allowForceCompaction, compactionThreshold,
+ duCritical, duWarning, maxOplogSize, queueSize, timeInterval, writeBufferSize);
+ }
+
+ private void executeAndVerifyCommand(final String commandString) {
+ CommandResult cmdResult = executeCommand(commandString);
+ getLogWriter().info("Command Result : \n" + commandResultToString(cmdResult));
+ assertEquals(Status.OK, cmdResult.getStatus());
+ assertFalse(cmdResult.failedToPersist());
+ }
+
+ private void createRegion(final String regionName, final RegionShortcut regionShortCut,
+ final String group) {
+ CommandStringBuilder csb = new CommandStringBuilder(CliStrings.CREATE_REGION);
+ csb.addOption(CliStrings.CREATE_REGION__REGION, regionName);
+ csb.addOption(CliStrings.CREATE_REGION__REGIONSHORTCUT, regionShortCut.name());
+ executeAndVerifyCommand(csb.getCommandString());
+ }
+
+ private void destroyRegion(final String regionName) {
+ CommandStringBuilder csb = new CommandStringBuilder(CliStrings.DESTROY_REGION);
+ csb.addOption(CliStrings.DESTROY_REGION__REGION, regionName);
+ executeAndVerifyCommand(csb.getCommandString());
+ }
+
+ private void stopServer(final String serverName) {
+ CommandStringBuilder csb = new CommandStringBuilder(CliStrings.STOP_SERVER);
+ csb.addOption(CliStrings.STOP_SERVER__MEMBER, serverName);
+ executeAndVerifyCommand(csb.getCommandString());
+ }
+
+ private void createAsyncEventQueue(final String queueName) throws IOException {
+ String queueCommandsJarName = "testEndToEndSC-QueueCommands.jar";
+ final File jarFile = new File(queueCommandsJarName);
+
+ try {
+ ClassBuilder classBuilder = new ClassBuilder();
+ byte[] jarBytes =
+ classBuilder.createJarFromClassContent("com/qcdunit/QueueCommandsDUnitTestListener",
+ "package com.qcdunit;" + "import java.util.List; import java.util.Properties;"
+ + "import org.apache.geode.internal.cache.xmlcache.Declarable2; import org.apache.geode.cache.asyncqueue.AsyncEvent;"
+ + "import org.apache.geode.cache.asyncqueue.AsyncEventListener;"
+ + "public class QueueCommandsDUnitTestListener implements Declarable2, AsyncEventListener {"
+ + "Properties props;"
+ + "public boolean processEvents(List<AsyncEvent> events) { return true; }"
+ + "public void close() {}"
+ + "public void init(final Properties props) {this.props = props;}"
+ + "public Properties getConfig() {return this.props;}}");
+
+ FileUtils.writeByteArrayToFile(jarFile, jarBytes);
+ CommandStringBuilder csb = new CommandStringBuilder(CliStrings.DEPLOY);
+ csb.addOption(CliStrings.DEPLOY__JAR, queueCommandsJarName);
+ executeAndVerifyCommand(csb.getCommandString());
+
+ csb = new CommandStringBuilder(CliStrings.CREATE_ASYNC_EVENT_QUEUE);
+ csb.addOption(CliStrings.CREATE_ASYNC_EVENT_QUEUE__ID, queueName);
+ csb.addOption(CliStrings.CREATE_ASYNC_EVENT_QUEUE__LISTENER,
+ "com.qcdunit.QueueCommandsDUnitTestListener");
+ csb.addOption(CliStrings.CREATE_ASYNC_EVENT_QUEUE__BATCH_SIZE, "100");
+ csb.addOption(CliStrings.CREATE_ASYNC_EVENT_QUEUE__BATCHTIMEINTERVAL, "200");
+ csb.addOption(CliStrings.CREATE_ASYNC_EVENT_QUEUE__DISPATCHERTHREADS, "4");
+ csb.addOption(CliStrings.CREATE_ASYNC_EVENT_QUEUE__ENABLEBATCHCONFLATION, "true");
+ csb.addOption(CliStrings.CREATE_ASYNC_EVENT_QUEUE__DISKSYNCHRONOUS, "true");
+ csb.addOption(CliStrings.CREATE_ASYNC_EVENT_QUEUE__FORWARD_EXPIRATION_DESTROY, "false");
+ csb.addOption(CliStrings.CREATE_ASYNC_EVENT_QUEUE__MAXIMUM_QUEUE_MEMORY, "1000");
+ csb.addOption(CliStrings.CREATE_ASYNC_EVENT_QUEUE__ORDERPOLICY, OrderPolicy.KEY.toString());
+ csb.addOption(CliStrings.CREATE_ASYNC_EVENT_QUEUE__PERSISTENT, "true");
+ csb.addOption(CliStrings.CREATE_ASYNC_EVENT_QUEUE__PARALLEL, "true");
+
+ executeAndVerifyCommand(csb.getCommandString());
+
+ } finally {
+ FileUtils.deleteQuietly(jarFile);
+ }
+ }
+
+ private void createDiskStore(final String diskStoreName, final String diskDirs,
+ final String autoCompact, final String allowForceCompaction, final String compactionThreshold,
+ final String duCritical, final String duWarning, final String maxOplogSize,
+ final String queueSize, final String timeInterval, final String writeBufferSize) {
+ CommandStringBuilder csb = new CommandStringBuilder(CliStrings.CREATE_DISK_STORE);
+ csb.addOption(CliStrings.CREATE_DISK_STORE__NAME, diskStoreName);
+ csb.addOption(CliStrings.CREATE_DISK_STORE__DIRECTORY_AND_SIZE, diskDirs);
+ csb.addOptionWithValueCheck(CliStrings.CREATE_DISK_STORE__AUTO_COMPACT, autoCompact);
+ csb.addOptionWithValueCheck(CliStrings.CREATE_DISK_STORE__ALLOW_FORCE_COMPACTION,
+ allowForceCompaction);
+ csb.addOptionWithValueCheck(CliStrings.CREATE_DISK_STORE__COMPACTION_THRESHOLD,
+ compactionThreshold);
+ csb.addOptionWithValueCheck(CliStrings.CREATE_DISK_STORE__DISK_USAGE_CRITICAL_PCT, duCritical);
+ csb.addOptionWithValueCheck(CliStrings.CREATE_DISK_STORE__DISK_USAGE_WARNING_PCT, duWarning);
+ csb.addOptionWithValueCheck(CliStrings.CREATE_DISK_STORE__MAX_OPLOG_SIZE, maxOplogSize);
+ csb.addOptionWithValueCheck(CliStrings.CREATE_DISK_STORE__QUEUE_SIZE, queueSize);
+ csb.addOptionWithValueCheck(CliStrings.CREATE_DISK_STORE__TIME_INTERVAL, timeInterval);
+ csb.addOptionWithValueCheck(CliStrings.CREATE_DISK_STORE__WRITE_BUFFER_SIZE, writeBufferSize);
+ executeAndVerifyCommand(csb.getCommandString());
+ }
+
+ private void destroyDiskStore(final String diskStoreName, final String group) {
+ CommandStringBuilder csb = new CommandStringBuilder(CliStrings.DESTROY_DISK_STORE);
+ csb.addOption(CliStrings.DESTROY_DISK_STORE__NAME, diskStoreName);
+ csb.addOptionWithValueCheck(CliStrings.DESTROY_DISK_STORE__GROUP, group);
+ executeAndVerifyCommand(csb.toString());
+ }
+
+ private void createIndex(final String indexName, final String expression, final String regionName,
+ final String group) {
+ CommandStringBuilder csb = new CommandStringBuilder(CliStrings.CREATE_INDEX);
+ csb.addOption(CliStrings.CREATE_INDEX__NAME, indexName);
+ csb.addOption(CliStrings.CREATE_INDEX__EXPRESSION, expression);
+ csb.addOption(CliStrings.CREATE_INDEX__REGION, regionName);
+ executeAndVerifyCommand(csb.getCommandString());
+ }
+
+ private void destroyIndex(final String indexName, final String regionName, final String group) {
+ if (isBlank(indexName) && isBlank(regionName) && isBlank(group)) {
+ return;
+ }
+ CommandStringBuilder csb = new CommandStringBuilder(CliStrings.DESTROY_INDEX);
+ if (!isBlank(indexName)) {
+ csb.addOption(CliStrings.DESTROY_INDEX__NAME, indexName);
+ }
+
+ if (!isBlank(regionName)) {
+ csb.addOption(CliStrings.DESTROY_INDEX__REGION, regionName);
+ }
+
+ if (!isBlank(group)) {
+ csb.addOption(CliStrings.DESTROY_INDEX__GROUP, group);
+ }
+ executeAndVerifyCommand(csb.getCommandString());
+ }
+
+ private void createAndDeployJar(final String jarName) throws IOException {
+ File newDeployableJarFile = new File(jarName);
+ this.classBuilder.writeJarFromName("ShareConfigClass", newDeployableJarFile);
+ CommandStringBuilder csb = new CommandStringBuilder(CliStrings.DEPLOY);
+ csb.addOption(CliStrings.DEPLOY__JAR, jarName);
+ executeAndVerifyCommand(csb.getCommandString());
+ jarFileNames.add(jarName);
+ }
+
+ private void deleteSavedJarFiles() throws IOException {
+ deleteMatching(new File("."), "^" + JarDeployer.JAR_PREFIX + "Deploy1.*#\\d++$");
+ delete(new File("Deploy1.jar"));
+ }
+
+ private Object[] setup() throws IOException {
+ final int[] ports = getRandomAvailableTCPPorts(3);
+ final int locator1Port = ports[0];
+
+ final String locator1Name = "locator1-" + locator1Port;
+ final String locatorLogPath = this.temporaryFolder.getRoot().getCanonicalPath() + File.separator
+ + "locator-" + locator1Port + ".log";
+
+ VM locatorAndMgr = getHost(0).getVM(3);
+ Object[] result = (Object[]) locatorAndMgr.invoke(new SerializableCallable() {
+ @Override
+ public Object call() throws IOException {
+ int httpPort;
+ int jmxPort;
+ String jmxHost;
+
+ try {
+ jmxHost = InetAddress.getLocalHost().getHostName();
+ } catch (UnknownHostException ignore) {
+ jmxHost = "localhost";
+ }
+
+ final int[] ports = getRandomAvailableTCPPorts(2);
+
+ jmxPort = ports[0];
+ httpPort = ports[1];
+
+ final File locatorLogFile = new File(locatorLogPath);
+
+ final Properties locatorProps = new Properties();
+ locatorProps.setProperty(NAME, locator1Name);
+ locatorProps.setProperty(MCAST_PORT, "0");
+ locatorProps.setProperty(LOG_LEVEL, "config");
+ locatorProps.setProperty(ENABLE_CLUSTER_CONFIGURATION, "true");
+ locatorProps.setProperty(JMX_MANAGER, "true");
+ locatorProps.setProperty(JMX_MANAGER_START, "true");
+ locatorProps.setProperty(JMX_MANAGER_BIND_ADDRESS, String.valueOf(jmxHost));
+ locatorProps.setProperty(JMX_MANAGER_PORT, String.valueOf(jmxPort));
+ locatorProps.setProperty(HTTP_SERVICE_PORT, String.valueOf(httpPort));
+
+ final InternalLocator locator = (InternalLocator) Locator.startLocatorAndDS(locator1Port,
+ locatorLogFile, null, locatorProps);
+
+ WaitCriterion wc = new WaitCriterion() {
+ @Override
+ public boolean done() {
+ return locator.isSharedConfigurationRunning();
+ }
+
+ @Override
+ public String description() {
+ return "Waiting for shared configuration to be started";
+ }
+ };
+ waitForCriterion(wc, TIMEOUT, INTERVAL, true);
+
+ final Object[] result = new Object[4];
+ result[0] = locator1Port;
+ result[1] = jmxHost;
+ result[2] = jmxPort;
+ result[3] = httpPort;
+ return result;
+ }
+ });
+
+ HeadlessGfsh gfsh = getDefaultShell();
+ String jmxHost = (String) result[1];
+ int jmxPort = (Integer) result[2];
+ int httpPort = (Integer) result[3];
+
+ connect(jmxHost, jmxPort, httpPort, gfsh);
+
+ // Create a cache in VM 1
+ VM dataMember = getHost(0).getVM(1);
+ dataMember.invoke(new SerializableCallable() {
+ @Override
+ public Object call() {
+ Properties localProps = new Properties();
+ localProps.setProperty(MCAST_PORT, "0");
+ localProps.setProperty(LOCATORS, "localhost[" + locator1Port + "]");
+ localProps.setProperty(NAME, "DataMember");
+ getSystem(localProps);
+ Cache cache = getCache();
+ assertNotNull(cache);
+ return getAllNormalMembers(cache);
+ }
+ });
+ return result;
+ }
+
+ private void shutdownAll() throws IOException {
+ VM locatorAndMgr = getHost(0).getVM(3);
+ locatorAndMgr.invoke(new SerializableCallable() {
+ @Override
+ public Object call() throws Exception {
+ GemFireCacheImpl cache = (GemFireCacheImpl) CacheFactory.getAnyInstance();
+ ShutdownAllRequest.send(cache.getDistributedSystem().getDistributionManager(), -1);
+ return null;
+ }
+ });
+
+ locatorAndMgr.invoke(SharedConfigurationTestUtils.cleanupLocator);
+
+ // Clean up the directories
+ if (!serverNames.isEmpty()) {
+ for (String serverName : serverNames) {
+ final File serverDir = new File(serverName);
+ FileUtils.cleanDirectory(serverDir);
+ FileUtils.deleteDirectory(serverDir);
+ }
+ }
+ serverNames.clear();
+ }
+
+ private void verifyRegionCreateOnAllMembers(final String regionName) {
+ CommandStringBuilder csb = new CommandStringBuilder(CliStrings.DESCRIBE_REGION);
+ csb.addOption(CliStrings.DESCRIBE_REGION__NAME, regionName);
+ CommandResult cmdResult = executeCommand(csb.getCommandString());
+ String resultAsString = commandResultToString(cmdResult);
+
+ for (String serverName : serverNames) {
+ assertTrue(resultAsString.contains(serverName));
+ }
+ }
+
+ private void verifyIndexCreationOnAllMembers(final String indexName) {
+ CommandStringBuilder csb = new CommandStringBuilder(CliStrings.LIST_INDEX);
+ CommandResult cmdResult = executeCommand(csb.getCommandString());
+ String resultAsString = commandResultToString(cmdResult);
+
+ for (String serverName : serverNames) {
+ assertTrue(resultAsString.contains(serverName));
+ }
+ }
+
+ private void verifyAsyncEventQueueCreation() {
+ CommandStringBuilder csb = new CommandStringBuilder(CliStrings.LIST_ASYNC_EVENT_QUEUES);
+ CommandResult cmdResult = executeCommand(csb.toString());
+ String resultAsString = commandResultToString(cmdResult);
+
+ for (String serverName : serverNames) {
+ assertTrue(resultAsString.contains(serverName));
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/geode/blob/e79e0103/geode-assembly/src/test/java/org/apache/geode/management/internal/configuration/SharedConfigurationEndToEndDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-assembly/src/test/java/org/apache/geode/management/internal/configuration/SharedConfigurationEndToEndDUnitTest.java b/geode-assembly/src/test/java/org/apache/geode/management/internal/configuration/SharedConfigurationEndToEndDUnitTest.java
deleted file mode 100644
index ec329d3..0000000
--- a/geode-assembly/src/test/java/org/apache/geode/management/internal/configuration/SharedConfigurationEndToEndDUnitTest.java
+++ /dev/null
@@ -1,464 +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.internal.configuration;
-
-import org.apache.geode.cache.Cache;
-import org.apache.geode.cache.CacheFactory;
-import org.apache.geode.cache.RegionShortcut;
-import org.apache.geode.cache.wan.GatewaySender.OrderPolicy;
-import org.apache.geode.distributed.Locator;
-import org.apache.geode.distributed.internal.InternalLocator;
-import org.apache.geode.internal.ClassBuilder;
-import org.apache.geode.internal.JarDeployer;
-import org.apache.geode.internal.admin.remote.ShutdownAllRequest;
-import org.apache.geode.internal.cache.GemFireCacheImpl;
-import org.apache.geode.management.cli.Result.Status;
-import org.apache.geode.management.internal.cli.HeadlessGfsh;
-import org.apache.geode.management.internal.cli.commands.CliCommandTestBase;
-import org.apache.geode.management.internal.cli.i18n.CliStrings;
-import org.apache.geode.management.internal.cli.result.CommandResult;
-import org.apache.geode.management.internal.cli.util.CommandStringBuilder;
-import org.apache.geode.test.dunit.SerializableCallable;
-import org.apache.geode.test.dunit.VM;
-import org.apache.geode.test.dunit.WaitCriterion;
-import org.apache.geode.test.junit.categories.DistributedTest;
-import org.apache.geode.test.junit.categories.FlakyTest;
-import org.apache.commons.io.FileUtils;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-
-import java.io.File;
-import java.io.IOException;
-import java.net.InetAddress;
-import java.net.UnknownHostException;
-import java.util.HashSet;
-import java.util.Properties;
-import java.util.Set;
-
-import static org.apache.geode.cache.RegionShortcut.PARTITION;
-import static org.apache.geode.cache.RegionShortcut.REPLICATE;
-import static org.apache.geode.distributed.ConfigurationProperties.*;
-import static org.apache.geode.internal.AvailablePortHelper.getRandomAvailableTCPPorts;
-import static org.apache.geode.internal.FileUtil.delete;
-import static org.apache.geode.internal.FileUtil.deleteMatching;
-import static org.apache.geode.internal.lang.StringUtils.isBlank;
-import static org.apache.geode.management.internal.cli.CliUtil.getAllNormalMembers;
-import static org.apache.geode.test.dunit.Assert.*;
-import static org.apache.geode.test.dunit.Host.getHost;
-import static org.apache.geode.test.dunit.IgnoredException.addIgnoredException;
-import static org.apache.geode.test.dunit.LogWriterUtils.getLogWriter;
-import static org.apache.geode.test.dunit.Wait.waitForCriterion;
-
-@Category(DistributedTest.class)
-public class SharedConfigurationEndToEndDUnitTest extends CliCommandTestBase {
-
- private static final int TIMEOUT = 10000;
- private static final int INTERVAL = 500;
-
- private static final String REGION1 = "R1";
- private static final String REGION2 = "R2";
- private static final String INDEX1 = "ID1";
-
- private static Set<String> serverNames;
- private static Set<String> jarFileNames;
-
- private transient ClassBuilder classBuilder;
- private transient String jmxHost;
- private transient int jmxPort;
- private transient int httpPort;
- private transient String locatorString;
-
- @Override
- public final void postSetUpCliCommandTestBase() throws Exception {
- disconnectAllFromDS();
-
- addIgnoredException("EntryDestroyedException");
-
- serverNames = new HashSet<>();
- jarFileNames = new HashSet<>();
-
- this.classBuilder = new ClassBuilder();
-
- Object[] result = setup();
- int locatorPort = (Integer) result[0];
-
- this.jmxHost = (String) result[1];
- this.jmxPort = (Integer) result[2];
- this.httpPort = (Integer) result[3];
- this.locatorString = "localHost[" + locatorPort + "]";
- }
-
- @Override
- public final void preTearDownCliCommandTestBase() throws Exception {
- // shutdown everything
- shutdownAll();
-
- serverNames.clear();
- jarFileNames.clear();
-
- serverNames = null;
- jarFileNames = null;
- }
-
- @Category(FlakyTest.class) // GEODE-1606
- @Test
- public void testStartServerAndExecuteCommands() throws Exception {
- final HeadlessGfsh gfsh = new HeadlessGfsh("gfsh2", 300, this.gfshDir);
- assertNotNull(gfsh);
- connect(jmxHost, jmxPort, httpPort, gfsh);
-
- serverNames.addAll(startServers(gfsh, locatorString, 2, "Server", 1));
- doCreateCommands();
- serverNames.addAll(startServers(gfsh, locatorString, 1, "NewMember", 4));
-
- verifyRegionCreateOnAllMembers(REGION1);
- verifyRegionCreateOnAllMembers(REGION2);
- verifyIndexCreationOnAllMembers(INDEX1);
- verifyAsyncEventQueueCreation();
- }
-
- private Set<String> startServers(final HeadlessGfsh gfsh, final String locatorString,
- final int numServers, final String serverNamePrefix, final int startNum)
- throws ClassNotFoundException, IOException {
- Set<String> serverNames = new HashSet<>();
-
- final int[] serverPorts = getRandomAvailableTCPPorts(numServers);
- for (int i = 0; i < numServers; i++) {
- int port = serverPorts[i];
- String serverName = serverNamePrefix + Integer.toString(i + startNum) + "-" + port;
-
- CommandStringBuilder csb = new CommandStringBuilder(CliStrings.START_SERVER);
- csb.addOption(CliStrings.START_SERVER__NAME, serverName);
- csb.addOption(CliStrings.START_SERVER__LOCATORS, locatorString);
- csb.addOption(CliStrings.START_SERVER__SERVER_PORT, Integer.toString(port));
-
- CommandResult cmdResult = executeCommand(gfsh, csb.getCommandString());
-
- assertEquals(Status.OK, cmdResult.getStatus());
- }
- return serverNames;
- }
-
- private void doCreateCommands() throws IOException {
- createRegion(REGION1, REPLICATE, null);
- createRegion(REGION2, PARTITION, null);
- createIndex(INDEX1, "AAPL", REGION1, null);
- createAndDeployJar(
- this.temporaryFolder.getRoot().getCanonicalPath() + File.separator + "Deploy1.jar");
- createAsyncEventQueue("q1");
- final String autoCompact = "true";
- final String allowForceCompaction = "true";
- final String compactionThreshold = "50";
- final String duCritical = "90";
- final String duWarning = "85";
- final String maxOplogSize = "1000";
- final String queueSize = "300";
- final String timeInterval = "10";
- final String writeBufferSize = "100";
- final String diskStoreName = "ds1";
- final String diskDirs = "ds1";
-
- createDiskStore(diskStoreName, diskDirs, autoCompact, allowForceCompaction, compactionThreshold,
- duCritical, duWarning, maxOplogSize, queueSize, timeInterval, writeBufferSize);
- }
-
- private void executeAndVerifyCommand(final String commandString) {
- CommandResult cmdResult = executeCommand(commandString);
- getLogWriter().info("Command Result : \n" + commandResultToString(cmdResult));
- assertEquals(Status.OK, cmdResult.getStatus());
- assertFalse(cmdResult.failedToPersist());
- }
-
- private void createRegion(final String regionName, final RegionShortcut regionShortCut,
- final String group) {
- CommandStringBuilder csb = new CommandStringBuilder(CliStrings.CREATE_REGION);
- csb.addOption(CliStrings.CREATE_REGION__REGION, regionName);
- csb.addOption(CliStrings.CREATE_REGION__REGIONSHORTCUT, regionShortCut.name());
- executeAndVerifyCommand(csb.getCommandString());
- }
-
- private void destroyRegion(final String regionName) {
- CommandStringBuilder csb = new CommandStringBuilder(CliStrings.DESTROY_REGION);
- csb.addOption(CliStrings.DESTROY_REGION__REGION, regionName);
- executeAndVerifyCommand(csb.getCommandString());
- }
-
- private void stopServer(final String serverName) {
- CommandStringBuilder csb = new CommandStringBuilder(CliStrings.STOP_SERVER);
- csb.addOption(CliStrings.STOP_SERVER__MEMBER, serverName);
- executeAndVerifyCommand(csb.getCommandString());
- }
-
- private void createAsyncEventQueue(final String queueName) throws IOException {
- String queueCommandsJarName = "testEndToEndSC-QueueCommands.jar";
- final File jarFile = new File(queueCommandsJarName);
-
- try {
- ClassBuilder classBuilder = new ClassBuilder();
- byte[] jarBytes =
- classBuilder.createJarFromClassContent("com/qcdunit/QueueCommandsDUnitTestListener",
- "package com.qcdunit;" + "import java.util.List; import java.util.Properties;"
- + "import org.apache.geode.internal.cache.xmlcache.Declarable2; import org.apache.geode.cache.asyncqueue.AsyncEvent;"
- + "import org.apache.geode.cache.asyncqueue.AsyncEventListener;"
- + "public class QueueCommandsDUnitTestListener implements Declarable2, AsyncEventListener {"
- + "Properties props;"
- + "public boolean processEvents(List<AsyncEvent> events) { return true; }"
- + "public void close() {}"
- + "public void init(final Properties props) {this.props = props;}"
- + "public Properties getConfig() {return this.props;}}");
-
- FileUtils.writeByteArrayToFile(jarFile, jarBytes);
- CommandStringBuilder csb = new CommandStringBuilder(CliStrings.DEPLOY);
- csb.addOption(CliStrings.DEPLOY__JAR, queueCommandsJarName);
- executeAndVerifyCommand(csb.getCommandString());
-
- csb = new CommandStringBuilder(CliStrings.CREATE_ASYNC_EVENT_QUEUE);
- csb.addOption(CliStrings.CREATE_ASYNC_EVENT_QUEUE__ID, queueName);
- csb.addOption(CliStrings.CREATE_ASYNC_EVENT_QUEUE__LISTENER,
- "com.qcdunit.QueueCommandsDUnitTestListener");
- csb.addOption(CliStrings.CREATE_ASYNC_EVENT_QUEUE__BATCH_SIZE, "100");
- csb.addOption(CliStrings.CREATE_ASYNC_EVENT_QUEUE__BATCHTIMEINTERVAL, "200");
- csb.addOption(CliStrings.CREATE_ASYNC_EVENT_QUEUE__DISPATCHERTHREADS, "4");
- csb.addOption(CliStrings.CREATE_ASYNC_EVENT_QUEUE__ENABLEBATCHCONFLATION, "true");
- csb.addOption(CliStrings.CREATE_ASYNC_EVENT_QUEUE__DISKSYNCHRONOUS, "true");
- csb.addOption(CliStrings.CREATE_ASYNC_EVENT_QUEUE__FORWARD_EXPIRATION_DESTROY, "false");
- csb.addOption(CliStrings.CREATE_ASYNC_EVENT_QUEUE__MAXIMUM_QUEUE_MEMORY, "1000");
- csb.addOption(CliStrings.CREATE_ASYNC_EVENT_QUEUE__ORDERPOLICY, OrderPolicy.KEY.toString());
- csb.addOption(CliStrings.CREATE_ASYNC_EVENT_QUEUE__PERSISTENT, "true");
- csb.addOption(CliStrings.CREATE_ASYNC_EVENT_QUEUE__PARALLEL, "true");
-
- executeAndVerifyCommand(csb.getCommandString());
-
- } finally {
- FileUtils.deleteQuietly(jarFile);
- }
- }
-
- private void createDiskStore(final String diskStoreName, final String diskDirs,
- final String autoCompact, final String allowForceCompaction, final String compactionThreshold,
- final String duCritical, final String duWarning, final String maxOplogSize,
- final String queueSize, final String timeInterval, final String writeBufferSize) {
- CommandStringBuilder csb = new CommandStringBuilder(CliStrings.CREATE_DISK_STORE);
- csb.addOption(CliStrings.CREATE_DISK_STORE__NAME, diskStoreName);
- csb.addOption(CliStrings.CREATE_DISK_STORE__DIRECTORY_AND_SIZE, diskDirs);
- csb.addOptionWithValueCheck(CliStrings.CREATE_DISK_STORE__AUTO_COMPACT, autoCompact);
- csb.addOptionWithValueCheck(CliStrings.CREATE_DISK_STORE__ALLOW_FORCE_COMPACTION,
- allowForceCompaction);
- csb.addOptionWithValueCheck(CliStrings.CREATE_DISK_STORE__COMPACTION_THRESHOLD,
- compactionThreshold);
- csb.addOptionWithValueCheck(CliStrings.CREATE_DISK_STORE__DISK_USAGE_CRITICAL_PCT, duCritical);
- csb.addOptionWithValueCheck(CliStrings.CREATE_DISK_STORE__DISK_USAGE_WARNING_PCT, duWarning);
- csb.addOptionWithValueCheck(CliStrings.CREATE_DISK_STORE__MAX_OPLOG_SIZE, maxOplogSize);
- csb.addOptionWithValueCheck(CliStrings.CREATE_DISK_STORE__QUEUE_SIZE, queueSize);
- csb.addOptionWithValueCheck(CliStrings.CREATE_DISK_STORE__TIME_INTERVAL, timeInterval);
- csb.addOptionWithValueCheck(CliStrings.CREATE_DISK_STORE__WRITE_BUFFER_SIZE, writeBufferSize);
- executeAndVerifyCommand(csb.getCommandString());
- }
-
- private void destroyDiskStore(final String diskStoreName, final String group) {
- CommandStringBuilder csb = new CommandStringBuilder(CliStrings.DESTROY_DISK_STORE);
- csb.addOption(CliStrings.DESTROY_DISK_STORE__NAME, diskStoreName);
- csb.addOptionWithValueCheck(CliStrings.DESTROY_DISK_STORE__GROUP, group);
- executeAndVerifyCommand(csb.toString());
- }
-
- private void createIndex(final String indexName, final String expression, final String regionName,
- final String group) {
- CommandStringBuilder csb = new CommandStringBuilder(CliStrings.CREATE_INDEX);
- csb.addOption(CliStrings.CREATE_INDEX__NAME, indexName);
- csb.addOption(CliStrings.CREATE_INDEX__EXPRESSION, expression);
- csb.addOption(CliStrings.CREATE_INDEX__REGION, regionName);
- executeAndVerifyCommand(csb.getCommandString());
- }
-
- private void destroyIndex(final String indexName, final String regionName, final String group) {
- if (isBlank(indexName) && isBlank(regionName) && isBlank(group)) {
- return;
- }
- CommandStringBuilder csb = new CommandStringBuilder(CliStrings.DESTROY_INDEX);
- if (!isBlank(indexName)) {
- csb.addOption(CliStrings.DESTROY_INDEX__NAME, indexName);
- }
-
- if (!isBlank(regionName)) {
- csb.addOption(CliStrings.DESTROY_INDEX__REGION, regionName);
- }
-
- if (!isBlank(group)) {
- csb.addOption(CliStrings.DESTROY_INDEX__GROUP, group);
- }
- executeAndVerifyCommand(csb.getCommandString());
- }
-
- private void createAndDeployJar(final String jarName) throws IOException {
- File newDeployableJarFile = new File(jarName);
- this.classBuilder.writeJarFromName("ShareConfigClass", newDeployableJarFile);
- CommandStringBuilder csb = new CommandStringBuilder(CliStrings.DEPLOY);
- csb.addOption(CliStrings.DEPLOY__JAR, jarName);
- executeAndVerifyCommand(csb.getCommandString());
- jarFileNames.add(jarName);
- }
-
- private void deleteSavedJarFiles() throws IOException {
- deleteMatching(new File("."), "^" + JarDeployer.JAR_PREFIX + "Deploy1.*#\\d++$");
- delete(new File("Deploy1.jar"));
- }
-
- private Object[] setup() throws IOException {
- final int[] ports = getRandomAvailableTCPPorts(3);
- final int locator1Port = ports[0];
-
- final String locator1Name = "locator1-" + locator1Port;
- final String locatorLogPath = this.temporaryFolder.getRoot().getCanonicalPath() + File.separator
- + "locator-" + locator1Port + ".log";
-
- VM locatorAndMgr = getHost(0).getVM(3);
- Object[] result = (Object[]) locatorAndMgr.invoke(new SerializableCallable() {
- @Override
- public Object call() throws IOException {
- int httpPort;
- int jmxPort;
- String jmxHost;
-
- try {
- jmxHost = InetAddress.getLocalHost().getHostName();
- } catch (UnknownHostException ignore) {
- jmxHost = "localhost";
- }
-
- final int[] ports = getRandomAvailableTCPPorts(2);
-
- jmxPort = ports[0];
- httpPort = ports[1];
-
- final File locatorLogFile = new File(locatorLogPath);
-
- final Properties locatorProps = new Properties();
- locatorProps.setProperty(NAME, locator1Name);
- locatorProps.setProperty(MCAST_PORT, "0");
- locatorProps.setProperty(LOG_LEVEL, "config");
- locatorProps.setProperty(ENABLE_CLUSTER_CONFIGURATION, "true");
- locatorProps.setProperty(JMX_MANAGER, "true");
- locatorProps.setProperty(JMX_MANAGER_START, "true");
- locatorProps.setProperty(JMX_MANAGER_BIND_ADDRESS, String.valueOf(jmxHost));
- locatorProps.setProperty(JMX_MANAGER_PORT, String.valueOf(jmxPort));
- locatorProps.setProperty(HTTP_SERVICE_PORT, String.valueOf(httpPort));
-
- final InternalLocator locator = (InternalLocator) Locator.startLocatorAndDS(locator1Port,
- locatorLogFile, null, locatorProps);
-
- WaitCriterion wc = new WaitCriterion() {
- @Override
- public boolean done() {
- return locator.isSharedConfigurationRunning();
- }
-
- @Override
- public String description() {
- return "Waiting for shared configuration to be started";
- }
- };
- waitForCriterion(wc, TIMEOUT, INTERVAL, true);
-
- final Object[] result = new Object[4];
- result[0] = locator1Port;
- result[1] = jmxHost;
- result[2] = jmxPort;
- result[3] = httpPort;
- return result;
- }
- });
-
- HeadlessGfsh gfsh = getDefaultShell();
- String jmxHost = (String) result[1];
- int jmxPort = (Integer) result[2];
- int httpPort = (Integer) result[3];
-
- connect(jmxHost, jmxPort, httpPort, gfsh);
-
- // Create a cache in VM 1
- VM dataMember = getHost(0).getVM(1);
- dataMember.invoke(new SerializableCallable() {
- @Override
- public Object call() {
- Properties localProps = new Properties();
- localProps.setProperty(MCAST_PORT, "0");
- localProps.setProperty(LOCATORS, "localhost[" + locator1Port + "]");
- localProps.setProperty(NAME, "DataMember");
- getSystem(localProps);
- Cache cache = getCache();
- assertNotNull(cache);
- return getAllNormalMembers(cache);
- }
- });
- return result;
- }
-
- private void shutdownAll() throws IOException {
- VM locatorAndMgr = getHost(0).getVM(3);
- locatorAndMgr.invoke(new SerializableCallable() {
- @Override
- public Object call() throws Exception {
- GemFireCacheImpl cache = (GemFireCacheImpl) CacheFactory.getAnyInstance();
- ShutdownAllRequest.send(cache.getDistributedSystem().getDistributionManager(), -1);
- return null;
- }
- });
-
- locatorAndMgr.invoke(SharedConfigurationTestUtils.cleanupLocator);
-
- // Clean up the directories
- if (!serverNames.isEmpty()) {
- for (String serverName : serverNames) {
- final File serverDir = new File(serverName);
- FileUtils.cleanDirectory(serverDir);
- FileUtils.deleteDirectory(serverDir);
- }
- }
- serverNames.clear();
- }
-
- private void verifyRegionCreateOnAllMembers(final String regionName) {
- CommandStringBuilder csb = new CommandStringBuilder(CliStrings.DESCRIBE_REGION);
- csb.addOption(CliStrings.DESCRIBE_REGION__NAME, regionName);
- CommandResult cmdResult = executeCommand(csb.getCommandString());
- String resultAsString = commandResultToString(cmdResult);
-
- for (String serverName : serverNames) {
- assertTrue(resultAsString.contains(serverName));
- }
- }
-
- private void verifyIndexCreationOnAllMembers(final String indexName) {
- CommandStringBuilder csb = new CommandStringBuilder(CliStrings.LIST_INDEX);
- CommandResult cmdResult = executeCommand(csb.getCommandString());
- String resultAsString = commandResultToString(cmdResult);
-
- for (String serverName : serverNames) {
- assertTrue(resultAsString.contains(serverName));
- }
- }
-
- private void verifyAsyncEventQueueCreation() {
- CommandStringBuilder csb = new CommandStringBuilder(CliStrings.LIST_ASYNC_EVENT_QUEUES);
- CommandResult cmdResult = executeCommand(csb.toString());
- String resultAsString = commandResultToString(cmdResult);
-
- for (String serverName : serverNames) {
- assertTrue(resultAsString.contains(serverName));
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/geode/blob/e79e0103/geode-core/src/main/java/org/apache/geode/distributed/internal/AbstractDistributionConfig.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/distributed/internal/AbstractDistributionConfig.java b/geode-core/src/main/java/org/apache/geode/distributed/internal/AbstractDistributionConfig.java
index c68e502..decb61d 100644
--- a/geode-core/src/main/java/org/apache/geode/distributed/internal/AbstractDistributionConfig.java
+++ b/geode-core/src/main/java/org/apache/geode/distributed/internal/AbstractDistributionConfig.java
@@ -16,20 +16,7 @@ package org.apache.geode.distributed.internal;
import static org.apache.geode.distributed.ConfigurationProperties.*;
-import java.lang.reflect.Method;
-import java.net.InetAddress;
-import java.net.UnknownHostException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.StringTokenizer;
-
import org.apache.commons.lang.StringUtils;
-
import org.apache.geode.InternalGemFireException;
import org.apache.geode.InvalidValueException;
import org.apache.geode.UnmodifiableException;
@@ -42,6 +29,18 @@ import org.apache.geode.internal.net.SocketCreator;
import org.apache.geode.internal.security.SecurableCommunicationChannel;
import org.apache.geode.memcached.GemFireMemcachedServer;
+import java.lang.reflect.Method;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.StringTokenizer;
+
/**
* Provides an implementation of <code>DistributionConfig</code> that knows how to read the
* configuration file.
@@ -1084,7 +1083,7 @@ public abstract class AbstractDistributionConfig extends AbstractConfig
LocalizedStrings.AbstractDistributionConfig_USE_SHARED_CONFIGURATION.toLocalizedString());
m.put(LOAD_CLUSTER_CONFIGURATION_FROM_DIR,
LocalizedStrings.AbstractDistributionConfig_LOAD_SHARED_CONFIGURATION_FROM_DIR
- .toLocalizedString(SharedConfiguration.CLUSTER_CONFIG_ARTIFACTS_DIR_NAME));
+ .toLocalizedString(ClusterConfigurationService.CLUSTER_CONFIG_ARTIFACTS_DIR_NAME));
m.put(CLUSTER_CONFIGURATION_DIR,
LocalizedStrings.AbstractDistributionConfig_CLUSTER_CONFIGURATION_DIR.toLocalizedString());
m.put(SSL_SERVER_ALIAS, LocalizedStrings.AbstractDistributionConfig_SERVER_SSL_ALIAS_0
http://git-wip-us.apache.org/repos/asf/geode/blob/e79e0103/geode-core/src/main/java/org/apache/geode/distributed/internal/ClusterConfigurationService.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/distributed/internal/ClusterConfigurationService.java b/geode-core/src/main/java/org/apache/geode/distributed/internal/ClusterConfigurationService.java
new file mode 100644
index 0000000..1d4030a
--- /dev/null
+++ b/geode-core/src/main/java/org/apache/geode/distributed/internal/ClusterConfigurationService.java
@@ -0,0 +1,748 @@
+/*
+ * 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.distributed.internal;
+
+import static org.apache.geode.distributed.ConfigurationProperties.CLUSTER_CONFIGURATION_DIR;
+import static org.apache.geode.distributed.ConfigurationProperties.SECURITY_MANAGER;
+import static org.apache.geode.distributed.ConfigurationProperties.SECURITY_POST_PROCESSOR;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.FilenameUtils;
+import org.apache.commons.io.filefilter.DirectoryFileFilter;
+import org.apache.geode.CancelException;
+import org.apache.geode.cache.AttributesFactory;
+import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.DataPolicy;
+import org.apache.geode.cache.DiskStore;
+import org.apache.geode.cache.Region;
+import org.apache.geode.cache.Scope;
+import org.apache.geode.cache.execute.ResultCollector;
+import org.apache.geode.distributed.DistributedLockService;
+import org.apache.geode.distributed.DistributedMember;
+import org.apache.geode.distributed.DistributedSystem;
+import org.apache.geode.distributed.internal.locks.DLockService;
+import org.apache.geode.internal.cache.GemFireCacheImpl;
+import org.apache.geode.internal.cache.InternalRegionArguments;
+import org.apache.geode.internal.cache.persistence.PersistentMemberID;
+import org.apache.geode.internal.cache.persistence.PersistentMemberManager;
+import org.apache.geode.internal.cache.persistence.PersistentMemberPattern;
+import org.apache.geode.internal.cache.xmlcache.CacheXmlGenerator;
+import org.apache.geode.internal.lang.StringUtils;
+import org.apache.geode.internal.logging.LogService;
+import org.apache.geode.management.internal.cli.CliUtil;
+import org.apache.geode.management.internal.configuration.callbacks.ConfigurationChangeListener;
+import org.apache.geode.management.internal.configuration.domain.Configuration;
+import org.apache.geode.management.internal.configuration.domain.SharedConfigurationStatus;
+import org.apache.geode.management.internal.configuration.domain.XmlEntity;
+import org.apache.geode.management.internal.configuration.functions.UploadJarFunction;
+import org.apache.geode.management.internal.configuration.messages.ConfigurationRequest;
+import org.apache.geode.management.internal.configuration.messages.ConfigurationResponse;
+import org.apache.geode.management.internal.configuration.messages.SharedConfigurationStatusResponse;
+import org.apache.geode.management.internal.configuration.utils.XmlUtils;
+import org.apache.logging.log4j.Logger;
+import org.w3c.dom.Document;
+import org.xml.sax.SAXException;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileFilter;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.nio.file.Path;
+import java.text.SimpleDateFormat;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Properties;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicReference;
+import java.util.stream.Collectors;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactoryConfigurationError;
+
+@SuppressWarnings({"deprecation", "unchecked"})
+public class ClusterConfigurationService {
+
+ private static final Logger logger = LogService.getLogger();
+
+ /**
+ * Name of the directory where the shared configuration artifacts are stored
+ */
+ public static final String CLUSTER_CONFIG_ARTIFACTS_DIR_NAME = "cluster_config";
+ private static final String CLUSTER_CONFIG_DISK_STORE_NAME = "cluster_config";
+ public static final String CLUSTER_CONFIG_DISK_DIR_PREFIX = "ConfigDiskDir_";
+
+ public static final String CLUSTER_CONFIG = "cluster";
+
+ /**
+ * Name of the lock service used for shared configuration
+ */
+ private static final String SHARED_CONFIG_LOCK_SERVICE_NAME = "__CLUSTER_CONFIG_LS";
+
+ /**
+ * Name of the lock for locking the shared configuration
+ */
+ public static final String SHARED_CONFIG_LOCK_NAME = "__CLUSTER_CONFIG_LOCK";
+
+ /**
+ * Name of the region which is used to store the configuration information
+ */
+ private static final String CONFIG_REGION_NAME = "_ConfigurationRegion";
+
+ private final String configDirPath;
+ private final String configDiskDirPath;
+
+ private final Set<PersistentMemberPattern> newerSharedConfigurationLocatorInfo = new HashSet<>();
+ private final AtomicReference<SharedConfigurationStatus> status = new AtomicReference<>();
+
+ private GemFireCacheImpl cache;
+ private final DistributedLockService sharedConfigLockingService;
+
+ /**
+ * Gets or creates (if not created) shared configuration lock service
+ */
+ public static DistributedLockService getSharedConfigLockService(DistributedSystem ds) {
+ DistributedLockService sharedConfigDls =
+ DLockService.getServiceNamed(SHARED_CONFIG_LOCK_SERVICE_NAME);
+ try {
+ if (sharedConfigDls == null) {
+ sharedConfigDls = DLockService.create(SHARED_CONFIG_LOCK_SERVICE_NAME,
+ (InternalDistributedSystem) ds, true, true);
+ }
+ } catch (IllegalArgumentException e) {
+ return DLockService.getServiceNamed(SHARED_CONFIG_LOCK_SERVICE_NAME);
+ }
+ return sharedConfigDls;
+ }
+
+ public ClusterConfigurationService(Cache cache) throws IOException {
+ this.cache = (GemFireCacheImpl) cache;
+ Properties properties = cache.getDistributedSystem().getProperties();
+ // resolve the cluster config dir
+ String clusterConfigRootDir = properties.getProperty(CLUSTER_CONFIGURATION_DIR);
+
+ if (StringUtils.isBlank(clusterConfigRootDir)) {
+ clusterConfigRootDir = System.getProperty("user.dir");
+ } else {
+ File diskDir = new File(clusterConfigRootDir);
+ if (!diskDir.exists() && !diskDir.mkdirs()) {
+ throw new IOException("Cannot create directory : " + clusterConfigRootDir);
+ }
+ clusterConfigRootDir = diskDir.getCanonicalPath();
+ }
+
+ // resolve the file paths
+ String configDiskDirName =
+ CLUSTER_CONFIG_DISK_DIR_PREFIX + cache.getDistributedSystem().getName();
+
+ configDirPath = FilenameUtils.concat(clusterConfigRootDir, CLUSTER_CONFIG_ARTIFACTS_DIR_NAME);
+ configDiskDirPath = FilenameUtils.concat(clusterConfigRootDir, configDiskDirName);
+ sharedConfigLockingService = getSharedConfigLockService(cache.getDistributedSystem());
+ status.set(SharedConfigurationStatus.NOT_STARTED);
+ }
+
+
+ /**
+ * Adds/replaces the xml entity in the shared configuration we don't need to trigger the change
+ * listener for this modification, so it's ok to operate on the original configuration object
+ */
+ public void addXmlEntity(XmlEntity xmlEntity, String[] groups) {
+ Region<String, Configuration> configRegion = getConfigurationRegion();
+ if (groups == null || groups.length == 0) {
+ groups = new String[] {ClusterConfigurationService.CLUSTER_CONFIG};
+ }
+ for (String group : groups) {
+ Configuration configuration = (Configuration) configRegion.get(group);
+ if (configuration == null) {
+ configuration = new Configuration(group);
+ }
+ String xmlContent = configuration.getCacheXmlContent();
+ if (xmlContent == null || xmlContent.isEmpty()) {
+ StringWriter sw = new StringWriter();
+ PrintWriter pw = new PrintWriter(sw);
+ CacheXmlGenerator.generateDefault(pw);
+ xmlContent = sw.toString();
+ }
+ try {
+ final Document doc = XmlUtils.createAndUpgradeDocumentFromXml(xmlContent);
+ XmlUtils.addNewNode(doc, xmlEntity);
+ configuration.setCacheXmlContent(XmlUtils.prettyXml(doc));
+ configRegion.put(group, configuration);
+ } catch (Exception e) {
+ logger.error("error updating cluster configuration for group " + group, e);
+ }
+ }
+ }
+
+ /**
+ * Deletes the xml entity from the shared configuration.
+ */
+ public void deleteXmlEntity(final XmlEntity xmlEntity, String[] groups) {
+ Region<String, Configuration> configRegion = getConfigurationRegion();
+ // No group is specified, so delete in every single group if it exists.
+ if (groups == null) {
+ Set<String> groupSet = configRegion.keySet();
+ groups = groupSet.toArray(new String[groupSet.size()]);
+ }
+ for (String group : groups) {
+ Configuration configuration = (Configuration) configRegion.get(group);
+ if (configuration != null) {
+ String xmlContent = configuration.getCacheXmlContent();
+ try {
+ if (xmlContent != null && !xmlContent.isEmpty()) {
+ Document doc = XmlUtils.createAndUpgradeDocumentFromXml(xmlContent);
+ XmlUtils.deleteNode(doc, xmlEntity);
+ configuration.setCacheXmlContent(XmlUtils.prettyXml(doc));
+ configRegion.put(group, configuration);
+ }
+ } catch (Exception e) {
+ logger.error("error updating cluster configuration for group " + group, e);
+ }
+ }
+ }
+ }
+
+ // we don't need to trigger the change listener for this modification, so it's ok to
+ // operate on the original configuration object
+ public void modifyXmlAndProperties(Properties properties, XmlEntity xmlEntity, String[] groups) {
+ if (groups == null) {
+ groups = new String[] {ClusterConfigurationService.CLUSTER_CONFIG};
+ }
+ Region<String, Configuration> configRegion = getConfigurationRegion();
+ for (String group : groups) {
+ Configuration configuration = configRegion.get(group);
+ if (configuration == null) {
+ configuration = new Configuration(group);
+ }
+
+ if (xmlEntity != null) {
+ String xmlContent = configuration.getCacheXmlContent();
+ if (xmlContent == null || xmlContent.isEmpty()) {
+ StringWriter sw = new StringWriter();
+ PrintWriter pw = new PrintWriter(sw);
+ CacheXmlGenerator.generateDefault(pw);
+ xmlContent = sw.toString();
+ }
+ try {
+ Document doc = XmlUtils.createAndUpgradeDocumentFromXml(xmlContent);
+ // Modify the cache attributes
+ XmlUtils.modifyRootAttributes(doc, xmlEntity);
+ // Change the xml content of the configuration and put it the config region
+ configuration.setCacheXmlContent(XmlUtils.prettyXml(doc));
+ } catch (Exception e) {
+ logger.error("error updating cluster configuration for group " + group, e);
+ }
+ }
+
+ if (properties != null) {
+ configuration.getGemfireProperties().putAll(properties);
+ }
+ configRegion.put(group, configuration);
+ }
+ }
+
+
+ /**
+ * Add jar information into the shared configuration and save the jars in the file system used
+ * when deploying jars
+ *
+ * @return true on success
+ */
+ public boolean addJarsToThisLocator(String[] jarNames, byte[][] jarBytes, String[] groups) {
+ boolean success = true;
+ try {
+ if (groups == null) {
+ groups = new String[] {ClusterConfigurationService.CLUSTER_CONFIG};
+ }
+ Region<String, Configuration> configRegion = getConfigurationRegion();
+ for (String group : groups) {
+ Configuration configuration = configRegion.get(group);
+
+ if (configuration == null) {
+ configuration = new Configuration(group);
+ createConfigDirIfNecessary(group);
+ }
+
+ String groupDir = FilenameUtils.concat(configDirPath, group);
+ for (int i = 0; i < jarNames.length; i++) {
+ String filePath = FilenameUtils.concat(groupDir, jarNames[i]);
+ File jarFile = new File(filePath);
+ try {
+ FileUtils.writeByteArrayToFile(jarFile, jarBytes[i]);
+ } catch (IOException e) {
+ logger.info(e);
+ }
+ }
+
+ // update the record after writing the jars to the file system, since the listener
+ // will need the jars on file to upload to other locators. Need to update the jars
+ // using a new copy of the Configuration so that the change listener will pick up the jar
+ // name changes.
+ Configuration configurationCopy = new Configuration(configuration);
+ configurationCopy.addJarNames(jarNames);
+ configRegion.put(group, configurationCopy);
+ }
+ } catch (Exception e) {
+ success = false;
+ logger.info(e.getMessage(), e);
+ }
+ return success;
+ }
+
+ /**
+ * read the jar bytes in the file system
+ */
+ // used when creating cluster config response
+ // and used when uploading the jars to another locator
+ public byte[] getJarBytesFromThisLocator(String group, String jarName) throws Exception {
+ Configuration configuration = getConfiguration(group);
+
+ File jar = getPathToJarOnThisLocator(group, jarName).toFile();
+
+ if (configuration == null || !configuration.getJarNames().contains(jarName) || !jar.exists()) {
+ return null;
+ }
+
+ return FileUtils.readFileToByteArray(jar);
+ }
+
+ /**
+ * Removes the jar files from the shared configuration. used when undeploy jars
+ *
+ * @param jarNames Names of the jar files.
+ * @param groups Names of the groups which had the jar file deployed.
+ * @return true on success.
+ */
+ public boolean removeJars(final String[] jarNames, String[] groups) {
+ boolean success = true;
+ try {
+ Region<String, Configuration> configRegion = getConfigurationRegion();
+ if (groups == null) {
+ groups = configRegion.keySet().stream().toArray(String[]::new);
+ }
+ for (String group : groups) {
+ Configuration configuration = configRegion.get(group);
+ if (configuration == null) {
+ break;
+ }
+ Configuration configurationCopy = new Configuration(configuration);
+ configurationCopy.removeJarNames(jarNames);
+ configRegion.put(group, configurationCopy);
+ }
+ } catch (Exception e) {
+ logger.info("Exception occurred while deleting the jar files", e);
+ success = false;
+ }
+ return success;
+ }
+
+ // used in the cluster config change listener when jarnames are changed in the internal region
+ public void downloadJarFromOtherLocators(String groupName, String jarName) throws Exception {
+ logger.info("Getting Jar files from other locators");
+ DM dm = cache.getDistributionManager();
+ DistributedMember me = cache.getMyId();
+ Set<DistributedMember> locators =
+ new HashSet<>(dm.getAllHostedLocatorsWithSharedConfiguration().keySet());
+ locators.remove(me);
+
+ createConfigDirIfNecessary(groupName);
+
+ byte[] jarBytes = locators.stream()
+ .map((DistributedMember locator) -> downloadJarFromLocator(locator, groupName, jarName))
+ .filter(Objects::nonNull).findFirst().orElseThrow(() -> new IllegalStateException(
+ "No locators have a deployed jar named " + jarName + " in " + groupName));
+
+ File jarToWrite = getPathToJarOnThisLocator(groupName, jarName).toFile();
+ FileUtils.writeByteArrayToFile(jarToWrite, jarBytes);
+ }
+
+
+ // used when creating cluster config response
+ public Map<String, byte[]> getAllJarsFromThisLocator(Set<String> groups) throws Exception {
+ Map<String, byte[]> jarNamesToJarBytes = new HashMap<>();
+
+ for (String group : groups) {
+ Configuration groupConfig = getConfiguration(group);
+ if (groupConfig == null) {
+ break;
+ }
+
+ Set<String> jars = groupConfig.getJarNames();
+ for (String jar : jars) {
+ byte[] jarBytes = getJarBytesFromThisLocator(group, jar);
+ jarNamesToJarBytes.put(jar, jarBytes);
+ }
+ }
+
+ return jarNamesToJarBytes;
+ }
+
+ public void clearSharedConfiguration() throws Exception {
+ Region<String, Configuration> configRegion = getConfigurationRegion();
+ configRegion.clear();
+ }
+
+ /**
+ * Creates the shared configuration service
+ *
+ * @param loadSharedConfigFromDir when set to true, loads the configuration from the share_config
+ * directory
+ */
+ public void initSharedConfiguration(boolean loadSharedConfigFromDir) throws Exception {
+ status.set(SharedConfigurationStatus.STARTED);
+ Region<String, Configuration> configRegion = this.getConfigurationRegion();
+ lockSharedConfiguration();
+
+ try {
+ if (loadSharedConfigFromDir) {
+ logger.info("Reading cluster configuration from '{}' directory",
+ ClusterConfigurationService.CLUSTER_CONFIG_ARTIFACTS_DIR_NAME);
+ this.loadSharedConfigurationFromDisk();
+ } else {
+ putSecurityPropsIntoClusterConfig(configRegion);
+ Set<String> groups = configRegion.keySet();
+ for (String group : groups) {
+ Configuration config = configRegion.get(group);
+ // for those groups that have jar files, need to download the jars from other locators
+ // if it doesn't exist yet
+ for (String jar : config.getJarNames()) {
+ if (!(getPathToJarOnThisLocator(group, jar).toFile()).exists()) {
+ downloadJarFromOtherLocators(group, jar);
+ }
+ }
+ }
+ }
+ } finally {
+ unlockSharedConfiguration();
+ }
+
+ status.set(SharedConfigurationStatus.RUNNING);
+ }
+
+ private void putSecurityPropsIntoClusterConfig(final Region<String, Configuration> configRegion) {
+ Properties securityProps = cache.getDistributedSystem().getSecurityProperties();
+ Configuration clusterPropertiesConfig =
+ configRegion.get(ClusterConfigurationService.CLUSTER_CONFIG);
+ if (clusterPropertiesConfig == null) {
+ clusterPropertiesConfig = new Configuration(ClusterConfigurationService.CLUSTER_CONFIG);
+ configRegion.put(ClusterConfigurationService.CLUSTER_CONFIG, clusterPropertiesConfig);
+ }
+ // put security-manager and security-post-processor in the cluster config
+ Properties clusterProperties = clusterPropertiesConfig.getGemfireProperties();
+ if (securityProps.containsKey(SECURITY_MANAGER)) {
+ clusterProperties.setProperty(SECURITY_MANAGER, securityProps.getProperty(SECURITY_MANAGER));
+ }
+ if (securityProps.containsKey(SECURITY_POST_PROCESSOR)) {
+ clusterProperties.setProperty(SECURITY_POST_PROCESSOR,
+ securityProps.getProperty(SECURITY_POST_PROCESSOR));
+ }
+ }
+
+ /**
+ * Creates a ConfigurationResponse based on the configRequest, configuration response contains the
+ * requested shared configuration This method locks the ClusterConfigurationService
+ */
+ public ConfigurationResponse createConfigurationReponse(final ConfigurationRequest configRequest)
+ throws Exception {
+
+ ConfigurationResponse configResponse = new ConfigurationResponse();
+
+ for (int i = 0; i < configRequest.getNumAttempts(); i++) {
+ boolean isLocked = sharedConfigLockingService.lock(SHARED_CONFIG_LOCK_NAME, 5000, 5000);
+ try {
+ if (isLocked) {
+ Set<String> groups = configRequest.getGroups();
+ groups.add(ClusterConfigurationService.CLUSTER_CONFIG);
+ logger.info("Building up configuration response with following configurations: {}",
+ groups);
+
+ for (String group : groups) {
+ Configuration configuration = getConfiguration(group);
+ configResponse.addConfiguration(configuration);
+ }
+
+ Map<String, byte[]> jarNamesToJarBytes = getAllJarsFromThisLocator(groups);
+ String[] jarNames = jarNamesToJarBytes.keySet().stream().toArray(String[]::new);
+ byte[][] jarBytes = jarNamesToJarBytes.values().toArray(new byte[jarNames.length][]);
+
+ configResponse.addJarsToBeDeployed(jarNames, jarBytes);
+ configResponse.setFailedToGetSharedConfig(false);
+ return configResponse;
+ }
+ } finally {
+ sharedConfigLockingService.unlock(SHARED_CONFIG_LOCK_NAME);
+ }
+
+ }
+ configResponse.setFailedToGetSharedConfig(true);
+ return configResponse;
+ }
+
+ /**
+ * Create a response containing the status of the Shared configuration and information about other
+ * locators containing newer shared configuration data (if at all)
+ *
+ * @return {@link SharedConfigurationStatusResponse} containing the
+ * {@link SharedConfigurationStatus}
+ */
+ public SharedConfigurationStatusResponse createStatusResponse() {
+ SharedConfigurationStatusResponse response = new SharedConfigurationStatusResponse();
+ response.setStatus(getStatus());
+ response.addWaitingLocatorInfo(newerSharedConfigurationLocatorInfo);
+ return response;
+ }
+
+ /**
+ * For tests only. TODO: clean this up and remove from production code
+ * <p/>
+ * Throws {@code AssertionError} wrapping any exception thrown by operation.
+ */
+ public void destroySharedConfiguration() {
+ try {
+ Region<String, Configuration> configRegion = getConfigurationRegion();
+ if (configRegion != null) {
+ configRegion.destroyRegion();
+ }
+ DiskStore configDiskStore = this.cache.findDiskStore(CLUSTER_CONFIG_ARTIFACTS_DIR_NAME);
+ if (configDiskStore != null) {
+ configDiskStore.destroy();
+ File file = new File(configDiskDirPath);
+ FileUtils.deleteDirectory(file);
+ }
+ FileUtils.deleteDirectory(new File(configDirPath));
+ } catch (Exception exception) {
+ throw new AssertionError(exception);
+ }
+ }
+
+ public Path getPathToJarOnThisLocator(String groupName, String jarName) {
+ return new File(configDirPath).toPath().resolve(groupName).resolve(jarName);
+ }
+
+ public Configuration getConfiguration(String groupName) {
+ Configuration configuration = getConfigurationRegion().get(groupName);
+ return configuration;
+ }
+
+ public Map<String, Configuration> getEntireConfiguration() throws Exception {
+ Set<String> keys = getConfigurationRegion().keySet();
+ return getConfigurationRegion().getAll(keys);
+ }
+
+ /**
+ * Returns the path of Shared configuration directory
+ *
+ * @return {@link String} path of the shared configuration directory
+ */
+ public String getSharedConfigurationDirPath() {
+ return configDirPath;
+ }
+
+ /**
+ * Gets the current status of the ClusterConfigurationService If the status is started , it
+ * determines if the shared configuration is waiting for new configuration on other locators
+ *
+ * @return {@link SharedConfigurationStatus}
+ */
+ public SharedConfigurationStatus getStatus() {
+ SharedConfigurationStatus scStatus = this.status.get();
+ if (scStatus == SharedConfigurationStatus.STARTED) {
+ PersistentMemberManager pmm = cache.getPersistentMemberManager();
+ Map<String, Set<PersistentMemberID>> waitingRegions = pmm.getWaitingRegions();
+ if (!waitingRegions.isEmpty()) {
+ this.status.compareAndSet(SharedConfigurationStatus.STARTED,
+ SharedConfigurationStatus.WAITING);
+ Set<PersistentMemberID> persMemIds =
+ waitingRegions.get(Region.SEPARATOR_CHAR + CONFIG_REGION_NAME);
+ for (PersistentMemberID persMemId : persMemIds) {
+ newerSharedConfigurationLocatorInfo.add(new PersistentMemberPattern(persMemId));
+ }
+ }
+ }
+ return this.status.get();
+ }
+
+ /**
+ * Loads the internal region with the configuration in the configDirPath
+ */
+ public void loadSharedConfigurationFromDisk() throws Exception {
+ File[] groupNames =
+ new File(configDirPath).listFiles((FileFilter) DirectoryFileFilter.INSTANCE);
+ Map<String, Configuration> sharedConfiguration = new HashMap<String, Configuration>();
+
+ for (File groupName : groupNames) {
+ Configuration configuration = readConfiguration(groupName);
+ sharedConfiguration.put(groupName.getName(), configuration);
+ }
+
+ getConfigurationRegion().clear();
+ getConfigurationRegion().putAll(sharedConfiguration);
+ }
+
+
+
+ public void renameExistingSharedConfigDirectory() {
+ File configDirFile = new File(configDirPath);
+ if (configDirFile.exists()) {
+ String configDirFileName2 = CLUSTER_CONFIG_ARTIFACTS_DIR_NAME
+ + new SimpleDateFormat("yyyyMMddhhmm").format(new Date()) + "." + System.nanoTime();
+ File configDirFile2 = new File(configDirFile.getParent(), configDirFileName2);
+ try {
+ FileUtils.moveDirectory(configDirFile, configDirFile2);
+ } catch (IOException e) {
+ logger.info(e);
+ }
+ }
+ }
+
+
+ // Write the content of xml and properties into the file system for exporting purpose
+ public void writeConfig(final Configuration configuration) throws Exception {
+ File configDir = createConfigDirIfNecessary(configuration.getConfigName());
+
+ File propsFile = new File(configDir, configuration.getPropertiesFileName());
+ BufferedWriter bw = new BufferedWriter(new FileWriter(propsFile));
+ configuration.getGemfireProperties().store(bw, null);
+ bw.close();
+
+ File xmlFile = new File(configDir, configuration.getCacheXmlFileName());
+ FileUtils.writeStringToFile(xmlFile, configuration.getCacheXmlContent(), "UTF-8");
+ }
+
+ private boolean lockSharedConfiguration() {
+ return sharedConfigLockingService.lock(SHARED_CONFIG_LOCK_NAME, -1, -1);
+ }
+
+ private void unlockSharedConfiguration() {
+ sharedConfigLockingService.unlock(SHARED_CONFIG_LOCK_NAME);
+ }
+
+
+ private byte[] downloadJarFromLocator(DistributedMember locator, String groupName,
+ String jarName) {
+ ResultCollector<byte[], List<byte[]>> rc = (ResultCollector<byte[], List<byte[]>>) CliUtil
+ .executeFunction(new UploadJarFunction(), new Object[] {groupName, jarName}, locator);
+
+ List<byte[]> result = rc.getResult();
+
+ // we should only get one byte[] back in the list
+ return result.stream().filter(Objects::nonNull).findFirst().orElse(null);
+ }
+
+ /**
+ * Gets the region containing the shared configuration data. The region is created , if it does
+ * not exist already. Note : this could block if this locator contains stale persistent
+ * configuration data.
+ *
+ * @return {@link Region} ConfigurationRegion, this should never be null
+ */
+ private Region<String, Configuration> getConfigurationRegion() {
+ Region<String, Configuration> configRegion = cache.getRegion(CONFIG_REGION_NAME);
+
+ try {
+ if (configRegion == null) {
+ File diskDir = new File(configDiskDirPath);
+
+ if (!diskDir.exists()) {
+ if (!diskDir.mkdirs()) {
+ throw new IOException("Cannot create directory at " + configDiskDirPath);
+ }
+ }
+
+ File[] diskDirs = {diskDir};
+ cache.createDiskStoreFactory().setDiskDirs(diskDirs).setAutoCompact(true)
+ .setMaxOplogSize(10).create(CLUSTER_CONFIG_DISK_STORE_NAME);
+
+ AttributesFactory<String, Configuration> regionAttrsFactory =
+ new AttributesFactory<String, Configuration>();
+ regionAttrsFactory.setDataPolicy(DataPolicy.PERSISTENT_REPLICATE);
+ regionAttrsFactory.setCacheListener(new ConfigurationChangeListener(this));
+ regionAttrsFactory.setDiskStoreName(CLUSTER_CONFIG_DISK_STORE_NAME);
+ regionAttrsFactory.setScope(Scope.DISTRIBUTED_ACK);
+ InternalRegionArguments internalArgs = new InternalRegionArguments();
+ internalArgs.setIsUsedForMetaRegion(true);
+ internalArgs.setMetaRegionWithTransactions(false);
+
+ configRegion =
+ cache.createVMRegion(CONFIG_REGION_NAME, regionAttrsFactory.create(), internalArgs);
+ }
+
+ } catch (CancelException e) {
+ if (configRegion == null) {
+ this.status.set(SharedConfigurationStatus.STOPPED);
+ }
+ throw e; // CONFIG: don't rethrow as Exception, keep it a subclass of CancelException
+
+ } catch (Exception e) {
+ if (configRegion == null) {
+ this.status.set(SharedConfigurationStatus.STOPPED);
+ }
+ throw new RuntimeException("Error occurred while initializing cluster configuration", e);
+ }
+
+ return configRegion;
+ }
+
+ /**
+ * Reads the configuration information from the shared configuration directory and returns a
+ * {@link Configuration} object
+ *
+ * @return {@link Configuration}
+ */
+ private Configuration readConfiguration(File groupConfigDir)
+ throws SAXException, ParserConfigurationException, TransformerFactoryConfigurationError,
+ TransformerException, IOException {
+ Configuration configuration = new Configuration(groupConfigDir.getName());
+ File cacheXmlFull = new File(groupConfigDir, configuration.getCacheXmlFileName());
+ File propertiesFull = new File(groupConfigDir, configuration.getPropertiesFileName());
+
+ configuration.setCacheXmlFile(cacheXmlFull);
+ configuration.setPropertiesFile(propertiesFull);
+
+ Set<String> jarFileNames = Arrays.stream(groupConfigDir.list())
+ .filter((String filename) -> filename.endsWith(".jar")).collect(Collectors.toSet());
+ configuration.addJarNames(jarFileNames);
+ return configuration;
+ }
+
+ /**
+ * Creates a directory for this configuration if it doesn't already exist.
+ */
+ private File createConfigDirIfNecessary(final String configName) throws Exception {
+ File clusterConfigDir = new File(getSharedConfigurationDirPath());
+ if (!clusterConfigDir.exists()) {
+ if (!clusterConfigDir.mkdirs()) {
+ throw new IOException("Cannot create directory : " + getSharedConfigurationDirPath());
+ }
+ }
+ Path configDirPath = clusterConfigDir.toPath().resolve(configName);
+
+ File configDir = configDirPath.toFile();
+ if (!configDir.exists()) {
+ if (!configDir.mkdir()) {
+ throw new IOException("Cannot create directory : " + configDirPath);
+ }
+ }
+
+ return configDir;
+ }
+}
http://git-wip-us.apache.org/repos/asf/geode/blob/e79e0103/geode-core/src/main/java/org/apache/geode/distributed/internal/InternalLocator.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/distributed/internal/InternalLocator.java b/geode-core/src/main/java/org/apache/geode/distributed/internal/InternalLocator.java
index 50f90aa..4ac2c9c 100644
--- a/geode-core/src/main/java/org/apache/geode/distributed/internal/InternalLocator.java
+++ b/geode-core/src/main/java/org/apache/geode/distributed/internal/InternalLocator.java
@@ -44,7 +44,6 @@ import org.apache.geode.cache.client.internal.locator.GetAllServersRequest;
import org.apache.geode.cache.client.internal.locator.LocatorListRequest;
import org.apache.geode.cache.client.internal.locator.LocatorStatusRequest;
import org.apache.geode.cache.client.internal.locator.QueueConnectionRequest;
-import org.apache.geode.cache.client.internal.locator.ServerLocationRequest;
import org.apache.geode.cache.client.internal.locator.wan.LocatorMembershipListener;
import org.apache.geode.distributed.DistributedSystem;
import org.apache.geode.distributed.Locator;
@@ -192,7 +191,7 @@ public class InternalLocator extends Locator implements ConnectListener {
private final AtomicBoolean shutdownHandled = new AtomicBoolean(false);
- private SharedConfiguration sharedConfig;
+ private ClusterConfigurationService sharedConfig;
private volatile boolean isSharedConfigurationStarted = false;
@@ -558,7 +557,7 @@ public class InternalLocator extends Locator implements ConnectListener {
server.start();
}
- public SharedConfiguration getSharedConfiguration() {
+ public ClusterConfigurationService getSharedConfiguration() {
return this.sharedConfig;
}
@@ -645,7 +644,7 @@ public class InternalLocator extends Locator implements ConnectListener {
try {
if (locator.sharedConfig == null) {
// locator.sharedConfig will already be created in case of auto-reconnect
- locator.sharedConfig = new SharedConfiguration(locator.myCache);
+ locator.sharedConfig = new ClusterConfigurationService(locator.myCache);
}
locator.sharedConfig.initSharedConfiguration(locator.loadFromSharedConfigDir());
locator.installSharedConfigDistribution();
@@ -1151,7 +1150,7 @@ public class InternalLocator extends Locator implements ConnectListener {
((InternalDistributedSystem) myDs).setDependentLocator(this);
logger.info("Locator restart: initializing TcpServer");
if (isSharedConfigurationEnabled()) {
- this.sharedConfig = new SharedConfiguration(newCache);
+ this.sharedConfig = new ClusterConfigurationService(newCache);
}
this.server.restarting(newSystem, newCache, this.sharedConfig);
if (this.productUseLog.isClosed()) {
@@ -1297,7 +1296,7 @@ public class InternalLocator extends Locator implements ConnectListener {
}
public void restarting(DistributedSystem ds, GemFireCache cache,
- SharedConfiguration sharedConfig) {
+ ClusterConfigurationService sharedConfig) {
if (ds != null) {
for (TcpHandler handler : this.allHandlers) {
handler.restarting(ds, cache, sharedConfig);
http://git-wip-us.apache.org/repos/asf/geode/blob/e79e0103/geode-core/src/main/java/org/apache/geode/distributed/internal/ServerLocator.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/distributed/internal/ServerLocator.java b/geode-core/src/main/java/org/apache/geode/distributed/internal/ServerLocator.java
index 928e8d8..fb66b4c 100755
--- a/geode-core/src/main/java/org/apache/geode/distributed/internal/ServerLocator.java
+++ b/geode-core/src/main/java/org/apache/geode/distributed/internal/ServerLocator.java
@@ -275,7 +275,7 @@ public class ServerLocator implements TcpHandler, DistributionAdvisee {
}
public void restarting(DistributedSystem ds, GemFireCache cache,
- SharedConfiguration sharedConfig) {
+ ClusterConfigurationService sharedConfig) {
if (ds != null) {
this.loadSnapshot = new LocatorLoadSnapshot();
this.ds = (InternalDistributedSystem) ds;
[3/4] geode git commit: GEODE-2261: rename SharedConfig to
ClusterConfigurationService
Posted by ji...@apache.org.
http://git-wip-us.apache.org/repos/asf/geode/blob/e79e0103/geode-core/src/main/java/org/apache/geode/distributed/internal/SharedConfiguration.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/distributed/internal/SharedConfiguration.java b/geode-core/src/main/java/org/apache/geode/distributed/internal/SharedConfiguration.java
deleted file mode 100644
index 901b3c9..0000000
--- a/geode-core/src/main/java/org/apache/geode/distributed/internal/SharedConfiguration.java
+++ /dev/null
@@ -1,747 +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.distributed.internal;
-
-import static org.apache.geode.distributed.ConfigurationProperties.CLUSTER_CONFIGURATION_DIR;
-import static org.apache.geode.distributed.ConfigurationProperties.SECURITY_MANAGER;
-import static org.apache.geode.distributed.ConfigurationProperties.SECURITY_POST_PROCESSOR;
-
-import org.apache.commons.io.FileUtils;
-import org.apache.commons.io.FilenameUtils;
-import org.apache.commons.io.filefilter.DirectoryFileFilter;
-import org.apache.geode.CancelException;
-import org.apache.geode.cache.AttributesFactory;
-import org.apache.geode.cache.Cache;
-import org.apache.geode.cache.DataPolicy;
-import org.apache.geode.cache.DiskStore;
-import org.apache.geode.cache.Region;
-import org.apache.geode.cache.Scope;
-import org.apache.geode.cache.execute.ResultCollector;
-import org.apache.geode.distributed.DistributedLockService;
-import org.apache.geode.distributed.DistributedMember;
-import org.apache.geode.distributed.DistributedSystem;
-import org.apache.geode.distributed.internal.locks.DLockService;
-import org.apache.geode.internal.cache.GemFireCacheImpl;
-import org.apache.geode.internal.cache.InternalRegionArguments;
-import org.apache.geode.internal.cache.persistence.PersistentMemberID;
-import org.apache.geode.internal.cache.persistence.PersistentMemberManager;
-import org.apache.geode.internal.cache.persistence.PersistentMemberPattern;
-import org.apache.geode.internal.cache.xmlcache.CacheXmlGenerator;
-import org.apache.geode.internal.lang.StringUtils;
-import org.apache.geode.internal.logging.LogService;
-import org.apache.geode.management.internal.cli.CliUtil;
-import org.apache.geode.management.internal.configuration.callbacks.ConfigurationChangeListener;
-import org.apache.geode.management.internal.configuration.domain.Configuration;
-import org.apache.geode.management.internal.configuration.domain.SharedConfigurationStatus;
-import org.apache.geode.management.internal.configuration.domain.XmlEntity;
-import org.apache.geode.management.internal.configuration.functions.UploadJarFunction;
-import org.apache.geode.management.internal.configuration.messages.ConfigurationRequest;
-import org.apache.geode.management.internal.configuration.messages.ConfigurationResponse;
-import org.apache.geode.management.internal.configuration.messages.SharedConfigurationStatusResponse;
-import org.apache.geode.management.internal.configuration.utils.XmlUtils;
-import org.apache.logging.log4j.Logger;
-import org.w3c.dom.Document;
-import org.xml.sax.SAXException;
-
-import java.io.BufferedWriter;
-import java.io.File;
-import java.io.FileFilter;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.io.StringWriter;
-import java.nio.file.Path;
-import java.text.SimpleDateFormat;
-import java.util.Arrays;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Properties;
-import java.util.Set;
-import java.util.concurrent.atomic.AtomicReference;
-import java.util.stream.Collectors;
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.transform.TransformerException;
-import javax.xml.transform.TransformerFactoryConfigurationError;
-
-@SuppressWarnings({"deprecation", "unchecked"})
-public class SharedConfiguration {
-
- private static final Logger logger = LogService.getLogger();
-
- /**
- * Name of the directory where the shared configuration artifacts are stored
- */
- public static final String CLUSTER_CONFIG_ARTIFACTS_DIR_NAME = "cluster_config";
- private static final String CLUSTER_CONFIG_DISK_STORE_NAME = "cluster_config";
- public static final String CLUSTER_CONFIG_DISK_DIR_PREFIX = "ConfigDiskDir_";
-
- public static final String CLUSTER_CONFIG = "cluster";
-
- /**
- * Name of the lock service used for shared configuration
- */
- private static final String SHARED_CONFIG_LOCK_SERVICE_NAME = "__CLUSTER_CONFIG_LS";
-
- /**
- * Name of the lock for locking the shared configuration
- */
- public static final String SHARED_CONFIG_LOCK_NAME = "__CLUSTER_CONFIG_LOCK";
-
- /**
- * Name of the region which is used to store the configuration information
- */
- private static final String CONFIG_REGION_NAME = "_ConfigurationRegion";
-
- private final String configDirPath;
- private final String configDiskDirPath;
-
- private final Set<PersistentMemberPattern> newerSharedConfigurationLocatorInfo = new HashSet<>();
- private final AtomicReference<SharedConfigurationStatus> status = new AtomicReference<>();
-
- private GemFireCacheImpl cache;
- private final DistributedLockService sharedConfigLockingService;
-
- /**
- * Gets or creates (if not created) shared configuration lock service
- */
- public static DistributedLockService getSharedConfigLockService(DistributedSystem ds) {
- DistributedLockService sharedConfigDls =
- DLockService.getServiceNamed(SHARED_CONFIG_LOCK_SERVICE_NAME);
- try {
- if (sharedConfigDls == null) {
- sharedConfigDls = DLockService.create(SHARED_CONFIG_LOCK_SERVICE_NAME,
- (InternalDistributedSystem) ds, true, true);
- }
- } catch (IllegalArgumentException e) {
- return DLockService.getServiceNamed(SHARED_CONFIG_LOCK_SERVICE_NAME);
- }
- return sharedConfigDls;
- }
-
- public SharedConfiguration(Cache cache) throws IOException {
- this.cache = (GemFireCacheImpl) cache;
- Properties properties = cache.getDistributedSystem().getProperties();
- // resolve the cluster config dir
- String clusterConfigRootDir = properties.getProperty(CLUSTER_CONFIGURATION_DIR);
-
- if (StringUtils.isBlank(clusterConfigRootDir)) {
- clusterConfigRootDir = System.getProperty("user.dir");
- } else {
- File diskDir = new File(clusterConfigRootDir);
- if (!diskDir.exists() && !diskDir.mkdirs()) {
- throw new IOException("Cannot create directory : " + clusterConfigRootDir);
- }
- clusterConfigRootDir = diskDir.getCanonicalPath();
- }
-
- // resolve the file paths
- String configDiskDirName =
- CLUSTER_CONFIG_DISK_DIR_PREFIX + cache.getDistributedSystem().getName();
-
- configDirPath = FilenameUtils.concat(clusterConfigRootDir, CLUSTER_CONFIG_ARTIFACTS_DIR_NAME);
- configDiskDirPath = FilenameUtils.concat(clusterConfigRootDir, configDiskDirName);
- sharedConfigLockingService = getSharedConfigLockService(cache.getDistributedSystem());
- status.set(SharedConfigurationStatus.NOT_STARTED);
- }
-
-
- /**
- * Adds/replaces the xml entity in the shared configuration we don't need to trigger the change
- * listener for this modification, so it's ok to operate on the original configuration object
- */
- public void addXmlEntity(XmlEntity xmlEntity, String[] groups) {
- Region<String, Configuration> configRegion = getConfigurationRegion();
- if (groups == null || groups.length == 0) {
- groups = new String[] {SharedConfiguration.CLUSTER_CONFIG};
- }
- for (String group : groups) {
- Configuration configuration = (Configuration) configRegion.get(group);
- if (configuration == null) {
- configuration = new Configuration(group);
- }
- String xmlContent = configuration.getCacheXmlContent();
- if (xmlContent == null || xmlContent.isEmpty()) {
- StringWriter sw = new StringWriter();
- PrintWriter pw = new PrintWriter(sw);
- CacheXmlGenerator.generateDefault(pw);
- xmlContent = sw.toString();
- }
- try {
- final Document doc = XmlUtils.createAndUpgradeDocumentFromXml(xmlContent);
- XmlUtils.addNewNode(doc, xmlEntity);
- configuration.setCacheXmlContent(XmlUtils.prettyXml(doc));
- configRegion.put(group, configuration);
- } catch (Exception e) {
- logger.error("error updating cluster configuration for group " + group, e);
- }
- }
- }
-
- /**
- * Deletes the xml entity from the shared configuration.
- */
- public void deleteXmlEntity(final XmlEntity xmlEntity, String[] groups) {
- Region<String, Configuration> configRegion = getConfigurationRegion();
- // No group is specified, so delete in every single group if it exists.
- if (groups == null) {
- Set<String> groupSet = configRegion.keySet();
- groups = groupSet.toArray(new String[groupSet.size()]);
- }
- for (String group : groups) {
- Configuration configuration = (Configuration) configRegion.get(group);
- if (configuration != null) {
- String xmlContent = configuration.getCacheXmlContent();
- try {
- if (xmlContent != null && !xmlContent.isEmpty()) {
- Document doc = XmlUtils.createAndUpgradeDocumentFromXml(xmlContent);
- XmlUtils.deleteNode(doc, xmlEntity);
- configuration.setCacheXmlContent(XmlUtils.prettyXml(doc));
- configRegion.put(group, configuration);
- }
- } catch (Exception e) {
- logger.error("error updating cluster configuration for group " + group, e);
- }
- }
- }
- }
-
- // we don't need to trigger the change listener for this modification, so it's ok to
- // operate on the original configuration object
- public void modifyXmlAndProperties(Properties properties, XmlEntity xmlEntity, String[] groups) {
- if (groups == null) {
- groups = new String[] {SharedConfiguration.CLUSTER_CONFIG};
- }
- Region<String, Configuration> configRegion = getConfigurationRegion();
- for (String group : groups) {
- Configuration configuration = configRegion.get(group);
- if (configuration == null) {
- configuration = new Configuration(group);
- }
-
- if (xmlEntity != null) {
- String xmlContent = configuration.getCacheXmlContent();
- if (xmlContent == null || xmlContent.isEmpty()) {
- StringWriter sw = new StringWriter();
- PrintWriter pw = new PrintWriter(sw);
- CacheXmlGenerator.generateDefault(pw);
- xmlContent = sw.toString();
- }
- try {
- Document doc = XmlUtils.createAndUpgradeDocumentFromXml(xmlContent);
- // Modify the cache attributes
- XmlUtils.modifyRootAttributes(doc, xmlEntity);
- // Change the xml content of the configuration and put it the config region
- configuration.setCacheXmlContent(XmlUtils.prettyXml(doc));
- } catch (Exception e) {
- logger.error("error updating cluster configuration for group " + group, e);
- }
- }
-
- if (properties != null) {
- configuration.getGemfireProperties().putAll(properties);
- }
- configRegion.put(group, configuration);
- }
- }
-
-
- /**
- * Add jar information into the shared configuration and save the jars in the file system used
- * when deploying jars
- *
- * @return true on success
- */
- public boolean addJarsToThisLocator(String[] jarNames, byte[][] jarBytes, String[] groups) {
- boolean success = true;
- try {
- if (groups == null) {
- groups = new String[] {SharedConfiguration.CLUSTER_CONFIG};
- }
- Region<String, Configuration> configRegion = getConfigurationRegion();
- for (String group : groups) {
- Configuration configuration = configRegion.get(group);
-
- if (configuration == null) {
- configuration = new Configuration(group);
- createConfigDirIfNecessary(group);
- }
-
- String groupDir = FilenameUtils.concat(configDirPath, group);
- for (int i = 0; i < jarNames.length; i++) {
- String filePath = FilenameUtils.concat(groupDir, jarNames[i]);
- File jarFile = new File(filePath);
- try {
- FileUtils.writeByteArrayToFile(jarFile, jarBytes[i]);
- } catch (IOException e) {
- logger.info(e);
- }
- }
-
- // update the record after writing the jars to the file system, since the listener
- // will need the jars on file to upload to other locators. Need to update the jars
- // using a new copy of the Configuration so that the change listener will pick up the jar
- // name changes.
- Configuration configurationCopy = new Configuration(configuration);
- configurationCopy.addJarNames(jarNames);
- configRegion.put(group, configurationCopy);
- }
- } catch (Exception e) {
- success = false;
- logger.info(e.getMessage(), e);
- }
- return success;
- }
-
- /**
- * read the jar bytes in the file system
- */
- // used when creating cluster config response
- // and used when uploading the jars to another locator
- public byte[] getJarBytesFromThisLocator(String group, String jarName) throws Exception {
- Configuration configuration = getConfiguration(group);
-
- File jar = getPathToJarOnThisLocator(group, jarName).toFile();
-
- if (configuration == null || !configuration.getJarNames().contains(jarName) || !jar.exists()) {
- return null;
- }
-
- return FileUtils.readFileToByteArray(jar);
- }
-
- /**
- * Removes the jar files from the shared configuration. used when undeploy jars
- *
- * @param jarNames Names of the jar files.
- * @param groups Names of the groups which had the jar file deployed.
- * @return true on success.
- */
- public boolean removeJars(final String[] jarNames, String[] groups) {
- boolean success = true;
- try {
- Region<String, Configuration> configRegion = getConfigurationRegion();
- if (groups == null) {
- groups = configRegion.keySet().stream().toArray(String[]::new);
- }
- for (String group : groups) {
- Configuration configuration = configRegion.get(group);
- if (configuration == null) {
- break;
- }
- Configuration configurationCopy = new Configuration(configuration);
- configurationCopy.removeJarNames(jarNames);
- configRegion.put(group, configurationCopy);
- }
- } catch (Exception e) {
- logger.info("Exception occurred while deleting the jar files", e);
- success = false;
- }
- return success;
- }
-
- // used in the cluster config change listener when jarnames are changed in the internal region
- public void downloadJarFromOtherLocators(String groupName, String jarName) throws Exception {
- logger.info("Getting Jar files from other locators");
- DM dm = cache.getDistributionManager();
- DistributedMember me = cache.getMyId();
- Set<DistributedMember> locators =
- new HashSet<>(dm.getAllHostedLocatorsWithSharedConfiguration().keySet());
- locators.remove(me);
-
- createConfigDirIfNecessary(groupName);
-
- byte[] jarBytes = locators.stream()
- .map((DistributedMember locator) -> downloadJarFromLocator(locator, groupName, jarName))
- .filter(Objects::nonNull).findFirst().orElseThrow(() -> new IllegalStateException(
- "No locators have a deployed jar named " + jarName + " in " + groupName));
-
- File jarToWrite = getPathToJarOnThisLocator(groupName, jarName).toFile();
- FileUtils.writeByteArrayToFile(jarToWrite, jarBytes);
- }
-
-
- // used when creating cluster config response
- public Map<String, byte[]> getAllJarsFromThisLocator(Set<String> groups) throws Exception {
- Map<String, byte[]> jarNamesToJarBytes = new HashMap<>();
-
- for (String group : groups) {
- Configuration groupConfig = getConfiguration(group);
- if (groupConfig == null) {
- break;
- }
-
- Set<String> jars = groupConfig.getJarNames();
- for (String jar : jars) {
- byte[] jarBytes = getJarBytesFromThisLocator(group, jar);
- jarNamesToJarBytes.put(jar, jarBytes);
- }
- }
-
- return jarNamesToJarBytes;
- }
-
- public void clearSharedConfiguration() throws Exception {
- Region<String, Configuration> configRegion = getConfigurationRegion();
- configRegion.clear();
- }
-
- /**
- * Creates the shared configuration service
- *
- * @param loadSharedConfigFromDir when set to true, loads the configuration from the share_config
- * directory
- */
- public void initSharedConfiguration(boolean loadSharedConfigFromDir) throws Exception {
- status.set(SharedConfigurationStatus.STARTED);
- Region<String, Configuration> configRegion = this.getConfigurationRegion();
- lockSharedConfiguration();
-
- try {
- if (loadSharedConfigFromDir) {
- logger.info("Reading cluster configuration from '{}' directory",
- SharedConfiguration.CLUSTER_CONFIG_ARTIFACTS_DIR_NAME);
- this.loadSharedConfigurationFromDisk();
- } else {
- putSecurityPropsIntoClusterConfig(configRegion);
- Set<String> groups = configRegion.keySet();
- for (String group : groups) {
- Configuration config = configRegion.get(group);
- // for those groups that have jar files, need to download the jars from other locators
- // if it doesn't exist yet
- for (String jar : config.getJarNames()) {
- if (!(getPathToJarOnThisLocator(group, jar).toFile()).exists()) {
- downloadJarFromOtherLocators(group, jar);
- }
- }
- }
- }
- } finally {
- unlockSharedConfiguration();
- }
-
- status.set(SharedConfigurationStatus.RUNNING);
- }
-
- private void putSecurityPropsIntoClusterConfig(final Region<String, Configuration> configRegion) {
- Properties securityProps = cache.getDistributedSystem().getSecurityProperties();
- Configuration clusterPropertiesConfig = configRegion.get(SharedConfiguration.CLUSTER_CONFIG);
- if (clusterPropertiesConfig == null) {
- clusterPropertiesConfig = new Configuration(SharedConfiguration.CLUSTER_CONFIG);
- configRegion.put(SharedConfiguration.CLUSTER_CONFIG, clusterPropertiesConfig);
- }
- // put security-manager and security-post-processor in the cluster config
- Properties clusterProperties = clusterPropertiesConfig.getGemfireProperties();
- if (securityProps.containsKey(SECURITY_MANAGER)) {
- clusterProperties.setProperty(SECURITY_MANAGER, securityProps.getProperty(SECURITY_MANAGER));
- }
- if (securityProps.containsKey(SECURITY_POST_PROCESSOR)) {
- clusterProperties.setProperty(SECURITY_POST_PROCESSOR,
- securityProps.getProperty(SECURITY_POST_PROCESSOR));
- }
- }
-
- /**
- * Creates a ConfigurationResponse based on the configRequest, configuration response contains the
- * requested shared configuration This method locks the SharedConfiguration
- */
- public ConfigurationResponse createConfigurationReponse(final ConfigurationRequest configRequest)
- throws Exception {
-
- ConfigurationResponse configResponse = new ConfigurationResponse();
-
- for (int i = 0; i < configRequest.getNumAttempts(); i++) {
- boolean isLocked = sharedConfigLockingService.lock(SHARED_CONFIG_LOCK_NAME, 5000, 5000);
- try {
- if (isLocked) {
- Set<String> groups = configRequest.getGroups();
- groups.add(SharedConfiguration.CLUSTER_CONFIG);
- logger.info("Building up configuration response with following configurations: {}",
- groups);
-
- for (String group : groups) {
- Configuration configuration = getConfiguration(group);
- configResponse.addConfiguration(configuration);
- }
-
- Map<String, byte[]> jarNamesToJarBytes = getAllJarsFromThisLocator(groups);
- String[] jarNames = jarNamesToJarBytes.keySet().stream().toArray(String[]::new);
- byte[][] jarBytes = jarNamesToJarBytes.values().toArray(new byte[jarNames.length][]);
-
- configResponse.addJarsToBeDeployed(jarNames, jarBytes);
- configResponse.setFailedToGetSharedConfig(false);
- return configResponse;
- }
- } finally {
- sharedConfigLockingService.unlock(SHARED_CONFIG_LOCK_NAME);
- }
-
- }
- configResponse.setFailedToGetSharedConfig(true);
- return configResponse;
- }
-
- /**
- * Create a response containing the status of the Shared configuration and information about other
- * locators containing newer shared configuration data (if at all)
- *
- * @return {@link SharedConfigurationStatusResponse} containing the
- * {@link SharedConfigurationStatus}
- */
- public SharedConfigurationStatusResponse createStatusResponse() {
- SharedConfigurationStatusResponse response = new SharedConfigurationStatusResponse();
- response.setStatus(getStatus());
- response.addWaitingLocatorInfo(newerSharedConfigurationLocatorInfo);
- return response;
- }
-
- /**
- * For tests only. TODO: clean this up and remove from production code
- * <p/>
- * Throws {@code AssertionError} wrapping any exception thrown by operation.
- */
- public void destroySharedConfiguration() {
- try {
- Region<String, Configuration> configRegion = getConfigurationRegion();
- if (configRegion != null) {
- configRegion.destroyRegion();
- }
- DiskStore configDiskStore = this.cache.findDiskStore(CLUSTER_CONFIG_ARTIFACTS_DIR_NAME);
- if (configDiskStore != null) {
- configDiskStore.destroy();
- File file = new File(configDiskDirPath);
- FileUtils.deleteDirectory(file);
- }
- FileUtils.deleteDirectory(new File(configDirPath));
- } catch (Exception exception) {
- throw new AssertionError(exception);
- }
- }
-
- public Path getPathToJarOnThisLocator(String groupName, String jarName) {
- return new File(configDirPath).toPath().resolve(groupName).resolve(jarName);
- }
-
- public Configuration getConfiguration(String groupName) {
- Configuration configuration = getConfigurationRegion().get(groupName);
- return configuration;
- }
-
- public Map<String, Configuration> getEntireConfiguration() throws Exception {
- Set<String> keys = getConfigurationRegion().keySet();
- return getConfigurationRegion().getAll(keys);
- }
-
- /**
- * Returns the path of Shared configuration directory
- *
- * @return {@link String} path of the shared configuration directory
- */
- public String getSharedConfigurationDirPath() {
- return configDirPath;
- }
-
- /**
- * Gets the current status of the SharedConfiguration If the status is started , it determines if
- * the shared configuration is waiting for new configuration on other locators
- *
- * @return {@link SharedConfigurationStatus}
- */
- public SharedConfigurationStatus getStatus() {
- SharedConfigurationStatus scStatus = this.status.get();
- if (scStatus == SharedConfigurationStatus.STARTED) {
- PersistentMemberManager pmm = cache.getPersistentMemberManager();
- Map<String, Set<PersistentMemberID>> waitingRegions = pmm.getWaitingRegions();
- if (!waitingRegions.isEmpty()) {
- this.status.compareAndSet(SharedConfigurationStatus.STARTED,
- SharedConfigurationStatus.WAITING);
- Set<PersistentMemberID> persMemIds =
- waitingRegions.get(Region.SEPARATOR_CHAR + CONFIG_REGION_NAME);
- for (PersistentMemberID persMemId : persMemIds) {
- newerSharedConfigurationLocatorInfo.add(new PersistentMemberPattern(persMemId));
- }
- }
- }
- return this.status.get();
- }
-
- /**
- * Loads the internal region with the configuration in the configDirPath
- */
- public void loadSharedConfigurationFromDisk() throws Exception {
- File[] groupNames =
- new File(configDirPath).listFiles((FileFilter) DirectoryFileFilter.INSTANCE);
- Map<String, Configuration> sharedConfiguration = new HashMap<String, Configuration>();
-
- for (File groupName : groupNames) {
- Configuration configuration = readConfiguration(groupName);
- sharedConfiguration.put(groupName.getName(), configuration);
- }
-
- getConfigurationRegion().clear();
- getConfigurationRegion().putAll(sharedConfiguration);
- }
-
-
-
- public void renameExistingSharedConfigDirectory() {
- File configDirFile = new File(configDirPath);
- if (configDirFile.exists()) {
- String configDirFileName2 = CLUSTER_CONFIG_ARTIFACTS_DIR_NAME
- + new SimpleDateFormat("yyyyMMddhhmm").format(new Date()) + "." + System.nanoTime();
- File configDirFile2 = new File(configDirFile.getParent(), configDirFileName2);
- try {
- FileUtils.moveDirectory(configDirFile, configDirFile2);
- } catch (IOException e) {
- logger.info(e);
- }
- }
- }
-
-
- // Write the content of xml and properties into the file system for exporting purpose
- public void writeConfig(final Configuration configuration) throws Exception {
- File configDir = createConfigDirIfNecessary(configuration.getConfigName());
-
- File propsFile = new File(configDir, configuration.getPropertiesFileName());
- BufferedWriter bw = new BufferedWriter(new FileWriter(propsFile));
- configuration.getGemfireProperties().store(bw, null);
- bw.close();
-
- File xmlFile = new File(configDir, configuration.getCacheXmlFileName());
- FileUtils.writeStringToFile(xmlFile, configuration.getCacheXmlContent(), "UTF-8");
- }
-
- private boolean lockSharedConfiguration() {
- return sharedConfigLockingService.lock(SHARED_CONFIG_LOCK_NAME, -1, -1);
- }
-
- private void unlockSharedConfiguration() {
- sharedConfigLockingService.unlock(SHARED_CONFIG_LOCK_NAME);
- }
-
-
- private byte[] downloadJarFromLocator(DistributedMember locator, String groupName,
- String jarName) {
- ResultCollector<byte[], List<byte[]>> rc = (ResultCollector<byte[], List<byte[]>>) CliUtil
- .executeFunction(new UploadJarFunction(), new Object[] {groupName, jarName}, locator);
-
- List<byte[]> result = rc.getResult();
-
- // we should only get one byte[] back in the list
- return result.stream().filter(Objects::nonNull).findFirst().orElse(null);
- }
-
- /**
- * Gets the region containing the shared configuration data. The region is created , if it does
- * not exist already. Note : this could block if this locator contains stale persistent
- * configuration data.
- *
- * @return {@link Region} ConfigurationRegion, this should never be null
- */
- private Region<String, Configuration> getConfigurationRegion() {
- Region<String, Configuration> configRegion = cache.getRegion(CONFIG_REGION_NAME);
-
- try {
- if (configRegion == null) {
- File diskDir = new File(configDiskDirPath);
-
- if (!diskDir.exists()) {
- if (!diskDir.mkdirs()) {
- throw new IOException("Cannot create directory at " + configDiskDirPath);
- }
- }
-
- File[] diskDirs = {diskDir};
- cache.createDiskStoreFactory().setDiskDirs(diskDirs).setAutoCompact(true)
- .setMaxOplogSize(10).create(CLUSTER_CONFIG_DISK_STORE_NAME);
-
- AttributesFactory<String, Configuration> regionAttrsFactory =
- new AttributesFactory<String, Configuration>();
- regionAttrsFactory.setDataPolicy(DataPolicy.PERSISTENT_REPLICATE);
- regionAttrsFactory.setCacheListener(new ConfigurationChangeListener(this));
- regionAttrsFactory.setDiskStoreName(CLUSTER_CONFIG_DISK_STORE_NAME);
- regionAttrsFactory.setScope(Scope.DISTRIBUTED_ACK);
- InternalRegionArguments internalArgs = new InternalRegionArguments();
- internalArgs.setIsUsedForMetaRegion(true);
- internalArgs.setMetaRegionWithTransactions(false);
-
- configRegion =
- cache.createVMRegion(CONFIG_REGION_NAME, regionAttrsFactory.create(), internalArgs);
- }
-
- } catch (CancelException e) {
- if (configRegion == null) {
- this.status.set(SharedConfigurationStatus.STOPPED);
- }
- throw e; // CONFIG: don't rethrow as Exception, keep it a subclass of CancelException
-
- } catch (Exception e) {
- if (configRegion == null) {
- this.status.set(SharedConfigurationStatus.STOPPED);
- }
- throw new RuntimeException("Error occurred while initializing cluster configuration", e);
- }
-
- return configRegion;
- }
-
- /**
- * Reads the configuration information from the shared configuration directory and returns a
- * {@link Configuration} object
- *
- * @return {@link Configuration}
- */
- private Configuration readConfiguration(File groupConfigDir)
- throws SAXException, ParserConfigurationException, TransformerFactoryConfigurationError,
- TransformerException, IOException {
- Configuration configuration = new Configuration(groupConfigDir.getName());
- File cacheXmlFull = new File(groupConfigDir, configuration.getCacheXmlFileName());
- File propertiesFull = new File(groupConfigDir, configuration.getPropertiesFileName());
-
- configuration.setCacheXmlFile(cacheXmlFull);
- configuration.setPropertiesFile(propertiesFull);
-
- Set<String> jarFileNames = Arrays.stream(groupConfigDir.list())
- .filter((String filename) -> filename.endsWith(".jar")).collect(Collectors.toSet());
- configuration.addJarNames(jarFileNames);
- return configuration;
- }
-
- /**
- * Creates a directory for this configuration if it doesn't already exist.
- */
- private File createConfigDirIfNecessary(final String configName) throws Exception {
- File clusterConfigDir = new File(getSharedConfigurationDirPath());
- if (!clusterConfigDir.exists()) {
- if (!clusterConfigDir.mkdirs()) {
- throw new IOException("Cannot create directory : " + getSharedConfigurationDirPath());
- }
- }
- Path configDirPath = clusterConfigDir.toPath().resolve(configName);
-
- File configDir = configDirPath.toFile();
- if (!configDir.exists()) {
- if (!configDir.mkdir()) {
- throw new IOException("Cannot create directory : " + configDirPath);
- }
- }
-
- return configDir;
- }
-}
http://git-wip-us.apache.org/repos/asf/geode/blob/e79e0103/geode-core/src/main/java/org/apache/geode/distributed/internal/membership/gms/locator/GMSLocator.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/distributed/internal/membership/gms/locator/GMSLocator.java b/geode-core/src/main/java/org/apache/geode/distributed/internal/membership/gms/locator/GMSLocator.java
index dd73492..7223c92 100644
--- a/geode-core/src/main/java/org/apache/geode/distributed/internal/membership/gms/locator/GMSLocator.java
+++ b/geode-core/src/main/java/org/apache/geode/distributed/internal/membership/gms/locator/GMSLocator.java
@@ -34,6 +34,7 @@ import java.util.concurrent.ConcurrentHashMap;
import org.apache.geode.InternalGemFireException;
+import org.apache.geode.distributed.internal.ClusterConfigurationService;
import org.apache.logging.log4j.Logger;
import org.apache.geode.DataSerializer;
@@ -41,7 +42,6 @@ import org.apache.geode.cache.GemFireCache;
import org.apache.geode.distributed.DistributedSystem;
import org.apache.geode.distributed.internal.InternalDistributedSystem;
import org.apache.geode.distributed.internal.LocatorStats;
-import org.apache.geode.distributed.internal.SharedConfiguration;
import org.apache.geode.distributed.internal.membership.InternalDistributedMember;
import org.apache.geode.distributed.internal.membership.MembershipManager;
import org.apache.geode.distributed.internal.membership.NetView;
@@ -56,7 +56,6 @@ import org.apache.geode.distributed.internal.tcpserver.TcpServer;
import org.apache.geode.internal.Version;
import org.apache.geode.internal.VersionedObjectInput;
import org.apache.geode.internal.logging.LogService;
-import org.apache.geode.internal.net.*;
import static org.apache.geode.internal.i18n.LocalizedStrings.LOCATOR_UNABLE_TO_RECOVER_VIEW;
@@ -340,7 +339,7 @@ public class GMSLocator implements Locator, NetLocator {
@Override
public void restarting(DistributedSystem ds, GemFireCache cache,
- SharedConfiguration sharedConfig) {
+ ClusterConfigurationService sharedConfig) {
setMembershipManager(((InternalDistributedSystem) ds).getDM().getMembershipManager());
}
http://git-wip-us.apache.org/repos/asf/geode/blob/e79e0103/geode-core/src/main/java/org/apache/geode/distributed/internal/tcpserver/TcpHandler.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/distributed/internal/tcpserver/TcpHandler.java b/geode-core/src/main/java/org/apache/geode/distributed/internal/tcpserver/TcpHandler.java
index f497d62..d4af158 100644
--- a/geode-core/src/main/java/org/apache/geode/distributed/internal/tcpserver/TcpHandler.java
+++ b/geode-core/src/main/java/org/apache/geode/distributed/internal/tcpserver/TcpHandler.java
@@ -18,7 +18,7 @@ import java.io.IOException;
import org.apache.geode.cache.GemFireCache;
import org.apache.geode.distributed.DistributedSystem;
-import org.apache.geode.distributed.internal.SharedConfiguration;
+import org.apache.geode.distributed.internal.ClusterConfigurationService;
/**
* A handler which responds to messages for the {@link TcpServer}
@@ -49,7 +49,8 @@ public interface TcpHandler {
*
* @param sharedConfig TODO
*/
- void restarting(DistributedSystem ds, GemFireCache cache, SharedConfiguration sharedConfig);
+ void restarting(DistributedSystem ds, GemFireCache cache,
+ ClusterConfigurationService sharedConfig);
/**
* Initialize the handler with the TcpServer. Called before the TcpServer starts accepting
http://git-wip-us.apache.org/repos/asf/geode/blob/e79e0103/geode-core/src/main/java/org/apache/geode/distributed/internal/tcpserver/TcpServer.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/distributed/internal/tcpserver/TcpServer.java b/geode-core/src/main/java/org/apache/geode/distributed/internal/tcpserver/TcpServer.java
index 461d3ac..4265349 100755
--- a/geode-core/src/main/java/org/apache/geode/distributed/internal/tcpserver/TcpServer.java
+++ b/geode-core/src/main/java/org/apache/geode/distributed/internal/tcpserver/TcpServer.java
@@ -17,13 +17,13 @@ package org.apache.geode.distributed.internal.tcpserver;
import org.apache.geode.CancelException;
import org.apache.geode.DataSerializer;
import org.apache.geode.SystemFailure;
+import org.apache.geode.distributed.internal.ClusterConfigurationService;
import org.apache.geode.distributed.internal.DistributionConfig;
import org.apache.geode.distributed.internal.DistributionConfigImpl;
import org.apache.geode.distributed.internal.DistributionStats;
import org.apache.geode.distributed.internal.InternalDistributedSystem;
import org.apache.geode.distributed.internal.PoolStatHelper;
import org.apache.geode.distributed.internal.PooledExecutorWithDMStats;
-import org.apache.geode.distributed.internal.SharedConfiguration;
import org.apache.geode.internal.DSFIDFactory;
import org.apache.geode.internal.GemFireVersion;
import org.apache.geode.internal.Version;
@@ -190,7 +190,7 @@ public class TcpServer {
}
public void restarting(InternalDistributedSystem ds, GemFireCacheImpl cache,
- SharedConfiguration sharedConfig) throws IOException {
+ ClusterConfigurationService sharedConfig) throws IOException {
this.shuttingDown = false;
this.handler.restarting(ds, cache, sharedConfig);
startServerThread();
http://git-wip-us.apache.org/repos/asf/geode/blob/e79e0103/geode-core/src/main/java/org/apache/geode/internal/cache/ClusterConfigurationLoader.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/ClusterConfigurationLoader.java b/geode-core/src/main/java/org/apache/geode/internal/cache/ClusterConfigurationLoader.java
index 67748f6..f904af1 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/ClusterConfigurationLoader.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/ClusterConfigurationLoader.java
@@ -32,7 +32,7 @@ import org.apache.logging.log4j.Logger;
import org.apache.geode.UnmodifiableException;
import org.apache.geode.cache.Cache;
import org.apache.geode.distributed.internal.DistributionConfig;
-import org.apache.geode.distributed.internal.SharedConfiguration;
+import org.apache.geode.distributed.internal.ClusterConfigurationService;
import org.apache.geode.distributed.internal.tcpserver.TcpClient;
import org.apache.geode.internal.ConfigSource;
import org.apache.geode.internal.JarClassLoader;
@@ -103,7 +103,7 @@ public class ClusterConfigurationLoader {
// apply the cluster config first
Configuration clusterConfiguration =
- requestedConfiguration.get(SharedConfiguration.CLUSTER_CONFIG);
+ requestedConfiguration.get(ClusterConfigurationService.CLUSTER_CONFIG);
if (clusterConfiguration != null) {
String cacheXmlContent = clusterConfiguration.getCacheXmlContent();
if (!StringUtils.isBlank(cacheXmlContent)) {
@@ -155,7 +155,7 @@ public class ClusterConfigurationLoader {
// apply the cluster config first
Configuration clusterConfiguration =
- requestedConfiguration.get(SharedConfiguration.CLUSTER_CONFIG);
+ requestedConfiguration.get(ClusterConfigurationService.CLUSTER_CONFIG);
if (clusterConfiguration != null) {
runtimeProps.putAll(clusterConfiguration.getGemfireProperties());
}
@@ -198,7 +198,7 @@ public class ClusterConfigurationLoader {
List<String> groups = ClusterConfigurationLoader.getGroups(config);
ConfigurationRequest request = new ConfigurationRequest();
- request.addGroups(SharedConfiguration.CLUSTER_CONFIG);
+ request.addGroups(ClusterConfigurationService.CLUSTER_CONFIG);
for (String group : groups) {
request.addGroups(group);
}
http://git-wip-us.apache.org/repos/asf/geode/blob/e79e0103/geode-core/src/main/java/org/apache/geode/internal/cache/GemFireCacheImpl.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/GemFireCacheImpl.java b/geode-core/src/main/java/org/apache/geode/internal/cache/GemFireCacheImpl.java
index 943a240..795164d 100755
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/GemFireCacheImpl.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/GemFireCacheImpl.java
@@ -102,7 +102,7 @@ import org.apache.geode.distributed.internal.ReplyProcessor21;
import org.apache.geode.distributed.internal.ResourceEvent;
import org.apache.geode.distributed.internal.ResourceEventsListener;
import org.apache.geode.distributed.internal.ServerLocation;
-import org.apache.geode.distributed.internal.SharedConfiguration;
+import org.apache.geode.distributed.internal.ClusterConfigurationService;
import org.apache.geode.distributed.internal.locks.DLockService;
import org.apache.geode.distributed.internal.membership.InternalDistributedMember;
import org.apache.geode.i18n.LogWriterI18n;
@@ -1033,7 +1033,7 @@ public class GemFireCacheImpl
logger.info(response.describeConfig());
Configuration clusterConfig =
- response.getRequestedConfiguration().get(SharedConfiguration.CLUSTER_CONFIG);
+ response.getRequestedConfiguration().get(ClusterConfigurationService.CLUSTER_CONFIG);
Properties clusterSecProperties =
(clusterConfig == null) ? new Properties() : clusterConfig.getGemfireProperties();
http://git-wip-us.apache.org/repos/asf/geode/blob/e79e0103/geode-core/src/main/java/org/apache/geode/management/internal/JmxManagerLocator.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/JmxManagerLocator.java b/geode-core/src/main/java/org/apache/geode/management/internal/JmxManagerLocator.java
index ddc0542..6417d57 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/JmxManagerLocator.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/JmxManagerLocator.java
@@ -18,6 +18,7 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
+import org.apache.geode.distributed.internal.ClusterConfigurationService;
import org.apache.logging.log4j.Logger;
import org.apache.geode.CancelException;
@@ -29,7 +30,6 @@ import org.apache.geode.cache.execute.Function;
import org.apache.geode.cache.execute.FunctionContext;
import org.apache.geode.cache.execute.FunctionService;
import org.apache.geode.distributed.DistributedSystem;
-import org.apache.geode.distributed.internal.SharedConfiguration;
import org.apache.geode.distributed.internal.membership.InternalDistributedMember;
import org.apache.geode.distributed.internal.tcpserver.TcpHandler;
import org.apache.geode.distributed.internal.tcpserver.TcpServer;
@@ -71,7 +71,7 @@ public class JmxManagerLocator implements TcpHandler {
}
public void restarting(DistributedSystem ds, GemFireCache cache,
- SharedConfiguration sharedConfig) {
+ ClusterConfigurationService sharedConfig) {
this.cache = (GemFireCacheImpl) cache;
}
http://git-wip-us.apache.org/repos/asf/geode/blob/e79e0103/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/AbstractCommandsSupport.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/AbstractCommandsSupport.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/AbstractCommandsSupport.java
index 41671a4..f077180 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/AbstractCommandsSupport.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/AbstractCommandsSupport.java
@@ -21,8 +21,8 @@ import org.apache.geode.cache.execute.Execution;
import org.apache.geode.cache.execute.Function;
import org.apache.geode.cache.execute.FunctionService;
import org.apache.geode.distributed.DistributedMember;
+import org.apache.geode.distributed.internal.ClusterConfigurationService;
import org.apache.geode.distributed.internal.InternalLocator;
-import org.apache.geode.distributed.internal.SharedConfiguration;
import org.apache.geode.internal.lang.StringUtils;
import org.apache.geode.internal.security.SecurityService;
import org.apache.geode.management.cli.CliMetaData;
@@ -100,7 +100,7 @@ public abstract class AbstractCommandsSupport implements CommandMarker {
return (getGfsh() != null && getGfsh().isConnectedAndReady());
}
- protected SharedConfiguration getSharedConfiguration() {
+ protected ClusterConfigurationService getSharedConfiguration() {
InternalLocator locator = InternalLocator.getLocator();
return (locator == null) ? null : locator.getSharedConfiguration();
}
@@ -109,7 +109,7 @@ public abstract class AbstractCommandsSupport implements CommandMarker {
if (result == null) {
throw new IllegalArgumentException("Result should not be null");
}
- SharedConfiguration sc = getSharedConfiguration();
+ ClusterConfigurationService sc = getSharedConfiguration();
if (sc == null) {
result.setCommandPersisted(false);
} else {
http://git-wip-us.apache.org/repos/asf/geode/blob/e79e0103/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ExportImportSharedConfigurationCommands.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ExportImportSharedConfigurationCommands.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ExportImportSharedConfigurationCommands.java
index 46ca18d..914576b 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ExportImportSharedConfigurationCommands.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ExportImportSharedConfigurationCommands.java
@@ -16,7 +16,7 @@ package org.apache.geode.management.internal.cli.commands;
import org.apache.commons.io.FileUtils;
import org.apache.geode.distributed.internal.InternalLocator;
-import org.apache.geode.distributed.internal.SharedConfiguration;
+import org.apache.geode.distributed.internal.ClusterConfigurationService;
import org.apache.geode.internal.cache.GemFireCacheImpl;
import org.apache.geode.internal.lang.StringUtils;
import org.apache.geode.internal.logging.LogService;
@@ -69,7 +69,7 @@ public class ExportImportSharedConfigurationCommands extends AbstractCommandsSup
return ResultBuilder.createGemFireErrorResult(CliStrings.SHARED_CONFIGURATION_NOT_STARTED);
}
- SharedConfiguration sc = locator.getSharedConfiguration();
+ ClusterConfigurationService sc = locator.getSharedConfiguration();
File zipFile = new File(zipFileName);
zipFile.getParentFile().mkdirs();
@@ -130,7 +130,7 @@ public class ExportImportSharedConfigurationCommands extends AbstractCommandsSup
Result result;
File zipFile = new File(zipFileName);
try {
- SharedConfiguration sc = locator.getSharedConfiguration();
+ ClusterConfigurationService sc = locator.getSharedConfiguration();
// backup the old config
for (Configuration config : sc.getEntireConfiguration().values()) {
http://git-wip-us.apache.org/repos/asf/geode/blob/e79e0103/geode-core/src/main/java/org/apache/geode/management/internal/cli/i18n/CliStrings.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/i18n/CliStrings.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/i18n/CliStrings.java
index 239b66f..fbeca62 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/i18n/CliStrings.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/i18n/CliStrings.java
@@ -22,7 +22,7 @@ import org.apache.geode.cache.PartitionAttributesFactory;
import org.apache.geode.cache.server.CacheServer;
import org.apache.geode.distributed.ConfigurationProperties;
import org.apache.geode.distributed.internal.DistributionConfig;
-import org.apache.geode.distributed.internal.SharedConfiguration;
+import org.apache.geode.distributed.internal.ClusterConfigurationService;
import org.apache.geode.internal.cache.xmlcache.CacheXml;
import org.apache.geode.management.internal.cli.shell.Gfsh;
@@ -2392,7 +2392,7 @@ public class CliStrings {
public static final String START_LOCATOR__LOAD__SHARED_CONFIGURATION__FROM__FILESYSTEM__HELP =
"When \" " + START_LOCATOR__LOAD__SHARED_CONFIGURATION__FROM__FILESYSTEM
+ " \" is set to true, the locator loads the cluster configuration from the \""
- + SharedConfiguration.CLUSTER_CONFIG_ARTIFACTS_DIR_NAME + "\" directory.";
+ + ClusterConfigurationService.CLUSTER_CONFIG_ARTIFACTS_DIR_NAME + "\" directory.";
public static final String START_LOCATOR__CLUSTER__CONFIG__DIR = "cluster-config-dir";
public static final String START_LOCATOR__CLUSTER__CONFIG__DIR__HELP =
"Directory used by the cluster configuration service to store the cluster configuration on the filesystem";
http://git-wip-us.apache.org/repos/asf/geode/blob/e79e0103/geode-core/src/main/java/org/apache/geode/management/internal/cli/remote/RemoteExecutionStrategy.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/remote/RemoteExecutionStrategy.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/remote/RemoteExecutionStrategy.java
index 708ea6b..1e4870f 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/remote/RemoteExecutionStrategy.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/remote/RemoteExecutionStrategy.java
@@ -22,7 +22,7 @@ import org.springframework.util.ReflectionUtils;
import org.apache.geode.distributed.DistributedLockService;
import org.apache.geode.distributed.internal.InternalDistributedSystem;
-import org.apache.geode.distributed.internal.SharedConfiguration;
+import org.apache.geode.distributed.internal.ClusterConfigurationService;
import org.apache.geode.internal.ClassPathLoader;
import org.apache.geode.internal.cache.GemFireCacheImpl;
import org.apache.geode.management.ManagementService;
@@ -100,14 +100,14 @@ public class RemoteExecutionStrategy {
// TODO: why do we need to care about this here?
if (gfc.getDistributionManager().isSharedConfigurationServiceEnabledForDS()
&& (writesToSharedConfiguration(method) || readsFromSharedConfiguration(method))) {
- DistributedLockService dls = SharedConfiguration
+ DistributedLockService dls = ClusterConfigurationService
.getSharedConfigLockService(InternalDistributedSystem.getAnyInstance());
- if (dls.lock(SharedConfiguration.SHARED_CONFIG_LOCK_NAME, 10000, -1)) {
+ if (dls.lock(ClusterConfigurationService.SHARED_CONFIG_LOCK_NAME, 10000, -1)) {
try {
result = (Result) ReflectionUtils.invokeMethod(gfshParseResult.getMethod(),
gfshParseResult.getInstance(), gfshParseResult.getArguments());
} finally {
- dls.unlock(SharedConfiguration.SHARED_CONFIG_LOCK_NAME);
+ dls.unlock(ClusterConfigurationService.SHARED_CONFIG_LOCK_NAME);
}
} else {
return ResultBuilder.createGemFireErrorResult(
http://git-wip-us.apache.org/repos/asf/geode/blob/e79e0103/geode-core/src/main/java/org/apache/geode/management/internal/configuration/callbacks/ConfigurationChangeListener.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/configuration/callbacks/ConfigurationChangeListener.java b/geode-core/src/main/java/org/apache/geode/management/internal/configuration/callbacks/ConfigurationChangeListener.java
index 6d685b8..ae8b9b3 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/configuration/callbacks/ConfigurationChangeListener.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/configuration/callbacks/ConfigurationChangeListener.java
@@ -15,7 +15,7 @@
package org.apache.geode.management.internal.configuration.callbacks;
import org.apache.commons.io.FileUtils;
-import org.apache.geode.distributed.internal.SharedConfiguration;
+import org.apache.geode.distributed.internal.ClusterConfigurationService;
import org.apache.logging.log4j.Logger;
import org.apache.geode.cache.EntryEvent;
@@ -35,9 +35,9 @@ import java.util.Set;
public class ConfigurationChangeListener extends CacheListenerAdapter<String, Configuration> {
private static final Logger logger = LogService.getLogger();
- private final SharedConfiguration sharedConfig;
+ private final ClusterConfigurationService sharedConfig;
- public ConfigurationChangeListener(SharedConfiguration sharedConfig) {
+ public ConfigurationChangeListener(ClusterConfigurationService sharedConfig) {
this.sharedConfig = sharedConfig;
}
http://git-wip-us.apache.org/repos/asf/geode/blob/e79e0103/geode-core/src/main/java/org/apache/geode/management/internal/configuration/functions/UploadJarFunction.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/configuration/functions/UploadJarFunction.java b/geode-core/src/main/java/org/apache/geode/management/internal/configuration/functions/UploadJarFunction.java
index aa211ac..c3b5035 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/configuration/functions/UploadJarFunction.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/configuration/functions/UploadJarFunction.java
@@ -18,8 +18,8 @@ package org.apache.geode.management.internal.configuration.functions;
import org.apache.geode.cache.execute.Function;
import org.apache.geode.cache.execute.FunctionContext;
import org.apache.geode.distributed.Locator;
+import org.apache.geode.distributed.internal.ClusterConfigurationService;
import org.apache.geode.distributed.internal.InternalLocator;
-import org.apache.geode.distributed.internal.SharedConfiguration;
import org.apache.geode.internal.InternalEntity;
import org.apache.geode.internal.logging.LogService;
import org.apache.logging.log4j.Logger;
@@ -37,7 +37,7 @@ public class UploadJarFunction implements Function, InternalEntity {
String jarName = (String) args[1];
if (locator != null && group != null && jarName != null) {
- SharedConfiguration sharedConfig = locator.getSharedConfiguration();
+ ClusterConfigurationService sharedConfig = locator.getSharedConfiguration();
if (sharedConfig != null) {
try {
byte[] jarBytes = sharedConfig.getJarBytesFromThisLocator(group, jarName);
http://git-wip-us.apache.org/repos/asf/geode/blob/e79e0103/geode-core/src/main/java/org/apache/geode/management/internal/configuration/handlers/ConfigurationRequestHandler.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/configuration/handlers/ConfigurationRequestHandler.java b/geode-core/src/main/java/org/apache/geode/management/internal/configuration/handlers/ConfigurationRequestHandler.java
index 3095560..6495d09 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/configuration/handlers/ConfigurationRequestHandler.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/configuration/handlers/ConfigurationRequestHandler.java
@@ -16,11 +16,11 @@ package org.apache.geode.management.internal.configuration.handlers;
import java.io.IOException;
+import org.apache.geode.distributed.internal.ClusterConfigurationService;
import org.apache.logging.log4j.Logger;
import org.apache.geode.cache.GemFireCache;
import org.apache.geode.distributed.DistributedSystem;
-import org.apache.geode.distributed.internal.SharedConfiguration;
import org.apache.geode.distributed.internal.tcpserver.TcpHandler;
import org.apache.geode.distributed.internal.tcpserver.TcpServer;
import org.apache.geode.internal.logging.LogService;
@@ -36,9 +36,9 @@ import org.apache.geode.management.internal.configuration.messages.Configuration
public class ConfigurationRequestHandler implements TcpHandler {
private static final Logger logger = LogService.getLogger();
- SharedConfiguration sharedConfig;
+ ClusterConfigurationService sharedConfig;
- public ConfigurationRequestHandler(SharedConfiguration sharedConfig) {
+ public ConfigurationRequestHandler(ClusterConfigurationService sharedConfig) {
this.sharedConfig = sharedConfig;
}
@@ -71,7 +71,7 @@ public class ConfigurationRequestHandler implements TcpHandler {
@Override
public void restarting(DistributedSystem system, GemFireCache cache,
- SharedConfiguration sharedConfig) {
+ ClusterConfigurationService sharedConfig) {
if (sharedConfig != null) {
this.sharedConfig = sharedConfig;
}
http://git-wip-us.apache.org/repos/asf/geode/blob/e79e0103/geode-core/src/main/java/org/apache/geode/management/internal/configuration/handlers/SharedConfigurationStatusRequestHandler.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/configuration/handlers/SharedConfigurationStatusRequestHandler.java b/geode-core/src/main/java/org/apache/geode/management/internal/configuration/handlers/SharedConfigurationStatusRequestHandler.java
index f866db7..a87e079 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/configuration/handlers/SharedConfigurationStatusRequestHandler.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/configuration/handlers/SharedConfigurationStatusRequestHandler.java
@@ -18,11 +18,10 @@ import java.io.IOException;
import org.apache.geode.cache.GemFireCache;
import org.apache.geode.distributed.DistributedSystem;
+import org.apache.geode.distributed.internal.ClusterConfigurationService;
import org.apache.geode.distributed.internal.InternalLocator;
-import org.apache.geode.distributed.internal.SharedConfiguration;
import org.apache.geode.distributed.internal.tcpserver.TcpHandler;
import org.apache.geode.distributed.internal.tcpserver.TcpServer;
-import org.apache.geode.management.internal.configuration.messages.ConfigurationRequest;
import org.apache.geode.management.internal.configuration.messages.SharedConfigurationStatusRequest;
public class SharedConfigurationStatusRequestHandler implements TcpHandler {
@@ -57,7 +56,7 @@ public class SharedConfigurationStatusRequestHandler implements TcpHandler {
@Override
public void restarting(DistributedSystem system, GemFireCache cache,
- SharedConfiguration sharedConfig) {
+ ClusterConfigurationService sharedConfig) {
}
http://git-wip-us.apache.org/repos/asf/geode/blob/e79e0103/geode-core/src/test/java/org/apache/geode/cache/client/internal/AutoConnectionSourceImplJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/cache/client/internal/AutoConnectionSourceImplJUnitTest.java b/geode-core/src/test/java/org/apache/geode/cache/client/internal/AutoConnectionSourceImplJUnitTest.java
index 737c583..2f9f867 100644
--- a/geode-core/src/test/java/org/apache/geode/cache/client/internal/AutoConnectionSourceImplJUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/cache/client/internal/AutoConnectionSourceImplJUnitTest.java
@@ -26,15 +26,13 @@ import org.apache.geode.distributed.DistributedSystem;
import org.apache.geode.distributed.internal.InternalDistributedSystem;
import org.apache.geode.distributed.internal.PoolStatHelper;
import org.apache.geode.distributed.internal.ServerLocation;
-import org.apache.geode.distributed.internal.SharedConfiguration;
+import org.apache.geode.distributed.internal.ClusterConfigurationService;
import org.apache.geode.distributed.internal.tcpserver.TcpClient;
import org.apache.geode.distributed.internal.tcpserver.TcpHandler;
import org.apache.geode.distributed.internal.tcpserver.TcpServer;
import org.apache.geode.internal.AvailablePortHelper;
import org.apache.geode.internal.cache.PoolStats;
import org.apache.geode.internal.cache.tier.InternalClientMembership;
-import org.apache.geode.internal.cache.tier.sockets.HandShake;
-import org.apache.geode.internal.net.SocketCreator;
import org.apache.geode.management.membership.ClientMembershipEvent;
import org.apache.geode.management.membership.ClientMembershipListener;
import org.apache.geode.test.junit.categories.ClientServerTest;
@@ -270,7 +268,7 @@ public class AutoConnectionSourceImplJUnitTest {
public void endResponse(Object request, long startTime) {}
public void restarting(DistributedSystem ds, GemFireCache cache,
- SharedConfiguration sharedConfig) {}
+ ClusterConfigurationService sharedConfig) {}
}
http://git-wip-us.apache.org/repos/asf/geode/blob/e79e0103/geode-core/src/test/java/org/apache/geode/distributed/AbstractLocatorLauncherIntegrationTestCase.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/distributed/AbstractLocatorLauncherIntegrationTestCase.java b/geode-core/src/test/java/org/apache/geode/distributed/AbstractLocatorLauncherIntegrationTestCase.java
index 120b939..0908b74 100755
--- a/geode-core/src/test/java/org/apache/geode/distributed/AbstractLocatorLauncherIntegrationTestCase.java
+++ b/geode-core/src/test/java/org/apache/geode/distributed/AbstractLocatorLauncherIntegrationTestCase.java
@@ -28,7 +28,7 @@ import org.junit.rules.TemporaryFolder;
import org.apache.geode.distributed.AbstractLauncher.Status;
import org.apache.geode.distributed.LocatorLauncher.Builder;
import org.apache.geode.distributed.LocatorLauncher.LocatorState;
-import org.apache.geode.distributed.internal.SharedConfiguration;
+import org.apache.geode.distributed.internal.ClusterConfigurationService;
import org.apache.geode.internal.AvailablePortHelper;
import org.apache.geode.internal.DistributionLocator;
import org.junit.runners.Parameterized;
@@ -67,7 +67,7 @@ public abstract class AbstractLocatorLauncherIntegrationTestCase
String.valueOf(this.locatorPort));
this.workingDirectory = this.temporaryFolder.getRoot().getCanonicalPath();
this.clusterConfigDirectory = this.temporaryFolder
- .newFolder(SharedConfiguration.CLUSTER_CONFIG_DISK_DIR_PREFIX + getUniqueName())
+ .newFolder(ClusterConfigurationService.CLUSTER_CONFIG_DISK_DIR_PREFIX + getUniqueName())
.getCanonicalPath();
}
http://git-wip-us.apache.org/repos/asf/geode/blob/e79e0103/geode-core/src/test/java/org/apache/geode/distributed/internal/tcpserver/TcpServerJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/distributed/internal/tcpserver/TcpServerJUnitTest.java b/geode-core/src/test/java/org/apache/geode/distributed/internal/tcpserver/TcpServerJUnitTest.java
index 1ad149e..7c7a2b3 100644
--- a/geode-core/src/test/java/org/apache/geode/distributed/internal/tcpserver/TcpServerJUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/distributed/internal/tcpserver/TcpServerJUnitTest.java
@@ -27,6 +27,7 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
+import org.apache.geode.distributed.internal.ClusterConfigurationService;
import org.apache.geode.test.junit.categories.MembershipTest;
import org.junit.After;
import org.junit.Before;
@@ -38,7 +39,6 @@ import org.apache.geode.cache.GemFireCache;
import org.apache.geode.distributed.DistributedSystem;
import org.apache.geode.distributed.internal.DistributionConfigImpl;
import org.apache.geode.distributed.internal.PoolStatHelper;
-import org.apache.geode.distributed.internal.SharedConfiguration;
import org.apache.geode.internal.AvailablePort;
import org.apache.geode.internal.net.SocketCreatorFactory;
import org.apache.geode.test.junit.categories.IntegrationTest;
@@ -179,7 +179,7 @@ public class TcpServerJUnitTest {
}
public void restarting(DistributedSystem ds, GemFireCache cache,
- SharedConfiguration sharedConfig) {}
+ ClusterConfigurationService sharedConfig) {}
public void endRequest(Object request, long startTime) {}
@@ -214,7 +214,7 @@ public class TcpServerJUnitTest {
public void shutDown() {}
public void restarting(DistributedSystem ds, GemFireCache cache,
- SharedConfiguration sharedConfig) {}
+ ClusterConfigurationService sharedConfig) {}
public void endRequest(Object request, long startTime) {}
http://git-wip-us.apache.org/repos/asf/geode/blob/e79e0103/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ClusterConfigurationServiceCommandsDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ClusterConfigurationServiceCommandsDUnitTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ClusterConfigurationServiceCommandsDUnitTest.java
new file mode 100644
index 0000000..87cac55
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ClusterConfigurationServiceCommandsDUnitTest.java
@@ -0,0 +1,344 @@
+/*
+ * 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.internal.cli.commands;
+
+import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.CacheFactory;
+import org.apache.geode.distributed.DistributedMember;
+import org.apache.geode.distributed.Locator;
+import org.apache.geode.distributed.internal.InternalLocator;
+import org.apache.geode.distributed.internal.ClusterConfigurationService;
+import org.apache.geode.internal.ClassBuilder;
+import org.apache.geode.management.cli.Result;
+import org.apache.geode.management.cli.Result.Status;
+import org.apache.geode.management.internal.cli.HeadlessGfsh;
+import org.apache.geode.management.internal.cli.result.CommandResult;
+import org.apache.geode.management.internal.cli.util.CommandStringBuilder;
+import org.apache.geode.management.internal.configuration.SharedConfigurationTestUtils;
+import org.apache.geode.management.internal.configuration.domain.Configuration;
+import org.apache.geode.test.dunit.SerializableCallable;
+import org.apache.geode.test.dunit.SerializableRunnable;
+import org.apache.geode.test.dunit.VM;
+import org.apache.geode.test.dunit.WaitCriterion;
+import org.apache.geode.test.junit.categories.DistributedTest;
+import org.apache.geode.test.junit.categories.FlakyTest;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Properties;
+import java.util.Set;
+
+import static org.apache.geode.distributed.ConfigurationProperties.*;
+import static org.apache.geode.internal.AvailablePortHelper.getRandomAvailableTCPPorts;
+import static org.apache.geode.management.internal.cli.CliUtil.getAllNormalMembers;
+import static org.apache.geode.management.internal.cli.i18n.CliStrings.*;
+import static org.apache.geode.test.dunit.Assert.*;
+import static org.apache.geode.test.dunit.Host.getHost;
+import static org.apache.geode.test.dunit.LogWriterUtils.getLogWriter;
+import static org.apache.geode.test.dunit.NetworkUtils.getIPLiteral;
+import static org.apache.geode.test.dunit.Wait.waitForCriterion;
+
+/**
+ * DUnit test to test export and import of shared configuration.
+ */
+@Category(DistributedTest.class)
+@SuppressWarnings("unchecked")
+public class ClusterConfigurationServiceCommandsDUnitTest extends CliCommandTestBase {
+
+ private static final int TIMEOUT = 10000;
+ private static final int INTERVAL = 500;
+
+ private final String region1Name = "r1";
+ private final String region2Name = "r2";
+ private final String logLevel = "info";
+
+ private String groupName;
+
+ private String deployedJarName;
+ private File newDeployableJarFile;
+ private ClassBuilder classBuilder;
+
+ private String sharedConfigZipFileName;
+ private String startArchiveFileName;
+ private int[] ports;
+
+ private int locator1Port;
+ private String locator1Name;
+ private String locator1LogFilePath;
+
+ private int locator2Port;
+ private String locator2Name;
+ private String locator2LogFilePath;
+
+ private int locator1HttpPort;
+ private int locator1JmxPort;
+ private String locator1JmxHost;
+
+ @Override
+ protected final void postSetUpCliCommandTestBase() throws Exception {
+ disconnectAllFromDS();
+
+ this.groupName = getName();
+ this.deployedJarName = "DeployCommandsDUnit1.jar";
+ this.newDeployableJarFile = new File(
+ this.temporaryFolder.getRoot().getCanonicalPath() + File.separator + deployedJarName);
+ this.classBuilder = new ClassBuilder();
+
+ this.sharedConfigZipFileName =
+ this.temporaryFolder.getRoot().getCanonicalPath() + File.separator + "sharedConfig.zip";
+ this.startArchiveFileName =
+ this.temporaryFolder.getRoot().getCanonicalPath() + File.separator + "stats.gfs";
+ this.ports = getRandomAvailableTCPPorts(4);
+
+ this.locator1Port = this.ports[0];
+ this.locator1Name = "locator1-" + this.locator1Port;
+ this.locator1LogFilePath = this.temporaryFolder.getRoot().getCanonicalPath() + File.separator
+ + "locator-" + this.locator1Port + ".log";
+
+ this.locator2Port = this.ports[1];
+ this.locator2Name = "Locator2-" + this.locator2Port;
+ this.locator2LogFilePath = this.temporaryFolder.getRoot().getCanonicalPath() + File.separator
+ + "locator-" + this.locator2Port + ".log";
+
+ this.locator1HttpPort = ports[2];
+ this.locator1JmxPort = ports[3];
+ this.locator1JmxHost = getIPLiteral();
+ }
+
+ @Override
+ public final void postTearDownCacheTestCase() throws Exception {
+ for (int i = 0; i < 4; i++) {
+ getHost(0).getVM(i).invoke(SharedConfigurationTestUtils.cleanupLocator);
+ }
+ }
+
+ @Category(FlakyTest.class) // GEODE-1519
+ @Test
+ public void testExportImportSharedConfiguration() throws IOException {
+ // Start the Locator and wait for shared configuration to be available
+ VM locatorAndMgr = getHost(0).getVM(3);
+ Set<DistributedMember> normalMembers1 =
+ (Set<DistributedMember>) locatorAndMgr.invoke(new SerializableCallable() {
+ @Override
+ public Object call() {
+ final File locatorLogFile = new File(locator1LogFilePath);
+
+ final Properties locatorProps = new Properties();
+ locatorProps.setProperty(NAME, locator1Name);
+ locatorProps.setProperty(MCAST_PORT, "0");
+ locatorProps.setProperty(LOG_LEVEL, "config");
+ locatorProps.setProperty(ENABLE_CLUSTER_CONFIGURATION, "true");
+ locatorProps.setProperty(JMX_MANAGER, "true");
+ locatorProps.setProperty(JMX_MANAGER_START, "true");
+ locatorProps.setProperty(JMX_MANAGER_BIND_ADDRESS, String.valueOf(locator1JmxHost));
+ locatorProps.setProperty(JMX_MANAGER_PORT, String.valueOf(locator1JmxPort));
+ locatorProps.setProperty(HTTP_SERVICE_PORT, String.valueOf(locator1HttpPort));
+
+ try {
+ final InternalLocator locator = (InternalLocator) Locator
+ .startLocatorAndDS(locator1Port, locatorLogFile, null, locatorProps);
+
+ WaitCriterion wc = new WaitCriterion() {
+ @Override
+ public boolean done() {
+ return locator.isSharedConfigurationRunning();
+ }
+
+ @Override
+ public String description() {
+ return "Waiting for shared configuration to be started";
+ }
+ };
+ waitForCriterion(wc, TIMEOUT, INTERVAL, true);
+
+ } catch (IOException e) {
+ fail("Unable to create a locator with a shared configuration", e);
+ }
+
+ return getAllNormalMembers(CacheFactory.getAnyInstance());
+ }
+ });
+
+ HeadlessGfsh gfsh = getDefaultShell();
+ connect(locator1JmxHost, locator1JmxPort, locator1HttpPort, gfsh);
+
+ // Create a cache in VM 1
+ VM dataMember = getHost(0).getVM(1);
+ normalMembers1 = (Set<DistributedMember>) dataMember.invoke(new SerializableCallable() {
+ @Override
+ public Object call() {
+ Properties localProps = new Properties();
+ localProps.setProperty(MCAST_PORT, "0");
+ localProps.setProperty(LOCATORS, "localhost[" + locator1Port + "]");
+ localProps.setProperty(GROUPS, groupName);
+ localProps.setProperty(NAME, "DataMember");
+ getSystem(localProps);
+ Cache cache = getCache();
+ assertNotNull(cache);
+ return getAllNormalMembers(cache);
+ }
+ });
+
+ // Create a JAR file
+ this.classBuilder.writeJarFromName("DeployCommandsDUnitA", this.newDeployableJarFile);
+
+ // Deploy the JAR
+ CommandResult cmdResult =
+ executeCommand("deploy --jar=" + this.newDeployableJarFile.getCanonicalPath());
+ assertEquals(Result.Status.OK, cmdResult.getStatus());
+
+ // Create the region1 on the group
+ CommandStringBuilder commandStringBuilder = new CommandStringBuilder(CREATE_REGION);
+ commandStringBuilder.addOption(CREATE_REGION__REGION, region1Name);
+ commandStringBuilder.addOption(CREATE_REGION__REGIONSHORTCUT, "REPLICATE");
+ commandStringBuilder.addOption(CREATE_REGION__STATISTICSENABLED, "true");
+ commandStringBuilder.addOption(CREATE_REGION__GROUP, groupName);
+
+ cmdResult = executeCommand(commandStringBuilder.toString());
+ assertEquals(Result.Status.OK, cmdResult.getStatus());
+
+ commandStringBuilder = new CommandStringBuilder(CREATE_REGION);
+ commandStringBuilder.addOption(CREATE_REGION__REGION, region2Name);
+ commandStringBuilder.addOption(CREATE_REGION__REGIONSHORTCUT, "PARTITION");
+ commandStringBuilder.addOption(CREATE_REGION__STATISTICSENABLED, "true");
+ cmdResult = executeCommand(commandStringBuilder.toString());
+ assertEquals(Result.Status.OK, cmdResult.getStatus());
+
+ // Alter runtime configuration
+ commandStringBuilder = new CommandStringBuilder(ALTER_RUNTIME_CONFIG);
+ commandStringBuilder.addOption(ALTER_RUNTIME_CONFIG__LOG__LEVEL, logLevel);
+ commandStringBuilder.addOption(ALTER_RUNTIME_CONFIG__LOG__FILE__SIZE__LIMIT, "50");
+ commandStringBuilder.addOption(ALTER_RUNTIME_CONFIG__ARCHIVE__DISK__SPACE__LIMIT, "32");
+ commandStringBuilder.addOption(ALTER_RUNTIME_CONFIG__ARCHIVE__FILE__SIZE__LIMIT, "49");
+ commandStringBuilder.addOption(ALTER_RUNTIME_CONFIG__STATISTIC__SAMPLE__RATE, "120");
+ commandStringBuilder.addOption(ALTER_RUNTIME_CONFIG__STATISTIC__ARCHIVE__FILE,
+ this.startArchiveFileName);
+ commandStringBuilder.addOption(ALTER_RUNTIME_CONFIG__STATISTIC__SAMPLING__ENABLED, "true");
+ commandStringBuilder.addOption(ALTER_RUNTIME_CONFIG__LOG__DISK__SPACE__LIMIT, "10");
+ cmdResult = executeCommand(commandStringBuilder.getCommandString());
+ String resultString = commandResultToString(cmdResult);
+
+ getLogWriter().info("#SB Result\n");
+ getLogWriter().info(resultString);
+ assertEquals(true, cmdResult.getStatus().equals(Status.OK));
+
+ commandStringBuilder = new CommandStringBuilder(STATUS_SHARED_CONFIG);
+ cmdResult = executeCommand(commandStringBuilder.getCommandString());
+ resultString = commandResultToString(cmdResult);
+ getLogWriter().info("#SB Result\n");
+ getLogWriter().info(resultString);
+ assertEquals(Status.OK, cmdResult.getStatus());
+
+ commandStringBuilder = new CommandStringBuilder(EXPORT_SHARED_CONFIG);
+ commandStringBuilder.addOption(EXPORT_SHARED_CONFIG__FILE, this.sharedConfigZipFileName);
+ cmdResult = executeCommand(commandStringBuilder.getCommandString());
+ resultString = commandResultToString(cmdResult);
+ getLogWriter().info("#SB Result\n");
+ getLogWriter().info(resultString);
+ assertEquals(Status.OK, cmdResult.getStatus());
+
+ // Import into a running system should fail
+ commandStringBuilder = new CommandStringBuilder(IMPORT_SHARED_CONFIG);
+ commandStringBuilder.addOption(IMPORT_SHARED_CONFIG__ZIP, this.sharedConfigZipFileName);
+ cmdResult = executeCommand(commandStringBuilder.getCommandString());
+ assertEquals(Status.ERROR, cmdResult.getStatus());
+
+ // Stop the data members and remove the shared configuration in the locator.
+ dataMember.invoke(new SerializableCallable() {
+ @Override
+ public Object call() throws Exception {
+ Cache cache = getCache();
+ cache.close();
+ assertTrue(cache.isClosed());
+ disconnectFromDS();
+ return null;
+ }
+ });
+
+ // Clear shared configuration in this locator to test the import shared configuration
+ locatorAndMgr.invoke(new SerializableCallable() {
+ @Override
+ public Object call() throws Exception {
+ InternalLocator locator = InternalLocator.getLocator();
+ ClusterConfigurationService sc = locator.getSharedConfiguration();
+ assertNotNull(sc);
+ sc.clearSharedConfiguration();
+ return null;
+ }
+ });
+
+ // Now execute import shared configuration
+ // Now import the shared configuration and it should succeed.
+ commandStringBuilder = new CommandStringBuilder(IMPORT_SHARED_CONFIG);
+ commandStringBuilder.addOption(IMPORT_SHARED_CONFIG__ZIP, this.sharedConfigZipFileName);
+ cmdResult = executeCommand(commandStringBuilder.getCommandString());
+ assertEquals(Status.OK, cmdResult.getStatus());
+
+ // Start a new locator , test if it has all the imported shared configuration artifacts
+ VM newLocator = getHost(0).getVM(2);
+ newLocator.invoke(new SerializableRunnable() {
+ @Override
+ public void run() {
+ final File locatorLogFile = new File(locator2LogFilePath);
+ final Properties locatorProps = new Properties();
+ locatorProps.setProperty(NAME, locator2Name);
+ locatorProps.setProperty(MCAST_PORT, "0");
+ locatorProps.setProperty(LOG_LEVEL, "fine");
+ locatorProps.setProperty(ENABLE_CLUSTER_CONFIGURATION, "true");
+ locatorProps.setProperty(LOCATORS, "localhost[" + locator1Port + "]");
+
+ try {
+ final InternalLocator locator = (InternalLocator) Locator.startLocatorAndDS(locator2Port,
+ locatorLogFile, null, locatorProps);
+
+ WaitCriterion wc = new WaitCriterion() {
+ @Override
+ public boolean done() {
+ return locator.isSharedConfigurationRunning();
+ }
+
+ @Override
+ public String description() {
+ return "Waiting for shared configuration to be started";
+ }
+ };
+ waitForCriterion(wc, 5000, 500, true);
+
+ ClusterConfigurationService sc = locator.getSharedConfiguration();
+ assertNotNull(sc);
+ Configuration groupConfig = sc.getConfiguration(groupName);
+ assertNotNull(groupConfig);
+ assertTrue(groupConfig.getCacheXmlContent().contains(region1Name));
+
+ Configuration clusterConfig =
+ sc.getConfiguration(ClusterConfigurationService.CLUSTER_CONFIG);
+ assertNotNull(clusterConfig);
+ assertTrue(clusterConfig.getCacheXmlContent().contains(region2Name));
+ assertTrue(clusterConfig.getJarNames().contains(deployedJarName));
+ assertTrue(clusterConfig.getGemfireProperties().getProperty(LOG_LEVEL).equals(logLevel));
+ assertTrue(clusterConfig.getGemfireProperties().getProperty(STATISTIC_ARCHIVE_FILE)
+ .equals(startArchiveFileName));
+
+ } catch (IOException e) {
+ fail("Unable to create a locator with a shared configuration", e);
+ } catch (Exception e) {
+ fail("Error occurred in cluster configuration service", e);
+ }
+ }
+ });
+ }
+}
http://git-wip-us.apache.org/repos/asf/geode/blob/e79e0103/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ConfigCommandsDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ConfigCommandsDUnitTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ConfigCommandsDUnitTest.java
index 87e6f66..760d2c4 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ConfigCommandsDUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ConfigCommandsDUnitTest.java
@@ -47,7 +47,7 @@ import org.apache.geode.distributed.Locator;
import org.apache.geode.distributed.internal.DistributionConfig;
import org.apache.geode.distributed.internal.InternalDistributedSystem;
import org.apache.geode.distributed.internal.InternalLocator;
-import org.apache.geode.distributed.internal.SharedConfiguration;
+import org.apache.geode.distributed.internal.ClusterConfigurationService;
import org.apache.geode.internal.AvailablePortHelper;
import org.apache.geode.internal.cache.GemFireCacheImpl;
import org.apache.geode.internal.cache.xmlcache.CacheXmlGenerator;
@@ -539,7 +539,7 @@ public class ConfigCommandsDUnitTest extends CliCommandTestBase {
Host.getHost(0).getVM(0).invoke(new SerializableRunnable() {
@Override
public void run() {
- SharedConfiguration sharedConfig =
+ ClusterConfigurationService sharedConfig =
((InternalLocator) Locator.getLocator()).getSharedConfiguration();
Properties gemfireProperties = null;
http://git-wip-us.apache.org/repos/asf/geode/blob/e79e0103/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/CreateAlterDestroyRegionCommandsDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/CreateAlterDestroyRegionCommandsDUnitTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/CreateAlterDestroyRegionCommandsDUnitTest.java
index f910721..dbfa653 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/CreateAlterDestroyRegionCommandsDUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/CreateAlterDestroyRegionCommandsDUnitTest.java
@@ -49,8 +49,8 @@ import org.apache.geode.cache.asyncqueue.AsyncEventListener;
import org.apache.geode.cache.wan.GatewaySenderFactory;
import org.apache.geode.compression.SnappyCompressor;
import org.apache.geode.distributed.Locator;
+import org.apache.geode.distributed.internal.ClusterConfigurationService;
import org.apache.geode.distributed.internal.InternalLocator;
-import org.apache.geode.distributed.internal.SharedConfiguration;
import org.apache.geode.internal.AvailablePort;
import org.apache.geode.internal.AvailablePortHelper;
import org.apache.geode.internal.ClassBuilder;
@@ -942,7 +942,7 @@ public class CreateAlterDestroyRegionCommandsDUnitTest extends CliCommandTestBas
// Make sure the region exists in the shared config
Host.getHost(0).getVM(0).invoke(() -> {
- SharedConfiguration sharedConfig =
+ ClusterConfigurationService sharedConfig =
((InternalLocator) Locator.getLocator()).getSharedConfiguration();
try {
assertTrue(
@@ -984,7 +984,7 @@ public class CreateAlterDestroyRegionCommandsDUnitTest extends CliCommandTestBas
// Make sure the region was altered in the shared config
Host.getHost(0).getVM(0).invoke(() -> {
- SharedConfiguration sharedConfig =
+ ClusterConfigurationService sharedConfig =
((InternalLocator) Locator.getLocator()).getSharedConfiguration();
try {
assertTrue(sharedConfig.getConfiguration(groupName).getCacheXmlContent().contains("45635"));
@@ -1091,7 +1091,7 @@ public class CreateAlterDestroyRegionCommandsDUnitTest extends CliCommandTestBas
// Make sure the region exists in the shared config
Host.getHost(0).getVM(0).invoke(() -> {
- SharedConfiguration sharedConfig =
+ ClusterConfigurationService sharedConfig =
((InternalLocator) Locator.getLocator()).getSharedConfiguration();
try {
assertTrue(
@@ -1110,7 +1110,7 @@ public class CreateAlterDestroyRegionCommandsDUnitTest extends CliCommandTestBas
// Make sure the region was removed from the shared config
Host.getHost(0).getVM(0).invoke(() -> {
- SharedConfiguration sharedConfig =
+ ClusterConfigurationService sharedConfig =
((InternalLocator) Locator.getLocator()).getSharedConfiguration();
try {
assertFalse(
http://git-wip-us.apache.org/repos/asf/geode/blob/e79e0103/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/DeployCommandsDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/DeployCommandsDUnitTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/DeployCommandsDUnitTest.java
index 34ffc7c..05f2c0c 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/DeployCommandsDUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/DeployCommandsDUnitTest.java
@@ -33,7 +33,7 @@ import static org.assertj.core.api.Assertions.assertThat;
import org.apache.geode.distributed.Locator;
import org.apache.geode.distributed.internal.DistributionManager;
import org.apache.geode.distributed.internal.InternalLocator;
-import org.apache.geode.distributed.internal.SharedConfiguration;
+import org.apache.geode.distributed.internal.ClusterConfigurationService;
import org.apache.geode.internal.AvailablePort;
import org.apache.geode.internal.AvailablePortHelper;
import org.apache.geode.internal.ClassBuilder;
@@ -444,7 +444,7 @@ public class DeployCommandsDUnitTest extends CliCommandTestBase {
Host.getHost(0).getVM(0).invoke(new SerializableRunnable() {
@Override
public void run() {
- SharedConfiguration sharedConfig =
+ ClusterConfigurationService sharedConfig =
((InternalLocator) Locator.getLocator()).getSharedConfiguration();
try {
assertTrue(sharedConfig.getConfiguration(groupName).getJarNames()
@@ -479,7 +479,7 @@ public class DeployCommandsDUnitTest extends CliCommandTestBase {
Host.getHost(0).getVM(0).invoke(new SerializableRunnable() {
@Override
public void run() {
- SharedConfiguration sharedConfig =
+ ClusterConfigurationService sharedConfig =
((InternalLocator) Locator.getLocator()).getSharedConfiguration();
try {
assertFalse(sharedConfig.getConfiguration(groupName).getJarNames()
[2/4] geode git commit: GEODE-2261: rename SharedConfig to
ClusterConfigurationService
Posted by ji...@apache.org.
http://git-wip-us.apache.org/repos/asf/geode/blob/e79e0103/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/DiskStoreCommandsDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/DiskStoreCommandsDUnitTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/DiskStoreCommandsDUnitTest.java
index a04bbe8..3729416 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/DiskStoreCommandsDUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/DiskStoreCommandsDUnitTest.java
@@ -54,7 +54,7 @@ import org.apache.geode.compression.SnappyCompressor;
import org.apache.geode.distributed.DistributedSystemDisconnectedException;
import org.apache.geode.distributed.Locator;
import org.apache.geode.distributed.internal.InternalLocator;
-import org.apache.geode.distributed.internal.SharedConfiguration;
+import org.apache.geode.distributed.internal.ClusterConfigurationService;
import org.apache.geode.internal.AvailablePort;
import org.apache.geode.internal.AvailablePortHelper;
import org.apache.geode.internal.FileUtil;
@@ -813,7 +813,7 @@ public class DiskStoreCommandsDUnitTest extends CliCommandTestBase {
Host.getHost(0).getVM(0).invoke(new SerializableRunnable() {
@Override
public void run() {
- SharedConfiguration sharedConfig =
+ ClusterConfigurationService sharedConfig =
((InternalLocator) Locator.getLocator()).getSharedConfiguration();
String xmlFromConfig;
try {
@@ -865,7 +865,7 @@ public class DiskStoreCommandsDUnitTest extends CliCommandTestBase {
Host.getHost(0).getVM(0).invoke(new SerializableRunnable() {
@Override
public void run() {
- SharedConfiguration sharedConfig =
+ ClusterConfigurationService sharedConfig =
((InternalLocator) Locator.getLocator()).getSharedConfiguration();
String xmlFromConfig;
try {
http://git-wip-us.apache.org/repos/asf/geode/blob/e79e0103/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/IndexCommandsDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/IndexCommandsDUnitTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/IndexCommandsDUnitTest.java
index 81c4545..a0a599f 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/IndexCommandsDUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/IndexCommandsDUnitTest.java
@@ -42,8 +42,8 @@ import org.apache.geode.cache.Region;
import org.apache.geode.cache.RegionFactory;
import org.apache.geode.cache.query.Index;
import org.apache.geode.distributed.Locator;
+import org.apache.geode.distributed.internal.ClusterConfigurationService;
import org.apache.geode.distributed.internal.InternalLocator;
-import org.apache.geode.distributed.internal.SharedConfiguration;
import org.apache.geode.internal.AvailablePort;
import org.apache.geode.internal.AvailablePortHelper;
import org.apache.geode.management.cli.Result;
@@ -711,7 +711,7 @@ public class IndexCommandsDUnitTest extends CliCommandTestBase {
Host.getHost(0).getVM(0).invoke(new SerializableRunnable() {
@Override
public void run() {
- SharedConfiguration sharedConfig =
+ ClusterConfigurationService sharedConfig =
((InternalLocator) Locator.getLocator()).getSharedConfiguration();
String xmlFromConfig;
try {
@@ -757,7 +757,7 @@ public class IndexCommandsDUnitTest extends CliCommandTestBase {
Host.getHost(0).getVM(0).invoke(new SerializableRunnable() {
@Override
public void run() {
- SharedConfiguration sharedConfig =
+ ClusterConfigurationService sharedConfig =
((InternalLocator) Locator.getLocator()).getSharedConfiguration();
String xmlFromConfig;
try {
http://git-wip-us.apache.org/repos/asf/geode/blob/e79e0103/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/QueueCommandsDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/QueueCommandsDUnitTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/QueueCommandsDUnitTest.java
index 98014a4..685bd48 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/QueueCommandsDUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/QueueCommandsDUnitTest.java
@@ -38,7 +38,7 @@ import org.apache.geode.cache.Cache;
import org.apache.geode.cache.asyncqueue.AsyncEventQueue;
import org.apache.geode.distributed.Locator;
import org.apache.geode.distributed.internal.InternalLocator;
-import org.apache.geode.distributed.internal.SharedConfiguration;
+import org.apache.geode.distributed.internal.ClusterConfigurationService;
import org.apache.geode.internal.AvailablePort;
import org.apache.geode.internal.AvailablePortHelper;
import org.apache.geode.internal.ClassBuilder;
@@ -375,7 +375,7 @@ public class QueueCommandsDUnitTest extends CliCommandTestBase {
Host.getHost(0).getVM(0).invoke(new SerializableRunnable() {
@Override
public void run() {
- SharedConfiguration sharedConfig =
+ ClusterConfigurationService sharedConfig =
((InternalLocator) Locator.getLocator()).getSharedConfiguration();
String xmlFromConfig;
try {
http://git-wip-us.apache.org/repos/asf/geode/blob/e79e0103/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/SharedConfigurationCommandsDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/SharedConfigurationCommandsDUnitTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/SharedConfigurationCommandsDUnitTest.java
deleted file mode 100644
index 096f0d8..0000000
--- a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/SharedConfigurationCommandsDUnitTest.java
+++ /dev/null
@@ -1,343 +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.internal.cli.commands;
-
-import org.apache.geode.cache.Cache;
-import org.apache.geode.cache.CacheFactory;
-import org.apache.geode.distributed.DistributedMember;
-import org.apache.geode.distributed.Locator;
-import org.apache.geode.distributed.internal.InternalLocator;
-import org.apache.geode.distributed.internal.SharedConfiguration;
-import org.apache.geode.internal.ClassBuilder;
-import org.apache.geode.management.cli.Result;
-import org.apache.geode.management.cli.Result.Status;
-import org.apache.geode.management.internal.cli.HeadlessGfsh;
-import org.apache.geode.management.internal.cli.result.CommandResult;
-import org.apache.geode.management.internal.cli.util.CommandStringBuilder;
-import org.apache.geode.management.internal.configuration.SharedConfigurationTestUtils;
-import org.apache.geode.management.internal.configuration.domain.Configuration;
-import org.apache.geode.test.dunit.SerializableCallable;
-import org.apache.geode.test.dunit.SerializableRunnable;
-import org.apache.geode.test.dunit.VM;
-import org.apache.geode.test.dunit.WaitCriterion;
-import org.apache.geode.test.junit.categories.DistributedTest;
-import org.apache.geode.test.junit.categories.FlakyTest;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.Properties;
-import java.util.Set;
-
-import static org.apache.geode.distributed.ConfigurationProperties.*;
-import static org.apache.geode.internal.AvailablePortHelper.getRandomAvailableTCPPorts;
-import static org.apache.geode.management.internal.cli.CliUtil.getAllNormalMembers;
-import static org.apache.geode.management.internal.cli.i18n.CliStrings.*;
-import static org.apache.geode.test.dunit.Assert.*;
-import static org.apache.geode.test.dunit.Host.getHost;
-import static org.apache.geode.test.dunit.LogWriterUtils.getLogWriter;
-import static org.apache.geode.test.dunit.NetworkUtils.getIPLiteral;
-import static org.apache.geode.test.dunit.Wait.waitForCriterion;
-
-/**
- * DUnit test to test export and import of shared configuration.
- */
-@Category(DistributedTest.class)
-@SuppressWarnings("unchecked")
-public class SharedConfigurationCommandsDUnitTest extends CliCommandTestBase {
-
- private static final int TIMEOUT = 10000;
- private static final int INTERVAL = 500;
-
- private final String region1Name = "r1";
- private final String region2Name = "r2";
- private final String logLevel = "info";
-
- private String groupName;
-
- private String deployedJarName;
- private File newDeployableJarFile;
- private ClassBuilder classBuilder;
-
- private String sharedConfigZipFileName;
- private String startArchiveFileName;
- private int[] ports;
-
- private int locator1Port;
- private String locator1Name;
- private String locator1LogFilePath;
-
- private int locator2Port;
- private String locator2Name;
- private String locator2LogFilePath;
-
- private int locator1HttpPort;
- private int locator1JmxPort;
- private String locator1JmxHost;
-
- @Override
- protected final void postSetUpCliCommandTestBase() throws Exception {
- disconnectAllFromDS();
-
- this.groupName = getName();
- this.deployedJarName = "DeployCommandsDUnit1.jar";
- this.newDeployableJarFile = new File(
- this.temporaryFolder.getRoot().getCanonicalPath() + File.separator + deployedJarName);
- this.classBuilder = new ClassBuilder();
-
- this.sharedConfigZipFileName =
- this.temporaryFolder.getRoot().getCanonicalPath() + File.separator + "sharedConfig.zip";
- this.startArchiveFileName =
- this.temporaryFolder.getRoot().getCanonicalPath() + File.separator + "stats.gfs";
- this.ports = getRandomAvailableTCPPorts(4);
-
- this.locator1Port = this.ports[0];
- this.locator1Name = "locator1-" + this.locator1Port;
- this.locator1LogFilePath = this.temporaryFolder.getRoot().getCanonicalPath() + File.separator
- + "locator-" + this.locator1Port + ".log";
-
- this.locator2Port = this.ports[1];
- this.locator2Name = "Locator2-" + this.locator2Port;
- this.locator2LogFilePath = this.temporaryFolder.getRoot().getCanonicalPath() + File.separator
- + "locator-" + this.locator2Port + ".log";
-
- this.locator1HttpPort = ports[2];
- this.locator1JmxPort = ports[3];
- this.locator1JmxHost = getIPLiteral();
- }
-
- @Override
- public final void postTearDownCacheTestCase() throws Exception {
- for (int i = 0; i < 4; i++) {
- getHost(0).getVM(i).invoke(SharedConfigurationTestUtils.cleanupLocator);
- }
- }
-
- @Category(FlakyTest.class) // GEODE-1519
- @Test
- public void testExportImportSharedConfiguration() throws IOException {
- // Start the Locator and wait for shared configuration to be available
- VM locatorAndMgr = getHost(0).getVM(3);
- Set<DistributedMember> normalMembers1 =
- (Set<DistributedMember>) locatorAndMgr.invoke(new SerializableCallable() {
- @Override
- public Object call() {
- final File locatorLogFile = new File(locator1LogFilePath);
-
- final Properties locatorProps = new Properties();
- locatorProps.setProperty(NAME, locator1Name);
- locatorProps.setProperty(MCAST_PORT, "0");
- locatorProps.setProperty(LOG_LEVEL, "config");
- locatorProps.setProperty(ENABLE_CLUSTER_CONFIGURATION, "true");
- locatorProps.setProperty(JMX_MANAGER, "true");
- locatorProps.setProperty(JMX_MANAGER_START, "true");
- locatorProps.setProperty(JMX_MANAGER_BIND_ADDRESS, String.valueOf(locator1JmxHost));
- locatorProps.setProperty(JMX_MANAGER_PORT, String.valueOf(locator1JmxPort));
- locatorProps.setProperty(HTTP_SERVICE_PORT, String.valueOf(locator1HttpPort));
-
- try {
- final InternalLocator locator = (InternalLocator) Locator
- .startLocatorAndDS(locator1Port, locatorLogFile, null, locatorProps);
-
- WaitCriterion wc = new WaitCriterion() {
- @Override
- public boolean done() {
- return locator.isSharedConfigurationRunning();
- }
-
- @Override
- public String description() {
- return "Waiting for shared configuration to be started";
- }
- };
- waitForCriterion(wc, TIMEOUT, INTERVAL, true);
-
- } catch (IOException e) {
- fail("Unable to create a locator with a shared configuration", e);
- }
-
- return getAllNormalMembers(CacheFactory.getAnyInstance());
- }
- });
-
- HeadlessGfsh gfsh = getDefaultShell();
- connect(locator1JmxHost, locator1JmxPort, locator1HttpPort, gfsh);
-
- // Create a cache in VM 1
- VM dataMember = getHost(0).getVM(1);
- normalMembers1 = (Set<DistributedMember>) dataMember.invoke(new SerializableCallable() {
- @Override
- public Object call() {
- Properties localProps = new Properties();
- localProps.setProperty(MCAST_PORT, "0");
- localProps.setProperty(LOCATORS, "localhost[" + locator1Port + "]");
- localProps.setProperty(GROUPS, groupName);
- localProps.setProperty(NAME, "DataMember");
- getSystem(localProps);
- Cache cache = getCache();
- assertNotNull(cache);
- return getAllNormalMembers(cache);
- }
- });
-
- // Create a JAR file
- this.classBuilder.writeJarFromName("DeployCommandsDUnitA", this.newDeployableJarFile);
-
- // Deploy the JAR
- CommandResult cmdResult =
- executeCommand("deploy --jar=" + this.newDeployableJarFile.getCanonicalPath());
- assertEquals(Result.Status.OK, cmdResult.getStatus());
-
- // Create the region1 on the group
- CommandStringBuilder commandStringBuilder = new CommandStringBuilder(CREATE_REGION);
- commandStringBuilder.addOption(CREATE_REGION__REGION, region1Name);
- commandStringBuilder.addOption(CREATE_REGION__REGIONSHORTCUT, "REPLICATE");
- commandStringBuilder.addOption(CREATE_REGION__STATISTICSENABLED, "true");
- commandStringBuilder.addOption(CREATE_REGION__GROUP, groupName);
-
- cmdResult = executeCommand(commandStringBuilder.toString());
- assertEquals(Result.Status.OK, cmdResult.getStatus());
-
- commandStringBuilder = new CommandStringBuilder(CREATE_REGION);
- commandStringBuilder.addOption(CREATE_REGION__REGION, region2Name);
- commandStringBuilder.addOption(CREATE_REGION__REGIONSHORTCUT, "PARTITION");
- commandStringBuilder.addOption(CREATE_REGION__STATISTICSENABLED, "true");
- cmdResult = executeCommand(commandStringBuilder.toString());
- assertEquals(Result.Status.OK, cmdResult.getStatus());
-
- // Alter runtime configuration
- commandStringBuilder = new CommandStringBuilder(ALTER_RUNTIME_CONFIG);
- commandStringBuilder.addOption(ALTER_RUNTIME_CONFIG__LOG__LEVEL, logLevel);
- commandStringBuilder.addOption(ALTER_RUNTIME_CONFIG__LOG__FILE__SIZE__LIMIT, "50");
- commandStringBuilder.addOption(ALTER_RUNTIME_CONFIG__ARCHIVE__DISK__SPACE__LIMIT, "32");
- commandStringBuilder.addOption(ALTER_RUNTIME_CONFIG__ARCHIVE__FILE__SIZE__LIMIT, "49");
- commandStringBuilder.addOption(ALTER_RUNTIME_CONFIG__STATISTIC__SAMPLE__RATE, "120");
- commandStringBuilder.addOption(ALTER_RUNTIME_CONFIG__STATISTIC__ARCHIVE__FILE,
- this.startArchiveFileName);
- commandStringBuilder.addOption(ALTER_RUNTIME_CONFIG__STATISTIC__SAMPLING__ENABLED, "true");
- commandStringBuilder.addOption(ALTER_RUNTIME_CONFIG__LOG__DISK__SPACE__LIMIT, "10");
- cmdResult = executeCommand(commandStringBuilder.getCommandString());
- String resultString = commandResultToString(cmdResult);
-
- getLogWriter().info("#SB Result\n");
- getLogWriter().info(resultString);
- assertEquals(true, cmdResult.getStatus().equals(Status.OK));
-
- commandStringBuilder = new CommandStringBuilder(STATUS_SHARED_CONFIG);
- cmdResult = executeCommand(commandStringBuilder.getCommandString());
- resultString = commandResultToString(cmdResult);
- getLogWriter().info("#SB Result\n");
- getLogWriter().info(resultString);
- assertEquals(Status.OK, cmdResult.getStatus());
-
- commandStringBuilder = new CommandStringBuilder(EXPORT_SHARED_CONFIG);
- commandStringBuilder.addOption(EXPORT_SHARED_CONFIG__FILE, this.sharedConfigZipFileName);
- cmdResult = executeCommand(commandStringBuilder.getCommandString());
- resultString = commandResultToString(cmdResult);
- getLogWriter().info("#SB Result\n");
- getLogWriter().info(resultString);
- assertEquals(Status.OK, cmdResult.getStatus());
-
- // Import into a running system should fail
- commandStringBuilder = new CommandStringBuilder(IMPORT_SHARED_CONFIG);
- commandStringBuilder.addOption(IMPORT_SHARED_CONFIG__ZIP, this.sharedConfigZipFileName);
- cmdResult = executeCommand(commandStringBuilder.getCommandString());
- assertEquals(Status.ERROR, cmdResult.getStatus());
-
- // Stop the data members and remove the shared configuration in the locator.
- dataMember.invoke(new SerializableCallable() {
- @Override
- public Object call() throws Exception {
- Cache cache = getCache();
- cache.close();
- assertTrue(cache.isClosed());
- disconnectFromDS();
- return null;
- }
- });
-
- // Clear shared configuration in this locator to test the import shared configuration
- locatorAndMgr.invoke(new SerializableCallable() {
- @Override
- public Object call() throws Exception {
- InternalLocator locator = InternalLocator.getLocator();
- SharedConfiguration sc = locator.getSharedConfiguration();
- assertNotNull(sc);
- sc.clearSharedConfiguration();
- return null;
- }
- });
-
- // Now execute import shared configuration
- // Now import the shared configuration and it should succeed.
- commandStringBuilder = new CommandStringBuilder(IMPORT_SHARED_CONFIG);
- commandStringBuilder.addOption(IMPORT_SHARED_CONFIG__ZIP, this.sharedConfigZipFileName);
- cmdResult = executeCommand(commandStringBuilder.getCommandString());
- assertEquals(Status.OK, cmdResult.getStatus());
-
- // Start a new locator , test if it has all the imported shared configuration artifacts
- VM newLocator = getHost(0).getVM(2);
- newLocator.invoke(new SerializableRunnable() {
- @Override
- public void run() {
- final File locatorLogFile = new File(locator2LogFilePath);
- final Properties locatorProps = new Properties();
- locatorProps.setProperty(NAME, locator2Name);
- locatorProps.setProperty(MCAST_PORT, "0");
- locatorProps.setProperty(LOG_LEVEL, "fine");
- locatorProps.setProperty(ENABLE_CLUSTER_CONFIGURATION, "true");
- locatorProps.setProperty(LOCATORS, "localhost[" + locator1Port + "]");
-
- try {
- final InternalLocator locator = (InternalLocator) Locator.startLocatorAndDS(locator2Port,
- locatorLogFile, null, locatorProps);
-
- WaitCriterion wc = new WaitCriterion() {
- @Override
- public boolean done() {
- return locator.isSharedConfigurationRunning();
- }
-
- @Override
- public String description() {
- return "Waiting for shared configuration to be started";
- }
- };
- waitForCriterion(wc, 5000, 500, true);
-
- SharedConfiguration sc = locator.getSharedConfiguration();
- assertNotNull(sc);
- Configuration groupConfig = sc.getConfiguration(groupName);
- assertNotNull(groupConfig);
- assertTrue(groupConfig.getCacheXmlContent().contains(region1Name));
-
- Configuration clusterConfig = sc.getConfiguration(SharedConfiguration.CLUSTER_CONFIG);
- assertNotNull(clusterConfig);
- assertTrue(clusterConfig.getCacheXmlContent().contains(region2Name));
- assertTrue(clusterConfig.getJarNames().contains(deployedJarName));
- assertTrue(clusterConfig.getGemfireProperties().getProperty(LOG_LEVEL).equals(logLevel));
- assertTrue(clusterConfig.getGemfireProperties().getProperty(STATISTIC_ARCHIVE_FILE)
- .equals(startArchiveFileName));
-
- } catch (IOException e) {
- fail("Unable to create a locator with a shared configuration", e);
- } catch (Exception e) {
- fail("Error occurred in cluster configuration service", e);
- }
- }
- });
- }
-}
http://git-wip-us.apache.org/repos/asf/geode/blob/e79e0103/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfig.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfig.java b/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfig.java
index 73ffbdd..c2d511d 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfig.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfig.java
@@ -22,7 +22,7 @@ import static org.assertj.core.api.Assertions.assertThat;
import org.apache.geode.cache.Cache;
import org.apache.geode.distributed.internal.InternalLocator;
-import org.apache.geode.distributed.internal.SharedConfiguration;
+import org.apache.geode.distributed.internal.ClusterConfigurationService;
import org.apache.geode.internal.ClassPathLoader;
import org.apache.geode.internal.JarClassLoader;
import org.apache.geode.internal.JarDeployer;
@@ -91,7 +91,7 @@ public class ClusterConfig implements Serializable {
// verify info exists in memeory
locator.invoke(() -> {
InternalLocator internalLocator = LocatorServerStartupRule.locatorStarter.locator;
- SharedConfiguration sc = internalLocator.getSharedConfiguration();
+ ClusterConfigurationService sc = internalLocator.getSharedConfiguration();
// verify no extra configs exist in memory
Set<String> actualGroupConfigs = sc.getEntireConfiguration().keySet();
http://git-wip-us.apache.org/repos/asf/geode/blob/e79e0103/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigurationServiceDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigurationServiceDUnitTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigurationServiceDUnitTest.java
new file mode 100644
index 0000000..74fb1418
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigurationServiceDUnitTest.java
@@ -0,0 +1,407 @@
+/*
+ * 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.internal.configuration;
+
+import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.DiskStoreFactory;
+import org.apache.geode.cache.RegionFactory;
+import org.apache.geode.cache.RegionShortcut;
+import org.apache.geode.distributed.Locator;
+import org.apache.geode.distributed.internal.ClusterConfigurationService;
+import org.apache.geode.distributed.internal.DM;
+import org.apache.geode.distributed.internal.InternalLocator;
+import org.apache.geode.distributed.internal.membership.InternalDistributedMember;
+import org.apache.geode.distributed.internal.tcpserver.TcpClient;
+import org.apache.geode.internal.cache.GemFireCacheImpl;
+import org.apache.geode.internal.cache.xmlcache.CacheXml;
+import org.apache.geode.management.internal.configuration.domain.Configuration;
+import org.apache.geode.management.internal.configuration.domain.XmlEntity;
+import org.apache.geode.management.internal.configuration.handlers.ConfigurationRequestHandler;
+import org.apache.geode.management.internal.configuration.messages.ConfigurationRequest;
+import org.apache.geode.management.internal.configuration.messages.ConfigurationResponse;
+import org.apache.geode.test.dunit.VM;
+import org.apache.geode.test.dunit.WaitCriterion;
+import org.apache.geode.test.dunit.cache.internal.JUnit4CacheTestCase;
+import org.apache.geode.test.junit.categories.DistributedTest;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.InetAddress;
+import java.util.*;
+
+import static org.apache.geode.distributed.ConfigurationProperties.*;
+import static org.apache.geode.internal.AvailablePortHelper.getRandomAvailableTCPPorts;
+import static org.apache.geode.test.dunit.Assert.*;
+import static org.apache.geode.test.dunit.Host.getHost;
+import static org.apache.geode.test.dunit.Wait.waitForCriterion;
+
+/**
+ * Tests the starting up of shared configuration, installation of
+ * {@link ConfigurationRequestHandler}
+ */
+@Category(DistributedTest.class)
+public class ClusterConfigurationServiceDUnitTest extends JUnit4CacheTestCase {
+
+ private static final String REGION1 = "region1";
+ private static final int TIMEOUT = 10000;
+ private static final int INTERVAL = 500;
+ private static final String DISKSTORENAME = "diskStore1";
+
+ @Override
+ public final void postSetUp() throws Exception {
+ disconnectAllFromDS();
+ }
+
+ @Override
+ public final void postTearDownCacheTestCase() throws Exception {
+ for (int i = 0; i < 4; i++) {
+ getHost(0).getVM(i).invoke(SharedConfigurationTestUtils.cleanupLocator);
+ }
+ }
+
+ @Test
+ public void testGetHostedLocatorsWithSharedConfiguration() throws Exception {
+ final VM locator1Vm = getHost(0).getVM(1);
+ final VM locator2Vm = getHost(0).getVM(2);
+
+ final String testName = getName();
+
+ final int[] ports = getRandomAvailableTCPPorts(3);
+
+ final int locator1Port = ports[0];
+ final String locator1Name = "locator1" + locator1Port;
+
+ locator1Vm.invoke(() -> {
+ final File locatorLogFile = new File(testName + "-locator-" + locator1Port + ".log");
+
+ final Properties locatorProps = new Properties();
+ locatorProps.setProperty(NAME, locator1Name);
+ locatorProps.setProperty(MCAST_PORT, "0");
+ locatorProps.setProperty(LOG_LEVEL, "fine");
+ locatorProps.setProperty(ENABLE_CLUSTER_CONFIGURATION, "true");
+
+ try {
+ final InternalLocator locator = (InternalLocator) Locator.startLocatorAndDS(locator1Port,
+ locatorLogFile, null, locatorProps);
+
+ WaitCriterion wc = new WaitCriterion() {
+ @Override
+ public boolean done() {
+ return locator.isSharedConfigurationRunning();
+ }
+
+ @Override
+ public String description() {
+ return "Waiting for shared configuration to be started";
+ }
+ };
+ waitForCriterion(wc, TIMEOUT, INTERVAL, true);
+
+ } catch (IOException e) {
+ fail("Unable to create a locator with a shared configuration", e);
+ }
+
+ GemFireCacheImpl cache = GemFireCacheImpl.getInstance();
+ InternalDistributedMember me = cache.getMyId();
+ DM dm = cache.getDistributionManager();
+
+ Map<InternalDistributedMember, Collection<String>> hostedLocators = dm.getAllHostedLocators();
+ assertFalse(hostedLocators.isEmpty());
+
+ Map<InternalDistributedMember, Collection<String>> hostedLocatorsWithSharedConfiguration =
+ dm.getAllHostedLocatorsWithSharedConfiguration();
+ assertFalse(hostedLocatorsWithSharedConfiguration.isEmpty());
+
+ assertNotNull(hostedLocators.get(me));
+ assertNotNull(hostedLocatorsWithSharedConfiguration.get(me));
+ return null;
+ });
+
+ final int locator2Port = ports[1];
+ final String locator2Name = "locator2" + locator2Port;
+
+ locator2Vm.invoke(() -> {
+ final File locatorLogFile = new File(testName + "-locator-" + locator2Port + ".log");
+
+ final Properties locatorProps = new Properties();
+ locatorProps.setProperty(NAME, locator2Name);
+ locatorProps.setProperty(MCAST_PORT, "0");
+ locatorProps.setProperty(LOG_LEVEL, "fine");
+ locatorProps.setProperty(LOCATORS, "localhost[" + locator1Port + "]");
+ locatorProps.setProperty(ENABLE_CLUSTER_CONFIGURATION, "false");
+
+ final InternalLocator locator = (InternalLocator) Locator.startLocatorAndDS(locator2Port,
+ locatorLogFile, null, locatorProps);
+
+ GemFireCacheImpl cache = GemFireCacheImpl.getInstance();
+ InternalDistributedMember me = cache.getMyId();
+ DM dm = cache.getDistributionManager();
+
+ Map<InternalDistributedMember, Collection<String>> hostedLocators = dm.getAllHostedLocators();
+ assertFalse(hostedLocators.isEmpty());
+
+ Map<InternalDistributedMember, Collection<String>> hostedLocatorsWithSharedConfiguration =
+ dm.getAllHostedLocatorsWithSharedConfiguration();
+ assertFalse(hostedLocatorsWithSharedConfiguration.isEmpty());
+ assertNotNull(hostedLocators.get(me));
+ assertNull(hostedLocatorsWithSharedConfiguration.get(me));
+ assertTrue(hostedLocators.size() == 2);
+ assertTrue(hostedLocatorsWithSharedConfiguration.size() == 1);
+
+ Set<InternalDistributedMember> locatorsWithSharedConfig =
+ hostedLocatorsWithSharedConfiguration.keySet();
+ Set<String> locatorsWithSharedConfigNames = new HashSet<String>();
+
+ for (InternalDistributedMember locatorWithSharedConfig : locatorsWithSharedConfig) {
+ locatorsWithSharedConfigNames.add(locatorWithSharedConfig.getName());
+ }
+ assertTrue(locatorsWithSharedConfigNames.contains(locator1Name));
+
+ return null;
+ });
+
+ locator1Vm.invoke(() -> {
+ InternalLocator locator = (InternalLocator) Locator.getLocator();
+ ClusterConfigurationService sharedConfig = locator.getSharedConfiguration();
+ sharedConfig.destroySharedConfiguration();
+ locator.stop();
+ return null;
+ });
+
+ locator2Vm.invoke(() -> {
+ GemFireCacheImpl cache = GemFireCacheImpl.getInstance();
+ InternalDistributedMember me = cache.getMyId();
+ DM dm = cache.getDistributionManager();
+ Map<InternalDistributedMember, Collection<String>> hostedLocators = dm.getAllHostedLocators();
+ assertFalse(hostedLocators.isEmpty());
+ Map<InternalDistributedMember, Collection<String>> hostedLocatorsWithSharedConfiguration =
+ dm.getAllHostedLocatorsWithSharedConfiguration();
+ assertTrue(hostedLocatorsWithSharedConfiguration.isEmpty());
+ assertNotNull(hostedLocators.get(me));
+ assertNull(hostedLocatorsWithSharedConfiguration.get(me));
+ assertTrue(hostedLocators.size() == 1);
+ assertTrue(hostedLocatorsWithSharedConfiguration.size() == 0);
+ return null;
+ });
+ }
+
+ @Test
+ public void testSharedConfigurationService() throws Exception {
+ // Start the Locator and wait for shared configuration to be available
+ final String testGroup = "G1";
+ final String clusterLogLevel = "error";
+ final String groupLogLevel = "fine";
+
+ final String testName = getName();
+
+ final VM locator1Vm = getHost(0).getVM(1);
+ final VM dataMemberVm = getHost(0).getVM(2);
+ final VM locator2Vm = getHost(0).getVM(3);
+
+ final int[] ports = getRandomAvailableTCPPorts(3);
+ final int locator1Port = ports[0];
+
+ locator1Vm.invoke(() -> {
+ final File locatorLogFile = new File(testName + "-locator-" + locator1Port + ".log");
+
+ final Properties locatorProps = new Properties();
+ locatorProps.setProperty(NAME, "Locator1");
+ locatorProps.setProperty(MCAST_PORT, "0");
+ locatorProps.setProperty(LOG_LEVEL, "info");
+ locatorProps.setProperty(ENABLE_CLUSTER_CONFIGURATION, "true");
+
+ try {
+ final InternalLocator locator = (InternalLocator) Locator.startLocatorAndDS(locator1Port,
+ locatorLogFile, null, locatorProps);
+
+ WaitCriterion wc = new WaitCriterion() {
+ @Override
+ public boolean done() {
+ return locator.isSharedConfigurationRunning();
+ }
+
+ @Override
+ public String description() {
+ return "Waiting for shared configuration to be started";
+ }
+ };
+ waitForCriterion(wc, TIMEOUT, INTERVAL, true);
+
+ } catch (IOException e) {
+ fail("Unable to create a locator with a shared configuration", e);
+ }
+ });
+
+ XmlEntity xmlEntity = dataMemberVm.invoke(() -> {
+ Properties localProps = new Properties();
+ localProps.setProperty(MCAST_PORT, "0");
+ localProps.setProperty(LOCATORS, "localhost[" + locator1Port + "]");
+ localProps.setProperty(GROUPS, testGroup);
+
+ getSystem(localProps);
+ Cache cache = getCache();
+ assertNotNull(cache);
+
+ DiskStoreFactory dsFactory = cache.createDiskStoreFactory();
+ File dsDir = new File("dsDir");
+ if (!dsDir.exists()) {
+ dsDir.mkdir();
+ }
+ dsFactory.setDiskDirs(new File[] {dsDir});
+ dsFactory.create(DISKSTORENAME);
+
+ RegionFactory regionFactory = getCache().createRegionFactory(RegionShortcut.REPLICATE);
+ regionFactory.create(REGION1);
+ return new XmlEntity(CacheXml.REGION, "name", REGION1);
+ });
+
+ locator1Vm.invoke(() -> {
+ ClusterConfigurationService sc = InternalLocator.getLocator().getSharedConfiguration();
+ sc.addXmlEntity(xmlEntity, new String[] {testGroup});
+
+ // Modify property and cache attributes
+ Properties clusterProperties = new Properties();
+ clusterProperties.setProperty(LOG_LEVEL, clusterLogLevel);
+ XmlEntity cacheEntity = XmlEntity.builder().withType(CacheXml.CACHE).build();
+ Map<String, String> cacheAttributes = new HashMap<String, String>();
+ cacheAttributes.put(CacheXml.COPY_ON_READ, "true");
+
+ sc.modifyXmlAndProperties(clusterProperties, cacheEntity, null);
+
+ clusterProperties.setProperty(LOG_LEVEL, groupLogLevel);
+ sc.modifyXmlAndProperties(clusterProperties, cacheEntity, new String[] {testGroup});
+
+ // Add a jar
+ byte[][] jarBytes = new byte[1][];
+ jarBytes[0] = "Hello".getBytes();
+ assertTrue(sc.addJarsToThisLocator(new String[] {"foo.jar"}, jarBytes, null));
+
+ // Add a jar for the group
+ jarBytes = new byte[1][];
+ jarBytes[0] = "Hello".getBytes();
+ assertTrue(
+ sc.addJarsToThisLocator(new String[] {"bar.jar"}, jarBytes, new String[] {testGroup}));
+ });
+
+ final int locator2Port = ports[1];
+
+ // Create another locator in VM2
+ locator2Vm.invoke(() -> {
+ final File locatorLogFile = new File(testName + "-locator-" + locator2Port + ".log");
+
+ final Properties locatorProps = new Properties();
+ locatorProps.setProperty(NAME, "Locator2");
+ locatorProps.setProperty(MCAST_PORT, "0");
+ locatorProps.setProperty(LOG_LEVEL, "info");
+ locatorProps.setProperty(ENABLE_CLUSTER_CONFIGURATION, "true");
+ locatorProps.setProperty(LOCATORS, "localhost[" + locator1Port + "]");
+
+ try {
+ final InternalLocator locator = (InternalLocator) Locator.startLocatorAndDS(locator2Port,
+ locatorLogFile, null, locatorProps);
+
+ WaitCriterion wc = new WaitCriterion() {
+ @Override
+ public boolean done() {
+ return locator.isSharedConfigurationRunning();
+ }
+
+ @Override
+ public String description() {
+ return "Waiting for shared configuration to be started";
+ }
+ };
+ waitForCriterion(wc, TIMEOUT, INTERVAL, true);
+
+ } catch (IOException e) {
+ fail("Unable to create a locator with a shared configuration", e);
+ }
+
+ InternalLocator locator = (InternalLocator) Locator.getLocator();
+ ClusterConfigurationService sharedConfig = locator.getSharedConfiguration();
+ Map<String, Configuration> entireConfiguration = sharedConfig.getEntireConfiguration();
+ Configuration clusterConfig =
+ entireConfiguration.get(ClusterConfigurationService.CLUSTER_CONFIG);
+ assertNotNull(clusterConfig);
+ assertNotNull(clusterConfig.getJarNames());
+ assertTrue(clusterConfig.getJarNames().contains("foo.jar"));
+ assertTrue(
+ clusterConfig.getGemfireProperties().getProperty(LOG_LEVEL).equals(clusterLogLevel));
+ assertNotNull(clusterConfig.getCacheXmlContent());
+
+ Configuration testGroupConfiguration = entireConfiguration.get(testGroup);
+ assertNotNull(testGroupConfiguration);
+ assertNotNull(testGroupConfiguration.getJarNames());
+ assertTrue(testGroupConfiguration.getJarNames().contains("bar.jar"));
+ assertTrue(testGroupConfiguration.getGemfireProperties().getProperty(LOG_LEVEL)
+ .equals(groupLogLevel));
+ assertNotNull(testGroupConfiguration.getCacheXmlContent());
+ assertTrue(testGroupConfiguration.getCacheXmlContent().contains(REGION1));
+
+ Map<String, byte[]> jarData =
+ sharedConfig.getAllJarsFromThisLocator(entireConfiguration.keySet());
+ String[] jarNames = jarData.keySet().stream().toArray(String[]::new);
+ byte[][] jarBytes = jarData.values().toArray(new byte[jarNames.length][]);
+
+ assertNotNull(jarNames);
+ assertNotNull(jarBytes);
+
+ sharedConfig.deleteXmlEntity(new XmlEntity(CacheXml.REGION, "name", REGION1),
+ new String[] {testGroup});
+ sharedConfig.removeJars(new String[] {"foo.jar"}, null);
+ sharedConfig.removeJars(null, null);
+ });
+
+ dataMemberVm.invoke(() -> {
+ Set<String> groups = new HashSet<String>();
+ groups.add(testGroup);
+ ConfigurationRequest configRequest = new ConfigurationRequest(groups);
+ ConfigurationResponse configResponse = (ConfigurationResponse) new TcpClient()
+ .requestToServer(InetAddress.getByName("localhost"), locator2Port, configRequest, 1000);
+ assertNotNull(configResponse);
+
+ Map<String, Configuration> requestedConfiguration =
+ configResponse.getRequestedConfiguration();
+ Configuration clusterConfiguration =
+ requestedConfiguration.get(ClusterConfigurationService.CLUSTER_CONFIG);
+ assertNotNull(clusterConfiguration);
+ assertTrue(configResponse.getJarNames().length == 0);
+ assertTrue(configResponse.getJars().length == 0);
+ assertTrue(clusterConfiguration.getJarNames().isEmpty());
+ assertTrue(clusterConfiguration.getGemfireProperties().getProperty(LOG_LEVEL)
+ .equals(clusterLogLevel));
+
+ Configuration testGroupConfiguration = requestedConfiguration.get(testGroup);
+ assertNotNull(testGroupConfiguration);
+ assertFalse(testGroupConfiguration.getCacheXmlContent().contains(REGION1));
+ assertTrue(testGroupConfiguration.getJarNames().isEmpty());
+ assertTrue(testGroupConfiguration.getGemfireProperties().getProperty(LOG_LEVEL)
+ .equals(groupLogLevel));
+
+ GemFireCacheImpl cache = (GemFireCacheImpl) getCache();
+ Map<InternalDistributedMember, Collection<String>> locatorsWithSharedConfiguration =
+ cache.getDistributionManager().getAllHostedLocatorsWithSharedConfiguration();
+ assertFalse(locatorsWithSharedConfiguration.isEmpty());
+ assertTrue(locatorsWithSharedConfiguration.size() == 2);
+ Set<InternalDistributedMember> locatorMembers = locatorsWithSharedConfiguration.keySet();
+ for (InternalDistributedMember locatorMember : locatorMembers) {
+ System.out.println(locatorMember);
+ }
+ return null;
+ });
+ }
+}
http://git-wip-us.apache.org/repos/asf/geode/blob/e79e0103/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigurationServiceUsingDirDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigurationServiceUsingDirDUnitTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigurationServiceUsingDirDUnitTest.java
new file mode 100644
index 0000000..fff7681
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigurationServiceUsingDirDUnitTest.java
@@ -0,0 +1,334 @@
+/*
+ * 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.internal.configuration;
+
+import static java.util.concurrent.TimeUnit.MINUTES;
+import static java.util.stream.Collectors.joining;
+import static org.apache.geode.distributed.ConfigurationProperties.ENABLE_CLUSTER_CONFIGURATION;
+import static org.apache.geode.distributed.ConfigurationProperties.LOAD_CLUSTER_CONFIGURATION_FROM_DIR;
+import static org.apache.geode.distributed.ConfigurationProperties.LOCATORS;
+import static org.apache.geode.distributed.ConfigurationProperties.LOG_FILE;
+import static org.apache.geode.distributed.ConfigurationProperties.MCAST_PORT;
+import static org.apache.geode.distributed.ConfigurationProperties.NAME;
+import static org.apache.geode.distributed.ConfigurationProperties.USE_CLUSTER_CONFIGURATION;
+import static org.apache.geode.internal.AvailablePortHelper.getRandomAvailableTCPPorts;
+import static org.apache.geode.test.dunit.Host.getHost;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+import com.jayway.awaitility.Awaitility;
+import com.jayway.awaitility.core.ConditionFactory;
+import org.apache.geode.cache.Region;
+import org.apache.geode.distributed.Locator;
+import org.apache.geode.distributed.internal.ClusterConfigurationService;
+import org.apache.geode.distributed.internal.InternalLocator;
+import org.apache.geode.test.dunit.VM;
+import org.apache.geode.test.dunit.cache.internal.JUnit4CacheTestCase;
+import org.apache.geode.test.junit.categories.DistributedTest;
+import org.apache.geode.test.junit.categories.FlakyTest;
+import org.apache.geode.util.test.TestUtil;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.nio.file.StandardCopyOption;
+import java.util.Arrays;
+import java.util.Properties;
+
+@Category({DistributedTest.class, FlakyTest.class}) // GEODE-1165
+public class ClusterConfigurationServiceUsingDirDUnitTest extends JUnit4CacheTestCase {
+
+ @Override
+ public final void preTearDownCacheTestCase() throws Exception {
+ for (int i = 0; i < 2; i++) {
+ VM vm = getHost(0).getVM(i);
+ vm.invoke("Removing shared configuration", () -> {
+ InternalLocator locator = InternalLocator.getLocator();
+ if (locator == null) {
+ return;
+ }
+
+ ClusterConfigurationService sharedConfig = locator.getSharedConfiguration();
+ if (sharedConfig != null) {
+ sharedConfig.destroySharedConfiguration();
+ }
+ });
+ }
+ }
+
+ @Test
+ public void basicClusterConfigDirWithOneLocator() throws Exception {
+ final int[] ports = getRandomAvailableTCPPorts(1);
+ final int locatorCount = ports.length;
+
+ for (int i = 0; i < locatorCount; i++) {
+ VM vm = getHost(0).getVM(i);
+ copyClusterXml(vm, "cluster-region.xml");
+ startLocator(vm, i, ports);
+ waitForSharedConfiguration(vm);
+ }
+
+ for (int i = 2; i < 4; i++) {
+ VM vm = getHost(0).getVM(i);
+ restartCache(vm, i, ports);
+
+ vm.invoke("Checking for region presence", () -> {
+ await().until(() -> getRootRegion("newReplicatedRegion") != null);
+ });
+ }
+ }
+
+ @Test
+ public void basicClusterConfigDirWithTwoLocators() throws Exception {
+ final int[] ports = getRandomAvailableTCPPorts(2);
+ final int locatorCount = ports.length;
+
+ for (int i = 0; i < locatorCount; i++) {
+ VM vm = getHost(0).getVM(i);
+ copyClusterXml(vm, "cluster-region.xml");
+ startLocator(vm, i, ports);
+ waitForSharedConfiguration(vm);
+ }
+
+ for (int i = 2; i < 4; i++) {
+ VM vm = getHost(0).getVM(i);
+ restartCache(vm, i, ports);
+
+ vm.invoke("Checking for region presence", () -> {
+ await().until(() -> getRootRegion("newReplicatedRegion") != null);
+ });
+ }
+ }
+
+ @Test
+ public void updateClusterConfigDirWithTwoLocatorsNoRollingServerRestart() throws Exception {
+ final int[] ports = getRandomAvailableTCPPorts(2);
+ final int locatorCount = ports.length;
+
+ for (int i = 0; i < locatorCount; i++) {
+ VM vm = getHost(0).getVM(i);
+ copyClusterXml(vm, "cluster-empty.xml");
+ startLocator(vm, i, ports);
+ waitForSharedConfiguration(vm);
+ }
+
+ for (int i = 2; i < 4; i++) {
+ VM vm = getHost(0).getVM(i);
+ restartCache(vm, i, ports);
+
+ vm.invoke("Checking for region absence", () -> {
+ Region r = getRootRegion("newReplicatedRegion");
+ assertNull("Region does exist", r);
+ });
+ }
+
+ // Shut down the locators in reverse order to how we will start them up in the next step.
+ // Unless we start them asynchronously, the older one will want to wait for a new diskstore
+ // to become available and will time out.
+ for (int i = locatorCount; i > 0; i--) {
+ VM vm = getHost(0).getVM(i - 1);
+ stopLocator(vm);
+ }
+
+ for (int i = 0; i < locatorCount; i++) {
+ VM vm = getHost(0).getVM(i);
+ copyClusterXml(vm, "cluster-region.xml");
+ startLocator(vm, i, ports);
+ waitForSharedConfiguration(vm);
+ }
+
+ for (int i = 2; i < 4; i++) {
+ VM vm = getHost(0).getVM(i);
+ vm.invoke(() -> disconnectFromDS());
+ }
+
+ for (int i = 2; i < 4; i++) {
+ VM vm = getHost(0).getVM(i);
+ restartCache(vm, i, ports);
+
+ vm.invoke("Checking for region presence", () -> {
+ await().until(() -> getRootRegion("newReplicatedRegion") != null);
+ });
+ }
+ }
+
+ @Test
+ public void updateClusterConfigDirWithTwoLocatorsAndRollingServerRestart() throws Exception {
+ final int[] ports = getRandomAvailableTCPPorts(2);
+ final int locatorCount = ports.length;
+
+ for (int i = 0; i < locatorCount; i++) {
+ VM vm = getHost(0).getVM(i);
+ copyClusterXml(vm, "cluster-empty.xml");
+ startLocator(vm, i, ports);
+ waitForSharedConfiguration(vm);
+ }
+
+ for (int i = 2; i < 4; i++) {
+ VM vm = getHost(0).getVM(i);
+ restartCache(vm, i, ports);
+
+ vm.invoke("Checking for region absence", () -> {
+ Region r = getRootRegion("newReplicatedRegion");
+ assertNull("Region does exist", r);
+ });
+ }
+
+ // Shut down the locators in reverse order to how we will start them up in the next step.
+ // Unless we start them asynchronously, the older one will want to wait for a new diskstore
+ // to become available and will time out.
+ for (int i = locatorCount; i > 0; i--) {
+ VM vm = getHost(0).getVM(i - 1);
+ stopLocator(vm);
+ }
+
+ for (int i = 0; i < locatorCount; i++) {
+ VM vm = getHost(0).getVM(i);
+ copyClusterXml(vm, "cluster-region.xml");
+ startLocator(vm, i, ports);
+ waitForSharedConfiguration(vm);
+ }
+
+ for (int i = 2; i < 4; i++) {
+ VM vm = getHost(0).getVM(i);
+ restartCache(vm, i, ports);
+
+ vm.invoke("Checking for region presence", () -> {
+ await().until(() -> getRootRegion("newReplicatedRegion") != null);
+ });
+ }
+ }
+
+ @Test
+ public void updateClusterConfigDirWithTwoLocatorsRollingRestartAndRollingServerRestart()
+ throws Exception {
+ final int[] ports = getRandomAvailableTCPPorts(2);
+ final int locatorCount = ports.length;
+
+ for (int i = 0; i < locatorCount; i++) {
+ VM vm = getHost(0).getVM(i);
+ copyClusterXml(vm, "cluster-empty.xml");
+ startLocator(vm, i, ports);
+ waitForSharedConfiguration(vm);
+ }
+
+ for (int i = 2; i < 4; i++) {
+ VM vm = getHost(0).getVM(i);
+ restartCache(vm, i, ports);
+
+ vm.invoke("Checking for region absence", () -> {
+ Region r = getRootRegion("newReplicatedRegion");
+ assertNull("Region does exist", r);
+ });
+ }
+
+ // Roll the locators
+ for (int i = locatorCount - 1; i >= 0; i--) {
+ VM vm = getHost(0).getVM(i);
+ stopLocator(vm);
+ copyClusterXml(vm, "cluster-region.xml");
+ startLocator(vm, i, ports);
+ waitForSharedConfiguration(vm);
+ }
+
+ // Roll the servers
+ for (int i = 2; i < 4; i++) {
+ VM vm = getHost(0).getVM(i);
+ restartCache(vm, i, ports);
+
+ vm.invoke("Checking for region presence", () -> {
+ await().until(() -> getRootRegion("newReplicatedRegion") != null);
+ });
+ }
+ }
+
+ private void copyClusterXml(final VM vm, final String clusterXml) {
+ vm.invoke("Copying new cluster.xml from " + clusterXml, () -> {
+ String clusterXmlPath =
+ TestUtil.getResourcePath(ClusterConfigurationServiceUsingDirDUnitTest.class, clusterXml);
+ InputStream cacheXml = new FileInputStream(clusterXmlPath);
+ assertNotNull("Could not create InputStream from " + clusterXmlPath, cacheXml);
+ Files.createDirectories(Paths.get("cluster_config", "cluster"));
+ Files.copy(cacheXml, Paths.get("cluster_config", "cluster", "cluster.xml"),
+ StandardCopyOption.REPLACE_EXISTING);
+ });
+ }
+
+ private void startLocator(final VM vm, final int i, final int[] locatorPorts) {
+ vm.invoke("Creating locator on " + vm, () -> {
+ final String locatorName = "locator" + i;
+ final File logFile = new File("locator-" + i + ".log");
+ final Properties props = new Properties();
+ props.setProperty(NAME, locatorName);
+ props.setProperty(MCAST_PORT, "0");
+ props.setProperty(ENABLE_CLUSTER_CONFIGURATION, "true");
+ props.setProperty(LOAD_CLUSTER_CONFIGURATION_FROM_DIR, "true");
+
+ if (locatorPorts.length > 1) {
+ int otherLocatorPort = locatorPorts[(i + 1) % locatorPorts.length];
+ props.setProperty(LOCATORS, "localhost[" + otherLocatorPort + "]");
+ }
+
+ Locator.startLocatorAndDS(locatorPorts[i], logFile, props);
+ });
+ }
+
+ private void waitForSharedConfiguration(final VM vm) {
+ vm.invoke("Waiting for shared configuration", () -> {
+ final InternalLocator locator = InternalLocator.getLocator();
+ await().until(() -> {
+ return locator.isSharedConfigurationRunning();
+ });
+ });
+ }
+
+ private void stopLocator(final VM vm) {
+ vm.invoke("Stopping locator on " + vm, () -> {
+ InternalLocator locator = InternalLocator.getLocator();
+ assertNotNull("No locator found", locator);
+ locator.stop();
+ disconnectAllFromDS();
+ });
+ }
+
+ private void restartCache(final VM vm, final int i, final int[] locatorPorts) {
+ vm.invoke("Creating cache on VM " + i, () -> {
+ disconnectFromDS();
+
+ final Properties props = new Properties();
+ props.setProperty(NAME, "member" + i);
+ props.setProperty(MCAST_PORT, "0");
+ props.setProperty(LOCATORS, getLocatorStr(locatorPorts));
+ props.setProperty(LOG_FILE, "server-" + i + ".log");
+ props.setProperty(USE_CLUSTER_CONFIGURATION, "true");
+ props.setProperty(ENABLE_CLUSTER_CONFIGURATION, "true");
+
+ getSystem(props);
+ getCache();
+ });
+ }
+
+ private String getLocatorStr(final int[] locatorPorts) {
+ return Arrays.stream(locatorPorts).mapToObj(p -> "localhost[" + p + "]").collect(joining(","));
+ }
+
+ private ConditionFactory await() {
+ return Awaitility.await().atMost(2, MINUTES);
+ }
+}
http://git-wip-us.apache.org/repos/asf/geode/blob/e79e0103/geode-core/src/test/java/org/apache/geode/management/internal/configuration/SharedConfigurationDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/configuration/SharedConfigurationDUnitTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/configuration/SharedConfigurationDUnitTest.java
deleted file mode 100644
index b310c50..0000000
--- a/geode-core/src/test/java/org/apache/geode/management/internal/configuration/SharedConfigurationDUnitTest.java
+++ /dev/null
@@ -1,407 +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.internal.configuration;
-
-import org.apache.geode.cache.Cache;
-import org.apache.geode.cache.DiskStoreFactory;
-import org.apache.geode.cache.RegionFactory;
-import org.apache.geode.cache.RegionShortcut;
-import org.apache.geode.distributed.Locator;
-import org.apache.geode.distributed.internal.DM;
-import org.apache.geode.distributed.internal.InternalLocator;
-import org.apache.geode.distributed.internal.SharedConfiguration;
-import org.apache.geode.distributed.internal.membership.InternalDistributedMember;
-import org.apache.geode.distributed.internal.tcpserver.TcpClient;
-import org.apache.geode.internal.cache.GemFireCacheImpl;
-import org.apache.geode.internal.cache.xmlcache.CacheXml;
-import org.apache.geode.management.internal.configuration.domain.Configuration;
-import org.apache.geode.management.internal.configuration.domain.XmlEntity;
-import org.apache.geode.management.internal.configuration.handlers.ConfigurationRequestHandler;
-import org.apache.geode.management.internal.configuration.messages.ConfigurationRequest;
-import org.apache.geode.management.internal.configuration.messages.ConfigurationResponse;
-import org.apache.geode.test.dunit.SerializableCallable;
-import org.apache.geode.test.dunit.VM;
-import org.apache.geode.test.dunit.WaitCriterion;
-import org.apache.geode.test.dunit.cache.internal.JUnit4CacheTestCase;
-import org.apache.geode.test.junit.categories.DistributedTest;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-
-import java.io.File;
-import java.io.IOException;
-import java.net.InetAddress;
-import java.util.*;
-
-import static org.apache.geode.distributed.ConfigurationProperties.*;
-import static org.apache.geode.internal.AvailablePortHelper.getRandomAvailableTCPPorts;
-import static org.apache.geode.test.dunit.Assert.*;
-import static org.apache.geode.test.dunit.Host.getHost;
-import static org.apache.geode.test.dunit.Wait.waitForCriterion;
-
-/**
- * Tests the starting up of shared configuration, installation of
- * {@link ConfigurationRequestHandler}
- */
-@Category(DistributedTest.class)
-public class SharedConfigurationDUnitTest extends JUnit4CacheTestCase {
-
- private static final String REGION1 = "region1";
- private static final int TIMEOUT = 10000;
- private static final int INTERVAL = 500;
- private static final String DISKSTORENAME = "diskStore1";
-
- @Override
- public final void postSetUp() throws Exception {
- disconnectAllFromDS();
- }
-
- @Override
- public final void postTearDownCacheTestCase() throws Exception {
- for (int i = 0; i < 4; i++) {
- getHost(0).getVM(i).invoke(SharedConfigurationTestUtils.cleanupLocator);
- }
- }
-
- @Test
- public void testGetHostedLocatorsWithSharedConfiguration() throws Exception {
- final VM locator1Vm = getHost(0).getVM(1);
- final VM locator2Vm = getHost(0).getVM(2);
-
- final String testName = getName();
-
- final int[] ports = getRandomAvailableTCPPorts(3);
-
- final int locator1Port = ports[0];
- final String locator1Name = "locator1" + locator1Port;
-
- locator1Vm.invoke(() -> {
- final File locatorLogFile = new File(testName + "-locator-" + locator1Port + ".log");
-
- final Properties locatorProps = new Properties();
- locatorProps.setProperty(NAME, locator1Name);
- locatorProps.setProperty(MCAST_PORT, "0");
- locatorProps.setProperty(LOG_LEVEL, "fine");
- locatorProps.setProperty(ENABLE_CLUSTER_CONFIGURATION, "true");
-
- try {
- final InternalLocator locator = (InternalLocator) Locator.startLocatorAndDS(locator1Port,
- locatorLogFile, null, locatorProps);
-
- WaitCriterion wc = new WaitCriterion() {
- @Override
- public boolean done() {
- return locator.isSharedConfigurationRunning();
- }
-
- @Override
- public String description() {
- return "Waiting for shared configuration to be started";
- }
- };
- waitForCriterion(wc, TIMEOUT, INTERVAL, true);
-
- } catch (IOException e) {
- fail("Unable to create a locator with a shared configuration", e);
- }
-
- GemFireCacheImpl cache = GemFireCacheImpl.getInstance();
- InternalDistributedMember me = cache.getMyId();
- DM dm = cache.getDistributionManager();
-
- Map<InternalDistributedMember, Collection<String>> hostedLocators = dm.getAllHostedLocators();
- assertFalse(hostedLocators.isEmpty());
-
- Map<InternalDistributedMember, Collection<String>> hostedLocatorsWithSharedConfiguration =
- dm.getAllHostedLocatorsWithSharedConfiguration();
- assertFalse(hostedLocatorsWithSharedConfiguration.isEmpty());
-
- assertNotNull(hostedLocators.get(me));
- assertNotNull(hostedLocatorsWithSharedConfiguration.get(me));
- return null;
- });
-
- final int locator2Port = ports[1];
- final String locator2Name = "locator2" + locator2Port;
-
- locator2Vm.invoke(() -> {
- final File locatorLogFile = new File(testName + "-locator-" + locator2Port + ".log");
-
- final Properties locatorProps = new Properties();
- locatorProps.setProperty(NAME, locator2Name);
- locatorProps.setProperty(MCAST_PORT, "0");
- locatorProps.setProperty(LOG_LEVEL, "fine");
- locatorProps.setProperty(LOCATORS, "localhost[" + locator1Port + "]");
- locatorProps.setProperty(ENABLE_CLUSTER_CONFIGURATION, "false");
-
- final InternalLocator locator = (InternalLocator) Locator.startLocatorAndDS(locator2Port,
- locatorLogFile, null, locatorProps);
-
- GemFireCacheImpl cache = GemFireCacheImpl.getInstance();
- InternalDistributedMember me = cache.getMyId();
- DM dm = cache.getDistributionManager();
-
- Map<InternalDistributedMember, Collection<String>> hostedLocators = dm.getAllHostedLocators();
- assertFalse(hostedLocators.isEmpty());
-
- Map<InternalDistributedMember, Collection<String>> hostedLocatorsWithSharedConfiguration =
- dm.getAllHostedLocatorsWithSharedConfiguration();
- assertFalse(hostedLocatorsWithSharedConfiguration.isEmpty());
- assertNotNull(hostedLocators.get(me));
- assertNull(hostedLocatorsWithSharedConfiguration.get(me));
- assertTrue(hostedLocators.size() == 2);
- assertTrue(hostedLocatorsWithSharedConfiguration.size() == 1);
-
- Set<InternalDistributedMember> locatorsWithSharedConfig =
- hostedLocatorsWithSharedConfiguration.keySet();
- Set<String> locatorsWithSharedConfigNames = new HashSet<String>();
-
- for (InternalDistributedMember locatorWithSharedConfig : locatorsWithSharedConfig) {
- locatorsWithSharedConfigNames.add(locatorWithSharedConfig.getName());
- }
- assertTrue(locatorsWithSharedConfigNames.contains(locator1Name));
-
- return null;
- });
-
- locator1Vm.invoke(() -> {
- InternalLocator locator = (InternalLocator) Locator.getLocator();
- SharedConfiguration sharedConfig = locator.getSharedConfiguration();
- sharedConfig.destroySharedConfiguration();
- locator.stop();
- return null;
- });
-
- locator2Vm.invoke(() -> {
- GemFireCacheImpl cache = GemFireCacheImpl.getInstance();
- InternalDistributedMember me = cache.getMyId();
- DM dm = cache.getDistributionManager();
- Map<InternalDistributedMember, Collection<String>> hostedLocators = dm.getAllHostedLocators();
- assertFalse(hostedLocators.isEmpty());
- Map<InternalDistributedMember, Collection<String>> hostedLocatorsWithSharedConfiguration =
- dm.getAllHostedLocatorsWithSharedConfiguration();
- assertTrue(hostedLocatorsWithSharedConfiguration.isEmpty());
- assertNotNull(hostedLocators.get(me));
- assertNull(hostedLocatorsWithSharedConfiguration.get(me));
- assertTrue(hostedLocators.size() == 1);
- assertTrue(hostedLocatorsWithSharedConfiguration.size() == 0);
- return null;
- });
- }
-
- @Test
- public void testSharedConfigurationService() throws Exception {
- // Start the Locator and wait for shared configuration to be available
- final String testGroup = "G1";
- final String clusterLogLevel = "error";
- final String groupLogLevel = "fine";
-
- final String testName = getName();
-
- final VM locator1Vm = getHost(0).getVM(1);
- final VM dataMemberVm = getHost(0).getVM(2);
- final VM locator2Vm = getHost(0).getVM(3);
-
- final int[] ports = getRandomAvailableTCPPorts(3);
- final int locator1Port = ports[0];
-
- locator1Vm.invoke(() -> {
- final File locatorLogFile = new File(testName + "-locator-" + locator1Port + ".log");
-
- final Properties locatorProps = new Properties();
- locatorProps.setProperty(NAME, "Locator1");
- locatorProps.setProperty(MCAST_PORT, "0");
- locatorProps.setProperty(LOG_LEVEL, "info");
- locatorProps.setProperty(ENABLE_CLUSTER_CONFIGURATION, "true");
-
- try {
- final InternalLocator locator = (InternalLocator) Locator.startLocatorAndDS(locator1Port,
- locatorLogFile, null, locatorProps);
-
- WaitCriterion wc = new WaitCriterion() {
- @Override
- public boolean done() {
- return locator.isSharedConfigurationRunning();
- }
-
- @Override
- public String description() {
- return "Waiting for shared configuration to be started";
- }
- };
- waitForCriterion(wc, TIMEOUT, INTERVAL, true);
-
- } catch (IOException e) {
- fail("Unable to create a locator with a shared configuration", e);
- }
- });
-
- XmlEntity xmlEntity = dataMemberVm.invoke(() -> {
- Properties localProps = new Properties();
- localProps.setProperty(MCAST_PORT, "0");
- localProps.setProperty(LOCATORS, "localhost[" + locator1Port + "]");
- localProps.setProperty(GROUPS, testGroup);
-
- getSystem(localProps);
- Cache cache = getCache();
- assertNotNull(cache);
-
- DiskStoreFactory dsFactory = cache.createDiskStoreFactory();
- File dsDir = new File("dsDir");
- if (!dsDir.exists()) {
- dsDir.mkdir();
- }
- dsFactory.setDiskDirs(new File[] {dsDir});
- dsFactory.create(DISKSTORENAME);
-
- RegionFactory regionFactory = getCache().createRegionFactory(RegionShortcut.REPLICATE);
- regionFactory.create(REGION1);
- return new XmlEntity(CacheXml.REGION, "name", REGION1);
- });
-
- locator1Vm.invoke(() -> {
- SharedConfiguration sc = InternalLocator.getLocator().getSharedConfiguration();
- sc.addXmlEntity(xmlEntity, new String[] {testGroup});
-
- // Modify property and cache attributes
- Properties clusterProperties = new Properties();
- clusterProperties.setProperty(LOG_LEVEL, clusterLogLevel);
- XmlEntity cacheEntity = XmlEntity.builder().withType(CacheXml.CACHE).build();
- Map<String, String> cacheAttributes = new HashMap<String, String>();
- cacheAttributes.put(CacheXml.COPY_ON_READ, "true");
-
- sc.modifyXmlAndProperties(clusterProperties, cacheEntity, null);
-
- clusterProperties.setProperty(LOG_LEVEL, groupLogLevel);
- sc.modifyXmlAndProperties(clusterProperties, cacheEntity, new String[] {testGroup});
-
- // Add a jar
- byte[][] jarBytes = new byte[1][];
- jarBytes[0] = "Hello".getBytes();
- assertTrue(sc.addJarsToThisLocator(new String[] {"foo.jar"}, jarBytes, null));
-
- // Add a jar for the group
- jarBytes = new byte[1][];
- jarBytes[0] = "Hello".getBytes();
- assertTrue(
- sc.addJarsToThisLocator(new String[] {"bar.jar"}, jarBytes, new String[] {testGroup}));
- });
-
- final int locator2Port = ports[1];
-
- // Create another locator in VM2
- locator2Vm.invoke(() -> {
- final File locatorLogFile = new File(testName + "-locator-" + locator2Port + ".log");
-
- final Properties locatorProps = new Properties();
- locatorProps.setProperty(NAME, "Locator2");
- locatorProps.setProperty(MCAST_PORT, "0");
- locatorProps.setProperty(LOG_LEVEL, "info");
- locatorProps.setProperty(ENABLE_CLUSTER_CONFIGURATION, "true");
- locatorProps.setProperty(LOCATORS, "localhost[" + locator1Port + "]");
-
- try {
- final InternalLocator locator = (InternalLocator) Locator.startLocatorAndDS(locator2Port,
- locatorLogFile, null, locatorProps);
-
- WaitCriterion wc = new WaitCriterion() {
- @Override
- public boolean done() {
- return locator.isSharedConfigurationRunning();
- }
-
- @Override
- public String description() {
- return "Waiting for shared configuration to be started";
- }
- };
- waitForCriterion(wc, TIMEOUT, INTERVAL, true);
-
- } catch (IOException e) {
- fail("Unable to create a locator with a shared configuration", e);
- }
-
- InternalLocator locator = (InternalLocator) Locator.getLocator();
- SharedConfiguration sharedConfig = locator.getSharedConfiguration();
- Map<String, Configuration> entireConfiguration = sharedConfig.getEntireConfiguration();
- Configuration clusterConfig = entireConfiguration.get(SharedConfiguration.CLUSTER_CONFIG);
- assertNotNull(clusterConfig);
- assertNotNull(clusterConfig.getJarNames());
- assertTrue(clusterConfig.getJarNames().contains("foo.jar"));
- assertTrue(
- clusterConfig.getGemfireProperties().getProperty(LOG_LEVEL).equals(clusterLogLevel));
- assertNotNull(clusterConfig.getCacheXmlContent());
-
- Configuration testGroupConfiguration = entireConfiguration.get(testGroup);
- assertNotNull(testGroupConfiguration);
- assertNotNull(testGroupConfiguration.getJarNames());
- assertTrue(testGroupConfiguration.getJarNames().contains("bar.jar"));
- assertTrue(testGroupConfiguration.getGemfireProperties().getProperty(LOG_LEVEL)
- .equals(groupLogLevel));
- assertNotNull(testGroupConfiguration.getCacheXmlContent());
- assertTrue(testGroupConfiguration.getCacheXmlContent().contains(REGION1));
-
- Map<String, byte[]> jarData =
- sharedConfig.getAllJarsFromThisLocator(entireConfiguration.keySet());
- String[] jarNames = jarData.keySet().stream().toArray(String[]::new);
- byte[][] jarBytes = jarData.values().toArray(new byte[jarNames.length][]);
-
- assertNotNull(jarNames);
- assertNotNull(jarBytes);
-
- sharedConfig.deleteXmlEntity(new XmlEntity(CacheXml.REGION, "name", REGION1),
- new String[] {testGroup});
- sharedConfig.removeJars(new String[] {"foo.jar"}, null);
- sharedConfig.removeJars(null, null);
- });
-
- dataMemberVm.invoke(() -> {
- Set<String> groups = new HashSet<String>();
- groups.add(testGroup);
- ConfigurationRequest configRequest = new ConfigurationRequest(groups);
- ConfigurationResponse configResponse = (ConfigurationResponse) new TcpClient()
- .requestToServer(InetAddress.getByName("localhost"), locator2Port, configRequest, 1000);
- assertNotNull(configResponse);
-
- Map<String, Configuration> requestedConfiguration =
- configResponse.getRequestedConfiguration();
- Configuration clusterConfiguration =
- requestedConfiguration.get(SharedConfiguration.CLUSTER_CONFIG);
- assertNotNull(clusterConfiguration);
- assertTrue(configResponse.getJarNames().length == 0);
- assertTrue(configResponse.getJars().length == 0);
- assertTrue(clusterConfiguration.getJarNames().isEmpty());
- assertTrue(clusterConfiguration.getGemfireProperties().getProperty(LOG_LEVEL)
- .equals(clusterLogLevel));
-
- Configuration testGroupConfiguration = requestedConfiguration.get(testGroup);
- assertNotNull(testGroupConfiguration);
- assertFalse(testGroupConfiguration.getCacheXmlContent().contains(REGION1));
- assertTrue(testGroupConfiguration.getJarNames().isEmpty());
- assertTrue(testGroupConfiguration.getGemfireProperties().getProperty(LOG_LEVEL)
- .equals(groupLogLevel));
-
- GemFireCacheImpl cache = (GemFireCacheImpl) getCache();
- Map<InternalDistributedMember, Collection<String>> locatorsWithSharedConfiguration =
- cache.getDistributionManager().getAllHostedLocatorsWithSharedConfiguration();
- assertFalse(locatorsWithSharedConfiguration.isEmpty());
- assertTrue(locatorsWithSharedConfiguration.size() == 2);
- Set<InternalDistributedMember> locatorMembers = locatorsWithSharedConfiguration.keySet();
- for (InternalDistributedMember locatorMember : locatorMembers) {
- System.out.println(locatorMember);
- }
- return null;
- });
- }
-}
http://git-wip-us.apache.org/repos/asf/geode/blob/e79e0103/geode-core/src/test/java/org/apache/geode/management/internal/configuration/SharedConfigurationTestUtils.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/configuration/SharedConfigurationTestUtils.java b/geode-core/src/test/java/org/apache/geode/management/internal/configuration/SharedConfigurationTestUtils.java
index 80c510a..eddaad2 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/configuration/SharedConfigurationTestUtils.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/configuration/SharedConfigurationTestUtils.java
@@ -14,8 +14,8 @@
*/
package org.apache.geode.management.internal.configuration;
+import org.apache.geode.distributed.internal.ClusterConfigurationService;
import org.apache.geode.distributed.internal.InternalLocator;
-import org.apache.geode.distributed.internal.SharedConfiguration;
import org.apache.geode.test.dunit.SerializableRunnable;
import org.apache.geode.test.dunit.internal.JUnit3DistributedTestCase;
@@ -26,7 +26,7 @@ public class SharedConfigurationTestUtils {
public void run() {
InternalLocator locator = InternalLocator.getLocator();
if (locator != null) {
- SharedConfiguration sharedConfig = locator.getSharedConfiguration();
+ ClusterConfigurationService sharedConfig = locator.getSharedConfiguration();
if (sharedConfig != null) {
sharedConfig.destroySharedConfiguration();
}
http://git-wip-us.apache.org/repos/asf/geode/blob/e79e0103/geode-core/src/test/java/org/apache/geode/management/internal/configuration/SharedConfigurationUsingDirDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/configuration/SharedConfigurationUsingDirDUnitTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/configuration/SharedConfigurationUsingDirDUnitTest.java
deleted file mode 100644
index a434f05..0000000
--- a/geode-core/src/test/java/org/apache/geode/management/internal/configuration/SharedConfigurationUsingDirDUnitTest.java
+++ /dev/null
@@ -1,334 +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.internal.configuration;
-
-import static java.util.concurrent.TimeUnit.MINUTES;
-import static java.util.stream.Collectors.joining;
-import static org.apache.geode.distributed.ConfigurationProperties.ENABLE_CLUSTER_CONFIGURATION;
-import static org.apache.geode.distributed.ConfigurationProperties.LOAD_CLUSTER_CONFIGURATION_FROM_DIR;
-import static org.apache.geode.distributed.ConfigurationProperties.LOCATORS;
-import static org.apache.geode.distributed.ConfigurationProperties.LOG_FILE;
-import static org.apache.geode.distributed.ConfigurationProperties.MCAST_PORT;
-import static org.apache.geode.distributed.ConfigurationProperties.NAME;
-import static org.apache.geode.distributed.ConfigurationProperties.USE_CLUSTER_CONFIGURATION;
-import static org.apache.geode.internal.AvailablePortHelper.getRandomAvailableTCPPorts;
-import static org.apache.geode.test.dunit.Host.getHost;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-
-import com.jayway.awaitility.Awaitility;
-import com.jayway.awaitility.core.ConditionFactory;
-import org.apache.geode.cache.Region;
-import org.apache.geode.distributed.Locator;
-import org.apache.geode.distributed.internal.InternalLocator;
-import org.apache.geode.distributed.internal.SharedConfiguration;
-import org.apache.geode.test.dunit.VM;
-import org.apache.geode.test.dunit.cache.internal.JUnit4CacheTestCase;
-import org.apache.geode.test.junit.categories.DistributedTest;
-import org.apache.geode.test.junit.categories.FlakyTest;
-import org.apache.geode.util.test.TestUtil;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.InputStream;
-import java.nio.file.Files;
-import java.nio.file.Paths;
-import java.nio.file.StandardCopyOption;
-import java.util.Arrays;
-import java.util.Properties;
-
-@Category({DistributedTest.class, FlakyTest.class}) // GEODE-1165
-public class SharedConfigurationUsingDirDUnitTest extends JUnit4CacheTestCase {
-
- @Override
- public final void preTearDownCacheTestCase() throws Exception {
- for (int i = 0; i < 2; i++) {
- VM vm = getHost(0).getVM(i);
- vm.invoke("Removing shared configuration", () -> {
- InternalLocator locator = InternalLocator.getLocator();
- if (locator == null) {
- return;
- }
-
- SharedConfiguration sharedConfig = locator.getSharedConfiguration();
- if (sharedConfig != null) {
- sharedConfig.destroySharedConfiguration();
- }
- });
- }
- }
-
- @Test
- public void basicClusterConfigDirWithOneLocator() throws Exception {
- final int[] ports = getRandomAvailableTCPPorts(1);
- final int locatorCount = ports.length;
-
- for (int i = 0; i < locatorCount; i++) {
- VM vm = getHost(0).getVM(i);
- copyClusterXml(vm, "cluster-region.xml");
- startLocator(vm, i, ports);
- waitForSharedConfiguration(vm);
- }
-
- for (int i = 2; i < 4; i++) {
- VM vm = getHost(0).getVM(i);
- restartCache(vm, i, ports);
-
- vm.invoke("Checking for region presence", () -> {
- await().until(() -> getRootRegion("newReplicatedRegion") != null);
- });
- }
- }
-
- @Test
- public void basicClusterConfigDirWithTwoLocators() throws Exception {
- final int[] ports = getRandomAvailableTCPPorts(2);
- final int locatorCount = ports.length;
-
- for (int i = 0; i < locatorCount; i++) {
- VM vm = getHost(0).getVM(i);
- copyClusterXml(vm, "cluster-region.xml");
- startLocator(vm, i, ports);
- waitForSharedConfiguration(vm);
- }
-
- for (int i = 2; i < 4; i++) {
- VM vm = getHost(0).getVM(i);
- restartCache(vm, i, ports);
-
- vm.invoke("Checking for region presence", () -> {
- await().until(() -> getRootRegion("newReplicatedRegion") != null);
- });
- }
- }
-
- @Test
- public void updateClusterConfigDirWithTwoLocatorsNoRollingServerRestart() throws Exception {
- final int[] ports = getRandomAvailableTCPPorts(2);
- final int locatorCount = ports.length;
-
- for (int i = 0; i < locatorCount; i++) {
- VM vm = getHost(0).getVM(i);
- copyClusterXml(vm, "cluster-empty.xml");
- startLocator(vm, i, ports);
- waitForSharedConfiguration(vm);
- }
-
- for (int i = 2; i < 4; i++) {
- VM vm = getHost(0).getVM(i);
- restartCache(vm, i, ports);
-
- vm.invoke("Checking for region absence", () -> {
- Region r = getRootRegion("newReplicatedRegion");
- assertNull("Region does exist", r);
- });
- }
-
- // Shut down the locators in reverse order to how we will start them up in the next step.
- // Unless we start them asynchronously, the older one will want to wait for a new diskstore
- // to become available and will time out.
- for (int i = locatorCount; i > 0; i--) {
- VM vm = getHost(0).getVM(i - 1);
- stopLocator(vm);
- }
-
- for (int i = 0; i < locatorCount; i++) {
- VM vm = getHost(0).getVM(i);
- copyClusterXml(vm, "cluster-region.xml");
- startLocator(vm, i, ports);
- waitForSharedConfiguration(vm);
- }
-
- for (int i = 2; i < 4; i++) {
- VM vm = getHost(0).getVM(i);
- vm.invoke(() -> disconnectFromDS());
- }
-
- for (int i = 2; i < 4; i++) {
- VM vm = getHost(0).getVM(i);
- restartCache(vm, i, ports);
-
- vm.invoke("Checking for region presence", () -> {
- await().until(() -> getRootRegion("newReplicatedRegion") != null);
- });
- }
- }
-
- @Test
- public void updateClusterConfigDirWithTwoLocatorsAndRollingServerRestart() throws Exception {
- final int[] ports = getRandomAvailableTCPPorts(2);
- final int locatorCount = ports.length;
-
- for (int i = 0; i < locatorCount; i++) {
- VM vm = getHost(0).getVM(i);
- copyClusterXml(vm, "cluster-empty.xml");
- startLocator(vm, i, ports);
- waitForSharedConfiguration(vm);
- }
-
- for (int i = 2; i < 4; i++) {
- VM vm = getHost(0).getVM(i);
- restartCache(vm, i, ports);
-
- vm.invoke("Checking for region absence", () -> {
- Region r = getRootRegion("newReplicatedRegion");
- assertNull("Region does exist", r);
- });
- }
-
- // Shut down the locators in reverse order to how we will start them up in the next step.
- // Unless we start them asynchronously, the older one will want to wait for a new diskstore
- // to become available and will time out.
- for (int i = locatorCount; i > 0; i--) {
- VM vm = getHost(0).getVM(i - 1);
- stopLocator(vm);
- }
-
- for (int i = 0; i < locatorCount; i++) {
- VM vm = getHost(0).getVM(i);
- copyClusterXml(vm, "cluster-region.xml");
- startLocator(vm, i, ports);
- waitForSharedConfiguration(vm);
- }
-
- for (int i = 2; i < 4; i++) {
- VM vm = getHost(0).getVM(i);
- restartCache(vm, i, ports);
-
- vm.invoke("Checking for region presence", () -> {
- await().until(() -> getRootRegion("newReplicatedRegion") != null);
- });
- }
- }
-
- @Test
- public void updateClusterConfigDirWithTwoLocatorsRollingRestartAndRollingServerRestart()
- throws Exception {
- final int[] ports = getRandomAvailableTCPPorts(2);
- final int locatorCount = ports.length;
-
- for (int i = 0; i < locatorCount; i++) {
- VM vm = getHost(0).getVM(i);
- copyClusterXml(vm, "cluster-empty.xml");
- startLocator(vm, i, ports);
- waitForSharedConfiguration(vm);
- }
-
- for (int i = 2; i < 4; i++) {
- VM vm = getHost(0).getVM(i);
- restartCache(vm, i, ports);
-
- vm.invoke("Checking for region absence", () -> {
- Region r = getRootRegion("newReplicatedRegion");
- assertNull("Region does exist", r);
- });
- }
-
- // Roll the locators
- for (int i = locatorCount - 1; i >= 0; i--) {
- VM vm = getHost(0).getVM(i);
- stopLocator(vm);
- copyClusterXml(vm, "cluster-region.xml");
- startLocator(vm, i, ports);
- waitForSharedConfiguration(vm);
- }
-
- // Roll the servers
- for (int i = 2; i < 4; i++) {
- VM vm = getHost(0).getVM(i);
- restartCache(vm, i, ports);
-
- vm.invoke("Checking for region presence", () -> {
- await().until(() -> getRootRegion("newReplicatedRegion") != null);
- });
- }
- }
-
- private void copyClusterXml(final VM vm, final String clusterXml) {
- vm.invoke("Copying new cluster.xml from " + clusterXml, () -> {
- String clusterXmlPath =
- TestUtil.getResourcePath(SharedConfigurationUsingDirDUnitTest.class, clusterXml);
- InputStream cacheXml = new FileInputStream(clusterXmlPath);
- assertNotNull("Could not create InputStream from " + clusterXmlPath, cacheXml);
- Files.createDirectories(Paths.get("cluster_config", "cluster"));
- Files.copy(cacheXml, Paths.get("cluster_config", "cluster", "cluster.xml"),
- StandardCopyOption.REPLACE_EXISTING);
- });
- }
-
- private void startLocator(final VM vm, final int i, final int[] locatorPorts) {
- vm.invoke("Creating locator on " + vm, () -> {
- final String locatorName = "locator" + i;
- final File logFile = new File("locator-" + i + ".log");
- final Properties props = new Properties();
- props.setProperty(NAME, locatorName);
- props.setProperty(MCAST_PORT, "0");
- props.setProperty(ENABLE_CLUSTER_CONFIGURATION, "true");
- props.setProperty(LOAD_CLUSTER_CONFIGURATION_FROM_DIR, "true");
-
- if (locatorPorts.length > 1) {
- int otherLocatorPort = locatorPorts[(i + 1) % locatorPorts.length];
- props.setProperty(LOCATORS, "localhost[" + otherLocatorPort + "]");
- }
-
- Locator.startLocatorAndDS(locatorPorts[i], logFile, props);
- });
- }
-
- private void waitForSharedConfiguration(final VM vm) {
- vm.invoke("Waiting for shared configuration", () -> {
- final InternalLocator locator = InternalLocator.getLocator();
- await().until(() -> {
- return locator.isSharedConfigurationRunning();
- });
- });
- }
-
- private void stopLocator(final VM vm) {
- vm.invoke("Stopping locator on " + vm, () -> {
- InternalLocator locator = InternalLocator.getLocator();
- assertNotNull("No locator found", locator);
- locator.stop();
- disconnectAllFromDS();
- });
- }
-
- private void restartCache(final VM vm, final int i, final int[] locatorPorts) {
- vm.invoke("Creating cache on VM " + i, () -> {
- disconnectFromDS();
-
- final Properties props = new Properties();
- props.setProperty(NAME, "member" + i);
- props.setProperty(MCAST_PORT, "0");
- props.setProperty(LOCATORS, getLocatorStr(locatorPorts));
- props.setProperty(LOG_FILE, "server-" + i + ".log");
- props.setProperty(USE_CLUSTER_CONFIGURATION, "true");
- props.setProperty(ENABLE_CLUSTER_CONFIGURATION, "true");
-
- getSystem(props);
- getCache();
- });
- }
-
- private String getLocatorStr(final int[] locatorPorts) {
- return Arrays.stream(locatorPorts).mapToObj(p -> "localhost[" + p + "]").collect(joining(","));
- }
-
- private ConditionFactory await() {
- return Awaitility.await().atMost(2, MINUTES);
- }
-}
http://git-wip-us.apache.org/repos/asf/geode/blob/e79e0103/geode-core/src/test/java/org/apache/geode/management/internal/configuration/utils/XmlUtilsAddNewNodeJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/configuration/utils/XmlUtilsAddNewNodeJUnitTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/configuration/utils/XmlUtilsAddNewNodeJUnitTest.java
index 66406a7..d7204fb 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/configuration/utils/XmlUtilsAddNewNodeJUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/configuration/utils/XmlUtilsAddNewNodeJUnitTest.java
@@ -16,7 +16,7 @@ package org.apache.geode.management.internal.configuration.utils;
import org.apache.geode.cache.Cache;
import org.apache.geode.cache.CacheFactory;
-import org.apache.geode.distributed.internal.SharedConfiguration;
+import org.apache.geode.distributed.internal.ClusterConfigurationService;
import org.apache.geode.internal.cache.extension.Extension;
import org.apache.geode.internal.cache.xmlcache.CacheXml;
import org.apache.geode.management.internal.configuration.domain.XmlEntity;
@@ -45,9 +45,9 @@ import static org.junit.Assert.assertEquals;
/**
* Unit tests for {@link XmlUtils#addNewNode(Document, XmlEntity)} and
- * {@link XmlUtils#deleteNode(Document, XmlEntity)}. Simulates the {@link SharedConfiguration}
- * method of extracting {@link XmlEntity} from the new config and applying it to the current shared
- * config.
+ * {@link XmlUtils#deleteNode(Document, XmlEntity)}. Simulates the
+ * {@link ClusterConfigurationService} method of extracting {@link XmlEntity} from the new config
+ * and applying it to the current shared config.
*
*
* @since GemFire 8.1